diff --git a/app/build.gradle b/app/build.gradle index 8686166..815045e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.application' def appName() { - return "DeviceInfo" + return "AoleyunDeviceInfo" } def releaseTime() { @@ -9,13 +9,35 @@ def releaseTime() { } android { + gradle.projectsEvaluated { + tasks.withType(JavaCompile) { + Set fileSet = options.bootstrapClasspath.getFiles() + List newFileList = new ArrayList<>(); + //JAVA语法,可连续调用,输入参数建议为相对路径 + newFileList.add(new File("libs/framework.jar")) + //最后将原始参数添加 + newFileList.addAll(fileSet) + options.bootstrapClasspath = files( + newFileList.toArray() + ) + } + } + compileSdkVersion 29 + buildToolsVersion "30.0.3" + defaultConfig { applicationId "com.aoleyun.sn" - minSdkVersion 24 + minSdkVersion 26 targetSdkVersion 29 multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + ndk { + //选择要添加的对应 cpu 类型的 .so 库。 + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86' + // 还可以添加 'armeabi' , 'x86', 'x86_64', 'mips', 'mips64' + } } lintOptions { @@ -36,8 +58,8 @@ android { //新平台正式 newly { flavorDimensions "default" - versionCode 1 - versionName "1.0" + versionCode 5 + versionName "1.4" /*********************************极光推送************************************/ manifestPlaceholders = [ JPUSH_PKGNAME: "com.aoleyun.sn", @@ -259,7 +281,7 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - compileOnly files('src/main/libs/classes.jar') + compileOnly files('libs/framework.jar') implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'androidx.recyclerview:recyclerview:1.2.1' @@ -292,6 +314,9 @@ dependencies { //Google implementation 'com.google.code.gson:gson:2.8.7' implementation 'com.google.zxing:core:3.3.0' + //图片加载框架 + implementation 'com.github.bumptech.glide:glide:4.11.0' + annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' //fastjson implementation 'com.alibaba:fastjson:1.2.76' //极光推送 @@ -337,6 +362,7 @@ dependencies { preBuild { doLast { def imlFile = file(project.name + ".iml") +// def imlFile = file("..\\.idea\\modules\\" + project.name + "\\" + rootProject.name + "." + project.name + ".iml") println 'Change ' + project.name + '.iml order' try { def parsedXml = (new XmlParser()).parse(imlFile) @@ -353,5 +379,7 @@ preBuild { } //https://www.pianshen.com/article/93481144911/ //https://blog.csdn.net/dhl_1986/article/details/102856026 + //https://blog.csdn.net/zhonghe1114/article/details/80923730 + //https://blog.csdn.net/u014175785/article/details/116235760 //使用系统编译后的framework.jar } diff --git a/app/src/main/libs/classes.jar b/app/libs/framework.jar similarity index 100% rename from app/src/main/libs/classes.jar rename to app/libs/framework.jar diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 583d6a0..462b970 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ @@ -9,6 +10,7 @@ + @@ -21,25 +23,28 @@ - - + + + tools:ignore="ProtectedPermissions" /> + + tools:ignore="ProtectedPermissions" /> + + android:protectionLevel="signature" /> + @@ -58,13 +63,15 @@ android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" android:maxSdkVersion="23" /> - - + + + + - + - + @@ -72,8 +79,10 @@ - - + + + + @@ -88,7 +97,7 @@ android:requestLegacyExternalStorage="true" android:supportsRtl="true" android:theme="@style/AppTheme"> - + @@ -98,11 +107,12 @@ - + android:launchMode="singleTop" /> - + + - + + + + + + + + + + + + + + + + @@ -134,12 +161,14 @@ + + - + + + tools:replace="android:exported" /> + - + + - + + + tools:replace="android:authorities" /> + - + + + tools:replace="android:authorities" /> + + android:exported="false" /> + - + + - + + - + + @@ -364,14 +404,17 @@ + android:value="developer-default" /> + + android:value="${JPUSH_APPKEY}" /> + + android:value="${AMAP_KEY}" /> + @@ -379,6 +422,9 @@ + \ No newline at end of file diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index a85bbf6..881107f 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -32,7 +32,7 @@ 3、只对新的多线程下载任务有效 4、只对多线程的任务有效 --> - + onReceive(), action=" + action); + Log.e(TAG, " -->onReceive(), action=" + action); // if (Utils.isServiceOnDestroying()) { // Utils.logw(TAG, "Service is On Destroying, juet do nothing for " + action); // return; @@ -43,7 +42,7 @@ public class LogReceiver extends BroadcastReceiver { receiverHandler.obtainMessage(ReceiverHandler.MSG_RECEIVER_FROM_BYPASS, intent).sendToTarget(); } - Logutils.e(TAG, " OnReceive function exit."); + Log.e(TAG, " OnReceive function exit."); } } diff --git a/app/src/main/java/com/aoleyun/sn/manager/AmapManager.java b/app/src/main/java/com/aoleyun/sn/manager/AmapManager.java index 1291187..42ceeba 100644 --- a/app/src/main/java/com/aoleyun/sn/manager/AmapManager.java +++ b/app/src/main/java/com/aoleyun/sn/manager/AmapManager.java @@ -1,12 +1,12 @@ package com.aoleyun.sn.manager; import android.content.Context; +import android.util.Log; import com.amap.api.location.AMapLocation; import com.amap.api.location.AMapLocationClient; import com.amap.api.location.AMapLocationClientOption; import com.amap.api.location.AMapLocationListener; -import com.aoleyun.sn.utils.Logutils; import com.aoleyun.sn.utils.SPUtils; public class AmapManager { @@ -64,8 +64,8 @@ public class AmapManager { StringBuilder sb = new StringBuilder(); //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明 if (aMapLocation.getErrorCode() == 0) { - Logutils.e(TAG, "onLocationChanged: " + "定位成功"); - Logutils.e(TAG, "onLocationChanged: " + aMapLocation.getAddress()); + Log.e(TAG, "onLocationChanged: " + "定位成功"); + Log.e(TAG, "onLocationChanged: " + aMapLocation.getAddress()); sb.append(aMapLocation.getAddress()).append("\n"); SPUtils.put(mContext, "AmapAddress", aMapLocation.getAddress()); SPUtils.put(mContext, "longitude", aMapLocation.getLongitude()); @@ -73,17 +73,17 @@ public class AmapManager { } else { //定位失败 sb.append("定位失败" + "\n"); - Logutils.e(TAG, "onLocationChanged: " + "定位失败"); + Log.e(TAG, "onLocationChanged: " + "定位失败"); SPUtils.put(mContext, "AmapError", String.valueOf(aMapLocation.getErrorInfo())); } - Logutils.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-")); - Logutils.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-")); - Logutils.e(TAG, "amap: " + sb.toString()); + Log.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-")); + Log.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-")); + Log.e(TAG, "amap: " + sb.toString()); } }); //设置场景模式后最好调用一次stop,再调用start以保证场景模式生效 locationClient.stopLocation(); locationClient.startLocation(); - Logutils.e(TAG, "initAmap: " + "startLocation"); + Log.e(TAG, "initAmap: " + "startLocation"); } } diff --git a/app/src/main/java/com/aoleyun/sn/manager/FileManager.java b/app/src/main/java/com/aoleyun/sn/manager/FileManager.java index cb94b60..6d7243c 100644 --- a/app/src/main/java/com/aoleyun/sn/manager/FileManager.java +++ b/app/src/main/java/com/aoleyun/sn/manager/FileManager.java @@ -1,9 +1,10 @@ package com.aoleyun.sn.manager; import android.content.Context; +import android.util.Log; +import com.aoleyun.sn.utils.JGYUtils; import com.blankj.utilcode.util.PathUtils; -import com.aoleyun.sn.utils.Logutils; import java.io.File; @@ -31,12 +32,12 @@ public class FileManager { } private static void initFolder() { - File file = new File(PathUtils.getExternalDownloadsPath() + File.separator + "jgy" + File.separator); + File file = new File(JGYUtils.getInstance().getDownLoadPath()); if (!file.exists()) { if (file.mkdirs()) { - Logutils.e("initFolder", "initFolder: success"); + Log.e("initFolder", "initFolder: success"); } else { - Logutils.e("initFolder", "initFolder: failed"); + Log.e("initFolder", "initFolder: failed"); } } } diff --git a/app/src/main/java/com/aoleyun/sn/network/HTTPInterface.java b/app/src/main/java/com/aoleyun/sn/network/HTTPInterface.java index dcc7914..2b81916 100644 --- a/app/src/main/java/com/aoleyun/sn/network/HTTPInterface.java +++ b/app/src/main/java/com/aoleyun/sn/network/HTTPInterface.java @@ -1,6 +1,8 @@ package com.aoleyun.sn.network; import android.annotation.SuppressLint; +import android.app.AlarmManager; +import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; @@ -13,10 +15,13 @@ import android.util.Log; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.aoleyun.sn.BuildConfig; import com.aoleyun.sn.action.JGYActions; +import com.aoleyun.sn.bean.PoweroffBean; +import com.aoleyun.sn.bean.SnRunLog; +import com.aoleyun.sn.bean.WiFiAlias; import com.aoleyun.sn.network.api.newapi.GetPublicIPApi; -import com.aoleyun.sn.network.api.newapi.SendScreenStatusApi; +import com.aoleyun.sn.service.LogcatService; +import com.aoleyun.sn.utils.WiFiUtils; import com.arialyy.aria.core.Aria; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -30,7 +35,6 @@ import com.aoleyun.sn.bean.ForceDownloadBean; import com.aoleyun.sn.bean.ForceDownloadData; import com.aoleyun.sn.utils.CacheUtils; import com.aoleyun.sn.utils.JGYUtils; -import com.aoleyun.sn.utils.Logutils; import com.aoleyun.sn.utils.URLUtils; import com.aoleyun.sn.bean.Appground; import com.aoleyun.sn.bean.BaseResponse; @@ -45,9 +49,11 @@ import com.aoleyun.sn.utils.ForegroundAppUtil; import com.aoleyun.sn.utils.SPUtils; import com.aoleyun.sn.utils.TimeUtils; import com.aoleyun.sn.utils.Utils; +import com.tencent.mmkv.MMKV; import java.io.IOException; import java.lang.reflect.Type; +import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -62,7 +68,6 @@ import okhttp3.ResponseBody; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; -import retrofit2.http.GET; import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.ACTION_SET; import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.sequence; @@ -91,7 +96,7 @@ public class HTTPInterface { if (packageInfo == null || packageInfo.versionCode < versionCode) { Utils.ariaDownload(context, url, object); } else { - Logutils.e("installTestAPK", "APK: " + "无更新"); + Log.e("installTestAPK", "APK: " + "无更新"); } } @@ -101,7 +106,7 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - Logutils.e(TAG + ":" + "setJpushTags", "onSubscribe: "); + Log.e(TAG + ":" + "setJpushTags", "onSubscribe: "); } @Override @@ -109,7 +114,7 @@ public class HTTPInterface { if (response.code == 200) { JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject(); String batch = jsonObject.get("batch").getAsString(); - Logutils.e(TAG + ":" + "setJpushTags", "onNext: " + batch); + Log.e(TAG + ":" + "setJpushTags", "onNext: " + batch); if (!TextUtils.isEmpty(batch)) { Set set = new HashSet(); set.add(batch); @@ -125,22 +130,22 @@ public class HTTPInterface { }); setTag(context, set); } else { - Logutils.e(TAG + ":" + "setJpushTags", "onNext: " + "batch empty"); + Log.e(TAG + ":" + "setJpushTags", "onNext: " + "batch empty"); } } else { - Logutils.e(TAG + ":" + "setJpushTags", "onNext: " + response.toString()); + Log.e(TAG + ":" + "setJpushTags", "onNext: " + response.toString()); } } @Override public void onError(@NonNull Throwable e) { - Logutils.e(TAG + ":" + "setJpushTags", "onError: " + e.getMessage()); + Log.e(TAG + ":" + "setJpushTags", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e(TAG + ":" + "setJpushTags", "onComplete: "); + Log.e(TAG + ":" + "setJpushTags", "onComplete: "); } }); } @@ -160,10 +165,10 @@ public class HTTPInterface { synchronized public static void getAppinsideWeb(Context context, GetAppinsideWebCallback callback) { if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.MTKPlatform) { - Logutils.e(TAG, "getAppinsideWeb: " + "setAppinsideWeb"); + Log.e(TAG, "getAppinsideWeb: " + "setAppinsideWeb"); setAppinsideWeb(callback); } else { - Logutils.e(TAG, "getAppinsideWeb: " + "setNewAppinsideWeb"); + Log.e(TAG, "getAppinsideWeb: " + "setNewAppinsideWeb"); setNewAppinsideWeb(callback); // setAppinsideWeb(callback); } @@ -176,24 +181,24 @@ public class HTTPInterface { .subscribe(new Observer>>() { @Override public void onSubscribe(@NonNull Disposable d) { - Logutils.e("setAppinsideWeb", "onSubscribe: "); + Log.e("setAppinsideWeb", "onSubscribe: "); } @Override public void onNext(@NonNull BaseResponse> listBaseResponse) { - Logutils.e("setAppinsideWeb", "onNext: " + listBaseResponse); + Log.e("setAppinsideWeb", "onNext: " + listBaseResponse); JGYUtils.getInstance().setAppinsideWeb(listBaseResponse); } @Override public void onError(@NonNull Throwable e) { - Logutils.e("setAppinsideWeb", "onError: " + e.getMessage()); + Log.e("setAppinsideWeb", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e("setAppinsideWeb", "onComplete: "); + Log.e("setAppinsideWeb", "onComplete: "); callback.onComplete(); } }); @@ -206,26 +211,26 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - Logutils.e("getNewAppinsideWeb", "onSubscribe: "); + Log.e("getNewAppinsideWeb", "onSubscribe: "); } @Override public void onNext(@NonNull BaseResponse listBaseResponse) { - Logutils.e("getNewAppinsideWeb", "onNext: " + listBaseResponse); + Log.e("getNewAppinsideWeb", "onNext: " + listBaseResponse); long time1 = System.currentTimeMillis(); JGYUtils.getInstance().setNewAppinsideWeb(listBaseResponse); - Logutils.e(TAG, "setWhiteApp: time = " + (System.currentTimeMillis() - time1)); + Log.e(TAG, "setWhiteApp: time = " + (System.currentTimeMillis() - time1)); } @Override public void onError(@NonNull Throwable e) { - Logutils.e("getNewAppinsideWeb", "onError: " + e.getMessage()); + Log.e("getNewAppinsideWeb", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e("getNewAppinsideWeb", "onComplete: "); + Log.e("getNewAppinsideWeb", "onComplete: "); callback.onComplete(); } }); @@ -254,12 +259,12 @@ public class HTTPInterface { .subscribe(new Observer>() { @Override public void onSubscribe(Disposable d) { - Logutils.e("setBrowserBlackList", "onSubscribe: "); + Log.e("setBrowserBlackList", "onSubscribe: "); } @Override public void onNext(BaseResponse browserDataBaseResponse) { - Logutils.e("setBrowserBlackList", "onNext: "); + Log.e("setBrowserBlackList", "onNext: "); String homePage = Settings.System.getString(context.getContentResolver(), "homepagURL"); if (browserDataBaseResponse.code == 200) { BrowserData data = browserDataBaseResponse.data; @@ -269,14 +274,14 @@ public class HTTPInterface { white += "," + homePage; } boolean DeselectBrowserArray = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white); - Logutils.e("setBrowserBlackList", "setBrowserList white = " + white + ":" + DeselectBrowserArray); + Log.e("setBrowserBlackList", "setBrowserList white = " + white + ":" + DeselectBrowserArray); } else { Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", homePage); } String black = data.getBlack(); if (!TextUtils.isEmpty(black)) { boolean qch_webblack_url = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black); - Logutils.e("setBrowserBlackList", "setBrowserList black = " + black + ":" + qch_webblack_url); + Log.e("setBrowserBlackList", "setBrowserList black = " + black + ":" + qch_webblack_url); } else { Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " "); } @@ -302,13 +307,13 @@ public class HTTPInterface { @Override public void onError(Throwable e) { - Logutils.e("setBrowserBlackList", "onError: " + e.getMessage()); + Log.e("setBrowserBlackList", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e("setBrowserBlackList", "onComplete: "); + Log.e("setBrowserBlackList", "onComplete: "); new URLUtils(context).setBrowserWhiteList(); new URLUtils(context).setBrowserBlackList(); } @@ -340,7 +345,7 @@ public class HTTPInterface { if (callback != null) { callback.onSubscribe(); } - Logutils.e("getHomePageBookmarks", "onSubscribe: "); + Log.e("getHomePageBookmarks", "onSubscribe: "); } @Override @@ -348,37 +353,37 @@ public class HTTPInterface { if (callback != null) { callback.onNext(); } - Logutils.e("getHomePageBookmarks", "onNext: "); + Log.e("getHomePageBookmarks", "onNext: "); if (browserBookmarksBaseResponse.code == 200) { //主页不包含白名单添加进去 String homepagURL = browserBookmarksBaseResponse.data.getHomepage(); - Logutils.e("getHomePageBookmarks ", "homepagURL: " + homepagURL); + Log.e("getHomePageBookmarks ", "homepagURL: " + homepagURL); String oldHome = Settings.System.getString(context.getContentResolver(), "homepagURL"); - Logutils.e("getHomePageBookmarks", "oldHome: " + oldHome); + Log.e("getHomePageBookmarks", "oldHome: " + oldHome); //数据和之前不一样的时候清除缓存 if (!TextUtils.isEmpty(oldHome) && !oldHome.equalsIgnoreCase(homepagURL)) { try { new CacheUtils().cleanApplicationUserData(context, "com.android.browser"); } catch (Exception e) { e.printStackTrace(); - Logutils.e(TAG, "setHomepagtag: " + e.getMessage()); + Log.e(TAG, "setHomepagtag: " + e.getMessage()); } } boolean home = Settings.System.putString(context.getContentResolver(), "homepagURL", homepagURL); - Logutils.e("getHomePageBookmarks", "onNext: homepagURL: save homepagURL = " + home); + Log.e("getHomePageBookmarks", "onNext: homepagURL: save homepagURL = " + home); String whitelist = Settings.System.getString(context.getContentResolver(), "DeselectBrowserArray"); - Logutils.e("getHomePageBookmarks ", "whitelist: " + whitelist); + Log.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); +// Log.e("getHomePageBookmarks", "onNext: homepagURL: add to whiteList = " + whiteString + "write: " + white); // } else { -// Logutils.e("getHomePageBookmarks", "onNext: whitelist is NULL"); +// Log.e("getHomePageBookmarks", "onNext: whitelist is NULL"); // boolean white = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", homepagURL); -// Logutils.e("getHomePageBookmarks", "onNext: homepagURL: homepagURL = " + homepagURL + "write: " + white); +// Log.e("getHomePageBookmarks", "onNext: homepagURL: homepagURL = " + homepagURL + "write: " + white); // } //书签 @@ -395,7 +400,7 @@ public class HTTPInterface { // urlList.add(JGYUtils.getPrefixHttpsURL(urls)); // } String join = String.join(",", labels); - Logutils.e("getHomePageBookmarks", "onNext: getHomePageBookmarks: " + join); + Log.e("getHomePageBookmarks", "onNext: getHomePageBookmarks: " + join); websiteBookMark.putExtra("websiteBookMark", join); } else { websiteBookMark.putExtra("websiteBookMark", "Invalid"); @@ -412,7 +417,7 @@ public class HTTPInterface { } if (!TextUtils.isEmpty(homepagURL)) { // String newHomePage = JGYUtils.getPrefixHttpsURL(homepagURL); - Logutils.e("getHomePageBookmarks", "onNext: newHomePage: " + homepagURL); + Log.e("getHomePageBookmarks", "onNext: newHomePage: " + homepagURL); homepag.putExtra("homepage", homepagURL); } else { homepag.putExtra("homepage", "Invalid"); @@ -445,7 +450,7 @@ public class HTTPInterface { if (callback != null) { callback.onError(e); } - Logutils.e("getHomePageBookmarks", "onError: " + e.getMessage()); + Log.e("getHomePageBookmarks", "onError: " + e.getMessage()); onComplete(); } @@ -454,7 +459,7 @@ public class HTTPInterface { if (callback != null) { callback.onComplete(); } - Logutils.e("getHomePageBookmarks", "onComplete: "); + Log.e("getHomePageBookmarks", "onComplete: "); setBrowserBlackList(context); } }); @@ -467,16 +472,16 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - Logutils.e(TAG + ":" + "getDesktopIcon", "onSubscribe: "); + Log.e(TAG + ":" + "getDesktopIcon", "onSubscribe: "); } @Override public void onNext(@NonNull BaseResponse response) { - Logutils.e(TAG + ":" + "getDesktopIcon", "onNext: "); + Log.e(TAG + ":" + "getDesktopIcon", "onNext: "); ApkUtils.showAllAPP(context); if (response.code == OK) { String data = response.data.toString(); - Logutils.e(TAG + ":" + "getDesktopIcon", "data: " + data); + Log.e(TAG + ":" + "getDesktopIcon", "data: " + data); if (!TextUtils.isEmpty(data)) { List newList = Arrays.asList(data.split(","));//新的list PackageManager pm = context.getPackageManager(); @@ -491,29 +496,29 @@ public class HTTPInterface { pm.setApplicationEnabledSetting("com.android.messaging", PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); } } catch (Exception ex) { - Logutils.e(TAG + ":" + "getDesktopIcon", "Exception: ex: " + ex.getMessage()); + Log.e(TAG + ":" + "getDesktopIcon", "Exception: ex: " + ex.getMessage()); } pm.setApplicationEnabledSetting(pack, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); - Logutils.e(TAG + ":" + "getDesktopIcon", pack); + Log.e(TAG + ":" + "getDesktopIcon", pack); } catch (Exception e) { - Logutils.e(TAG + ":" + "getDesktopIcon", "Exception: " + e.getMessage()); + Log.e(TAG + ":" + "getDesktopIcon", "Exception: " + e.getMessage()); } } } } else { - Logutils.e(TAG + ":" + "getDesktopIcon", "onNext: " + response.toString()); + Log.e(TAG + ":" + "getDesktopIcon", "onNext: " + response.toString()); } } @Override public void onError(@NonNull Throwable e) { - Logutils.e(TAG + ":" + "getDesktopIcon", "onError: " + e.getMessage()); + Log.e(TAG + ":" + "getDesktopIcon", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e(TAG + ":" + "getDesktopIcon", "onComplete: "); + Log.e(TAG + ":" + "getDesktopIcon", "onComplete: "); } }); } @@ -551,7 +556,7 @@ public class HTTPInterface { @Override public void onNext(ResponseBody responseBody) { try { - Logutils.e("updateDeviceInfo", "上传的结果" + responseBody.string()); + Log.e("updateDeviceInfo", "上传的结果" + responseBody.string()); } catch (IOException e) { e.printStackTrace(); } @@ -559,7 +564,7 @@ public class HTTPInterface { @Override public void onError(Throwable e) { - Logutils.e("updateDeviceInfo", e.getMessage()); + Log.e("updateDeviceInfo", e.getMessage()); } @Override @@ -578,11 +583,12 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(Disposable d) { - Logutils.e(TAG, "onSubscribe: "); + Log.e("getSnTimeControl", "onSubscribe: "); } @Override public void onNext(BaseResponse response) { + Log.e("getSnTimeControl", "onNext: "); int code = response.code; if (code == 200) { JSONObject jsonObject = (JSONObject) JSON.toJSON(response.data); @@ -590,24 +596,25 @@ public class HTTPInterface { String end_time = jsonObject.getString("end_time"); TimeUtils.ContralTime c = TimeUtils.String2ContralTime(context, start_time + "-" + end_time); if (null != c) { - Logutils.e("getTimeControl", "200: " + c.toString()); + Log.e("getTimeControl", "200: " + c.toString()); } } else { TimeUtils.setEmpty(context); TimeUtils.ContralTime c = TimeUtils.getDefaltContralTime(context); if (null != c) { - Logutils.e("getTimeControl", c.toString()); + Log.e("getTimeControl", c.toString()); } } } @Override public void onError(Throwable e) { - Logutils.e("getSnTimeControl", "onError: " + e.getMessage()); + Log.e("getSnTimeControl", "onError: " + e.getMessage()); } @Override public void onComplete() { + Log.e("getSnTimeControl", "onComplete: "); Intent intent = new Intent(); intent.setAction(MainService.TimeChangedReceiver.ACTION_UPDATE); context.sendBroadcast(intent); @@ -659,41 +666,41 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - Logutils.e("getAppLimit", "onSubscribe: "); + Log.e("getAppLimit", "onSubscribe: "); } @Override public void onNext(@NonNull ResponseBody responseBody) { try { String bodyString = responseBody.string(); - Logutils.e("getAppLimit", "onNext: " + bodyString); + Log.e("getAppLimit", "onNext: " + bodyString); JsonObject jsonObject = JsonParser.parseString(bodyString).getAsJsonObject(); int code = jsonObject.get("code").getAsInt(); if (code == 200) { String data = jsonObject.get("data").getAsJsonObject().get("result").getAsString(); //开机图标 只记录后台传的包名 boolean write = Settings.System.putString(context.getContentResolver(), JGYActions.ACTION_JGY_SHORTCUTLIST, data); - Logutils.e(TAG, "onNext: only_jgy_shortcut_list: " + write); + Log.e(TAG, "onNext: only_jgy_shortcut_list: " + write); JGYUtils.getInstance().writeAppPackageList(context, data); JGYUtils.getInstance().deleteOtherApp(); } else { - Logutils.e("getAppLimit", "onNext: " + bodyString); + Log.e("getAppLimit", "onNext: " + bodyString); } } catch (IOException e) { e.printStackTrace(); - Logutils.e("getAppLimit", "onNext: IOException: " + e.getMessage()); + Log.e("getAppLimit", "onNext: IOException: " + e.getMessage()); } } @Override public void onError(@NonNull Throwable e) { - Logutils.e("getAppLimit", "onError: " + e.getMessage()); + Log.e("getAppLimit", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e("getAppLimit", "onComplete: "); + Log.e("getAppLimit", "onComplete: "); getAllAppList(context); } }); @@ -708,31 +715,31 @@ public class HTTPInterface { .subscribe(new Observer>>() { @Override public void onSubscribe(Disposable d) { - Logutils.e("getAllAppList", "onSubscribe: "); + Log.e("getAllAppList", "onSubscribe: "); } @Override public void onNext(BaseResponse> listBaseResponse) { - Logutils.e("getAllAppList", "onNext: " + JSONObject.toJSONString(listBaseResponse)); + Log.e("getAllAppList", "onNext: " + JSONObject.toJSONString(listBaseResponse)); int code = listBaseResponse.code; if (code == 200) { List appListInfos = listBaseResponse.data; getAppAutoStartUpdateAndNet(appListInfos); } else { - Logutils.e("getAllAppList", "onNext: " + "no data"); - Logutils.e("getAllAppList", "onNext: " + listBaseResponse.data); + Log.e("getAllAppList", "onNext: " + "no data"); + Log.e("getAllAppList", "onNext: " + listBaseResponse.data); } } @Override public void onError(Throwable e) { - Logutils.e("getAllAppList", "onError: " + e.getMessage()); + Log.e("getAllAppList", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e("getAllAppList", "onComplete: "); + Log.e("getAllAppList", "onComplete: "); getForceDownload(context); } }); @@ -744,15 +751,15 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - Logutils.e(TAG + ":" + "getForceDownload", "onSubscribe: "); + Log.e(TAG + ":" + "getForceDownload", "onSubscribe: "); } @Override public void onNext(@NonNull ForceDownloadBean forceDownloadBean) { - Logutils.e(TAG + ":" + "getForceDownload", "onNext: "); + Log.e(TAG + ":" + "getForceDownload", "onNext: "); switch (forceDownloadBean.getCode()) { case 200: - Logutils.e(TAG + ":" + "getForceDownload", "isDownloading=" + BaseApplication.getInstance().isDownloading()); + Log.e(TAG + ":" + "getForceDownload", "isDownloading=" + BaseApplication.getInstance().isDownloading()); BaseApplication.getInstance().checkIsDownloading(); if (!BaseApplication.getInstance().isDownloading()) { Type type = new TypeToken>() { @@ -766,23 +773,23 @@ public class HTTPInterface { break; case -200: boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", "invalid"); - Logutils.e(TAG + ":" + "getForceDownload", "qch_force_app:" + qch_force_app); + Log.e(TAG + ":" + "getForceDownload", "qch_force_app:" + qch_force_app); break; default: - Logutils.e(TAG + ":" + "getForceDownload", forceDownloadBean.getMsg()); + Log.e(TAG + ":" + "getForceDownload", forceDownloadBean.getMsg()); break; } } @Override public void onError(@NonNull Throwable e) { - Logutils.e(TAG + ":" + "getForceDownload", "onError: " + e.getMessage()); + Log.e(TAG + ":" + "getForceDownload", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e(TAG + ":" + "getForceDownload", "onComplete: "); + Log.e(TAG + ":" + "getForceDownload", "onComplete: "); } }); } @@ -795,28 +802,28 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - Logutils.e("getAppAutoStartUpdateAndNet", "onSubscribe: "); + Log.e("getAppAutoStartUpdateAndNet", "onSubscribe: "); } @Override public void onNext(@NonNull NetAndLaunchBean netAndLaunchBean) { - Logutils.e("getAppAutoStartUpdateAndNet", "onNext: " + netAndLaunchBean.toString()); + Log.e("getAppAutoStartUpdateAndNet", "onNext: " + netAndLaunchBean.toString()); if (netAndLaunchBean.getCode() == 200) { JGYUtils.getInstance().setNetAndlaunch(netAndLaunchBean, appListInfos); } else { - Logutils.e("getAppAutoStartUpdateAndNet", "onNext: " + netAndLaunchBean.toString()); + Log.e("getAppAutoStartUpdateAndNet", "onNext: " + netAndLaunchBean.toString()); } } @Override public void onError(@NonNull Throwable e) { - Logutils.e("getAppAutoStartUpdateAndNet", "onError: " + e.getMessage()); + Log.e("getAppAutoStartUpdateAndNet", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e("getAppAutoStartUpdateAndNet", "onComplete: "); + Log.e("getAppAutoStartUpdateAndNet", "onComplete: "); } }); } @@ -829,28 +836,28 @@ public class HTTPInterface { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - Logutils.e("getNetAndLaunchSetting", "onSubscribe: "); + Log.e("getNetAndLaunchSetting", "onSubscribe: "); } @Override public void onNext(@NonNull NetAndLaunchBean netAndLaunchBean) { - Logutils.e("getNetAndLaunchSetting", "onNext: " + netAndLaunchBean.toString()); + Log.e("getNetAndLaunchSetting", "onNext: " + netAndLaunchBean.toString()); if (netAndLaunchBean.getCode() == 200) { JGYUtils.getInstance().setNetAndlaunch(netAndLaunchBean); } else { - Logutils.e("getNetAndLaunchSetting", "onNext: " + netAndLaunchBean.toString()); + Log.e("getNetAndLaunchSetting", "onNext: " + netAndLaunchBean.toString()); } } @Override public void onError(@NonNull Throwable e) { - Logutils.e("getNetAndLaunchSetting", "onError: " + e.getMessage()); + Log.e("getNetAndLaunchSetting", "onError: " + e.getMessage()); onComplete(); } @Override public void onComplete() { - Logutils.e("getNetAndLaunchSetting", "onComplete: "); + Log.e("getNetAndLaunchSetting", "onComplete: "); } }); } @@ -922,4 +929,129 @@ public class HTTPInterface { } }); } + + public static void getPoweroffTime() { + NetInterfaceManager.getInstance() + .getPoweroffTimeControl() + .subscribe(new Observer>>() { + @Override + public void onSubscribe(Disposable d) { + Log.e("getPoweroffTime", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse> listBaseResponse) { + Log.e("getPoweroffTime", "onNext: " + listBaseResponse); + MMKV mmkv = MMKV.defaultMMKV(); + if (listBaseResponse.code == 200) { + List poweroffBeanList = listBaseResponse.data; + String poweroffTime = new Gson().toJson(poweroffBeanList); + mmkv.encode("poweroffTime", poweroffTime); + } else { + mmkv.encode("PoweroffTime", ""); + } + } + + @Override + public void onError(Throwable e) { + Log.e("getPoweroffTime", "onError: " + e.getLocalizedMessage()); + } + + @Override + public void onComplete() { + Log.e("getPoweroffTime", "onComplete: "); + } + }); + } + + public static void getWiFiPasswd(Context context) { + NetInterfaceManager.getInstance().getWiFiControl() + .subscribe(new Observer>>() { + @Override + public void onSubscribe(Disposable d) { + Log.e("getWiFiPasswd", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse> listBaseResponse) { + Log.e("getWiFiPasswd", "onNext: "); + if (listBaseResponse.code == 200) { + WiFiUtils.saveWiFiPasswd(listBaseResponse.data); + MMKV.defaultMMKV().encode("WiFiPassword", JsonParser.parseString(new Gson().toJson(listBaseResponse.data)).toString()); + } else { + WiFiUtils.saveWiFiPasswd(listBaseResponse.data); + MMKV.defaultMMKV().encode("WiFiPassword", ""); + Log.e("getWiFiPasswd", "onNext: msg = " + listBaseResponse.msg); + } + } + + @Override + public void onError(Throwable e) { + Log.e("getWiFiPasswd", "onError: " + e.getMessage()); + } + + @Override + public void onComplete() { + Log.e("getWiFiPasswd", "onComplete: "); + } + }); + } + + private static int REQUEST_CODE = 12345; + + public static void getRunLog(Context context) { + NetInterfaceManager.getInstance().getSnRunLogApiControl() + .subscribe(new Observer>() { + @Override + public void onSubscribe(Disposable d) { + Log.e("getRunLog", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse snRunLogBaseResponse) { + Log.e("getRunLog", "onNext: " + snRunLogBaseResponse); + if (snRunLogBaseResponse.code == OK) { + SnRunLog snRunLog = snRunLogBaseResponse.data; + LogcatService.setStart_Time(snRunLog.getStart_time()); + LogcatService.setDuration(snRunLog.getDuration()); + LogcatService.setFileMaxSize(snRunLog.getFile_max_size()); + LogcatService.setClearFile(snRunLog.getIs_clear()); + long timestamp = snRunLog.getStart_time() * 1000; + long nowTime = System.currentTimeMillis(); + AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + if (nowTime > timestamp) { + Intent intent = new Intent(LogcatService.LOGCAT_START_ACTION); + context.sendBroadcast(intent); + } else { + Intent intent = new Intent(LogcatService.LOGCAT_START_ACTION); + PendingIntent startPendingIntent = PendingIntent.getBroadcast(context, + REQUEST_CODE, intent, + PendingIntent.FLAG_CANCEL_CURRENT); + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, + timestamp, startPendingIntent); + } + Intent intent = new Intent(LogcatService.LOGCAT_STOP_ACTION); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, + REQUEST_CODE, intent, + PendingIntent.FLAG_CANCEL_CURRENT); + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, + timestamp + snRunLog.getDuration() * 1000, pendingIntent); + } else { + + } + + } + + @Override + public void onError(Throwable e) { + Log.e("getRunLog", "onError: " + e.getMessage()); + onComplete(); + } + + @Override + public void onComplete() { + Log.e("getRunLog", "onComplete: "); + } + }); + } } \ No newline at end of file diff --git a/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java b/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java index b838808..dd12f66 100644 --- a/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java +++ b/app/src/main/java/com/aoleyun/sn/network/NetInterfaceManager.java @@ -14,7 +14,11 @@ import com.aoleyun.sn.bean.ForceDownloadBean; import com.aoleyun.sn.bean.ForceDownloadData; import com.aoleyun.sn.bean.LogoImg; import com.aoleyun.sn.bean.NetAndLaunchBean; +import com.aoleyun.sn.bean.PoweroffBean; +import com.aoleyun.sn.bean.SnRunLog; import com.aoleyun.sn.bean.StudentsInfo; +import com.aoleyun.sn.bean.WiFiAlias; +import com.aoleyun.sn.comm.PackageNames; import com.aoleyun.sn.network.api.AppLimitApi; import com.aoleyun.sn.network.api.DeselectIDApi; import com.aoleyun.sn.network.api.ForceDownloadApi; @@ -38,18 +42,24 @@ import com.aoleyun.sn.network.api.newapi.GetDeveloperApi; import com.aoleyun.sn.network.api.newapi.GetEBagCodeApi; import com.aoleyun.sn.network.api.newapi.GetLockStateApi; import com.aoleyun.sn.network.api.newapi.GetJpushTagsApi; +import com.aoleyun.sn.network.api.newapi.GetPoweroffApi; +import com.aoleyun.sn.network.api.newapi.GetSnRunLogApi; +import com.aoleyun.sn.network.api.newapi.GetUploadLogApi; +import com.aoleyun.sn.network.api.newapi.GetWiFiAliasApi; import com.aoleyun.sn.network.api.newapi.LogoImgApi; import com.aoleyun.sn.network.api.newapi.MACAddressApi; import com.aoleyun.sn.network.api.newapi.NewAppinsideWebApi; import com.aoleyun.sn.network.api.newapi.ScreenLockStateApi; import com.aoleyun.sn.network.api.newapi.SendDownloadInfoApi; import com.aoleyun.sn.network.api.newapi.SendDownloadTimesApi; +import com.aoleyun.sn.network.api.newapi.SendRestoreTimesApi; import com.aoleyun.sn.network.api.newapi.SendScreenshotApi; import com.aoleyun.sn.network.api.newapi.SnTimeControlApi; import com.aoleyun.sn.network.api.newapi.StudentsInfosApi; import com.aoleyun.sn.network.api.newapi.TopAppControlApi; import com.aoleyun.sn.network.api.newapi.UpdateDeviceInfoApi; import com.aoleyun.sn.utils.MD5Util; +import com.aoleyun.sn.utils.SPUtils; import com.aoleyun.sn.utils.Utils; import org.jetbrains.annotations.NotNull; @@ -103,19 +113,19 @@ public class NetInterfaceManager { Request request = chain.request(); String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString()); Response response = chain.proceed(request); //准备返回Response -// try { -// response.close(); -// response = chain.proceed(request); -// } catch (Exception e) { -// Log.e(TAG, "intercept: " + e.getMessage()); -// //异常的返回也是完成Http请求。在这里移除请求登记 -// if (!TextUtils.isEmpty(e.toString()) && e.toString().contains(NetInterfaceManager.CUSTOM_REPEAT_REQ_PROTOCOL)) { -// Log.e("REPEAT-REQUEST", "移除请求1:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url()); -// } else { -// requestIdsMap.remove(requestKey); -// } -// throw e; -// } +// try { +// response.close(); +// response = chain.proceed(request); +// } catch (Exception e) { +// //异常的返回也是完成Http请求。在这里移除请求登记 +// if (!TextUtils.isEmpty(e.toString()) && e.toString().contains(NetInterfaceManager.CUSTOM_REPEAT_REQ_PROTOCOL)) { +// Log.e("REPEAT-REQUEST", "intercept: " + e.getMessage()); +// Log.e("REPEAT-REQUEST", "移除请求1:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url()); +// } else { +// requestIdsMap.remove(requestKey); +// } +// throw e; +// } synchronized (requestIdsMap) { requestIdsMap.remove(requestKey); //在这里移除正常的请求登记 Log.e("REPEAT-REQUEST", "移除请求2:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url()); @@ -144,19 +154,51 @@ public class NetInterfaceManager { .build(); } } - Response originalResponse = chain.proceed(request); - return originalResponse.newBuilder().build(); + Response response = chain.proceed(request); + return response; + } + }; + Interceptor interceptor = new Interceptor() { + @NotNull + @Override + public Response intercept(@NotNull Chain chain) throws IOException { + Request request = chain.request(); + //相同的请求 + String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString()); + long time = System.currentTimeMillis();//请求时间 + try { + if (requestIdsMap.size() > 0 && requestIdsMap.containsKey(requestKey)) { + Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url()); + chain.call().cancel(); + return new Response.Builder() + .protocol(Protocol.get(CUSTOM_REPEAT_REQ_PROTOCOL)) + .request(request) //multi thread + .build(); + } + requestIdsMap.put(requestKey, time); + Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url()); +// Request.Builder builder = request.newBuilder(); +// builder.addHeader("header", jsonObject.toString()); + return chain.proceed(request); + } catch (IOException e) { + throw e; + } finally { + if (requestIdsMap.containsKey(requestKey) && requestIdsMap.containsValue(time)) {//请求任务完成删除map中的数据 + requestIdsMap.remove(requestKey); + Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url()); + } + } } }; - //如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了 OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.connectTimeout(timeOut, TimeUnit.SECONDS); // 设置连接超时时间 builder.writeTimeout(timeOut, TimeUnit.SECONDS);// 设置写入超时时间 builder.readTimeout(timeOut, TimeUnit.SECONDS);// 设置读取数据超时时间 builder.retryOnConnectionFailure(true);// 设置进行连接失败重试 - builder.addInterceptor(myHttpInterceptor); - builder.addNetworkInterceptor(mRequestInterceptor); + builder.addInterceptor(interceptor); +// builder.addInterceptor(myHttpInterceptor); +// builder.addNetworkInterceptor(mRequestInterceptor); // 设置缓存文件路径 String cacheDirectory = mContext.getExternalCacheDir().getAbsolutePath() + "/OkHttpCache"; @@ -228,8 +270,16 @@ public class NetInterfaceManager { JPushInterface.getRegistrationID(mContext), Utils.getCustomVersion(), BuildConfig.VERSION_NAME, - Utils.getAPPVersionName(mContext), - Utils.getAndroid7MAC() + Utils.getAPPVersionName(PackageNames.APPSTORE, mContext), + Utils.getAPPVersionName(PackageNames.DESKTOP, mContext), + Utils.getAndroid7MAC(), + Utils.obtainWifiInfo(mContext), + (String) SPUtils.get(mContext, "PublicIP", ""), + Utils.getIPAddress(mContext), + Utils.getBluetoothList(), + Utils.getWifiAlias(mContext), + Utils.getAPPVersionName(PackageNames.BROWSER, mContext), + Utils.getAPPVersionName(PackageNames.NOTIFICATIONS, mContext) ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); @@ -387,6 +437,35 @@ public class NetInterfaceManager { .observeOn(AndroidSchedulers.mainThread()); } + public Observable getRestoreTimesApi() { + return mRetrofit.create(SendRestoreTimesApi.class) + .sendRestoreTimes(Utils.getSerial()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + + public Observable>> getWiFiControl() { + return mRetrofit.create(GetWiFiAliasApi.class) + .getWiFiAlias(Utils.getSerial()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + + public Observable>> getPoweroffTimeControl() { + return mRetrofit.create(GetPoweroffApi.class) + .getPoweroffTime(Utils.getSerial()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + + public Observable> getSnRunLogApiControl() { + return mRetrofit.create(GetSnRunLogApi.class) + .GetSnRunLog(Utils.getSerial()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + + /* * * API @@ -463,4 +542,9 @@ public class NetInterfaceManager { public SendScreenshotApi getScreenshotApi() { return mRetrofit.create(SendScreenshotApi.class); } + + public GetUploadLogApi getUploadLogApi() { + return mRetrofit.create(GetUploadLogApi.class); + } + } diff --git a/app/src/main/java/com/aoleyun/sn/network/UrlAddress.java b/app/src/main/java/com/aoleyun/sn/network/UrlAddress.java index 8995fd5..7baddee 100644 --- a/app/src/main/java/com/aoleyun/sn/network/UrlAddress.java +++ b/app/src/main/java/com/aoleyun/sn/network/UrlAddress.java @@ -48,7 +48,7 @@ public class UrlAddress { //上传截图 public static final String SEND_SCREENSHOT = "Screenshot/addImg"; //上传我的设备 - //public static final String UPDATE_DEVICEINFO = "Mac/getInfo"; + public static final String UPDATE_DEVICEINFO = "Mac/getInfo"; //获取霸屏状态 public static final String GET_LOCK_SCREEN_STATE = "Sn/getSnScreen"; //获取默认桌面升级 @@ -71,6 +71,16 @@ public class UrlAddress { public static final String GET_EBAG_CODE = "And/getEbagCode"; //获取系统默认程序 public static final String GET_DEFAULT_APP = "app/getDefaultApp"; + //恢复出厂设置次数 + public static final String SEND_RESTORE_TIMES = "And/restore"; + //获取远程关机时间 + public static final String GET_POWEROFF_TIME = "And/getTimedShutdown"; + //获取WiFi名和密码 + public static final String GET_WIFI_ALIAS_PW = "And/getWifi"; + //获取log任务 + public static final String GET_LOG_ORDER = "And/getSnRunLog"; + //上传log文件 + public static final String UPLOAD_LOG_FILE = "And/uploadLogFile"; //获取公网IP public static final String SHOUHU_CITYJSON = "http://pv.sohu.com/cityjson/"; diff --git a/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetPoweroffApi.java b/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetPoweroffApi.java new file mode 100644 index 0000000..f6b68d1 --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetPoweroffApi.java @@ -0,0 +1,20 @@ +package com.aoleyun.sn.network.api.newapi; + +import com.aoleyun.sn.bean.BaseResponse; +import com.aoleyun.sn.bean.PoweroffBean; +import com.aoleyun.sn.network.UrlAddress; + +import java.util.List; + +import io.reactivex.Observable; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.POST; + +public interface GetPoweroffApi { + @FormUrlEncoded + @POST(UrlAddress.GET_POWEROFF_TIME) + Observable>> getPoweroffTime( + @Field("sn") String sn + ); +} diff --git a/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetSnRunLogApi.java b/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetSnRunLogApi.java new file mode 100644 index 0000000..197d108 --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetSnRunLogApi.java @@ -0,0 +1,16 @@ +package com.aoleyun.sn.network.api.newapi; + +import com.aoleyun.sn.bean.BaseResponse; +import com.aoleyun.sn.bean.SnRunLog; +import com.aoleyun.sn.network.UrlAddress; + +import io.reactivex.Observable; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface GetSnRunLogApi { + @GET(UrlAddress.GET_LOG_ORDER) + Observable> GetSnRunLog( + @Query("sn") String sn + ); +} diff --git a/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetUploadLogApi.java b/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetUploadLogApi.java new file mode 100644 index 0000000..b2cf45c --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetUploadLogApi.java @@ -0,0 +1,25 @@ +package com.aoleyun.sn.network.api.newapi; + +import com.aoleyun.sn.bean.BaseResponse; +import com.aoleyun.sn.bean.SnRunLog; +import com.aoleyun.sn.network.UrlAddress; + +import java.util.Map; + +import io.reactivex.Observable; +import okhttp3.MultipartBody; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.Multipart; +import retrofit2.http.POST; +import retrofit2.http.Part; +import retrofit2.http.QueryMap; + +public interface GetUploadLogApi { + @Multipart + @POST(UrlAddress.UPLOAD_LOG_FILE) + Observable> GetSnRunLog( + @QueryMap Map params, + @Part MultipartBody.Part body + ); +} diff --git a/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetWiFiAliasApi.java b/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetWiFiAliasApi.java new file mode 100644 index 0000000..6564133 --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/network/api/newapi/GetWiFiAliasApi.java @@ -0,0 +1,28 @@ +package com.aoleyun.sn.network.api.newapi; + + +import com.aoleyun.sn.bean.BaseResponse; +import com.aoleyun.sn.bean.WiFiAlias; +import com.aoleyun.sn.network.UrlAddress; + +import java.util.List; + +import io.reactivex.Observable; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.POST; + +/** + * @author : fanhuitong + * e-mail : + * @date : 2021/10/26 10:07 + * desc : + * version: 1.0 + */ +public interface GetWiFiAliasApi { + @FormUrlEncoded + @POST(UrlAddress.GET_WIFI_ALIAS_PW) + Observable>> getWiFiAlias( + @Field("sn") String sn + ); +} diff --git a/app/src/main/java/com/aoleyun/sn/network/api/newapi/MACAddressApi.java b/app/src/main/java/com/aoleyun/sn/network/api/newapi/MACAddressApi.java index 701d4f5..8953c51 100644 --- a/app/src/main/java/com/aoleyun/sn/network/api/newapi/MACAddressApi.java +++ b/app/src/main/java/com/aoleyun/sn/network/api/newapi/MACAddressApi.java @@ -18,6 +18,14 @@ public interface MACAddressApi { @Field("devices_version") String devicesVersion, @Field("appstore_version") String appstoreVersion, @Field("store_version") String storeVersion, - @Field("local_mac") String local_mac + @Field("desktop_version") String desktop_version, + @Field("local_mac") String local_mac, + @Field("wifi_status") int wifi_status, + @Field("PN_ip") String PN_ip, + @Field("LAN_ip") String LAN_ip, + @Field("bluetooth") String bluetooth, + @Field("wifi_name") String wifi_name, + @Field("browser_version") String browser_version, + @Field("notice_version") String notice_version ); } diff --git a/app/src/main/java/com/aoleyun/sn/network/api/newapi/SendRestoreTimesApi.java b/app/src/main/java/com/aoleyun/sn/network/api/newapi/SendRestoreTimesApi.java new file mode 100644 index 0000000..fdb122c --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/network/api/newapi/SendRestoreTimesApi.java @@ -0,0 +1,24 @@ +package com.aoleyun.sn.network.api.newapi; + +import com.aoleyun.sn.bean.BaseResponse; +import com.aoleyun.sn.network.UrlAddress; + +import io.reactivex.Observable; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.POST; + +/** + * @author : fanhuitong + * e-mail : + * @date : 2021/10/2115:02 + * desc : + * version: 1.0 + */ +public interface SendRestoreTimesApi { + @FormUrlEncoded + @POST(UrlAddress.SEND_RESTORE_TIMES) + Observable sendRestoreTimes( + @Field("sn") String sn + ); +} diff --git a/app/src/main/java/com/aoleyun/sn/network/api/newapi/SendScreenshotApi.java b/app/src/main/java/com/aoleyun/sn/network/api/newapi/SendScreenshotApi.java index db0ca20..79b3763 100644 --- a/app/src/main/java/com/aoleyun/sn/network/api/newapi/SendScreenshotApi.java +++ b/app/src/main/java/com/aoleyun/sn/network/api/newapi/SendScreenshotApi.java @@ -3,19 +3,21 @@ package com.aoleyun.sn.network.api.newapi; import com.aoleyun.sn.bean.BaseResponse; import com.aoleyun.sn.network.UrlAddress; +import java.util.Map; + import io.reactivex.Observable; import okhttp3.MultipartBody; import retrofit2.http.Field; import retrofit2.http.Multipart; import retrofit2.http.POST; import retrofit2.http.Part; +import retrofit2.http.QueryMap; public interface SendScreenshotApi { @Multipart @POST(UrlAddress.SEND_SCREENSHOT) Observable sendScreenshot( - @Field("sn") String sn, - @Field("createtime") long createtime, + @QueryMap Map params, @Part MultipartBody.Part body ); } diff --git a/app/src/main/java/com/aoleyun/sn/network/api/newapi/UpdateDeviceInfoApi.java b/app/src/main/java/com/aoleyun/sn/network/api/newapi/UpdateDeviceInfoApi.java index df4ea8e..5ef752d 100644 --- a/app/src/main/java/com/aoleyun/sn/network/api/newapi/UpdateDeviceInfoApi.java +++ b/app/src/main/java/com/aoleyun/sn/network/api/newapi/UpdateDeviceInfoApi.java @@ -1,5 +1,7 @@ package com.aoleyun.sn.network.api.newapi; +import com.aoleyun.sn.network.UrlAddress; + import io.reactivex.Observable; import okhttp3.ResponseBody; import retrofit2.http.Field; @@ -8,7 +10,7 @@ import retrofit2.http.POST; public interface UpdateDeviceInfoApi { @FormUrlEncoded - @POST("Mac/getInfo") + @POST(UrlAddress.UPDATE_DEVICEINFO) Observable updateDeviceInfo( @Field("sn") String sn, @Field("key") String key, diff --git a/app/src/main/java/com/aoleyun/sn/receiver/BootReceiver.java b/app/src/main/java/com/aoleyun/sn/receiver/BootReceiver.java index a9e4cdc..13610b4 100644 --- a/app/src/main/java/com/aoleyun/sn/receiver/BootReceiver.java +++ b/app/src/main/java/com/aoleyun/sn/receiver/BootReceiver.java @@ -10,7 +10,6 @@ import com.aoleyun.sn.activity.CheckNetActivity; import com.aoleyun.sn.service.MainService; import com.aoleyun.sn.utils.BootManager; import com.aoleyun.sn.utils.JGYUtils; -import com.aoleyun.sn.utils.Logutils; import java.util.concurrent.TimeUnit; @@ -41,9 +40,9 @@ public class BootReceiver extends BroadcastReceiver { Log.e("getLockedState", "onNext: "); if (MainService.mPresenter != null) { MainService.mPresenter.getLockedState(); - Logutils.e("getLockedState", "mPresenter: " + "getLockedState"); + Log.e("getLockedState", "mPresenter: " + "getLockedState"); } else { - Logutils.e("getLockedState", "mPresenter is NULL"); + Log.e("getLockedState", "mPresenter is NULL"); } } @@ -68,12 +67,14 @@ public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - Logutils.e(TAG, "action:" + intent.getAction()); + Log.e(TAG, "action:" + intent.getAction()); switch (intent.getAction()) { default: break; case Intent.ACTION_BOOT_COMPLETED: - context.startActivity(new Intent(context, CheckNetActivity.class)); + Intent intent1 = new Intent(context, CheckNetActivity.class); + intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent1); JGYUtils.startServices(context); new BootManager(context).start(); break; diff --git a/app/src/main/java/com/aoleyun/sn/receiver/MyJPushReceiver.java b/app/src/main/java/com/aoleyun/sn/receiver/MyJPushReceiver.java index 94add1a..4b303a5 100644 --- a/app/src/main/java/com/aoleyun/sn/receiver/MyJPushReceiver.java +++ b/app/src/main/java/com/aoleyun/sn/receiver/MyJPushReceiver.java @@ -25,6 +25,8 @@ import com.amap.api.location.AMapLocationClient; import com.amap.api.location.AMapLocationListener; import com.aoleyun.sn.action.JGYActions; import com.aoleyun.sn.bean.BaseResponse; +import com.aoleyun.sn.bean.RemoteDebug; +import com.aoleyun.sn.bean.TTAppground; import com.arialyy.aria.core.Aria; import com.blankj.utilcode.util.PathUtils; import com.aoleyun.sn.R; @@ -39,17 +41,23 @@ import com.aoleyun.sn.service.MainService; import com.aoleyun.sn.utils.ApkUtils; import com.aoleyun.sn.utils.CmdUtil; import com.aoleyun.sn.utils.ForegroundAppUtil; -import com.aoleyun.sn.utils.Logutils; import com.aoleyun.sn.utils.MySQLData; import com.aoleyun.sn.utils.SPUtils; import com.aoleyun.sn.utils.SaveListUtils; import com.aoleyun.sn.utils.ServiceAliveUtils; import com.aoleyun.sn.utils.ToastUtil; import com.aoleyun.sn.utils.Utils; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import java.io.File; +import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; +import java.util.Map; import cn.jpush.android.api.JPushInterface; import io.reactivex.Observable; @@ -139,6 +147,14 @@ public class MyJPushReceiver extends BroadcastReceiver { private final String UPDATE_WHITELIST = "36"; //更换批次不恢复出厂 private final String UPDATE_BATCH = "37"; + //添加wifi + private final String UPDATE_WIFI_PW = "38"; + //远程关机 + private final String DEVICES_POWEROFF = "41"; + //远程log + private final String SN_RUN_LOG = "43"; + //自定义指令 + private final String CUSTOM_ORDER = "44"; private Context mContext; @@ -154,32 +170,32 @@ public class MyJPushReceiver extends BroadcastReceiver { if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); - Logutils.e(TAG, "[MyReceiver] 接收Registration Id : " + regId); + Log.e(TAG, "[MyReceiver] 接收Registration Id : " + regId); //send the Registration Id to your server... } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { // ToastTool.show("[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE) // + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE) // + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name")); - // Logutils.e(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE) + // Log.e(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE) // + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE) // + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name")); processCustomMessage(context, bundle);//屏蔽推送 } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { - Logutils.e(TAG, "[MyReceiver] 接收到推送下来的通知" + bundle.getString(JPushInterface.EXTRA_EXTRA)); + Log.e(TAG, "[MyReceiver] 接收到推送下来的通知" + bundle.getString(JPushInterface.EXTRA_EXTRA)); // doDownloadAndInstall(bundle.getString(JPushInterface.EXTRA_EXTRA)); - // Logutils.e(getBatteryLevel()+"-0-iweroiwerewefeerer-----------"); + // Log.e(getBatteryLevel()+"-0-iweroiwerewefeerer-----------"); int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); - Logutils.e(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId); + Log.e(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId); } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { - Logutils.e(TAG, "[MyReceiver] 用户点击打开了通知"); + Log.e(TAG, "[MyReceiver] 用户点击打开了通知"); } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { - Logutils.e(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); + Log.e(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等.. } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) { boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false); - Logutils.i(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected); + Log.i(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected); } else { - Logutils.e(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction()); + Log.e(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction()); } } @@ -189,7 +205,7 @@ 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); + Log.e(TAG, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras); switch (message) { default: break; @@ -260,12 +276,12 @@ public class MyJPushReceiver extends BroadcastReceiver { break; case GET_FORCEDOWNLOADURL: ToastUtil.betaShow("收到管控:应用强制安装"); - File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/"); + File file = new File(JGYUtils.getInstance().getDownLoadPath()); if (!file.exists()) { file.mkdirs(); } if (TextUtils.isEmpty(extras)) { - Logutils.e(TAG, "settingNetControl extras is null"); + Log.e(TAG, "settingNetControl extras is null"); return; } JSONObject extra = JSON.parseObject(extras); @@ -278,11 +294,6 @@ public class MyJPushReceiver extends BroadcastReceiver { packageObj.put("app_name", app_name); packageObj.put("app_package", app_package); packageObj.put("app_id", app_id); -// Aria.download(this) -// .load(url) //读取下载地址 -// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(url) + ".apk", true) -// .setExtendField(packageObj.toJSONString()) -// .create(); //启动下载} Utils.ariaDownload(mContext, url, packageObj); break; case SET_HOMEPAG_TAG: @@ -293,7 +304,7 @@ public class MyJPushReceiver extends BroadcastReceiver { new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser"); } catch (Exception e) { e.printStackTrace(); - Logutils.e(TAG, "setHomepagtag: " + e.getMessage()); + Log.e(TAG, "setHomepagtag: " + e.getMessage()); } setHomepagtag(extras); ToastUtil.betaShow("收到管控:浏览器主页书签设置"); @@ -313,7 +324,7 @@ public class MyJPushReceiver extends BroadcastReceiver { ToastUtil.betaShow("收到管控:隐藏应用设置"); Handler.getMain().postDelayed(() -> { //后台发送时数据库未改变,有时候可能获取到的数据时上一次的 - Logutils.e(TAG, "run: HIDE_DESKTOP_ICON "); + Log.e(TAG, "run: HIDE_DESKTOP_ICON "); HTTPInterface.setHideDesktopIcon(context); }, 2000); break; @@ -337,9 +348,10 @@ public class MyJPushReceiver extends BroadcastReceiver { ToastUtil.betaShow("收到管控:获取设备信息"); if (MainService.mPresenter != null) { MainService.mPresenter.getLockedState(); - Logutils.e(TAG, "mPresenter: " + "getLockedState"); + MainService.mPresenter.sendMACAddress(); + Log.e(TAG, "mPresenter: " + "getLockedState"); } else { - Logutils.e(TAG, "mPresenter is NULL"); + Log.e(TAG, "mPresenter is NULL"); } AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient(); aMapLocationClient.stopLocation(); @@ -350,8 +362,8 @@ public class MyJPushReceiver extends BroadcastReceiver { StringBuilder sb = new StringBuilder(); //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明 if (aMapLocation.getErrorCode() == 0) { - Logutils.e(TAG, "onLocationChanged: " + "定位成功"); - Logutils.e(TAG, "onLocationChanged: " + aMapLocation.getAddress()); + Log.e(TAG, "onLocationChanged: " + "定位成功"); + Log.e(TAG, "onLocationChanged: " + aMapLocation.getAddress()); sb.append(aMapLocation.getAddress()).append("\n"); SPUtils.put(mContext, "AmapAddress", aMapLocation.getAddress()); SPUtils.put(mContext, "longitude", aMapLocation.getLongitude()); @@ -361,9 +373,9 @@ public class MyJPushReceiver extends BroadcastReceiver { sb.append("定位失败" + "\n"); SPUtils.put(mContext, "AmapError", String.valueOf(aMapLocation.getErrorCode())); } - Logutils.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-")); - Logutils.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-")); - Logutils.e(TAG, "amap: " + sb.toString()); + Log.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-")); + Log.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-")); + Log.e(TAG, "amap: " + sb.toString()); HTTPInterface.updateDeviceInfo(mContext); } }); @@ -395,7 +407,7 @@ public class MyJPushReceiver extends BroadcastReceiver { case LOGO_IMG: ToastUtil.betaShow("收到管控:开机动画设置"); setBootanimation(context, extras); - Logutils.e(TAG, "processCustomMessage: " + extras); + Log.e(TAG, "processCustomMessage: " + extras); break; case DEFAULTP_APP: ToastUtil.betaShow("收到管控:"); @@ -433,15 +445,27 @@ public class MyJPushReceiver extends BroadcastReceiver { new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser"); } catch (Exception e) { e.printStackTrace(); - Logutils.e(TAG, "setHomepagtag: " + e.getMessage()); + Log.e(TAG, "setHomepagtag: " + e.getMessage()); } if (MainService.mPresenter != null) { MainService.mPresenter.getLockedState(); - Logutils.e("getLockedState", "mPresenter: " + "getLockedState"); + Log.e("getLockedState", "mPresenter: " + "getLockedState"); } else { - Logutils.e("getLockedState", "mPresenter is NULL"); + Log.e("getLockedState", "mPresenter is NULL"); } break; + case UPDATE_WIFI_PW: + HTTPInterface.getWiFiPasswd(context); + break; + case DEVICES_POWEROFF: + HTTPInterface.getPoweroffTime(); + break; + case SN_RUN_LOG: + recordLog(context, extras); + break; + case CUSTOM_ORDER: + customOrder(context, extras); + break; } } @@ -461,12 +485,12 @@ public class MyJPushReceiver extends BroadcastReceiver { } private void doDownloadAndInstall(String jsonString) { - File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/"); + File file = new File(JGYUtils.getInstance().getDownLoadPath()); if (!file.exists()) { file.mkdirs(); } if (TextUtils.isEmpty(jsonString)) { - Logutils.e(TAG, "doDownloadAndInstall: extras is null"); + Log.e(TAG, "doDownloadAndInstall: extras is null"); return; } JSONObject jSONObject = JSON.parseObject(jsonString); @@ -481,8 +505,8 @@ public class MyJPushReceiver extends BroadcastReceiver { packageObj.put("app_package", app_package); packageObj.put("app_id", app_id); packageObj.put("MD5", MD5); - Logutils.e(TAG, "doDownloadAndInstall: app_package:" + app_package); - Logutils.e(TAG, "doDownloadAndInstall: app_url:" + app_url); + Log.e(TAG, "doDownloadAndInstall: app_package:" + app_package); + Log.e(TAG, "doDownloadAndInstall: app_url:" + app_url); SaveListUtils.addList(app_package); SaveListUtils.sendForceAPP(mContext); PackageManager pm = mContext.getPackageManager(); @@ -493,9 +517,9 @@ public class MyJPushReceiver extends BroadcastReceiver { e.printStackTrace(); } if (packageInfo == null) { - Logutils.e(TAG, "doDownloadAndInstall: " + app_package + "未安装"); + Log.e(TAG, "doDownloadAndInstall: " + app_package + "未安装"); if (!SaveListUtils.isDownLoading(app_url)) { - Logutils.e(TAG, "doDownloadAndInstall: " + app_package + "开始下载"); + Log.e(TAG, "doDownloadAndInstall: " + app_package + "开始下载"); Utils.ariaDownload(mContext, app_url, packageObj); } } else { @@ -510,7 +534,7 @@ public class MyJPushReceiver extends BroadcastReceiver { Utils.ariaDownload(mContext, app_url, packageObj); } } else { - Logutils.e(TAG, "doDownloadAndInstall: " + app_package + "已安装最新版"); + Log.e(TAG, "doDownloadAndInstall: " + app_package + "已安装最新版"); } } } @@ -536,7 +560,7 @@ public class MyJPushReceiver extends BroadcastReceiver { .subscribe(new Observer() { @Override public void onSubscribe(Disposable param1Disposable) { - Logutils.e("getDeselectID", "onSubscribe: "); + Log.e("getDeselectID", "onSubscribe: "); } @Override @@ -545,7 +569,7 @@ public class MyJPushReceiver extends BroadcastReceiver { String packages = ""; try { String responString = param1ResponseBody.string(); - Logutils.e("getDeselectID", "onNext: " + responString); + Log.e("getDeselectID", "onNext: " + responString); JSONObject jSONObject = JSON.parseObject(responString); int code = jSONObject.getInteger("code"); if (code == 200) { @@ -553,7 +577,7 @@ public class MyJPushReceiver extends BroadcastReceiver { packages = jSONObject.getJSONObject("data").getString("package"); } } catch (Exception e) { - Logutils.e("getDeselectID", "onNext: Exception: " + e.getMessage()); + Log.e("getDeselectID", "onNext: Exception: " + e.getMessage()); e.printStackTrace(); } JGYUtils.getInstance().writeDeselectIDtoSystem(ids, packages); @@ -561,12 +585,12 @@ public class MyJPushReceiver extends BroadcastReceiver { @Override public void onError(Throwable param1Throwable) { - Logutils.e("getDeselectID", "onError: " + param1Throwable.getMessage()); + Log.e("getDeselectID", "onError: " + param1Throwable.getMessage()); } @Override public void onComplete() { - Logutils.e("getDeselectID", "onComplete: "); + Log.e("getDeselectID", "onComplete: "); } }); } @@ -574,23 +598,23 @@ public class MyJPushReceiver extends BroadcastReceiver { private void setDisableSlideList(String s) { JSONObject jSONObject = JSON.parseObject(s); - Logutils.e("setDisableSlideList", "jSONObject::" + jSONObject.toString()); + Log.e("setDisableSlideList", "jSONObject::" + jSONObject.toString()); String strban = jSONObject.getString("ban"); String strnot = jSONObject.getString("not"); String qch_disable_slide = Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide"); - Logutils.e("fht", "qch_disable_slide::" + qch_disable_slide); + Log.e("fht", "qch_disable_slide::" + qch_disable_slide); if (!TextUtils.isEmpty(strban)) { Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", strban); - Logutils.e("fht", "sendban::" + strban); + Log.e("fht", "sendban::" + strban); } else { Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid"); } - Logutils.e("fht", "qch_disable_slide::" + Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide")); + Log.e("fht", "qch_disable_slide::" + Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide")); } private void setDisableUpdateList(String s) { - Logutils.e("setDisableUpdateList", s); + Log.e("setDisableUpdateList", s); JSONObject jsonObject = JSON.parseObject(s); String ban = jsonObject.getString("ban"); String not = jsonObject.getString("not"); @@ -605,14 +629,14 @@ public class MyJPushReceiver extends BroadcastReceiver { Intent intent = new Intent("qch_camera_forbid").setPackage("com.android.settings"); intent.putExtra("camera_package_name", "close"); this.mContext.sendBroadcast(intent); - Logutils.e(TAG, "settingNetControl extras is null"); + Log.e(TAG, "settingNetControl extras is null"); return; } JSONObject jSONObject = JSON.parseObject(s); String s1 = jSONObject.getString("ban"); // String str = jSONObject.optString("not"); - Logutils.e("settingCamera", "ban::" + s1); -// Logutils.e("settingCamera", "not::" + str); + Log.e("settingCamera", "ban::" + s1); +// Log.e("settingCamera", "not::" + str); if ("0".equals(s1)) { Intent intent2 = new Intent("qch_camera_forbid").setPackage("com.android.settings"); // intent2.putExtra("camera_package_name", s1); @@ -626,11 +650,11 @@ public class MyJPushReceiver extends BroadcastReceiver { private void settingOneNet(String s) { if (TextUtils.isEmpty(s)) { - Logutils.e(TAG, "settingNetControl extras is null"); + Log.e(TAG, "settingNetControl extras is null"); // return; } JSONObject jSONObject = JSON.parseObject(s); - Logutils.e("settingOneNet", "jSONObject::" + jSONObject.toString()); + Log.e("settingOneNet", "jSONObject::" + jSONObject.toString()); String packages = jSONObject.getString("package"); String status = jSONObject.getString("status"); @@ -638,10 +662,10 @@ public class MyJPushReceiver extends BroadcastReceiver { private void settingNetControl(String s) { if (TextUtils.isEmpty(s)) { - Logutils.e(TAG, "settingNetControl extras is null"); + Log.e(TAG, "settingNetControl extras is null"); } JSONObject jSONObject = JSON.parseObject(s); - Logutils.e("settingNetControl", "jSONObject::" + jSONObject.toString()); + Log.e("settingNetControl", "jSONObject::" + jSONObject.toString()); String disallow = jSONObject.getString("ban"); String allow = jSONObject.getString("not"); HashSet disallowApp = new HashSet<>(Arrays.asList(disallow.split(","))); @@ -650,13 +674,13 @@ public class MyJPushReceiver extends BroadcastReceiver { private void settingPowerOn(String s) { if (TextUtils.isEmpty(s)) { - Logutils.e(TAG, "settingPowerOn extras is null"); + Log.e(TAG, "settingPowerOn extras is null"); return; } JSONObject jSONObject = JSON.parseObject(s); String ban = jSONObject.getString("ban"); String not = jSONObject.getString("not"); - Logutils.e(TAG, "settingPowerOn: qch_app_power_on = " + not); + Log.e(TAG, "settingPowerOn: qch_app_power_on = " + not); if (TextUtils.isEmpty(not)) { //当 qch_app_power_on 的值为空时,会造成系统所有应用断网 Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "Invalid"); @@ -668,8 +692,8 @@ public class MyJPushReceiver extends BroadcastReceiver { private void writeDeselectBrowserIDtoSystem(String s) { boolean bool = Settings.System.putString(this.mContext.getContentResolver(), "DeselectBrowserArray", s); - Logutils.e("SystemSetting", "DeselectBrowserArray---------" + s); - Logutils.e("SystemSetting", "DeselectBrowserArray---------" + bool); + Log.e("SystemSetting", "DeselectBrowserArray---------" + s); + Log.e("SystemSetting", "DeselectBrowserArray---------" + bool); } private void setHomepagtag(String s) { @@ -681,7 +705,7 @@ public class MyJPushReceiver extends BroadcastReceiver { HTTPInterface.getAppinsideWeb(mContext, new HTTPInterface.GetAppinsideWebCallback() { @Override public void onComplete() { - Logutils.e(TAG, "ononComplete: setAPPinsideWebsite"); + Log.e(TAG, "ononComplete: setAPPinsideWebsite"); } }); } @@ -693,14 +717,14 @@ public class MyJPushReceiver extends BroadcastReceiver { */ public void settingLock(String s) { if (TextUtils.isEmpty(s)) { - Logutils.e(TAG, "settingLock extras is null"); + Log.e(TAG, "settingLock extras is null"); return; } JSONObject jSONObject = JSON.parseObject(s); int i = changeNum(jSONObject.getIntValue("lock")); Settings.System.putInt(this.mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, i); - Logutils.e("SystemSetting", "qch_unlock_ipad---------" + i); + Log.e("SystemSetting", "qch_unlock_ipad---------" + i); if (getBatteryLevel() >= CommonDatas.MIN_POWER) { Utils.doMasterClear(mContext); @@ -713,7 +737,7 @@ public class MyJPushReceiver extends BroadcastReceiver { JSONObject jSONObject = JSON.parseObject(s); long createTime = jSONObject.getLong("createTime"); if (createTime != 0) { - Logutils.e("createTime", String.valueOf(createTime)); + Log.e("createTime", String.valueOf(createTime)); doscreenshot(createTime); } } @@ -739,13 +763,13 @@ public class MyJPushReceiver extends BroadcastReceiver { if (integer == 0) { uplaodImage(time); } else { - Logutils.e("doss", "失败"); + Log.e("doss", "失败"); } } @Override public void onError(Throwable e) { - Logutils.e("doss", "Throwable=" + e.getMessage()); + Log.e("doss", "Throwable=" + e.getMessage()); } @Override @@ -762,7 +786,7 @@ public class MyJPushReceiver extends BroadcastReceiver { File file = new File(filepath + File.separator + time + ".db"); //不要直接使用常用图片格式 if (!file.exists()) { - Logutils.e("uplaodImage", "File does not exists"); + Log.e("uplaodImage", "File does not exists"); return; } //设置图片格式 @@ -772,8 +796,11 @@ public class MyJPushReceiver extends BroadcastReceiver { RequestBody fileBody = RequestBody.Companion.create(file, mediaType); //设置一个file文件 MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), fileBody); + Map params = new HashMap<>(); + params.put("sn", Utils.getSerial()); + params.put("createtime", String.valueOf(time)); NetInterfaceManager.getInstance().getScreenshotApi() - .sendScreenshot(Utils.getSerial(), time, body) + .sendScreenshot(params, body) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer() { @@ -868,7 +895,7 @@ public class MyJPushReceiver extends BroadcastReceiver { // mediaPlayer.prepare(); mediaPlayer.setLooping(false); int duration = mediaPlayer.getDuration() / 1000; - Logutils.e(TAG, "defaultCallMediaPlayer: " + "duration: " + duration); + Log.e(TAG, "defaultCallMediaPlayer: " + "duration: " + duration); int loop = 0; if (duration <= 1) { loop = 30; @@ -884,13 +911,13 @@ public class MyJPushReceiver extends BroadcastReceiver { setMaxVolume(context); mediaPlayer.start(); soundCount[0] += 1; - Logutils.e(TAG, "onCompletion: " + "loop: " + finalLoop); - Logutils.e(TAG, "onCompletion: " + "soundCount: " + soundCount[0]); + Log.e(TAG, "onCompletion: " + "loop: " + finalLoop); + Log.e(TAG, "onCompletion: " + "soundCount: " + soundCount[0]); } else { mediaPlayer.stop(); mediaPlayer.release(); - Logutils.e(TAG, "onCompletion: " + "loop: " + finalLoop); - Logutils.e(TAG, "onCompletion: " + "soundCount: " + soundCount[0]); + Log.e(TAG, "onCompletion: " + "loop: " + finalLoop); + Log.e(TAG, "onCompletion: " + "soundCount: " + soundCount[0]); } } }); @@ -899,7 +926,7 @@ public class MyJPushReceiver extends BroadcastReceiver { mediaPlayer.start(); } catch (Exception e) { e.printStackTrace(); - Logutils.e(TAG, "defaultCallMediaPlayer: " + e.getMessage()); + Log.e(TAG, "defaultCallMediaPlayer: " + e.getMessage()); } } @@ -921,17 +948,17 @@ public class MyJPushReceiver extends BroadcastReceiver { JSONObject jsonObject = JSONObject.parseObject(extras); String packageName = jsonObject.getString("app_package"); if (TextUtils.isEmpty(packageName)) { - Logutils.e(TAG, "cleanCache: " + "package is empty"); + Log.e(TAG, "cleanCache: " + "package is empty"); } else { try { if (new CacheUtils().cleanApplicationUserData(context, packageName)) { - Logutils.e(TAG, "cleanCache: " + packageName + " success"); + Log.e(TAG, "cleanCache: " + packageName + " success"); } else { - Logutils.e(TAG, "cleanCache: " + packageName + " failed"); + Log.e(TAG, "cleanCache: " + packageName + " failed"); } } catch (Exception e) { e.printStackTrace(); - Logutils.e(TAG, "cleanCache: " + e.getMessage()); + Log.e(TAG, "cleanCache: " + e.getMessage()); } } } @@ -939,8 +966,8 @@ 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); + Log.e(TAG + ":" + "getDeveloper", "onNext: " + is_developer); + Log.e(TAG, "setDeveloperoptions: " + is_developer); JGYUtils.getInstance().setDeveloperOptions(is_developer == 0 ? 1 : 0); } @@ -953,7 +980,7 @@ public class MyJPushReceiver extends BroadcastReceiver { if (JGYUtils.getInstance().isSamePlatform(platform)) { checkAPPInstall(jsonObject); } else { - Logutils.e(TAG, "GlobalUpdate: " + "应用与app平台不符合"); + Log.e(TAG, "GlobalUpdate: " + "应用与app平台不符合"); } } @@ -970,7 +997,7 @@ public class MyJPushReceiver extends BroadcastReceiver { if (packageInfo == null || packageInfo.getLongVersionCode() < version_code) { Utils.ariaDownload(mContext, jsonObject.getString("app_url"), jsonObject); } else { - Logutils.e(TAG, "checkAPPInstall: " + "已经是最新版"); + Log.e(TAG, "checkAPPInstall: " + "已经是最新版"); } } @@ -978,9 +1005,44 @@ public class MyJPushReceiver extends BroadcastReceiver { JSONObject jsonObject = JSON.parseObject(jsonString); String ebagCode = jsonObject.getString("ebagCode"); if (TextUtils.isEmpty(ebagCode)) { - Logutils.e(TAG, "setEbagCode: " + "ebagCode is empty"); + Log.e(TAG, "setEbagCode: " + "ebagCode is empty"); } else { SPUtils.put(mContext, "ebagCode", ebagCode); } } + + private void recordLog(Context context, String jsonString) { + HTTPInterface.getRunLog(context); + } + + private static final int ACTION_PULL = 1; + private static final int ACTION_DELETE = 2; + private static final int ACTION_UPGRADE = 3; + + private void customOrder(Context context, String jsonString) { + Gson gson = new Gson(); + Type type = new TypeToken() { + }.getType(); + RemoteDebug remoteDebug = gson.fromJson(jsonString, type); + if (remoteDebug != null) { + String pkg = remoteDebug.getApp_package(); + String content = remoteDebug.getContent(); + switch (remoteDebug.getType()) { + case ACTION_PULL: + Log.e(TAG, "customOrder: 唤起"); + ApkUtils.openPackage(context, pkg); + break; + case ACTION_DELETE: + Log.e(TAG, "customOrder: 删除"); + ApkUtils.UninstallAPP(context, pkg); + break; + case ACTION_UPGRADE: + Log.e(TAG, "customOrder: 更新"); + HTTPInterface.getForceDownload(context); + break; + default: + break; + } + } + } } diff --git a/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java b/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java index 84df1d0..07d127b 100644 --- a/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java +++ b/app/src/main/java/com/aoleyun/sn/receiver/NewAppReceiver.java @@ -14,7 +14,6 @@ import com.aoleyun.sn.network.HTTPInterface; import com.aoleyun.sn.utils.ApkUtils; import com.aoleyun.sn.utils.CacheUtils; import com.aoleyun.sn.utils.JGYUtils; -import com.aoleyun.sn.utils.Logutils; import com.aoleyun.sn.utils.SPUtils; import com.aoleyun.sn.utils.SaveListUtils; @@ -42,10 +41,10 @@ public class NewAppReceiver extends BroadcastReceiver { mContext = context; String action = intent.getAction(); JGYUtils.getInstance().cleanLauncherCache(); - Logutils.e(TAG, "onReceive: " + "action = " + action); + Log.e(TAG, "onReceive: " + "action = " + action); String state; if (TextUtils.isEmpty(action)) { - Logutils.e(TAG, "onReceive: " + "action is empty "); + Log.e(TAG, "onReceive: " + "action is empty "); return; } String packageName = intent.getDataString().replace("package:", ""); @@ -64,7 +63,7 @@ public class NewAppReceiver extends BroadcastReceiver { state = "未知:"; break; } - Logutils.e(TAG, "sendAppInfo: " + state + packageName); + Log.e(TAG, "sendAppInfo: " + state + packageName); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (!PackageNames.APPSTORE.equals(packageName) || !PackageNames.DEVICE_INFO.equals(packageName)) { ApkUtils.addShortcut(context); @@ -93,9 +92,7 @@ public class NewAppReceiver extends BroadcastReceiver { private static void sendAppInfo() { Observable.create((ObservableEmitter emitter) -> { - newAppListener = (String packageName) -> { - emitter.onNext(packageName); - }; + newAppListener = emitter::onNext; }) .throttleLast(5, TimeUnit.SECONDS) //这句很关键,这是RxJava中的操作符,在规定时间内观察者不在接收被观察者发送的事件 @@ -107,15 +104,15 @@ public class NewAppReceiver extends BroadcastReceiver { @Override public void onNext(@NonNull String s) { - Logutils.e(TAG, "sendAppInfo: onNext: " + s); + Log.e(TAG, "sendAppInfo: onNext: " + s); SaveListUtils.getDownLoadList().remove(s); ApkUtils.getAppInfo(mContext); //HTTPInterface.getNetAndLaunchSetting(mContext); HTTPInterface.getAppLimit(mContext); -// HTTPInterface.getAppinsideWeb(mContext, () -> Logutils.e(TAG, "onNext: setAPPinsideWebsite")); +// HTTPInterface.getAppinsideWeb(mContext, () -> Log.e(TAG, "onNext: setAPPinsideWebsite")); String oldDesktop = (String) SPUtils.get(mContext, "default_launcher", ""); if (s.equals(oldDesktop)){ - ApkUtils.openApp(mContext, s); + ApkUtils.openPackage(mContext, s); } } @@ -126,7 +123,7 @@ public class NewAppReceiver extends BroadcastReceiver { @Override public void onComplete() { - Logutils.e(TAG, "onComplete: "); + Log.e(TAG, "onComplete: "); } }); } diff --git a/app/src/main/java/com/aoleyun/sn/service/GuardService.java b/app/src/main/java/com/aoleyun/sn/service/GuardService.java index 57a14b4..a70a844 100644 --- a/app/src/main/java/com/aoleyun/sn/service/GuardService.java +++ b/app/src/main/java/com/aoleyun/sn/service/GuardService.java @@ -35,7 +35,6 @@ import com.aoleyun.sn.network.api.newapi.GetLockStateApi; import com.aoleyun.sn.receiver.BootReceiver; import com.aoleyun.sn.receiver.NewAppReceiver; import com.aoleyun.sn.utils.JGYUtils; -import com.aoleyun.sn.utils.Logutils; import com.aoleyun.sn.utils.SPUtils; import com.aoleyun.sn.utils.XAPKUtils; import com.aoleyun.sn.KeepAliveConnection; @@ -75,7 +74,7 @@ public class GuardService extends Service { private ServiceConnection mServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { - Logutils.w(TAG, "GuardService:建立链接"); + Log.w(TAG, "GuardService:建立链接"); boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(GuardService.this, StepService.class.getName()); if (!isServiceRunning) { startService(new Intent(GuardService.this, StepService.class)); @@ -119,7 +118,7 @@ public class GuardService extends Service { @Override public void onNext(Long aLong) { - Logutils.e(TAG, "timeObserver: onNext: " + aLong); + Log.e(TAG, "timeObserver: onNext: " + aLong); startService(new Intent(GuardService.this, MainService.class)); } @@ -151,7 +150,7 @@ public class GuardService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - Logutils.e(TAG, "onStartCommand: "); + Log.e(TAG, "onStartCommand: "); Aria.init(this); Aria.download(this).register(); // 绑定建立链接 @@ -197,8 +196,12 @@ public class GuardService extends Service { filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_USER_UNLOCKED); - filter.addAction("android.intent.action.FACTORY_RESET"); - filter.addAction("android.intent.action.MASTER_CLEAR"); + filter.addAction(Intent.ACTION_FACTORY_RESET); + filter.addAction(Intent.ACTION_MASTER_CLEAR); + filter.addAction(Intent.ACTION_MASTER_CLEAR_NOTIFICATION); + filter.addAction("android.intent.action.FORCE_FACTORY_RESET"); + filter.addAction(Intent.ACTION_SHUTDOWN); + filter.addAction(Intent.ACTION_REBOOT); registerReceiver(presentReceiver, filter); } @@ -206,7 +209,7 @@ public class GuardService extends Service { @Override public void onReceive(final Context context, Intent intent) { String action = intent.getAction(); - Logutils.e(TAG, "action:" + action); + Log.e(TAG, "action:" + action); switch (action) { default: break; @@ -267,18 +270,50 @@ public class GuardService extends Service { sendScreenStatus(2); } break; - case "android.intent.action.FACTORY_RESET": - case "android.intent.action.MASTER_CLEAR": - case "android.intent.action.MASTER_CLEAR_NOTIFICATION": + case Intent.ACTION_SHUTDOWN: + case Intent.ACTION_REBOOT: + int restart_count = (int) SPUtils.get(context, "restart_count", 0); + SPUtils.put(context, "restart_count", restart_count + 1); +// android.os.Process.killProcess(android.os.Process.myPid()); + break; + case Intent.ACTION_FACTORY_RESET: + case Intent.ACTION_MASTER_CLEAR: + case Intent.ACTION_MASTER_CLEAR_NOTIFICATION: case "android.intent.action.FORCE_FACTORY_RESET": - Logutils.e("PresentReceiver", "MASTER_CLEAR"); - android.os.Process.killProcess(android.os.Process.myPid()); - System.exit(0); + sendRestoreTimes(); + Log.e("PresentReceiver", "MASTER_CLEAR"); +// android.os.Process.killProcess(android.os.Process.myPid()); +// System.exit(0); break; } } } + private void sendRestoreTimes() { + NetInterfaceManager.getInstance().getRestoreTimesApi() + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + Log.e("sendRestoreTimes", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse baseResponse) { + Log.e("sendRestoreTimes", "onNext: "); + } + + @Override + public void onError(Throwable e) { + Log.e("sendRestoreTimes", "onError: " + e.getMessage()); + } + + @Override + public void onComplete() { + Log.e("sendRestoreTimes", "onComplete: "); + } + }); + } + private void sendScreenStatus(int status) { Retrofit retrofit = new Retrofit.Builder() .client(NetInterfaceManager.getInstance().getOkHttpClient()) @@ -378,7 +413,7 @@ public class GuardService extends Service { // 最大电量 int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0); int elec = (level * 100) / scale; -// Logutils.e(TAG, "electricity:=" + elec + "%"); +// Log.e(TAG, "electricity:=" + elec + "%"); if (elec == 50) { start.onstar(SystemClock.elapsedRealtime()); } @@ -388,7 +423,7 @@ public class GuardService extends Service { || Intent.ACTION_BATTERY_OKAY.equals(action) ) { setDefaultUSBStatus(); - Logutils.e(TAG, action); + Log.e(TAG, action); start.onstar(SystemClock.elapsedRealtime()); } } @@ -396,7 +431,7 @@ public class GuardService extends Service { private void setDefaultUSBStatus() { String setting_usb = Settings.System.getString(getContentResolver(), "qch_usb_choose"); - Logutils.e("setDefaultUSBStatus", "setting_usb---------" + setting_usb); + Log.e("setDefaultUSBStatus", "setting_usb---------" + setting_usb); String usbStatus = ""; if (TextUtils.isEmpty(setting_usb)) { usbStatus = "qch_action_usb_usb_charge"; @@ -425,7 +460,7 @@ public class GuardService extends Service { JSONObject jsonObject = JSON.parseObject(task.getExtendField()); String app_name = jsonObject.getString("app_name"); String app_package = jsonObject.getString("app_package"); - Logutils.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField()); + Log.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField()); ToastUtil.show("正在下载:" + app_name + "-" + task.getPercent() + "%" + "\t" + Formatter.formatFileSize(GuardService.this, task.getSpeed()) + "/s"); } @@ -434,8 +469,8 @@ public class GuardService extends Service { //在这里处理任务完成的状态 String filepath = task.getFilePath(); String extendField = task.getExtendField(); - Logutils.e("taskComplete", "downloadPath::" + filepath); - Logutils.e("taskComplete", "extendField::" + extendField); + Log.e("taskComplete", "downloadPath::" + filepath); + Log.e("taskComplete", "extendField::" + extendField); if (filepath.endsWith("apk")) { JSONObject jsonObject = JSON.parseObject(extendField); @@ -445,13 +480,13 @@ public class GuardService extends Service { ToastUtil.show(app_name + "\t:下载完成"); if (filepath.endsWith(".xapk")) { XAPKUtils.getInstance().installXAPK(filepath); - Logutils.e(TAG, "taskComplete: " + filepath); + Log.e(TAG, "taskComplete: " + filepath); } else if (filepath.endsWith(".apk")) { new Thread(() -> ApkUtils.installApp(GuardService.this, filepath)).start(); List list = Aria.download(this).getDRunningTask(); if (list == null || list.size() == 0) { BaseApplication.getInstance().setDownloadState(false); - Logutils.e("taskComplete", "isDownloading=" + BaseApplication.getInstance().isDownloading()); + Log.e("taskComplete", "isDownloading=" + BaseApplication.getInstance().isDownloading()); } } NetInterfaceManager.getInstance() @@ -495,12 +530,12 @@ public class GuardService extends Service { @Override public void onNext(BaseResponse baseResponse) { - Log.e("SEND_DOWNLOAD_FILE_INFO", "onNext: "+baseResponse.msg); + Log.e("SEND_DOWNLOAD_FILE_INFO", "onNext: " + baseResponse.msg); } @Override public void onError(Throwable e) { - Log.e("SEND_DOWNLOAD_FILE_INFO", "onError: "+e.getMessage()); + Log.e("SEND_DOWNLOAD_FILE_INFO", "onError: " + e.getMessage()); } @Override @@ -509,7 +544,7 @@ public class GuardService extends Service { } }); } else if (filepath.endsWith(".zip")) { - Logutils.e("taskComplete", "下载完成:" + task.getPercent() + ":" + task.getExtendField()); + Log.e("taskComplete", "下载完成:" + task.getPercent() + ":" + task.getExtendField()); JGYUtils.getInstance().setBootanimation(task.getFilePath()); } } @@ -522,10 +557,10 @@ public class GuardService extends Service { JSONObject jsonObject = JSON.parseObject(task.getExtendField()); String app_name = jsonObject.getString("app_name"); String app_package = jsonObject.getString("app_package"); - Logutils.e("aria", "下载失败: " + packageName + "filepath: " + filepath + "Exception: " + e.getMessage()); + Log.e("aria", "taskFail: " + packageName + "filepath: " + filepath + "Exception: " + e.getMessage()); // ToastUtil.show(app_name + "\t:下载失败"); } catch (Exception e1) { - Logutils.e("aria", "taskFail: " + e1.getMessage()); + Log.e("aria", "taskFail: " + e1.getMessage()); } } } diff --git a/app/src/main/java/com/aoleyun/sn/service/JWebSocketClient.java b/app/src/main/java/com/aoleyun/sn/service/JWebSocketClient.java index 8ab3416..acd693e 100644 --- a/app/src/main/java/com/aoleyun/sn/service/JWebSocketClient.java +++ b/app/src/main/java/com/aoleyun/sn/service/JWebSocketClient.java @@ -1,6 +1,6 @@ package com.aoleyun.sn.service; -import com.aoleyun.sn.utils.Logutils; +import android.util.Log; import org.java_websocket.client.WebSocketClient; import org.java_websocket.drafts.Draft_6455; @@ -15,22 +15,22 @@ public class JWebSocketClient extends WebSocketClient { @Override public void onOpen(ServerHandshake handshakedata) { - Logutils.e("JWebSocketClient", "onOpen()"); + Log.e("JWebSocketClient", "onOpen()"); } @Override public void onMessage(String message) { - Logutils.e("JWebSocketClient", "onMessage()"); + Log.e("JWebSocketClient", "onMessage()"); } @Override public void onClose(int code, String reason, boolean remote) { - Logutils.e("JWebSocketClient", "onClose():" + reason); + Log.e("JWebSocketClient", "onClose():" + reason); } @Override public void onError(Exception ex) { - Logutils.e("JWebSocketClient", "onError():" + ex.getMessage()); + Log.e("JWebSocketClient", "onError():" + ex.getMessage()); } } \ No newline at end of file diff --git a/app/src/main/java/com/aoleyun/sn/service/LogcatService.java b/app/src/main/java/com/aoleyun/sn/service/LogcatService.java index 14b9be3..cc82c6a 100644 --- a/app/src/main/java/com/aoleyun/sn/service/LogcatService.java +++ b/app/src/main/java/com/aoleyun/sn/service/LogcatService.java @@ -7,8 +7,11 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.IBinder; import android.text.TextUtils; +import android.util.Log; -import com.aoleyun.sn.utils.Logutils; +import com.aoleyun.sn.bean.BaseResponse; +import com.aoleyun.sn.bean.SnRunLog; +import com.aoleyun.sn.network.NetInterfaceManager; import com.aoleyun.sn.utils.Utils; import java.io.BufferedReader; @@ -19,6 +22,16 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.RequestBody; public class LogcatService extends Service { public final static String LOGCAT_START_ACTION = "START"; @@ -58,11 +71,33 @@ public class LogcatService extends Service { //// exec.destroy(); // } catch (IOException e) { //// e.printStackTrace(); -// Logutils.e("第一个是Logcat", e.getMessage()); +// Log.e("第一个是Logcat", e.getMessage()); // } registerLogcatReceiver(); } + private static long start_Time; + private static long condition_duration; + private static long condition_file_max_size; + private static boolean clear_file; + + public static void setStart_Time(long start_Time) { + LogcatService.start_Time = start_Time; + } + + public static void setDuration(long duration) { + condition_duration = duration; + } + + public static void setFileMaxSize(long fileMaxSize) { + condition_file_max_size = fileMaxSize * 1024 * 1024; + } + + public static void setClearFile(int clearfile) { + clear_file = clearfile == 1; + } + + LogcatReceiver receiver; private void registerLogcatReceiver() { @@ -103,6 +138,7 @@ public class LogcatService extends Service { e.printStackTrace(); } } + uploadFile(); } @@ -118,6 +154,7 @@ public class LogcatService extends Service { String logFilePath; //= getExternalCacheDir() + File.separator + "LOG" + File.separator; String logFileName; + String tempFilePath; class LogThread extends Thread { InputStream is; @@ -133,7 +170,7 @@ public class LogcatService extends Service { try { //新建一个路径信息 File file = new File(logFilePath + logFileName); - Logutils.e(TAG, "run: " + logFilePath); + Log.e(TAG, "run: " + logFilePath); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); @@ -146,7 +183,7 @@ public class LogcatService extends Service { os.flush(); } } catch (Exception e) { - Logutils.e("writelog", "read logcat process failed. message: " + Log.e("writelog", "read logcat process failed. message: " + e.getMessage()); } finally { if (null != os) { @@ -161,12 +198,7 @@ public class LogcatService extends Service { } } - private Runnable LogcatRunnale = new Runnable() { - @Override - public void run() { - getLog(); - } - }; + private Runnable LogcatRunnale = this::getLog; public static boolean shouldGetLog = true; @@ -181,27 +213,41 @@ public class LogcatService extends Service { BufferedReader bufferedReader; FileOutputStream fileOutputStream; File file = new File(logFilePath); - Logutils.e(TAG, "getLog: " + logFilePath); + Log.e(TAG, "getLog: " + logFilePath); if (!file.exists()) { file.mkdirs(); } - logFileName = Utils.getSerial() + "-" + getTime() + ".log"; + + if (clear_file) { + logFileName = Utils.getSerial() + ".log"; + } else { + logFileName = Utils.getSerial() + "-" + getTime() + ".log"; + } + try { inputStreamReader = new InputStreamReader(process.getInputStream()); bufferedReader = new BufferedReader(inputStreamReader); - fileOutputStream = new FileOutputStream(logFilePath + logFileName); - Logutils.e(TAG, "getLog: " + logFilePath + logFileName); - + tempFilePath = logFilePath + logFileName; + fileOutputStream = new FileOutputStream(tempFilePath); + Log.e(TAG, "getLog: " + tempFilePath); + long fileSize = file.length(); String logEntry; while (shouldGetLog) { logEntry = bufferedReader.readLine() + "\n"; fileOutputStream.write(logEntry.getBytes()); fileOutputStream.flush(); + fileSize += logEntry.length(); +// Log.e(TAG, "getLog: " + fileSize); + if (fileSize >= condition_file_max_size || + (start_Time + condition_duration) * 1000 < System.currentTimeMillis()) { + shouldGetLog = false; + stopLogThread(); + } } inputStreamReader.close(); bufferedReader.close(); fileOutputStream.close(); - Logutils.e(TAG, "getLog: " + "closed"); + Log.e(TAG, "getLog: " + "closed"); } catch (IOException e) { e.printStackTrace(); } catch (NullPointerException e) { @@ -209,20 +255,66 @@ public class LogcatService extends Service { } } + private void uploadFile() { + File file = new File(tempFilePath); + if (!file.exists() || file.isDirectory()) { + Log.e("uploadFile", "File does not exists"); + return; + } + Map params = new HashMap<>(); + params.put("sn", Utils.getSerial()); + MediaType mediaType = MediaType.Companion.parse("text/plain"); + RequestBody fileBody = RequestBody.Companion.create(file, mediaType); + //设置一个file文件 + MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), fileBody); + + NetInterfaceManager.getInstance().getUploadLogApi() + .GetSnRunLog(params, body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer>() { + @Override + public void onSubscribe(Disposable d) { + Log.e("uploadFile", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse snRunLogBaseResponse) { + Log.e("uploadFile", "onNext: " + snRunLogBaseResponse); + } + + @Override + public void onError(Throwable e) { + Log.e("uploadFile", "onError: " + e.getMessage()); + + } + + @Override + public void onComplete() { + Log.e("uploadFile", "onComplete: "); + if (clear_file) { + file.delete(); + } + } + }); + } + class LogcatReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - Logutils.e(TAG, "onReceive: " + action); + Log.e(TAG, "onReceive: " + action); if (TextUtils.isEmpty(action)) { return; } switch (action) { case LOGCAT_START_ACTION: + Log.e(TAG, "onReceive: "+"开始录制log"); startLogThread(); break; case LOGCAT_STOP_ACTION: + Log.e(TAG, "onReceive: "+"停止录制log"); stopLogThread(); break; default: diff --git a/app/src/main/java/com/aoleyun/sn/service/MainService.java b/app/src/main/java/com/aoleyun/sn/service/MainService.java index c90c87a..ea1506a 100644 --- a/app/src/main/java/com/aoleyun/sn/service/MainService.java +++ b/app/src/main/java/com/aoleyun/sn/service/MainService.java @@ -1,10 +1,8 @@ package com.aoleyun.sn.service; import android.annotation.SuppressLint; -import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; -import android.app.PendingIntent; import android.app.Service; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -12,10 +10,8 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.PixelFormat; -import android.net.Uri; import android.os.Build; import android.os.IBinder; import android.os.SystemClock; @@ -29,37 +25,43 @@ import android.view.WindowManager; import android.widget.Button; import android.widget.TextView; -import androidx.annotation.RequiresApi; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.aoleyun.sn.comm.PackageNames; -import com.blankj.utilcode.util.NetworkUtils; -import com.google.gson.JsonObject; import com.aoleyun.sn.R; import com.aoleyun.sn.action.JGYActions; import com.aoleyun.sn.activity.MainActivity; import com.aoleyun.sn.activity.MainContact; import com.aoleyun.sn.activity.MainPresenter; +import com.aoleyun.sn.bean.PoweroffBean; +import com.aoleyun.sn.comm.PackageNames; import com.aoleyun.sn.receiver.BootReceiver; import com.aoleyun.sn.utils.ApkUtils; import com.aoleyun.sn.utils.ForegroundAppUtil; -import com.aoleyun.sn.utils.Logutils; +import com.aoleyun.sn.utils.JGYUtils; import com.aoleyun.sn.utils.SPUtils; import com.aoleyun.sn.utils.SaveListUtils; import com.aoleyun.sn.utils.SysSettingUtils; import com.aoleyun.sn.utils.TimeUtils; import com.aoleyun.sn.utils.ToastUtil; +import com.aoleyun.sn.utils.Utils; +import com.blankj.utilcode.util.NetworkUtils; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.tencent.mmkv.MMKV; import com.trello.rxlifecycle2.LifecycleProvider; import com.trello.rxlifecycle2.LifecycleTransformer; import com.trello.rxlifecycle2.RxLifecycle; import com.trello.rxlifecycle2.android.ActivityEvent; import com.trello.rxlifecycle2.android.RxLifecycleAndroid; +import java.lang.reflect.Type; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.concurrent.TimeUnit; import cn.jpush.android.api.JPushInterface; @@ -88,6 +90,7 @@ public class MainService extends Service implements MainContact.MainView, Networ runningTime = SystemClock.elapsedRealtime(); //直接获取数据 ToastUtil.betaShow("网络已连接"); + Utils.getPublicIP(this); mPresenter.getLockedState(); start.onstar(SystemClock.elapsedRealtime()); } @@ -130,7 +133,7 @@ public class MainService extends Service implements MainContact.MainView, Networ @Override public void onNext(Long aLong) { - Logutils.e("TimeObserver", "onNext: " + aLong); + Log.e("TimeObserver", "onNext: " + aLong); startCommandTime = runningTime = SystemClock.elapsedRealtime(); mPresenter.getFirstConnect(); mPresenter.getLockedState(); @@ -165,7 +168,7 @@ public class MainService extends Service implements MainContact.MainView, Networ mPresenter.setProvider(this); if ((int) SPUtils.get(this, "first_connect", 0) == 0) { // TODO: 2021/5/26 待底层修改,临时解决办法 - Logutils.e(TAG, "onCreate: " + "Disable All Settings"); + Log.e(TAG, "onCreate: " + "Disable All Settings"); mPresenter.setDisableSetting(); } registerReceivers(); @@ -209,20 +212,20 @@ public class MainService extends Service implements MainContact.MainView, Networ sendBroadcast(bootIntent); JPushInterface.init(this); if (MainActivity.isForeground) { - Logutils.e(TAG, "onStartCommand: MainService: isForeground: " + MainActivity.isForeground); + Log.e(TAG, "onStartCommand: MainService: isForeground: " + MainActivity.isForeground); } else { // if (((SystemClock.elapsedRealtime() - startCommandTime) < 60000) && startCommandTime != 0) { -// Logutils.e(TAG, "onStartCommand: " + "启动时间过短"); +// Log.e(TAG, "onStartCommand: " + "启动时间过短"); // //一分钟内防止多次调用 // } else { // mPresenter.getFirstConnect(); // mPresenter.getLockedState(); // startCommandTime = runningTime = SystemClock.elapsedRealtime(); -// Logutils.e(TAG, "onStartCommand: isForeground: " + MainActivity.isForeground); -// Logutils.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime)); +// Log.e(TAG, "onStartCommand: isForeground: " + MainActivity.isForeground); +// Log.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime)); // } start.onstar(SystemClock.elapsedRealtime()); - Logutils.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms"); + Log.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms"); } return START_STICKY; } @@ -268,9 +271,9 @@ public class MainService extends Service implements MainContact.MainView, Networ private void setStatusbar() { String status = (String) SPUtils.get(this, JGYActions.ACTION_STATUS_BAR_STATUS, ""); - Logutils.e(TAG, "setStatusbar: String: " + status); + Log.e(TAG, "setStatusbar: String: " + status); if (TextUtils.isEmpty(status)) { - Logutils.e(TAG, "setStatusbar: " + "status is NULL"); + Log.e(TAG, "setStatusbar: " + "status is NULL"); return; } JSONObject jsonObject = JSON.parseObject(status); @@ -393,7 +396,7 @@ public class MainService extends Service implements MainContact.MainView, Networ @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - Logutils.e("LockScreenReceiver", "onReceive: " + action); + Log.e("LockScreenReceiver", "onReceive: " + action); if (TextUtils.isEmpty(action)) { return; } @@ -473,44 +476,73 @@ public class MainService extends Service implements MainContact.MainView, Networ public void onReceive(Context context, Intent intent) { Log.e(TAG, "onReceive: " + intent.getAction()); if (Intent.ACTION_DATE_CHANGED.equals(intent.getAction())) { - Logutils.e("TimeChangedReceiver", "onReceive:" + "data changed"); + Log.e("TimeChangedReceiver", "onReceive:" + "data changed"); } else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) { - Logutils.e("TimeChangedReceiver", "onReceive:" + "time changed"); + Log.e("TimeChangedReceiver", "onReceive:" + "time changed"); } else if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) { - Logutils.e("TimeChangedReceiver", "onReceive:" + "timezone changed"); + Log.e("TimeChangedReceiver", "onReceive:" + "timezone changed"); } else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) { - Logutils.e("TimeChangedReceiver", "onReceive:" + "time tick"); + Log.e("TimeChangedReceiver", "onReceive:" + "time tick"); + checkShutdownTime(); setFloatingWindow(MainService.this); } else if (ACTION_UPDATE.equals(intent.getAction())) { setFloatingWindow(MainService.this); mPresenter.getScreenLockState(); - Logutils.e("TimeChangedReceiver", "onReceive:" + "date update"); + Log.e("TimeChangedReceiver", "onReceive:" + "date update"); } timeChangedStart.onstar(System.currentTimeMillis()); } } + private void checkShutdownTime() { + MMKV mmkv = MMKV.defaultMMKV(); + String poweroffTime = mmkv.decodeString("poweroffTime", ""); + Log.e("checkShutdownTime", "poweroffTime: " + poweroffTime); + Gson gson = new Gson(); + Type listType = new TypeToken>() { + }.getType(); + List poweroffBeanList = gson.fromJson(poweroffTime, listType); + if (poweroffBeanList != null && poweroffBeanList.size() != 0) { + boolean inTime = false; + for (PoweroffBean poweroffBean : poweroffBeanList) { + if (TimeUtils.isShutdownTime(poweroffBean)) { + inTime = true; + } + } + if (inTime) { + JGYUtils.getInstance().shutdown(); + Log.e(TAG, "checkShutdownTime: " + "设备关机"); + } else { + Log.e(TAG, "checkShutdownTime: " + "没有关机事件"); + } + } + } + synchronized private void setFloatingWindow(Context context) { ForegroundAppUtil.openTopApp(context); long nowTime = System.currentTimeMillis(); TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(MainService.this); + Log.e(TAG, "setFloatingWindow: " + contralTime); Log.e(TAG, "setFloatingWindow: screenlocked: " + screenlocked); if (null != contralTime) { if (contralTime.inControlTime(nowTime)) { + Log.e(TAG, "setFloatingWindow: " + "inControlTime is true"); if (!screenlocked) { - showFloatingWindow("管控时间:" + contralTime.toString()); + showFloatingWindow("设备可用时间:" + contralTime.toString()); } else { TextView textView = topView.findViewById(R.id.textView); - textView.setText("管控时间:" + contralTime.toString()); + textView.setText("设备可用时间:" + contralTime.toString()); } timelocked = true; } else { + Log.e(TAG, "setFloatingWindow: " + "inControlTime is false"); if (!screenlocked) { hideFloatingWindow(); } timelocked = false; } } else { + Log.e(TAG, "setFloatingWindow: " + "inControlTime is null"); if (!screenlocked) { hideFloatingWindow(); } @@ -540,25 +572,25 @@ public class MainService extends Service implements MainContact.MainView, Networ public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (TextUtils.isEmpty(action)) { - Logutils.e(TAG, "onReceive: " + "Action is NULL!"); + Log.e(TAG, "onReceive: " + "Action is NULL!"); return; } - Logutils.e(TAG, "onReceive: " + "Sender is " + intent.getPackage()); + Log.e(TAG, "onReceive: " + "Sender is " + intent.getPackage()); String packageName = intent.getStringExtra("packageName"); String filePath = intent.getStringExtra("filePath"); if (!TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(filePath)) { - Logutils.e(TAG, "onReceive: " + "packageName: " + packageName + "filePath: " + filePath); + Log.e(TAG, "onReceive: " + "packageName: " + packageName + "filePath: " + filePath); installApkByPackage(filePath, packageName); } else if (!TextUtils.isEmpty(filePath)) { String pkg = ApkUtils.getPackageName(MainService.this, filePath); if (TextUtils.isEmpty(pkg)) { - Logutils.e(TAG, "onReceive: " + "unknow packageName"); + Log.e(TAG, "onReceive: " + "unknow packageName"); } else { - Logutils.e(TAG, "onReceive: " + "pkg: " + pkg + "\tfilePath: " + filePath); + Log.e(TAG, "onReceive: " + "pkg: " + pkg + "\tfilePath: " + filePath); installApkByPackage(filePath, pkg); } } else { - Logutils.e(TAG, "onReceive: " + "no filePath and packageName"); + Log.e(TAG, "onReceive: " + "no filePath and packageName"); } } } @@ -572,9 +604,9 @@ public class MainService extends Service implements MainContact.MainView, Networ String oldListString = Settings.System.getString(getContentResolver(), "qch_app_forbid"); HashSet packageList = new HashSet<>(Arrays.asList(oldListString.split(","))); if (!packageList.contains(pkg)) { - Logutils.e(TAG, "installApkByPackage: " + "packageName: " + pkg + " not in whitelist"); + Log.e(TAG, "installApkByPackage: " + "packageName: " + pkg + " not in whitelist"); } else { - Logutils.e(TAG, "installApkByPackage: " + "packageName: " + pkg); + Log.e(TAG, "installApkByPackage: " + "packageName: " + pkg); ApkUtils.installApp(MainService.this, filePath); } } @@ -604,25 +636,29 @@ public class MainService extends Service implements MainContact.MainView, Networ } + @Override + public void setHead(String url) { + + } + @Override public void setLockedState(boolean loocked) { + //发送设备mac地址和信息 + mPresenter.sendMACAddress(); + //设置极光推送别名 + mPresenter.setJpushAlias(); + //设置极光推送标签 + mPresenter.setJpushTags(); if (loocked) { ToastUtil.betaShow("设备已上锁"); - Logutils.e(TAG, "setLockedState: " + netWorkIsRunning); + Log.e(TAG, "setLockedState: " + netWorkIsRunning); //上传APP信息 ApkUtils.getAppInfo(this); - //发送设备mac地址和信息 - mPresenter.sendMACAddress(); - //设置极光推送别名 - mPresenter.setJpushAlias(); - //设置极光推送标签 SaveListUtils.getList(); if (netWorkIsRunning) { //如果正在执行,不执行 // return; } - //获取系统管控 - mPresenter.setJpushTags(); netWorkIsRunning = true; } else { ToastUtil.betaShow("设备已解锁"); @@ -638,7 +674,7 @@ public class MainService extends Service implements MainContact.MainView, Networ */ @Override public void setFirstConnect(boolean state) { - Logutils.e(TAG, "isFirstConnect: " + "end request: " + state); + Log.e(TAG, "isFirstConnect: " + "end request: " + state); if (state) { mPresenter.setDisableSetting(); } else { @@ -647,57 +683,72 @@ public class MainService extends Service implements MainContact.MainView, Networ } @Override - public void sendMACFinished() { + public void sendMACFinish() { mPresenter.updateDeviceInfo(); } @Override - public void updateDeviceInfoFinished() { + public void updateDeviceInfoFinish() { mPresenter.getSnTimeControl(); } @Override - public void getSnTimeControlFinished() { + public void getSnTimeControlFinish() { mPresenter.getEBagCode(); } @Override - public void getEBagCodeFinished() { + public void getEBagCodeFinish() { } @Override - public void setAliasFinished() { + public void setAliasFinish() { mPresenter.checkStoreUpdate(); } @Override - public void setJpushPlatformTagsFinished() { + public void setJpushPlatformTagsFinish() { } @Override - public void checkStoreUpdateFinished() { + public void checkStoreUpdateFinish() { mPresenter.checkInfoUpdate(); } @Override - public void checkInfoUpdateFinished() { + public void checkInfoUpdateFinish() { + mPresenter.checkDesktopUpdate(); + } + + @Override + public void checkDesktopUpdateFinish() { + mPresenter.checkNotifyUpdate(); + } + + @Override + public void checkNotifyUpdateFinish() { + mPresenter.checkBrowserUpdate(); + } + + @Override + public void checkBrowserUpdateFinish() { mPresenter.checkTestUpdate(); } @Override - public void checkTestUpdateFinished() { + public void buttonCheckUpdateFinish(boolean update, JsonObject jsonObject) { } @Override - public void buttonCheckUpdateFinished(boolean update, JsonObject jsonObject) { + public void checkTestUpdateFinish() { } @Override - public void setTagsFinished(boolean noTag) { + public void setTagsFinish(boolean noTag) { if (noTag) { Log.e(TAG, "setTagsFinished: " + "not set tag"); netWorkIsRunning = false; @@ -705,6 +756,12 @@ public class MainService extends Service implements MainContact.MainView, Networ } else { mPresenter.getSystemSettingbegin(); } + mPresenter.getDeveloper(); + } + + @Override + public void getDeveloperFinish() { + Log.e(TAG, "getDeveloperFinished: "); } @Override @@ -713,89 +770,95 @@ public class MainService extends Service implements MainContact.MainView, Networ } @Override - public void getAppLimitFinished(String packageList) { + public void getAppLimitFinish(String packageList) { mPresenter.getDeviceBatch(packageList); } @Override - public void getDeviceBatchFinished() { + public void getDeviceBatchFinish() { mPresenter.getForceDownload(); } @Override - public void getForceDownloadFinished() { + public void getForceDownloadFinish() { mPresenter.getBrowserList(); } @Override - public void getBrowserListFinished(String whitelist) { + public void getBrowserListFinish(String whitelist) { mPresenter.getBrowserBookmarks(whitelist); } @Override - public void getBrowserBookmarksFinished() { + public void getBrowserBookmarksFinish() { mPresenter.getBrowserWhiteList(); mPresenter.getDesktopIcon(); } @Override - public void getDesktopIconFinished() { + public void getDesktopIconFinish() { mPresenter.getAppAutoStartUpdateAndNet(); } @Override - public void getAppAutoStartUpdateAndNetFinished() { + public void getAppAutoStartUpdateAndNetFinish() { mPresenter.getAppIDControl(); } @Override - public void getAppIDControlFinished() { + public void getAppIDControlFinish() { mPresenter.setAppinsideWeb(); } @Override - public void setAppinsideWebFinished() { + public void setAppinsideWebFinish() { mPresenter.setSystemSetting(); } @Override - public void setSystemSettingFinished() { + public void setSystemSettingFinish() { mPresenter.getDefaultApp(); } @Override - public void setDefaultAppFinished() { + public void setDefaultAppFinish() { mPresenter.getROMApp(); } @Override - public void getROMAppFinished() { - mPresenter.getDeveloper(); - } - - @Override - public void getDeveloperFinished() { + public void getROMAppFinish() { mPresenter.setLogoImg(); } @Override - public void setLogoImgFinished() { + public void setLogoImgFinish() { mPresenter.setTopApp(); } @Override - public void setTopAppFinished() { + public void setTopAppFinish() { mPresenter.getDefaultDesktop(); } @Override - public void getDefaultDesktopFinished() { + public void getDefaultDesktopFinish() { netWorkIsRunning = false; Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - runningTime) + " ms"); + mPresenter.getPoweroffTime(); } @Override - public void setScreenLockStateFinished(boolean locked, String tips) { + public void setPoweroffTime() { + mPresenter.getWiFiPasswd(); + } + + @Override + public void setWiFiPasswd() { + + } + + @Override + public void setScreenLockStateFinish(boolean locked, String tips) { if (locked) { if (!timelocked) { showFloatingWindow(tips); diff --git a/app/src/main/java/com/aoleyun/sn/service/RemoteService.java b/app/src/main/java/com/aoleyun/sn/service/RemoteService.java index 9671a59..3ebfef8 100644 --- a/app/src/main/java/com/aoleyun/sn/service/RemoteService.java +++ b/app/src/main/java/com/aoleyun/sn/service/RemoteService.java @@ -4,9 +4,9 @@ import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.os.RemoteException; +import android.util.Log; import com.aoleyun.sn.IGetLicenseInterface; -import com.aoleyun.sn.utils.Logutils; import com.aoleyun.sn.utils.SPUtils; public class RemoteService extends Service { @@ -17,7 +17,7 @@ public class RemoteService extends Service { @Override public IBinder onBind(Intent intent) { - Logutils.e(TAG, "onBind: "); + Log.e(TAG, "onBind: "); return mBinde; } @@ -35,7 +35,7 @@ public class RemoteService extends Service { @Override public String getLicense() throws RemoteException { String ebagCode = (String) SPUtils.get(RemoteService.this, "ebagCode", ""); - Logutils.e(TAG, "getLicense: " + ebagCode); + Log.e(TAG, "getLicense: " + ebagCode); return ebagCode; } }; diff --git a/app/src/main/java/com/aoleyun/sn/service/StepService.java b/app/src/main/java/com/aoleyun/sn/service/StepService.java index ec21088..ed48668 100644 --- a/app/src/main/java/com/aoleyun/sn/service/StepService.java +++ b/app/src/main/java/com/aoleyun/sn/service/StepService.java @@ -20,8 +20,6 @@ import com.alibaba.fastjson.JSONObject; import com.aoleyun.sn.BuildConfig; import com.blankj.utilcode.util.NetworkUtils; import com.aoleyun.sn.KeepAliveConnection; -import com.aoleyun.sn.network.NetInterfaceManager; -import com.aoleyun.sn.utils.Logutils; import com.aoleyun.sn.utils.ServiceAliveUtils; import com.aoleyun.sn.utils.Utils; @@ -61,7 +59,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus private ServiceConnection mServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { - Logutils.w(TAG, "StepService:建立链接"); + Log.w(TAG, "StepService:建立链接"); boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(StepService.this, GuardService.class.getName()); if (!isServiceRunning) { Intent i = new Intent(StepService.this, GuardService.class); @@ -99,7 +97,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus public int onStartCommand(Intent intent, int flags, int startId) { // startForeground(1, new Notification()); // 绑定建立链接 - Logutils.e("JWebSocketClientService", "onStartCommand: "); + Log.e("JWebSocketClientService", "onStartCommand: "); bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT); return START_STICKY; } @@ -117,6 +115,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus filter.addAction(Intent.ACTION_BOOT_COMPLETED); filter.addAction(Intent.ACTION_USER_PRESENT); filter.addAction(Intent.ACTION_SHUTDOWN); + filter.addAction(Intent.ACTION_REBOOT); filter.addAction(Intent.ACTION_FACTORY_RESET); filter.addAction(Intent.ACTION_MASTER_CLEAR); registerReceiver(screenLockReceiver, filter); @@ -139,6 +138,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus break; case Intent.ACTION_SCREEN_OFF: case Intent.ACTION_SHUTDOWN: + case Intent.ACTION_REBOOT: case Intent.ACTION_FACTORY_RESET: case Intent.ACTION_MASTER_CLEAR: sendMsg(2); @@ -169,20 +169,20 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus client = new JWebSocketClient(uri) { @Override public void onMessage(String message) { - Logutils.i("JWebSocketClientService", "收到服务器发来的消息:" + message); + Log.i("JWebSocketClientService", "收到服务器发来的消息:" + message); } @Override public void onOpen(ServerHandshake handshakedata) { super.onOpen(handshakedata); - Logutils.i("JWebSocketClientService", "websocket连接成功"); + Log.i("JWebSocketClientService", "websocket连接成功"); sendMsg(1); } @Override public void onClose(int code, String reason, boolean remote) { super.onClose(code, reason, remote); - Logutils.i("JWebSocketClientService", "websocket连接关闭"); + Log.i("JWebSocketClientService", "websocket连接关闭"); // client.close(); // initSocketClient(); mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 @@ -192,7 +192,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus @Override public void onError(Exception ex) { super.onError(ex); - Logutils.i("JWebSocketClientService", "websocket连接错误:" + ex.getMessage()); + Log.i("JWebSocketClientService", "websocket连接错误:" + ex.getMessage()); // client.close(); // initSocketClient(); mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 @@ -211,10 +211,10 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus public void run() { try { //connectBlocking多出一个等待操作,会先连接再发送,否则未连接发送会报错 - Logutils.i("JWebSocketClientService", "websocket链接中"); + Log.i("JWebSocketClientService", "websocket链接中"); client.connectBlocking(); } catch (Exception e) { - Logutils.i("JWebSocketClientService", e.getMessage()); + Log.i("JWebSocketClientService", e.getMessage()); // e.printStackTrace(); } } @@ -236,7 +236,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus jsonObject.put("online", 1); } if (null != client) { - Logutils.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString()); + Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString()); client.send(jsonObject.toJSONString()); } } @@ -247,10 +247,10 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus jsonObject.put("online", state); try { if (null != client) { - Logutils.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString()); + Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString()); client.send(jsonObject.toJSONString()); } else { - Logutils.i("JWebSocketClientService", "未连接"); + Log.i("JWebSocketClientService", "未连接"); } } catch (Exception e) { Log.e(TAG, "sendMsg: " + e.getMessage()); @@ -278,13 +278,13 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus private Runnable heartBeatRunnable = new Runnable() { @Override public void run() { - Logutils.i("JWebSocketClientService", "心跳包检测websocket连接状态"); + Log.i("JWebSocketClientService", "心跳包检测websocket连接状态"); if (client != null) { if (client.isOpen()) { - Logutils.i("JWebSocketClientService", "websocket已连接"); + Log.i("JWebSocketClientService", "websocket已连接"); sendMsg(); } else if (client.isClosed()) { - Logutils.i("JWebSocketClientService", "websocket重连中"); + Log.i("JWebSocketClientService", "websocket重连中"); reconnectWs(); } } else { @@ -306,7 +306,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus @Override public void run() { try { - Logutils.i("JWebSocketClientService", "开启重连"); + Log.i("JWebSocketClientService", "开启重连"); client.reconnectBlocking(); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java b/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java index f3ed2b3..3453124 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java @@ -2,6 +2,7 @@ package com.aoleyun.sn.utils; import android.app.ActivityManager; import android.app.PendingIntent; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -22,6 +23,7 @@ import androidx.annotation.RequiresApi; import androidx.core.content.FileProvider; import android.text.TextUtils; +import android.text.format.Formatter; import android.util.Log; import android.view.View; import android.widget.Toast; @@ -83,7 +85,7 @@ public class ApkUtils { return false; } } catch (Exception e) { - Logutils.e("*** DEBUG ***", "Unexpected error - Here is what I know: " + Log.e("*** DEBUG ***", "Unexpected error - Here is what I know: " + e.getMessage()); return false; } finally { @@ -116,6 +118,58 @@ public class ApkUtils { } } + public static boolean openPackage(Context context, String packageName) { + Context pkgContext = getPackageContext(context, packageName); + Intent intent = getAppOpenIntentByPackageName(context, packageName); + if (pkgContext != null && intent != null) { + pkgContext.startActivity(intent); + return true; + } + return false; + } + + public static Context getPackageContext(Context context, String packageName) { + Context pkgContext = null; + if (context.getPackageName().equals(packageName)) { + pkgContext = context; + } else { + // 创建第三方应用的上下文环境 + try { + pkgContext = context.createPackageContext(packageName, + Context.CONTEXT_IGNORE_SECURITY + | Context.CONTEXT_INCLUDE_CODE); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + } + return pkgContext; + } + + public static Intent getAppOpenIntentByPackageName(Context context, String packageName) { + //Activity完整名 + String mainAct = null; + //根据包名寻找 + PackageManager pkgMag = context.getPackageManager(); + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.addCategory(Intent.CATEGORY_LAUNCHER); + intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK); + + List list = pkgMag.queryIntentActivities(intent, + PackageManager.GET_ACTIVITIES); + for (int i = 0; i < list.size(); i++) { + ResolveInfo info = list.get(i); + if (info.activityInfo.packageName.equals(packageName)) { + mainAct = info.activityInfo.name; + break; + } + } + if (TextUtils.isEmpty(mainAct)) { + return null; + } + intent.setComponent(new ComponentName(packageName, mainAct)); + return intent; + } + /** * 安装一个apk文件 */ @@ -228,20 +282,19 @@ public class ApkUtils { public static void installRx(final Context context, final String packageName, final String filePath) { - Observable.create(new ObservableOnSubscribe() { @Override public void subscribe(ObservableEmitter emitter) throws Exception { File file = new File(filePath); if (TextUtils.isEmpty(filePath) || !file.exists()) { - Logutils.e("installRx", "filePath is empty"); + Log.e("installRx", "filePath is empty"); emitter.onNext(0); return; } // String[] args = { "pm", "install", "-r", filePath }; String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath}; // String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath; - Logutils.e("installRx", "argss====" + args); + Log.e("installRx", "argss====" + args); ProcessBuilder processBuilder = new ProcessBuilder(args); Process process = null; BufferedReader successResult = null; @@ -254,15 +307,15 @@ public class ApkUtils { errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream())); String s; while ((s = successResult.readLine()) != null) { - Logutils.e("mjhseng", "successResult----------" + s); + Log.e("mjhseng", "successResult----------" + s); successMsg.append(s); } while ((s = errorResult.readLine()) != null) { - Logutils.e("mjhseng", "errorResult----------" + s); + Log.e("mjhseng", "errorResult----------" + s); errorMsg.append(s); } } catch (IOException e1) { - Logutils.e("installRx", "IOException e1)----------" + e1.toString()); + Log.e("installRx", "IOException e1)----------" + e1.toString()); e1.printStackTrace(); } finally { try { @@ -273,7 +326,7 @@ public class ApkUtils { errorResult.close(); } } catch (IOException e1) { - Logutils.e("installRx", "IOException e11)---------" + e1.toString()); + Log.e("installRx", "IOException e11)---------" + e1.toString()); e1.printStackTrace(); } if (process != null) { @@ -283,7 +336,7 @@ public class ApkUtils { if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) { emitter.onNext(2); } else { - Logutils.e("installRx", "errormesg :" + errorMsg.toString()); + Log.e("installRx", "errormesg :" + errorMsg.toString()); emitter.onNext(1); } } @@ -300,10 +353,10 @@ public class ApkUtils { if (value == 2) { //安装成功 ToastUtil.show("安装成功"); - Logutils.e("installRx", "-----------安装成功-----------"); + Log.e("installRx", "-----------安装成功-----------"); } else { //安装错误 - Logutils.e("installRx", "------------安装错误-----------"); + Log.e("installRx", "------------安装错误-----------"); ToastUtil.show("安装失败"); } } @@ -325,7 +378,7 @@ public class ApkUtils { } public static void installApp(Context context, String filePath) { - Logutils.e(TAG, "installApp: " + filePath); + Log.e(TAG, "installApp: " + filePath); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { installAppatPie(context, filePath); } else { @@ -368,9 +421,9 @@ public class ApkUtils { process.destroy(); } } - Logutils.e("result", "" + errorMsg.toString()); + Log.e("result", "" + errorMsg.toString()); //如果含有“success”认为安装成功 - Logutils.e("installApp", successMsg.toString()); + Log.e("installApp", successMsg.toString()); // if (!successMsg.toString().equalsIgnoreCase("success")) { // ApkUtils.install(context, new File(apkPath)); // } @@ -451,7 +504,7 @@ public class ApkUtils { } } catch (IOException e) { e.printStackTrace(); - Logutils.e("fht", "copyApkFile" + e.getMessage()); + Log.e("fht", "copyApkFile" + e.getMessage()); } return success; } @@ -474,16 +527,16 @@ public class ApkUtils { method.invoke(PackageManagerService, installPath, null, 0x00000040, packageName, getUserId(Binder.getCallingUid()));//getUserId } catch (ClassNotFoundException e) { e.printStackTrace(); - Logutils.e("installApkInSilence", "ClassNotFoundException:" + e.getMessage()); + Log.e("installApkInSilence", "ClassNotFoundException:" + e.getMessage()); } catch (NoSuchMethodException e) { e.printStackTrace(); - Logutils.e("installApkInSilence", "NoSuchMethodException:" + e.getMessage()); + Log.e("installApkInSilence", "NoSuchMethodException:" + e.getMessage()); } catch (IllegalAccessException e) { e.printStackTrace(); - Logutils.e("installApkInSilence", "IllegalAccessException:" + e.getMessage()); + Log.e("installApkInSilence", "IllegalAccessException:" + e.getMessage()); } catch (InvocationTargetException e) { e.printStackTrace(); - Logutils.e("installApkInSilence", "InvocationTargetException:" + e.getMessage()); + Log.e("installApkInSilence", "InvocationTargetException:" + e.getMessage()); } } @@ -521,7 +574,7 @@ public class ApkUtils { Observable.create(new ObservableOnSubscribe() { @Override public void subscribe(ObservableEmitter emitter) throws Exception { - Logutils.e("UninstallAPP", "call: " + Thread.currentThread().getName()); + Log.e("UninstallAPP", "call: " + Thread.currentThread().getName()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ApkUtils.uninstall(context, pkg); } else { @@ -534,23 +587,23 @@ public class ApkUtils { .subscribe(new Observer() { @Override public void onSubscribe(Disposable d) { - Logutils.e("UninstallAPP", "onSubscribe: "); + Log.e("UninstallAPP", "onSubscribe: "); } @Override public void onNext(String s) { - Logutils.e("UninstallAPP", "onNext: " + Thread.currentThread().getName()); - Logutils.e("UninstallAPP", "onNext: " + s); + Log.e("UninstallAPP", "onNext: " + Thread.currentThread().getName()); + Log.e("UninstallAPP", "onNext: " + s); } @Override public void onError(Throwable e) { - Logutils.e("UninstallAPP", "onError: " + e.getMessage()); + Log.e("UninstallAPP", "onError: " + e.getMessage()); } @Override public void onComplete() { - Logutils.e("UninstallAPP", "onComplete: "); + Log.e("UninstallAPP", "onComplete: "); } }); @@ -642,13 +695,13 @@ public class ApkUtils { List appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的 List applicationInfos = new ArrayList<>(); for (ApplicationInfo app : appInfos) { -// Logutils.e("queryFilterAppInfo", String.valueOf(app.flags)); -// Logutils.e("queryFilterAppInfo", String.valueOf((app.flags & mask))); +// Log.e("queryFilterAppInfo", String.valueOf(app.flags)); +// Log.e("queryFilterAppInfo", String.valueOf((app.flags & mask))); if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) { //通过flag排除系统应用,会将电话、短信也排除掉 } else { applicationInfos.add(app.packageName); - Logutils.e("queryFilterAppInfo", app.packageName); + Log.e("queryFilterAppInfo", app.packageName); } } return applicationInfos; @@ -691,7 +744,7 @@ public class ApkUtils { //根据需求内置 this.add("com.easyclient.activity");//移动课堂 this.add("com.jiandan.mobilelesson");//简单课堂 - this.add("com.jiaoguanyi.store");//教官壹 + this.add(PackageNames.APPSTORE);//教官壹 //展讯 this.add("com.android.calculator2");//计算器 this.add("com.android.email");//电子邮件 @@ -704,9 +757,19 @@ public class ApkUtils { public static List desktopAPP = new ArrayList() {{ this.add("com.uiuios.jgy1"); this.add("com.uiuios.jgy2"); +// this.add("com.aoleyunos.dop1"); +// this.add("com.aoleyunos.dop2"); this.add("com.android.uiuios"); }}; + public static List aoleyunAPP = new ArrayList() {{ + this.add("com.aoleyun.appstore"); + this.add("com.aoleyun.sn"); + this.add("com.aoleyun.info"); + this.add("com.aoleyun.os"); + this.add("com.uiui.browser"); + }}; + //出厂自带的app public static List factoryapp = new ArrayList() {{ this.add("com.android.fmradio"); @@ -903,7 +966,7 @@ public class ApkUtils { try { pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0); } catch (Exception e) { - Logutils.e(TAG, "showAllAPP: " + e.getMessage()); + Log.e(TAG, "showAllAPP: " + e.getMessage()); } } } @@ -912,7 +975,7 @@ public class ApkUtils { try { pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0); } catch (Exception e) { - Logutils.e(TAG, "showAllAPP: " + e.getMessage()); + Log.e(TAG, "showAllAPP: " + e.getMessage()); } hideSystemSettingAPP(context, packageInfo.packageName); } @@ -974,7 +1037,7 @@ public class ApkUtils { PackageManager pm = context.getPackageManager(); pi = pm.getPackageInfo(pkgName, 0); } catch (PackageManager.NameNotFoundException e) { - Logutils.e("isSystemApp: NameNotFoundException:", e.getMessage()); + Log.e("isSystemApp: NameNotFoundException:", e.getMessage()); } // 是系统中已安装的应用 if (pi != null) { @@ -1007,7 +1070,7 @@ public class ApkUtils { // 通过getPackageManager()的queryIntentActivities方法遍历 List resolveinfoList = pm.queryIntentActivities(resolveIntent, 0); for (ResolveInfo resolveInfo : resolveinfoList) { - Logutils.d("", "resolveInfo:" + resolveInfo); + Log.d("", "resolveInfo:" + resolveInfo); } ResolveInfo resolveinfo = resolveinfoList.iterator().next(); if (resolveinfo != null) { @@ -1045,11 +1108,11 @@ public class ApkUtils { Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", ""); return; } - Logutils.e("addShortcut", "addShortcut: " + result); + Log.e("addShortcut", "addShortcut: " + result); String[] stringList = result.split(","); HashSet packages = new HashSet<>(Arrays.asList(stringList)); String romapps = Settings.System.getString(context.getContentResolver(), "jgy_customromapp"); - Logutils.e(TAG, "addShortcut: romapps: " + romapps); + Log.e(TAG, "addShortcut: romapps: " + romapps); HashSet appSet = new HashSet<>(); if (!TextUtils.isEmpty(romapps)) { appSet = new HashSet<>(Arrays.asList(romapps.split(","))); @@ -1079,23 +1142,23 @@ public class ApkUtils { installedListBuilder.append(","); } installedListBuilder.append(s); - Logutils.i("addShortcut", "packages: " + s); + Log.i("addShortcut", "packages: " + s); } String installedList = installedListBuilder.toString(); boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", installedList); // String old = Settings.System.getString(context.getContentResolver(), "qch_launcher_icon_app"); -// Logutils.e("addShortcut", old); - Logutils.e("addShortcut", "installedList:" + installedList); - Logutils.e("addShortcut", "putstring:" + qch_force_app); +// Log.e("addShortcut", old); + Log.e("addShortcut", "installedList:" + installedList); + Log.e("addShortcut", "putstring:" + qch_force_app); } public static void getAppInfo(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List infoList = activityManager.getRunningServices(Integer.MAX_VALUE); for (ActivityManager.RunningServiceInfo info : infoList) { -// Logutils.e("fht", "getAppInfo1: "+info.process); -// Logutils.e("fht", "getAppInfo2: "+info.service.getPackageName()); -// Logutils.e("fht", "getAppInfo3: "+info.service.getClassName()); +// Log.e("fht", "getAppInfo1: "+info.process); +// Log.e("fht", "getAppInfo2: "+info.service.getPackageName()); +// Log.e("fht", "getAppInfo3: "+info.service.getClassName()); } ArrayList appList = new ArrayList(); //用来存储获取的应用信息数据 List packages = context.getPackageManager().getInstalledPackages(0); @@ -1104,6 +1167,7 @@ public class ApkUtils { //排除桌面app和出厂自带app if (desktopAPP.contains(packageName) || factoryapp.contains(packageName) +// || aoleyunAPP.contains(packageName) ) { continue; } @@ -1134,7 +1198,7 @@ public class ApkUtils { uploadAppInfo.setApp_name(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString()); uploadAppInfo.setPackage_name(packageInfo.packageName); - Logutils.e("getAppInfo", "getAppInfo:" + packageInfo.packageName); + Log.e("getAppInfo", "getAppInfo:" + packageInfo.packageName); // uploadAppInfo.setId(i); // String firstInstallTime = Utils.transferLongToDate(packageInfo.firstInstallTime); // String lastUpdateTime = Utils.transferLongToDate(packageInfo.lastUpdateTime); @@ -1143,18 +1207,20 @@ public class ApkUtils { uploadAppInfo.setVersionCode(String.valueOf(packageInfo.versionCode)); uploadAppInfo.setState(0); uploadAppInfo.setVersionName(packageInfo.versionName); - + String appInstallDir = packageInfo.applicationInfo.publicSourceDir; + int size = Integer.valueOf((int) new File(appInstallDir).length()); + uploadAppInfo.setApp_size(Formatter.formatFileSize(context, size)); for (ActivityManager.RunningServiceInfo info : infoList) { if (info.process.contains(packageInfo.packageName)) { uploadAppInfo.setState(1); - Logutils.e("getAppInfo", "getAppInfo running: " + packageInfo.packageName); + Log.e("getAppInfo", "getAppInfo running: " + packageInfo.packageName); } } appList.add(uploadAppInfo); } Gson gson = new Gson(); String jsonString = gson.toJson(appList); - Logutils.e(TAG, "getAppInfo: " + jsonString); + Log.e(TAG, "getAppInfo: " + jsonString); NetInterfaceManager.getInstance() .getUploadAppInfoApi() @@ -1171,7 +1237,7 @@ public class ApkUtils { @Override public void onNext(ResponseBody responseBody) { try { - Logutils.e("getAppInfo", "上传的结果" + responseBody.string()); + Log.e("getAppInfo", "上传的结果" + responseBody.string()); } catch (IOException e) { e.printStackTrace(); } @@ -1179,12 +1245,12 @@ public class ApkUtils { @Override public void onError(Throwable e) { - Logutils.e("getAppInfo", "UploadAppInfoApi onError: " + e.getMessage()); + Log.e("getAppInfo", "UploadAppInfoApi onError: " + e.getMessage()); } @Override public void onComplete() { - Logutils.e("getAppInfo", "onComplete: "); + Log.e("getAppInfo", "onComplete: "); } }); } @@ -1202,7 +1268,7 @@ public class ApkUtils { String extendField = Aria.download(this).load(id).getExtendField(); JSONObject jsonObject = JSON.parseObject(extendField); if (packageName.equals(jsonObject.getString("app_package"))) { - Logutils.e("RemoveTask", "subscribe: " + "删除文件:" + entity.getFilePath()); + Log.e("RemoveTask", "subscribe: " + "删除文件:" + entity.getFilePath()); Aria.download(this).load(id).cancel(true); } } @@ -1213,22 +1279,22 @@ public class ApkUtils { .subscribe(new Observer() { @Override public void onSubscribe(Disposable d) { - Logutils.e("RemoveTask", "onSubscribe: "); + Log.e("RemoveTask", "onSubscribe: "); } @Override public void onNext(String s) { - Logutils.e("RemoveTask", "onNext: "); + Log.e("RemoveTask", "onNext: "); } @Override public void onError(Throwable e) { - Logutils.e("RemoveTask", "onError: " + e.getMessage()); + Log.e("RemoveTask", "onError: " + e.getMessage()); } @Override public void onComplete() { - Logutils.e("RemoveTask", "onComplete: "); + Log.e("RemoveTask", "onComplete: "); } }); diff --git a/app/src/main/java/com/aoleyun/sn/utils/CacheUtils.java b/app/src/main/java/com/aoleyun/sn/utils/CacheUtils.java index ee38a76..a3cae9e 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/CacheUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/CacheUtils.java @@ -9,6 +9,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageStats; import android.os.RemoteException; import android.os.ServiceManager; +import android.util.Log; import java.lang.reflect.Method; @@ -44,13 +45,13 @@ public class CacheUtils { throw new Exception("Timed out waiting for PackageStatsObserver.onGetStatsCompleted"); } } - Logutils.d(TAG, "toString " + observer.stats.toString()); + Log.d(TAG, "toString " + observer.stats.toString()); return observer.stats.dataSize + observer.stats.cacheSize; } catch (RemoteException e) { - Logutils.w(TAG, "Failed to get handle for PackageManger Exception: " + e); + Log.w(TAG, "Failed to get handle for PackageManger Exception: " + e); return -1; } catch (InterruptedException e) { - Logutils.w(TAG, "InterruptedException :" + e); + Log.w(TAG, "InterruptedException :" + e); return -1; } } @@ -80,13 +81,13 @@ public class CacheUtils { throw new Exception("timed out waiting for PackageDataObserver.onRemoveCompleted"); } } - Logutils.d(TAG, "cleanApplicationCache " + observer.retValue); + Log.d(TAG, "cleanApplicationCache " + observer.retValue); return observer.retValue; } catch (RemoteException e) { - Logutils.w(TAG, "Failed to get handle for PackageManger Exception: " + e); + Log.w(TAG, "Failed to get handle for PackageManger Exception: " + e); return false; } catch (InterruptedException e) { - Logutils.w(TAG, "InterruptedException :" + e); + Log.w(TAG, "InterruptedException :" + e); return false; } } diff --git a/app/src/main/java/com/aoleyun/sn/utils/CmdUtil.java b/app/src/main/java/com/aoleyun/sn/utils/CmdUtil.java index 0d94a2b..dedf52e 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/CmdUtil.java +++ b/app/src/main/java/com/aoleyun/sn/utils/CmdUtil.java @@ -1,6 +1,7 @@ package com.aoleyun.sn.utils; import android.text.TextUtils; +import android.util.Log; import java.io.BufferedReader; import java.io.DataOutputStream; @@ -22,11 +23,11 @@ public class CmdUtil { * @return 结果 */ public static Result execute(String command) { - Logutils.i(TAG, "execute() command = " + command); + Log.i(TAG, "execute() command = " + command); Result result = new Result(); if (TextUtils.isEmpty(command)) { - Logutils.w(TAG, "WARNING: command should not be null or empty"); + Log.w(TAG, "WARNING: command should not be null or empty"); return result; } @@ -44,13 +45,13 @@ public class CmdUtil { result.code = process.waitFor(); result.success = readBuffer(new BufferedReader(new InputStreamReader(process.getInputStream()))); result.error = readBuffer(new BufferedReader(new InputStreamReader(process.getErrorStream()))); - Logutils.i(TAG, "result = " + result); + Log.i(TAG, "result = " + result); } catch (IOException ioe) { ioe.printStackTrace(); - Logutils.e(TAG, ioe.getMessage()); + Log.e(TAG, ioe.getMessage()); } catch (InterruptedException ie) { ie.printStackTrace(); - Logutils.e(TAG, ie.getMessage()); + Log.e(TAG, ie.getMessage()); } finally { try { if (null != dos) { @@ -58,7 +59,7 @@ public class CmdUtil { } } catch (IOException ioe) { ioe.printStackTrace(); - Logutils.e(TAG, ioe.getMessage()); + Log.e(TAG, ioe.getMessage()); } if (null != process) { process.destroy(); diff --git a/app/src/main/java/com/aoleyun/sn/utils/ForegroundAppUtil.java b/app/src/main/java/com/aoleyun/sn/utils/ForegroundAppUtil.java index d72156c..0dc90bf 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/ForegroundAppUtil.java +++ b/app/src/main/java/com/aoleyun/sn/utils/ForegroundAppUtil.java @@ -34,14 +34,14 @@ public class ForegroundAppUtil { return; } String packages = ForegroundAppUtil.getForegroundPackageName(context); - Logutils.e("openTopApp", "old:" + topAppName); + Log.e("openTopApp", "old:" + topAppName); if (!TextUtils.isEmpty(topAppName)) { if (!packages.equals(topAppName)) { - ApkUtils.openApp(context, topAppName); + ApkUtils.openPackage(context, topAppName); } } else { - Logutils.e("openTopApp", ":" + packages); + Log.e("openTopApp", ":" + packages); } } @@ -62,7 +62,7 @@ public class ForegroundAppUtil { boolean always_top_classname = Settings.System.putString(context.getContentResolver(), "always_top_classname", ClassName); Log.e(TAG, "setTopAppClass: always_top_packagename = " + always_top_packagename); Log.e(TAG, "setTopAppClass: always_top_classname = " + always_top_classname); - ApkUtils.openApp(context, pkg); + ApkUtils.openPackage(context, pkg); } diff --git a/app/src/main/java/com/aoleyun/sn/utils/InstallResultReceiver.java b/app/src/main/java/com/aoleyun/sn/utils/InstallResultReceiver.java index 64943b1..c73c1f9 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/InstallResultReceiver.java +++ b/app/src/main/java/com/aoleyun/sn/utils/InstallResultReceiver.java @@ -5,6 +5,8 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageInstaller; import android.os.Build; +import android.util.Log; + import androidx.annotation.RequiresApi; public class InstallResultReceiver extends BroadcastReceiver { @@ -25,7 +27,7 @@ public class InstallResultReceiver extends BroadcastReceiver { // success String PACKAGE_NAME = intent.getStringExtra("android.content.pm.extra.PACKAGE_NAME"); - Logutils.e(TAG, "APP Install Success!"); + Log.e(TAG, "APP Install Success!"); } else { String msg = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE); } diff --git a/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java b/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java index 33b662a..3ab02cd 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/JGYUtils.java @@ -18,14 +18,18 @@ import android.graphics.Bitmap; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; +import android.net.wifi.WifiManager; import android.os.BatteryManager; import android.os.Build; +import android.os.Environment; import android.os.PowerManager; import android.os.RemoteException; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; +import androidx.core.content.ContextCompat; + import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.aoleyun.sn.comm.PackageNames; @@ -113,7 +117,7 @@ public class JGYUtils { public static void init(Context context) { if (sInstance == null) { - Logutils.e(TAG, "init: "); + Log.e(TAG, "init: "); sInstance = new JGYUtils(context); } } @@ -133,7 +137,7 @@ public class JGYUtils { } public static boolean isOfficialVersion(Context context) { - Logutils.e(TAG, "isOfficialVersion: " + ProcessUtil.getCurrentProcessName(context)); + Log.e(TAG, "isOfficialVersion: " + ProcessUtil.getCurrentProcessName(context)); String channelValue = JGYUtils.getInstance().getStringMetaData(); return "official".equals(channelValue); } @@ -155,12 +159,16 @@ public class JGYUtils { public void resetDevice() { boolean isReset = MySQLData.GetBooleanData(mContext, CommonDatas.IS_RESET); int batteryLevel = getBatteryLevel(); - Logutils.e(TAG, "batteryLevel:" + batteryLevel + " isReset" + isReset); + Log.e(TAG, "batteryLevel:" + batteryLevel + " isReset" + isReset); if (isReset && batteryLevel >= CommonDatas.MIN_POWER) { Utils.doMasterClear(mContext); } } + public String getDownLoadPath() { + String path = ContextCompat.getExternalFilesDirs(mContext, Environment.DIRECTORY_DOWNLOADS)[0].getAbsolutePath(); + return path + File.separator; + } private int getBatteryLevel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -187,7 +195,7 @@ public class JGYUtils { wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, mWakeLockName); if (null != wakeLock) { - Logutils.e("fht", "acquireWakeLock!"); + Log.e("fht", "acquireWakeLock!"); wakeLock.acquire(); } } @@ -198,7 +206,7 @@ public class JGYUtils { */ private synchronized void releaseWakeLock() { if (null != wakeLock) { - Logutils.e("fht", "releaseWakeLock!"); + Log.e("fht", "releaseWakeLock!"); wakeLock.release(); wakeLock = null; } @@ -211,8 +219,8 @@ public class JGYUtils { */ @SuppressLint("NewApi") synchronized public void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean, List appListInfos) { - Logutils.e(TAG, "setNetAndlaunch: " + "应用联网管控: " + netAndLaunchBean.getData().toString()); - Logutils.e(TAG, "setNetAndlaunch: "); + Log.e(TAG, "setNetAndlaunch: " + "应用联网管控: " + netAndLaunchBean.getData().toString()); + Log.e(TAG, "setNetAndlaunch: "); HashSet autoLaunchApp = new HashSet<>();//开机自启app HashSet allowNetApp = new HashSet<>();//允许联网 HashSet disallowNetApp = new HashSet<>();//禁止联网 @@ -244,11 +252,11 @@ public class JGYUtils { if (disallowSlide.size() != 0) { String slide_not = String.join(",", disallowSlide); boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", slide_not); - Logutils.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not); + Log.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not); } else { String slide_ok = String.join(",", allowSlide); boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid"); - Logutils.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok); + Log.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok); } String[] upgrade_ok = new String[allowUpgrade.size()]; @@ -258,26 +266,26 @@ public class JGYUtils { disallowUpgrade.toArray(upgrade_not); Utils.writeDisableUpdateList(mContext, upgrade_not, upgrade_ok); String qch_app_power_on = String.join(",", autoLaunchApp); - Logutils.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on); + Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on); 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"); + Log.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); + Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on); } // if (BuildConfig.DEBUG) { // TODO: 2021/7/2 测试写入为空是否断网 // boolean w = Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", ""); -// Logutils.e(TAG, "setNetAndlaunch: 测试写入: " + w); +// Log.e(TAG, "setNetAndlaunch: 测试写入: " + w); // } setAppNetwork(mContext, disallowNetApp); BaseApplication.getInstance().setFinished(true); } private void checkPackageAndVersion(HashSet disallowUpgrade, List appListInfos) { - Logutils.e(TAG, "checkPackageAndVersion: " + disallowUpgrade); + Log.e(TAG, "checkPackageAndVersion: " + disallowUpgrade); PackageManager pm = mContext.getPackageManager(); HashMap listInfoHashMap = new HashMap<>(); for (AppListInfo appListInfo : appListInfos) { @@ -296,8 +304,8 @@ public class JGYUtils { appVersionCode = packageInfo.versionCode; } if (appVersionCode > info.getApp_version_code() && info.getApp_version_code() != 0) { - Logutils.e(TAG, "checkPackageAndVersion: appVersionCode: " + appVersionCode + " getApp_version_code: " + info.getApp_version_code()); - Logutils.e(TAG, "checkPackageAndVersion: " + pkg + " 卸载"); + Log.e(TAG, "checkPackageAndVersion: appVersionCode: " + appVersionCode + " getApp_version_code: " + info.getApp_version_code()); + Log.e(TAG, "checkPackageAndVersion: " + pkg + " 卸载"); ApkUtils.UninstallAPP(mContext, pkg); JSONObject packageObj = new JSONObject(); packageObj.put("app_name", info.getApp_name()); @@ -306,7 +314,7 @@ public class JGYUtils { packageObj.put("MD5", info.getApp_md5()); Utils.ariaDownload(mContext, info.getApp_url(), packageObj); } else { - Logutils.e(TAG, "checkPackageAndVersion: " + pkg + " 版本正常"); + Log.e(TAG, "checkPackageAndVersion: " + pkg + " 版本正常"); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); @@ -320,8 +328,8 @@ public class JGYUtils { @SuppressLint("NewApi") synchronized public void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean) { - Logutils.e(TAG, "setNetAndlaunch: " + "应用联网管控: " + netAndLaunchBean.getData().toString()); - Logutils.e(TAG, "setNetAndlaunch: "); + Log.e(TAG, "setNetAndlaunch: " + "应用联网管控: " + netAndLaunchBean.getData().toString()); + Log.e(TAG, "setNetAndlaunch: "); HashSet autoLaunchApp = new HashSet<>();//开机自启app HashSet allowNetApp = new HashSet<>();//允许联网 HashSet disallowNetApp = new HashSet<>();//禁止联网 @@ -353,11 +361,11 @@ public class JGYUtils { if (disallowSlide.size() != 0) { String slide_not = String.join(",", disallowSlide); boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", slide_not); - Logutils.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not); + Log.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not); } else { String slide_ok = String.join(",", allowSlide); boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid"); - Logutils.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok); + Log.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok); } String[] upgrade_ok = new String[allowUpgrade.size()]; @@ -366,19 +374,19 @@ public class JGYUtils { disallowUpgrade.toArray(upgrade_not); Utils.writeDisableUpdateList(mContext, upgrade_not, upgrade_ok); String qch_app_power_on = String.join(",", autoLaunchApp); - Logutils.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on); + Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on); 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"); + Log.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); + Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on); } // if (BuildConfig.DEBUG) { // TODO: 2021/7/2 测试写入为空是否断网 // boolean w = Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", ""); -// Logutils.e(TAG, "setNetAndlaunch: 测试写入: " + w); +// Log.e(TAG, "setNetAndlaunch: 测试写入: " + w); // } setAppNetwork(mContext, disallowNetApp); BaseApplication.getInstance().setFinished(true); @@ -386,16 +394,16 @@ public class JGYUtils { @SuppressLint("NewApi") synchronized public static void setAppNetwork(Context context, HashSet blackList) { - Logutils.e(TAG, "setAppNetwork: " + "设置应用联网管控" + blackList); + Log.e(TAG, "setAppNetwork: " + "设置应用联网管控" + blackList); String dis = Settings.System.getString(context.getContentResolver(), JGYActions.ACTION_HR_RECEIVER_JGY_DIS); String not = Settings.System.getString(context.getContentResolver(), JGYActions.ACTION_HR_RECEIVER_JGY); //清除旧数据 if (!TextUtils.isEmpty(dis)) { - Logutils.e(TAG, "setAppNetwork: dis = " + dis); + Log.e(TAG, "setAppNetwork: dis = " + dis); Settings.System.putString(context.getContentResolver(), JGYActions.ACTION_HR_RECEIVER_JGY_DIS, "Invalid"); } if (!TextUtils.isEmpty(not)) { - Logutils.e(TAG, "setAppNetwork: not = " + not); + Log.e(TAG, "setAppNetwork: not = " + not); Settings.System.putString(context.getContentResolver(), JGYActions.ACTION_HR_RECEIVER_JGY, "Invalid"); } @@ -403,14 +411,15 @@ public class JGYUtils { HashSet oldBlackListSet = new HashSet<>(Arrays.asList(oldBlackList.split(","))); oldBlackListSet.removeIf(s -> TextUtils.isEmpty(s.trim())); //之前禁止上网得列表 - Logutils.e(TAG, "setAppNetwork: oldBlackListSet: " + oldBlackListSet); + Log.e(TAG, "setAppNetwork: oldBlackListSet: " + oldBlackListSet); if (oldBlackListSet.size() == 0) { - Logutils.e(TAG, "setAppNetwork: blackList: " + blackList); - for (String pkg : blackList) { + Log.e(TAG, "setAppNetwork: blackList: " + blackList); + for (String pkg : new HashSet<>(blackList)) { if (TextUtils.isEmpty(pkg)) continue; //发送没有安装的 if (!ApkUtils.isAvailable(context, pkg)) { Log.e(TAG, "setAppNetwork: skip: " + pkg); + blackList.remove(pkg); continue; } else { Log.e(TAG, "setAppNetwork: " + pkg + " 已安装"); @@ -434,8 +443,8 @@ public class JGYUtils { } } - Logutils.e(TAG, "setAppNetwork: removedNet: " + removedNet); - Logutils.e(TAG, "setAppNetwork: addedNet: " + addedNet); + Log.e(TAG, "setAppNetwork: removedNet: " + removedNet); + Log.e(TAG, "setAppNetwork: addedNet: " + addedNet); for (String pkg : removedNet) { if (TextUtils.isEmpty(pkg)) continue; Intent netControlNotIntent = new Intent(JGYActions.ACTION_HR_RECEIVER_JGY); @@ -447,6 +456,7 @@ public class JGYUtils { if (TextUtils.isEmpty(pkg)) continue; if (!ApkUtils.isAvailable(context, pkg)) { Log.e(TAG, "setAppNetwork: skip: " + pkg); + blackList.remove(pkg); continue; } else { Log.e(TAG, "setAppNetwork: " + pkg + " 已安装"); @@ -461,7 +471,7 @@ public class JGYUtils { String net_not = String.join(",", blackList); SPUtils.put(context, JGYActions.ACTION_HR_RECEIVER_JGY_DIS, net_not); //Settings.System.putString(mContext.getContentResolver(), JGYActions.ACTION_HrReceiver_JGY_DIS, net_not); - Logutils.e("fht", "not::" + net_not); + Log.e("fht", "not::" + net_not); //Intent netControlIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY_DIS); //netControlIntent.putExtra("package_name", net_not); @@ -476,7 +486,7 @@ public class JGYUtils { synchronized public void onBootSendNetwork() { String oldBlackListString = (String) SPUtils.get(mContext, JGYActions.ACTION_HR_RECEIVER_JGY_DIS, ""); HashSet oldBlackListSet = new HashSet<>(Arrays.asList(oldBlackListString.split(","))); - Logutils.e(TAG, "setAppNetwork: oldBlackListSet: " + oldBlackListSet); + Log.e(TAG, "setAppNetwork: oldBlackListSet: " + oldBlackListSet); oldBlackListSet.removeIf(new Predicate() { @Override public boolean test(String s) { @@ -525,14 +535,14 @@ public class JGYUtils { String olddeselectViewArray = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid_id"); - Logutils.e("writeDeselectIDtoSystem", "olddeselectViewArray: " + olddeselectViewArray); + Log.e("writeDeselectIDtoSystem", "olddeselectViewArray: " + olddeselectViewArray); Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid_id", packageStringBuilder.toString()); Settings.System.putString(mContext.getContentResolver(), "DeselectViewArray", idStringBuilder.toString()); - Logutils.e("writeDeselectIDtoSystem", "qch_app_forbid_id: " + packageStringBuilder.toString()); - Logutils.e("writeDeselectIDtoSystem", "deselectViewArray: " + idStringBuilder.toString()); + Log.e("writeDeselectIDtoSystem", "qch_app_forbid_id: " + packageStringBuilder.toString()); + Log.e("writeDeselectIDtoSystem", "deselectViewArray: " + idStringBuilder.toString()); } else { - Logutils.e("writeDeselectIDtoSystem", "writeDeselectIDtoSystem is null:"); + Log.e("writeDeselectIDtoSystem", "writeDeselectIDtoSystem is null:"); Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid_id", ""); Settings.System.putString(mContext.getContentResolver(), "DeselectViewArray", ""); } @@ -561,7 +571,7 @@ public class JGYUtils { if (packageList.length() > 0) { //app内所有的网页禁止 - Logutils.e("setAppinsideWeb ", "packageList:" + packageList.toString()); + Log.e("setAppinsideWeb ", "packageList:" + packageList.toString()); Intent qch_app_website = new Intent("qch_app_website") .setPackage("com.android.settings"); qch_app_website.putExtra("package_name", packageList.toString()); @@ -572,7 +582,7 @@ public class JGYUtils { if (strings.length() > 0) { //app内单个网页地址禁止打开 - Logutils.e("setAppinsideWeb ", "strings:" + strings.toString()); + Log.e("setAppinsideWeb ", "strings:" + strings.toString()); Intent intent = new Intent("qch_app_inside_website") .setPackage("com.android.settings"); intent.putExtra("websitelist", strings.toString()); @@ -586,7 +596,7 @@ public class JGYUtils { sendAllweb(mContext); sendwebUrl(mContext); //ToastUtil.show(msg); - Logutils.e("setAppinsideWeb", "setAppinsideWeb: " + response.msg); + Log.e("setAppinsideWeb", "setAppinsideWeb: " + response.msg); } } @@ -594,7 +604,7 @@ public class JGYUtils { * @param response 黑白名单都可以管控 */ synchronized public void setNewAppinsideWeb(BaseResponse response) { - Logutils.e(TAG, "setNewAppinsideWeb: " + "应用内部联网管控: " + response); + Log.e(TAG, "setNewAppinsideWeb: " + "应用内部联网管控: " + response); if (response.code == 200) { String jsonString = JSONArray.toJSONString(response.data); List appgrounds = JSONObject.parseArray(jsonString, TTAppground.class); @@ -608,8 +618,8 @@ public class JGYUtils { blackApp.add(appground); } } - Logutils.e(TAG, "setAppinsideWeb: whiteApp: " + whiteApp); - Logutils.e(TAG, "setAppinsideWeb: blackApp: " + blackApp); + Log.e(TAG, "setAppinsideWeb: whiteApp: " + whiteApp); + Log.e(TAG, "setAppinsideWeb: blackApp: " + blackApp); setWhiteApp(whiteApp); setBlackApp(blackApp); } @@ -620,7 +630,7 @@ public class JGYUtils { sendAllweb(mContext); sendwebUrl(mContext); //ToastUtil.show(msg); - Logutils.e("setAppinsideWeb", "setAppinsideWeb: " + response.msg); + Log.e("setAppinsideWeb", "setAppinsideWeb: " + response.msg); } } @@ -667,9 +677,9 @@ public class JGYUtils { addAppgrounds.add(entry.getValue()); } - Logutils.e(TAG, "comparedAppground: addAppgrounds.size():" + addAppgrounds.size()); - Logutils.e(TAG, "comparedAppground: deleteAppgrounds.size():" + deleteAppgrounds.size()); - Logutils.e(TAG, "comparedAppground: changedAppgrounds.size():" + changedAppgrounds.size()); + Log.e(TAG, "comparedAppground: addAppgrounds.size():" + addAppgrounds.size()); + Log.e(TAG, "comparedAppground: deleteAppgrounds.size():" + deleteAppgrounds.size()); + Log.e(TAG, "comparedAppground: changedAppgrounds.size():" + changedAppgrounds.size()); addAppground(addAppgrounds); deleteAppground(deleteAppgrounds); @@ -683,7 +693,7 @@ public class JGYUtils { //删除空的,旧版本使用这个清除 deleteWhitelistUrl(appground.getPackages(), "Invalid"); addToWhitelist(appground.getPackages(), appground.getAddress()); - Logutils.e("comparedAppground", "addAppground: " + appground.getAddress()); + Log.e("comparedAppground", "addAppground: " + appground.getAddress()); } } @@ -691,7 +701,7 @@ public class JGYUtils { for (TTAppground appground : appgroundList) { deleteWhitelistUrl(appground.getPackages(), appground.getAddress()); deleteOtherAppWhitelist(appground.getPackages()); - Logutils.e("comparedAppground", "deleteAppground: " + appground.getAddress()); + Log.e("comparedAppground", "deleteAppground: " + appground.getAddress()); } } @@ -705,12 +715,12 @@ public class JGYUtils { oldURL.remove(url); } else { addToWhitelist(appground.getPackages(), url); - Logutils.e("comparedAppground", "addToWhitelist: " + url); + Log.e("comparedAppground", "addToWhitelist: " + url); } } for (String url : oldURL) { deleteWhitelistUrl(appground.getPackages(), url); - Logutils.e("comparedAppground", "deleteWhitelistUrl: " + url); + Log.e("comparedAppground", "deleteWhitelistUrl: " + url); } } } @@ -718,7 +728,7 @@ public class JGYUtils { private List getOldWhitelist() { String whiteListString = (String) SPUtils.get(mContext, JGY_APPINSIDE_WHITELIST, ""); - Logutils.e(TAG, "getOldWhitelist: " + whiteListString); + Log.e(TAG, "getOldWhitelist: " + whiteListString); Gson gson = new Gson(); Type listType = new TypeToken>() { }.getType(); @@ -753,10 +763,10 @@ public class JGYUtils { public void onBootSetAppInsideWeb() { List old = getOldWhitelist(); - Logutils.e(TAG, "onBootSetAppInsideWeb: " + old); + Log.e(TAG, "onBootSetAppInsideWeb: " + old); for (TTAppground appground : old) { if (TextUtils.isEmpty(appground.getAddress())) { - Logutils.e(TAG, "setWhiteApp: " + "skip: " + appground.getAddress()); + Log.e(TAG, "setWhiteApp: " + "skip: " + appground.getAddress()); } else { addPackage(appground.getPackages()); //删除空的,旧版本使用这个清除 @@ -771,7 +781,7 @@ public class JGYUtils { * @param pkg 开启app白名单 */ synchronized private void addPackage(String pkg) { - Logutils.e(TAG, "addPackage: " + pkg); + Log.e(TAG, "addPackage: " + pkg); Intent intent26 = new Intent(); intent26.setAction("qch_app_inside_website"); intent26.putExtra("WEBURLforbidapp", pkg); @@ -785,7 +795,7 @@ public class JGYUtils { */ synchronized private void addToWhitelist(String pkg, String urls) { if (TextUtils.isEmpty(urls)) { - Logutils.e(TAG, "addToWhitelist: " + "urls is NULL"); + Log.e(TAG, "addToWhitelist: " + "urls is NULL"); return; } HashSet urlSet = new HashSet<>(Arrays.asList(urls.trim().split(","))); @@ -794,7 +804,7 @@ public class JGYUtils { continue; } deleteOtherAppWhitelist(pkg); - Logutils.e(TAG, "addToWhitelist: pkg:" + pkg + " url: " + url); + Log.e(TAG, "addToWhitelist: pkg:" + pkg + " url: " + url); Intent intent25 = new Intent(); intent25.setAction("qch_app_setAddAppWhitWebUid"); intent25.putExtra("AddAppWhitWebUidPackage", pkg); @@ -810,7 +820,7 @@ public class JGYUtils { */ synchronized private void deleteWhitelistUrl(String pkg, String urls) { if (TextUtils.isEmpty(urls)) { - Logutils.e(TAG, "addToWhitelist: " + "urls is NULL"); + Log.e(TAG, "addToWhitelist: " + "urls is NULL"); return; } HashSet urlSet = new HashSet<>(Arrays.asList(urls.trim().split(","))); @@ -818,7 +828,7 @@ public class JGYUtils { if (TextUtils.isEmpty(url)) { continue; } - Logutils.e(TAG, "deleteWhitelistUrl: qch_app_setDelAppWhitWebUid" + "pkg: " + pkg + " url: " + url); + Log.e(TAG, "deleteWhitelistUrl: qch_app_setDelAppWhitWebUid" + "pkg: " + pkg + " url: " + url); Intent intent25 = new Intent(); intent25.setAction("qch_app_setDelAppWhitWebUid"); intent25.putExtra("DelAppWhitWebUidPackage", pkg); @@ -832,7 +842,7 @@ public class JGYUtils { * @param pkg 开启和关闭白名单管控都需要发送 */ synchronized private void deleteOtherAppWhitelist(String pkg) { - Logutils.e(TAG, "disableAppWhitelist: " + pkg); + Log.e(TAG, "disableAppWhitelist: " + pkg); Intent intent24 = new Intent(); intent24.setAction("qch_app_setDelAppWhitUid"); intent24.putExtra("DelAppWhitUidPackage", pkg); @@ -844,7 +854,7 @@ public class JGYUtils { * @param appgrounds 设置黑名单管控 */ synchronized private void setBlackApp(List appgrounds) { - Logutils.e(TAG, "setBlackApp: " + appgrounds); + Log.e(TAG, "setBlackApp: " + appgrounds); StringBuilder blackList = new StringBuilder(); StringBuilder packageList = new StringBuilder();//单条管控名单 for (TTAppground appground : appgrounds) { @@ -863,7 +873,7 @@ public class JGYUtils { //old if (packageList.length() > 0) { //app内所有的网页禁止 - Logutils.e("setAppinsideWeb ", "packageList:" + packageList.toString()); + Log.e("setAppinsideWeb ", "packageList:" + packageList.toString()); Intent qch_app_website = new Intent("qch_app_website") .setPackage("com.android.settings"); qch_app_website.putExtra("package_name", packageList.toString()); @@ -873,7 +883,7 @@ public class JGYUtils { } if (blackList.length() > 0) { //app内单个网页地址禁止打开 - Logutils.e("setAppinsideWeb ", "blackList:" + blackList.toString()); + Log.e("setAppinsideWeb ", "blackList:" + blackList.toString()); Intent intent = new Intent("qch_app_inside_website") .setPackage("com.android.settings"); intent.putExtra("websitelist", blackList.toString()); @@ -884,7 +894,7 @@ public class JGYUtils { } synchronized private static void sendAllweb(Context context) { - Logutils.e(TAG, "sendAllweb: "); + Log.e(TAG, "sendAllweb: "); Intent intent = new Intent("qch_app_website") .setPackage("com.android.settings"); intent.putExtra("package_name", "Invalid"); @@ -892,7 +902,7 @@ public class JGYUtils { } synchronized private static void sendwebUrl(Context context) { - Logutils.e(TAG, "sendwebUrl: "); + Log.e(TAG, "sendwebUrl: "); Intent intent = new Intent("qch_app_inside_website") .setPackage("com.android.settings"); intent.putExtra("websitelist", "Invalid"); @@ -902,7 +912,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"); + Log.e(TAG, "SettingSysData: " + "data is empty"); SysSettingUtils.setDisableSetting(mContext); } else { SysSettingUtils.setSystemSetting(mContext, data); @@ -921,15 +931,20 @@ public class JGYUtils { this.add("com.uiuios.jgy1"); this.add("com.uiuios.jgy2"); this.add("com.tt.ttutils"); + this.add("com.uiui.browser"); this.add("com.android.uiuios"); + this.add("com.aoleyun.os"); + this.add("com.aoleyunos.dop1"); + this.add("com.aoleyunos.dop2"); + this.add("com.aoleyun.info"); }}; HashSet pkgSet = new HashSet<>(Arrays.asList(packageList.split(","))); pkgSet.addAll(packages); pkgSet.removeIf(TextUtils::isEmpty); String qch_app_forbid = String.join(",", pkgSet); - Logutils.e(TAG, "writeAppPackageList: " + qch_app_forbid); + Log.e(TAG, "writeAppPackageList: " + qch_app_forbid); boolean b = Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid", qch_app_forbid); - Logutils.e("writeAppPackageList: ", "qch_app_forbid is :" + b + " " + Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid")); + Log.e("writeAppPackageList: ", "qch_app_forbid is :" + b + " " + Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid")); } public void forceDownload(List data) { @@ -951,7 +966,7 @@ public class JGYUtils { jsonObject.put("app_id", app_id); jsonObject.put("MD5", app_md5); long app_version_code = forceDownloadData.getApp_version_code(); - Logutils.e("fht ", "packageName=" + app_package + ",URL= " + app_url + ",app_version_code=" + app_version_code); + Log.e("fht ", "packageName=" + app_package + ",URL= " + app_url + ",app_version_code=" + app_version_code); if (BuildConfig.APPLICATION_ID.equals(data.get(i).getApp_package())) { continue;//为自身的跳过下载 } @@ -964,7 +979,7 @@ public class JGYUtils { packageInfo = pm.getPackageInfo(app_package, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); - Logutils.e("fht", "forceDownload=" + e.getMessage()); + Log.e("fht", "forceDownload=" + e.getMessage()); } if (packageInfo != null) { long appVersionCode; @@ -974,11 +989,11 @@ public class JGYUtils { appVersionCode = packageInfo.versionCode; } if (app_version_code > appVersionCode) { - Logutils.e("fht ", "download URL " + app_url); + Log.e("fht ", "download URL " + app_url); Utils.ariaDownload(mContext, app_url, jsonObject); } } else { - Logutils.e("fht ", "download URL " + app_url); + Log.e("fht ", "download URL " + app_url); Utils.ariaDownload(mContext, app_url, jsonObject); } } @@ -1001,7 +1016,7 @@ public class JGYUtils { Utils.ariaDownload(mContext, forceDownloadData.getApp_url(), jsonObject); } } else { -// Logutils.e("fht", "未上传应用"); +// Log.e("fht", "未上传应用"); } } } @@ -1032,7 +1047,7 @@ public class JGYUtils { if (packageInfo == null || packageInfo.versionCode < versionCode) { Utils.ariaDownload(mContext, url, object); } else { - Logutils.e("installAPK", "已是最新版本"); + Log.e("installAPK", "已是最新版本"); } } @@ -1059,7 +1074,7 @@ public class JGYUtils { if (packageInfo == null || packageInfo.versionCode < versionCode) { Utils.ariaDownload(mContext, url, object); } else { - Logutils.e("installTestAPK", "TestAPK: " + "无更新"); + Log.e("installTestAPK", "TestAPK: " + "无更新"); } } @@ -1092,7 +1107,7 @@ public class JGYUtils { if (packageInfo == null || packageInfo.versionCode < versionCode) { Utils.ariaDownload(mContext, url, object); } else { - Logutils.e("installTestAPK", "TestAPK: " + packageName + "\t无更新"); + Log.e("installTestAPK", "TestAPK: " + packageName + "\t无更新"); } } } @@ -1114,7 +1129,7 @@ public class JGYUtils { info = packageManager.getPackageInfo(app_package, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); - Logutils.e("fht", "installDesktop: " + e.getMessage()); + Log.e("fht", "installDesktop: " + e.getMessage()); } if (null != info) { long versionCode; @@ -1143,26 +1158,33 @@ public class JGYUtils { if (locked == 1) { return; } - Logutils.e(TAG, "deleteOtherApp: " + "start"); + Log.e(TAG, "deleteOtherApp: " + "start"); + String[] result_white = new String[]{}; + String[] result_forbid = new String[]{}; //获取后台应用白名单 String only_jgy_shortcut_list = Settings.System.getString(mContext.getContentResolver(), JGYActions.ACTION_JGY_SHORTCUTLIST); + if (!TextUtils.isEmpty(only_jgy_shortcut_list)) { + result_white = only_jgy_shortcut_list.split(","); + } //获取可以被安装的包名 String qch_app_forbid = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid"); - Logutils.e("deleteOtherApp", "only_jgy_shortcut_list:" + only_jgy_shortcut_list); - Logutils.e("deleteOtherApp", "qch_app_forbid:" + qch_app_forbid); - String[] result_white = only_jgy_shortcut_list.split(","); - String[] result_forbid = qch_app_forbid.split(","); + if (!TextUtils.isEmpty(qch_app_forbid)) { + result_forbid = qch_app_forbid.split(","); + } + Log.e("deleteOtherApp", "only_jgy_shortcut_list:" + only_jgy_shortcut_list); + Log.e("deleteOtherApp", "qch_app_forbid:" + qch_app_forbid); + List resulWhitetList = new ArrayList<>(Arrays.asList(result_white)); List resulForbidtList = new ArrayList<>(Arrays.asList(result_forbid)); resulWhitetList.addAll(resulForbidtList); HashSet allWhitePkg = new HashSet<>(resulWhitetList); List installedPackageList = ApkUtils.queryFilterAppInfo(mContext); - Logutils.e("deleteOtherApp", "installedPackageList:" + installedPackageList.toString()); + Log.e("deleteOtherApp", "installedPackageList:" + installedPackageList.toString()); if (allWhitePkg.size() > 0) { for (final String packageName : installedPackageList) { if (ApkUtils.isSystemApp(mContext, packageName)) { - Logutils.e("deleteOtherApp", "is systemApp:" + packageName); + Log.e("deleteOtherApp", "is systemApp:" + packageName); continue; } if (ApkUtils.desktopAPP.contains(packageName)) { @@ -1177,11 +1199,11 @@ public class JGYUtils { } if (!allWhitePkg.contains(packageName)) { ApkUtils.UninstallAPP(mContext, packageName); - Logutils.e("deleteOtherApp", "uninstall apkName:" + packageName); + Log.e("deleteOtherApp", "uninstall apkName:" + packageName); } } } - Logutils.e(TAG, "deleteOtherApp: " + "end"); + Log.e(TAG, "deleteOtherApp: " + "end"); } @@ -1204,19 +1226,19 @@ public class JGYUtils { public void checkBootFile(String url, String MD5) { String urlFileName = Utils.getFileNamefromURL(url); - File bootFile = new File(PathUtils.getExternalDownloadsPath() + File.separator + "jgy" + File.separator + urlFileName); - Logutils.e(TAG, "checkBootFile: bootFile file path=" + bootFile.getAbsolutePath()); - Logutils.e(TAG, "checkBootFile: bootFile exists=" + bootFile.exists() + " isFile=" + bootFile.isFile()); + File bootFile = new File(JGYUtils.getInstance().getDownLoadPath() + urlFileName); + Log.e(TAG, "checkBootFile: bootFile file path=" + bootFile.getAbsolutePath()); + Log.e(TAG, "checkBootFile: bootFile exists=" + bootFile.exists() + " isFile=" + bootFile.isFile()); if (bootFile.exists() && bootFile.isFile()) { String oldMd5 = FileUtils.getFileMD5ToString(bootFile); if (!TextUtils.isEmpty(oldMd5) && oldMd5.equalsIgnoreCase(MD5)) { - Logutils.e(TAG, "checkBootFile: Bootanimation file exists"); + Log.e(TAG, "checkBootFile: Bootanimation file exists"); setBootanimation(bootFile.getAbsolutePath()); } else { JSONObject jsonObject = new JSONObject(); jsonObject.put("MD5", MD5); Utils.ariaDownload(mContext, url, jsonObject); - Logutils.e(TAG, "checkBootFile: " + "download file"); + Log.e(TAG, "checkBootFile: " + "download file"); } } else { JSONObject jsonObject = new JSONObject(); @@ -1234,12 +1256,12 @@ public class JGYUtils { if (!systemFile.exists()) { systemFile.getParentFile().mkdirs(); File file = systemFile.getParentFile(); - Logutils.e(TAG, "setBootanimation: " + file.getAbsolutePath()); + Log.e(TAG, "setBootanimation: " + file.getAbsolutePath()); try { systemFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); - Logutils.e("setBootanimation: ", "createNewFile: " + e.getMessage()); + Log.e("setBootanimation: ", "createNewFile: " + e.getMessage()); } } File newFile = new File(filePath); @@ -1247,31 +1269,31 @@ public class JGYUtils { String systemMD5 = FileUtils.getFileMD5ToString(systemFile); String newMD5 = FileUtils.getFileMD5ToString(newFile); if (systemMD5.equals(newMD5)) { - Logutils.e(TAG, "setBootanimation: 文件一致"); + Log.e(TAG, "setBootanimation: 文件一致"); } else { Path path = Paths.get(newFile.getAbsolutePath()); try { Files.copy(path, new FileOutputStream(systemFile)); - Logutils.e(TAG, "setBootanimation: 设置新开机动画"); + Log.e(TAG, "setBootanimation: 设置新开机动画"); } catch (IOException e) { - Logutils.e(TAG, "setBootanimation: IOException: " + e.getMessage()); + Log.e(TAG, "setBootanimation: IOException: " + e.getMessage()); e.printStackTrace(); } } } else { File file = new File(BOOTANIMATION_PATH); - Logutils.e(TAG, "setBootanimation: " + file.getParentFile().getAbsolutePath()); - Logutils.e(TAG, "setBootanimation: " + "Is a directory = " + file.isDirectory()); + Log.e(TAG, "setBootanimation: " + file.getParentFile().getAbsolutePath()); + Log.e(TAG, "setBootanimation: " + "Is a directory = " + file.isDirectory()); if (!file.getParentFile().delete()) { - Logutils.e(TAG, "setBootanimation: " + "系统动画删除失败"); + Log.e(TAG, "setBootanimation: " + "系统动画删除失败"); } Path path = Paths.get(newFile.getAbsolutePath()); try { Files.copy(path, new FileOutputStream(systemFile)); copy(systemFile.getAbsolutePath(), newFile.getAbsolutePath()); - Logutils.e(TAG, "setBootanimation: 设置新开机动画"); + Log.e(TAG, "setBootanimation: 设置新开机动画"); } catch (IOException e) { - Logutils.e(TAG, "setBootanimation: IOException: " + e.getMessage()); + Log.e(TAG, "setBootanimation: IOException: " + e.getMessage()); e.printStackTrace(); } } @@ -1281,9 +1303,9 @@ public class JGYUtils { File systemFile = new File(BOOTANIMATION_PATH); if (systemFile.exists()) { if (systemFile.delete()) { - Logutils.e(TAG, "removeBootanimation: delete: " + "ture"); + Log.e(TAG, "removeBootanimation: delete: " + "ture"); } else { - Logutils.e(TAG, "removeBootanimation: delete: " + "false"); + Log.e(TAG, "removeBootanimation: delete: " + "false"); } } } @@ -1306,7 +1328,7 @@ public class JGYUtils { inStream.close(); } } catch (Exception e) { - Logutils.e(TAG, "setBootanimation: " + e.getMessage()); + Log.e(TAG, "setBootanimation: " + e.getMessage()); e.printStackTrace(); } } @@ -1336,7 +1358,7 @@ public class JGYUtils { field.setAccessible(true); Object sProviderInstance = field.get(null); if (sProviderInstance != null) { - Logutils.i(TAG, "sProviderInstance isn't null"); + Log.i(TAG, "sProviderInstance isn't null"); return; } @@ -1346,7 +1368,7 @@ public class JGYUtils { } else if (sdkInt == 22) { getProviderClassMethod = factoryClass.getDeclaredMethod("getFactoryClass"); } else { - Logutils.i(TAG, "Don't need to Hook WebView"); + Log.i(TAG, "Don't need to Hook WebView"); return; } getProviderClassMethod.setAccessible(true); @@ -1375,23 +1397,23 @@ public class JGYUtils { if (sProviderInstance != null) { field.set("sProviderInstance", sProviderInstance); - Logutils.i(TAG, "Hook success!"); + Log.i(TAG, "Hook success!"); } else { - Logutils.i(TAG, "Hook failed!"); + Log.i(TAG, "Hook failed!"); } } catch (Throwable e) { - Logutils.w(TAG, e.getMessage()); + Log.w(TAG, e.getMessage()); } } public void deleteScreenshots() { - Logutils.e("File", "deleteScreenshots"); + Log.e("File", "deleteScreenshots"); String path = mContext.getExternalFilesDir("db").getAbsolutePath(); File file = new File(path); File[] files = file.listFiles(); for (File f : files) { if (f.isFile()) { - Logutils.e("File", f.getAbsolutePath()); + Log.e("File", f.getAbsolutePath()); f.delete(); } } @@ -1437,7 +1459,7 @@ public class JGYUtils { } public void openLauncher() { - Logutils.e(TAG, "openLauncher: "); + Log.e(TAG, "openLauncher: "); killPackage("com.android.launcher3"); Intent intent = new Intent(); // 为Intent设置Action、Category属性 @@ -1448,16 +1470,16 @@ public class JGYUtils { } public void cleanLauncherCache() { - Logutils.e(TAG, "cleanLauncherCache: Start"); + Log.e(TAG, "cleanLauncherCache: Start"); int cleaned = (int) SPUtils.get(mContext, "fristcleanLauncherCache", 0); if (cleaned == 0) { try { new CacheUtils().cleanApplicationUserData(mContext, "com.android.launcher3"); SPUtils.put(mContext, "fristcleanLauncherCache", 1); - Logutils.e(TAG, "cleanLauncherCache: end"); + Log.e(TAG, "cleanLauncherCache: end"); } catch (Exception e) { e.printStackTrace(); - Logutils.e(TAG, "cleanLauncherCache: " + e.getMessage()); + Log.e(TAG, "cleanLauncherCache: " + e.getMessage()); } } } @@ -1469,7 +1491,7 @@ public class JGYUtils { } else if ("R".equalsIgnoreCase(secondChars)) {//展锐平台 return ZhanruiPlatform; } else { - Logutils.e(TAG, "checkSNPlatform: " + "sn: " + sn + "没有对应平台"); + Log.e(TAG, "checkSNPlatform: " + "sn: " + sn + "没有对应平台"); return UnknowPlatform; } } @@ -1477,13 +1499,13 @@ public class JGYUtils { public int checkAppPlatform() { String platform = BuildConfig.platform; if ("MTK".equalsIgnoreCase(platform)) { - Logutils.i(TAG, "checkAppPlatform: " + "MTK平台"); + Log.i(TAG, "checkAppPlatform: " + "MTK平台"); return MTKPlatform; } else if ("ZhanRui".equalsIgnoreCase(platform)) { - Logutils.i(TAG, "checkAppPlatform: " + "展锐平台"); + Log.i(TAG, "checkAppPlatform: " + "展锐平台"); return ZhanruiPlatform; } else { - Logutils.i(TAG, "checkAppPlatform: " + "没有数据"); + Log.i(TAG, "checkAppPlatform: " + "没有数据"); return UnknowPlatform; } } @@ -1554,7 +1576,7 @@ public class JGYUtils { for (ActivityManager.RecentTaskInfo info : list) { if (info.realActivity != null) { - Logutils.e(TAG, "removeAllTask: " + info.realActivity.getPackageName()); + Log.e(TAG, "removeAllTask: " + info.realActivity.getPackageName()); //排除自身 if (BuildConfig.APPLICATION_ID.equals(info.realActivity.getPackageName())) { continue; @@ -1564,7 +1586,7 @@ public class JGYUtils { ActivityManagerNative.getDefault().removeTask(info.id); } catch (RemoteException e) { e.printStackTrace(); - Logutils.e(TAG, "removeAllTask: " + e.getMessage()); + Log.e(TAG, "removeAllTask: " + e.getMessage()); } } } @@ -1579,9 +1601,9 @@ public class JGYUtils { ActivityManagerNative.getDefault().removeTask(taskMap.get(packageName)); } catch (RemoteException e) { e.printStackTrace(); - Logutils.e(TAG, "removeTask: " + e.getMessage()); + Log.e(TAG, "removeTask: " + e.getMessage()); } catch (NullPointerException e) { - Logutils.e(TAG, "removeTask: " + e.getMessage()); + Log.e(TAG, "removeTask: " + e.getMessage()); } } @@ -1605,7 +1627,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); + Log.e(TAG, "Failed to get recent tasks " + e); return new ArrayList<>(); } } @@ -1757,7 +1779,7 @@ public class JGYUtils { private void openLauncher3() { setDefaultDesktop(Launcher3, Launcher3Class); - ApkUtils.openApp(mContext, Launcher3); + ApkUtils.openPackage(mContext, Launcher3); } public String getStartClassName(String pkg) { @@ -1806,7 +1828,7 @@ public class JGYUtils { intent.putExtra("className", className); intent.setPackage("com.android.settings"); mContext.sendBroadcast(intent); - ApkUtils.openApp(mContext, pkg); + ApkUtils.openPackage(mContext, pkg); Log.e(TAG, "setDefaultDesktop: " + pkg + ":" + className); } @@ -1817,8 +1839,25 @@ public class JGYUtils { jsonObject.addProperty("jpush_id", JPushInterface.getRegistrationID(mContext)); jsonObject.addProperty("devices_version", Utils.getCustomVersion()); jsonObject.addProperty("appstore_version", BuildConfig.VERSION_NAME); - jsonObject.addProperty("store_version", Utils.getAPPVersionName(mContext)); + jsonObject.addProperty("store_version", Utils.getAPPVersionName(PackageNames.APPSTORE, mContext)); + jsonObject.addProperty("desktop_version", Utils.getAPPVersionName("com.aoleyun.os", mContext)); jsonObject.addProperty("local_mac", Utils.getAndroid7MAC()); + jsonObject.addProperty("wifi_status", Utils.obtainWifiInfo(mContext)); + jsonObject.addProperty("PN_ip", (String) SPUtils.get(mContext, "PublicIP", "")); + jsonObject.addProperty("LAN_ip", Utils.getIPAddress(mContext)); + jsonObject.addProperty("bluetooth", Utils.getBluetoothList()); + jsonObject.addProperty("wifi_name", Utils.getWifiAlias(mContext)); return jsonObject.toString(); } + + public void shutdown() { + if (ActivityManagerNative.isSystemReady()) { + Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN); + intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + } + } + + } diff --git a/app/src/main/java/com/aoleyun/sn/utils/Logutils.java b/app/src/main/java/com/aoleyun/sn/utils/Logutils.java deleted file mode 100644 index 3e057e9..0000000 --- a/app/src/main/java/com/aoleyun/sn/utils/Logutils.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.aoleyun.sn.utils; - -import android.util.Log; - -public class Logutils { -// private final static boolean debug = BuildConfig.DEBUG; - private final static boolean debug = true; - - public static void i(String tag, String msg) { - if (debug) { - Log.i(tag, msg); - } - } - - public static void d(String tag, String msg) { - if (debug) { - Log.d(tag, msg); - } - } - - public static void e(String tag, String msg) { - if (debug) { - Log.e(tag, msg); - } - } - - - public static void w(String tag, String msg) { - if (debug) { - Log.w(tag, msg); - } - } - - - -} diff --git a/app/src/main/java/com/aoleyun/sn/utils/NetworkUtils.java b/app/src/main/java/com/aoleyun/sn/utils/NetworkUtils.java index 08f336a..7f3b8fe 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/NetworkUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/NetworkUtils.java @@ -6,6 +6,7 @@ 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) { @@ -14,7 +15,7 @@ public class NetworkUtils { //获取网络属性 NetworkCapabilities networkCapabilities = mConnectivityManager.getNetworkCapabilities(mConnectivityManager.getActiveNetwork()); if (networkCapabilities != null) { - Logutils.e("Avalible", "NetworkCapalbilities:" + networkCapabilities.toString()); + Log.e("Avalible", "NetworkCapalbilities:" + networkCapabilities.toString()); return networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); } } else { diff --git a/app/src/main/java/com/aoleyun/sn/utils/SaveListUtils.java b/app/src/main/java/com/aoleyun/sn/utils/SaveListUtils.java index be3f37c..8b86503 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/SaveListUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/SaveListUtils.java @@ -2,6 +2,7 @@ package com.aoleyun.sn.utils; import android.content.Context; import android.provider.Settings; +import android.util.Log; import com.blankj.utilcode.util.SPStaticUtils; import com.google.gson.Gson; @@ -18,13 +19,13 @@ public class SaveListUtils { public static List getList() { String data = SPStaticUtils.getString(CommonDatas.FORCE_INSTALL); - Logutils.e("SaveListUtils", data); + Log.e("SaveListUtils", data); Gson gson = new Gson(); Type listType = new TypeToken>() { }.getType(); List list = gson.fromJson(data, listType); if (list != null && list.size() > 0) { - Logutils.e("fht", "getList:" + list.toString()); + Log.e("fht", "getList:" + list.toString()); } else { list = new ArrayList<>(); } @@ -42,7 +43,7 @@ public class SaveListUtils { String gsonData = gson.toJson(list); SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData); } - Logutils.e("fht", "addToList:" + list.toString()); + Log.e("fht", "addToList:" + list.toString()); } @@ -57,7 +58,7 @@ public class SaveListUtils { Gson gson = new Gson(); String gsonData = gson.toJson(forceList); SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData); - Logutils.e("fht", "setList:" + forceList.toString()); + Log.e("fht", "setList:" + forceList.toString()); } @@ -65,7 +66,7 @@ public class SaveListUtils { if (!forceList.contains(s)) { forceList.add(s); } - Logutils.e("fht", "addList:" + forceList.toString()); + Log.e("fht", "addList:" + forceList.toString()); } @@ -92,10 +93,10 @@ public class SaveListUtils { String txt = txtBuilder.toString(); if (txt.length() > 0) { boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", txt); - Logutils.e("fht", "qch_force_app:" + qch_force_app + ":" + txt); + Log.e("fht", "qch_force_app:" + qch_force_app + ":" + txt); } else { boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", "invalid"); - Logutils.e("fht", "qch_force_app:" + qch_force_app + ":" + txt); + Log.e("fht", "qch_force_app:" + qch_force_app + ":" + txt); } setList(); } diff --git a/app/src/main/java/com/aoleyun/sn/utils/ServiceAliveUtils.java b/app/src/main/java/com/aoleyun/sn/utils/ServiceAliveUtils.java index 3d84cc8..b20b50c 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/ServiceAliveUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/ServiceAliveUtils.java @@ -2,6 +2,7 @@ package com.aoleyun.sn.utils; import android.app.ActivityManager; import android.content.Context; +import android.util.Log; public class ServiceAliveUtils { public static boolean isServiceAlive(Context mContext) { @@ -16,7 +17,7 @@ public class ServiceAliveUtils { isServiceRunning = true; } } - Logutils.i("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning); + Log.i("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning); return isServiceRunning; } @@ -32,7 +33,7 @@ public class ServiceAliveUtils { isServiceRunning = true; } } - Logutils.i("ServiceAliveUtils", serviceName + " :isServiceAlice: " + isServiceRunning); + Log.i("ServiceAliveUtils", serviceName + " :isServiceAlice: " + isServiceRunning); return isServiceRunning; } } diff --git a/app/src/main/java/com/aoleyun/sn/utils/SysSettingUtils.java b/app/src/main/java/com/aoleyun/sn/utils/SysSettingUtils.java index fcd8941..8ceed3b 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/SysSettingUtils.java +++ b/app/src/main/java/com/aoleyun/sn/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(TAG, "setting_otg---------" + setting_otg); +// Log.e(TAG, "setting_otg---------" + setting_otg); // String otgStatus = ""; // switch (setting_otg) { // case 0: @@ -74,7 +75,7 @@ public class SysSettingUtils { */ public static void setDisableSetting(Context context) { ToastUtil.betaShow("关闭所有功能"); - Logutils.e("setDisableSetting", "Close all settings: "); + Log.e("setDisableSetting", "Close all settings: "); setPhoneList(context, 1); setUSBstate(context, 1); setBluetooth(context, 1); @@ -117,19 +118,19 @@ public class SysSettingUtils { try { //设置电话功能,电话白名单 boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", state); - Logutils.e(TAG, "qch_call_forbid:" + qch_call_forbid); + Log.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(TAG, "qch_white_list_on:" + qch_white_list_on); + Log.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(TAG, "qch_white_list_Array:" + qch_white_list_Array + "---" + qch_white_list_Array); + Log.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(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); + Log.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); } catch (Exception e) { - Logutils.e(TAG, "setPhoneList: " + e.getMessage()); + Log.e(TAG, "setPhoneList: " + e.getMessage()); } } @@ -139,28 +140,28 @@ 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(TAG, "qch_call_forbid:" + qch_call_forbid); + Log.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(TAG, "qch_white_list_on:" + qch_white_list_on); + Log.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(TAG, "qch_white_list_Array:" + qch_white_list_Array); + Log.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(TAG, "qch_white_list_Array:" + qch_white_list_Array + "---" + setting_phones); + Log.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(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); + Log.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); } catch (Exception e) { - Logutils.e(TAG, "setPhoneList: " + e.getMessage()); + Log.e(TAG, "setPhoneList: " + e.getMessage()); } } @@ -172,12 +173,12 @@ public class SysSettingUtils { if (!BuildConfig.DEBUG) { try { boolean qch_usb_choose = Settings.System.putString(context.getContentResolver(), "qch_usb_choose", "usb_charge"); - Logutils.e(TAG, "qch_usb_choose:" + qch_usb_choose); + Log.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); } catch (Exception e) { - Logutils.e(TAG, "setUSBstate: " + e.getMessage()); + Log.e(TAG, "setUSBstate: " + e.getMessage()); } } } @@ -191,7 +192,7 @@ public class SysSettingUtils { if (!BuildConfig.DEBUG) { try { boolean qch_usb_choose = Settings.System.putString(context.getContentResolver(), "qch_usb_choose", setting_usb); - Logutils.e(TAG, "qch_usb_choose---------" + qch_usb_choose); + Log.e(TAG, "qch_usb_choose---------" + qch_usb_choose); String usbStatus = ""; switch (setting_usb) { case "usb_charge": @@ -208,7 +209,7 @@ public class SysSettingUtils { Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); context.sendBroadcast(usbIntent); } catch (Exception e) { - Logutils.e(TAG, "setUSBstate: " + e.getMessage()); + Log.e(TAG, "setUSBstate: " + e.getMessage()); } } } @@ -217,7 +218,7 @@ public class SysSettingUtils { try { boolean qch_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", state); //写入系统数据库 - Logutils.e(TAG, "qch_bht_forbid_on:" + qch_bht_forbid_on); + Log.e(TAG, "qch_bht_forbid_on:" + qch_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (qch_bht_forbid_on) { //成功 @@ -232,7 +233,7 @@ public class SysSettingUtils { //设置关闭时关闭蓝牙 } } catch (Exception e) { - Logutils.e(TAG, "setBluetooth: " + e.getMessage()); + Log.e(TAG, "setBluetooth: " + e.getMessage()); } } @@ -247,7 +248,7 @@ public class SysSettingUtils { //蓝牙传输开关 boolean qch_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", setting_bht); - Logutils.e(TAG, "qch_bht_forbid_on:" + qch_bht_forbid_on); + Log.e(TAG, "qch_bht_forbid_on:" + qch_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (qch_bht_forbid_on) { //成功 @@ -260,7 +261,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(TAG, "setting_context:" + setting_context); + Log.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"); @@ -275,7 +276,7 @@ public class SysSettingUtils { } } } catch (Exception e) { - Logutils.e(TAG, "setBluetooth: " + e.getMessage()); + Log.e(TAG, "setBluetooth: " + e.getMessage()); } } @@ -286,9 +287,9 @@ 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(TAG, "qch_hotspot_forbid_on:" + qch_hotspot_forbid_on); + Log.e(TAG, "qch_hotspot_forbid_on:" + qch_hotspot_forbid_on); } catch (Exception e) { - Logutils.e(TAG, "setHotspot: " + e.getMessage()); + Log.e(TAG, "setHotspot: " + e.getMessage()); } } @@ -302,10 +303,10 @@ public class SysSettingUtils { context.sendStickyBroadcast(intent); } boolean qch_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_hotspot_forbid_on", setting_hotspot); - Logutils.e(TAG, "qch_hotspot_forbid_on---------" + setting_hotspot); - Logutils.e(TAG, "qch_hotspot_forbid_on---------" + qch_hotspot_forbid_on); + Log.e(TAG, "qch_hotspot_forbid_on---------" + setting_hotspot); + Log.e(TAG, "qch_hotspot_forbid_on---------" + qch_hotspot_forbid_on); } catch (Exception e) { - Logutils.e(TAG, "setHotspot: " + e.getMessage()); + Log.e(TAG, "setHotspot: " + e.getMessage()); } } @@ -314,7 +315,7 @@ public class SysSettingUtils { int setting_navigation = 0; //写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示 boolean qch_hide_navigationBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_NavigationBar", setting_navigation); - Logutils.e(TAG, "qch_hide_navigationBar---------" + qch_hide_navigationBar); + Log.e(TAG, "qch_hide_navigationBar---------" + qch_hide_navigationBar); String navigationStatus = ""; switch (setting_navigation) { @@ -336,7 +337,7 @@ public class SysSettingUtils { if (oldNum != setting_statusbar) { //写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示 boolean qch_hide_statusBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_statusBar", setting_statusbar); - Logutils.e(TAG, "qch_hide_statusBar---------" + qch_hide_statusBar); + Log.e(TAG, "qch_hide_statusBar---------" + qch_hide_statusBar); String statusbarStatus = ""; switch (setting_statusbar) { case 0: @@ -356,7 +357,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(TAG, "qch_hide_navigationBar---------" + qch_hide_navigationBar); + Log.e(TAG, "qch_hide_navigationBar---------" + qch_hide_navigationBar); String navigationStatus = ""; switch (setting_navigation) { @@ -377,7 +378,7 @@ public class SysSettingUtils { if (oldNum != setting_statusbar) { //写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示 boolean qch_hide_statusBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_statusBar", setting_statusbar); - Logutils.e(TAG, "qch_hide_statusBar---------" + qch_hide_statusBar); + Log.e(TAG, "qch_hide_statusBar---------" + qch_hide_statusBar); String statusbarStatus = ""; switch (setting_statusbar) { case 0: @@ -396,9 +397,9 @@ public class SysSettingUtils { try { //摄像头开关 boolean qch_app_camera = Settings.System.putInt(context.getContentResolver(), "qch_app_camera", state); - Logutils.e(TAG, "qch_app_camera1:" + state); + Log.e(TAG, "qch_app_camera1:" + state); // ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera"); - Logutils.e(TAG, "setting_camera---------" + qch_app_camera); + Log.e(TAG, "setting_camera---------" + qch_app_camera); String cameraStatus = "qch_camera_forbid"; switch (state) { case 0: @@ -411,7 +412,7 @@ public class SysSettingUtils { Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings"); context.sendBroadcast(cameraIntent); } catch (Exception e) { - Logutils.e(TAG, "setCamera: " + e.getMessage()); + Log.e(TAG, "setCamera: " + e.getMessage()); } } @@ -420,9 +421,9 @@ public class SysSettingUtils { //摄像头开关 int setting_camera = changeNum(jsonObject.getInteger("setting_camera")); Settings.System.putInt(context.getContentResolver(), "qch_app_camera", setting_camera); - Logutils.e(TAG, "qch_app_camera2:" + setting_camera); + Log.e(TAG, "qch_app_camera2:" + setting_camera); // ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera"); - Logutils.e(TAG, "setting_camera---------" + setting_camera); + Log.e(TAG, "setting_camera---------" + setting_camera); String cameraStatus = ""; switch (setting_camera) { case 0: @@ -435,7 +436,7 @@ public class SysSettingUtils { Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings"); context.sendBroadcast(cameraIntent); } catch (Exception e) { - Logutils.e(TAG, "setCamera: " + e.getMessage()); + Log.e(TAG, "setCamera: " + e.getMessage()); } } @@ -444,7 +445,7 @@ public class SysSettingUtils { //tfmedia开关 // int setting_tfmedia = 1; boolean qch_tfmedia_forbid = Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", state); - Logutils.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid); + Log.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid); String tfmediaStatus = ""; switch (state) { case 0: @@ -458,12 +459,12 @@ public class SysSettingUtils { context.sendBroadcast(tfmediaIntent); if (state == 1) { boolean qch_tfmedia_filetypes = Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", "Empty");//影音管控 - Logutils.e(TAG, "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes); + Log.e(TAG, "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes); } else { Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0); } } catch (Exception e) { - Logutils.e(TAG, "setTF: " + e.getMessage()); + Log.e(TAG, "setTF: " + e.getMessage()); } } @@ -479,15 +480,15 @@ public class SysSettingUtils { // } boolean qch_tfmedia_forbid = Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", setting_tfmedia); - Logutils.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid); + Log.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid); String tfmediaStatus = ""; switch (setting_tfmedia) { case 0: - Logutils.e(TAG, "setting_tfmedia: " + "打开"); + Log.e(TAG, "setting_tfmedia: " + "打开"); tfmediaStatus = "qch_tfmedia_open"; break; case 1: - Logutils.e(TAG, "setting_tfmedia: " + "禁止"); + Log.e(TAG, "setting_tfmedia: " + "禁止"); tfmediaStatus = "qch_tfmedia_forbid"; break; } @@ -504,12 +505,12 @@ public class SysSettingUtils { } stringBuffer.deleteCharAt(stringBuffer.length() - 1); Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控 - Logutils.e(TAG, "qch_tfmedia_filetypes---------" + stringBuffer.toString()); + Log.e(TAG, "qch_tfmedia_filetypes---------" + stringBuffer.toString()); } else { Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0); } } catch (Exception e) { - Logutils.e(TAG, "setTF: " + e.getMessage()); + Log.e(TAG, "setTF: " + e.getMessage()); } } @@ -521,22 +522,22 @@ public class SysSettingUtils { // int deskclock = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", state); ApkUtils.hideSystemSettingAPP(context, "com.android.deskclock"); - Logutils.e(TAG, "qch_app_deskclock" + state); + Log.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(TAG, "qch_app_soundrecorder" + state); + Log.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(TAG, "qch_app_music" + state); + Log.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(TAG, "qch_app_gallery" + state); + Log.e(TAG, "qch_app_gallery" + state); //文件管理器 // int filemanager = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", state); @@ -545,12 +546,12 @@ public class SysSettingUtils { } else { ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui"); } - Logutils.e(TAG, "qch_app_filemanager" + state); + Log.e(TAG, "qch_app_filemanager" + state); Settings.System.putInt(context.getContentResolver(), "qch_app_browser", state); - Logutils.e(TAG, "qch_app_browser" + state); + Log.e(TAG, "qch_app_browser" + state); } catch (Exception e) { - Logutils.e(TAG, "setIcon: " + e.getMessage()); + Log.e(TAG, "setIcon: " + e.getMessage()); } } @@ -562,22 +563,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(TAG, "qch_app_deskclock" + deskclock); + Log.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(TAG, "qch_app_soundrecorder" + soundrecorder); + Log.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(TAG, "qch_app_music" + music); + Log.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(TAG, "qch_app_gallery" + gallery); + Log.e(TAG, "qch_app_gallery" + gallery); //壁纸 int wallpaper = changeNum(jsonObject.getInteger("setting_wallpaper")); setWallpaper(context, wallpaper); @@ -589,14 +590,14 @@ public class SysSettingUtils { } else { ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui"); } - Logutils.e(TAG, "qch_app_filemanager" + filemanager); + Log.e(TAG, "qch_app_filemanager" + filemanager); //浏览器 int browser = changeNum(jsonObject.getInteger("setting_browser")); Settings.System.putInt(context.getContentResolver(), "qch_app_browser", browser); - Logutils.e(TAG, "qch_app_browser" + browser); + Log.e(TAG, "qch_app_browser" + browser); } catch (Exception e) { - Logutils.e(TAG, "setIcon: " + e.getMessage()); + Log.e(TAG, "setIcon: " + e.getMessage()); } } @@ -604,12 +605,12 @@ public class SysSettingUtils { //壁纸 // int wallpaper = 1; Settings.System.putInt(context.getContentResolver(), "qch_app_wallpaper", state); - Logutils.e(TAG, "qch_app_wallpaper" + state); + Log.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(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); + Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); //默认打开 } @@ -619,10 +620,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(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); + Log.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(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); + Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on); } } @@ -664,7 +665,7 @@ public class SysSettingUtils { break; } } - Logutils.e(TAG, "setAutoTime: " + "action=" + action); + Log.e(TAG, "setAutoTime: " + "action=" + action); Intent intent = new Intent(); intent.setAction(action); intent.setPackage("com.android.settings"); @@ -672,7 +673,7 @@ public class SysSettingUtils { } private static void setAutoTime(Context context, int state) { - Logutils.e(TAG, "setAutoTime: " + "default"); + Log.e(TAG, "setAutoTime: " + "default"); Intent intent = new Intent(); intent.setAction("qch_autotime_network"); intent.setPackage("com.android.settings"); @@ -681,7 +682,7 @@ public class SysSettingUtils { @SuppressLint("NewApi") public static void setStatusBar(Context context, JSONObject jsonObject) { - Logutils.e(TAG, "setStatusBar: " + jsonObject.toJSONString()); + Log.e(TAG, "setStatusBar: " + jsonObject.toJSONString()); if (null != jsonObject) { int whole = jsonObject.getInteger("whole"); if (whole == 1) { @@ -715,7 +716,7 @@ public class SysSettingUtils { @SuppressLint("NewApi") private static void setStatusBar(Context context, int state) { - Logutils.e(TAG, "setStatusBar: " + "default"); + Log.e(TAG, "setStatusBar: " + "default"); StatusBarManager mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE); mStatusBarManager.disable(StatusBarManager.DISABLE_BACK | StatusBarManager.DISABLE_RECENT | StatusBarManager.DISABLE_HOME); mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);//显示隐藏的虚拟按键 @@ -731,15 +732,15 @@ public class SysSettingUtils { int state = 1; try { state = jsonObject.getInteger("setting_browserInput"); - Logutils.e(TAG, "setBrowserInput: " + state); + Log.e(TAG, "setBrowserInput: " + state); String json = jsonObject.getString("setting_browserInput"); if (TextUtils.isEmpty(json)) { state = 1; } } catch (Exception e) { - Logutils.e(TAG, "setBrowserInput: e: " + e.getMessage()); + Log.e(TAG, "setBrowserInput: e: " + e.getMessage()); } - Logutils.e(TAG, "setBrowserInput: " + state); + Log.e(TAG, "setBrowserInput: " + state); //后台没有这个选项默认打开 if (state == 0) { Settings.System.putInt(context.getContentResolver(), "qch_Browser_input", 1); diff --git a/app/src/main/java/com/aoleyun/sn/utils/TimeUtils.java b/app/src/main/java/com/aoleyun/sn/utils/TimeUtils.java index b87e020..b9e4c88 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/TimeUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/TimeUtils.java @@ -6,8 +6,10 @@ import android.content.Intent; import androidx.annotation.NonNull; import android.text.TextUtils; +import android.util.Log; +import com.aoleyun.sn.bean.PoweroffBean; import com.aoleyun.sn.service.MainService; import java.text.DateFormat; @@ -20,10 +22,12 @@ import java.util.Date; * 时间管控工具类 */ public class TimeUtils { + private static final String TAG = TimeUtils.class.getSimpleName(); private static DateFormat df = new SimpleDateFormat("HH:mm"); public static final String START_TIME_KEY = "START_TIME"; public static final String END_TIME_KEY = "END_TIME"; public static long dayTime = 60 * 60 * 24 * 1000; + public static long minuteTime = 60 * 1000; public static String getNowTime() { long nowTime = System.currentTimeMillis(); @@ -38,6 +42,64 @@ public class TimeUtils { // // } + public static boolean isShutdownTime(PoweroffBean poweroffBean) { + int type = poweroffBean.getType(); + if (type == 1) { //单次定时关机 + return isShutdownTime(poweroffBean.getTime()); + } else if (type == 2) {//循环定时关机 + return isShutdownTime(getZeroTiemstamp() + getLoopTime(poweroffBean.getTime())); + } + return false; + } + + private static long getZeroTiemstamp() { + long nowTime = System.currentTimeMillis(); + long dayMillisecond = 60 * 60 * 24 * 1000; + long zeroTime = ((nowTime) / dayMillisecond) * dayMillisecond; + Log.e(TAG, "getZeroTiemstamp: " + zeroTime); + return zeroTime; + } + + private static long getLoopTime(String timestamp) { + //"15:34:39" + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + try { + Date d = sdf.parse(timestamp); + long loopTime = d.getTime(); + Log.e(TAG, "getLoopTime: LoopTime = " + loopTime); + return loopTime; + } catch (ParseException e) { + Log.e(TAG, "getLoopTime: e: " + e.getStackTrace()); + return 0; + } + } + + public static boolean isShutdownTime(String timestamp) { + //"2021-11-18 00:00:00" + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + Date d = sdf.parse(timestamp); + long realTime = d.getTime(); + return isShutdownTime(realTime); + } catch (ParseException e) { + Log.e(TAG, "isShutdownTime: " + e.getStackTrace()); + return false; + } + } + + public static boolean isShutdownTime(long timestamp) { + long realTime = timestamp; + long nowTime = System.currentTimeMillis(); + if (String.valueOf(timestamp).length() < String.valueOf(nowTime).length()) { + realTime = timestamp * 1000; + } + if (realTime >= nowTime && realTime <= (nowTime + 1000 * 60)) { + return true; + } else { + return false; + } + } + public static ContralTime String2ContralTime(Context context, @NonNull String timeText) { DateFormat df = ContralTime.getDf(); String[] time = timeText.trim().split("-"); @@ -157,7 +219,9 @@ public class TimeUtils { //开始时间大于结束时间 列 16:00-01:00 endDate.setTime(endDate.getTime() + dayTime); } - if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) { + Log.e(TAG, "inControlTime: " + (startDate.getTime() - minuteTime)); + assert nowDate != null; + if (nowDate.getTime() <= startDate.getTime() - minuteTime || nowDate.getTime() >= endDate.getTime()) { return true; } else { return false; diff --git a/app/src/main/java/com/aoleyun/sn/utils/ToastUtil.java b/app/src/main/java/com/aoleyun/sn/utils/ToastUtil.java index 6e4da4a..c4cb2c3 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/ToastUtil.java +++ b/app/src/main/java/com/aoleyun/sn/utils/ToastUtil.java @@ -7,8 +7,11 @@ import android.os.Build; import android.os.Handler; import android.os.Looper; import android.util.Log; +import android.view.Gravity; import android.widget.Toast; +import com.aoleyun.sn.R; +import com.blankj.utilcode.util.ColorUtils; import com.blankj.utilcode.util.ToastUtils; import com.aoleyun.sn.BuildConfig; @@ -60,6 +63,15 @@ public class ToastUtil { } } + public static void showCenter(final String msg) { + ToastUtils.make() + .setBgColor(ColorUtils.getColor(R.color.toast_color)) + .setTextColor(Color.WHITE) + .setGravity(Gravity.CENTER, 0, 0) + .setNotUseSystemToast() + .show(msg); + } + private static Toast mToast = null; //android 8.0以后限制 diff --git a/app/src/main/java/com/aoleyun/sn/utils/URLUtils.java b/app/src/main/java/com/aoleyun/sn/utils/URLUtils.java index 1f0e23d..e075ab9 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/URLUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/URLUtils.java @@ -47,7 +47,7 @@ public class URLUtils { String oldwhiteList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray"); String oldWhiteIP = (String) SPUtils.get(mContext, "white_ip", ""); if (TextUtils.isEmpty(oldwhiteList) && TextUtils.isEmpty(oldWhiteIP)) { - Logutils.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is empty"); + Log.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is empty"); Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", "Invalid"); } else { String white_ip = (String) SPUtils.get(mContext, "white_ip", ""); @@ -55,7 +55,7 @@ public class URLUtils { whiteIPList = new HashSet<>(Arrays.asList(white_ip.split(","))); } whiteIPList.removeIf(TextUtils::isEmpty); - Logutils.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is : " + oldwhiteList); + Log.e(TAG, "getBrowserWhiteList: " + "oldwhiteList is : " + oldwhiteList); HashSet URLList = new HashSet<>(Arrays.asList(oldwhiteList.trim().split(","))); URLList.removeIf(TextUtils::isEmpty); if (URLList.size() == 0 && whiteIPList.size() == 0) { @@ -134,7 +134,7 @@ public class URLUtils { // emitter.onNext(getOkHttpURL("http://" + nowww)); // baseURLList.add("https://" + nowww); // emitter.onNext(getOkHttpURL("https://" + nowww)); -// Logutils.e(TAG, "subscribe: nowww: " + nowww); +// Log.e(TAG, "subscribe: nowww: " + nowww); // baseURLList.add("http://" + url); // emitter.onNext(getOkHttpURL("http://" + url)); // baseURLList.add("https://" + url); @@ -154,13 +154,13 @@ public class URLUtils { // baseURLList.add("https://" + url); // emitter.onNext(getOkHttpURL("https://" + url)); // } else { -//// Logutils.e(TAG, "subscribe: 0:" + url); +//// Log.e(TAG, "subscribe: 0:" + url); // baseURLList.add(url); // if (!TextUtils.isEmpty(url)) { // emitter.onNext(getOkHttpURL(url)); // } // } -// Logutils.e(TAG, "subscribe: " + url); +// Log.e(TAG, "subscribe: " + url); // emitter.onNext(getOkHttpURL(url)); } emitter.onComplete(); @@ -175,35 +175,35 @@ public class URLUtils { @Override public void onNext(String s) { - Logutils.e(TAG, "onNext: " + s); + Log.e(TAG, "onNext: " + s); baseURLList.add(s); // if (s.startsWith("http://")) { // String noHttp = s.substring(7); -// Logutils.e(TAG, "onNext: noHttp: " + noHttp); +// Log.e(TAG, "onNext: noHttp: " + noHttp); // baseURLList.add(noHttp); // } // if (s.startsWith("https://")) { // String noHttps = s.substring(8); -// Logutils.e(TAG, "onNext: noHttps: " + noHttps); +// Log.e(TAG, "onNext: noHttps: " + noHttps); // baseURLList.add(noHttps); // } } @Override public void onError(Throwable e) { - Logutils.e(TAG, "onError: " + e.getMessage()); + Log.e(TAG, "onError: " + e.getMessage()); } @Override public void onComplete() { - Logutils.i(TAG, "onComplete: " + baseURLList); + Log.i(TAG, "onComplete: " + baseURLList); baseURLList.addAll(nohttpURLList); baseURLList.addAll(whiteIPList); baseURLList.removeIf(TextUtils::isEmpty); String DeselectBrowserArray = String.join(",", baseURLList); - Logutils.e(TAG, "onComplete: " + "white list: " + DeselectBrowserArray); + Log.e(TAG, "onComplete: " + "white list: " + DeselectBrowserArray); boolean write = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", DeselectBrowserArray); - Logutils.i(TAG, "onComplete: " + "write :" + write + " time = " + (System.currentTimeMillis() - time1)); + Log.i(TAG, "onComplete: " + "write :" + write + " time = " + (System.currentTimeMillis() - time1)); } }); } @@ -214,7 +214,7 @@ public class URLUtils { public void setBrowserBlackList() { String qch_webblack_url = Settings.System.getString(mContext.getContentResolver(), "qch_webblack_url"); - Logutils.e(TAG, "setBrowserBlackList: qch_webblack_url = " + qch_webblack_url); + Log.e(TAG, "setBrowserBlackList: qch_webblack_url = " + qch_webblack_url); if (TextUtils.isEmpty(qch_webblack_url)) { Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", "Invalid"); } else { @@ -228,7 +228,7 @@ public class URLUtils { if (TextUtils.isEmpty(url)) { continue; } - Logutils.e(TAG, "setBrowserBlackList: url: " + url); + Log.e(TAG, "setBrowserBlackList: url: " + url); if (qch_webblack_url.startsWith("http://")) { blackList.add(url); blackList.add(url.replace("http://", "https://")); @@ -242,9 +242,9 @@ public class URLUtils { } blackList.addAll(blackIPList); blackList.removeIf(TextUtils::isEmpty); - Logutils.e(TAG, "setBrowserBlackList: blackList: " + blackList); + Log.e(TAG, "setBrowserBlackList: blackList: " + blackList); boolean write = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", String.join(",", blackList)); - Logutils.e(TAG, "setBrowserBlackList: write: " + write); + Log.e(TAG, "setBrowserBlackList: write: " + write); } } @@ -268,25 +268,25 @@ public class URLUtils { // call.enqueue(new Callback() { // @Override // public void onFailure(Call call, IOException e) { -// Logutils.e(TAG, "onFailure: "); +// Log.e(TAG, "onFailure: "); // } // // @Override // public void onResponse(Call call, Response response) throws IOException { -// Logutils.e(TAG, "onResponse: " + getIP(response.request().url().uri())); +// Log.e(TAG, "onResponse: " + getIP(response.request().url().uri())); // } // }); try { Response response = call.execute(); if (response.isSuccessful()) { - Logutils.e(TAG, "getOkHttpURL: " + response.request().url().toString()); + Log.e(TAG, "getOkHttpURL: " + response.request().url().toString()); return getIP(response.request().url().uri()).toString(); } else { return ""; } } catch (IOException e) { e.printStackTrace(); - Logutils.w(TAG, "getOkHttpURL: " + e.getMessage() + " : " + URL); + Log.w(TAG, "getOkHttpURL: " + e.getMessage() + " : " + URL); return ""; } } @@ -377,7 +377,7 @@ public class URLUtils { userAgent = WebSettings.getDefaultUserAgent(mContext); //需要hook webview } catch (Exception e) { - Logutils.e(TAG, "getUserAgent: " + e.getMessage()); + Log.e(TAG, "getUserAgent: " + e.getMessage()); userAgent = System.getProperty("http.agent"); } } else { diff --git a/app/src/main/java/com/aoleyun/sn/utils/Utils.java b/app/src/main/java/com/aoleyun/sn/utils/Utils.java index 95f8f38..c61420c 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/Utils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/Utils.java @@ -2,6 +2,8 @@ package com.aoleyun.sn.utils; import android.annotation.SuppressLint; import android.app.ActivityManager; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; @@ -29,6 +31,7 @@ import android.os.BatteryManager; import android.os.Build; import android.os.Environment; import android.os.StatFs; +import android.os.SystemClock; import android.provider.Settings; import androidx.annotation.RequiresApi; @@ -47,6 +50,7 @@ import android.widget.EditText; import android.widget.Toast; import com.alibaba.fastjson.JSONObject; +import com.aoleyun.sn.network.HTTPInterface; import com.arialyy.aria.core.Aria; import com.blankj.utilcode.util.FileUtils; import com.blankj.utilcode.util.PathUtils; @@ -88,9 +92,11 @@ import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.regex.Pattern; import io.reactivex.Observable; @@ -634,16 +640,16 @@ public class Utils { return ""; } - //获取教管易版本号 - public static synchronized String getAPPVersionName(Context context) { + //获取App版本号 + public static synchronized String getAPPVersionName(String pck, Context context) { PackageManager pm = context.getPackageManager(); String versionName; try { - PackageInfo packageInfo = pm.getPackageInfo("com.jiaoguanyi.store", 0); + PackageInfo packageInfo = pm.getPackageInfo(pck, 0); versionName = packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); - versionName = "0"; + versionName = ""; } return versionName; } @@ -704,7 +710,7 @@ public class Utils { } } catch (Exception e) { e.printStackTrace(); - Logutils.e("e", "读取设备序列号异常:" + e.toString()); + Log.e("e", "读取设备序列号异常:" + e.toString()); } if (BuildConfig.DEBUG) { // return "QNG2DKB00463"; @@ -759,7 +765,7 @@ public class Utils { return String.format("%.2fGB", gbValue); } else { double mbValue = (double) space / A_MB; - // Logutils.e("GB", "gbvalue=" + mbValue); + // Log.e("GB", "gbvalue=" + mbValue); if (mbValue >= 1) { return String.format("%.2fMB", mbValue); } else { @@ -877,7 +883,7 @@ public class Utils { // // float roundPx = 15; //圆角半径 // mPaint.setAntiAlias(true); -// //Logutils.d("wy"+TAG,"mBitmap.getWidth()="+mBitmap.getWidth()+", mBitmap.getHeight()="+mBitmap.getHeight()); +// //Log.d("wy"+TAG,"mBitmap.getWidth()="+mBitmap.getWidth()+", mBitmap.getHeight()="+mBitmap.getHeight()); // mCanvas.drawRoundRect(mRectF, roundPx, roundPx, mPaint); // mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // mCanvas.drawBitmap(mBitmap, mRect, mRect, mPaint); @@ -996,9 +1002,9 @@ public class Utils { list += str + ","; } list = list.substring(0, list.length() - 1); - Logutils.e("fht", list); + Log.e("fht", list); writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", list); - Logutils.e("fht", "qch_app_forbid:" + list); + Log.e("fht", "qch_app_forbid:" + list); } else { writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", "Invalid"); } @@ -1042,22 +1048,23 @@ public class Utils { public static void ariaDownload(Context context, String url, JSONObject jsonObject) { String fileName = getFileNamefromURL(url); String urlMD5 = jsonObject.getString("MD5"); - Logutils.e("ariaDownload", "urlMD5=" + urlMD5); - String p = PathUtils.getExternalDownloadsPath(); - File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName); + Log.e("ariaDownload", "urlMD5=" + urlMD5); + String p = JGYUtils.getInstance().getDownLoadPath(); + File file = new File(JGYUtils.getInstance().getDownLoadPath() + fileName); if (file.exists() && !file.isDirectory()) { String filenameMD5 = getMD5fromFileName(url); String fileMD5 = FileUtils.getFileMD5ToString(file); - Logutils.e("ariaDownload", "filenameMD5=" + filenameMD5); - Logutils.e("ariaDownload", "fileMD5=" + fileMD5); + Log.e("ariaDownload", "filenameMD5=" + filenameMD5); + Log.e("ariaDownload", "fileMD5=" + fileMD5); //后端还没有完成json字段的MD5,暂时用文件名获取 if (fileMD5.equalsIgnoreCase(urlMD5)) { ApkUtils.installApp(context, file.getAbsolutePath()); } else { Aria.download(context) .load(url) //读取下载地址 - .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName, true) + .setFilePath(JGYUtils.getInstance().getDownLoadPath() + fileName) + .ignoreFilePathOccupy() .setExtendField(jsonObject.toJSONString()) .create(); //启动下载} // SaveListUtils.addDownLoadList(app_package); @@ -1066,11 +1073,11 @@ public class Utils { } else { Aria.download(context) .load(url) //读取下载地址 - .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName, true) + .setFilePath(JGYUtils.getInstance().getDownLoadPath() + fileName) + .ignoreFilePathOccupy() .setExtendField(jsonObject.toJSONString()) .create(); //启动下载} } - } /** @@ -1098,15 +1105,15 @@ public class Utils { @Override public void onNext(Integer integer) { if (integer == 0) { - Logutils.e("doss", "成功"); + Log.e("doss", "成功"); } else { - Logutils.e("doss", "失败"); + Log.e("doss", "失败"); } } @Override public void onError(Throwable e) { - Logutils.e("doss", "Throwable=" + e.getMessage()); + Log.e("doss", "Throwable=" + e.getMessage()); } @Override @@ -1117,12 +1124,12 @@ public class Utils { // new Thread(new Runnable() { // @Override // public void run() { -// Logutils.e("whh0914", "开始屏幕截图..."); +// Log.e("whh0914", "开始屏幕截图..."); // String filepath = context.getFileStreamPath("screenshot").getAbsolutePath(); // try { // CmdUtil.execute("screencap -p " + filepath); // } catch (Exception e) { -// Logutils.e("whh0914", "屏幕截图出现异常:" + e.toString()); +// Log.e("whh0914", "屏幕截图出现异常:" + e.toString()); // } // } // }).start(); @@ -1172,12 +1179,12 @@ public class Utils { int screenWidth = (int) (width / density); // 屏幕宽度(dp) int screenHeight = (int) (height / density);// 屏幕高度(dp) -// Logutils.e("h_bl", "屏幕宽度(像素):" + width); -// Logutils.e("h_bl", "屏幕高度(像素):" + height); -// Logutils.e("h_bl", "屏幕密度(0.75 / 1.0 / 1.5):" + density); -// Logutils.e("h_bl", "屏幕密度dpi(120 / 160 / 240):" + densityDpi); -// Logutils.e("h_bl", "屏幕宽度(dp):" + screenWidth); -// Logutils.e("h_bl", "屏幕高度(dp):" + screenHeight); +// Log.e("h_bl", "屏幕宽度(像素):" + width); +// Log.e("h_bl", "屏幕高度(像素):" + height); +// Log.e("h_bl", "屏幕密度(0.75 / 1.0 / 1.5):" + density); +// Log.e("h_bl", "屏幕密度dpi(120 / 160 / 240):" + densityDpi); +// Log.e("h_bl", "屏幕宽度(dp):" + screenWidth); +// Log.e("h_bl", "屏幕高度(dp):" + screenHeight); return width + "×" + height; } @@ -1223,14 +1230,14 @@ public class Utils { // IMEI = (String) method.invoke(TelephonyMgr); // } catch (Exception e) { // e.printStackTrace(); -// Logutils.e("getIMEI", e.getMessage()); +// Log.e("getIMEI", e.getMessage()); // } // IMEI = TelephonyMgr.getDeviceId(); // } else {//9.0到10.0获取 IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } - Logutils.e("IMEI:", "IMEI: " + IMEI); + Log.e("IMEI:", "IMEI: " + IMEI); if (null == IMEI) { return "-"; } else { @@ -1253,8 +1260,12 @@ public class Utils { jsonObject.put("firmware_version", firmware_version); jsonObject.put("rom", rom); jsonObject.put("screen_rate", screen_rate); + jsonObject.put("working_time", SystemClock.elapsedRealtime() / 1000); + jsonObject.put("restart_count", SPUtils.get(context, "restart_count", 0)); + jsonObject.put("storage_usable", getRemnantSize(context)); + jsonObject.put("storage_total", getDataTotalSize(context)); String jsonString = jsonObject.toJSONString(); - Logutils.e(TAG, "getMachine: " + jsonString); + Log.e(TAG, "getMachine: " + jsonString); return jsonString; } @@ -1263,7 +1274,7 @@ public class Utils { int electric = getBattery(context); int charging = getIsCharging(context); String memory = Formatter.formatFileSize(context, getFreeMemory(context)) + "\t 已用" + "/" + "共" + Formatter.formatFileSize(context, getTotalMemory(context)); - Logutils.e("getHardware", "Memory: " + memory); + Log.e("getHardware", "Memory: " + memory); String storage = getRemnantSize(context) + "/" + getDataTotalSize(context); int CPU = getNumCores(); JSONObject jsonObject = new JSONObject(); @@ -1273,7 +1284,7 @@ public class Utils { jsonObject.put("storage", storage); jsonObject.put("CPU", CPU + "核"); String jsonString = jsonObject.toJSONString(); - Logutils.e(TAG, "getHardware: " + jsonString); + Log.e(TAG, "getHardware: " + jsonString); return jsonString; } @@ -1309,7 +1320,7 @@ public class Utils { BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE); return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); } catch (Exception e) { - Logutils.e("getBattery", "getBattery" + e.getMessage()); + Log.e("getBattery", "getBattery" + e.getMessage()); } return 0; } @@ -1370,7 +1381,7 @@ public class Utils { ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); long freeMem = memoryInfo.totalMem - memoryInfo.availMem; -// Logutils.e("getHardware", "getFreeMemory: " + freeMem); +// Log.e("getHardware", "getFreeMemory: " + freeMem); return freeMem; } @@ -1383,7 +1394,7 @@ public class Utils { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); -// Logutils.e("getHardware", "getFreeMemory: " + memoryInfo.totalMem); +// Log.e("getHardware", "getFreeMemory: " + memoryInfo.totalMem); return memoryInfo.totalMem; } @@ -1456,13 +1467,13 @@ public class Utils { long totalSize = statFs.getTotalBytes(); long availableSize = statFs.getAvailableBytes(); - Logutils.e("statfs", "total = " + getUnit(totalSize)); - Logutils.e("statfs", "availableSize = " + getUnit(availableSize)); + Log.e("statfs", "total = " + getUnit(totalSize)); + Log.e("statfs", "availableSize = " + getUnit(availableSize)); //这里可以看出 available 是小于 free ,free 包括保留块。 - Logutils.e("statfs", "total = " + getUnit(blockSize * blockCount)); - Logutils.e("statfs", "available = " + getUnit(blockSize * availableCount)); - Logutils.e("statfs", "free = " + getUnit(blockSize * freeBlocks)); + Log.e("statfs", "total = " + getUnit(blockSize * blockCount)); + Log.e("statfs", "available = " + getUnit(blockSize * availableCount)); + Log.e("statfs", "free = " + getUnit(blockSize * freeBlocks)); } @@ -1541,5 +1552,86 @@ public class Utils { } return "获取失败"; } + + /** + * 获取公网IP并保存 + * + * @param context + */ + public static void getPublicIP(Context context) { + HTTPInterface.getPublicIP(context, new HTTPInterface.PublicIP() { + @Override + public void set(String ip) { + SPUtils.put(context, "PublicIP", ip); + Log.e("getPublicIP", "set: " + ip); + } + }); + } + + /** + * 获取WiFi信号强度 + * + * @param context + * @return + */ + public static int obtainWifiInfo(Context context) { + // Wifi的连接速度及信号强度: + WifiManager wifiManager = (WifiManager) context.getSystemService(WIFI_SERVICE); + // WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + WifiInfo info = wifiManager.getConnectionInfo(); + if (info.getBSSID() != null) { + // 链接信号强度 + int strength = WifiManager.calculateSignalLevel(info.getRssi(), 5); + // 链接速度 + int speed = info.getLinkSpeed(); + // 链接速度单位 + String units = WifiInfo.LINK_SPEED_UNITS; + // Wifi源名称 + String ssid = info.getSSID(); + + int RSSI = info.getRssi(); + return RSSI; + } else { + return 0; + } + } + + public static String getWifiAlias(Context context) { + WifiManager wifiManager = (WifiManager) context.getSystemService(WIFI_SERVICE); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + if (wifiInfo.getSSID() == null) { + return "WiFi未连接"; + } else { + Log.e(TAG, "getWifiAlias: " + wifiInfo.getSSID()); + return wifiInfo.getSSID(); + } + } + + + public static String getBluetoothList() { + BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + if (bluetoothAdapter == null) { + return "没有蓝牙设备"; + } else { + if (!bluetoothAdapter.isEnabled())//判断蓝牙设备是否已开起 + { + return "蓝牙未开启"; +// //开起蓝牙设备 +// Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); +// context.startActivity(intent); + } else { + Set devices = bluetoothAdapter.getBondedDevices(); + StringBuilder stringBuilder = new StringBuilder(); + for (Iterator iterator = devices.iterator(); iterator.hasNext(); ) { + BluetoothDevice device = iterator.next(); + stringBuilder.append(device.getAlias()).append(";"); + } + Log.e(TAG, "getBluetoothList: " + stringBuilder.toString()); + return stringBuilder.toString(); + } + } + } + + } diff --git a/app/src/main/java/com/aoleyun/sn/utils/WiFiUtils.java b/app/src/main/java/com/aoleyun/sn/utils/WiFiUtils.java new file mode 100644 index 0000000..6a8ecb3 --- /dev/null +++ b/app/src/main/java/com/aoleyun/sn/utils/WiFiUtils.java @@ -0,0 +1,269 @@ +package com.aoleyun.sn.utils; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.net.wifi.ScanResult; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiManager; +import android.text.TextUtils; +import android.util.Log; + +import com.aoleyun.sn.bean.WiFiAlias; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import com.tencent.mmkv.MMKV; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +/** + * @author : fanhuitong + * e-mail : + * @date : 2021/10/25 10:20 + * desc : + * version: 1.0 + */ +public class WiFiUtils { + private static WiFiUtils sInstance; + private static WifiManager mWifiManager; + @SuppressLint("StaticFieldLeak") + private Context mContext; + private static String TAG = WiFiUtils.class.getSimpleName(); + + public WiFiUtils(Context context) { + this.mContext = context; + } + + public static void init(Context context) { + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + if (sInstance == null) { + Log.e(TAG, "init: "); + sInstance = new WiFiUtils(context); + } + } + + public static WiFiUtils getInstance() { + if (sInstance == null) { + throw new IllegalStateException("You must be init WiFiUtils first"); + } + return sInstance; + } + + /** + * wifi是否打开 + * + * @return + */ + public boolean isWifiEnable() { + boolean isEnable = false; + if (mWifiManager != null) { + if (mWifiManager.isWifiEnabled()) { + isEnable = true; + } + } + return isEnable; + } + + /** + * 打开WiFi + */ + public void openWifi() { + if (mWifiManager != null && !isWifiEnable()) { + mWifiManager.setWifiEnabled(true); + } + } + + /** + * 关闭WiFi + */ + public void closeWifi() { + if (mWifiManager != null && isWifiEnable()) { + mWifiManager.setWifiEnabled(false); + } + } + + /** + * 获取WiFi列表 + * + * @return + */ + public List getWifiList() { + List resultList = new ArrayList<>(); + if (mWifiManager != null && isWifiEnable()) { + resultList.addAll(mWifiManager.getScanResults()); + } + return resultList; + } + + + /** + * 有密码连接 + * + * @param ssid + * @param pws + */ + public void connectWifiPws(String ssid, String pws) { +// mWifiManager.disableNetwork(mWifiManager.getConnectionInfo().getNetworkId()); + mWifiManager.disconnect(); + int netId = mWifiManager.addNetwork(getWifiConfig(ssid, pws, true)); + mWifiManager.enableNetwork(netId, true); + mWifiManager.reconnect(); + } + + /** + * 无密码连接 + * + * @param ssid + */ + public void connectWifiNoPws(String ssid) { +// mWifiManager.disableNetwork(mWifiManager.getConnectionInfo().getNetworkId()); + int netId = mWifiManager.addNetwork(getWifiConfig(ssid, "", false)); + mWifiManager.enableNetwork(netId, true); + } + + /** + * wifi设置 + * + * @param ssid + * @param pws + * @param isHasPws + */ + private static WifiConfiguration getWifiConfig(String ssid, String pws, boolean isHasPws) { + WifiConfiguration config = new WifiConfiguration(); + config.allowedAuthAlgorithms.clear(); + config.allowedGroupCiphers.clear(); + config.allowedKeyManagement.clear(); + config.allowedPairwiseCiphers.clear(); + config.allowedProtocols.clear(); + config.SSID = "\"" + ssid + "\""; + + WifiConfiguration tempConfig = isExist(ssid); + if (tempConfig != null) { + mWifiManager.removeNetwork(tempConfig.networkId); + } + if (isHasPws) { + config.preSharedKey = "\"" + pws + "\""; + config.hiddenSSID = true; + config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + config.status = WifiConfiguration.Status.ENABLED; + } else { + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); + } + return config; + } + + /** + * 得到配置好的网络连接 + * + * @param ssid + * @return + */ + private static WifiConfiguration isExist(String ssid) { + List configs = mWifiManager.getConfiguredNetworks(); + for (WifiConfiguration config : configs) { + if (config.SSID.equals("\"" + ssid + "\"")) { + return config; + } + } + return null; + } + + + synchronized public static void saveWiFiPasswd(List passwd) { + String jsonString = MMKV.defaultMMKV().decodeString("WiFiPassword", ""); + Log.e(TAG, "saveWiFiPasswd: " + jsonString); + Gson gson = new Gson(); + Type listType = new TypeToken>() { + }.getType(); + List oldList = gson.fromJson(jsonString, listType); + comparedWiFiAlias(oldList, passwd); + } + + private static void comparedWiFiAlias(List oldWiFiAlias, List newWiFiAlias) { + Log.e("comparedWiFiAlias", "oldWiFiAlias: " + oldWiFiAlias); + Log.e("comparedWiFiAlias", "newWiFiAlias: " + newWiFiAlias); + if (newWiFiAlias == null || newWiFiAlias.size() == 0) { + if (oldWiFiAlias == null || oldWiFiAlias.size() == 0) { + return; + } + for (WiFiAlias wiFiAlias : oldWiFiAlias) { + WifiConfiguration tempConfig = isExist(wiFiAlias.getWifi_name()); + if (tempConfig != null) { + mWifiManager.removeNetwork(tempConfig.networkId); + } + } + } else if (oldWiFiAlias == null || oldWiFiAlias.size() == 0) { + for (WiFiAlias wiFiAlias : newWiFiAlias) { + addWiFiNetwork(wiFiAlias); + } + } else { + List removedWiFiAlias = new ArrayList<>(oldWiFiAlias); + List addedWiFiAlias = new ArrayList<>(); + List tempWiFiAlias = new ArrayList<>(); + for (WiFiAlias alias : newWiFiAlias) { + if (oldWiFiAlias.contains(alias)) { + //减少的 + removedWiFiAlias.remove(alias); + tempWiFiAlias.add(alias); + } else { + //增加的 + addedWiFiAlias.add(alias); + } + } + Log.e("comparedWiFiAlias", "removedWiFiAlias: " + removedWiFiAlias); + Log.e("comparedWiFiAlias", "addedWiFiAlias: " + addedWiFiAlias); + if (removedWiFiAlias.size() != 0) { + for (WiFiAlias alias : removedWiFiAlias) { + WifiConfiguration tempConfig = isExist(alias.getWifi_name()); + if (tempConfig != null) { + mWifiManager.removeNetwork(tempConfig.networkId); + Log.e("comparedWiFiAlias", "removedWiFiAlias: " + alias.getWifi_name()); + } + } + } + Log.e("comparedWiFiAlias", "tempWiFiAlias: " + tempWiFiAlias); + if (addedWiFiAlias.size() != 0) { + for (WiFiAlias alias : tempWiFiAlias) { + if (!wifiSaved(alias.getWifi_name())) { + addWiFiNetwork(alias); + } + } + for (WiFiAlias alias : addedWiFiAlias) { + addWiFiNetwork(alias); + } + } + } + mWifiManager.reconnect(); + } + + private static void addWiFiNetwork(WiFiAlias alias) { + int netId; + if (TextUtils.isEmpty(alias.getPassword())) { + netId = mWifiManager.addNetwork(getWifiConfig(alias.getWifi_name(), "", false)); + } else { + netId = mWifiManager.addNetwork(getWifiConfig(alias.getWifi_name(), alias.getPassword(), true)); + } + mWifiManager.enableNetwork(netId, true); + } + + + synchronized private static boolean wifiSaved(String ssid) { + // 获取已保存wifi配置链表 + List configs = mWifiManager.getConfiguredNetworks(); + boolean saved = false; + for (WifiConfiguration configuration : configs) { + if (ssid.equals(configuration.SSID)) { + saved = true; + } + } + return saved; + } +} diff --git a/app/src/main/java/com/aoleyun/sn/utils/XAPKUtils.java b/app/src/main/java/com/aoleyun/sn/utils/XAPKUtils.java index 8a8fb27..6b541ca 100644 --- a/app/src/main/java/com/aoleyun/sn/utils/XAPKUtils.java +++ b/app/src/main/java/com/aoleyun/sn/utils/XAPKUtils.java @@ -7,6 +7,7 @@ import android.content.pm.PackageInstaller; import android.os.Build; import android.os.Environment; import android.text.TextUtils; +import android.util.Log; import androidx.annotation.RequiresApi; @@ -75,7 +76,7 @@ public class XAPKUtils { if (file.exists() && file.isFile()) { upzipXAPK(file); } else { - Logutils.e(TAG, "installXAPK: " + "File not exists"); + Log.e(TAG, "installXAPK: " + "File not exists"); } } @@ -118,17 +119,17 @@ public class XAPKUtils { //获取OBB文件配置 JsonElement split_apks_em = jsonObject.get("split_apks"); readConfig(split_configs_em, expansions_em, split_apks_em); -// Logutils.e(TAG, "installXAPK: " + jsonString); +// Log.e(TAG, "installXAPK: " + jsonString); } @Override public void onError(Throwable e) { - Logutils.e(TAG, "onError: " + e.getMessage()); + Log.e(TAG, "onError: " + e.getMessage()); } @Override public void onComplete() { - Logutils.e(TAG, "onComplete: "); + Log.e(TAG, "onComplete: "); } }); } @@ -140,19 +141,19 @@ public class XAPKUtils { if (null != split_configs) { getSplitConfigs(split_configs.getAsJsonArray()); } else { - Logutils.e(TAG, "readConfig: " + "not found split_configs json data"); + Log.e(TAG, "readConfig: " + "not found split_configs json data"); } if (null != expansions) { readOBBConfig(expansions.getAsJsonArray()); } else { - Logutils.e(TAG, "readConfig: " + "not found expansions json data"); + Log.e(TAG, "readConfig: " + "not found expansions json data"); } if (null != split_apks) { getSplitApks(split_apks.getAsJsonArray()); } else { - Logutils.e(TAG, "readConfig: " + "not found split_apks json data"); + Log.e(TAG, "readConfig: " + "not found split_apks json data"); } @@ -177,7 +178,7 @@ public class XAPKUtils { // } // configStringBuilder.append(config); // } -// Logutils.e(TAG, "getSplitConfigs: " + configStringBuilder.toString()); +// Log.e(TAG, "getSplitConfigs: " + configStringBuilder.toString()); } /** @@ -187,7 +188,7 @@ public class XAPKUtils { */ private void readOBBConfig(JsonArray jsonArray) { if (TextUtils.isEmpty(unpackPath)) { - Logutils.e(TAG, "readOBBConfig: " + "unpack directory is empty"); + Log.e(TAG, "readOBBConfig: " + "unpack directory is empty"); return; } Type type = new TypeToken>() { @@ -197,9 +198,9 @@ public class XAPKUtils { if (null != expansionsList && expansionsList.size() > 0) { for (Expansions expansions : expansionsList) { if (copyObbFile(expansions)) { - Logutils.e(TAG, "readOBBConfig: " + "success"); + Log.e(TAG, "readOBBConfig: " + "success"); } else { - Logutils.e(TAG, "readOBBConfig: " + "copy oob File failure"); + Log.e(TAG, "readOBBConfig: " + "copy oob File failure"); } } } @@ -214,25 +215,25 @@ public class XAPKUtils { String install_path = expansions.getInstall_path(); if (TextUtils.isEmpty(file)) { - Logutils.e(TAG, "copyObbFile: " + "file path is empty"); + Log.e(TAG, "copyObbFile: " + "file path is empty"); return false; } else { File localFile = new File(unpackPath + File.separator + file); if (localFile.exists() && localFile.isFile()) { File installFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + install_path); - Logutils.e(TAG, "copyObbFile: " + "localFile: " + localFile.getAbsolutePath()); - Logutils.e(TAG, "copyObbFile: " + "installFile: " + installFile.getAbsolutePath()); + Log.e(TAG, "copyObbFile: " + "localFile: " + localFile.getAbsolutePath()); + Log.e(TAG, "copyObbFile: " + "installFile: " + installFile.getAbsolutePath()); try { Path path = Paths.get(localFile.getAbsolutePath()); Files.copy(path, new FileOutputStream(installFile)); return true; } catch (IOException e) { - Logutils.e(TAG, "copyObbFile: " + "IOException" + e.getMessage()); + Log.e(TAG, "copyObbFile: " + "IOException" + e.getMessage()); e.printStackTrace(); return false; } } else { - Logutils.e(TAG, "copyObbFile: " + "localFile: " + "File not exists"); + Log.e(TAG, "copyObbFile: " + "localFile: " + "File not exists"); return false; } @@ -276,14 +277,14 @@ public class XAPKUtils { filePath.add(unpackPath + File.separator + file); } } -// Logutils.e(TAG, "installxApk: " + filePath.toString()); +// Log.e(TAG, "installxApk: " + filePath.toString()); } else { //split_configs为空的情况 int position = getFileFromId(apkList, "base"); if (position != -1) { String file = apkList.get(position).getFile(); filePath.add(file); - Logutils.e(TAG, "installxApk: " + "base file = " + file); + Log.e(TAG, "installxApk: " + "base file = " + file); } } @@ -353,7 +354,7 @@ public class XAPKUtils { session.commit(pendingIntent.getIntentSender()); } catch (IOException e) { e.printStackTrace(); - Logutils.e(TAG, "install: " + e.getMessage()); + Log.e(TAG, "install: " + e.getMessage()); } } @@ -365,7 +366,7 @@ public class XAPKUtils { sessionId = packageInstaller.createSession(sessionParams); } catch (IOException e) { e.printStackTrace(); - Logutils.e(TAG, "createSession: " + e.getMessage()); + Log.e(TAG, "createSession: " + e.getMessage()); } return sessionId; } @@ -398,9 +399,9 @@ public class XAPKUtils { } } catch (IOException e) { e.printStackTrace(); - Logutils.e("fht", "copyApkFile" + e.getMessage()); + Log.e("fht", "copyApkFile" + e.getMessage()); } - Logutils.e("fht", "copyApkFile" + "success = " + success); + Log.e("fht", "copyApkFile" + "success = " + success); return success; } } diff --git a/app/src/main/res/drawable-hdpi/head.png b/app/src/main/res/drawable-hdpi/head.png new file mode 100644 index 0000000..cd65693 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/head.png differ diff --git a/app/src/main/res/drawable-hdpi/logo.png b/app/src/main/res/drawable-hdpi/logo.png index 279bbcb..398bfe8 100644 Binary files a/app/src/main/res/drawable-hdpi/logo.png and b/app/src/main/res/drawable-hdpi/logo.png differ diff --git a/app/src/main/res/drawable-hdpi/main_logo.png b/app/src/main/res/drawable-hdpi/main_logo.png index 56fbd6b..398bfe8 100644 Binary files a/app/src/main/res/drawable-hdpi/main_logo.png and b/app/src/main/res/drawable-hdpi/main_logo.png differ diff --git a/app/src/main/res/drawable-hdpi/successful.png b/app/src/main/res/drawable-hdpi/succeed.png similarity index 100% rename from app/src/main/res/drawable-hdpi/successful.png rename to app/src/main/res/drawable-hdpi/succeed.png diff --git a/app/src/main/res/layout-land/activity_home.xml b/app/src/main/res/layout-land/activity_home.xml index 5456745..c1c4403 100644 --- a/app/src/main/res/layout-land/activity_home.xml +++ b/app/src/main/res/layout-land/activity_home.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" - tools:context="com.aoleyun.sn.activity.HomeActivity"> + tools:context="com.aoleyun.sn.activity.SplashActivity"> - - diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index b04cba8..2e537cd 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -86,11 +86,11 @@ @@ -241,7 +241,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:text="班级" + android:text="部门" android:textColor="#000000" android:textSize="@dimen/sp_12" app:layout_constraintBottom_toBottomOf="parent" @@ -282,7 +282,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:text="学号" + android:text="工号" android:textColor="#000000" android:textSize="@dimen/sp_12" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/layout-port/activity_home.xml b/app/src/main/res/layout-port/activity_home.xml index ce6fbe2..f27ef97 100644 --- a/app/src/main/res/layout-port/activity_home.xml +++ b/app/src/main/res/layout-port/activity_home.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" - tools:context="com.aoleyun.sn.activity.HomeActivity"> + tools:context="com.aoleyun.sn.activity.SplashActivity"> - - diff --git a/app/src/main/res/layout-port/activity_main.xml b/app/src/main/res/layout-port/activity_main.xml index c348c91..994249d 100644 --- a/app/src/main/res/layout-port/activity_main.xml +++ b/app/src/main/res/layout-port/activity_main.xml @@ -72,11 +72,11 @@ @@ -212,7 +212,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:text="班级" + android:text="部门" android:textColor="#000000" android:textSize="@dimen/sp_12" app:layout_constraintBottom_toBottomOf="parent" @@ -253,7 +253,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:text="学号" + android:text="工号" android:textColor="#000000" android:textSize="@dimen/sp_12" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index bde29d6..dc1a2f2 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -52,4 +52,6 @@ #3e76f6 #494949 + #CD000000 + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9bc7ade..a483793 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -7,6 +7,8 @@ @color/colorPrimaryDark @color/colorAccent @color/colorPrimary + true + ?attr/colorPrimary - - - diff --git a/build.gradle b/build.gradle index 3b2f1c9..92d9aa0 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ allprojects { } gradle.projectsEvaluated { tasks.withType(JavaCompile) { - options.compilerArgs.add('-Xbootclasspath/p:app/src/main/libs/classes.jar') + options.compilerArgs.add('-Xbootclasspath/p:libs/framework.jar') } } }