diff --git a/app/build.gradle b/app/build.gradle index e3b2b06..4488782 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,9 +41,28 @@ android { //新平台正式 newly { flavorDimensions "default" - versionCode 520 + versionCode 623 //versionCode 1037 - versionName "2.2.0" + versionName "2.2.3" + /*********************************极光推送************************************/ + manifestPlaceholders = [ + JPUSH_PKGNAME: "com.jiaoguanyi.appstore", + JPUSH_APPKEY : "20f70bbeb78bad23eddd08d0", //JPush上注册的包名对应的appkey. + JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可. + channel_value: "newly" , +// AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05" + ] + /*********************************极光推送end************************************/ + buildConfigField "String", "ROOT_URL", '"http://name.jiaoguanyi.cn/api/"' + buildConfigField "String", "WebsocketURL", '"ws://47.119.147.245:2345"' + buildConfigField "String", "SCREEN_URL", '"https://name.jiaoguanyi.cn:2018/wm/is_online"' + } + + MTKnewly { + flavorDimensions "default" + versionCode 717 + //versionCode 1037 + versionName "2.1.7" /*********************************极光推送************************************/ manifestPlaceholders = [ JPUSH_PKGNAME: "com.jiaoguanyi.appstore", @@ -61,8 +80,10 @@ android { //新平台测试 beta { flavorDimensions "default" - versionCode 530 - versionName "2.2.0" + versionCode 2 + versionName "1.1" +// versionCode 633 +// versionName "2.2.3" /*********************************极光推送************************************/ manifestPlaceholders = [ JPUSH_PKGNAME: "com.jiaoguanyi.appstore", @@ -166,10 +187,17 @@ android { if (variant.buildType.name.endsWith('zhanRuiRelease')) { variant.setIgnore(variant.getFlavors().get(0).name.equals('official')||variant.getFlavors().get(0).name.equals('zhongyou')) } - if (variant.buildType.name.endsWith('zhanRuiDebug')) { variant.setIgnore(variant.getFlavors().get(0).name.equals('official')||variant.getFlavors().get(0).name.equals('zhongyou')) } + if (name.contains("MTKnewly")){ + variant.setIgnore(variant.buildType.name.endsWith("zhanRuiRelease")||variant.buildType.name.endsWith("zhanRuiDebug")||variant.buildType.name.endsWith("zhanRuiUserdebug") + ||variant.buildType.name.endsWith("zhanRuiUserdebugReleas")) + } + if (name.endsWith("newlyDebug")||name.endsWith("newlyRelease")){ + variant.setIgnore(!name.contains("MTK")) + } + // // Icon recents is Go only // if (name.contains("WithQuickstepIconRecents") && !name.contains("l3go")) { // variant.setIgnore(true) @@ -209,6 +237,16 @@ android { signingConfig signingConfigs.zhanRuiUserdebug } + zhanRuiUserdebugReleas.initWith(release) + zhanRuiUserdebugReleas { + manifestPlaceholders = [ + AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05" + ] + buildConfigField "String", "platform", '"ZhanRui"' + debuggable true + signingConfig signingConfigs.zhanRuiUserdebug + } + debug { buildConfigField "String", "platform", '"MTK"' manifestPlaceholders = [ @@ -265,36 +303,47 @@ dependencies { //implementation fileTree(include: ['*.jar'], dir: 'libs') compileOnly files('src/main/libs/classes.jar') - implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' - testImplementation 'junit:junit:4.13.1' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation 'com.jakewharton:butterknife:10.1.0' annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0' implementation 'uk.co.chrisjenx:calligraphy:2.3.0' implementation "org.java-websocket:Java-WebSocket:1.4.1" - implementation 'com.squareup.okhttp3:okhttp:4.6.0' + implementation 'com.squareup.okhttp3:okhttp:4.9.1' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' - implementation 'io.reactivex.rxjava2:rxjava:2.2.5' - implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' + implementation 'io.reactivex.rxjava2:rxjava:2.2.8' + implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' //implementation "com.uber.autodispose:autodispose:1.3.0" //implementation "com.uber.autodispose:autodispose-android-archcomponents:1.3.0" - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.8.7' implementation 'com.google.zxing:core:3.3.0' implementation 'cn.jiguang.sdk:jpush:3.8.6' // 此处以JPush 3.5.6 版本为例。 implementation 'cn.jiguang.sdk:jcore:2.6.0' // 此处以JCore 2.2.8 版本为例。 - implementation 'com.alibaba:fastjson:1.2.70' + implementation 'com.alibaba:fastjson:1.2.76' + //逐渐弃用,几年没更新了 implementation 'com.lzy.net:okgo:2.1.4' implementation 'com.lzy.net:okrx:0.1.2' //implementation 'com.lzy.net:okserver:1.1.3' - implementation 'com.blankj:utilcode:1.23.7' + //okhttp框架 + implementation 'com.github.liujingxing.rxhttp:rxhttp:2.6.5' + //implementation 'com.squareup.okhttp3:okhttp:4.9.1' //rxhttp v2.2.2版本起,需要手动依赖okhttp + annotationProcessor 'com.github.liujingxing.rxhttp:rxhttp-compiler:2.6.5' //生成RxHttp类,纯Java项目,请使用annotationProcessor代替kapt + implementation 'com.github.liujingxing.rxlife:rxlife-coroutine:2.1.0' //管理协程生命周期,页面销毁,关闭请求 + //rxjava2 (RxJava2/Rxjava3二选一,使用asXxx方法时必须) + //implementation 'io.reactivex.rxjava2:rxjava:2.2.8' + //implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' + implementation 'com.github.liujingxing.rxlife:rxlife-rxjava2:2.1.0' //管理RxJava2生命周期,页面销毁,关闭请求 + + implementation 'com.blankj:utilcodex:1.30.6' implementation 'com.arialyy.aria:core:3.8.15' annotationProcessor 'com.arialyy.aria:compiler:3.8.15' //高德地图定位 @@ -321,5 +370,6 @@ preBuild { } } //https://www.pianshen.com/article/93481144911/ + //https://blog.csdn.net/dhl_1986/article/details/102856026 //使用系统编译后的framework.jar } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ddcfd4f..88dda0f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -95,8 +95,8 @@ + android:exported="true" + android:process=":remote" /> dialog.dismiss()); - builder.show(); + AlertDialog dialog = builder.create(); //创建AlertDialog对象 + if (!this.isFinishing() && !dialog.isShowing()) { + dialog.show(); + } } //执行所有接口耗时 @@ -161,9 +168,10 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { @Override public void initData() { + JPushInterface.init(this); registerMessageReceiver(); - Logutils.e("getMacAddress", Utils.getAndroid7MAC()); - timeMillis = System.currentTimeMillis(); + Logutils.e("getMacAddress", Utils.getAndroid10MAC(this)); + timeMillis = SystemClock.elapsedRealtime(); mPresenter.getLockedState(); } @@ -201,6 +209,10 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { */ @Override public void setLockedState(boolean loocked) { + //发送设备mac地址和信息 + mPresenter.sendMACAddress(); + //设置极光推送别名 + mPresenter.setJpushAlias(); if (loocked) { iv_locked.setVisibility(View.VISIBLE); iv_locked.setImageDrawable(getDrawable(R.drawable.locked)); @@ -210,13 +222,9 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { //如果正在执行,不执行 return; } - //发送设备mac地址和信息 - mPresenter.sendMACAddress(); - //设置极光推送别名 - mPresenter.setJpushAlias(); SaveListUtils.getList(); //获取系统管控 - mPresenter.getSystemSettingbegin(); + mPresenter.setJpushTags(); netWorkIsRunning = true; } else { iv_locked.setVisibility(View.VISIBLE); @@ -263,12 +271,6 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { @Override public void setAliasFinished() { - //设置极光推送tag - mPresenter.setJpushTags(); - } - - @Override - public void setTagsFinished() { mPresenter.checkStoreUpdate(); } @@ -277,16 +279,19 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { } - @Override public void checkStoreUpdateFinished() { + mPresenter.checkInfoUpdate(); + } + + @Override + public void checkInfoUpdateFinished() { mPresenter.checkTestUpdate(); } - @Override public void checkTestUpdateFinished() { - mPresenter.getDefaultDesktop(); + } @Override @@ -301,6 +306,21 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { } } + /** + * @param noTag 为空,没有,错误都返回true + * 设备可以没有批次,但是没有批次相当于没有数据了,就不执行下面的请求了 + */ + @Override + public void setTagsFinished(boolean noTag) { + if (noTag) { + Log.e(TAG, "setTagsFinished: " + "not set tag"); + netWorkIsRunning = false; + Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - timeMillis) + " ms"); + } else { + mPresenter.getSystemSettingbegin(); + } + } + private void showDialog(JsonObject jsonObject) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("更新:"); @@ -378,6 +398,11 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { @Override public void setSystemSettingFinished() { + mPresenter.getDefaultApp(); + } + + @Override + public void setDefaultAppFinished() { mPresenter.getROMApp(); } @@ -398,17 +423,17 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { @Override public void setTopAppFinished() { - netWorkIsRunning = false; - Logutils.e(TAG, "SettingFinished: " + (System.currentTimeMillis() - timeMillis) + " ms"); - } - - @Override - public void setScreenLockStateFinished(boolean locked, String tips) { - + mPresenter.getDefaultDesktop(); } @Override public void getDefaultDesktopFinished() { + netWorkIsRunning = false; + Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - timeMillis) + " ms"); + } + + @Override + public void setScreenLockStateFinished(boolean locked, String tips) { } @@ -434,6 +459,7 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { protected void onDestroy() { super.onDestroy(); mPresenter.detachView(); + startService(new Intent(MainActivity.this, MainService.class)); } @Override @@ -523,6 +549,19 @@ public class MainActivity extends BaseActivity implements MainContact.MainView { LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter); } + @Override + public void onDisconnected() { + Log.e("OnNetworkStatusChangedListener", "onDisconnected: "); + } + + @Override + public void onConnected(NetworkUtils.NetworkType networkType) { + Log.e("OnNetworkStatusChangedListener", "onConnected: "); + timeMillis = SystemClock.elapsedRealtime(); + //直接获取数据 + mPresenter.getLockedState(); + } + public static class MessageReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/java/com/mjsheng/myappstore/activity/MainContact.java b/app/src/main/java/com/mjsheng/myappstore/activity/MainContact.java index 198f596..207b15e 100644 --- a/app/src/main/java/com/mjsheng/myappstore/activity/MainContact.java +++ b/app/src/main/java/com/mjsheng/myappstore/activity/MainContact.java @@ -8,6 +8,83 @@ import com.mjsheng.myappstore.base.BasePresenter; import com.mjsheng.myappstore.base.BaseView; public class MainContact { + public interface Presenter extends BasePresenter { + //设置二维码 + void getQRImage(String mac); + //获取学生信息 + void getStudesInfo(); + //获取设备锁定状态 + void getLockedState(); + //是否第一次联网 + void getFirstConnect(); + //关闭所有功能 + void setDisableSetting(); + //发送mac地址 + void sendMACAddress(); + //更新设备信息 + void updateDeviceInfo(); + //获取时间管控 + void getSnTimeControl(); + //获取电子书包激活码 + void getEBagCode(); + //设置击关推送别名 + void setJpushAlias(); + //设置极光推送平台标签 + void setJpushPlatformTags(int platform); + //获取应用市场更新 + void checkStoreUpdate(); + //获取设备信息更新 + void checkInfoUpdate(); + //手动获取设备信息更新 + void buttonCheckUpdate(View view); + //获取测试应用更新 + void checkTestUpdate(); + //开始 + //设置极光推送标签 + void setJpushTags(); + //获取设备后台设置 + void getSystemSettingbegin(); + //获取可被写入的安装包名 + void getAppLimit(); + //获取设备批次 + void getDeviceBatch(String packageList); + //获取强制下载apk + void getForceDownload(); + //获取浏览器上网管控设置 + void getBrowserList(); + //获取浏览器书签设置管控 + void getBrowserBookmarks(String whitelist); + //设置白名单的url + void getBrowserWhiteList(); + //获取应用图标桌面可见性管控 + void getDesktopIcon(); + //获取应用自启升级和网络权限管理 + void getAppAutoStartUpdateAndNet(); + //获取第三方应用子页面ID连网限制 + void getAppIDControl(); + //获取第三方应用内部网页跳转屏蔽 + void setAppinsideWeb(); + //获取系统其他管控设置 + void setSystemSetting(); + //获取系统默认程序设置 + void getDefaultApp(); + //获取自定义版本内置app + void getROMApp(); + //获取开发者选项 + void getDeveloper(); + //设置开机动画 + void setLogoImg(); + //应用霸屏 + void setTopApp(); + //获取桌面 + void getDefaultDesktop(); + /* + * MainService + * */ + //获取屏幕锁状态 + void getScreenLockState(); + } + public interface MainView extends BaseView { //获取二维码 void setQRImage(Bitmap qrImage); @@ -33,17 +110,19 @@ public class MainContact { void getEBagCodeFinished(); //设置击关推送别名 void setAliasFinished(); - //设置极光推送标签 - void setTagsFinished(); //设置极光推送平台标签 void setJpushPlatformTagsFinished(); //获取应用市场更新 void checkStoreUpdateFinished(); + //获取设备信息更新 + void checkInfoUpdateFinished(); //获取测试应用更新 void checkTestUpdateFinished(); //手动获取设备信息更新 void buttonCheckUpdateFinished(boolean update, JsonObject jsonObject); //开始 + //设置极光推送标签 + void setTagsFinished(boolean noTag); //设置设备后台设置 void getSystemSettingbegin(); //获取可被写入的安装包名结束 @@ -66,6 +145,8 @@ public class MainContact { void setAppinsideWebFinished(); //获取系统其他管控设置结束 void setSystemSettingFinished(); + //获取系统默认程序设置 + void setDefaultAppFinished(); //获取自定义版本内置app void getROMAppFinished(); //获取开发者选项结束 @@ -74,85 +155,12 @@ public class MainContact { void setLogoImgFinished (); //获取应用霸屏结束 void setTopAppFinished(); + //获取桌面结束 + void getDefaultDesktopFinished(); /* * MainService * */ //设置屏幕锁状态结束 void setScreenLockStateFinished(boolean locked, String tips); - //获取桌面结束 - void getDefaultDesktopFinished(); - } - - public interface Presenter extends BasePresenter { - //设置二维码 - void getQRImage(String mac); - //获取学生信息 - void getStudesInfo(); - //获取设备锁定状态 - void getLockedState(); - //是否第一次联网 - void getFirstConnect(); - //关闭所有功能 - void setDisableSetting(); - //发送mac地址 - void sendMACAddress(); - //更新设备信息 - void updateDeviceInfo(); - //获取时间管控 - void getSnTimeControl(); - //获取电子书包激活码 - void getEBagCode(); - //设置击关推送别名 - void setJpushAlias(); - //设置极光推送标签 - void setJpushTags(); - //设置极光推送平台标签 - void setJpushPlatformTags(int platform); - //获取应用更新 - void checkStoreUpdate(); - //手动获取设备信息更新 - void buttonCheckUpdate(View view); - //获取测试应用更新 - void checkTestUpdate(); - //开始 - //获取设备后台设置 - void getSystemSettingbegin(); - //获取可被写入的安装包名 - void getAppLimit(); - //获取设备批次 - void getDeviceBatch(String packageList); - //获取强制下载apk - void getForceDownload(); - //获取浏览器上网管控设置 - void getBrowserList(); - //获取浏览器书签设置管控 - void getBrowserBookmarks(String whitelist); - //设置白名单的url - void getBrowserWhiteList(); - //获取应用图标桌面可见性管控 - void getDesktopIcon(); - //获取应用自启升级和网络权限管理 - void getAppAutoStartUpdateAndNet(); - //获取第三方应用子页面ID连网限制 - void getAppIDControl(); - //获取第三方应用内部网页跳转屏蔽 - void setAppinsideWeb(); - //获取系统其他管控设置 - void setSystemSetting(); - //获取自定义版本内置app - void getROMApp(); - //获取开发者选项 - void getDeveloper(); - //设置开机动画 - void setLogoImg(); - //应用霸屏 - void setTopApp(); - /* - * MainService - * */ - //获取屏幕锁状态 - void getScreenLockState(); - //获取桌面 - void getDefaultDesktop(); } } diff --git a/app/src/main/java/com/mjsheng/myappstore/activity/MainPresenter.java b/app/src/main/java/com/mjsheng/myappstore/activity/MainPresenter.java index 1eb335c..f05dfed 100644 --- a/app/src/main/java/com/mjsheng/myappstore/activity/MainPresenter.java +++ b/app/src/main/java/com/mjsheng/myappstore/activity/MainPresenter.java @@ -7,6 +7,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.provider.Settings; import android.text.TextUtils; +import android.util.Log; import android.view.View; import com.alibaba.fastjson.JSON; @@ -21,6 +22,7 @@ import com.mjsheng.myappstore.BuildConfig; import com.mjsheng.myappstore.base.BaseApplication; import com.mjsheng.myappstore.bean.BaseResponse; import com.mjsheng.myappstore.bean.BrowserData; +import com.mjsheng.myappstore.bean.DefaultApp; import com.mjsheng.myappstore.bean.ForceDownloadBean; import com.mjsheng.myappstore.bean.ForceDownloadData; import com.mjsheng.myappstore.bean.LogoImg; @@ -38,6 +40,7 @@ import com.mjsheng.myappstore.utils.Logutils; import com.mjsheng.myappstore.utils.SPUtils; import com.mjsheng.myappstore.utils.SysSettingUtils; import com.mjsheng.myappstore.utils.TimeUtils; +import com.mjsheng.myappstore.utils.ToastUtil; import com.mjsheng.myappstore.utils.URLUtils; import com.mjsheng.myappstore.utils.Utils; @@ -277,11 +280,13 @@ public class MainPresenter implements MainContact.Presenter { @Override public void getFirstConnect() { int first = (int) SPUtils.get(mContext, "first_connect", 0); + Log.e(TAG, "getFirstConnect: " + "first_connect = " + first); mView.setFirstConnect(first == 0); } @Override public void setDisableSetting() { + Log.e(TAG, "setDisableSetting: "); //设置系统管控 SysSettingUtils.setDisableSetting(mContext); } @@ -363,10 +368,10 @@ public class MainPresenter implements MainContact.Presenter { @Override public void onNext(@NonNull ResponseBody responseBody) { try { - Logutils.e(TAG + ":" + "updateDevicesInfo", "onSubscribe: " + responseBody.string()); + Logutils.e(TAG + ":" + "updateDevicesInfo", "onNext: " + responseBody.string()); } catch (IOException e) { e.printStackTrace(); - Logutils.e(TAG + ":" + "updateDevicesInfo", "onSubscribe: IOException: " + e.getMessage()); + Logutils.e(TAG + ":" + "updateDevicesInfo", "onNext: IOException: " + e.getMessage()); } } @@ -510,6 +515,7 @@ public class MainPresenter implements MainContact.Presenter { String batch = jsonObject.get("batch").getAsString(); Logutils.e(TAG + ":" + "setJpushTags", "onNext: " + batch); if (!TextUtils.isEmpty(batch)) { + mView.setTagsFinished(false); Set set = new HashSet(); set.add(batch); JGYUtils.getInstance().getAppPlatform(new JGYUtils.GetAppPlatformCallback() { @@ -524,9 +530,11 @@ public class MainPresenter implements MainContact.Presenter { }); setTag(set); } else { + mView.setTagsFinished(true); Logutils.e(TAG + ":" + "setJpushTags", "onNext: " + "batch empty"); } } else { + mView.setTagsFinished(true); Logutils.e(TAG + ":" + "setJpushTags", "onNext: " + response.toString()); } } @@ -534,13 +542,13 @@ public class MainPresenter implements MainContact.Presenter { @Override public void onError(@NonNull Throwable e) { Logutils.e(TAG + ":" + "setJpushTags", "onError: " + e.getMessage()); + mView.setTagsFinished(true); onComplete(); } @Override public void onComplete() { Logutils.e(TAG + ":" + "setJpushTags", "onComplete: "); - mView.setTagsFinished(); } }); } @@ -564,7 +572,6 @@ public class MainPresenter implements MainContact.Presenter { checkUpdateStore(); } - private void checkUpdateStore() { NetInterfaceManager.getInstance() .getUpdateApi() @@ -605,6 +612,45 @@ public class MainPresenter implements MainContact.Presenter { }); } + @Override + public void checkInfoUpdate() { + NetInterfaceManager.getInstance() + .getUpdateApi() + .getUpdate(BuildConfig.APPLICATION_ID, + JGYUtils.getInstance().checkAppPlatform()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NonNull Disposable d) { + Log.e("checkInfoUpdate", "onSubscribe: "); + } + + @Override + public void onNext(@NonNull BaseResponse response) { + Log.e("checkInfoUpdate", "onNext: " + response.data); + if (response.code == OK) { + JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject(); + JGYUtils.getInstance().installAPK(jsonObject); + } else { + Log.e("checkInfoUpdate", "onNext: " + response); + } + } + + @Override + public void onError(@NonNull Throwable e) { + Log.e("checkInfoUpdate", "onError: " + e.getMessage()); + onComplete(); + } + + @Override + public void onComplete() { + Log.e("checkInfoUpdate", "onComplete: "); + mView.checkInfoUpdateFinished(); + } + }); + } + long buttonCheckUpdateTime = 0; @Override @@ -667,16 +713,11 @@ public class MainPresenter implements MainContact.Presenter { }); } - /** * 获取灰度测试更新 */ @Override public void checkTestUpdate() { - if (JGYUtils.isOfficialVersion()) { - mView.checkTestUpdateFinished(); - return; - } NetInterfaceManager.getInstance() .getTestUpdateObservable() .subscribe(new Observer>>() { @@ -687,6 +728,7 @@ public class MainPresenter implements MainContact.Presenter { @Override public void onNext(BaseResponse> listBaseResponse) { + Logutils.e(TAG + ":" + "checkTestUpdate", "onNext: " + listBaseResponse.data); if (listBaseResponse.code == OK) { List APPlist = listBaseResponse.data; JGYUtils.getInstance().installTestAPK(APPlist); @@ -715,6 +757,7 @@ public class MainPresenter implements MainContact.Presenter { //重置设备 JGYUtils.getInstance().resetDevice(); mView.getSystemSettingbegin(); + ToastUtil.betaShow("开始获取管控"); } @Override @@ -743,10 +786,13 @@ public class MainPresenter implements MainContact.Presenter { mView.getAppLimitFinished(data); } else { // mView.getAppLimitFinished(""); - boolean write = Settings.System.putString(mContext.getContentResolver(), "only_jgy_shortcut_list", ""); + boolean write = Settings.System.putString(mContext.getContentResolver(), "only_jgy_shortcut_list", " "); Logutils.e(TAG, "onNext: only_jgy_shortcut_list: " + write); Logutils.e(TAG + ":" + "getAppLimit", "onNext: " + bodyString); mView.getAppLimitFinished(""); +// String oldListString = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid"); +// Log.e("getAppLimit", "oldListString: " + oldListString); +// mView.getAppLimitFinished(oldListString); } } catch (IOException e) { e.printStackTrace(); @@ -757,7 +803,7 @@ public class MainPresenter implements MainContact.Presenter { @Override public void onError(@NonNull Throwable e) { Logutils.e(TAG + ":" + "getAppLimit", "onError: " + e.getMessage()); - String oldListString = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid"); + String oldListString = Settings.System.getString(mContext.getContentResolver(), "only_jgy_shortcut_list"); Logutils.e(TAG + ":" + "getAppLimit", "oldListString: " + oldListString); mView.getAppLimitFinished(oldListString); } @@ -771,10 +817,10 @@ public class MainPresenter implements MainContact.Presenter { @Override public void getDeviceBatch(String packageList) { - if (JGYUtils.isOfficialVersion() || TextUtils.isEmpty(packageList)) { - mView.getDeviceBatchFinished(); - return; - } +// if (JGYUtils.isOfficialVersion() || TextUtils.isEmpty(packageList)) { +// mView.getDeviceBatchFinished(); +// return; +// } int locked = Settings.System.getInt(mContext.getContentResolver(), "qch_unlock_ipad", 0); Logutils.e(TAG, "getDeviceBatch: " + locked); if (locked == 0) { @@ -825,7 +871,6 @@ public class MainPresenter implements MainContact.Presenter { // } // }); // mView.getDeviceBatchFinished(); - } } @@ -843,7 +888,7 @@ public class MainPresenter implements MainContact.Presenter { public void onNext(@NonNull ForceDownloadBean forceDownloadBean) { Logutils.e(TAG + ":" + "getForceDownload", "onNext: "); switch (forceDownloadBean.getCode()) { - case 200: + case OK: Logutils.e(TAG + ":" + "getForceDownload", "isDownloading=" + BaseApplication.getInstance().isDownloading()); BaseApplication.getInstance().checkIsDownloading(); if (!BaseApplication.getInstance().isDownloading()) { @@ -893,62 +938,64 @@ public class MainPresenter implements MainContact.Presenter { @Override public void getBrowserList() { - NetInterfaceManager.getInstance() - .getBrowserListSettingObservable() - .observeOn(Schedulers.io()) - .subscribe(new Observer>() { - @Override - public void onSubscribe(@NonNull Disposable d) { - Logutils.e(TAG + ":" + "getBrowserList", "onSubscribe: "); - } - - @Override - public void onNext(@NonNull BaseResponse browserDataBaseResponse) { - Logutils.e(TAG + ":" + "getBrowserList", "onNext: "); - if (browserDataBaseResponse.code == 200) { - String white = browserDataBaseResponse.data.getWhite(); - - if (!TextUtils.isEmpty(white)) { - String homePage = Settings.System.getString(mContext.getContentResolver(), "homepagURL"); - if (!TextUtils.isEmpty(homePage) && !white.contains(homePage)) { - white += "," + homePage; - } - boolean whiteList = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", white); - Logutils.e(TAG + ":" + "getBrowserList", "setBrowserList white: " + white + ":" + whiteList); - mView.getBrowserListFinished(white); - } else { - Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", " "); - mView.getBrowserListFinished(""); - } - String black = browserDataBaseResponse.data.getBlack(); - if (!TextUtils.isEmpty(black)) { - boolean blackList = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", black); - Logutils.e(TAG + ":" + "getBrowserList", "setBrowserList black: " + black + ":" + blackList); - } else { - Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", " "); - } - } else { - mView.getBrowserListFinished(""); - } - } - - @Override - public void onError(@NonNull Throwable e) { - Logutils.e(TAG + ":" + "getBrowserList", "onError: " + e.getMessage()); - String whiteURLList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray"); - Logutils.e(TAG + ":" + "getBrowserList", "whiteURLList: " + whiteURLList); - mView.getBrowserListFinished(whiteURLList); - onComplete(); - } - - @Override - public void onComplete() { - Logutils.e(TAG + ":" + "getBrowserList", "onComplete: "); - } - }); +// NetInterfaceManager.getInstance() +// .getBrowserListSettingObservable() +// .observeOn(Schedulers.io()) +// .subscribe(new Observer>() { +// @Override +// public void onSubscribe(@NonNull Disposable d) { +// Logutils.e(TAG + ":" + "getBrowserList", "onSubscribe: "); +// } +// +// @Override +// public void onNext(@NonNull BaseResponse browserDataBaseResponse) { +// Logutils.e(TAG + ":" + "getBrowserList", "onNext: "); +// if (browserDataBaseResponse.code == OK) { +// String white = browserDataBaseResponse.data.getWhite(); +// +// if (!TextUtils.isEmpty(white)) { +// String homePage = Settings.System.getString(mContext.getContentResolver(), "homepagURL"); +// if (!TextUtils.isEmpty(homePage) && !white.contains(homePage)) { +// white += "," + homePage; +// } +// boolean whiteList = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", white); +// Logutils.e(TAG + ":" + "getBrowserList", "setBrowserList white: " + white + ":" + whiteList); +// mView.getBrowserListFinished(white); +// } else { +// Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", " "); +// mView.getBrowserListFinished(""); +// } +// String black = browserDataBaseResponse.data.getBlack(); +// if (!TextUtils.isEmpty(black)) { +// boolean blackList = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", black); +// Logutils.e(TAG + ":" + "getBrowserList", "setBrowserList black: " + black + ":" + blackList); +// } else { +// Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", " "); +// } +// } else { +// mView.getBrowserListFinished(""); +// } +// } +// +// @Override +// public void onError(@NonNull Throwable e) { +// Logutils.e(TAG + ":" + "getBrowserList", "onError: " + e.getMessage()); +// String whiteURLList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray"); +// Logutils.e(TAG + ":" + "getBrowserList", "whiteURLList: " + whiteURLList); +// mView.getBrowserListFinished(whiteURLList); +// onComplete(); +// } +// +// @Override +// public void onComplete() { +// Logutils.e(TAG + ":" + "getBrowserList", "onComplete: "); +// } +// }); + //获取书签后会获取黑白名单 + Log.e(TAG, "getBrowserList: "); + mView.getBrowserListFinished(""); } - private void NewSetBrowserList() { NetInterfaceManager.getInstance() .getBrowserListSettingObservable() @@ -1290,7 +1337,7 @@ public class MainPresenter implements MainContact.Presenter { @Override public void onComplete() { - Logutils.e(TAG + ":" + "getAppAutoStart", "onSubscribe: "); + Logutils.e(TAG + ":" + "getAppAutoStart", "onComplete: "); mView.getAppAutoStartUpdateAndNetFinished(); } }); @@ -1350,9 +1397,11 @@ public class MainPresenter implements MainContact.Presenter { @Override public void setAppinsideWeb() { + Log.e(TAG, "setAppinsideWeb: "); HTTPInterface.getAppinsideWeb(mContext, new HTTPInterface.GetAppinsideWebCallback() { @Override - public void ononComplete() { + public void onComplete() { + Log.e(TAG, "setAppinsideWeb: " + "onComplete"); mView.setAppinsideWebFinished(); } }); @@ -1381,12 +1430,12 @@ public class MainPresenter implements MainContact.Presenter { if (code == OK) { String data = jsonObject.getAsJsonObject("data").toString(); //结果保存到本地 - SPUtils.put(mContext, "SystemSettingData", data); JGYUtils.getInstance().SettingSysData(data); } else { //没有数据全部关闭 - SysSettingUtils.setDisableSetting(mContext); - SPUtils.put(mContext, "SystemSettingData", ""); +// SysSettingUtils.setDisableSetting(mContext); +// SPUtils.put(mContext, "SystemSettingData", ""); + JGYUtils.getInstance().SettingSysData(""); //获取系统管控先不要关闭开发人员选项 if (!BuildConfig.DEBUG) { Settings.System.putInt(mContext.getContentResolver(), "qch_Developeroptions", 1); @@ -1416,6 +1465,42 @@ public class MainPresenter implements MainContact.Presenter { } + @Override + public void getDefaultApp() { + NetInterfaceManager.getInstance() + .getDefaultAppApi() + .subscribe(new Observer>() { + @Override + public void onSubscribe(Disposable d) { + Log.e("getDefaultApp", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse defaultAppBaseResponse) { + Log.e("getDefaultApp", "onNext: " + JSONObject.toJSONString(defaultAppBaseResponse.data)); + int code = defaultAppBaseResponse.code; + if (code == OK) { + DefaultApp defaultApp = defaultAppBaseResponse.data; + JGYUtils.getInstance().setDefaultDesktop(defaultApp.getDefault_launcher()); + } else { + Log.e("getDefaultApp", "onNext: " + defaultAppBaseResponse.msg); + } + } + + @Override + public void onError(Throwable e) { + Log.e("getDefaultApp", "onError: " + e.getMessage()); + onComplete(); + } + + @Override + public void onComplete() { + Log.e("getDefaultApp", "onComplete: "); + mView.setDefaultAppFinished(); + } + }); + } + @Override public void getROMApp() { String customVersion = Utils.getCustomVersion(); @@ -1439,7 +1524,7 @@ public class MainPresenter implements MainContact.Presenter { Settings.System.putString(mContext.getContentResolver(), "jgy_customromapp", packageName); } else { Logutils.e(TAG + ":" + "getROMApp", "onNext: " + baseResponse.msg); - Settings.System.putString(mContext.getContentResolver(), "jgy_customromapp", ""); + Settings.System.putString(mContext.getContentResolver(), "jgy_customromapp", " "); // onComplete(); } } @@ -1583,12 +1668,13 @@ public class MainPresenter implements MainContact.Presenter { public void onComplete() { Logutils.e(TAG + ":" + "setTopApp", "onComplete: "); mView.setTopAppFinished(); + ToastUtil.betaShow("获取管控结束"); } }); } @Override - public void getScreenLockState() { + synchronized public void getScreenLockState() { int locked = Settings.System.getInt(mContext.getContentResolver(), "qch_unlock_ipad", 0); if (JGYUtils.isOfficialVersion() || locked == 1) { mView.setScreenLockStateFinished(false, ""); @@ -1680,6 +1766,4 @@ public class MainPresenter implements MainContact.Presenter { } }); } - - } diff --git a/app/src/main/java/com/mjsheng/myappstore/bean/DefaultApp.java b/app/src/main/java/com/mjsheng/myappstore/bean/DefaultApp.java new file mode 100644 index 0000000..cc22f56 --- /dev/null +++ b/app/src/main/java/com/mjsheng/myappstore/bean/DefaultApp.java @@ -0,0 +1,73 @@ +package com.mjsheng.myappstore.bean; + +import java.io.Serializable; + +/** + * @author jgy02 + */ +public class DefaultApp implements Serializable { + + String default_launcher; + String default_browser; + String default_videoplayer; + String default_musiclayer; + String default_filemanager; + String default_gallery; + String default_IME; + + public String getDefault_launcher() { + return default_launcher; + } + + public void setDefault_launcher(String default_launcher) { + this.default_launcher = default_launcher; + } + + public String getDefault_browser() { + return default_browser; + } + + public void setDefault_browser(String default_browser) { + this.default_browser = default_browser; + } + + public String getDefault_videoplayer() { + return default_videoplayer; + } + + public void setDefault_videoplayer(String default_videoplayer) { + this.default_videoplayer = default_videoplayer; + } + + public String getDefault_musiclayer() { + return default_musiclayer; + } + + public void setDefault_musiclayer(String default_musiclayer) { + this.default_musiclayer = default_musiclayer; + } + + public String getDefault_filemanager() { + return default_filemanager; + } + + public void setDefault_filemanager(String default_filemanager) { + this.default_filemanager = default_filemanager; + } + + public String getDefault_gallery() { + return default_gallery; + } + + public void setDefault_gallery(String default_gallery) { + this.default_gallery = default_gallery; + } + + public String getDefault_IME() { + return default_IME; + } + + public void setDefault_IME(String default_IME) { + this.default_IME = default_IME; + } +} diff --git a/app/src/main/java/com/mjsheng/myappstore/jpush/TagAliasOperatorHelper.java b/app/src/main/java/com/mjsheng/myappstore/jpush/TagAliasOperatorHelper.java index 332b5a1..e7b0d8c 100644 --- a/app/src/main/java/com/mjsheng/myappstore/jpush/TagAliasOperatorHelper.java +++ b/app/src/main/java/com/mjsheng/myappstore/jpush/TagAliasOperatorHelper.java @@ -7,6 +7,7 @@ import android.util.Log; import android.util.SparseArray; import com.mjsheng.myappstore.utils.Logutils; +import com.mjsheng.myappstore.utils.ToastUtil; import java.util.Locale; import java.util.Set; @@ -243,6 +244,7 @@ public class TagAliasOperatorHelper { String logs = getActionStr(tagAliasBean.action)+" tags success"; Logger.i(TAG,logs); Logutils.e(TAG,"Tag绑定成功: " + jPushMessage.getTags()); + ToastUtil.betaShow("Tag绑定成功: " + jPushMessage.getTags()); ExampleUtil.showToast(logs, context); }else{ String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags"; @@ -297,6 +299,7 @@ public class TagAliasOperatorHelper { String logs = getActionStr(tagAliasBean.action)+" alias success"; Logger.i(TAG,logs); Log.e(TAG,"Alias绑定成功: "+jPushMessage.getAlias()); + ToastUtil.betaShow("Alias绑定成功: "+jPushMessage.getAlias()); ExampleUtil.showToast(logs, context); }else{ String logs = "Failed to " + getActionStr(tagAliasBean.action)+" alias, errorCode:" + jPushMessage.getErrorCode(); diff --git a/app/src/main/java/com/mjsheng/myappstore/manager/AmapManager.java b/app/src/main/java/com/mjsheng/myappstore/manager/AmapManager.java index 50441a3..0ec9b0b 100644 --- a/app/src/main/java/com/mjsheng/myappstore/manager/AmapManager.java +++ b/app/src/main/java/com/mjsheng/myappstore/manager/AmapManager.java @@ -86,6 +86,4 @@ public class AmapManager { locationClient.startLocation(); Logutils.e(TAG, "initAmap: " + "startLocation"); } - - } diff --git a/app/src/main/java/com/mjsheng/myappstore/manager/NetInterfaceManager.java b/app/src/main/java/com/mjsheng/myappstore/manager/NetInterfaceManager.java index bdb08d8..4a52361 100644 --- a/app/src/main/java/com/mjsheng/myappstore/manager/NetInterfaceManager.java +++ b/app/src/main/java/com/mjsheng/myappstore/manager/NetInterfaceManager.java @@ -9,6 +9,7 @@ import com.mjsheng.myappstore.bean.Appground; import com.mjsheng.myappstore.bean.BaseResponse; import com.mjsheng.myappstore.bean.BrowserBookmarks; import com.mjsheng.myappstore.bean.BrowserData; +import com.mjsheng.myappstore.bean.DefaultApp; import com.mjsheng.myappstore.bean.ForceDownloadBean; import com.mjsheng.myappstore.bean.ForceDownloadData; import com.mjsheng.myappstore.bean.LogoImg; @@ -31,6 +32,7 @@ import com.mjsheng.myappstore.network.api.newapi.BrowserListApi; import com.mjsheng.myappstore.network.api.newapi.CheckTestUpdateApi; import com.mjsheng.myappstore.network.api.newapi.CheckUpdateApi; import com.mjsheng.myappstore.network.api.newapi.CustomROMApp; +import com.mjsheng.myappstore.network.api.newapi.DefaultAppApi; import com.mjsheng.myappstore.network.api.newapi.DesktopIconApi; import com.mjsheng.myappstore.network.api.newapi.DevicesLockedStateApi; import com.mjsheng.myappstore.network.api.newapi.GetAllApp; @@ -61,6 +63,7 @@ import io.reactivex.schedulers.Schedulers; import okhttp3.Cache; import okhttp3.OkHttpClient; import okhttp3.ResponseBody; +import okhttp3.internal.Util; import retrofit2.CallAdapter; import retrofit2.Converter; import retrofit2.Retrofit; @@ -158,11 +161,12 @@ public class NetInterfaceManager { return mRetrofit .create(MACAddressApi.class) .sendMACaddress(Utils.getSerial(), - Utils.getAndroid7MAC(), + Utils.getAndroid10MAC(mContext), JPushInterface.getRegistrationID(mContext), Utils.getCustomVersion(), BuildConfig.VERSION_NAME, - Utils.getAPPVersionName(mContext) + Utils.getAPPVersionName(mContext), + Utils.getAndroid7MAC() ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); @@ -416,4 +420,11 @@ public class NetInterfaceManager { return mRetrofit.create(GetAllApp.class); } + public Observable> getDefaultAppApi() { + return mRetrofit.create(DefaultAppApi.class) + .getDefaultApp(Utils.getSerial()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + } diff --git a/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java b/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java index b5df747..a0e7576 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java @@ -10,6 +10,7 @@ import android.os.Handler; import android.os.Message; import android.provider.Settings; import android.text.TextUtils; +import android.util.Log; import com.alibaba.fastjson.JSON; @@ -48,6 +49,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -57,7 +59,6 @@ import io.reactivex.schedulers.Schedulers; import okhttp3.Call; import okhttp3.Response; import okhttp3.ResponseBody; -import okhttp3.internal.Util; import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_SET; import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.sequence; @@ -339,9 +340,11 @@ public class HTTPInterface { int versionCode = jsonObject.getInteger("app_version_code"); final String packageName = jsonObject.getString("app_package"); String app_name = jsonObject.getString("app_name"); + String app_md5 = jsonObject.getString("app_md5"); final com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject(); object.put("app_name", app_name); object.put("app_package", packageName); + object.put("MD5",app_md5); PackageManager pm = context.getPackageManager(); PackageInfo packageInfo = null; try { @@ -368,7 +371,7 @@ public class HTTPInterface { com.alibaba.fastjson.JSONObject data = jsonObject.getJSONObject("data"); if (code == 200) { String batch = data.getString("batch"); - if (batch != null && !batch.equals("")) { + if (batch != null && !"".equals(batch)) { Set set = new HashSet(); set.add(batch); TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean(); @@ -397,7 +400,7 @@ public class HTTPInterface { @Override public void onSuccess(String s, Call call, Response response) { String body = response.body().toString(); - if (body.equals("200")) { + if ("200".equals(body)) { Logutils.e("jiguangInterface", "alias清除成功"); } else { Logutils.e("jiguangInterface", "alias清除失败"); @@ -413,7 +416,7 @@ public class HTTPInterface { } public interface GetAppinsideWebCallback { - void ononComplete(); + void onComplete(); } synchronized public static void getAppinsideWeb(Context context, GetAppinsideWebCallback callback) { @@ -423,6 +426,7 @@ public class HTTPInterface { } else { Logutils.e(TAG, "getAppinsideWeb: " + "setNewAppinsideWeb"); setNewAppinsideWeb(callback); +// setAppinsideWeb(callback); } } @@ -451,7 +455,7 @@ public class HTTPInterface { @Override public void onComplete() { Logutils.e("setAppinsideWeb", "onComplete: "); - callback.ononComplete(); + callback.onComplete(); } }); } @@ -483,7 +487,7 @@ public class HTTPInterface { @Override public void onComplete() { Logutils.e("getNewAppinsideWeb", "onComplete: "); - callback.ononComplete(); + callback.onComplete(); } }); } @@ -535,11 +539,9 @@ public class HTTPInterface { white += "," + homePage; } boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white); - new URLUtils(context).setBrowserWhiteList(); - Logutils.e("setBrowserBlackList", "setBrowserList----white-----" + whiteList + ":" + white); } else { - Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " "); + Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", homePage); } String black = data.getString("black"); if (!TextUtils.isEmpty(black)) { @@ -555,7 +557,7 @@ public class HTTPInterface { } catch (JSONException e) { Logutils.e("setBrowserBlackList", "JSONException" + e.getMessage()); } - + new URLUtils(context).setBrowserWhiteList(); } @Override @@ -704,14 +706,14 @@ public class HTTPInterface { if (code == 200) { JSONObject data = JSON.parseObject(jsonObject.getString("data")); String white = data.getString("white"); - if (white != null && !white.equals("")) { + if (white != null && !"".equals(white)) { boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white); Logutils.e("SystemSetting", "OldSetBrowserList----white-----" + whiteList + ":" + white); } else { Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " "); } String black = data.getString("black"); - if (black != null && !black.equals("")) { + if (black != null && !"".equals(black)) { boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black); Logutils.e("SystemSetting", "OldSetBrowserList----black-----" + blackList + ":" + black); } else { @@ -836,23 +838,26 @@ public class HTTPInterface { .subscribe(new Observer>() { @Override public void onSubscribe(@NonNull Disposable d) { - if (callback != null) + if (callback != null) { callback.onSubscribe(); + } Logutils.e("getHomePageBookmarks", "onSubscribe: "); } @Override public void onNext(@NonNull BaseResponse browserBookmarksBaseResponse) { - if (callback != null) + if (callback != null) { callback.onNext(); + } Logutils.e("getHomePageBookmarks", "onNext: "); if (browserBookmarksBaseResponse.code == 200) { //主页不包含白名单添加进去 String homepagURL = browserBookmarksBaseResponse.data.getHomepage(); Logutils.e("getHomePageBookmarks ", "homepagURL: " + homepagURL); String oldHome = Settings.System.getString(context.getContentResolver(), "homepagURL"); + Log.e("getHomePageBookmarks", "oldHome: " + oldHome); //数据和之前不一样的时候清除缓存 - if (!TextUtils.isEmpty(oldHome)&&oldHome.equalsIgnoreCase(homepagURL)){ + if (!TextUtils.isEmpty(oldHome) && !oldHome.equalsIgnoreCase(homepagURL)) { try { new CacheUtils().cleanApplicationUserData(context, "com.android.browser"); } catch (Exception e) { @@ -865,17 +870,17 @@ public class HTTPInterface { String whitelist = Settings.System.getString(context.getContentResolver(), "DeselectBrowserArray"); Logutils.e("getHomePageBookmarks ", "whitelist: " + whitelist); - if (!TextUtils.isEmpty(whitelist.trim())) { - HashSet whiteLists = new HashSet<>(Arrays.asList(whitelist.trim().split(","))); - whiteLists.add(homepagURL); - String whiteString = String.join(",", whiteLists); - boolean white = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", whiteString); - Logutils.e("getHomePageBookmarks", "onNext: homepagURL: add to whiteList = " + whiteString + "write: " + white); - } else { - Logutils.e("getHomePageBookmarks", "onNext: whitelist is NULL"); - boolean white = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", homepagURL); - Logutils.e("getHomePageBookmarks", "onNext: homepagURL: homepagURL = " + homepagURL + "write: " + white); - } +// if (!TextUtils.isEmpty(whitelist.trim())) { +// HashSet whiteLists = new HashSet<>(Arrays.asList(whitelist.trim().split(","))); +// whiteLists.add(homepagURL); +// String whiteString = String.join(",", whiteLists); +// boolean white = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", whiteString); +// Logutils.e("getHomePageBookmarks", "onNext: homepagURL: add to whiteList = " + whiteString + "write: " + white); +// } else { +// Logutils.e("getHomePageBookmarks", "onNext: whitelist is NULL"); +// boolean white = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", homepagURL); +// Logutils.e("getHomePageBookmarks", "onNext: homepagURL: homepagURL = " + homepagURL + "write: " + white); +// } //主页 Intent homepag = new Intent("qch_app_brower_homepage"); @@ -901,11 +906,11 @@ public class HTTPInterface { } if (!TextUtils.isEmpty(labelpage)) { HashSet labels = new HashSet<>(Arrays.asList(labelpage.split(","))); - List urlList = new ArrayList<>(); - for (String urls : labels) { - urlList.add(JGYUtils.getPrefixHttpsURL(urls)); - } - String join = String.join(",", urlList); +// List urlList = new ArrayList<>(); +// for (String urls : labels) { +// urlList.add(JGYUtils.getPrefixHttpsURL(urls)); +// } + String join = String.join(",", labels); Logutils.e("getHomePageBookmarks", "onNext: getHomePageBookmarks: " + join); websiteBookMark.putExtra("websiteBookMark", join); } else { @@ -921,7 +926,7 @@ public class HTTPInterface { intent1.putExtra("homepage", "Invalid"); context.sendBroadcast(intent1); - Settings.System.putString(context.getContentResolver(), "homepagURL", ""); + Settings.System.putString(context.getContentResolver(), "homepagURL", " "); Intent intent2 = new Intent("qch_app_brower_website"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { intent2.setPackage("com.android.settings") @@ -934,16 +939,18 @@ public class HTTPInterface { @Override public void onError(@NonNull Throwable e) { - if (callback != null) + if (callback != null) { callback.onError(e); + } Logutils.e("getHomePageBookmarks", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - if (callback != null) + if (callback != null) { callback.onComplete(); + } Logutils.e("getHomePageBookmarks", "onComplete: "); setBrowserBlackList(context); } @@ -1098,7 +1105,7 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(Disposable d) { - + Log.e(TAG, "onSubscribe: "); } @Override @@ -1287,7 +1294,7 @@ public class HTTPInterface { @Override public void onComplete() { - Logutils.e("getAppAutoStart", "onSubscribe: "); + Logutils.e("getAppAutoStart", "onComplete: "); } }); } diff --git a/app/src/main/java/com/mjsheng/myappstore/network/URLAddress.java b/app/src/main/java/com/mjsheng/myappstore/network/URLAddress.java index 2b8cefe..c258143 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/URLAddress.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/URLAddress.java @@ -3,12 +3,15 @@ package com.mjsheng.myappstore.network; import com.mjsheng.myappstore.BuildConfig; import com.mjsheng.myappstore.manager.NetInterfaceManager; +import rxhttp.wrapper.annotation.DefaultDomain; + /** * @author Administrator */ public class URLAddress { //根网址 - private static final String HTTP_TAG_HEAD_NEW = BuildConfig.ROOT_URL; + @DefaultDomain + public static final String HTTP_TAG_HEAD_NEW = BuildConfig.ROOT_URL; // 下载接口 根据包名匹配 请求后更新下载次数 @@ -16,9 +19,9 @@ public class URLAddress { //app下载完成发送下载次数 public static final String SEND_DOWNLOAD_FILE_INFO = HTTP_TAG_HEAD_NEW + "app/downloadApp"; //获取设备锁定状态 - public static final String GET_DEVICES_LOCKED = HTTP_TAG_HEAD_NEW + "lock/index"; + public static final String GET_DEVICES_LOCKED = "lock/index"; //发送设备信息 - public static final String SEND_DEVICES = HTTP_TAG_HEAD_NEW + "Mac/getMac"; + public static final String SEND_DEVICES = "Mac/getMac"; //发送app使用情况 public static final String SEND_USEDTIME = HTTP_TAG_HEAD_NEW + "Applog/getAppLog"; //更新接口 @@ -30,11 +33,11 @@ public class URLAddress { //浏览器书签主页设置 public static final String SET_HOMEPAG_TAG = HTTP_TAG_HEAD_NEW + "Label"; //app内部网页管控 - public static final String SET_APPINSIDEWEB = HTTP_TAG_HEAD_NEW + "Appground"; + public static final String SET_APPINSIDEWEB = "Appground"; //浏览器黑白名单地址 public static final String SET_BROWSER_LIST = HTTP_TAG_HEAD_NEW + "browser"; //强制安装应用 - public static final String GET_FORCE_INSTALL_LIST = "forceinstall/index"; + public static final String GET_FORCE_INSTALL_LIST = "forceinstall/index"; //应用白名单 public static final String SET_WHITE_PACKAGE_LIST = "firmware/index"; //获取隐藏桌面图标 @@ -42,29 +45,31 @@ public class URLAddress { //获取应用升级自启 public final static String NET_AND_LAUNCH_API = HTTP_TAG_HEAD_NEW + "automatic/get"; //通过sn获取信息 - public static final String GET_STUDENTS_INFO = HTTP_TAG_HEAD_NEW + "Sn/getStudent"; + public static final String GET_STUDENTS_INFO = "Sn/getStudent"; //上传截图 public static final String SEND_SCREENSHOT = HTTP_TAG_HEAD_NEW + "Screenshot/addImg"; //上传我的设备 //public static final String UPDATE_DEVICEINFO = HTTP_TAG_HEAD_NEW + "Mac/getInfo"; //获取霸屏状态 - public final static String GET_LOCK_SCREEN_STATE = HTTP_TAG_HEAD_NEW + "Sn/getSnScreen"; + public final static String GET_LOCK_SCREEN_STATE = "Sn/getSnScreen"; //获取默认桌面升级 - public final static String GET_DESKTOP = HTTP_TAG_HEAD_NEW + "Sn/getSnDesktop"; + public final static String GET_DESKTOP = "Sn/getSnDesktop"; //获取时间管控 - public final static String GET_SN_TIME_CONTROL = HTTP_TAG_HEAD_NEW + "Sn/getSnTimeControl"; + public final static String GET_SN_TIME_CONTROL = "Sn/getSnTimeControl"; //获取顶部app管控 - public final static String GET_TOP_APP_CONTROL = HTTP_TAG_HEAD_NEW + "Sn/getSnAppControl"; + public final static String GET_TOP_APP_CONTROL = "Sn/getSnAppControl"; //获取测试app public final static String GET_SN_APP_TEST = HTTP_TAG_HEAD_NEW + "Sn/getSnAppTest"; //开机动画 - public final static String GET_LOGO_IMG = HTTP_TAG_HEAD_NEW + "Sn/getLogoImg"; + public final static String GET_LOGO_IMG = "Sn/getLogoImg"; //开发人员选项开关 - public final static String GET_DEVELOPER = HTTP_TAG_HEAD_NEW + "Sn/getDeveloper"; + public final static String GET_DEVELOPER = "Sn/getDeveloper"; //通过固件名获取内置应用 - public final static String GET_ROM_APP = HTTP_TAG_HEAD_NEW + "And/getFirmwareApp"; + public final static String GET_ROM_APP = "And/getFirmwareApp"; //获取全部应用 - public final static String GET_ALL_APP = HTTP_TAG_HEAD_NEW + "recommend/index"; + public final static String GET_ALL_APP = "recommend/index"; //获取电子书包激活码 - public final static String GET_EBAG_CODE = HTTP_TAG_HEAD_NEW + "And/getEbagCode"; + public final static String GET_EBAG_CODE = "And/getEbagCode"; + //获取系统默认程序 + public final static String GET_DEFAULT_APP = "app/getDefaultApp"; } diff --git a/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/DefaultAppApi.java b/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/DefaultAppApi.java new file mode 100644 index 0000000..7edbb9f --- /dev/null +++ b/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/DefaultAppApi.java @@ -0,0 +1,16 @@ +package com.mjsheng.myappstore.network.api.newapi; + +import com.mjsheng.myappstore.bean.BaseResponse; +import com.mjsheng.myappstore.bean.DefaultApp; +import com.mjsheng.myappstore.network.URLAddress; + +import io.reactivex.Observable; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface DefaultAppApi { + @GET(URLAddress.GET_DEFAULT_APP) + Observable> getDefaultApp( + @Query("sn") String sn + ); +} diff --git a/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/MACAddressApi.java b/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/MACAddressApi.java index 41116f2..3d0547d 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/MACAddressApi.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/MACAddressApi.java @@ -17,6 +17,7 @@ public interface MACAddressApi { @Field("jpush_id") String jpushId, @Field("devices_version") String devicesVersion, @Field("appstore_version") String appstoreVersion, - @Field("store_version") String storeVersion + @Field("store_version") String storeVersion, + @Field("local_mac") String local_mac ); } diff --git a/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java b/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java index 6805a2f..a5a92ea 100644 --- a/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java +++ b/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java @@ -4,11 +4,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import com.mjsheng.myappstore.service.GuardService; -import com.mjsheng.myappstore.service.LogcatService; import com.mjsheng.myappstore.service.MainService; -import com.mjsheng.myappstore.service.StepService; import com.mjsheng.myappstore.utils.BootManager; +import com.mjsheng.myappstore.utils.JGYUtils; import com.mjsheng.myappstore.utils.Logutils; public class BootReceiver extends BroadcastReceiver { @@ -22,10 +20,16 @@ public class BootReceiver extends BroadcastReceiver { default: break; case Intent.ACTION_BOOT_COMPLETED: - startService(context); + JGYUtils.startServices(context); new BootManager(context).start(); break; case BOOT_COMPLETED: + if (MainService.mPresenter != null) { + MainService.mPresenter.getLockedState(); + Logutils.e(TAG, "mPresenter: " + "getLockedState"); + } else { + Logutils.e(TAG, "mPresenter is NULL"); + } case Intent.ACTION_BATTERY_CHANGED: case Intent.ACTION_BATTERY_LOW: case Intent.ACTION_BATTERY_OKAY: @@ -49,15 +53,8 @@ public class BootReceiver extends BroadcastReceiver { // case "android.intent.action.MEDIA_BAD_REMOVAL": //除了USER_PRESENT应该都收不到 // Log.e("fht", "BootReceiver MSG:" + intent.getAction()); - startService(context); + JGYUtils.startServices(context); break; } } - - private void startService(Context context) { - context.startService(new Intent(context, MainService.class)); - context.startService(new Intent(context, StepService.class)); - context.startService(new Intent(context, GuardService.class)); - context.startService(new Intent(context, LogcatService.class)); - } } diff --git a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java index 3c0243d..1819f94 100644 --- a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java +++ b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java @@ -13,6 +13,7 @@ import android.media.MediaPlayer; import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.provider.Settings; import android.text.TextUtils; @@ -42,6 +43,7 @@ import com.mjsheng.myappstore.utils.MySQLData; import com.mjsheng.myappstore.utils.SPUtils; import com.mjsheng.myappstore.utils.SaveListUtils; import com.mjsheng.myappstore.utils.ServiceAliveUtils; +import com.mjsheng.myappstore.utils.ToastUtil; import com.mjsheng.myappstore.utils.Utils; import java.io.File; @@ -69,11 +71,11 @@ public class MyJPushReceiver extends BroadcastReceiver { private final String MSG_SETTING = "2"; //浏览器网址管控 private final String MSG_BROWSER = "4"; - + //app id管控 private final String MSG_APPID = "5"; - + //应用联网管控 private final String MSG_NET_CONTROL = "6"; - + //APP自启联网滑动管控 private final String MSG_POWER_ON = "7"; //重置 private final String MSG_RESET = "8"; @@ -81,11 +83,11 @@ public class MyJPushReceiver extends BroadcastReceiver { private final String MSG_INSTALL = "9"; //解锁 private final String MSG_LOCK = "10"; - + //旧版相机管控 private final String MSG_CAMERA = "11"; private final String MSG_ONEPACKAGES = "12"; - + //app使用时间 private final String GET_APP_USEDTIME = "13"; //强制下载 private final String GET_FORCEDOWNLOADURL = "14"; @@ -99,7 +101,7 @@ public class MyJPushReceiver extends BroadcastReceiver { private final String HIDE_DESKTOP_ICON = "18"; //禁止滑动 private final String DISABLE_APP_SLIDE = "19"; - + //更新引用白名单 private final String UPDATE_INFO = "20"; //截图 private final String SN_SCREENSHOT = "21"; @@ -133,6 +135,7 @@ public class MyJPushReceiver extends BroadcastReceiver { private final String EBAG_CODE = "35"; //更新白名单 private final String UPDATE_WHITELIST = "36"; + private Context mContext; private int changeNum(int paramInt) { @@ -181,7 +184,6 @@ public class MyJPushReceiver extends BroadcastReceiver { String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE); String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); String package_name = bundle.getString("package_name"); - Logutils.e(TAG, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras); // ToastUtils.showShort("message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name); // Toast.makeText(context, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name, Toast.LENGTH_SHORT).show(); @@ -189,6 +191,7 @@ public class MyJPushReceiver extends BroadcastReceiver { default: break; case MSG_DELETE: + ToastUtil.betaShow("收到管控:应用删除"); if (!TextUtils.isEmpty(title)) { if (SaveListUtils.getlist().contains(title)) { SaveListUtils.getlist().remove(title); @@ -200,6 +203,7 @@ public class MyJPushReceiver extends BroadcastReceiver { HTTPInterface.getNetAndLaunchSetting(mContext); break; case MSG_SETTING: + ToastUtil.betaShow("收到管控:系统设置"); if (!TextUtils.isEmpty(extras)) { JGYUtils.getInstance().SettingSysData(extras); // Logutils.e(TAG, "title--------" + extras); @@ -207,44 +211,55 @@ public class MyJPushReceiver extends BroadcastReceiver { // getSystemSetting(); break; case MSG_BROWSER: + ToastUtil.betaShow("收到管控:浏览器网址管控"); getDeselectBrowerID(); break; case MSG_APPID: + ToastUtil.betaShow("收到管控:APP ID管控"); getDeselectID(); break; case MSG_NET_CONTROL: + ToastUtil.betaShow("收到管控:应用联网管控"); settingNetControl(extras); break; case MSG_POWER_ON: + ToastUtil.betaShow("收到管控:应用自启管控"); settingPowerOn(extras); break; case MSG_RESET: + ToastUtil.betaShow("收到管控:设备重置"); Utils.doMasterClear(mContext); break; case MSG_INSTALL: + ToastUtil.betaShow("收到管控:应用安装"); // mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); HTTPInterface.getAppLimit(context); doDownloadAndInstall(extras); HTTPInterface.setHideDesktopIcon(mContext); break; case MSG_LOCK: + ToastUtil.betaShow("收到管控:设备锁定"); settingLock(extras); break; case MSG_CAMERA: + ToastUtil.betaShow("收到管控:相机管控"); settingCamera(extras); break; case MSG_ONEPACKAGES: + ToastUtil.betaShow("收到管控:"); if (BaseApplication.getInstance().isFinished()) { settingOneNet(extras); } break; case GET_APP_USEDTIME: + ToastUtil.betaShow("收到管控:获取应用使用时间"); JSONObject jsonObject = JSON.parseObject(extras); String random = jsonObject.getString("random"); String sendType = jsonObject.getString("type"); BaseApplication.sendAppUsedTime(random, sendType); break; case GET_FORCEDOWNLOADURL: + ToastUtil.betaShow("收到管控:应用强制安装"); File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/"); if (!file.exists()) { file.mkdirs(); @@ -271,31 +286,49 @@ public class MyJPushReceiver extends BroadcastReceiver { Utils.ariaDownload(mContext, url, packageObj); break; case SET_HOMEPAG_TAG: + ToastUtil.betaShow("收到管控:浏览器主页书签设置"); setHomepagtag(extras); break; - case APP_WEBSITE: + ToastUtil.betaShow("收到管控:APP内部网页管控"); setAPPinsideWebsite(extras); break; case DISABLE_APPUPDATE: + ToastUtil.betaShow("收到管控:应用禁止更新设置"); setDisableUpdateList(extras); break; case HIDE_DESKTOP_ICON: - HTTPInterface.setHideDesktopIcon(context); + ToastUtil.betaShow("收到管控:隐藏应用设置"); + Handler.getMain().postDelayed(() -> { + //后台发送时数据库未改变,有时候可能获取到的数据时上一次的 + Logutils.e(TAG, "run: HIDE_DESKTOP_ICON "); + HTTPInterface.setHideDesktopIcon(context); + }, 2000); break; case DISABLE_APP_SLIDE: + ToastUtil.betaShow("收到管控:应用滑动设置"); setDisableSlideList(extras); break; case UPDATE_INFO: + ToastUtil.betaShow("收到管控:更新白名单"); HTTPInterface.getAppLimit(context); break; case SN_SCREENSHOT: + ToastUtil.betaShow("收到管控:设备截图"); screenshot(extras); break; case DEVICES_REBOOT: + ToastUtil.betaShow("收到管控:设备重启"); Utils.rebootDevices(mContext); break; case GET_DEVICES_INFO: + ToastUtil.betaShow("收到管控:获取设备信息"); + if (MainService.mPresenter != null) { + MainService.mPresenter.getLockedState(); + Logutils.e(TAG, "mPresenter: " + "getLockedState"); + } else { + Logutils.e(TAG, "mPresenter is NULL"); + } AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient(); aMapLocationClient.stopLocation(); aMapLocationClient.startLocation(); @@ -324,47 +357,61 @@ public class MyJPushReceiver extends BroadcastReceiver { }); break; case LOCK_SCREEN: + ToastUtil.betaShow("收到管控:屏幕锁定"); JSONObject lockJSONObject = JSON.parseObject(extras); String name = lockJSONObject.getString("name"); setLock_screen(1, context, name); break; case UNLOCK_SCREEN: + ToastUtil.betaShow("收到管控:屏幕解锁"); setLock_screen(0, context, ""); break; case KILL_SERVER: + ToastUtil.betaShow("收到管控:停止应用"); JSONObject killJSONObject = JSON.parseObject(extras); String packages = killJSONObject.getString("package_name"); JGYUtils.getInstance().killBackgroundProcesses(context, packages); break; case TIME_CONTROL: + ToastUtil.betaShow("收到管控:使用时间管控"); getTimeControl(context, extras); break; case TOP_APP: + ToastUtil.betaShow("收到管控:应用霸屏"); getTopApp(context, extras); break; case LOGO_IMG: + ToastUtil.betaShow("收到管控:开机动画设置"); setBootanimation(context, extras); Logutils.e(TAG, "processCustomMessage: " + extras); break; - case DEFAULTP_APP: + ToastUtil.betaShow("收到管控:"); + setDefalutApp(context, extras); break; case PLAY_SOUND: + ToastUtil.betaShow("收到管控:查找设备"); playSound(context, extras); break; case CLEAN_APP_CACHE: + ToastUtil.betaShow("收到管控:应用缓存清除"); cleanCache(context, extras); break; case DEVELOPER_OPTIONS: + ToastUtil.betaShow("收到管控:开发人员选项管控"); setDeveloperoptions(extras); break; case GLOBAL_UPDATE: + ToastUtil.betaShow("收到管控:全局更新"); GlobalUpdate(extras); break; case EBAG_CODE: + ToastUtil.betaShow("收到管控:电子书包激活码"); setEbagCode(extras); + JGYUtils.getInstance().killBackgroundProcesses(context, "com.jxw.launcher"); break; case UPDATE_WHITELIST: + ToastUtil.betaShow("收到管控:更新白名单"); HTTPInterface.getAppLimit(mContext); break; } @@ -699,7 +746,7 @@ public class MyJPushReceiver extends BroadcastReceiver { Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", strban); Logutils.e("fht", "sendban::" + strban); } else { - Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "invalid"); + Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid"); } Logutils.e("fht", "qch_disable_slide::" + Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide")); } @@ -798,13 +845,13 @@ public class MyJPushReceiver extends BroadcastReceiver { private void setHomepagtag(String s) { //设置主页和标签 // HTTPInterface.setHomepagtag(mContext);//设置主页和标签 - HTTPInterface.getHomePageBookmarks(mContext, null); try { new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser"); } catch (Exception e) { e.printStackTrace(); Logutils.e(TAG, "setHomepagtag: " + e.getMessage()); } + HTTPInterface.getHomePageBookmarks(mContext, null); // if (TextUtils.isEmpty(s)) { // Logutils.e(TAG, "setHomepagtag extras is null"); // @@ -827,7 +874,7 @@ public class MyJPushReceiver extends BroadcastReceiver { //禁止app内部网页访问,包名用,隔开 HTTPInterface.getAppinsideWeb(mContext, new HTTPInterface.GetAppinsideWebCallback() { @Override - public void ononComplete() { + public void onComplete() { Logutils.e(TAG, "ononComplete: setAPPinsideWebsite"); } }); @@ -1002,6 +1049,19 @@ public class MyJPushReceiver extends BroadcastReceiver { } } + private void setDefalutApp(Context context, String extras) { + if (TextUtils.isEmpty(extras)) { + JGYUtils.getInstance().setDefaultDesktop(""); + } else { + JSONObject jsonObject = JSON.parseObject(extras); + String default_launcher = jsonObject.getString("default_launcher"); + if (TextUtils.isEmpty(default_launcher)) { + JGYUtils.getInstance().setDefaultDesktop(""); + } else { + JGYUtils.getInstance().setDefaultDesktop(default_launcher); + } + } + } private void playSound(Context context, String extras) { JSONObject jsonObject = JSONObject.parseObject(extras); @@ -1100,6 +1160,7 @@ public class MyJPushReceiver extends BroadcastReceiver { private void setDeveloperoptions(String extras) { JSONObject jsonObject = JSONObject.parseObject(extras); int is_developer = jsonObject.getInteger("is_developer"); + Logutils.e(TAG + ":" + "getDeveloper", "onNext: " + is_developer); Logutils.e(TAG, "setDeveloperoptions: " + is_developer); JGYUtils.getInstance().setDeveloperOptions(is_developer == 0 ? 1 : 0); } diff --git a/app/src/main/java/com/mjsheng/myappstore/receiver/NewAppReceiver.java b/app/src/main/java/com/mjsheng/myappstore/receiver/NewAppReceiver.java index 7bc7cb9..75b9a7a 100644 --- a/app/src/main/java/com/mjsheng/myappstore/receiver/NewAppReceiver.java +++ b/app/src/main/java/com/mjsheng/myappstore/receiver/NewAppReceiver.java @@ -1,11 +1,13 @@ package com.mjsheng.myappstore.receiver; +import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Build; import android.text.TextUtils; +import android.util.Log; import com.mjsheng.myappstore.BuildConfig; import com.mjsheng.myappstore.network.HTTPInterface; @@ -13,7 +15,6 @@ import com.mjsheng.myappstore.utils.ApkUtils; import com.mjsheng.myappstore.utils.CacheUtils; import com.mjsheng.myappstore.utils.JGYUtils; import com.mjsheng.myappstore.utils.Logutils; -import com.mjsheng.myappstore.utils.SPUtils; import com.mjsheng.myappstore.utils.SaveListUtils; import java.util.concurrent.TimeUnit; @@ -29,6 +30,7 @@ public class NewAppReceiver extends BroadcastReceiver { private static final String TAG = NewAppReceiver.class.getSimpleName(); private static final String APPSTORE = "com.jiaoguanyi.store"; private static NewAppListener newAppListener; + @SuppressLint("StaticFieldLeak") private static Context mContext; static { @@ -52,6 +54,7 @@ public class NewAppReceiver extends BroadcastReceiver { state = "安装了:"; break; case Intent.ACTION_PACKAGE_REPLACED: + cleanLauncher3Cache(); state = "重装了:"; break; case Intent.ACTION_PACKAGE_REMOVED: @@ -86,21 +89,24 @@ public class NewAppReceiver extends BroadcastReceiver { // } } + private void cleanLauncher3Cache() { + try { + new CacheUtils().cleanApplicationUserData(mContext, "com.android.launcher3"); + } catch (Exception e) { + Log.e(TAG, "onReceive: " + e.getMessage()); + e.printStackTrace(); + } + } + public interface NewAppListener { void setNewAppListener(String packageName); } private static void sendAppInfo() { - Observable.create(new ObservableOnSubscribe() { - @Override - public void subscribe(@NonNull ObservableEmitter emitter) throws Exception { - newAppListener = new NewAppListener() { - @Override - public void setNewAppListener(String packageName) { - emitter.onNext(packageName); - } - }; - } + Observable.create((ObservableEmitter emitter) -> { + newAppListener = (String packageName) -> { + emitter.onNext(packageName); + }; }) .throttleLast(5, TimeUnit.SECONDS) //这句很关键,这是RxJava中的操作符,在规定时间内观察者不在接收被观察者发送的事件 @@ -115,8 +121,9 @@ public class NewAppReceiver extends BroadcastReceiver { Logutils.e(TAG, "sendAppInfo: onNext: " + s); SaveListUtils.getDownLoadList().remove(s); ApkUtils.getAppInfo(mContext); - // HTTPInterface.getNetAndLaunchSetting(mContext); + //HTTPInterface.getNetAndLaunchSetting(mContext); HTTPInterface.getAppLimit(mContext); +// HTTPInterface.getAppinsideWeb(mContext, () -> Logutils.e(TAG, "onNext: setAPPinsideWebsite")); } @Override diff --git a/app/src/main/java/com/mjsheng/myappstore/service/GuardService.java b/app/src/main/java/com/mjsheng/myappstore/service/GuardService.java index 0fc25bd..d332b2f 100644 --- a/app/src/main/java/com/mjsheng/myappstore/service/GuardService.java +++ b/app/src/main/java/com/mjsheng/myappstore/service/GuardService.java @@ -14,17 +14,14 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; -import android.net.ConnectivityManager; -import android.net.Network; -import android.net.NetworkInfo; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; import android.os.BatteryManager; import android.os.Build; import android.os.IBinder; +import android.os.SystemClock; import android.provider.Settings; import android.text.TextUtils; import android.text.format.Formatter; +import android.util.Log; import androidx.annotation.Nullable; @@ -43,7 +40,6 @@ import com.mjsheng.myappstore.receiver.BootReceiver; import com.mjsheng.myappstore.receiver.NewAppReceiver; import com.mjsheng.myappstore.utils.JGYUtils; import com.mjsheng.myappstore.utils.Logutils; -import com.mjsheng.myappstore.utils.NetworkUtils; import com.mjsheng.myappstore.utils.SPUtils; import com.mjsheng.myappstore.utils.XAPKUtils; import com.lzy.okgo.OkGo; @@ -59,7 +55,11 @@ import com.mjsheng.myappstore.utils.Utils; import java.io.IOException; import java.util.List; +import java.util.concurrent.TimeUnit; +import io.reactivex.Observable; +import io.reactivex.ObservableEmitter; +import io.reactivex.ObservableOnSubscribe; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -84,8 +84,7 @@ public class GuardService extends Service { Logutils.e(TAG, "GuardService:建立链接"); boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(GuardService.this, StepService.class.getName()); if (!isServiceRunning) { - Intent i = new Intent(GuardService.this, StepService.class); - startService(i); + startService(new Intent(GuardService.this, StepService.class)); } } @@ -105,20 +104,54 @@ public class GuardService extends Service { }; } + private interface Start { + void onstar(long time); + } + + private Start start; + + private ObservableOnSubscribe subscribe = new ObservableOnSubscribe() { + @Override + public void subscribe(ObservableEmitter emitter) throws Exception { + start = emitter::onNext; + } + }; + + private Observer timeObserver = new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(Long aLong) { + Logutils.e(TAG, "timeObserver: onNext: " + aLong); + startService(new Intent(GuardService.this, MainService.class)); + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + + } + }; + @Override public void onCreate() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // 8.0之后需要在 registmNewAppReceiver(); - startService(new Intent(this, MainService.class)); - startService(new Intent(this, StepService.class)); - startService(new Intent(this, GuardService.class)); - startService(new Intent(this, LogcatService.class)); + JGYUtils.startServices(GuardService.this); } registerPresentReceiver(); registerBatteryReceiver(); - registerNetworkReceiver(); - registerNetworkConnectedReceiver(); + Observable.create(subscribe) + .throttleFirst(10, TimeUnit.MINUTES) + .subscribe(timeObserver); super.onCreate(); } @@ -135,9 +168,6 @@ public class GuardService extends Service { @Override public void onDestroy() { super.onDestroy(); - if (null != mNetworkChangedRecceiver) { - unregisterReceiver(mNetworkChangedRecceiver); - } if (null != mNewAppReceiver) { unregisterReceiver(mNewAppReceiver); } @@ -147,93 +177,6 @@ public class GuardService extends Service { if (null != batteryReceiver) { unregisterReceiver(batteryReceiver); } - if (null != netReceiver) { - unregisterReceiver(netReceiver); - } - } - - private NetworkChangedRecceiver mNetworkChangedRecceiver; - - public void registerNetworkReceiver() { - mNetworkChangedRecceiver = new NetworkChangedRecceiver(); - IntentFilter filter = new IntentFilter(); - filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); - filter.addAction("android.net.ethernet.ETHERNET_STATE_CHANGED"); - filter.addAction("android.net.ethernet.STATE_CHANGE"); - filter.addAction("android.net.conn.CONNECTIVITY_CHANGE"); - filter.addAction("android.net.wifi.WIFI_STATE_CHANGED"); - filter.addAction("android.net.wifi.STATE_CHANGE"); - filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - registerReceiver(mNetworkChangedRecceiver, filter); - } - - public class NetworkChangedRecceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { - //获得ConnectivityManager对象 - ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - //获取ConnectivityManager对象对应的NetworkInfo对象 - //获取WIFI连接的信息 - NetworkInfo wifiNetworkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - //获取移动数据连接的信息 - NetworkInfo dataNetworkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); - if (wifiNetworkInfo.isConnected() && dataNetworkInfo.isConnected()) { - Logutils.e("NetworkChangedRecceiver", "WIFI已连接,移动数据已连接"); - } else if (wifiNetworkInfo.isConnected() && !dataNetworkInfo.isConnected()) { - Logutils.e("NetworkChangedRecceiver", "WIFI已连接,移动数据已断开"); - } else if (!wifiNetworkInfo.isConnected() && dataNetworkInfo.isConnected()) { - Logutils.e("NetworkChangedRecceiver", "WIFI已连接,移动数据已连接"); - } else { - Logutils.e("NetworkChangedRecceiver", "WIFI已连接,移动数据已断开"); - } - //API大于23时使用下面的方式进行网络监听 - } else { - //获得ConnectivityManager对象 - ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - //获取所有网络连接的信息 - Network[] networks = connMgr.getAllNetworks(); - //用于存放网络连接信息 - StringBuilder sb = new StringBuilder(); - //通过循环将网络信息逐个取出来 - for (int i = 0; i < networks.length; i++) { - //获取ConnectivityManager对象对应的NetworkInfo对象 - NetworkInfo networkInfo = connMgr.getNetworkInfo(networks[i]); - if (null != networkInfo) { - sb.append(networkInfo.getTypeName() + " connect is " + networkInfo.isConnected()); - } - } - Logutils.e("NetworkChangedRecceiver", sb.toString()); - } - if (intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) { - Logutils.e("NetworkChangedRecceiver", "wifi信号强度变化"); - } - //wifi连接上与否 - if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { - - NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); - if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) { - Logutils.e("NetworkChangedRecceiver", "wifi断开"); - } else if (info.getState().equals(NetworkInfo.State.CONNECTED)) { - WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - WifiInfo wifiInfo = wifiManager.getConnectionInfo(); - //获取当前wifi名称 - Logutils.e("NetworkChangedRecceiver", "连接到网络 " + wifiInfo.getSSID()); - startService(new Intent(context, MainService.class)); - Aria.download(this).resumeAllTask(); - } - } - //wifi打开与否 - if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { - int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED); - if (wifistate == WifiManager.WIFI_STATE_DISABLED) { - Logutils.e("NetworkChangedRecceiver", "系统关闭wifi"); - } else if (wifistate == WifiManager.WIFI_STATE_ENABLED) { - Logutils.e("NetworkChangedRecceiver", "系统开启wifi"); - } - } - } } private NewAppReceiver mNewAppReceiver; @@ -284,10 +227,7 @@ public class GuardService extends Service { //intent1.putExtra("test", "我是来测 A 应用的Android 8.0 系统静态广播的测试数据"); // 启动发送广播 sendBroadcast(intent1); - startService(new Intent(context, MainService.class)); - startService(new Intent(context, StepService.class)); - startService(new Intent(context, GuardService.class)); - startService(new Intent(context, LogcatService.class)); + JGYUtils.startServices(GuardService.this); if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) { int setting_statusbar = Settings.System.getInt(context.getContentResolver(), "qch_hide_statusBar", 0); String statusbarStatus = ""; @@ -313,8 +253,8 @@ public class GuardService extends Service { // context.sendBroadcast(navIntent); // } sendScreenStatus(1); - break; } + break; case Intent.ACTION_SCREEN_OFF: { HTTPInterface.getAppLimit(GuardService.this); long time = System.currentTimeMillis(); @@ -331,8 +271,8 @@ public class GuardService extends Service { // context.sendBroadcast(navIntent); // } sendScreenStatus(2); - break; } + break; case "android.intent.action.FACTORY_RESET": case "android.intent.action.MASTER_CLEAR": case "android.intent.action.MASTER_CLEAR_NOTIFICATION": @@ -379,15 +319,16 @@ public class GuardService extends Service { .subscribe(new Observer() { @Override public void onSubscribe(Disposable d) { - + Log.e("getLockState", "onSubscribe: "); } @Override public void onNext(ResponseBody responseBody) { try { com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(responseBody.string()); + Log.e("getLockState", "onNext: " + jsonObject); int code = jsonObject.getInteger("code"); - + Log.e("getLockState", "onNext: code: "+code ); } catch (IOException e) { e.printStackTrace(); } @@ -395,17 +336,16 @@ public class GuardService extends Service { @Override public void onError(Throwable e) { - + Log.e("getLockState", "onError: " + e.getMessage()); } @Override public void onComplete() { - + Log.e("getLockState", "onComplete: "); } }); } - private void registerBatteryReceiver() { if (null == batteryReceiver) { batteryReceiver = new BatteryReceiver(); @@ -435,7 +375,7 @@ public class GuardService extends Service { int elec = (level * 100) / scale; Logutils.e(TAG, "electricity:=" + elec + "%"); if (elec == 50) { - startService(new Intent(getBaseContext(), MainService.class)); + start.onstar(SystemClock.elapsedRealtime()); } } else if (Intent.ACTION_POWER_CONNECTED.equals(action) || Intent.ACTION_POWER_DISCONNECTED.equals(action) @@ -444,7 +384,7 @@ public class GuardService extends Service { ) { setDefaultUSBStatus(); Logutils.e(TAG, action); - startService(new Intent(getBaseContext(), MainService.class)); + start.onstar(SystemClock.elapsedRealtime()); } } } @@ -474,41 +414,6 @@ public class GuardService extends Service { sendBroadcast(usbIntent); } - private void registerNetworkConnectedReceiver() { - if (null == netReceiver) { - netReceiver = new NetworkStateReceiver(); - } - IntentFilter filter = new IntentFilter(); - filter.addAction("android.net.ethernet.ETHERNET_STATE_CHANGED"); - filter.addAction("android.net.ethernet.STATE_CHANGE"); - filter.addAction("android.net.conn.CONNECTIVITY_CHANGE"); - filter.addAction("android.net.wifi.WIFI_STATE_CHANGED"); - filter.addAction("android.net.wifi.STATE_CHANGE"); - filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - registerReceiver(netReceiver, filter); - } - - private NetworkStateReceiver netReceiver; - - - public class NetworkStateReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - if (intent == null || intent.getAction() == null) { - Logutils.e(TAG, "NetworkStateReceiver: 异常"); - return; - } - if (NetworkUtils.isConnected(getBaseContext())) { - Logutils.e(TAG, "NetworkStateReceiver: 网络连接成功"); - startService(new Intent(getBaseContext(), MainService.class)); - } else { - Logutils.e(TAG, "NetworkStateReceiver: 网络连接失败"); - } - } - } - - //在这里处理任务执行中的状态,如进度进度条的刷新 @Download.onTaskRunning protected void running(DownloadTask task) { diff --git a/app/src/main/java/com/mjsheng/myappstore/service/MainService.java b/app/src/main/java/com/mjsheng/myappstore/service/MainService.java index 808f1be..95cc297 100644 --- a/app/src/main/java/com/mjsheng/myappstore/service/MainService.java +++ b/app/src/main/java/com/mjsheng/myappstore/service/MainService.java @@ -6,6 +6,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.PixelFormat; @@ -15,6 +16,7 @@ import android.os.SystemClock; import android.provider.Settings; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; @@ -23,6 +25,8 @@ import android.widget.TextView; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.blankj.utilcode.util.AdaptScreenUtils; +import com.blankj.utilcode.util.NetworkUtils; import com.google.gson.JsonObject; import com.mjsheng.myappstore.R; import com.mjsheng.myappstore.action.JGYActions; @@ -36,6 +40,7 @@ import com.mjsheng.myappstore.utils.SPUtils; import com.mjsheng.myappstore.utils.SaveListUtils; import com.mjsheng.myappstore.utils.SysSettingUtils; import com.mjsheng.myappstore.utils.TimeUtils; +import com.mjsheng.myappstore.utils.ToastUtil; import java.util.Arrays; import java.util.HashSet; @@ -48,11 +53,33 @@ import io.reactivex.ObservableOnSubscribe; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; -public class MainService extends Service implements MainContact.MainView { - private MainPresenter mPresenter; +public class MainService extends Service implements MainContact.MainView, NetworkUtils.OnNetworkStatusChangedListener { + @SuppressLint("StaticFieldLeak") + public static MainPresenter mPresenter; private static final String TAG = MainService.class.getSimpleName(); public static boolean netWorkIsRunning = false; + @Override + public void onDisconnected() { + Log.e("OnNetworkStatusChangedListener", "onDisconnected: "); + ToastUtil.betaShow("网络断开连接"); + } + + @Override + public void onConnected(NetworkUtils.NetworkType networkType) { + Log.e("OnNetworkStatusChangedListener", "onConnected: "); + runningTime = SystemClock.elapsedRealtime(); + //直接获取数据 + ToastUtil.betaShow("网络已连接"); + mPresenter.getLockedState(); + } + + @Override + public Resources getResources() { + //1920是设计稿的宽(单位p:x) + return AdaptScreenUtils.adaptWidth(super.getResources(), 1920); + } + private interface Start { void onstar(long time); } @@ -110,13 +137,20 @@ public class MainService extends Service implements MainContact.MainView { mPresenter.setDisableSetting(); } registerReceivers(); + NetworkUtils.registerNetworkStatusChangedListener(this); addShortcut(); Observable.create(subscribe) - .throttleLast(60, TimeUnit.SECONDS) + .throttleFirst(3, TimeUnit.HOURS) .subscribe(timeObserver); + Observable.create(timeChangedSubscribe) + .throttleFirst(3, TimeUnit.HOURS) + .subscribe(timeChangedObserver); // cleanLauncherCache(); - setFloatingWindow(this); + timeChangedStart.onstar(System.currentTimeMillis()); setStatusbar(); + //发送设备mac地址和信息 + mPresenter.sendMACAddress(); + setFloatingWindow(this); super.onCreate(); } @@ -124,6 +158,7 @@ public class MainService extends Service implements MainContact.MainView { public void onDestroy() { super.onDestroy(); unRegisterReceivers(); + NetworkUtils.unregisterNetworkStatusChangedListener(this); mPresenter.detachView(); } @@ -305,6 +340,41 @@ public class MainService extends Service implements MainContact.MainView { } } + private interface TimeChangedStart { + void onstar(long time); + } + + private TimeChangedStart timeChangedStart; + + private ObservableOnSubscribe timeChangedSubscribe = new ObservableOnSubscribe() { + @Override + public void subscribe(ObservableEmitter emitter) throws Exception { + timeChangedStart = emitter::onNext; + } + }; + + private Observer timeChangedObserver = new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(Long aLong) { + setFloatingWindow(MainService.this); + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + + } + }; + private TimeChangedReceiver mTimeChangedReceiver; /** @@ -337,17 +407,21 @@ public class MainService extends Service implements MainContact.MainView { Logutils.e("TimeChangedReceiver", "onReceive:" + "timezone changed"); } else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) { Logutils.e("TimeChangedReceiver", "onReceive:" + "time tick"); + setFloatingWindow(MainService.this); } else if (ACTION_UPDATE.equals(intent.getAction())) { + setFloatingWindow(MainService.this); + mPresenter.getScreenLockState(); Logutils.e("TimeChangedReceiver", "onReceive:" + "date update"); } - setFloatingWindow(context); + timeChangedStart.onstar(System.currentTimeMillis()); } } - private void setFloatingWindow(Context context) { + synchronized private void setFloatingWindow(Context context) { ForegroundAppUtil.openTopApp(context); long nowTime = System.currentTimeMillis(); TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(MainService.this); + Log.e(TAG, "setFloatingWindow: screenlocked: " + screenlocked); if (null != contralTime) { if (contralTime.inControlTime(nowTime)) { if (!screenlocked) { @@ -358,7 +432,6 @@ public class MainService extends Service implements MainContact.MainView { } timelocked = true; } else { - mPresenter.getScreenLockState(); if (!screenlocked) { hideFloatingWindow(); } @@ -368,7 +441,6 @@ public class MainService extends Service implements MainContact.MainView { if (!screenlocked) { hideFloatingWindow(); } - mPresenter.getScreenLockState(); timelocked = false; } } @@ -462,6 +534,7 @@ public class MainService extends Service implements MainContact.MainView { @Override public void setLockedState(boolean loocked) { if (loocked) { + ToastUtil.betaShow("设备已上锁"); Logutils.e(TAG, "setLockedState: " + netWorkIsRunning); //上传APP信息 ApkUtils.getAppInfo(this); @@ -476,9 +549,10 @@ public class MainService extends Service implements MainContact.MainView { // return; } //获取系统管控 - mPresenter.getSystemSettingbegin(); + mPresenter.setJpushTags(); netWorkIsRunning = true; } else { + ToastUtil.betaShow("设备已解锁"); netWorkIsRunning = false; SysSettingUtils.setEnableSetting(this); } @@ -521,12 +595,6 @@ public class MainService extends Service implements MainContact.MainView { @Override public void setAliasFinished() { - mPresenter.setJpushTags(); - //设置极光推送tag - } - - @Override - public void setTagsFinished() { mPresenter.checkStoreUpdate(); } @@ -537,12 +605,17 @@ public class MainService extends Service implements MainContact.MainView { @Override public void checkStoreUpdateFinished() { + mPresenter.checkInfoUpdate(); + } + + @Override + public void checkInfoUpdateFinished() { mPresenter.checkTestUpdate(); } @Override public void checkTestUpdateFinished() { - mPresenter.getDefaultDesktop(); + } @Override @@ -550,6 +623,17 @@ public class MainService extends Service implements MainContact.MainView { } + @Override + public void setTagsFinished(boolean noTag) { + if (noTag) { + Log.e(TAG, "setTagsFinished: " + "not set tag"); + netWorkIsRunning = false; + Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - runningTime) + " ms"); + } else { + mPresenter.getSystemSettingbegin(); + } + } + @Override public void getSystemSettingbegin() { mPresenter.getAppLimit(); @@ -603,6 +687,11 @@ public class MainService extends Service implements MainContact.MainView { @Override public void setSystemSettingFinished() { + mPresenter.getDefaultApp(); + } + + @Override + public void setDefaultAppFinished() { mPresenter.getROMApp(); } @@ -623,8 +712,13 @@ public class MainService extends Service implements MainContact.MainView { @Override public void setTopAppFinished() { + mPresenter.getDefaultDesktop(); + } + + @Override + public void getDefaultDesktopFinished() { netWorkIsRunning = false; - Logutils.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - runningTime) + " ms"); + Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - runningTime) + " ms"); } @Override @@ -641,9 +735,4 @@ public class MainService extends Service implements MainContact.MainView { screenlocked = false; } } - - @Override - public void getDefaultDesktopFinished() { - - } } diff --git a/app/src/main/java/com/mjsheng/myappstore/service/StepService.java b/app/src/main/java/com/mjsheng/myappstore/service/StepService.java index e07006c..e87fd88 100644 --- a/app/src/main/java/com/mjsheng/myappstore/service/StepService.java +++ b/app/src/main/java/com/mjsheng/myappstore/service/StepService.java @@ -92,8 +92,8 @@ public class StepService extends Service { //初始化websocket Logutils.e(TAG, "onStartCommand: "); - initSocketClient(); - mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 +// initSocketClient(); +// mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT); return START_STICKY; } @@ -129,7 +129,7 @@ public class StepService extends Service { Logutils.i("JWebSocketClientService", "websocket连接关闭"); // client.close(); // initSocketClient(); - mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 +// mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 } @@ -139,7 +139,7 @@ public class StepService extends Service { Logutils.i("JWebSocketClientService", "websocket连接错误"); // client.close(); // initSocketClient(); - mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 +// mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 } }; @@ -206,7 +206,7 @@ public class StepService extends Service { sendMsg(Utils.getSerial()); } else if (client.isClosed()) { Logutils.i("JWebSocketClientService", "websocket重连中"); - reconnectWs(); +// reconnectWs(); } } else { //如果client已为空,重新初始化连接 @@ -214,7 +214,7 @@ public class StepService extends Service { initSocketClient(); } //每隔一定的时间,对长连接进行一次心跳检测 - mHandler.postDelayed(this, HEART_BEAT_RATE); +// mHandler.postDelayed(this, HEART_BEAT_RATE); } }; diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java index 1475dae..5f6a278 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java @@ -22,6 +22,7 @@ import androidx.annotation.RequiresApi; import androidx.core.content.FileProvider; import android.text.TextUtils; +import android.util.Log; import android.view.View; import android.widget.Toast; @@ -50,7 +51,6 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.function.Predicate; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -154,21 +154,14 @@ public class ApkUtils { * 检查手机上是否安装了指定的软件 */ public static boolean isAvailable(Context context, String packageName) { - // 获取packagemanager - final PackageManager packageManager = context.getPackageManager(); - // 获取所有已安装程序的包信息 - List packageInfos = packageManager.getInstalledPackages(0); - // 用于存储所有已安装程序的包名 - List packageNames = new ArrayList<>(); - // 从pinfo中将包名字逐一取出,压入pName list中 - if (packageInfos != null) { - for (int i = 0; i < packageInfos.size(); i++) { - String packName = packageInfos.get(i).packageName; - packageNames.add(packName); - } + PackageManager packageManager = context.getPackageManager(); + PackageInfo info = null; + try { + info = packageManager.getPackageInfo(packageName, 0); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); } - // 判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE - return packageNames.contains(packageName); + return info != null; } /** diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/CmdUtil.java b/app/src/main/java/com/mjsheng/myappstore/utils/CmdUtil.java index 01f04d0..6089fd9 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/CmdUtil.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/CmdUtil.java @@ -86,8 +86,8 @@ public class CmdUtil { public static final int ERROR = -1; public int code = ERROR; - String error; - String success; + public String error; + public String success; @Override public String toString() { diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java index 8d6e089..c75fea1 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java @@ -12,6 +12,7 @@ import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.content.pm.UserInfo; import android.graphics.Bitmap; import android.net.ConnectivityManager; @@ -23,6 +24,7 @@ import android.os.PowerManager; import android.os.RemoteException; import android.provider.Settings; import android.text.TextUtils; +import android.util.Log; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -48,6 +50,12 @@ import com.mjsheng.myappstore.bean.NetAndLaunchBean; import com.mjsheng.myappstore.bean.NetAndLaunchData; import com.mjsheng.myappstore.bean.TTAppground; import com.mjsheng.myappstore.comm.CommonDatas; +import com.mjsheng.myappstore.service.GuardService; +import com.mjsheng.myappstore.service.LogcatService; +import com.mjsheng.myappstore.service.MainService; +import com.mjsheng.myappstore.service.StepService; + +import org.w3c.dom.Text; import java.io.File; import java.io.FileInputStream; @@ -75,6 +83,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Predicate; +import java.util.stream.Collectors; import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE; @@ -245,8 +254,10 @@ public class JGYUtils { if (TextUtils.isEmpty(qch_app_power_on)) { //当 qch_app_power_on 的值为空时,会造成系统所有应用断网 Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "Invalid"); + Logutils.e(TAG, "setNetAndlaunch: qch_app_power_on: " + "Invalid"); } else { Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", qch_app_power_on); + Logutils.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on); } // if (BuildConfig.DEBUG) { // TODO: 2021/7/2 测试写入为空是否断网 @@ -351,8 +362,10 @@ public class JGYUtils { if (TextUtils.isEmpty(qch_app_power_on)) { //当 qch_app_power_on 的值为空时,会造成系统所有应用断网 Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "Invalid"); + Logutils.e(TAG, "setNetAndlaunch: qch_app_power_on: " + "Invalid"); } else { Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", qch_app_power_on); + Logutils.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on); } // if (BuildConfig.DEBUG) { // TODO: 2021/7/2 测试写入为空是否断网 @@ -370,15 +383,15 @@ public class JGYUtils { String not = Settings.System.getString(context.getContentResolver(), JGYActions.ACTION_HrReceiver_JGY); //清除旧数据 if (!TextUtils.isEmpty(dis)) { - Logutils.e(TAG, "setAppNetwork: " + dis); + Logutils.e(TAG, "setAppNetwork: dis = " + dis); Settings.System.putString(context.getContentResolver(), JGYActions.ACTION_HrReceiver_JGY_DIS, "Invalid"); } if (!TextUtils.isEmpty(not)) { - Logutils.e(TAG, "setAppNetwork: " + not); + Logutils.e(TAG, "setAppNetwork: not = " + not); Settings.System.putString(context.getContentResolver(), JGYActions.ACTION_HrReceiver_JGY, "Invalid"); } - String oldBlackList = (String) SPUtils.get(context, JGYActions.ACTION_HrReceiver_JGY_DIS, "Invalid"); + String oldBlackList = (String) SPUtils.get(context, JGYActions.ACTION_HrReceiver_JGY_DIS, ""); HashSet oldBlackListSet = new HashSet<>(Arrays.asList(oldBlackList.split(","))); oldBlackListSet.removeIf(new Predicate() { @Override @@ -393,6 +406,13 @@ public class JGYUtils { Logutils.e(TAG, "setAppNetwork: blackList: " + blackList); for (String pkg : blackList) { if (TextUtils.isEmpty(pkg)) continue; + //发送没有安装的 + if (!ApkUtils.isAvailable(context, pkg)) { + Log.e(TAG, "setAppNetwork: skip: " + pkg); + continue; + } else { + Log.e(TAG, "setAppNetwork: " + pkg + " 已安装"); + } Intent netControlNotIntent = new Intent(JGYActions.ACTION_HrReceiver_JGY_DIS); netControlNotIntent.putExtra("package_name", pkg); netControlNotIntent.setPackage("com.android.settings"); @@ -423,6 +443,12 @@ public class JGYUtils { } for (String pkg : addedNet) { if (TextUtils.isEmpty(pkg)) continue; + if (!ApkUtils.isAvailable(context, pkg)) { + Log.e(TAG, "setAppNetwork: skip: " + pkg); + continue; + } else { + Log.e(TAG, "setAppNetwork: " + pkg + " 已安装"); + } Intent netControlNotIntent = new Intent(JGYActions.ACTION_HrReceiver_JGY_DIS); netControlNotIntent.putExtra("package_name", pkg); netControlNotIntent.setPackage("com.android.settings"); @@ -457,6 +483,10 @@ public class JGYUtils { }); for (String pkg : oldBlackListSet) { if (TextUtils.isEmpty(pkg)) continue; + if (!ApkUtils.isAvailable(mContext, pkg)) { + Log.e(TAG, "setAppNetwork: skip: " + pkg); + continue; + } Intent netControlNotIntent = new Intent(JGYActions.ACTION_HrReceiver_JGY_DIS); netControlNotIntent.putExtra("package_name", pkg); netControlNotIntent.setPackage("com.android.settings"); @@ -583,6 +613,8 @@ public class JGYUtils { } } else if (response.code == 400) { //列表为空的情况 + List whiteApp = new ArrayList<>(); + setWhiteApp(whiteApp); sendAllweb(mContext); sendwebUrl(mContext); //ToastUtil.show(msg); @@ -595,9 +627,11 @@ public class JGYUtils { @SuppressLint("NewApi") synchronized private void setWhiteApp(List appgrounds) { + //去重 + List ttAppgrounds = appgrounds.stream().distinct().collect(Collectors.toList()); List old = getOldWhitelist(); - comparedAppground(old, appgrounds); - setWhiteList(appgrounds); + comparedAppground(old, ttAppgrounds); + setWhiteList(ttAppgrounds); } synchronized private void comparedAppground(List oldAppgrounds, List newAppgrounds) { @@ -638,8 +672,7 @@ public class JGYUtils { addAppground(addAppgrounds); deleteAppground(deleteAppgrounds); changeAppground(oldAppgroundsMap, changedAppgrounds); - - + Log.e(TAG, "comparedAppground: complete"); } private void addAppground(List appgroundList) { @@ -655,6 +688,7 @@ public class JGYUtils { private void deleteAppground(List appgroundList) { for (TTAppground appground : appgroundList) { deleteWhitelistUrl(appground.getPackages(), appground.getAddress()); + deleteOtherAppWhitelist(appground.getPackages()); Logutils.e("comparedAppground", "deleteAppground: " + appground.getAddress()); } } @@ -690,13 +724,27 @@ public class JGYUtils { if (whiteList == null) { whiteList = new ArrayList<>(); } - return whiteList; + //去重 + whiteList.removeIf(new Predicate() { + @Override + public boolean test(TTAppground ttAppground) { + return !ApkUtils.isAvailable(mContext, ttAppground.getPackages()); + } + }); + List ttAppgrounds = whiteList.stream().distinct().collect(Collectors.toList()); + return ttAppgrounds; } /** * @param appgrounds 写入缓存 */ private void setWhiteList(List appgrounds) { + appgrounds.removeIf(new Predicate() { + @Override + public boolean test(TTAppground ttAppground) { + return !ApkUtils.isAvailable(mContext, ttAppground.getPackages()); + } + }); String data = new Gson().toJson(appgrounds); SPUtils.put(mContext, JGY_APPINSIDE_WHITELIST, data); } @@ -710,8 +758,8 @@ public class JGYUtils { } else { addPackage(appground.getPackages()); //删除空的,旧版本使用这个清除 - deleteWhitelistUrl(appground.getPackages(), "Invalid"); addToWhitelist(appground.getPackages(), appground.getAddress()); + deleteWhitelistUrl(appground.getPackages(), "Invalid"); } } } @@ -734,7 +782,7 @@ public class JGYUtils { * @param urls 添加app白名单 */ synchronized private void addToWhitelist(String pkg, String urls) { - if (TextUtils.isEmpty(urls.trim())) { + if (TextUtils.isEmpty(urls)) { Logutils.e(TAG, "addToWhitelist: " + "urls is NULL"); return; } @@ -743,7 +791,8 @@ public class JGYUtils { if (TextUtils.isEmpty(url)) { continue; } - Logutils.e(TAG, "addToWhitelist: pkg:" + pkg); + deleteOtherAppWhitelist(pkg); + Logutils.e(TAG, "addToWhitelist: pkg:" + pkg + " url: " + url); Intent intent25 = new Intent(); intent25.setAction("qch_app_setAddAppWhitWebUid"); intent25.putExtra("AddAppWhitWebUidPackage", pkg); @@ -758,7 +807,7 @@ public class JGYUtils { * @param urls 删除某个app 内某个白名单 */ synchronized private void deleteWhitelistUrl(String pkg, String urls) { - if (TextUtils.isEmpty(urls.trim())) { + if (TextUtils.isEmpty(urls)) { Logutils.e(TAG, "addToWhitelist: " + "urls is NULL"); return; } @@ -778,10 +827,9 @@ public class JGYUtils { } /** - * @param pkg 取消某个白名单app + * @param pkg 开启和关闭白名单管控都需要发送 */ - // TODO: 2021/6/16 底层未实现功能 - synchronized private void disableAppWhitelist(String pkg) { + synchronized private void deleteOtherAppWhitelist(String pkg) { Logutils.e(TAG, "disableAppWhitelist: " + pkg); Intent intent24 = new Intent(); intent24.setAction("qch_app_setDelAppWhitUid"); @@ -850,6 +898,7 @@ public class JGYUtils { } synchronized public void SettingSysData(String data) { + SPUtils.put(mContext, "SystemSettingData", data); if (TextUtils.isEmpty(data)) { Logutils.e(TAG, "SettingSysData: " + "data is empty"); SysSettingUtils.setDisableSetting(mContext); @@ -1046,10 +1095,12 @@ public class JGYUtils { long versionCode = data.getApp_version_code(); String packageName = data.getApp_package(); String app_name = data.getApp_name(); + String app_md5 = data.getApp_md5(); // String app_id = jsonObject.get("app_id").getAsString(); JSONObject object = new JSONObject(); object.put("app_name", app_name); object.put("app_package", packageName); + object.put("MD5", app_md5); // object.put("app_id", app_id); PackageManager pm = mContext.getPackageManager(); PackageInfo packageInfo = null; @@ -1277,6 +1328,7 @@ public class JGYUtils { } public void setDeveloperOptions(int state) { + Log.e(TAG, "getDeveloper: " + state); if (!BuildConfig.DEBUG) { Settings.System.putInt(mContext.getContentResolver(), "qch_Developeroptions", state); if (state == 1) { @@ -1284,9 +1336,12 @@ public class JGYUtils { intent.setAction("qch_developeroptions_close"); intent.setPackage("com.android.settings"); mContext.sendBroadcast(intent); + Log.e(TAG, "getDeveloper: " + "关闭开发者模式"); + } else { + Log.e(TAG, "getDeveloper: " + "打开开发者模式"); +// ToastUtil.show("打开开发者模式"); } } - } public void hookWebView() { @@ -1566,7 +1621,7 @@ public class JGYUtils { return ActivityTaskManager.getService().getRecentTasks(numTasks, RECENT_IGNORE_UNAVAILABLE, userId).getList(); } catch (RemoteException e) { - Logutils.e(TAG, "Failed to get recent tasks "+ e); + Logutils.e(TAG, "Failed to get recent tasks " + e); return new ArrayList<>(); } } @@ -1684,4 +1739,75 @@ public class JGYUtils { return "未获取到IP"; } + private static long lastTime; + + public static void startServices(Context context) { + Log.e(TAG, "startServices: " + context.getClass().getSimpleName()); + if (System.currentTimeMillis() - lastTime < 10 * 60 * 1000) { + Log.e(TAG, "startServices: " + "lastTime: " + lastTime); + } else { + lastTime = System.currentTimeMillis(); + context.startService(new Intent(context, MainService.class)); + context.startService(new Intent(context, StepService.class)); + context.startService(new Intent(context, GuardService.class)); + context.startService(new Intent(context, LogcatService.class)); + } + } + + public void setDefaultDesktop(String pkg) { + if (TextUtils.isEmpty(pkg)) { + setDefaultDesktop("", ""); + } else { + String className = getStartClassName(pkg); + if (TextUtils.isEmpty(className)) { + setDefaultDesktop("", ""); + } else { + setDefaultDesktop(pkg, className); + } + } + } + + public String getStartClassName(String pkg) { + PackageInfo packageInfo = null; + try { + packageInfo = mContext.getPackageManager().getPackageInfo(pkg, 0); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + if (packageInfo == null) { + return ""; + } else { + // 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent + Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); + resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); + resolveIntent.setPackage(packageInfo.packageName); + + // 通过getPackageManager()的queryIntentActivities方法遍历 + List resolveinfoList = mContext.getPackageManager() + .queryIntentActivities(resolveIntent, 0); + if (resolveinfoList == null || resolveinfoList.size() == 0) { + return ""; + } + + ResolveInfo resolveinfo = resolveinfoList.iterator().next(); + if (resolveinfo != null) { + // packagename = 参数packname + String packageName = resolveinfo.activityInfo.packageName; + // 这个就是我们要找的该APP的LAUNCHER的Activity[组织形式:packagename.mainActivityname] + String className = resolveinfo.activityInfo.name; + return className; + } else { + return ""; + } + } + } + + public void setDefaultDesktop(String pkg, String className) { + Intent intent = new Intent("setDefaultLauncher"); + intent.putExtra("package", pkg); + intent.putExtra("className", className); + intent.setPackage("com.android.settings"); + mContext.sendBroadcast(intent); + Log.e(TAG, "setDefaultDesktop: " + pkg + ":" + className); + } } diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/Logutils.java b/app/src/main/java/com/mjsheng/myappstore/utils/Logutils.java index 1857285..c507911 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/Logutils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/Logutils.java @@ -5,7 +5,8 @@ import android.util.Log; import com.mjsheng.myappstore.BuildConfig; public class Logutils { - private final static boolean debug = BuildConfig.DEBUG; +// private final static boolean debug = BuildConfig.DEBUG; + private final static boolean debug = true; public static void i(String tag, String msg) { if (debug) { diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/NetworkUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/NetworkUtils.java index 6949909..2a2946c 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/NetworkUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/NetworkUtils.java @@ -6,7 +6,6 @@ import android.net.ConnectivityManager; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.os.Build; -import android.util.Log; public class NetworkUtils { public static boolean isConnected(Context context) { diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/SysSettingUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/SysSettingUtils.java index 13e1263..91001cd 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/SysSettingUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/SysSettingUtils.java @@ -8,6 +8,7 @@ import android.content.Intent; import android.os.Build; import android.provider.Settings; import android.text.TextUtils; +import android.util.Log; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; @@ -55,7 +56,7 @@ public class SysSettingUtils { setBrowserInput(context, jsonObject); //otg开关 // int setting_otg = changeNum(jsonObject.getInteger("setting_otg")); -// Logutils.e("SystemSetting", "setting_otg---------" + setting_otg); +// Logutils.e(TAG, "setting_otg---------" + setting_otg); // String otgStatus = ""; // switch (setting_otg) { // case 0: @@ -73,6 +74,7 @@ public class SysSettingUtils { * @param context 关闭所有功能 */ public static void setDisableSetting(Context context) { + ToastUtil.betaShow("关闭所有功能"); Logutils.e("setDisableSetting", "Close all settings: "); setPhoneList(context, 1); setUSBstate(context, 1); @@ -85,8 +87,10 @@ public class SysSettingUtils { setWallpaper(context, 0); setCanReset(context, 1); setAutoTime(context, 1); - setBrowserInput(context, 0); - JGYUtils.getInstance().setDeveloperOptions(1); + setBrowserInput(context, 1); + if (!BuildConfig.DEBUG) { + JGYUtils.getInstance().setDeveloperOptions(1); + } setStatusBar(context, 1); } @@ -94,6 +98,7 @@ public class SysSettingUtils { * @param context 开启所有功能 */ public static void setEnableSetting(Context context) { + ToastUtil.betaShow("打开所有功能"); setPhoneList(context, 0); // setUSBstate(context,0); setBluetooth(context, 0); @@ -113,17 +118,17 @@ public class SysSettingUtils { try { //设置电话功能,电话白名单 boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", state); - Logutils.e("SystemSetting", "qch_call_forbid:" + qch_call_forbid); + Logutils.e(TAG, "qch_call_forbid:" + qch_call_forbid); boolean qch_white_list_on = Settings.System.putInt(context.getContentResolver(), "qch_white_list_on", state); - Logutils.e("SystemSetting", "qch_white_list_on:" + qch_white_list_on); + Logutils.e(TAG, "qch_white_list_on:" + qch_white_list_on); boolean qch_white_list_Array = Settings.System.putString(context.getContentResolver(), "qch_white_list_Array", ""); // ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+qch_white_list_Array+"---"+qch_call_forbid); - Logutils.e("SystemSetting", "qch_white_list_Array:" + qch_white_list_Array + "---" + qch_white_list_Array); + Logutils.e(TAG, "qch_white_list_Array:" + qch_white_list_Array + "---" + qch_white_list_Array); boolean qch_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_sdcard_forbid_on", state); - Logutils.e("SystemSetting", "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); + Logutils.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); } catch (Exception e) { Logutils.e(TAG, "setPhoneList: " + e.getMessage()); } @@ -136,26 +141,26 @@ public class SysSettingUtils { //电话通话开关 int setting_call = changeNum(jsonObject.getInteger("setting_call")); boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", setting_call); - Logutils.e("SystemSetting", "qch_call_forbid:" + qch_call_forbid); + Logutils.e(TAG, "qch_call_forbid:" + qch_call_forbid); //电话白名单开关 int setting_phone = changeNum(jsonObject.getInteger("setting_phone")); boolean qch_white_list_on = Settings.System.putInt(context.getContentResolver(), "qch_white_list_on", setting_phone); - Logutils.e("SystemSetting", "qch_white_list_on:" + qch_white_list_on); + Logutils.e(TAG, "qch_white_list_on:" + qch_white_list_on); //白名单列表 if (setting_phone == 1) { boolean qch_white_list_Array = Settings.System.putString(context.getContentResolver(), "qch_white_list_Array", "empty"); // ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+qch_white_list_Array+"---"+qch_call_forbid); - Logutils.e("SystemSetting", "qch_white_list_Array:" + qch_white_list_Array); + Logutils.e(TAG, "qch_white_list_Array:" + qch_white_list_Array); } else { String setting_phones = jsonObject.getString("setting_phones"); boolean qch_white_list_Array = Settings.System.putString(context.getContentResolver(), "qch_white_list_Array", setting_phones); // ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+qch_white_list_Array+"---"+qch_call_forbid); - Logutils.e("SystemSetting", "qch_white_list_Array:" + qch_white_list_Array + "---" + setting_phones); + Logutils.e(TAG, "qch_white_list_Array:" + qch_white_list_Array + "---" + setting_phones); } //存储卡 int setting_memory = changeNum(jsonObject.getInteger("setting_memory")); boolean qch_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_sdcard_forbid_on", setting_memory); - Logutils.e("SystemSetting", "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); + Logutils.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); } catch (Exception e) { Logutils.e(TAG, "setPhoneList: " + e.getMessage()); } @@ -169,7 +174,7 @@ public class SysSettingUtils { if (!BuildConfig.DEBUG) { try { boolean qch_usb_choose = Settings.System.putString(context.getContentResolver(), "qch_usb_choose", "usb_charge"); - Logutils.e("SystemSetting", "qch_usb_choose:" + qch_usb_choose); + Logutils.e(TAG, "qch_usb_choose:" + qch_usb_choose); String usbStatus = "qch_action_usb_usb_charge"; Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); context.sendBroadcast(usbIntent); @@ -188,7 +193,7 @@ public class SysSettingUtils { if (!BuildConfig.DEBUG) { try { boolean qch_usb_choose = Settings.System.putString(context.getContentResolver(), "qch_usb_choose", setting_usb); - Logutils.e("SystemSetting", "qch_usb_choose---------" + qch_usb_choose); + Logutils.e(TAG, "qch_usb_choose---------" + qch_usb_choose); String usbStatus = ""; switch (setting_usb) { case "usb_charge": @@ -214,7 +219,7 @@ public class SysSettingUtils { try { boolean qch_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", state); //写入系统数据库 - Logutils.e("SystemSetting", "qch_bht_forbid_on:" + qch_bht_forbid_on); + Logutils.e(TAG, "qch_bht_forbid_on:" + qch_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (qch_bht_forbid_on) { //成功 @@ -244,7 +249,7 @@ public class SysSettingUtils { //蓝牙传输开关 boolean qch_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", setting_bht); - Logutils.e("SystemSetting", "qch_bht_forbid_on:" + qch_bht_forbid_on); + Logutils.e(TAG, "qch_bht_forbid_on:" + qch_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (qch_bht_forbid_on) { //成功 @@ -257,7 +262,7 @@ public class SysSettingUtils { String setting_context = jsonObject.getString("setting_context"); if (setting_bhtvideo == 0) { if (null != setting_context && !setting_context.equals("") && !setting_context.equals(" ") && !setting_context.equals("null")) { - Logutils.e("SystemSetting", "setting_context:" + setting_context); + Logutils.e(TAG, "setting_context:" + setting_context); Settings.System.putString(context.getContentResolver(), "qch_bhtvideo_forbid_on", setting_context); } else { Settings.System.putString(context.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty"); @@ -283,7 +288,7 @@ public class SysSettingUtils { intent.setPackage("com.android.settings"); context.sendStickyBroadcast(intent); boolean qch_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_hotspot_forbid_on", state); - Logutils.e("SystemSetting", "qch_hotspot_forbid_on:" + qch_hotspot_forbid_on); + Logutils.e(TAG, "qch_hotspot_forbid_on:" + qch_hotspot_forbid_on); } catch (Exception e) { Logutils.e(TAG, "setHotspot: " + e.getMessage()); } @@ -299,8 +304,8 @@ public class SysSettingUtils { context.sendStickyBroadcast(intent); } boolean qch_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_hotspot_forbid_on", setting_hotspot); - Logutils.e("SystemSetting", "qch_hotspot_forbid_on---------" + setting_hotspot); - Logutils.e("SystemSetting", "qch_hotspot_forbid_on---------" + qch_hotspot_forbid_on); + Logutils.e(TAG, "qch_hotspot_forbid_on---------" + setting_hotspot); + Logutils.e(TAG, "qch_hotspot_forbid_on---------" + qch_hotspot_forbid_on); } catch (Exception e) { Logutils.e(TAG, "setHotspot: " + e.getMessage()); } @@ -311,7 +316,7 @@ public class SysSettingUtils { int setting_navigation = 0; //写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示 boolean qch_hide_navigationBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_NavigationBar", setting_navigation); - Logutils.e("SystemSetting", "qch_hide_navigationBar---------" + qch_hide_navigationBar); + Logutils.e(TAG, "qch_hide_navigationBar---------" + qch_hide_navigationBar); String navigationStatus = ""; switch (setting_navigation) { @@ -333,7 +338,7 @@ public class SysSettingUtils { if (oldNum != setting_statusbar) { //写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示 boolean qch_hide_statusBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_statusBar", setting_statusbar); - Logutils.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar); + Logutils.e(TAG, "qch_hide_statusBar---------" + qch_hide_statusBar); String statusbarStatus = ""; switch (setting_statusbar) { case 0: @@ -353,7 +358,7 @@ public class SysSettingUtils { int setting_navigation = changeNum(jsonObject.getInteger("setting_navigation")); //写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示 boolean qch_hide_navigationBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_NavigationBar", setting_navigation); - Logutils.e("SystemSetting", "qch_hide_navigationBar---------" + qch_hide_navigationBar); + Logutils.e(TAG, "qch_hide_navigationBar---------" + qch_hide_navigationBar); String navigationStatus = ""; switch (setting_navigation) { @@ -374,7 +379,7 @@ public class SysSettingUtils { if (oldNum != setting_statusbar) { //写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示 boolean qch_hide_statusBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_statusBar", setting_statusbar); - Logutils.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar); + Logutils.e(TAG, "qch_hide_statusBar---------" + qch_hide_statusBar); String statusbarStatus = ""; switch (setting_statusbar) { case 0: @@ -393,9 +398,9 @@ public class SysSettingUtils { try { //摄像头开关 boolean qch_app_camera = Settings.System.putInt(context.getContentResolver(), "qch_app_camera", state); - Logutils.e("SystemSetting", "qch_app_camera1:" + state); + Logutils.e(TAG, "qch_app_camera1:" + state); // ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera"); - Logutils.e("SystemSetting", "setting_camera---------" + qch_app_camera); + Logutils.e(TAG, "setting_camera---------" + qch_app_camera); String cameraStatus = "qch_camera_forbid"; switch (state) { case 0: @@ -417,9 +422,9 @@ public class SysSettingUtils { //摄像头开关 int setting_camera = changeNum(jsonObject.getInteger("setting_camera")); Settings.System.putInt(context.getContentResolver(), "qch_app_camera", setting_camera); - Logutils.e("SystemSetting", "qch_app_camera2:" + setting_camera); + Logutils.e(TAG, "qch_app_camera2:" + setting_camera); // ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera"); - Logutils.e("SystemSetting", "setting_camera---------" + setting_camera); + Logutils.e(TAG, "setting_camera---------" + setting_camera); String cameraStatus = ""; switch (setting_camera) { case 0: @@ -441,7 +446,7 @@ public class SysSettingUtils { //tfmedia开关 // int setting_tfmedia = 1; boolean qch_tfmedia_forbid = Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", state); - Logutils.e("SystemSetting", "setting_tfmedia---------" + qch_tfmedia_forbid); + Logutils.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid); String tfmediaStatus = ""; switch (state) { case 0: @@ -455,7 +460,7 @@ public class SysSettingUtils { context.sendBroadcast(tfmediaIntent); if (state == 1) { boolean qch_tfmedia_filetypes = Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", "Empty");//影音管控 - Logutils.e("SystemSetting", "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes); + Logutils.e(TAG, "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes); } else { Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0); } @@ -464,23 +469,28 @@ public class SysSettingUtils { } } + /** + * @param context + * @param jsonObject + * tfmedia开关 + */ private static void setTF(Context context, JSONObject jsonObject) { try { - //tfmedia开关 - // TODO: 2021/5/24 正式后台暂时无法修改 int setting_tfmedia = jsonObject.getInteger("setting_tfmedia"); - if (JGYUtils.isOfficialVersion() || JGYUtils.isBetaVersion()) { - setting_tfmedia = changeNum(setting_tfmedia); - } +// if (JGYUtils.isOfficialVersion() ) { +// setting_tfmedia = changeNum(setting_tfmedia); +// } boolean qch_tfmedia_forbid = Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", setting_tfmedia); - Logutils.e("SystemSetting", "setting_tfmedia---------" + qch_tfmedia_forbid); + Logutils.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid); String tfmediaStatus = ""; switch (setting_tfmedia) { case 0: + Logutils.e(TAG, "setting_tfmedia: " + "打开"); tfmediaStatus = "qch_tfmedia_open"; break; case 1: + Logutils.e(TAG, "setting_tfmedia: " + "禁止"); tfmediaStatus = "qch_tfmedia_forbid"; break; } @@ -497,12 +507,12 @@ public class SysSettingUtils { } stringBuffer.deleteCharAt(stringBuffer.length() - 1); Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控 - Logutils.e("SystemSetting", "qch_tfmedia_filetypes---------" + stringBuffer.toString()); + Logutils.e(TAG, "qch_tfmedia_filetypes---------" + stringBuffer.toString()); } else { Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0); } } catch (Exception e) { - Logutils.e("SystemSetting", "setTF: " + e.getMessage()); + Logutils.e(TAG, "setTF: " + e.getMessage()); } } @@ -514,22 +524,22 @@ public class SysSettingUtils { // int deskclock = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", state); ApkUtils.hideSystemSettingAPP(context, "com.android.deskclock"); - Logutils.e("SystemSetting", "qch_app_deskclock" + state); + Logutils.e(TAG, "qch_app_deskclock" + state); //录音机 // int soundrecorder = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", state); ApkUtils.hideSystemSettingAPP(context, "com.android.soundrecorder"); - Logutils.e("SystemSetting", "qch_app_soundrecorder" + state); + Logutils.e(TAG, "qch_app_soundrecorder" + state); //音乐 // int music = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_music", state); ApkUtils.hideSystemSettingAPP(context, "com.android.music"); - Logutils.e("SystemSetting", "qch_app_music" + state); + Logutils.e(TAG, "qch_app_music" + state); //图库 // int gallery = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", state); ApkUtils.hideSystemSettingAPP(context, "com.android.gallery3d"); - Logutils.e("SystemSetting", "qch_app_gallery" + state); + Logutils.e(TAG, "qch_app_gallery" + state); //文件管理器 // int filemanager = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", state); @@ -538,7 +548,7 @@ public class SysSettingUtils { } else { ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui"); } - Logutils.e("SystemSetting", "qch_app_filemanager" + state); + Logutils.e(TAG, "qch_app_filemanager" + state); } catch (Exception e) { Logutils.e(TAG, "setIcon: " + e.getMessage()); } @@ -552,22 +562,22 @@ public class SysSettingUtils { int deskclock = changeNum(jsonObject.getInteger("setting_clock")); Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", deskclock); ApkUtils.hideSystemSettingAPP(context, "com.android.deskclock"); - Logutils.e("SystemSetting", "qch_app_deskclock" + deskclock); + Logutils.e(TAG, "qch_app_deskclock" + deskclock); //录音机 int soundrecorder = changeNum(jsonObject.getInteger("setting_recording")); Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", soundrecorder); ApkUtils.hideSystemSettingAPP(context, "com.android.soundrecorder"); - Logutils.e("SystemSetting", "qch_app_soundrecorder" + soundrecorder); + Logutils.e(TAG, "qch_app_soundrecorder" + soundrecorder); //音乐 int music = changeNum(jsonObject.getInteger("setting_music")); Settings.System.putInt(context.getContentResolver(), "qch_app_music", music); ApkUtils.hideSystemSettingAPP(context, "com.android.music"); - Logutils.e("SystemSetting", "qch_app_music" + music); + Logutils.e(TAG, "qch_app_music" + music); //图库 int gallery = changeNum(jsonObject.getInteger("setting_picture")); Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", gallery); ApkUtils.hideSystemSettingAPP(context, "com.android.gallery3d"); - Logutils.e("SystemSetting", "qch_app_gallery" + gallery); + Logutils.e(TAG, "qch_app_gallery" + gallery); //壁纸 int wallpaper = changeNum(jsonObject.getInteger("setting_wallpaper")); setWallpaper(context, wallpaper); @@ -579,7 +589,7 @@ public class SysSettingUtils { } else { ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui"); } - Logutils.e("SystemSetting", "qch_app_filemanager" + filemanager); + Logutils.e(TAG, "qch_app_filemanager" + filemanager); } catch (Exception e) { Logutils.e(TAG, "setIcon: " + e.getMessage()); } @@ -589,12 +599,12 @@ public class SysSettingUtils { //壁纸 // int wallpaper = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_wallpaper", state); - Logutils.e("SystemSetting", "qch_app_wallpaper" + state); + Logutils.e(TAG, "qch_app_wallpaper" + state); } private static void setCanReset(Context context, int state) { boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0); - Logutils.e("SystemSetting", "qch_restore_forbid_on:" + qch_restore_forbid_on); + Logutils.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); //默认打开 } @@ -604,10 +614,10 @@ public class SysSettingUtils { int mode = jsonObject.getInteger("qch_restore"); if (mode == 1) { boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0); - Logutils.e("SystemSetting", "qch_restore_forbid_on:" + qch_restore_forbid_on); + Logutils.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); } else { boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 1); - Logutils.e("SystemSetting", "qch_restore_forbid_on:" + qch_restore_forbid_on); + Logutils.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); } } @@ -649,7 +659,7 @@ public class SysSettingUtils { break; } } - Logutils.e("SystemSetting", "setAutoTime: " + "action=" + action); + Logutils.e(TAG, "setAutoTime: " + "action=" + action); Intent intent = new Intent(); intent.setAction(action); intent.setPackage("com.android.settings"); @@ -657,7 +667,7 @@ public class SysSettingUtils { } private static void setAutoTime(Context context, int state) { - Logutils.e("SystemSetting", "setAutoTime: " + "default"); + Logutils.e(TAG, "setAutoTime: " + "default"); Intent intent = new Intent(); intent.setAction("qch_autotime_network"); intent.setPackage("com.android.settings"); diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/TimeUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/TimeUtils.java index 40a5e4d..9d765b5 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/TimeUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/TimeUtils.java @@ -2,7 +2,9 @@ package com.mjsheng.myappstore.utils; import android.content.Context; import android.content.Intent; + import androidx.annotation.NonNull; + import android.text.TextUtils; @@ -65,7 +67,7 @@ public class TimeUtils { public static ContralTime getDefaltContralTime(Context context) { String startTime = (String) SPUtils.get(context, START_TIME_KEY, "00:00"); String endTime = (String) SPUtils.get(context, END_TIME_KEY, "00:00"); - if (null == startTime || null == endTime || (startTime.equals("00:00") && endTime.equals("00:00"))) { + if (null == startTime || null == endTime || ("00:00".equals(startTime) && "00:00".equals(endTime))) { return null; } else { try { @@ -94,15 +96,15 @@ public class TimeUtils { public static class ContralTime { //format HH:mm - static String startTime; - static String endTime; + String startTime; + String endTime; public ContralTime() { } public ContralTime(String startT, String endT) { - startTime = startT; + this.startTime = startT; endTime = endT; } @@ -112,7 +114,7 @@ public class TimeUtils { public void setStartTime(String startT) { - startTime = startT; + this.startTime = startT; } public String getEndTime() { @@ -120,7 +122,7 @@ public class TimeUtils { } public void setEndTime(String endT) { - endTime = endT; + this.endTime = endT; } public static DateFormat getDf() { diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/ToastUtil.java b/app/src/main/java/com/mjsheng/myappstore/utils/ToastUtil.java index acbbe1b..84bff17 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/ToastUtil.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/ToastUtil.java @@ -15,9 +15,11 @@ import com.mjsheng.myappstore.BuildConfig; */ public class ToastUtil { - private static Handler mainHandler = new Handler(Looper.getMainLooper()); - private static Toast toast; + @SuppressLint("StaticFieldLeak") private static Context mContext; + private static Handler mainHandler = new Handler(Looper.getMainLooper()); + private static Toast debugToast; + private static Toast toast; @SuppressLint("ShowToast") public static void init(Context context) { @@ -31,25 +33,35 @@ public class ToastUtil { private static long time2 = 0L; public static void show(final String msg) { - mainHandler.post(new Runnable() { - @Override - public void run() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - time2 = System.currentTimeMillis(); - if ((time2 - time1) > 3500) { - showToast(mContext, msg, Toast.LENGTH_SHORT); - Logutils.e("fht", "LENGTH_LONG"); - time1 = time2; - } - } else { - if (toast != null) { - toast.setText(msg); - toast.show(); - } + mainHandler.post(() -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + time2 = System.currentTimeMillis(); + if ((time2 - time1) > 3500) { + showToast(mContext, msg, Toast.LENGTH_SHORT); + time1 = time2; + } + } else { + if (toast != null) { + toast.setText(msg); + toast.show(); } } }); + } + public static void betaShow(final String msg) { + if (JGYUtils.isBetaVersion() || BuildConfig.DEBUG) { + mainHandler.post(() -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + showToast(mContext, msg, Toast.LENGTH_SHORT); + } else { + if (debugToast != null) { + debugToast.setText(msg); + debugToast.show(); + } + } + }); + } } private static Toast mToast = null; @@ -80,21 +92,6 @@ public class ToastUtil { // } // }); // } - static Handler debugHandler = new Handler(Looper.getMainLooper()); - static Toast debugToast; - public static void debugShow(final String msg) { - mainHandler.post(new Runnable() { - @Override - public void run() { - if (BuildConfig.DEBUG) { - if (toast != null) { - toast.setText(msg); - toast.show(); - } - } - } - }); - } } diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/URLUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/URLUtils.java index 62e6c78..690e00c 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/URLUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/URLUtils.java @@ -4,14 +4,13 @@ import android.content.Context; import android.os.Build; import android.provider.Settings; import android.text.TextUtils; +import android.util.Log; import android.webkit.WebSettings; import java.io.IOException; import java.net.URI; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -37,17 +36,21 @@ public class URLUtils { } public void setBrowserWhiteList() { - String whiteList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray"); - if (TextUtils.isEmpty(whiteList.trim())) { + //会写入两次,第一次是不带前缀的,第二次会把实际的地址写入进去 + String oldwhiteList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray"); + if (TextUtils.isEmpty(oldwhiteList)) { Logutils.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is empty"); + Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray","Invalid"); } else { - Logutils.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is : " + whiteList); - HashSet URLList = new HashSet<>(Arrays.asList(whiteList.split(","))); + Logutils.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is : " + oldwhiteList); + HashSet URLList = new HashSet<>(Arrays.asList(oldwhiteList.trim().split(","))); + Log.e(TAG, "setBrowserWhiteList: " + URLList); Observable.create(new ObservableOnSubscribe() { @Override public void subscribe(ObservableEmitter emitter) throws Exception { baseURLList.clear(); for (String url : URLList) { + Log.e(TAG, "subscribe: " + url); if (TextUtils.isEmpty(url)) { continue; } @@ -63,7 +66,32 @@ public class URLUtils { // } // }else { // } - baseURLList.add("https://" + url); + + if (!url.startsWith("http")) { + String httpsUrl = "https://" + url; + String httpUrl = "http://" + url; + emitter.onNext(getOkHttpURL(httpsUrl)); + emitter.onNext(getOkHttpURL(httpUrl)); + baseURLList.add(httpsUrl); + String pattern = "(http|https)://(www.)?(\\w+(\\.)?)+"; + Pattern r = Pattern.compile(pattern); + Matcher m = r.matcher(httpsUrl); + while (m.find()) { + baseURLList.add(m.group()); + } + }else { + String pattern = "[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\\.?"; + Pattern r = Pattern.compile(pattern); + Matcher m = r.matcher(url); + if (m.find()) { + Log.e(TAG, "matcher: " + m.group()); + String httpsUrl = "https://" + m.group(); + String httpUrl = "http://" + m.group(); + emitter.onNext(getOkHttpURL(httpsUrl)); + emitter.onNext(getOkHttpURL(httpUrl)); + } + } + // if (url.startsWith("www.")) {//前缀为www的顶级域名 // String nowww = url.substring(4); // baseURLList.add(nowww); @@ -113,7 +141,7 @@ public class URLUtils { @Override public void onNext(String s) { Logutils.e(TAG, "onNext: " + s); -// baseURLList.add(s); + baseURLList.add(s); // if (s.startsWith("http://")) { // String noHttp = s.substring(7); // Logutils.e(TAG, "onNext: noHttp: " + noHttp); @@ -148,20 +176,22 @@ public class URLUtils { } }); } - } - private HashSet blackList = new HashSet<>(); public void setBrowserBlackList() { String qch_webblack_url = Settings.System.getString(mContext.getContentResolver(), "qch_webblack_url"); - Logutils.e(TAG, "setBrowserBlackList: " + qch_webblack_url); - if (TextUtils.isEmpty(qch_webblack_url.trim())) { + Logutils.e(TAG, "setBrowserBlackList: qch_webblack_url = " + qch_webblack_url); + if (TextUtils.isEmpty(qch_webblack_url)) { + Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url","Invalid"); return; } - HashSet URLList = new HashSet<>(Arrays.asList(qch_webblack_url.split(","))); + HashSet URLList = new HashSet<>(Arrays.asList(qch_webblack_url.trim().split(","))); for (String url : URLList) { + if (TextUtils.isEmpty(url)) { + continue; + } Logutils.e(TAG, "setBrowserBlackList: url: " + url); if (qch_webblack_url.startsWith("http://")) { blackList.add(url); @@ -224,10 +254,15 @@ public class URLUtils { } } + + //https://blog.csdn.net/yong472727322/article/details/73321935 + //https://blog.csdn.net/liehuo123/article/details/81509486?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-1&spm=1001.2101.3001.4242 + //https://www.cnblogs.com/breakdown/archive/2012/09/17/2689101.html + /** * Gets ip. * 通过url获取到域名 - * + *https://www.cnblogs.com/shizhijie/p/8277092.html * @param url the url * @return the ip */ diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java b/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java index 4efb16b..c2437eb 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java @@ -2,7 +2,6 @@ package com.mjsheng.myappstore.utils; import android.annotation.SuppressLint; import android.app.ActivityManager; -import android.app.admin.DevicePolicyManager; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; @@ -10,7 +9,6 @@ import android.content.ContextWrapper; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -34,11 +32,13 @@ import android.os.StatFs; import android.provider.Settings; import androidx.annotation.RequiresApi; +import androidx.annotation.VisibleForTesting; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.text.format.Formatter; import android.util.DisplayMetrics; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; @@ -65,6 +65,7 @@ import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; import java.io.FileFilter; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; @@ -83,6 +84,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -96,6 +98,8 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import static android.content.Context.WIFI_SERVICE; + public class Utils { private static String TAG = Utils.class.getSimpleName(); @@ -106,7 +110,7 @@ public class Utils { return getMac(); } else { try { - WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiManager wifiManager = (WifiManager) context.getSystemService(WIFI_SERVICE); // 获取MAC地址 WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String mac = wifiInfo.getMacAddress(); @@ -157,6 +161,14 @@ public class Utils { return macSerial; } + public static String getAndroid10MAC(Context context) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1){ + return getMacAddress(context); + }else { + return getAndroid7MAC(); + } + } + /** * 兼容7.0获取不到的问题 * @@ -186,6 +198,64 @@ public class Utils { return ""; } + + @SuppressLint("HardwareIds") + @VisibleForTesting + public static String getMacAddress(Context mContext) { + WifiManager mWifiManager = (WifiManager) mContext.getSystemService(WIFI_SERVICE); + final String[] macAddresses = mWifiManager.getFactoryMacAddresses(); + String macAddress = null; + if (macAddresses != null && macAddresses.length > 0) { + macAddress = macAddresses[0]; + } + + if (TextUtils.isEmpty(macAddress)) { + String mac = getMacFromFile(); + // Add for CTCC Feature:WIFI MAC should be gotten while wifi disabled. + // Get Wifi MAC from file since we can not get it with WifiManager. + if (!TextUtils.isEmpty(mac)) { + macAddress = mac; + } else { + macAddress = "未能获取到MAC地址"; + } + } + return macAddress; + } + + /** + * Add for CTCC Feature:WIFI MAC should be gotten while wifi disabled. + * get Wifi MAC from /mnt/vendor/wifimac.txt + * + * @{ + */ + private static String MACID_FILE_PATH = "/mnt/vendor/wifimac.txt"; + + private static String getMacFromFile() { + File file = new File(MACID_FILE_PATH); + BufferedReader reader = null; + String macAddress = null; + try { + reader = new BufferedReader(new FileReader(file)); + String line; + while ((line = reader.readLine()) != null) { + macAddress = line; + break; + } + } catch (FileNotFoundException e) { + Log.w(TAG, "Mac file not exist", e); + } catch (Exception e) { + Log.w(TAG, "get mac from file caught exception", e); + } finally { + try { + if (reader != null) + reader.close(); + } catch (IOException e) { + Log.w(TAG, "reader close exception"); + } + } + return macAddress; + } + public static String loadFileAsString(String fileName) throws Exception { FileReader reader = new FileReader(fileName); String text = loadReaderAsString(reader); @@ -636,6 +706,40 @@ public class Utils { return serial; } + public static String getDeviceSN() { + String serial = null; + try { + Class c = Class.forName("android.os.SystemProperties"); + Method get = c.getMethod("get", String.class); + serial = (String) get.invoke(c, "persist.sys.hrSerial"); + } catch (Exception e) { + e.printStackTrace(); + } + return serial; + } + + /** + * @return 获取第三方内置apk + */ + public static HashSet getPackage() { + String packages = ""; + try { + Class c = Class.forName("android.os.SystemProperties"); + Method get = c.getMethod("get", String.class); + packages = (String) get.invoke(c, "persist.sys.package"); + } catch (Exception e) { + e.printStackTrace(); + } + HashSet packageSet = new HashSet<>(); + if (TextUtils.isEmpty(packages)) { + return packageSet; + } else { + packageSet.addAll(Arrays.asList(packages.split(","))); + return packageSet; + } + } + + public static final long A_GB = 1073741824; public static final long A_MB = 1048576; public static final int A_KB = 1024; @@ -845,7 +949,7 @@ public class Utils { * 更新应用白名单禁止升级 * * @param context - * @param allowList 禁止 + * @param allowList 禁止 * @param disallowList 允许 * @return */ diff --git a/build.gradle b/build.gradle index aadc452..3b2f1c9 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,10 @@ buildscript { repositories { google() - jcenter() + mavenCentral() + maven { url "https://jitpack.io" } + maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } + maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } dependencies { classpath 'com.android.tools.build:gradle:3.6.4' @@ -16,11 +19,11 @@ buildscript { allprojects { repositories { + //jcenter即将关闭 google() - jcenter() - } - repositories { - maven { url 'https://jitpack.io' } + mavenCentral() + maven { url "https://jitpack.io" } + maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } gradle.projectsEvaluated { diff --git a/教管壹更新日志.txt b/教管壹更新日志.txt new file mode 100644 index 0000000..cbd5a0a --- /dev/null +++ b/教管壹更新日志.txt @@ -0,0 +1,30 @@ +更新: +2021-08-04 17:19:09 +设备信息: +1.白名单网址获取重定向后的地址 +2.增加获取随机mac地址 +3.MAC地址显示为设备MAC +4.发送禁止联网的包名时如果应用未安装会断网 +5.修复平板使用时间管控到时间不会解锁的bug +应用市场: + +更新: +2021-07-29 18:18:28 +v2.2.1 + +设备信息: +1.删除所有白名单之外的APK,如果能正确获取到白名单数据就删除,如果获取失败或者网络错误则不删除 +2.监听网络变化,如果可以联网直接获取数据,不用等待 +3.当打开了应用市场的时候,唤醒设备信息直接获取数据 +4.减少更新设备系统信息的频率 +5.应用内网页管控更新 +6.亮屏请求间隔为3个小时 +7.桌面图标隐藏显示延迟修复 +8.删除管控默认关闭功能 +9.浏览器主页自动添加到白名单 +10.修复删除系统其他管控,重启之后是上一个的管控 +11.没有设置白名单时主页无法访问 +12.修复重启偶尔会删除禁止升级的应用 + +应用市场: +1.优化应用安装后广播逻辑 \ No newline at end of file