From ac0ec1feee3616c3568c24f5a52afa052ccd2e80 Mon Sep 17 00:00:00 2001 From: Fanhuitong <981964879@qq.com> Date: Thu, 4 Jan 2024 11:44:53 +0800 Subject: [PATCH] =?UTF-8?q?version:3.2.0=20fix:=E4=BC=98=E5=8C=96=E7=AE=A1?= =?UTF-8?q?=E6=8E=A7=E9=80=BB=E8=BE=91=20update:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 11 +- .../fuying/sn/activity/main/MainActivity.java | 54 ++- .../com/fuying/sn/desktop/MachineControl.java | 11 + .../fuying/sn/desktop/RunningAppManager.java | 457 ++++++++++++++---- .../fuying/sn/desktop/TimeControlManager.java | 4 +- .../com/fuying/sn/manager/ControlManager.java | 12 +- .../sn/network/NetInterfaceManager.java | 17 +- .../com/fuying/sn/service/RemoteService.java | 42 +- .../com/fuying/sn/tpush/MessageReceiver.java | 7 +- .../java/com/fuying/sn/utils/JGYUtils.java | 46 +- app/tpns-configs.json | 14 + build.gradle | 2 + 12 files changed, 541 insertions(+), 136 deletions(-) create mode 100644 app/tpns-configs.json diff --git a/app/build.gradle b/app/build.gradle index ef4cf8f..ce7f8c7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply plugin: "com.tencent.android.tpns" static def appName() { return "FLYSN" @@ -73,8 +74,8 @@ android { official { flavorDimensions "default" - versionCode 50 - versionName "3.1.0" + versionCode 60 + versionName "3.2.0" } } @@ -152,7 +153,7 @@ android { v2SigningEnabled true } - G10P{ + G10P { storeFile file("keystore/G10PMTK11.jks") storePassword "123456" keyAlias "G10PMTK11" @@ -161,7 +162,7 @@ android { v2SigningEnabled true } - Teclast8515{ + Teclast8515 { storeFile file("keystore/Teclast8515.keystore") storePassword "123456" keyAlias "Teclast8515" @@ -484,7 +485,7 @@ dependencies { //bugly implementation 'com.tencent.bugly:crashreport:4.1.9.2' //腾讯移动推送 TPNS - implementation 'com.tencent.tpns:tpns:1.3.2.0-release' + implementation 'com.tencent.tpns:tpns:1.4.3.4-release' //百度地图 implementation 'com.baidu.lbsyun:BaiduMapSDK_Location:9.1.8' //工具类 diff --git a/app/src/main/java/com/fuying/sn/activity/main/MainActivity.java b/app/src/main/java/com/fuying/sn/activity/main/MainActivity.java index fd1837d..bf27a69 100644 --- a/app/src/main/java/com/fuying/sn/activity/main/MainActivity.java +++ b/app/src/main/java/com/fuying/sn/activity/main/MainActivity.java @@ -28,6 +28,7 @@ import com.blankj.utilcode.util.NetworkUtils; import com.fuying.sn.BuildConfig; import com.fuying.sn.R; import com.fuying.sn.base.BaseActivity; +import com.fuying.sn.bean.AppInfo; import com.fuying.sn.bean.BaseResponse; import com.fuying.sn.bean.SnInfo; import com.fuying.sn.config.CommonConfig; @@ -50,6 +51,8 @@ import com.fuying.sn.utils.SPUtils; import com.fuying.sn.utils.TimeUtils; import com.fuying.sn.utils.ToastUtil; import com.fuying.sn.utils.Utils; +import com.trello.rxlifecycle4.RxLifecycle; +import com.trello.rxlifecycle4.android.ActivityEvent; import org.jetbrains.annotations.NotNull; @@ -58,6 +61,9 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; +import io.reactivex.rxjava3.annotations.NonNull; +import io.reactivex.rxjava3.core.Observer; +import io.reactivex.rxjava3.disposables.Disposable; public class MainActivity extends BaseActivity implements MainAContact.MainView, NetworkUtils.OnNetworkStatusChangedListener { private static final String TAG = MainActivity.class.getSimpleName(); @@ -151,12 +157,58 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView, tv_update.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ToastUtil.show("正在检查更新"); mPresenter.getAllApp(); + if (mCheckUpdate) { + ToastUtil.show("您已检查过更新,请稍后再试"); + } else { + ToastUtil.show("正在检查更新"); + checkUpdate(); + } } }); } + private boolean mCheckUpdate = false; + + private void checkUpdate() { + NetInterfaceManager.getInstance().getUpdateObservable(BuildConfig.APPLICATION_ID) + .compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY)) + .subscribe(new Observer>() { + @Override + public void onSubscribe(@NonNull Disposable d) { + Log.e("checkUpdate", "onSubscribe: "); + } + + @Override + public void onNext(@NonNull BaseResponse appInfoBaseResponse) { + Log.e("checkUpdate", "onSubscribe: " + appInfoBaseResponse); + if (appInfoBaseResponse.code == 200) { + AppInfo appInfo = appInfoBaseResponse.data; + if (appInfo.getApp_version_code() > BuildConfig.VERSION_CODE) { + ToastUtil.show("正在下载更新"); + } else { + ToastUtil.show("已是最新版本"); + } + } else { + ToastUtil.show("没有找到更新"); + } + } + + @Override + public void onError(@NonNull Throwable e) { + Log.e("checkUpdate", "onError: " + e.getMessage()); + ToastUtil.show("请稍后重试"); + onComplete(); + } + + @Override + public void onComplete() { + Log.e("checkUpdate", "onComplete: "); + mCheckUpdate = true; + } + }); + } + private TimeTask task; private static class TimeTask extends AsyncTask { diff --git a/app/src/main/java/com/fuying/sn/desktop/MachineControl.java b/app/src/main/java/com/fuying/sn/desktop/MachineControl.java index 14227d6..bf7178b 100644 --- a/app/src/main/java/com/fuying/sn/desktop/MachineControl.java +++ b/app/src/main/java/com/fuying/sn/desktop/MachineControl.java @@ -29,6 +29,9 @@ public class MachineControl implements Serializable { /*上学日时间段*/ List time_part; + /*是否设置了可用时间*/ + int is_set; + public int getId() { return id; } @@ -93,6 +96,14 @@ public class MachineControl implements Serializable { this.time_part = time_part; } + public int getIs_set() { + return is_set; + } + + public void setIs_set(int is_set) { + this.is_set = is_set; + } + @NonNull @Override public String toString() { diff --git a/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java b/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java index 8255fd5..1c1e238 100644 --- a/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java +++ b/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java @@ -36,7 +36,6 @@ import com.fuying.sn.bean.MyAppUsageBean; import com.fuying.sn.bean.PartTime; import com.fuying.sn.bean.RemainTime; import com.fuying.sn.config.CommonConfig; -import com.fuying.sn.disklrucache.CacheHelper; import com.fuying.sn.gson.GsonUtils; import com.fuying.sn.network.NetInterfaceManager; import com.fuying.sn.network.UrlAddress; @@ -171,9 +170,9 @@ public class RunningAppManager { // Log.i(TAG, "accept: " + aLong); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); - if (!isScreenOn) { - return; - } +// if (!isScreenOn) { +// return; +// } checkForegroundAppName(); } }); @@ -199,8 +198,8 @@ public class RunningAppManager { @Override public void onComplete() { Log.i(TAG, "onComplete: "); -// NetInterfaceManager.getInstance().getSnTimeControl(); -// NetInterfaceManager.getInstance().getAppTimeControl(); + NetInterfaceManager.getInstance().getAppTimeControl(); + NetInterfaceManager.getInstance().getSnTimeControl(); } }); NetInterfaceManager.getInstance().getMyAppList(new NetInterfaceManager.MyAppListCallback() { @@ -211,7 +210,6 @@ public class RunningAppManager { }); AppUsedTimeUtils.getInstance().setApp_package(topPackage); AppUsedTimeUtils.getInstance().setStart_time(System.currentTimeMillis() / 1000); -// NetInterfaceManager.getInstance().sendRunningApp(); } } mMMKV.encode(RUNNING_APP_PACKAGENAME, ""); @@ -224,7 +222,6 @@ public class RunningAppManager { recordPackageOpenTime(topPackage); AppUsedTimeUtils.getInstance().setApp_package(topPackage); AppUsedTimeUtils.getInstance().setStart_time(System.currentTimeMillis() / 1000); -// NetInterfaceManager.getInstance().sendRunningApp(); return; } long onClickTime = getOnClickTime(); @@ -232,7 +229,11 @@ public class RunningAppManager { if (appPackageName.equals(topPackage)) { Log.i(TAG, "checkForegroundAppName: 没有切换应用"); if (inControlTime(appPackageName)) { - removeTask(topPackage); + Log.i(TAG, "checkForegroundAppName: 没有剩余时间1"); +// removeTask(topPackage); + NetInterfaceManager.getInstance().getAppTimeControl(); + NetInterfaceManager.getInstance().getSnTimeControl(); + JGYUtils.getInstance().killPackage(appPackageName); killApp(); gotoLauncher(); } else { @@ -244,16 +245,11 @@ public class RunningAppManager { NetInterfaceManager.getInstance().sendCloseApp(appPackageName, new NetInterfaceManager.CompleteCallback() { @Override public void onComplete() { -// NetInterfaceManager.getInstance().getSnTimeControl(); -// NetInterfaceManager.getInstance().getAppTimeControl(); + NetInterfaceManager.getInstance().getAppTimeControl(); + NetInterfaceManager.getInstance().getSnTimeControl(); } }); -// NetInterfaceManager.getInstance().getMyAppList(new NetInterfaceManager.MyAppListCallback() { -// @Override -// public void setMyAppList(List myAppList) { -// syncAllAppUsageTime(myAppList); -// } -// }); + reduceAppRemainingTime(topPackage, 1); appPackageName = topPackage; AppUsedTimeUtils.getInstance().setApp_package(appPackageName); @@ -262,9 +258,12 @@ public class RunningAppManager { AppUsedTimeUtils.getInstance().setStart_time(onClickTime); if (inControlTime(appPackageName)) { Log.i(TAG, "checkForegroundAppName: 没有剩余时间2"); - removeTask(topPackage); +// removeTask(topPackage); killApp(); + JGYUtils.getInstance().killPackage(appPackageName); gotoLauncher(); + NetInterfaceManager.getInstance().getAppTimeControl(); + NetInterfaceManager.getInstance().getSnTimeControl(); } else { recordPackageOpenTime(topPackage); Log.i(TAG, "checkForegroundAppName: 没有管控2"); @@ -287,7 +286,7 @@ public class RunningAppManager { ) { continue; } - JGYUtils.getInstance().killBackgroundProcesses(pkg); + JGYUtils.getInstance().killPackage(pkg); } } @@ -332,7 +331,7 @@ public class RunningAppManager { public void killBackgroundProcesses(String processName) { // gotoLauncher(); // mIsScanning = true; - removeTask(processName); +// removeTask(processName); ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); String packageName = null; try { @@ -583,7 +582,7 @@ public class RunningAppManager { boolean havaConfigure = TimeControlManager.getInstance().havaConfigure(pkg); MachineControl machineControl = TimeControlManager.getInstance().getGlobalMachineControl(); - Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime); + Log.e(TAG, "reduceAppRemainingTime: globalRemainingTime = " + globalRemainingTime); if (globalRemainingTime <= 0) { if (machineControl != null) { if (machineControl.getIs_part() == 0 && machineControl.getIs_quota() == 0) { @@ -715,20 +714,27 @@ public class RunningAppManager { * @param pkg * @return */ - public boolean inControlTime(String pkg) { + public boolean inControlTime2(String pkg) { + Log.i(TAG, "inControlTime: pkg = " + pkg); if (allowPackage.contains(pkg)) { + Log.i(TAG, "inControlTime: allow = " + pkg); return false; } - Log.i(TAG, "inControlTime: pkg = " + pkg); int isControl = Settings.System.getInt(mContext.getContentResolver(), CommonConfig.KEY_IS_CONTROL, 1); Log.i(TAG, "inControlTime: isControl = " + isControl); - //家长管控关闭始终可用 + //家长管控关闭 始终可用 if (isControl == 0) { return false; } boolean havaConfigure = TimeControlManager.getInstance().havaConfigure(pkg); MachineControl machineControl = TimeControlManager.getInstance().getGlobalMachineControl(); + long work_time = machineControl.getWork_time(); + long rest_time = machineControl.getRest_time(); + long today_time = machineControl.getToday_time(); + int is_part = machineControl.getIs_part(); + int is_set = machineControl.getIs_set(); + if (havaConfigure) { //有单独设置 不管是分类整机还是其他都是这个设置 AppTimeControl appTimeControl = TimeControlManager.getInstance().getAppTimeControl(pkg); @@ -742,62 +748,96 @@ public class RunningAppManager { return false; } - Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime); - if (appTimeControl.getTc_use_type() != 3) { - if (globalRemainingTime <= 0) { - if (machineControl != null) { - if (machineControl.getIs_part() == 0 && machineControl.getIs_quota() == 0) { - Log.e(TAG, "inControlTime: is_part = 0 is_quota = 0"); - //整机额度和时间段关闭不管控 + if (work_time == 0 && rest_time == 0 && is_set == 0 && is_part == 0) { + //没有整机额度,没有整机时段,没有修改临时时长 + Log.e(TAG, "inControlTime: not set"); + return false; + } + + if (machineControl.getIs_quota() == 1) {//打开整机额度 + Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime); + if (appTimeControl.getTc_use_type() != 3) { + if (work_time == 0 && rest_time == 0 && is_set == 0) { + Log.e(TAG, "inControlTime: work_time == 0 rest_time == 0 is_set == 0"); + if (appTimeControl.getIs_part() == 1) {//时间段管控打开 + boolean inControlTime = inControlTime(machineControl, appTimeControl); + //判断是否在时间段内 + if (inControlTime) { + Log.i(TAG, "inControlTime: " + "应用在管控时间段不能打开" + appTimeControl.time_part.toString()); + ToastUtil.show("该应用" + partTime2String(appTimeControl)); + Log.e(TAG, "inControlTime: " + "该应用" + partTime2String(appTimeControl)); + return true; + } else { + Log.e(TAG, "inControlTime: " + "不在管控时间段内"); + return false; + } + } else { + Log.e(TAG, "inControlTime: " + "关闭整机和关闭时间段"); return false; } } else { - ToastUtil.show("今日可使用时间已用完"); - return true; + if (globalRemainingTime <= 0) {//没有剩余时间 + ToastUtil.show("今日可使用时间已用完"); + return true; + } } } - } - //打开时间段管控 - if (appTimeControl.getIs_part() == 1) { - boolean inControlTime = inControlTime(machineControl, appTimeControl); - //判断是否在时间段内 - if (inControlTime) { - Log.i(TAG, "inControlTime: " + "应用在管控时间段不能打开" + appTimeControl.time_part.toString()); - ToastUtil.show("该应用" + partTime2String(appTimeControl)); - Log.e(TAG, "inControlTime: " + "该应用" + partTime2String(appTimeControl)); - return true; - } else { - if (appTimeControl.getIs_quota() == 0) { - //要求设置了管控时间段没有设置使用额度也可以使用 - return false; + + //打开时间段管控 + if (appTimeControl.getIs_part() == 1) { + boolean inControlTime = inControlTime(machineControl, appTimeControl); + //判断是否在时间段内 + if (inControlTime) { + Log.i(TAG, "inControlTime: " + "应用在管控时间段不能打开" + appTimeControl.time_part.toString()); + ToastUtil.show("该应用" + partTime2String(appTimeControl)); + Log.e(TAG, "inControlTime: " + "该应用" + partTime2String(appTimeControl)); + return true; + } else { + + if (getAppRemainingTime(pkg) <= 0) { + //没有剩余时间 + ToastUtil.show("该应用今日可使用时间已用完"); + Log.e(TAG, "inControlTime: " + "该应用今日可使用时间已用完"); + return true; + } else { + return false; + } } + } else { if (getAppRemainingTime(pkg) <= 0) { //没有剩余时间 ToastUtil.show("该应用今日可使用时间已用完"); Log.e(TAG, "inControlTime: " + "该应用今日可使用时间已用完"); - return true; } else { return false; } } - } else { - //关闭时间段管控关闭额度开关为不管控 - if (appTimeControl.getIs_quota() == 0) { - Log.e(TAG, "inControlTime: " + "没有使用额度"); - return false; - } - if (getAppRemainingTime(pkg) <= 0) { - //没有剩余时间 - ToastUtil.show("该应用今日可使用时间已用完"); - Log.e(TAG, "inControlTime: " + "该应用今日可使用时间已用完"); - return true; + } else {//关闭整机额度 + //打开时间段管控 + if (appTimeControl.getIs_part() == 1) { + boolean inControlTime = inControlTime(machineControl, appTimeControl); + //判断是否在时间段内 + if (inControlTime) { + Log.i(TAG, "inControlTime: " + "应用在管控时间段不能打开" + appTimeControl.time_part.toString()); + ToastUtil.show("该应用" + partTime2String(appTimeControl)); + Log.e(TAG, "inControlTime: " + "该应用" + partTime2String(appTimeControl)); + return true; + } else { + Log.e(TAG, "inControlTime: " + "不在管控时间段内"); + return false; + } } else { + Log.e(TAG, "inControlTime: " + "关闭整机和关闭时间段"); return false; } } } else { //根据整机 + if (work_time == 0 && rest_time == 0 && is_set == 0) { + Log.e(TAG, "inControlTime: not set"); + return false; + } if (machineControl == null) { return false; } @@ -806,6 +846,8 @@ public class RunningAppManager { Log.e(TAG, "inControlTime: is_part = 0 is_quota = 0"); //整机额度和时间段关闭不管控 return false; + } else { + return true; } } @@ -827,6 +869,251 @@ public class RunningAppManager { } } + /** + * 是否在管控时间内 + * + * @param pkg 包名 + * @return 可用返回false,不可用返回true + */ + public boolean inControlTime(String pkg) { + Log.e(TAG, "inControlTime: pkg = " + pkg); + if (allowPackage.contains(pkg)) { + Log.e(TAG, "inControlTime: allow = " + pkg); + return false; + } + int isControl = Settings.System.getInt(mContext.getContentResolver(), CommonConfig.KEY_IS_CONTROL, 1); + Log.e(TAG, "inControlTime: isControl = " + isControl); + //只要关闭家长管控开关,相关内容需无效 + if (isControl == 0) { + Log.e(TAG, "inControlTime: 管控开关关闭家长"); + return false; + } + boolean havaConfigure = TimeControlManager.getInstance().havaConfigure(pkg); + Log.e(TAG, "inControlTime: havaConfigure = " + havaConfigure); + MachineControl machineControl = TimeControlManager.getInstance().getGlobalMachineControl(); + Log.e(TAG, "inControlTime: inControlTime = " + machineControl); + + Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime); + //整机额度开关 + int is_quota = machineControl.getIs_quota(); + //整机使用时段开关 + int is_part = machineControl.getIs_part(); + long work_time = machineControl.getWork_time(); + long rest_time = machineControl.getRest_time(); + long today_time = machineControl.getToday_time(); + //是否手动设置临时时间 + int is_set = machineControl.getIs_set(); + + if (havaConfigure) {//app有单独配置的情况 + //有单独设置 不管是分类整机还是其他都是这个设置 + AppTimeControl appTimeControl = TimeControlManager.getInstance().getAppTimeControl(pkg); + if (appTimeControl.getIs_control() == 0) {//先判断是否被禁用 + Log.e(TAG, "inControlTime: appTimeControl " + "应用已被禁用"); + ToastUtil.show("应用已被禁用"); + return true; + } + if (appTimeControl.getTc_use_type() == 0) {//是否始终可用 + Log.e(TAG, "inControlTime: appTimeControl " + "应用始终可用"); + return false; + } + if (work_time == 0 && rest_time == 0 && is_set == 0 && is_part == 0) { + //没有整机额度,没有整机时段,没有修改临时时长 + Log.e(TAG, "inControlTime: appTimeControl not set"); + return false; + } + + if (appTimeControl.getIs_quota() == 1) {//app额度打开 + Log.e(TAG, "inControlTime: appTimeControl is_quota = 1"); + if (appTimeControl.getIs_part() == 1) {//app额度打开 app使用时段打开 + Log.e(TAG, "inControlTime: appTimeControl is_quota = 1 is_part = 1"); + boolean inControlTime = inControlTime(machineControl, appTimeControl); + //判断是否在时间段内 + if (inControlTime) { + Log.e(TAG, "inControlTime: appTimeControl " + "应用在管控时间段不能打开" + appTimeControl.time_part.toString()); + ToastUtil.show("该应用" + partTime2String(appTimeControl)); + Log.e(TAG, "inControlTime: appTimeControl " + "该应用" + partTime2String(appTimeControl)); + return true; + } else { + if (appTimeControl.getWork_time() == 0 && appTimeControl.getRest_time() == 0) { + Log.e(TAG, "inControlTime: appTimeControl " + "没有设置管控时间"); + return false; + } else { + if (getTodayTime(appTimeControl) == 0) { + Log.e(TAG, "inControlTime: appTimeControl " + "对应日期没有设置额度"); + return false; + } else { + if (getAppRemainingTime(pkg) <= 0) { + //没有剩余时间 + ToastUtil.show("该应用今日可使用时间已用完"); + Log.e(TAG, "inControlTime: appTimeControl " + "该应用今日可使用时间已用完"); + return true; + } else { + Log.e(TAG, "inControlTime: appTimeControl " + "不在管控时间段,app有剩余时间"); + return false; + } + } + } + } + } else {//app额度打开 app使用时段关闭 + Log.e(TAG, "inControlTime: appTimeControl is_quota = 1 is_part = 0"); + if (appTimeControl.getRest_time() == 0 && appTimeControl.getWork_time() == 0) {//自由配置且没有设置额度 + return false; + } else { + if (getTodayTime(appTimeControl) == 0) { + Log.e(TAG, "inControlTime: appTimeControl " + "对应日期没有设置额度"); + return false; + } else { + if (getAppRemainingTime(pkg) <= 0) { + //没有剩余时间 + ToastUtil.show("该应用今日可使用时间已用完"); + Log.e(TAG, "inControlTime: appTimeControl " + "该应用今日可使用时间已用完"); + return true; + } else { + Log.e(TAG, "inControlTime: appTimeControl " + "app有剩余时间"); + return false; + } + } + } + } + } else {//app额度关闭 + Log.e(TAG, "inControlTime: appTimeControl is_quota = 0"); + if (appTimeControl.getIs_part() == 1) {//app额度关闭 app使用时段打开 + Log.e(TAG, "inControlTime: appTimeControl is_quota = 0 is_part = 1"); + boolean inControlTime = inControlTime(machineControl, appTimeControl); + //判断是否在时间段内 + if (inControlTime) { + Log.e(TAG, "inControlTime: appTimeControl " + "应用在管控时间段不能打开" + appTimeControl.time_part.toString()); + ToastUtil.show("该应用" + partTime2String(appTimeControl)); + Log.e(TAG, "inControlTime: appTimeControl " + "该应用" + partTime2String(appTimeControl)); + return true; + } else { + Log.e(TAG, "inControlTime: appTimeControl " + "不在管控时间内"); + if (appTimeControl.getRest_time() == 0 && appTimeControl.getWork_time() == 0) {//自由配置且没有设置额度 + Log.e(TAG, "inControlTime: appTimeControl " + "自由配置且没有设置额度"); + return false; + } else { + //额度关闭时,如果手动设置了时长,用完也不能继续使用 + if (is_set == 1) { + if (getAppRemainingTime(pkg) <= 0) { + //没有剩余时间 + ToastUtil.show("该应用今日可使用时间已用完"); + Log.e(TAG, "inControlTime: appTimeControl " + "该应用今日可使用时间已用完"); + return true; + } else { + Log.e(TAG, "inControlTime: appTimeControl " + "该应用手动设置时长,app有剩余时间"); + return false; + } + } else { + Log.e(TAG, "inControlTime: appTimeControl " + "app额度关闭"); + return false; + } + } + } + } else {//app额度关闭 app使用时段关闭 + Log.e(TAG, "inControlTime: appTimeControl is_quota = 0 is_part = 0"); + //额度关闭时,如果手动设置了时长,用完也不能继续使用 + if (is_set == 1) { + if (getAppRemainingTime(pkg) <= 0) { + //没有剩余时间 + ToastUtil.show("该应用今日可使用时间已用完"); + Log.e(TAG, "inControlTime: appTimeControl " + "该应用今日可使用时间已用完"); + return true; + } else { + Log.e(TAG, "inControlTime: appTimeControl " + "该应用手动设置时长,app有剩余时间"); + return false; + } + } else { + Log.e(TAG, "inControlTime: appTimeControl " + "app额度关闭"); + return false; + } + } + } + } else {//app没有单独配置的情况 + if (is_quota == 1) {//整机额度打开 + Log.e(TAG, "inControlTime: machineControl is_quota = 1"); + if (is_part == 1) {//整机额度打开 整机使用时段打开 + Log.e(TAG, "inControlTime: machineControl is_quota = 1 is_part = 1"); + boolean inControlTime = inControlTime(machineControl); + if (inControlTime) { + Log.e(TAG, "inControlTime: machineControl " + "应用在管控时间段不能打开" + machineControl.time_part.toString()); + ToastUtil.show("该应用" + partTime2String(machineControl)); + return true; + } else { + if (globalRemainingTime <= 0) { + Log.e(TAG, "inControlTime: machineControl globalRemainingTime = 0"); + ToastUtil.show("整机可用时间已用完"); + return true; + } else { + ToastUtil.show("整机可用时间有剩余"); + return false; + } + } + } else {//整机额度打开 整机使用时段关闭 + Log.e(TAG, "inControlTime: machineControl is_quota = 1 is_part = 0"); + if (globalRemainingTime <= 0) { + Log.e(TAG, "inControlTime: machineControl globalRemainingTime = 0"); + ToastUtil.show("整机可用时间已用完"); + return true; + } else { + ToastUtil.show("整机可用时间有剩余"); + return false; + } + } + } else {//整机额度关闭 + Log.e(TAG, "inControlTime: machineControl is_quota = 0"); + //额度关闭时,如果手动设置了时长,用完也不能继续使用 + if (is_part == 1) {//整机额度关闭 整机使用时段打开 + Log.e(TAG, "inControlTime: machineControl is_quota = 0 is_part = 1"); + boolean inControlTime = inControlTime(machineControl); + if (inControlTime) { + Log.e(TAG, "inControlTime: machineControl " + "应用在管控时间段不能打开" + machineControl.time_part.toString()); + ToastUtil.show("该应用" + partTime2String(machineControl)); + return true; + } else { + if (is_set == 1) { + if (globalRemainingTime == 0) { + Log.e(TAG, "inControlTime: machineControl globalRemainingTime = 0"); + ToastUtil.show("整机可用时间已用完"); + return true; + } else { + Log.e(TAG, "inControlTime: machineControl " + "手动设置时长,有剩余时间"); + return false; + } + } else { + Log.e(TAG, "inControlTime: machineControl " + "整机额度关闭"); + return false; + } + } + } else {//整机额度关闭 整机使用时段关闭 + Log.e(TAG, "inControlTime: machineControl is_quota = 0 is_part = 0"); + if (is_set == 1) { + if (globalRemainingTime == 0) { + Log.e(TAG, "inControlTime: machineControl globalRemainingTime = 0"); + ToastUtil.show("整机可用时间已用完"); + return true; + } else { + Log.e(TAG, "inControlTime: machineControl " + "手动设置时长,有剩余时间"); + return false; + } + } else { + Log.e(TAG, "inControlTime: machineControl " + "整机额度关闭"); + return false; + } + } + } + } + } + + private int getTodayTime(AppTimeControl appTimeControl) { + if (inWeekDay()) { + Log.e(TAG, "getTodayTime: Work"); + return (int) appTimeControl.getWork_time(); + } else { + Log.e(TAG, "getTodayTime: Rest"); + return (int) appTimeControl.getRest_time(); + } + } + private String partTime2String(AppTimeControl appTimeControl) { List partTimes = appTimeControl.getTime_part(); if (partTimes == null || partTimes.size() == 0) { @@ -882,37 +1169,13 @@ public class RunningAppManager { * @return json数据 */ public String getDisableContent(String pkg) { -// NetInterfaceManager.getInstance().getMyAppList(new NetInterfaceManager.MyAppListCallback() { -// @Override -// public void setMyAppList(List myAppList) { -// -// } -// }); RemainTime remainTime = new RemainTime(); remainTime.setPkg(pkg); -// if (allowPackage.contains(pkg)) { -// return ""; -// } -// Log.i(TAG, "inControlTime: pkg = " + pkg); -// int is_control = Settings.System.getInt(mContext.getContentResolver(), CommonConfig.KEY_IS_CONTROL, 1); -// Log.i(TAG, "inControlTime: is_control = " + is_control); - //家长管控关闭始终可用 -// if (is_control == 0) { -// return ""; -// } + boolean havaConfigure = TimeControlManager.getInstance().havaConfigure(pkg); MachineControl machineControl = TimeControlManager.getInstance().getGlobalMachineControl(); Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime); -// if (globalRemainingTime <= 0) { -// if (machineControl != null) { -// if (machineControl.getIs_part() == 0 && machineControl.getIs_quota() == 0) { -// return ""; -// } -// } else { -// return ""; -// } -// } if (havaConfigure) { //有单独设置 不管是分类整机还是其他都是这个设置 @@ -927,9 +1190,6 @@ public class RunningAppManager { remainTime.setContent("应用已被禁用"); return remainTime.toString(); } -// if (appTimeControl.getTc_use_type() == 0) { -// return ""; -// } //打开时间段管控 if (appTimeControl.getIs_part() == 1) { boolean inControlTime = inControlTime(machineControl, appTimeControl); @@ -1131,7 +1391,7 @@ public class RunningAppManager { // } else { // return restTime - todayTime <= 0; // } - Log.i(TAG, "haveUseTime: " + globalRemainingTime); + Log.e(TAG, "haveUseTime: " + globalRemainingTime); return (globalRemainingTime > 0); } @@ -1204,6 +1464,9 @@ public class RunningAppManager { public boolean isControlTime(AppTimeControl appTimeControl) { //整机使用时段开关 开启时 if (appTimeControl.getIs_part() == 1) { + if (appTimeControl.getTime_part() == null || appTimeControl.getTime_part().size() == 0) { + return false; + } int partType = appTimeControl.getPart_type(); HashMap> partTimeMap = new HashMap(); HashSet weekdayPart = new HashSet(appTimeControl.getTime_part().stream().filter(partTime -> partTime.getDay_type() == 0).collect(Collectors.toList())); @@ -1239,7 +1502,7 @@ public class RunningAppManager { * @return */ private boolean inControlTime(int partType, Set partTimeHashSet) { - if (partTimeHashSet != null) { + if (partTimeHashSet != null && partTimeHashSet.size() != 0) { if (partType == 0) { List inPartTimes = new ArrayList<>(); for (PartTime partTime : partTimeHashSet) { @@ -1253,11 +1516,15 @@ public class RunningAppManager { for (PartTime partTime : partTimeHashSet) { if (inControlTime(partTime)) { return false; + } else { + return true; } } } + } else { + return false; } - return true; + return false; } private boolean inControlTime(PartTime partTime) { @@ -1265,7 +1532,7 @@ public class RunningAppManager { String endTime = partTime.getEnd_time(); ContralTime contralTime = new ContralTime(startTime, endTime); boolean inControlTime = contralTime.inControlTime(); - Log.i(TAG, "inControlTime: " + inControlTime); + Log.e(TAG, "inControlTime: PartTime " + inControlTime); return inControlTime; } @@ -1338,7 +1605,7 @@ public class RunningAppManager { //开始时间大于结束时间 列 16:00-01:00 endDate.setTime(endDate.getTime() + dayTime); } - Log.i(TAG, "inControlTime: " + (startDate.getTime() - minuteTime)); + Log.e(TAG, "inControlTime: ContralTime " + (startDate.getTime() - minuteTime)); assert nowDate != null; // if (nowDate.getTime() <= startDate.getTime() - minuteTime || nowDate.getTime() >= endDate.getTime()) { if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) { @@ -1369,7 +1636,7 @@ public class RunningAppManager { public String getDate(long time) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String finaWayDate = sdf.format(time); - Log.i(TAG, "getDate: " + finaWayDate); + Log.e(TAG, "getDate: " + finaWayDate); return finaWayDate; } @@ -1380,7 +1647,7 @@ public class RunningAppManager { */ public int getWeekDay() { long time = System.currentTimeMillis(); - Log.i(TAG, "getWeekDay: " + time); + Log.e(TAG, "getWeekDay: " + time); return getWeekDay(time); } @@ -1496,7 +1763,7 @@ public class RunningAppManager { currentClassName = initStat.getPackageName(); } } - Log.i(TAG, "getForegroundActivityName: " + currentClassName); + Log.e(TAG, "getForegroundActivityName: " + currentClassName); return currentClassName; } diff --git a/app/src/main/java/com/fuying/sn/desktop/TimeControlManager.java b/app/src/main/java/com/fuying/sn/desktop/TimeControlManager.java index 6eeec5b..2aab32d 100644 --- a/app/src/main/java/com/fuying/sn/desktop/TimeControlManager.java +++ b/app/src/main/java/com/fuying/sn/desktop/TimeControlManager.java @@ -98,9 +98,9 @@ public class TimeControlManager { return null; } else { Gson gson = new Gson(); - Type Type = new TypeToken() { + Type type = new TypeToken() { }.getType(); - MachineControl machineControl = gson.fromJson(jsonString, Type); + MachineControl machineControl = gson.fromJson(jsonString, type); return machineControl; } } else { diff --git a/app/src/main/java/com/fuying/sn/manager/ControlManager.java b/app/src/main/java/com/fuying/sn/manager/ControlManager.java index d13a474..c73d0cd 100644 --- a/app/src/main/java/com/fuying/sn/manager/ControlManager.java +++ b/app/src/main/java/com/fuying/sn/manager/ControlManager.java @@ -659,7 +659,7 @@ public class ControlManager { public void setDeveloperOptions(SystemSettings systemSettings) { int dev_mode = changeNum(systemSettings.getDev_mode()); Log.e(TAG, "setDeveloperOptions: " + dev_mode); - if (!DeviceManager.isDebugMode()) { +// if (!DeviceManager.isDebugMode()) { Settings.System.putInt(mResolver, "qch_Developeroptions", dev_mode); int old_dev_enabled = Settings.Global.getInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0); Log.e(TAG, "setDeveloperOptions: " + old_dev_enabled); @@ -680,7 +680,7 @@ public class ControlManager { Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式"); ToastUtil.debugShow("打开开发者模式"); } - } +// } setUSBstate("usb_mtp"); closeSettingsApp(); } @@ -689,7 +689,7 @@ public class ControlManager { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); int dev_mode = changeNum(jsonObject.get("dev_mode").getAsInt()); Log.e(TAG, "setDeveloperOptions: " + dev_mode); - if (!DeviceManager.isDebugMode()) { +// if (!DeviceManager.isDebugMode()) { Settings.System.putInt(mResolver, "qch_Developeroptions", dev_mode); int old_dev_enabled = Settings.Global.getInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0); Log.e(TAG, "setDeveloperOptions: " + old_dev_enabled); @@ -710,14 +710,14 @@ public class ControlManager { Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式"); ToastUtil.debugShow("打开开发者模式"); } - } +// } setUSBstate("usb_mtp"); closeSettingsApp(); } public void setDeveloperOptions(int state) { Log.e(TAG, "setDeveloperOptions: " + state); - if (!DeviceManager.isDebugMode()) { +// if (!DeviceManager.isDebugMode()) { Settings.System.putInt(mResolver, "qch_Developeroptions", state); int old_dev_enabled = Settings.Global.getInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0); Log.e(TAG, "setDeveloperOptions: " + old_dev_enabled); @@ -737,7 +737,7 @@ public class ControlManager { Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式"); // ToastUtil.show("打开开发者模式"); } - } +// } closeSettingsApp(); } diff --git a/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java b/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java index 9c1607d..bf1616d 100644 --- a/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java +++ b/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java @@ -117,6 +117,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; import java.util.stream.Collectors; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; @@ -1131,7 +1132,7 @@ public class NetInterfaceManager { if (packageInfo == null) { //未安装 String s = new Gson().toJson(entry.getValue()); - Log.e(TAG, "getAllAppUpdate: " + s); + Log.e(TAG, "getAllAppUpdate: install " + s); JsonObject jsonObject = GsonUtils.getJsonObject(s); FileUtils.ariaDownload(mContext, entry.getValue().getApp_url(), jsonObject); } else { @@ -1144,12 +1145,14 @@ public class NetInterfaceManager { long versionCode = entry.getValue().getApp_version_code(); //版本升级 if (appVersionCode < versionCode) { + Log.e(TAG, "getAllAppUpdate: upgrade " + entry.getKey()); JsonObject jsonObject = GsonUtils.getJsonObject(new Gson().toJson(entry.getValue())); FileUtils.ariaDownload(mContext, entry.getValue().getApp_url(), jsonObject); + } else { + Log.e(TAG, "getAllAppUpdate: is up to date" + entry.getKey()); } } } - } } @@ -1951,6 +1954,15 @@ public class NetInterfaceManager { int code = listBaseResponse.code; if (code == 200) { List appInfos = listBaseResponse.data; + if (appInfos != null && appInfos.size() != 0) { + List temp = appInfos.stream().filter(appInfo -> "com.alibaba.android.rimet".equals(appInfo.getApp_package())).collect(Collectors.toList()); + if (temp.size() == 0 && ApkUtils.isAvailable(mContext, "com.alibaba.android.rimet")) { + Log.e("getForceInstall", "onNext: uninstall dingtalk"); + ApkUtils.uninstallApp(mContext, "com.alibaba.android.rimet"); + }else { + Log.e("getForceInstall", "onNext: dingtalk force"); + } + } mCacheHelper.put(UrlAddress.GET_FORCE_INSTALL, GsonUtils.toJSONString(appInfos)); if (null != appInfos && appInfos.size() != 0) { getForceInstallState(appInfos); @@ -3034,7 +3046,6 @@ public class NetInterfaceManager { } - private static final int REQUEST_CODE = 12345; public void getRunLog() { diff --git a/app/src/main/java/com/fuying/sn/service/RemoteService.java b/app/src/main/java/com/fuying/sn/service/RemoteService.java index 02d229d..e155f95 100644 --- a/app/src/main/java/com/fuying/sn/service/RemoteService.java +++ b/app/src/main/java/com/fuying/sn/service/RemoteService.java @@ -11,6 +11,15 @@ import com.fuying.sn.BuildConfig; import com.fuying.sn.IGetInfoInterface; import com.fuying.sn.config.CommonConfig; import com.fuying.sn.desktop.RunningAppManager; +import com.fuying.sn.network.NetInterfaceManager; +import com.fuying.sn.service.main.MainService; +import com.fuying.sn.utils.Utils; +import com.tencent.android.tpush.XGIOperateCallback; +import com.tencent.android.tpush.XGPushConfig; +import com.tencent.android.tpush.XGPushManager; + +import java.util.ArrayList; +import java.util.List; public class RemoteService extends Service { private String TAG = RemoteService.class.getSimpleName(); @@ -26,8 +35,39 @@ public class RemoteService extends Service { @Override public void onCreate() { - Log.e(TAG, "onCreate: "); super.onCreate(); + Log.e(TAG, "onCreate: "); + tPushInit(); + } + + private void tPushInit() { + XGPushConfig.enableDebug(this, true); + XGPushManager.registerPush(this, new XGIOperateCallback() { + @Override + public void onSuccess(Object data, int flag) { + //token在设备卸载重装的时候有可能会变 + Log.e("TPush", "注册成功,设备token为:" + data); + List accountInfoList = new ArrayList<>(); + accountInfoList.add(new XGPushManager.AccountInfo(XGPushManager.AccountType.CUSTOM.getValue(), Utils.getSerial())); + XGPushManager.upsertAccounts(RemoteService.this, accountInfoList, new XGIOperateCallback() { + @Override + public void onSuccess(Object data, int flag) { + Log.e("TPush", "onSuccess, data:" + data + ", flag:" + flag); + NetInterfaceManager.getInstance().setPushTags(); + } + + @Override + public void onFail(Object data, int errCode, String msg) { + Log.e("TPush", "onFail, data:" + data + ", code:" + errCode + ", msg:" + msg); + } + }); + } + + @Override + public void onFail(Object data, int errCode, String msg) { + Log.e("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg); + } + }); } @Override diff --git a/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java b/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java index 5af9de8..9d54942 100644 --- a/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java +++ b/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java @@ -640,7 +640,7 @@ public class MessageReceiver extends XGPushBaseReceiver { ToastUtil.debugShow("收到推送消息: 强制停止应用"); JsonObject killJSONObject = GsonUtils.getJsonObject(extras); String packages = killJSONObject.get("app_package").getAsString(); - JGYUtils.getInstance().killBackgroundProcesses(packages); + JGYUtils.getInstance().killPackage(packages); JGYUtils.getInstance().gotoLauncher(); Log.e(TAG, extras); break; @@ -784,15 +784,20 @@ public class MessageReceiver extends XGPushBaseReceiver { setDefaultInputMethod(context, extras); break; case ACTION_PARENTAL_CONTROL: + ToastUtil.debugShow("收到推送消息: 家长管控"); NetInterfaceManager.getInstance().getSystemSettings(); break; case ACTION_WHOLE_MACHINE_QUOTA: + ToastUtil.debugShow("收到推送消息: 整机管控"); NetInterfaceManager.getInstance().getSystemSettings(); NetInterfaceManager.getInstance().getAppTimeControl(); NetInterfaceManager.getInstance().getSnTimeControl(); break; case ACTION_APP_CONTROL: + ToastUtil.debugShow("收到推送消息: APP管控"); + NetInterfaceManager.getInstance().getSystemSettings(); NetInterfaceManager.getInstance().getAppTimeControl(); + NetInterfaceManager.getInstance().getSnTimeControl(); break; case UPDATE_WHITE_LIST: NetInterfaceManager.getInstance().getAllappPackage(); diff --git a/app/src/main/java/com/fuying/sn/utils/JGYUtils.java b/app/src/main/java/com/fuying/sn/utils/JGYUtils.java index 527f321..76b9546 100644 --- a/app/src/main/java/com/fuying/sn/utils/JGYUtils.java +++ b/app/src/main/java/com/fuying/sn/utils/JGYUtils.java @@ -442,6 +442,7 @@ public class JGYUtils { } public void killPackage(String pkg) { + Log.e(TAG, "killPackage: " + pkg); ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); manager.killBackgroundProcesses(pkg); CmdUtil.execute("am force-stop " + pkg); @@ -611,28 +612,29 @@ public class JGYUtils { } } - public void killBackgroundProcesses(String processName) { -// gotoLauncher(); - // mIsScanning = true; - removeTask(processName); - ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); - String packageName = null; - try { - if (processName.indexOf(":") == -1) { - packageName = processName; - } else { - packageName = processName.split(":")[0]; - } - activityManager.killBackgroundProcesses(packageName); - // - Method forceStopPackage = activityManager.getClass() - .getDeclaredMethod("forceStopPackage", String.class); - forceStopPackage.setAccessible(true); - forceStopPackage.invoke(activityManager, packageName); - } catch (Exception e) { - e.printStackTrace(); - } - } +// public void killBackgroundProcesses(String processName) { +//// gotoLauncher(); +// // mIsScanning = true; +// removeTask(processName); +// ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); +// String packageName = null; +// try { +// if (processName.indexOf(":") == -1) { +// packageName = processName; +// } else { +// packageName = processName.split(":")[0]; +// } +// activityManager.killBackgroundProcesses(packageName); +// // +// Method forceStopPackage = activityManager.getClass() +// .getDeclaredMethod("forceStopPackage", String.class); +// forceStopPackage.setAccessible(true); +// forceStopPackage.invoke(activityManager, packageName); +// Log.e(TAG, "killBackgroundProcesses: " + packageName); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } /** * 清除所有最近记录 diff --git a/app/tpns-configs.json b/app/tpns-configs.json new file mode 100644 index 0000000..81f3138 --- /dev/null +++ b/app/tpns-configs.json @@ -0,0 +1,14 @@ +{ + "tpns": { + "access_id": "1500031216", + "access_key": "A1HBG2922B9Z" + }, + "com.fuying.sn": { + "channel": { + "enable": true + } + }, + "debug": false, + "version": "1.4.3.4", + "upgrade": false +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index ae67568..b4ed19d 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,8 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.6.4' + classpath "com.tencent.android.tpns:tpnsplugin:1.8.0" + // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }