From e41becbdb0d76127e82822a81202d31b29bc33af Mon Sep 17 00:00:00 2001 From: fanhuitong <981964879@qq.com> Date: Thu, 30 Sep 2021 18:28:44 +0800 Subject: [PATCH] version:1.7.0 fix:0918 add: --- app/build.gradle | 13 +- app/src/main/AndroidManifest.xml | 6 +- .../info/sn/activity/main/MainActivity.java | 58 ++- .../info/sn/activity/main/MainContact.java | 6 + .../info/sn/activity/main/MainPresenter.java | 76 +++- .../selectegrade/SelecteGradeActivity.java | 20 +- .../java/com/info/sn/base/BaseActivity.java | 3 +- .../com/info/sn/base/BaseApplication.java | 17 +- .../com/info/sn/bean/zuoye/AppUploadInfo.java | 20 + .../com/info/sn/bean/zuoye/BaseResponse.java | 12 +- .../info/sn/jpush/TagAliasOperatorHelper.java | 7 + .../info/sn/manager/NetInterfaceManager.java | 29 +- .../com/info/sn/network/HTTPInterface.java | 21 +- .../java/com/info/sn/network/UrlAddress.java | 3 +- .../com/info/sn/network/api/GetBatchApi.java | 16 + .../java/com/info/sn/network/api/SettingKT.kt | 15 - .../info/sn/network/api/UpdateAdminSn.java | 3 +- .../com/info/sn/receiver/MyJPushReceiver.java | 38 +- .../java/com/info/sn/service/MainService.java | 52 ++- .../com/info/sn/service/ManagerService.java | 2 +- .../main/java/com/info/sn/utils/ApkUtils.java | 27 +- .../main/java/com/info/sn/utils/JGYUtils.java | 58 ++- .../main/java/com/info/sn/utils/SPUtils.java | 18 +- .../java/com/info/sn/utils/StatusBarUtil.java | 344 ++++++++++++++++++ .../java/com/info/sn/utils/SystemUtils.java | 24 ++ .../main/java/com/info/sn/utils/URLUtils.java | 2 + build.gradle | 4 +- 27 files changed, 786 insertions(+), 108 deletions(-) create mode 100644 app/src/main/java/com/info/sn/network/api/GetBatchApi.java delete mode 100644 app/src/main/java/com/info/sn/network/api/SettingKT.kt create mode 100644 app/src/main/java/com/info/sn/utils/StatusBarUtil.java create mode 100644 app/src/main/java/com/info/sn/utils/SystemUtils.java diff --git a/app/build.gradle b/app/build.gradle index 1a9e0bb..9e14206 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,4 @@ apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' -apply plugin: 'kotlin-kapt' def appName() { return "SnInfo" @@ -18,8 +15,8 @@ android { applicationId "com.info.sn" minSdkVersion 24 targetSdkVersion 29 - versionCode 70 - versionName "1.7.0" + versionCode 73 + versionName "1.7.3" multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ndk { @@ -166,7 +163,7 @@ dependencies { // implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.legacy:legacy-support-v4:1.0.0' compileOnly files('src/main/libs/classes.jar') - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.3.1' //implementation 'com.android.support:multidex:1.0.3' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' @@ -201,7 +198,7 @@ dependencies { //implementation 'com.blankj:utilcode:1.26.0' implementation 'com.arialyy.aria:core:3.8.15' - kapt 'com.arialyy.aria:compiler:3.8.15' + annotationProcessor 'com.arialyy.aria:compiler:3.8.15' implementation "org.java-websocket:Java-WebSocket:1.4.1" @@ -222,7 +219,7 @@ dependencies { implementation 'com.jakewharton:butterknife:10.2.1' // If you are using Kotlin, replace annotationProcessor with kapt. // annotationProcessor rootProject.ext.dependencies["butterknife-compiler"] - kapt 'com.jakewharton:butterknife-compiler:10.2.1' + annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d8e1bc1..bdc4110 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,11 +19,12 @@ - + + - + @@ -57,6 +58,7 @@ android:label="@string/app_name" android:networkSecurityConfig="@xml/network" android:roundIcon="@mipmap/ic_launcher" + android:requestLegacyExternalStorage="true" android:supportsRtl="true" android:theme="@style/AppTheme"> { @@ -336,21 +346,8 @@ public class MainActivity extends BaseActivity implements MainContact.MainView, ToastUtil.debugShow("RegId:" + rid); Log.e("RegId", rid); } - setAlias(); } - private void setAlias() { - String alias = Utils.getSerial(); - int action = ACTION_SET; - TagAliasBean tagAliasBean = new TagAliasBean(); - tagAliasBean.action = action; - TagAliasOperatorHelper.sequence++; - tagAliasBean.alias = alias; - tagAliasBean.isAliasAction = true; - TagAliasOperatorHelper.getInstance().handleAction(MainActivity.this, TagAliasOperatorHelper.sequence, tagAliasBean); - } - - private long mExitTime; private void exit() { @@ -371,6 +368,8 @@ public class MainActivity extends BaseActivity implements MainContact.MainView, tv_grade.setText(grade); int statu = (int) SPUtils.get(this, Configs.isLogined, 0); switch (statu) { + default: + break; case 0: // tv_note.setText("设备未绑定"); break; @@ -590,6 +589,39 @@ public class MainActivity extends BaseActivity implements MainContact.MainView, } } + @Override + public void setAlias() { + setJpushAlias(); + Log.e(TAG, "setAlias: " + "finish"); + mPresenter.getBatch(); + } + + private void setJpushAlias() { + String alias = Utils.getSerial(); + TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean(); + tagAliasBean.action = ACTION_SET; + TagAliasOperatorHelper.sequence++; + tagAliasBean.alias = alias; + tagAliasBean.isAliasAction = true; + TagAliasOperatorHelper.getInstance().handleAction(this, TagAliasOperatorHelper.sequence, tagAliasBean); + } + + private void setTag(Set set) { + TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean(); + tagAliasBean.action = ACTION_SET; + TagAliasOperatorHelper.sequence++; + tagAliasBean.tags = set; + tagAliasBean.isAliasAction = false; + TagAliasOperatorHelper.getInstance().handleAction(this, TagAliasOperatorHelper.sequence, tagAliasBean); + } + + @Override + public void setBatch(String batch) { + HashSet hashSet = new HashSet(); + hashSet.add(batch); + setTag(hashSet); + } + private void toGankaoApp() { String gankaoUID = (String) SPUtils.get(MainActivity.this, "gankaoUID", ""); if (TextUtils.isEmpty(gankaoUID)) { diff --git a/app/src/main/java/com/info/sn/activity/main/MainContact.java b/app/src/main/java/com/info/sn/activity/main/MainContact.java index b9a93e7..658c424 100644 --- a/app/src/main/java/com/info/sn/activity/main/MainContact.java +++ b/app/src/main/java/com/info/sn/activity/main/MainContact.java @@ -19,6 +19,8 @@ public class MainContact { void setAvailableProduct(List availableProductList, String gankaoUID); void activeUserFinish(int code); + void setAlias(); + void setBatch(String batch); void setQRCode(Bitmap bitmap); void setSnInfo(BaseResponse response); void setSnUid(JSONObject jsonObject); @@ -44,6 +46,10 @@ public class MainContact { void queryAvailableProduct(String gankaoUID); void activeUser(AvailableProduct product, String gankaoUID); + //设置别名 + void setAlias(); + //获取班级id + void getBatch(); //获取二维码 void getQRCode(); //获取设备信息 diff --git a/app/src/main/java/com/info/sn/activity/main/MainPresenter.java b/app/src/main/java/com/info/sn/activity/main/MainPresenter.java index 341db17..e9842fa 100644 --- a/app/src/main/java/com/info/sn/activity/main/MainPresenter.java +++ b/app/src/main/java/com/info/sn/activity/main/MainPresenter.java @@ -33,10 +33,12 @@ import com.info.sn.bean.zuoye.UserAvatarInfo; import com.info.sn.bean.zuoye.UserInfo; import com.info.sn.config.Configs; import com.info.sn.config.Scheme; +import com.info.sn.jpush.TagAliasOperatorHelper; import com.info.sn.manager.AmapManager; import com.info.sn.manager.ControlManager; import com.info.sn.manager.NetInterfaceManager; import com.info.sn.network.HTTPInterface; +import com.info.sn.service.MainService; import com.info.sn.service.ManagerService; import com.info.sn.service.RemoteService; import com.info.sn.utils.ApkUtils; @@ -58,12 +60,16 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Set; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_SET; +import static com.info.sn.jpush.TagAliasOperatorHelper.sequence; + /** * @author jgy02 */ @@ -359,8 +365,61 @@ public class MainPresenter implements MainContact.Presenter { }); } + @Override + public void setAlias() { + mView.setAlias(); + } -// private void sendUid(AvailableProduct product, String gankaoUID) { + @Override + public void getBatch() { + NetInterfaceManager.getInstance() + .getBatchApiControl() + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + Log.e("getBatch", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse baseResponse) { + Log.e("getBatch", "onNext: "); + if (baseResponse.code == 200) { + Gson gson = new Gson(); + JsonObject jsonObject = JsonParser.parseString(gson.toJson(baseResponse.data)).getAsJsonObject(); + int batch_id = jsonObject.get("batch_id").getAsInt(); + Log.e("getBatch", "onNext: " + batch_id); + mView.setBatch(String.valueOf(batch_id)); + } else { + Log.e("getBatch", "onNext: " + baseResponse.msg); + mView.setBatch(""); + } + } + + @Override + public void onError(Throwable e) { + Log.e("getBatch", "onError: " + e.getMessage()); + mView.setBatch(""); + onComplete(); + } + + @Override + public void onComplete() { + Log.e("getBatch", "onComplete: "); + } + }); + } + + + private void setTag(Set set) { + TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean(); + tagAliasBean.action = ACTION_SET; + TagAliasOperatorHelper.sequence++; + tagAliasBean.tags = set; + tagAliasBean.isAliasAction = false; + TagAliasOperatorHelper.getInstance().handleAction(mContext, TagAliasOperatorHelper.sequence, tagAliasBean); + } + + // private void sendUid(AvailableProduct product, String gankaoUID) { // NetInterfaceManager.getInstance() // .getSaveSnUidApiControl() // .saveSnUid(Utils.getSerial(), gankaoUID, System.currentTimeMillis() / 1000, product.getDuration()) @@ -436,7 +495,7 @@ public class MainPresenter implements MainContact.Presenter { } String gankaoUID = Settings.System.getString(mContext.getContentResolver(), "gankaoUID"); String avatar = Settings.System.getString(mContext.getContentResolver(), "UserInfo_avatar"); - int gread = (int) SPUtils.get(mContext,"int_grade",0); + int gread = (int) SPUtils.get(mContext, "int_grade", 0); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("username", userInfo.getSn_name()); @@ -480,7 +539,7 @@ public class MainPresenter implements MainContact.Presenter { @Override public void onNext(BaseResponse baseResponse) { - Log.e("getSnUid", "onNext: "+JSONObject.toJSONString(baseResponse)); + Log.e("getSnUid", "onNext: " + JSONObject.toJSONString(baseResponse)); int code = baseResponse.code; if (code == 200) { Settings.System.putInt(mContext.getContentResolver(), MainActivity.activation, 1); @@ -655,9 +714,12 @@ public class MainPresenter implements MainContact.Presenter { allPkgSet.add(pkg.getApp_package()); } String allPkgString = String.join(",", allPkgSet); + Settings.System.putString(mContext.getContentResolver(), "only_jgy_shortcut_list", allPkgString); + Log.e(TAG + "getAllApp", "onNext: " + allPkgString); ApkUtils.writeAppPackageList(mContext, allPkgString); HTTPInterface.getAppStart(mContext, appInfoList); } + JGYUtils.getInstance().deleteOtherApp(); } } @@ -757,16 +819,16 @@ public class MainPresenter implements MainContact.Presenter { @Override public void getSystemSettings() { NetInterfaceManager.getInstance() - .getsettingKTControl() + .getsettingControl() .compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY)) - .subscribe(new Observer>() { + .subscribe(new Observer() { @Override public void onSubscribe(Disposable d) { Log.e(TAG + "getSystemSettings", "onSubscribe: "); } @Override - public void onNext(BaseResponse systemSettingsBaseResponse) { + public void onNext(BaseResponse systemSettingsBaseResponse) { Log.e(TAG + "getSystemSettings", "onNext: "); SPUtils.put(mContext, "is_first_connection", 0); int code = systemSettingsBaseResponse.code; @@ -921,7 +983,7 @@ public class MainPresenter implements MainContact.Presenter { } else { JGYUtils.putString(mContext.getContentResolver(), "qch_webblack_url", " "); } - }else { + } else { JGYUtils.putString(mContext.getContentResolver(), "DeselectBrowserArray", " "); JGYUtils.putString(mContext.getContentResolver(), "qch_webblack_url", " "); } diff --git a/app/src/main/java/com/info/sn/activity/selectegrade/SelecteGradeActivity.java b/app/src/main/java/com/info/sn/activity/selectegrade/SelecteGradeActivity.java index fb23335..d64fcb7 100644 --- a/app/src/main/java/com/info/sn/activity/selectegrade/SelecteGradeActivity.java +++ b/app/src/main/java/com/info/sn/activity/selectegrade/SelecteGradeActivity.java @@ -26,8 +26,12 @@ import com.info.sn.utils.SPUtils; import com.info.sn.utils.ToastUtil; import com.info.sn.utils.Utils; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.TimeZone; import butterknife.BindView; import butterknife.ButterKnife; @@ -328,7 +332,7 @@ public class SelecteGradeActivity extends BaseActivity implements SelecteGradeCo JSONObject jsonObject = new JSONObject(); jsonObject.put("card_info", powerUser.getAuthorityName()); jsonObject.put("grade", powerUser.getGrade()); - jsonObject.put("activate_time", powerUser.getAuthorizationDate()); + jsonObject.put("activate_time", getTime(powerUser.getAuthorizationDate())); jsonObject.put("user_power_id", powerUser.getAuthorizationNumber()); jsonObject.put("specification_id", mAvailableProductHashMap.get(powerUser.getAuthorityName())); jsonArray.add(jsonObject); @@ -338,6 +342,20 @@ public class SelecteGradeActivity extends BaseActivity implements SelecteGradeCo mPresenter.sendUid(jsonArray.toJSONString(), grade); } + private String getTime(String timestamp) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'"); + sdf.setTimeZone(TimeZone.getTimeZone("GMT+00")); + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + Date date = sdf.parse(timestamp);//拿到Date对象. + String str = sdf2.format(date); + return str; + } catch (ParseException e) { + e.printStackTrace(); + return timestamp; + } + } + @Override public void sendUidFinish(int code) { if (code == 200) { diff --git a/app/src/main/java/com/info/sn/base/BaseActivity.java b/app/src/main/java/com/info/sn/base/BaseActivity.java index a676920..24d066f 100644 --- a/app/src/main/java/com/info/sn/base/BaseActivity.java +++ b/app/src/main/java/com/info/sn/base/BaseActivity.java @@ -3,8 +3,8 @@ package com.info.sn.base; import android.os.Bundle; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; +import com.info.sn.utils.StatusBarUtil; import com.trello.rxlifecycle2.components.support.RxAppCompatActivity; @@ -12,6 +12,7 @@ public abstract class BaseActivity extends RxAppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + StatusBarUtil.init(this); setContentView(this.getLayoutId()); initView(); initData(); diff --git a/app/src/main/java/com/info/sn/base/BaseApplication.java b/app/src/main/java/com/info/sn/base/BaseApplication.java index 8107d82..a4b1b17 100644 --- a/app/src/main/java/com/info/sn/base/BaseApplication.java +++ b/app/src/main/java/com/info/sn/base/BaseApplication.java @@ -3,6 +3,7 @@ package com.info.sn.base; import android.app.Application; import android.os.Handler; import android.os.Looper; +import android.os.Process; import android.util.Log; import com.arialyy.aria.core.Aria; @@ -13,21 +14,31 @@ import com.info.sn.manager.NetInterfaceManager; import com.info.sn.manager.ControlManager; import com.info.sn.manager.DeviceManager; import com.info.sn.utils.JGYUtils; +import com.info.sn.utils.SystemUtils; + +import cn.jpush.android.api.JPushInterface; public class BaseApplication extends Application { @Override public void onCreate() { super.onCreate(); - if (!getPackageName().equals(ProcessUtils.getCurrentProcessName())) { - return; +// if (!getPackageName().equals(ProcessUtils.getCurrentProcessName())) { +// return; +// } + if (SystemUtils.isMainProcessName(this, Process.myPid())) { + //非主进程不初始化 + utilsInint(); } - utilsInint(); } private void utilsInint() { if (!BuildConfig.DEBUG) { catchException(); } + // 设置开启日志,发布时请关闭日志 + JPushInterface.setDebugMode(true); + JPushInterface.requestPermission(this); + Aria.init(this); Aria.download(this).resumeAllTask(); JGYUtils.init(this); diff --git a/app/src/main/java/com/info/sn/bean/zuoye/AppUploadInfo.java b/app/src/main/java/com/info/sn/bean/zuoye/AppUploadInfo.java index a44ce73..fb4add6 100644 --- a/app/src/main/java/com/info/sn/bean/zuoye/AppUploadInfo.java +++ b/app/src/main/java/com/info/sn/bean/zuoye/AppUploadInfo.java @@ -3,8 +3,12 @@ package com.info.sn.bean.zuoye; import java.io.Serializable; public class AppUploadInfo implements Serializable { + private static final long serialVersionUID = -6920148363520647811L; + String app_package; long app_version_code; + long firstInstallTime; + long lastUpdateTime; public String getApp_package() { return app_package; @@ -21,4 +25,20 @@ public class AppUploadInfo implements Serializable { public void setApp_version_code(long app_version_code) { this.app_version_code = app_version_code; } + + public long getFirstInstallTime() { + return firstInstallTime; + } + + public void setFirstInstallTime(long firstInstallTime) { + this.firstInstallTime = firstInstallTime; + } + + public long getLastUpdateTime() { + return lastUpdateTime; + } + + public void setLastUpdateTime(long lastUpdateTime) { + this.lastUpdateTime = lastUpdateTime; + } } diff --git a/app/src/main/java/com/info/sn/bean/zuoye/BaseResponse.java b/app/src/main/java/com/info/sn/bean/zuoye/BaseResponse.java index f711954..8c54587 100644 --- a/app/src/main/java/com/info/sn/bean/zuoye/BaseResponse.java +++ b/app/src/main/java/com/info/sn/bean/zuoye/BaseResponse.java @@ -2,6 +2,10 @@ package com.info.sn.bean.zuoye; import androidx.annotation.NonNull; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + import java.io.Serializable; @@ -16,10 +20,8 @@ public class BaseResponse implements Serializable { @NonNull @Override public String toString() { - return "{\n" +// - "\tcode=" + code + "\n" +// - "\tmsg='" + msg + "\'\n" +// - "\tdata=" + data + "\n" +// - '}'; + Gson gson = new Gson(); + JsonObject jsonObject = JsonParser.parseString(gson.toJson(this)).getAsJsonObject(); + return jsonObject.toString(); } } \ No newline at end of file diff --git a/app/src/main/java/com/info/sn/jpush/TagAliasOperatorHelper.java b/app/src/main/java/com/info/sn/jpush/TagAliasOperatorHelper.java index 20051e2..c5f5509 100644 --- a/app/src/main/java/com/info/sn/jpush/TagAliasOperatorHelper.java +++ b/app/src/main/java/com/info/sn/jpush/TagAliasOperatorHelper.java @@ -3,8 +3,11 @@ package com.info.sn.jpush; import android.content.Context; import android.os.Handler; import android.os.Message; +import android.util.Log; import android.util.SparseArray; +import com.info.sn.utils.ToastUtil; + import java.util.Locale; import java.util.Set; @@ -239,6 +242,8 @@ public class TagAliasOperatorHelper { setActionCache.remove(sequence); String logs = getActionStr(tagAliasBean.action)+" tags success"; Logger.i(TAG,logs); + Log.e(TAG,"Tag绑定成功: " + jPushMessage.getTags()); + ToastUtil.debugShow("Tag绑定成功: " + jPushMessage.getTags()); ExampleUtil.showToast(logs, context); }else{ String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags"; @@ -292,6 +297,8 @@ public class TagAliasOperatorHelper { setActionCache.remove(sequence); String logs = getActionStr(tagAliasBean.action)+" alias success"; Logger.i(TAG,logs); + Log.e(TAG,"Alias绑定成功: "+jPushMessage.getAlias()); + ToastUtil.debugShow("Alias绑定成功: "+jPushMessage.getAlias()); ExampleUtil.showToast(logs, context); }else{ String logs = "Failed to " + getActionStr(tagAliasBean.action)+" alias, errorCode:" + jPushMessage.getErrorCode(); diff --git a/app/src/main/java/com/info/sn/manager/NetInterfaceManager.java b/app/src/main/java/com/info/sn/manager/NetInterfaceManager.java index e56fa1f..173231b 100644 --- a/app/src/main/java/com/info/sn/manager/NetInterfaceManager.java +++ b/app/src/main/java/com/info/sn/manager/NetInterfaceManager.java @@ -7,28 +7,23 @@ import android.os.Environment; import com.info.sn.bean.zuoye.AppInfo; import com.info.sn.bean.zuoye.AppStart; import com.info.sn.bean.zuoye.BaseResponse; -import com.info.sn.bean.zuoye.SystemSettings; import com.info.sn.bean.zuoye.UserAvatarInfo; import com.info.sn.bean.zuoye.UserInfo; import com.info.sn.network.UrlAddress; import com.info.sn.network.api.APPJump; -import com.info.sn.network.api.gankao.ActiveUserApi; import com.info.sn.network.api.AddAppInstall; import com.info.sn.network.api.AppUsedApi; import com.info.sn.network.api.BindDevices; import com.info.sn.network.api.Browser; -import com.info.sn.network.api.gankao.CancelUserPowerApi; -import com.info.sn.network.api.gankao.CreateUserApi; -import com.info.sn.network.api.ForceInstall; import com.info.sn.network.api.BrowserLabel; +import com.info.sn.network.api.ForceInstall; +import com.info.sn.network.api.GetBatchApi; import com.info.sn.network.api.GetGuideApi; import com.info.sn.network.api.GetSnUidApi; import com.info.sn.network.api.NewestAppUpdate; import com.info.sn.network.api.QRCodeApi; import com.info.sn.network.api.QueryAllApp; import com.info.sn.network.api.QueryAppInside; -import com.info.sn.network.api.gankao.QueryPowerUserListApi; -import com.info.sn.network.api.gankao.QueryProductApi; import com.info.sn.network.api.QuerySnAppStart; import com.info.sn.network.api.RunningApp; import com.info.sn.network.api.SNInfoApi; @@ -36,11 +31,15 @@ import com.info.sn.network.api.SaveSnUidApi; import com.info.sn.network.api.ScreenLock; import com.info.sn.network.api.ScreenState; import com.info.sn.network.api.Setting; -import com.info.sn.network.api.SettingKT; import com.info.sn.network.api.TimeControl; import com.info.sn.network.api.UpdateAdminSn; import com.info.sn.network.api.UploadScreenshot; import com.info.sn.network.api.UserInfoControl; +import com.info.sn.network.api.gankao.ActiveUserApi; +import com.info.sn.network.api.gankao.CancelUserPowerApi; +import com.info.sn.network.api.gankao.CreateUserApi; +import com.info.sn.network.api.gankao.QueryPowerUserListApi; +import com.info.sn.network.api.gankao.QueryProductApi; import com.info.sn.network.api.gankao.UpgradeUserPowerApi; import com.info.sn.network.api.gankao.UserProductsApi; import com.info.sn.utils.Utils; @@ -135,13 +134,6 @@ public class NetInterfaceManager { .observeOn(AndroidSchedulers.mainThread()); } - public Observable> getsettingKTControl() { - return mRetrofit.create(SettingKT.class) - .getSetting(Utils.getSerial()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()); - } - public Observable>> getForceInstallControl() { return mRetrofit.create(ForceInstall.class) .getForceInstall(Utils.getSerial()) @@ -267,6 +259,13 @@ public class NetInterfaceManager { .observeOn(AndroidSchedulers.mainThread()); } + public Observable getBatchApiControl() { + return mRetrofit.create(GetBatchApi.class) + .getBatch(Utils.getSerial()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + //赶考 public CreateUserApi getCreateUserControl() { diff --git a/app/src/main/java/com/info/sn/network/HTTPInterface.java b/app/src/main/java/com/info/sn/network/HTTPInterface.java index f564b77..15ff33c 100644 --- a/app/src/main/java/com/info/sn/network/HTTPInterface.java +++ b/app/src/main/java/com/info/sn/network/HTTPInterface.java @@ -42,6 +42,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import cn.jpush.android.api.JPushInterface; import io.reactivex.Observable; import io.reactivex.ObservableOnSubscribe; import io.reactivex.Observer; @@ -58,7 +59,7 @@ public class HTTPInterface { // Log.e("SendAppInstall", installOrRemove + "return: " + packages); // return; // } - Log.e(TAG, "SendAppInstall: " + jsonString); +// Log.e(TAG, "SendAppInstall: " + jsonString); NetInterfaceManager.getInstance() .getAddAppInstallControl() .installorRemove( @@ -132,7 +133,7 @@ public class HTTPInterface { } else { JGYUtils.putString(context.getContentResolver(), "qch_webblack_url", " "); } - }else { + } else { JGYUtils.putString(context.getContentResolver(), "DeselectBrowserArray", " "); JGYUtils.putString(context.getContentResolver(), "qch_webblack_url", " "); } @@ -556,11 +557,21 @@ public class HTTPInterface { String machine = Utils.getMachine(context); String hardware = Utils.getHardware(context); Log.e(TAG, "updateAdminInfo: getHardware = " + hardware); + JSONObject softwareJson = new JSONObject(); + softwareJson.put("appstore_version", ApkUtils.getAPPVersionName(context, "com.appstore.uiui")); + softwareJson.put("updatetools_version", ApkUtils.getAPPVersionName(context, "com.uiuios.updatetools")); + softwareJson.put("info_version", ApkUtils.getAPPVersionName(context, "com.info.sn")); + softwareJson.put("jiaoguanyi_version", ApkUtils.getAPPVersionName(context, "com.gankao.gkwxhd")); + softwareJson.put("gankao_version", ApkUtils.getAPPVersionName(context, "com.jiaoguanyi.os")); + softwareJson.put("learning_version", ApkUtils.getAPPVersionName(context, "com.info.learning")); + softwareJson.put("chat_version", ApkUtils.getAPPVersionName(context, "com.info.chat")); + softwareJson.put("jpush_id", JPushInterface.getRegistrationID(context)); UpdateAdminSn updateAdminSn = NetInterfaceManager.getInstance().getUpdateAdminSnControl(); updateAdminSn.sendAdminSn(Utils.getSerial(), jsonObject.toJSONString(), machine, - hardware + hardware, + softwareJson.toJSONString() ).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer() { @@ -611,7 +622,7 @@ public class HTTPInterface { allAppPkg.add(appInfo.getApp_package()); } String allPkgSet = String.join(",", allAppPkg); - SPUtils.put(context, "only_jgy_shortcut_list", allPkgSet); + Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", allPkgSet); ApkUtils.writeAppPackageList(context, allPkgSet); HTTPInterface.getAppStart(context, appInfoList); } else { @@ -997,6 +1008,8 @@ public class HTTPInterface { } else { uploadInfo.setApp_version_code(info.versionCode); } + uploadInfo.setFirstInstallTime(info.firstInstallTime / 1000); + uploadInfo.setLastUpdateTime(info.lastUpdateTime / 1000); uploadInfos.add(uploadInfo); } emitter.onNext(uploadInfos); diff --git a/app/src/main/java/com/info/sn/network/UrlAddress.java b/app/src/main/java/com/info/sn/network/UrlAddress.java index 17af6e7..a681c1a 100644 --- a/app/src/main/java/com/info/sn/network/UrlAddress.java +++ b/app/src/main/java/com/info/sn/network/UrlAddress.java @@ -3,6 +3,8 @@ package com.info.sn.network; public class UrlAddress { //主页接口 public static final String ROOT_URL = "http://homework.uiuios.com/android/"; + //获取班级ID + public static final String GET_BATCH = ROOT_URL + "sn/getBatch"; //设备信息接口 public static final String SNINFO = ROOT_URL + "sn/getSnInfo"; //发送app信息 @@ -59,7 +61,6 @@ public class UrlAddress { public static final String GET_OPERATION_GUIDE = "file/getFiles"; - //赶考 public static final String GANKAN_ROOT_URL = "https://www.gankao.com/api/service/"; //创建/查询用户 diff --git a/app/src/main/java/com/info/sn/network/api/GetBatchApi.java b/app/src/main/java/com/info/sn/network/api/GetBatchApi.java new file mode 100644 index 0000000..2869f55 --- /dev/null +++ b/app/src/main/java/com/info/sn/network/api/GetBatchApi.java @@ -0,0 +1,16 @@ +package com.info.sn.network.api; + +import com.info.sn.bean.zuoye.BaseResponse; +import com.info.sn.network.UrlAddress; + +import io.reactivex.Observable; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface GetBatchApi { + @GET(UrlAddress.GET_BATCH) + Observable getBatch( + @Query("sn") String sn + ); + +} diff --git a/app/src/main/java/com/info/sn/network/api/SettingKT.kt b/app/src/main/java/com/info/sn/network/api/SettingKT.kt deleted file mode 100644 index 455b4ae..0000000 --- a/app/src/main/java/com/info/sn/network/api/SettingKT.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.info.sn.network.api - -import com.info.sn.bean.zuoye.BaseResponse -import com.info.sn.bean.zuoye.SystemSettings -import com.info.sn.network.UrlAddress -import io.reactivex.Observable -import retrofit2.http.GET -import retrofit2.http.Query - -interface SettingKT { - @GET(UrlAddress.GET_SETTINGS) - fun getSetting( - @Query("sn") sn: String - ): Observable> -} \ No newline at end of file diff --git a/app/src/main/java/com/info/sn/network/api/UpdateAdminSn.java b/app/src/main/java/com/info/sn/network/api/UpdateAdminSn.java index 255ca2c..c10250e 100644 --- a/app/src/main/java/com/info/sn/network/api/UpdateAdminSn.java +++ b/app/src/main/java/com/info/sn/network/api/UpdateAdminSn.java @@ -15,6 +15,7 @@ public interface UpdateAdminSn { @Field("sn") String sn, @Field("address") String address, @Field("machine") String machine, - @Field("hardware") String hardware + @Field("hardware") String hardware, + @Field("software") String software ); } diff --git a/app/src/main/java/com/info/sn/receiver/MyJPushReceiver.java b/app/src/main/java/com/info/sn/receiver/MyJPushReceiver.java index 421b22e..c10b30a 100644 --- a/app/src/main/java/com/info/sn/receiver/MyJPushReceiver.java +++ b/app/src/main/java/com/info/sn/receiver/MyJPushReceiver.java @@ -43,6 +43,7 @@ import com.info.sn.network.HTTPInterface; import com.info.sn.manager.NetInterfaceManager; import com.info.sn.network.api.BindDevices; import com.info.sn.network.api.UploadScreenshot; +import com.info.sn.service.MainService; import com.info.sn.service.ManagerService; import com.info.sn.utils.ApkUtils; import com.info.sn.utils.CacheUtils; @@ -168,6 +169,9 @@ public class MyJPushReceiver extends BroadcastReceiver { private static final String JIGUANG_CANCEL_COMBO = "42"; //升级套餐 private static final String JIGUANG_UPGRADE_COMBO = "44"; + //设备授权和解除 + private static final String JIGUANG_BIND_UNBIND = "45"; + @Override public void onReceive(Context context, Intent intent) { @@ -211,6 +215,8 @@ public class MyJPushReceiver extends BroadcastReceiver { // HTTPInterface.checkDevicesInfo(context); Log.e(TAG, "processCustomMessage: " + message); switch (message) { + default: + break; case JIGUANG_GET_DRIVELINE: ToastUtil.debugShow("收到推送消息: 获取在线信息"); // HTTPInterface.getDriveState(member_id, sn_id); @@ -239,8 +245,13 @@ public class MyJPushReceiver extends BroadcastReceiver { } catch (Exception e) { e.printStackTrace(); } - HTTPInterface.getBrowserWhiteList(context); - HTTPInterface.getBrowserLabel(context); + Handler.getMain().postDelayed(new Runnable() { + @Override + public void run() { + HTTPInterface.getBrowserWhiteList(context); + HTTPInterface.getBrowserLabel(context); + } + }, 2000); break; case JIGUANG_APP_NETWORKSTATE: ToastUtil.debugShow("收到推送消息: 应用联网管控"); @@ -294,14 +305,19 @@ public class MyJPushReceiver extends BroadcastReceiver { Handler.getMain().postDelayed(() -> HTTPInterface.getAllappPackage(context), 2000); break; case JIGUANG_BROWSER_LABEL: + ToastUtil.debugShow("收到推送消息: 浏览器书签"); try { new CacheUtils().cleanApplicationUserData(context, "com.android.browser"); } catch (Exception e) { e.printStackTrace(); } - ToastUtil.debugShow("收到推送消息: 浏览器书签"); - HTTPInterface.getBrowserWhiteList(context); - HTTPInterface.getBrowserLabel(context); + Handler.getMain().postDelayed(new Runnable() { + @Override + public void run() { + HTTPInterface.getBrowserWhiteList(context); + HTTPInterface.getBrowserLabel(context); + } + }, 2000); break; case JIGUANG_SYSTEM_SETTING: ToastUtil.debugShow("收到推送消息: 系统管控"); @@ -372,20 +388,28 @@ public class MyJPushReceiver extends BroadcastReceiver { setPhone(context, extras); break; case JIGUANG_CHANGE_COMBO: + ToastUtil.debugShow("更换套餐"); changeCombo(context, extras); break; case JIGUANG_CANCEL_COMBO: + ToastUtil.debugShow("取消套餐"); cancleCombo(context, extras); break; case JIGUANG_UPGRADE_COMBO: + ToastUtil.debugShow("升级套餐"); upgradeCombo(context, extras); case JIGUANG_APP_BROWSER: ToastUtil.debugShow("收到推送消息: 系统APP管控"); Log.e(TAG, "processCustomMessage: " + extras); hideDesktopIcon(context); break; - default: + case JIGUANG_BIND_UNBIND: + ToastUtil.debugShow("老师授权/取消授权"); + MainService.getPresenter().getAllApp(); + MainService.getPresenter().getForceInstall(); + DeviceManager.doMasterClear(); break; + } } @@ -945,7 +969,7 @@ public class MyJPushReceiver extends BroadcastReceiver { Log.e(TAG, "searchTopic: " + jsonString); JSONObject jsonObject = JSON.parseObject(jsonString); int search_topic = jsonObject.getIntValue("search_topic"); - SPUtils.put(context, "search_topic", search_topic); + Log.e(TAG, "searchTopic: put = " + SPUtils.put(context, "search_topic", search_topic)); JGYUtils.updateForbidList(context); } diff --git a/app/src/main/java/com/info/sn/service/MainService.java b/app/src/main/java/com/info/sn/service/MainService.java index c36e741..31b14e3 100644 --- a/app/src/main/java/com/info/sn/service/MainService.java +++ b/app/src/main/java/com/info/sn/service/MainService.java @@ -35,7 +35,9 @@ import org.jetbrains.annotations.NotNull; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import cn.jpush.android.api.JPushInterface; @@ -54,7 +56,7 @@ import static com.info.sn.jpush.TagAliasOperatorHelper.sequence; */ public class MainService extends Service implements MainContact.MainView, NetworkUtils.OnNetworkStatusChangedListener, LifecycleProvider { private String TAG = MainService.class.getSimpleName(); - private MainPresenter mPresenter = new MainPresenter(this); + private static MainPresenter mPresenter ; //执行所有请求的时间 long runningTime = 0; @@ -85,6 +87,7 @@ public class MainService extends Service implements MainContact.MainView, Networ private interface Start { void onstar(long time); } + private Start start; private final ObservableOnSubscribe subscribe = new ObservableOnSubscribe() { @@ -117,7 +120,7 @@ public class MainService extends Service implements MainContact.MainView, Networ HTTPInterface.sendRunningApp(MainService.this); HTTPInterface.getAPPinfo(MainService.this); startService(); - setAlias(); + mPresenter.setAlias(); } @Override @@ -141,6 +144,7 @@ public class MainService extends Service implements MainContact.MainView, Networ super.onCreate(); lifecycleSubject.onNext(ActivityEvent.CREATE); JPushInterface.init(this); + mPresenter = new MainPresenter(this); mPresenter.setProvider(this); mPresenter.attachView(this); NetworkUtils.registerNetworkStatusChangedListener(this); @@ -155,6 +159,7 @@ public class MainService extends Service implements MainContact.MainView, Networ Log.e(TAG, "onCreate: " + e.getMessage()); } ControlManager.getInstance().setDefaultUSBstate(); + mPresenter.setAlias(); } @Override @@ -199,15 +204,11 @@ public class MainService extends Service implements MainContact.MainView, Networ startService(new Intent(this, MyDownloadService.class)); } - private void setAlias() { - TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean(); - tagAliasBean.action = ACTION_SET; - sequence++; - tagAliasBean.alias = Utils.getSerial(); - tagAliasBean.isAliasAction = true; - TagAliasOperatorHelper.getInstance().handleAction(MainService.this, TagAliasOperatorHelper.sequence, tagAliasBean); + public static MainPresenter getPresenter(){ + return mPresenter; } + @Override public void setPowerUserList(String date) { @@ -233,6 +234,39 @@ public class MainService extends Service implements MainContact.MainView, Networ } + @Override + public void setAlias() { + setJpushAlias(); + Log.e(TAG, "setAlias: " + "finish"); + mPresenter.getBatch(); + } + + private void setJpushAlias() { + String alias = Utils.getSerial(); + TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean(); + tagAliasBean.action = ACTION_SET; + TagAliasOperatorHelper.sequence++; + tagAliasBean.alias = alias; + tagAliasBean.isAliasAction = true; + TagAliasOperatorHelper.getInstance().handleAction(this, TagAliasOperatorHelper.sequence, tagAliasBean); + } + + private void setTag(Set set) { + TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean(); + tagAliasBean.action = ACTION_SET; + TagAliasOperatorHelper.sequence++; + tagAliasBean.tags = set; + tagAliasBean.isAliasAction = false; + TagAliasOperatorHelper.getInstance().handleAction(this, TagAliasOperatorHelper.sequence, tagAliasBean); + } + + @Override + public void setBatch(String batch) { + HashSet hashSet = new HashSet(); + hashSet.add(batch); + setTag(hashSet); + } + @Override public void setQRCode(Bitmap bitmap) { diff --git a/app/src/main/java/com/info/sn/service/ManagerService.java b/app/src/main/java/com/info/sn/service/ManagerService.java index 084cc2e..1ea4206 100644 --- a/app/src/main/java/com/info/sn/service/ManagerService.java +++ b/app/src/main/java/com/info/sn/service/ManagerService.java @@ -119,7 +119,7 @@ public class ManagerService extends Service { @Override public void onError(Throwable e) { - Log.e("getScreenLockState", "onError: "); + Log.e("getScreenLockState", "onError: " + e.getMessage()); } @Override diff --git a/app/src/main/java/com/info/sn/utils/ApkUtils.java b/app/src/main/java/com/info/sn/utils/ApkUtils.java index db5d302..4ef4ee3 100644 --- a/app/src/main/java/com/info/sn/utils/ApkUtils.java +++ b/app/src/main/java/com/info/sn/utils/ApkUtils.java @@ -102,7 +102,6 @@ public class ApkUtils { } } - /** * 安装一个apk文件 */ @@ -672,7 +671,7 @@ public class ApkUtils { } public static void addShortcut(Context context) { - String packageList = (String) SPUtils.get(context, "only_jgy_shortcut_list", "Invalid"); + String packageList = Settings.System.getString(context.getContentResolver(), "only_jgy_shortcut_list"); if (TextUtils.isEmpty(packageList)) { JGYUtils.putString(context.getContentResolver(), "qch_launcher_icon_app", ""); return; @@ -834,4 +833,28 @@ public class ApkUtils { } + /** + * 获取第三方应用 + * + * @param context + * @return + */ + public static List queryFilterAppInfo(Context context) { + PackageManager pm = context.getPackageManager(); + // 查询所有已经安装的应用程序 + 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))); + if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) { + //通过flag排除系统应用,会将电话、短信也排除掉 + } else { + applicationInfos.add(app.packageName); + Log.e("queryFilterAppInfo", app.packageName); + } + } + return applicationInfos; + } + } diff --git a/app/src/main/java/com/info/sn/utils/JGYUtils.java b/app/src/main/java/com/info/sn/utils/JGYUtils.java index 880fd2c..88de53f 100644 --- a/app/src/main/java/com/info/sn/utils/JGYUtils.java +++ b/app/src/main/java/com/info/sn/utils/JGYUtils.java @@ -24,6 +24,7 @@ import android.provider.Settings; import android.text.TextUtils; import android.util.Log; +import com.alibaba.fastjson.JSONObject; import com.info.sn.BuildConfig; import com.info.sn.service.RemoteService; @@ -561,7 +562,11 @@ public class JGYUtils { public static ArrayList getForbidList(Context context) { ArrayList disableApp = new ArrayList<>(); - if ((int) SPUtils.get(context, "search_topic", 0) == 0) { + int search_topic = (int) SPUtils.get(context, "search_topic", 0); + Log.e(TAG, "getForbidList: search_topic = " + search_topic); + Log.e(TAG, "getForbidList: " + JSONObject.toJSONString(SPUtils.getAll(context))); + + if (search_topic == 0) { disableApp.add("拍照搜题"); } if (JGYUtils.getInt(context.getContentResolver(), "qch_app_camera", 0) == 1) { @@ -580,6 +585,9 @@ public class JGYUtils { if (JGYUtils.getInt(context.getContentResolver(), "qch_app_music", 0) == 1) { disableApp.add("com.android.music"); } + if (JGYUtils.getInt(context.getContentResolver(), "qch_app_browser", 0) == 1) { + disableApp.add("com.android.browser"); + } Log.e(TAG, "getForbidAPP: " + disableApp); return disableApp; } @@ -589,6 +597,7 @@ public class JGYUtils { public static void updateForbidList(Context context) { Intent intent = new Intent(UPDATE_FORBID_APP); intent.putStringArrayListExtra("forbid_app_list", getForbidList(context)); + Log.e(TAG, "updateForbidList: " + getForbidList(context)); intent.setPackage("com.jiaoguanyi.os"); intent.setPackage("com.tt.ttutils"); context.sendBroadcast(intent); @@ -603,6 +612,7 @@ public class JGYUtils { return new ArrayList<>(Arrays.asList(appString.split(","))); } } + private static final String UPDATE_HIDE_APP = "UPDATE_HIDE_APP"; public static void updateHideList(Context context) { @@ -736,6 +746,50 @@ public class JGYUtils { } } + //删除用户除了在应用市场的其他应用 + public void deleteOtherApp() { + int locked = Settings.System.getInt(mContext.getContentResolver(), "qch_unlock_ipad", 0); + if (locked == 1) { + return; + } + Log.e(TAG, "deleteOtherApp: " + "start"); + //获取后台应用白名单 + String only_jgy_shortcut_list = Settings.System.getString(mContext.getContentResolver(), "only_jgy_shortcut_list"); + //获取可以被安装的包名 + String qch_app_forbid = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid"); + Log.e("deleteOtherApp", "only_jgy_shortcut_list:" + only_jgy_shortcut_list); + Log.e("deleteOtherApp", "qch_app_forbid:" + qch_app_forbid); + String[] result_white = only_jgy_shortcut_list.split(","); + String[] result_forbid = qch_app_forbid.split(","); + 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); - + Log.e("deleteOtherApp", "installedPackageList:" + installedPackageList.toString()); + if (allWhitePkg.size() > 0) { + for (final String packageName : installedPackageList) { + if (ApkUtils.isSystemApp(mContext, packageName)) { + Log.e("deleteOtherApp", "is systemApp:" + packageName); + continue; + } +// if (ApkUtils.desktopAPP.contains(packageName)) { +// continue; +// } +// if (ApkUtils.canremove_systemapp.contains(packageName)) { +// continue; +// } + if ("com.jiaoguanyi.appstore".equals(packageName) || "com.jiaoguanyi.store".equals(packageName) + ) { + continue; + } + if (!allWhitePkg.contains(packageName)) { + ApkUtils.uninstallApp(mContext, packageName); + Log.e("deleteOtherApp", "uninstall apkName:" + packageName); + } + } + } + Log.e(TAG, "deleteOtherApp: " + "end"); + } } diff --git a/app/src/main/java/com/info/sn/utils/SPUtils.java b/app/src/main/java/com/info/sn/utils/SPUtils.java index 665c0d8..5a1f27f 100644 --- a/app/src/main/java/com/info/sn/utils/SPUtils.java +++ b/app/src/main/java/com/info/sn/utils/SPUtils.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.util.Base64; +import android.util.Log; import android.widget.ImageView; import java.io.ByteArrayInputStream; @@ -26,11 +27,12 @@ public class SPUtils { * 保存在手机里面的文件名 */ public static final String FILE_NAME = "share_data"; + private static String TAG = SPUtils.class.getSimpleName(); /** * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 */ - public static void put(Context context, String key, Object object) { + public static boolean put(Context context, String key, Object object) { SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); @@ -50,7 +52,7 @@ public class SPUtils { editor.putString(key, object.toString()); } - SharedPreferencesCompat.apply(editor); + return SharedPreferencesCompat.apply(editor); } /** @@ -183,17 +185,17 @@ public class SPUtils { /** * 如果找到则使用apply执行,否则使用commit */ - public static void apply(SharedPreferences.Editor editor) { + public static boolean apply(SharedPreferences.Editor editor) { try { if (sApplyMethod != null) { + Log.e(TAG, "apply: false"); sApplyMethod.invoke(editor); - return; + return false; } - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { + } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { + Log.e(TAG, "apply: " + e.getStackTrace()); } - editor.commit(); + return editor.commit(); } } } diff --git a/app/src/main/java/com/info/sn/utils/StatusBarUtil.java b/app/src/main/java/com/info/sn/utils/StatusBarUtil.java new file mode 100644 index 0000000..c7311ab --- /dev/null +++ b/app/src/main/java/com/info/sn/utils/StatusBarUtil.java @@ -0,0 +1,344 @@ +package com.info.sn.utils; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Color; +import android.os.Build; +import android.os.Environment; +import android.text.TextUtils; +import android.util.DisplayMetrics; +import android.view.Display; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Properties; + +public class StatusBarUtil { + public static int screenWidth; + public static int screenHeight; + public static int navigationHeight = 0; + + private static DisplayMetrics mMetrics; + public static final String HOME_CURRENT_TAB_POSITION = "HOME_CURRENT_TAB_POSITION"; + + public static final String SYS_EMUI = "sys_emui"; + public static final String SYS_MIUI = "sys_miui"; + public static final String SYS_FLYME = "sys_flyme"; + private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code"; + private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name"; + private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage"; + private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level"; + private static final String KEY_EMUI_VERSION = "ro.build.version.emui"; + private static final String KEY_EMUI_CONFIG_HW_SYS_VERSION = "ro.confg.hw_systemversion"; + + public static void init(Activity activity) { + ViewGroup contentLayout = activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT); + StatusBarUtil.setStatusBar(activity, false, true); + StatusBarUtil.setStatusTextColor(true, activity); + StatusBarUtil.setStatusBarPadding(activity, contentLayout); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + activity.getWindow().setStatusBarColor(activity.getResources().getColor(android.R.color.transparent)); + } + } + + /** + * 通过反射的方式获取状态栏高度 + * + * @return + */ + public static int getStatusBarHeight(Context context) { + try { + Class c = Class.forName("com.android.internal.R$dimen"); + Object obj = c.newInstance(); + Field field = c.getField("status_bar_height"); + int x = Integer.parseInt(field.get(obj).toString()); + return context.getResources().getDimensionPixelSize(x); + } catch (Exception e) { + } + return 0; + } + + /** + * 获取底部导航栏高度 + * + * @return + */ + public static int getNavigationBarHeight(Context context) { + Resources resources = context.getResources(); + int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + //获取NavigationBar的高度 + navigationHeight = resources.getDimensionPixelSize(resourceId); + return navigationHeight; + } + + //获取是否存在NavigationBar + public static boolean checkDeviceHasNavigationBar(Context context) { + boolean hasNavigationBar = false; + Resources rs = context.getResources(); + int id = rs.getIdentifier("config_showNavigationBar", "bool", "android"); + if (id > 0) { + hasNavigationBar = rs.getBoolean(id); + } + try { + Class systemPropertiesClass = Class.forName("android.os.SystemProperties"); + Method m = systemPropertiesClass.getMethod("get", String.class); + String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys"); + if ("1".equals(navBarOverride)) { + hasNavigationBar = false; + } else if ("0".equals(navBarOverride)) { + hasNavigationBar = true; + } + } catch (Exception e) { + + } + return hasNavigationBar; + + } + + /** + * @param activity + * @param useThemestatusBarColor 是否要状态栏的颜色,不设置则为透明色 + * @param withoutUseStatusBarColor 是否不需要使用状态栏为暗色调 + */ + public static void setStatusBar(Activity activity, boolean useThemestatusBarColor, boolean withoutUseStatusBarColor) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上 + View decorView = activity.getWindow().getDecorView(); + int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; + decorView.setSystemUiVisibility(option); + if (useThemestatusBarColor) { + activity.getWindow().setStatusBarColor(activity.getResources().getColor(android.R.color.white)); + } else { + activity.getWindow().setStatusBarColor(Color.TRANSPARENT); + } + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0 + WindowManager.LayoutParams localLayoutParams = activity.getWindow().getAttributes(); + localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !withoutUseStatusBarColor) { + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + } + } + + public static void reMeasure(Activity activity) { + Display display = activity.getWindowManager().getDefaultDisplay(); + mMetrics = new DisplayMetrics(); + + if (Build.VERSION.SDK_INT >= 17) { + display.getRealMetrics(mMetrics); + } else { + display.getMetrics(mMetrics); + } + + screenWidth = mMetrics.widthPixels; + screenHeight = mMetrics.heightPixels; + } + + /** + * 改变魅族的状态栏字体为黑色,要求FlyMe4以上 + */ + private static void processFlyMe(boolean isLightStatusBar, Activity activity) { + WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); + try { + Class instance = Class.forName("android.view.WindowManager$LayoutParams"); + int value = instance.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON").getInt(lp); + Field field = instance.getDeclaredField("meizuFlags"); + field.setAccessible(true); + int origin = field.getInt(lp); + if (isLightStatusBar) { + field.set(lp, origin | value); + } else { + field.set(lp, (~value) & origin); + } + } catch (Exception e) { + } + } + + /** + * 改变小米的状态栏字体颜色为黑色, 要求MIUI6以上 lightStatusBar为真时表示黑色字体 + */ + private static void processMIUI(boolean lightStatusBar, Activity activity) { + Class clazz = activity.getWindow().getClass(); + try { + int darkModeFlag; + Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); + Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); + darkModeFlag = field.getInt(layoutParams); + Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); + extraFlagField.invoke(activity.getWindow(), lightStatusBar ? darkModeFlag : 0, darkModeFlag); + } catch (Exception e) { + } + } + + /** + * 设置OPPO手机状态栏字体为黑色(colorOS3.0,6.0以下部分手机) + * + * @param lightStatusBar + * @param activity + */ + private static final int SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT = 0x00000010; + + private static void setOPPOStatusTextColor(boolean lightStatusBar, Activity activity) { + Window window = activity.getWindow(); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + int vis = window.getDecorView().getSystemUiVisibility(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (lightStatusBar) { + vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + } else { + vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + } + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (lightStatusBar) { + vis |= SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT; + } else { + vis &= ~SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT; + } + } + window.getDecorView().setSystemUiVisibility(vis); + } + + + /** + * 判断手机是否是小米 + * + * @return + */ + public static boolean isMIUI() { + return SYS_MIUI.equals(getSystem()); + } + + /** + * 判断手机是否是魅族 + * + * @return + */ + public static boolean isFlyme() { + try { + // Invoke Build.hasSmartBar() + final Method method = Build.class.getMethod("hasSmartBar"); + return method != null; + } catch (final Exception e) { + return false; + } + } + + /** + * 设置状态栏文字色值为深色调 + * + * @param useDart 是否使用深色调 + * @param activity + */ + public static void setStatusTextColor(boolean useDart, Activity activity) { + if (isFlyme()) { + processFlyMe(useDart, activity); + } else if (isMIUI()) { + processMIUI(useDart, activity); + } else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")) { + //OPPO + setOPPOStatusTextColor(useDart, activity); + } else { + if (useDart) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + } + } else { + activity.getWindow().getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); + } + activity.getWindow().getDecorView().findViewById(android.R.id.content).setPadding(0, 0, 0, navigationHeight); + } + } + + /** + * 作者:Loyea + * 链接:https://www.jianshu.com/p/abd021c22728 + * 來源:简书 + * 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。 + */ + public static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) { + View decor = activity.getWindow().getDecorView(); + if (dark) { + decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + } else { + // We want to change tint color to white again. + // You can also record the flags in advance so that you can turn UI back completely if + // you have set other flags before, such as translucent or full screen. + decor.setSystemUiVisibility(0); + } + } + + public static String getSystem() { + String SYS = ""; + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { + if (!TextUtils.isEmpty(getSystemProperty(KEY_MIUI_VERSION_CODE, "")) + || !TextUtils.isEmpty(getSystemProperty(KEY_MIUI_VERSION_NAME, "")) + || !TextUtils.isEmpty(getSystemProperty(KEY_MIUI_INTERNAL_STORAGE, ""))) { + SYS = SYS_MIUI;//小米 + } else if (!TextUtils.isEmpty(getSystemProperty(KEY_EMUI_API_LEVEL, "")) + || !TextUtils.isEmpty(getSystemProperty(KEY_EMUI_VERSION, "")) + || !TextUtils.isEmpty(getSystemProperty(KEY_EMUI_CONFIG_HW_SYS_VERSION, ""))) { + SYS = SYS_EMUI;//华为 + } else if (getMeizuFlymeOSFlag().toLowerCase().contains("flyme")) { + SYS = SYS_FLYME;//魅族 + } + return SYS; + } else { + try { + Properties prop = new Properties(); + prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"))); + if (prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null + || prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null + || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null) { + SYS = SYS_MIUI;//小米 + } else if (prop.getProperty(KEY_EMUI_API_LEVEL, null) != null + || prop.getProperty(KEY_EMUI_VERSION, null) != null + || prop.getProperty(KEY_EMUI_CONFIG_HW_SYS_VERSION, null) != null) { + SYS = SYS_EMUI;//华为 + } else if (getMeizuFlymeOSFlag().toLowerCase().contains("flyme")) { + SYS = SYS_FLYME;//魅族 + } + } catch (IOException e) { + e.printStackTrace(); + return SYS; + } finally { + return SYS; + } + } + } + + private static String getSystemProperty(String key, String defaultValue) { + try { + Class clz = Class.forName("android.os.SystemProperties"); + Method get = clz.getMethod("get", String.class, String.class); + return (String) get.invoke(clz, key, defaultValue); + } catch (Exception e) { + } + return defaultValue; + } + + public static String getMeizuFlymeOSFlag() { + return getSystemProperty("ro.build.display.id", ""); + } + + /** + * 全屏模式下 针对刘海屏向下移动view + * + * @param context + * @param view 需要设置padding的view + */ + public static void setStatusBarPadding(Context context, View view) { + if (view != null) { + view.setPadding(0, getStatusBarHeight(context), 0, 0); + } + } +} diff --git a/app/src/main/java/com/info/sn/utils/SystemUtils.java b/app/src/main/java/com/info/sn/utils/SystemUtils.java new file mode 100644 index 0000000..84b02dc --- /dev/null +++ b/app/src/main/java/com/info/sn/utils/SystemUtils.java @@ -0,0 +1,24 @@ +package com.info.sn.utils; + +import android.app.ActivityManager; +import android.content.Context; + +import java.util.List; + +public class SystemUtils { + + public static boolean isMainProcessName(Context cxt, int pid) { + String packageName = cxt.getPackageName(); + ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE); + List runningApps = am.getRunningAppProcesses(); + if (runningApps == null) { + return false; + } + for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) { + if (procInfo.pid == pid) { + return procInfo.processName.equals(packageName); + } + } + return false; + } +} diff --git a/app/src/main/java/com/info/sn/utils/URLUtils.java b/app/src/main/java/com/info/sn/utils/URLUtils.java index a68d165..8563cf4 100644 --- a/app/src/main/java/com/info/sn/utils/URLUtils.java +++ b/app/src/main/java/com/info/sn/utils/URLUtils.java @@ -31,6 +31,7 @@ public class URLUtils { private static String TAG = URLUtils.class.getSimpleName(); private Context mContext; private HashSet baseURLList = new HashSet<>(); + private HashSet nohttpURLList = new HashSet<>(); public URLUtils(Context context) { this.mContext = context; @@ -39,6 +40,7 @@ public class URLUtils { public void setBrowserList() { String whiteList = JGYUtils.getString(mContext.getContentResolver(), "DeselectBrowserArray"); String homePage = JGYUtils.getString(mContext.getContentResolver(), "homepagURL"); + Log.e(TAG, "setBrowserList old: " + whiteList); HashSet URLList = new HashSet<>(); if (!TextUtils.isEmpty(whiteList)){ diff --git a/build.gradle b/build.gradle index cf469fe..a588c49 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.4.10" repositories { google() jcenter() @@ -11,7 +10,6 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.6.4' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -34,5 +32,5 @@ allprojects { } task clean(type: Delete) { - delete rootProject.buildDir +// delete rootProject.buildDir }