- 移除 GuardService、StepService、ControlPanelService,替换为 SocketService - 将 QR 码生成从 Utils 迁移到 BitmapUtils - 将缓存目录选择逻辑统一到 FileUtils.getCacheFileDir - 将 ServiceAliveUtils、NetStateUtils 合并到 SystemUtils - 将 CacheUtils 同步清理替换为 ApkUtils.cleanApplicationUserDataAsync - 用 EncryptUtils 替代自定义 MD5Util - 重写 catchException 支持主线程兜底循环与子线程 Bugly 上报 - 移除 RunningAppManager 中未使用的 killBackgroundProcesses 方法 - 移除 ControlManager 中冗余的 hideSystemSettingAPP 调用 - MyGlideModule 重命名为 BaseGlideModule
607 lines
27 KiB
Java
607 lines
27 KiB
Java
package com.fuying.sn.sync;
|
|
|
|
import static com.fuying.sn.sync.RequestCallbacks.asRequest;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.pm.PackageInfo;
|
|
import android.content.pm.PackageManager;
|
|
import android.os.Build;
|
|
import android.provider.Settings;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
|
|
import com.fuying.sn.bean.AppAndWhiteBean;
|
|
import com.fuying.sn.bean.AppInfo;
|
|
import com.fuying.sn.bean.AppJump;
|
|
import com.fuying.sn.bean.AppStart;
|
|
import com.fuying.sn.bean.BaseResponse;
|
|
import com.fuying.sn.bean.BlacklistBean;
|
|
import com.fuying.sn.config.CommonConfig;
|
|
import com.fuying.sn.data.repository.DeviceRepository;
|
|
import com.fuying.sn.disklrucache.CacheHelper;
|
|
import com.fuying.sn.gson.GsonUtils;
|
|
import com.fuying.sn.network.BackgroundRequests;
|
|
import com.fuying.sn.network.UrlAddress;
|
|
import com.fuying.sn.sync.RequestCallbacks.CompleteCallback;
|
|
import com.fuying.sn.utils.ApkUtils;
|
|
import com.fuying.sn.utils.FileUtils;
|
|
import com.fuying.sn.utils.JgyUtils;
|
|
import com.fuying.sn.utils.SPUtils;
|
|
import com.fuying.sn.utils.Utils;
|
|
import com.google.gson.JsonObject;
|
|
import com.tencent.mmkv.MMKV;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.rxjava3.annotations.NonNull;
|
|
import io.reactivex.rxjava3.core.Completable;
|
|
import io.reactivex.rxjava3.core.Observable;
|
|
import io.reactivex.rxjava3.core.Observer;
|
|
import io.reactivex.rxjava3.disposables.Disposable;
|
|
import io.reactivex.rxjava3.functions.BiFunction;
|
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
|
|
|
/**
|
|
* 应用启动、升级、显示与跳转管控策略,并处理强制安装名单。
|
|
*/
|
|
public final class AppPolicySync {
|
|
private static final String TAG = "AppPolicySync";
|
|
|
|
private static volatile AppPolicySync instance;
|
|
private final Context mContext;
|
|
private final ContentResolver crv;
|
|
private final CacheHelper mCacheHelper;
|
|
private final DeviceRepository repository;
|
|
private final MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
|
|
|
private AppPolicySync(Context context, CacheHelper cacheHelper) {
|
|
mContext = context;
|
|
crv = context.getContentResolver();
|
|
mCacheHelper = cacheHelper;
|
|
repository = DeviceRepository.getInstance();
|
|
}
|
|
|
|
public static synchronized void init(Context context, CacheHelper cacheHelper) {
|
|
if (instance == null) {
|
|
instance = new AppPolicySync(context.getApplicationContext(), cacheHelper);
|
|
}
|
|
}
|
|
|
|
public static AppPolicySync getInstance() {
|
|
if (instance == null) {
|
|
throw new IllegalStateException("AppPolicySync must be initialized first");
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
public void setAppState(List<AppStart> list) {
|
|
// Settings.System.putString(crv, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "null");
|
|
// setAppAutoStart( list);
|
|
// setAppNetwork(list);
|
|
setAppUpdate(list);
|
|
setAppSlide(list);
|
|
setAppHide(list);
|
|
// setAPPinsideBrowser( list);
|
|
// setAPPIDJump( list);
|
|
}
|
|
|
|
private void checkPackageAndVersion(List<AppStart> list, List<AppInfo> appInfoList) {
|
|
if (list != null && appInfoList != null) {
|
|
PackageManager pm = mContext.getPackageManager();
|
|
HashMap<String, AppInfo> appInfoHashMap = new HashMap<>();
|
|
for (AppInfo appInfo : appInfoList) {
|
|
appInfoHashMap.put(appInfo.getApp_package(), appInfo);
|
|
}
|
|
for (AppStart appStart : list) {
|
|
String pkg = appStart.getApp_package();
|
|
if (appStart.getIs_upgrade() == 0) {
|
|
Log.e(TAG, "checkPackageAndVersion: " + pkg + ": 禁止升级");
|
|
AppInfo info = appInfoHashMap.get(pkg);
|
|
PackageInfo packageInfo = null;
|
|
try {
|
|
packageInfo = pm.getPackageInfo(pkg, 0);
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
e.printStackTrace();
|
|
}
|
|
if (packageInfo != null && info != null) {
|
|
Log.e(TAG, "checkPackageAndVersion: " + info.getApp_package());
|
|
long onlineVersion = info.getApp_version_code();
|
|
long appVersionCode;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
appVersionCode = packageInfo.getLongVersionCode();
|
|
} else {
|
|
appVersionCode = packageInfo.versionCode;
|
|
}
|
|
if (appVersionCode > onlineVersion && appVersionCode != 0) {
|
|
ApkUtils.uninstallApp(mContext, pkg);
|
|
JsonObject jsonObject = GsonUtils.getJsonObject(info.toString());
|
|
FileUtils.ariaDownload(mContext, info.getApp_url(), jsonObject);
|
|
Log.e(TAG, "checkPackageAndVersion: " + pkg + ": 卸载");
|
|
} else {
|
|
Log.e(TAG, "checkPackageAndVersion: " + pkg + ": 版本正常");
|
|
}
|
|
} else {
|
|
Log.e(TAG, "checkPackageAndVersion: " + pkg + ": 未安装");
|
|
}
|
|
} else {
|
|
Log.e(TAG, "checkPackageAndVersion: " + pkg + ": 未禁止升级");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//应用自启动
|
|
public void setAppAutoStart(List<AppStart> list) {
|
|
String auto_allow = "";
|
|
String auto_not = "";
|
|
if (null != list && list.size() != 0) {
|
|
for (AppStart app : list) {
|
|
int is_auto = app.getIs_auto();
|
|
String app_package = app.getApp_package();
|
|
if (is_auto == 1) {
|
|
if (!auto_allow.contains(app_package)) {
|
|
auto_allow += app_package + ",";
|
|
}
|
|
} else {
|
|
if (!auto_not.contains(app_package)) {
|
|
auto_not += app_package + ",";
|
|
}
|
|
}
|
|
}
|
|
if (!TextUtils.isEmpty(auto_allow) && auto_allow.endsWith(",")) {
|
|
auto_allow = auto_allow.substring(0, auto_allow.length() - 1);
|
|
boolean aole_app_power_on = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_APP_POWER_ON, auto_allow);
|
|
}
|
|
if (!TextUtils.isEmpty(auto_not) && auto_not.endsWith(",")) {
|
|
auto_not = auto_not.substring(0, auto_not.length() - 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
//app更新
|
|
@SuppressLint("NewApi")
|
|
private void setAppUpdate(List<AppStart> list) {
|
|
if (null != list && list.size() != 0) {
|
|
HashSet<String> notApp = new HashSet<>();
|
|
HashSet<String> allowApp = new HashSet<>();
|
|
for (AppStart app : list) {
|
|
int is_upgrade = app.getIs_upgrade();
|
|
String app_package = app.getApp_package();
|
|
if (is_upgrade == 0) {
|
|
notApp.add(app_package);
|
|
} else {
|
|
allowApp.add(app_package);
|
|
}
|
|
}
|
|
String upgrade_disallow = String.join(",", notApp);
|
|
String upgrade_allow = String.join(",", allowApp);
|
|
Log.e("setAppUpdate", "upgrade_allow: " + upgrade_allow);
|
|
Log.e("setAppUpdate", "upgrade_disallow: " + upgrade_disallow);
|
|
Settings.System.putString(crv, CommonConfig.AOLE_ACTION_DISALLOW_UPGRADE, upgrade_disallow);
|
|
Utils.writeDisableUpdateList(mContext);
|
|
}
|
|
}
|
|
|
|
//app滑动管控
|
|
private void setAppSlide(List<AppStart> list) {
|
|
String slide_allow = "";
|
|
String slide_not = "";
|
|
if (null != list && list.size() != 0) {
|
|
for (AppStart app : list) {
|
|
int is_slide = app.getIs_slide();
|
|
String app_package = app.getApp_package();
|
|
if (is_slide == 1) {
|
|
if (!slide_allow.contains(app_package)) {
|
|
slide_allow += app_package + ",";
|
|
}
|
|
} else {
|
|
if (!slide_not.contains(app_package)) {
|
|
slide_not += app_package + ",";
|
|
}
|
|
}
|
|
}
|
|
if (!TextUtils.isEmpty(slide_allow) && slide_allow.endsWith(",")) {
|
|
slide_allow = slide_allow.substring(0, slide_allow.length() - 1);
|
|
}
|
|
if (!TextUtils.isEmpty(slide_not) && slide_not.endsWith(",")) {
|
|
slide_not = slide_not.substring(0, slide_not.length() - 1);
|
|
boolean writeSucceed = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_DISABLE_SLIDE, slide_not);
|
|
Log.e(TAG, "aole_disable_slide=" + writeSucceed + ":" + slide_not);
|
|
} else {
|
|
boolean writeSucceed = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_DISABLE_SLIDE, "");
|
|
Log.e(TAG, "aole_disable_slide ok=" + writeSucceed + ":" + slide_allow);
|
|
}
|
|
|
|
} else {
|
|
setInvalid();
|
|
}
|
|
}
|
|
|
|
private int hide = 1;
|
|
|
|
//隐藏显示app
|
|
@SuppressLint("NewApi")
|
|
private void setAppHide(List<AppStart> list) {
|
|
PackageManager pm = mContext.getPackageManager();
|
|
if (null != list && list.size() != 0) {
|
|
List<String> hideAPPList = new ArrayList<>();
|
|
for (AppStart app : list) {
|
|
String app_package = app.getApp_package();
|
|
int is_lock = app.getIs_lock();
|
|
try {
|
|
if (is_lock == hide) {
|
|
pm.setApplicationEnabledSetting(app_package, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
|
|
hideAPPList.add(app_package);
|
|
} else {
|
|
pm.setApplicationEnabledSetting(app_package, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
|
|
}
|
|
} catch (Exception e) {
|
|
Log.e("setAppHide", "setAppHide: " + e.getMessage());
|
|
}
|
|
}
|
|
String jsonString = GsonUtils.toJSONString(hideAPPList);
|
|
SPUtils.put(mContext, "Hide_APP_List", String.join(",", jsonString));
|
|
JgyUtils.getInstance().updateHideList();
|
|
Log.e(TAG, "Hide_APP_List: " + jsonString);
|
|
}
|
|
}
|
|
|
|
//应用ID管控
|
|
@SuppressLint("NewApi")
|
|
public void setAPPIDJump(List<AppStart> list) {
|
|
if (null != list && list.size() != 0) {
|
|
HashSet<String> pkgs = new HashSet<>();
|
|
HashSet<String> idList = new HashSet<>();
|
|
for (AppStart app : list) {
|
|
pkgs.add(app.getApp_package());
|
|
idList.add(app.getVisit());
|
|
}
|
|
String packages = String.join(",", pkgs);
|
|
String ids = String.join(",", idList);
|
|
Log.e(TAG, "setAPPIDJump: " + packages);
|
|
Log.e(TAG, "setAPPIDJump: " + ids);
|
|
if (TextUtils.isEmpty(ids)) {
|
|
Settings.System.putString(crv, CommonConfig.AOLE_ACTION_APP_FORBID_ID, "");
|
|
Settings.System.putString(crv, CommonConfig.AOLE_ACTION_APP_FORBID_ARRAY, "");
|
|
} else {
|
|
Settings.System.putString(crv, CommonConfig.AOLE_ACTION_APP_FORBID_ID, packages);
|
|
Settings.System.putString(crv, CommonConfig.AOLE_ACTION_APP_FORBID_ARRAY, ids);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setInvalid() {
|
|
boolean aole_app_power_on = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_APP_POWER_ON, "");
|
|
// boolean aole_network_allow = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
|
|
// boolean aole_network_disallow = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
|
|
boolean writeSucceed = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_DISABLE_SLIDE, "");
|
|
}
|
|
|
|
public void getForceInstall(CompleteCallback callback) {
|
|
BackgroundRequests.submit(getForceInstallRequest(callback));
|
|
}
|
|
|
|
public Completable getForceInstallRequest(CompleteCallback callback) {
|
|
return asRequest(repository.getForceInstallControl(), getForceInstallObserver(callback));
|
|
}
|
|
|
|
public void getForceInstall() {
|
|
repository.getForceInstallControl()
|
|
.to(BackgroundRequests.submit(getForceInstallObserver(null)));
|
|
}
|
|
|
|
private Observer<BaseResponse<List<AppInfo>>> getForceInstallObserver(CompleteCallback callback) {
|
|
return new Observer<BaseResponse<List<AppInfo>>>() {
|
|
@Override
|
|
public void onSubscribe(@NonNull Disposable d) {
|
|
Log.e("getForceInstall", "onSubscribe: ");
|
|
}
|
|
|
|
@Override
|
|
public void onNext(@NonNull BaseResponse<List<AppInfo>> listBaseResponse) {
|
|
Log.e("getForceInstall", "onNext: " + listBaseResponse);
|
|
int code = listBaseResponse.code;
|
|
if (code == 200) {
|
|
List<AppInfo> appInfos = listBaseResponse.data;
|
|
if (appInfos != null && appInfos.size() != 0) {
|
|
List<AppInfo> temp = appInfos.stream().filter(appInfo -> "com.alibaba.android.rimet".equals(appInfo.getApp_package())).collect(Collectors.toList());
|
|
if (temp.size() == 0 && ApkUtils.isAvailable(mContext, "com.alibaba.android.rimet")) {
|
|
Log.e("getForceInstall", "onNext: uninstall dingtalk");
|
|
ApkUtils.uninstallApp(mContext, "com.alibaba.android.rimet");
|
|
} else {
|
|
Log.e("getForceInstall", "onNext: dingtalk force");
|
|
}
|
|
}
|
|
mCacheHelper.put(UrlAddress.GET_FORCE_INSTALL, GsonUtils.toJSONString(appInfos));
|
|
if (null != appInfos && appInfos.size() != 0) {
|
|
getForceInstallState(appInfos);
|
|
}
|
|
// JGYUtils.getInstance().deleteOtherApp();
|
|
} else {
|
|
mCacheHelper.put(UrlAddress.GET_FORCE_INSTALL, "");
|
|
boolean aole_force_app = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_FORCE_APP, "");
|
|
Log.e(TAG, "aole_force_app:" + aole_force_app + ":" + "");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onError(@NonNull Throwable e) {
|
|
Log.e("getForceInstall", "onError: " + e.getMessage());
|
|
onComplete();
|
|
}
|
|
|
|
@Override
|
|
public void onComplete() {
|
|
Log.e("getForceInstall", "onComplete: ");
|
|
if (callback != null) {
|
|
callback.onComplete();
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
@SuppressLint("NewApi")
|
|
public void getForceInstallState(List<AppInfo> list) {
|
|
if (null != list && list.size() != 0) {
|
|
HashSet<String> forceAppSet = new HashSet<>();
|
|
PackageManager pm = mContext.getPackageManager();
|
|
for (AppInfo appInfo : list) {
|
|
forceAppSet.add(appInfo.getApp_package());
|
|
PackageInfo info = null;
|
|
try {
|
|
info = pm.getPackageInfo(appInfo.getApp_package(), 0);
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
e.printStackTrace();
|
|
}
|
|
if (null != info) {
|
|
long appVersionCode;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
appVersionCode = info.getLongVersionCode();
|
|
} else {
|
|
appVersionCode = info.versionCode;
|
|
}
|
|
if (appVersionCode < appInfo.getApp_version_code()) {
|
|
JsonObject jsonObject = GsonUtils.getJsonObject(appInfo.toString());
|
|
FileUtils.ariaDownload(mContext, appInfo.getApp_url(), jsonObject);
|
|
}
|
|
} else {
|
|
JsonObject jsonObject = GsonUtils.getJsonObject(appInfo.toString());
|
|
FileUtils.ariaDownload(mContext, appInfo.getApp_url(), jsonObject);
|
|
}
|
|
}
|
|
String packageList = String.join(",", forceAppSet);
|
|
Log.e(TAG, "getForceInstallState: " + packageList);
|
|
boolean aole_force_app = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_FORCE_APP, packageList);
|
|
} else {
|
|
boolean aole_force_app = Settings.System.putString(crv, CommonConfig.AOLE_ACTION_FORCE_APP, "");
|
|
Log.e(TAG, "getForceInstallState:" + aole_force_app + ":" + "");
|
|
}
|
|
}
|
|
|
|
public void getAppJump(CompleteCallback callback) {
|
|
BackgroundRequests.submit(getAppJumpRequest(callback));
|
|
}
|
|
|
|
public Completable getAppJumpRequest(CompleteCallback callback) {
|
|
return asRequest(Observable.zip(repository.getAppJumpObservable(), repository.getBlacklistObservable(), getBlacklistBiFunction())
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread()), getBlacklistObserver(callback));
|
|
}
|
|
|
|
public void getAppJump() {
|
|
// repository.getAppJumpObservable()
|
|
// .subscribe(getAppJumpObserver(null));
|
|
|
|
Observable.zip(repository.getAppJumpObservable(), repository.getBlacklistObservable(), getBlacklistBiFunction())
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.to(BackgroundRequests.submit(getBlacklistObserver(null)));
|
|
}
|
|
|
|
private BiFunction<BaseResponse<List<AppJump>>, BaseResponse<BlacklistBean>, List<String>> getBlacklistBiFunction() {
|
|
return new BiFunction<BaseResponse<List<AppJump>>, BaseResponse<BlacklistBean>, List<String>>() {
|
|
@Override
|
|
public List<String> apply(BaseResponse<List<AppJump>> listBaseResponse, BaseResponse<BlacklistBean> blacklistBeanBaseResponse) throws Throwable {
|
|
Log.e("getBlacklistBiFunction", "apply: listBaseResponse = " + listBaseResponse);
|
|
Log.e("getBlacklistBiFunction", "apply: blacklistBeanBaseResponse = " + blacklistBeanBaseResponse);
|
|
Set<String> blackListUrls = new HashSet<>();
|
|
if (listBaseResponse.code == 200) {
|
|
List<AppJump> appJumpList = listBaseResponse.data;
|
|
if (appJumpList != null && !appJumpList.isEmpty()) {
|
|
List<String> urls = appJumpList.stream().map(new java.util.function.Function<AppJump, String>() {
|
|
@Override
|
|
public String apply(AppJump appJump) {
|
|
return appJump.getAddress();
|
|
}
|
|
}).collect(Collectors.toList());
|
|
blackListUrls.addAll(urls);
|
|
}
|
|
}
|
|
if (blacklistBeanBaseResponse.code == 200) {
|
|
BlacklistBean blacklistBean = blacklistBeanBaseResponse.data;
|
|
List<String> stringList = blacklistBean.getBlacklist();
|
|
if (stringList != null && !stringList.isEmpty()) {
|
|
blackListUrls.addAll(stringList);
|
|
}
|
|
}
|
|
// if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.G12NLPlatform) {
|
|
blackListUrls.add("com.tencent.wemeet.app.com.tencent.wemeet.sdk.view.OnlyPrivacyBrowserActivity");
|
|
blackListUrls.add("com.tencent.wemeet.app.com.tencent.wemeet.components.webcore.activity.GestureBrowserActivity");
|
|
blackListUrls.add("com.tencent.wemeet.components.webcore.activity.GestureBrowserActivity");
|
|
// }
|
|
return new ArrayList<>(blackListUrls);
|
|
}
|
|
};
|
|
}
|
|
|
|
private Observer<List<String>> getBlacklistObserver(CompleteCallback callback) {
|
|
return new Observer<List<String>>() {
|
|
@Override
|
|
public void onSubscribe(@NonNull Disposable d) {
|
|
Log.e("getBlacklistObserver", "onSubscribe: ");
|
|
}
|
|
|
|
@Override
|
|
public void onNext(@NonNull List<String> strings) {
|
|
Log.e("getBlacklistObserver", "onNext: " + strings);
|
|
if (strings == null || strings.isEmpty()) {
|
|
mCacheHelper.put(UrlAddress.GET_APP_JUMP, "");
|
|
Settings.System.putString(crv, CommonConfig.AOLE_APP_WEB_BLACK_LIST, "");
|
|
} else {
|
|
Settings.System.putString(crv, CommonConfig.AOLE_APP_WEB_BLACK_LIST, String.join(",", strings));
|
|
mCacheHelper.put(UrlAddress.GET_APP_JUMP, GsonUtils.toJSONString(strings));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onError(@NonNull Throwable e) {
|
|
Log.e("getBlacklistObserver", "onError: " + e.getMessage());
|
|
}
|
|
|
|
@Override
|
|
public void onComplete() {
|
|
Log.e("getBlacklistObserver", "onComplete: ");
|
|
if (callback != null) callback.onComplete();
|
|
}
|
|
};
|
|
}
|
|
|
|
public Observer<BaseResponse<List<AppJump>>> getAppJumpObserver(CompleteCallback completeCallback) {
|
|
return new Observer<BaseResponse<List<AppJump>>>() {
|
|
@Override
|
|
public void onSubscribe(@NonNull Disposable d) {
|
|
Log.e("getAppJump", "onSubscribe: ");
|
|
}
|
|
|
|
@Override
|
|
public void onNext(@NonNull BaseResponse<List<AppJump>> listBaseResponse) {
|
|
Log.e("getAppJump", "onNext: " + listBaseResponse);
|
|
if (listBaseResponse.code == 200) {
|
|
List<AppJump> appJumpList = listBaseResponse.data;
|
|
if (appJumpList == null || appJumpList.size() == 0) {
|
|
boolean putString = Settings.System.putString(crv, CommonConfig.AOLE_APP_WEB_BLACK_LIST, "");
|
|
mCacheHelper.put(UrlAddress.GET_APP_JUMP, "");
|
|
Log.e(TAG, "getAppJump: " + putString);
|
|
} else {
|
|
List<String> urls = appJumpList.stream().map(new java.util.function.Function<AppJump, String>() {
|
|
@Override
|
|
public String apply(AppJump appJump) {
|
|
return appJump.getAddress();
|
|
}
|
|
}).collect(Collectors.toList());
|
|
boolean putString = Settings.System.putString(crv, CommonConfig.AOLE_APP_WEB_BLACK_LIST, String.join(",", urls));
|
|
mCacheHelper.put(UrlAddress.GET_APP_JUMP, GsonUtils.toJSONString(urls));
|
|
Log.e(TAG, "getAppJump: " + putString);
|
|
}
|
|
} else {
|
|
mCacheHelper.put(UrlAddress.GET_APP_JUMP, "");
|
|
boolean putString = Settings.System.putString(crv, CommonConfig.AOLE_APP_WEB_BLACK_LIST, "");
|
|
Log.e(TAG, "getAppJump: " + putString);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onError(@NonNull Throwable e) {
|
|
Log.e("getAppJump", "onError: " + e.getMessage());
|
|
onComplete();
|
|
}
|
|
|
|
@Override
|
|
public void onComplete() {
|
|
Log.e("getAppJump", "onComplete: ");
|
|
if (completeCallback != null) {
|
|
completeCallback.onComplete();
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
// public void getAdminApp() {
|
|
// repository.getAdminAppObservable()
|
|
// .subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
|
|
// @Override
|
|
// public void onSubscribe(@NonNull Disposable d) {
|
|
// Log.e("getAdminApp", "onSubscribe: ");
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onNext(@NonNull BaseResponse<List<AppInfo>> baseResponse) {
|
|
// Log.e("getAdminApp", "onNext: " + baseResponse);
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onError(@NonNull Throwable e) {
|
|
// Log.e("getAdminApp", "onError: ");
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onComplete() {
|
|
// Log.e("getAdminApp", "onComplete: ");
|
|
// }
|
|
// });
|
|
// }
|
|
|
|
public void getAppAndWhite(CompleteCallback callback) {
|
|
BackgroundRequests.submit(getAppAndWhiteRequest(callback));
|
|
}
|
|
|
|
public Completable getAppAndWhiteRequest(CompleteCallback callback) {
|
|
return asRequest(repository.getAppAndWhiteApiObservable(), getAppAndWhiteObserver(callback));
|
|
}
|
|
|
|
public void getAppAndWhite() {
|
|
repository.getAppAndWhiteApiObservable()
|
|
.to(BackgroundRequests.submit(getAppAndWhiteObserver(null)));
|
|
}
|
|
|
|
public Observer<BaseResponse<List<AppAndWhiteBean>>> getAppAndWhiteObserver(CompleteCallback callback) {
|
|
return new Observer<BaseResponse<List<AppAndWhiteBean>>>() {
|
|
@Override
|
|
public void onSubscribe(@NonNull Disposable d) {
|
|
Log.e("getAppAndWhite", "onSubscribe: ");
|
|
}
|
|
|
|
@Override
|
|
public void onNext(@NonNull BaseResponse<List<AppAndWhiteBean>> baseResponse) {
|
|
Log.e("getAppAndWhite", "onSubscribe: " + baseResponse);
|
|
if (baseResponse.code == 200) {
|
|
List<AppAndWhiteBean> appAndWhiteList = baseResponse.data;
|
|
if (appAndWhiteList != null) {
|
|
List<String> pkgList = appAndWhiteList.stream().map(AppAndWhiteBean::getApp_package).collect(Collectors.toList());
|
|
String pkgString = String.join(",", pkgList);
|
|
mMMKV.encode(CommonConfig.BUILT_IN_APPS, pkgString);
|
|
Log.e("getAppAndWhite", "onNext: " + pkgString);
|
|
}
|
|
} else {
|
|
mMMKV.remove(CommonConfig.BUILT_IN_APPS);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onError(@NonNull Throwable e) {
|
|
Log.e("getAppAndWhite", "onError: " + e.getMessage());
|
|
onComplete();
|
|
}
|
|
|
|
@Override
|
|
public void onComplete() {
|
|
Log.e("getAppAndWhite", "onComplete: ");
|
|
JgyUtils.getInstance().putBuiltInApps();
|
|
if (callback != null) {
|
|
callback.onComplete();
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|