version:1.3.5
fix:增加展锐平台签名 add:
This commit is contained in:
455
app/src/main/java/com/info/sn/utils/JGYUtils.java
Normal file
455
app/src/main/java/com/info/sn/utils/JGYUtils.java
Normal file
@@ -0,0 +1,455 @@
|
||||
package com.info.sn.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.ActivityTaskManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.info.sn.BuildConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
|
||||
|
||||
|
||||
public class JGYUtils {
|
||||
private static final String TAG = JGYUtils.class.getSimpleName();
|
||||
|
||||
private static JGYUtils sInstance;
|
||||
private Context mContext;
|
||||
public static int MTKPlatform = 1;
|
||||
public static int ZhanruiPlatform = 2;
|
||||
public static int UnknowPlatform = 0;
|
||||
public static String MTKTag = "MTK";
|
||||
public static String ZhanruiTag = "展锐";
|
||||
|
||||
|
||||
private JGYUtils(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new JGYUtils(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static JGYUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init JGYUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static boolean isOfficialVersion() {
|
||||
String channelValue = JGYUtils.getInstance().getStringMetaData();
|
||||
return "official".equals(channelValue);
|
||||
}
|
||||
|
||||
public static boolean isNewlyVersion() {
|
||||
String channelValue = JGYUtils.getInstance().getStringMetaData();
|
||||
return "beta".equals(channelValue);
|
||||
}
|
||||
|
||||
public static boolean isBetaVersion() {
|
||||
String channelValue = JGYUtils.getInstance().getStringMetaData();
|
||||
return "beta".equals(channelValue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private int getBatteryLevel() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
BatteryManager batteryManager = (BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE);
|
||||
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||
} else {
|
||||
Intent intent = new ContextWrapper(mContext).registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
return (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) /
|
||||
intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private PowerManager.WakeLock wakeLock = null;
|
||||
private static final String mWakeLockName = "BackupService";
|
||||
|
||||
/**
|
||||
* 获取电源锁,保持该服务在屏幕熄灭时仍然获取CPU时,保持运行
|
||||
*/
|
||||
@SuppressLint("InvalidWakeLockTag")
|
||||
private synchronized void acquireWakeLock() {
|
||||
if (null == wakeLock) {
|
||||
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
|
||||
| PowerManager.ON_AFTER_RELEASE, mWakeLockName);
|
||||
if (null != wakeLock) {
|
||||
Log.e("fht", "acquireWakeLock!");
|
||||
wakeLock.acquire();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放设备电源锁
|
||||
*/
|
||||
private synchronized void releaseWakeLock() {
|
||||
if (null != wakeLock) {
|
||||
Log.e("fht", "releaseWakeLock!");
|
||||
wakeLock.release();
|
||||
wakeLock = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ids 需要管控的ID
|
||||
* @param packages 应用程序包名
|
||||
*/
|
||||
public void writeDeselectIDtoSystem(String ids, String packages) {
|
||||
if (!TextUtils.isEmpty(ids) && !TextUtils.isEmpty(packages)) {
|
||||
ArrayList<String> idArrayList = new ArrayList<>(Arrays.asList(ids.split(",")));
|
||||
ArrayList<String> packageArrayList = new ArrayList<>(Arrays.asList(packages.split(",")));
|
||||
LinkedHashSet<String> idHashSet = new LinkedHashSet<>(idArrayList);
|
||||
LinkedHashSet<String> packageHashSet = new LinkedHashSet<>(packageArrayList);
|
||||
ArrayList<String> idList = new ArrayList<>(idHashSet);
|
||||
ArrayList<String> packageList = new ArrayList<>(packageHashSet);
|
||||
StringBuilder idStringBuilder = new StringBuilder();
|
||||
for (String id : idList) {
|
||||
if (idStringBuilder.length() > 0) {
|
||||
idStringBuilder.append(",");
|
||||
}
|
||||
idStringBuilder.append(id);
|
||||
}
|
||||
StringBuilder packageStringBuilder = new StringBuilder();
|
||||
for (String pkg : packageList) {
|
||||
if (packageStringBuilder.length() > 0) {
|
||||
packageStringBuilder.append(",");
|
||||
}
|
||||
packageStringBuilder.append(pkg);
|
||||
}
|
||||
|
||||
|
||||
String olddeselectViewArray = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid_id");
|
||||
Log.e("writeDeselectIDtoSystem", "olddeselectViewArray: " + olddeselectViewArray);
|
||||
|
||||
Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid_id", packageStringBuilder.toString());
|
||||
Settings.System.putString(mContext.getContentResolver(), "DeselectViewArray", idStringBuilder.toString());
|
||||
Log.e("writeDeselectIDtoSystem", "qch_app_forbid_id: " + packageStringBuilder.toString());
|
||||
Log.e("writeDeselectIDtoSystem", "deselectViewArray: " + idStringBuilder.toString());
|
||||
} else {
|
||||
Log.e("writeDeselectIDtoSystem", "writeDeselectIDtoSystem is null:");
|
||||
Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid_id", "");
|
||||
Settings.System.putString(mContext.getContentResolver(), "DeselectViewArray", "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static void sendAllweb(Context context) {
|
||||
Intent intent = new Intent("qch_app_website")
|
||||
.setPackage("com.android.settings");
|
||||
intent.putExtra("package_name", "Invalid");
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
private static void sendwebUrl(Context context) {
|
||||
Intent intent = new Intent("qch_app_inside_website")
|
||||
.setPackage("com.android.settings");
|
||||
intent.putExtra("websitelist", "Invalid");
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从Manifest中获取meta-data值
|
||||
* https://blog.csdn.net/yue_233/article/details/91453451
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getStringMetaData() {
|
||||
ApplicationInfo appInfo = null;
|
||||
try {
|
||||
appInfo = mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String value = appInfo.metaData.getString("CHANNEL_VALUE");
|
||||
return value;
|
||||
}
|
||||
|
||||
public void hookWebView() {
|
||||
int sdkInt = Build.VERSION.SDK_INT;
|
||||
try {
|
||||
Class<?> factoryClass = Class.forName("android.webkit.WebViewFactory");
|
||||
Field field = factoryClass.getDeclaredField("sProviderInstance");
|
||||
field.setAccessible(true);
|
||||
Object sProviderInstance = field.get(null);
|
||||
if (sProviderInstance != null) {
|
||||
Log.i(TAG, "sProviderInstance isn't null");
|
||||
return;
|
||||
}
|
||||
|
||||
Method getProviderClassMethod;
|
||||
if (sdkInt > 22) {
|
||||
getProviderClassMethod = factoryClass.getDeclaredMethod("getProviderClass");
|
||||
} else if (sdkInt == 22) {
|
||||
getProviderClassMethod = factoryClass.getDeclaredMethod("getFactoryClass");
|
||||
} else {
|
||||
Log.i(TAG, "Don't need to Hook WebView");
|
||||
return;
|
||||
}
|
||||
getProviderClassMethod.setAccessible(true);
|
||||
Class<?> factoryProviderClass = (Class<?>) getProviderClassMethod.invoke(factoryClass);
|
||||
Class<?> delegateClass = Class.forName("android.webkit.WebViewDelegate");
|
||||
Constructor<?> delegateConstructor = delegateClass.getDeclaredConstructor();
|
||||
delegateConstructor.setAccessible(true);
|
||||
if (sdkInt < 26) {//低于Android O版本
|
||||
Constructor<?> providerConstructor = factoryProviderClass.getConstructor(delegateClass);
|
||||
if (providerConstructor != null) {
|
||||
providerConstructor.setAccessible(true);
|
||||
sProviderInstance = providerConstructor.newInstance(delegateConstructor.newInstance());
|
||||
}
|
||||
} else {
|
||||
Field chromiumMethodName = factoryClass.getDeclaredField("CHROMIUM_WEBVIEW_FACTORY_METHOD");
|
||||
chromiumMethodName.setAccessible(true);
|
||||
String chromiumMethodNameStr = (String) chromiumMethodName.get(null);
|
||||
if (chromiumMethodNameStr == null) {
|
||||
chromiumMethodNameStr = "create";
|
||||
}
|
||||
Method staticFactory = factoryProviderClass.getMethod(chromiumMethodNameStr, delegateClass);
|
||||
if (staticFactory != null) {
|
||||
sProviderInstance = staticFactory.invoke(null, delegateConstructor.newInstance());
|
||||
}
|
||||
}
|
||||
|
||||
if (sProviderInstance != null) {
|
||||
field.set("sProviderInstance", sProviderInstance);
|
||||
Log.i(TAG, "Hook success!");
|
||||
} else {
|
||||
Log.i(TAG, "Hook failed!");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 忽略电池优化
|
||||
*/
|
||||
private void ignoreBatteryOptimization(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
|
||||
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
|
||||
// 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。
|
||||
if (!hasIgnored) {
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void KillOTA() {
|
||||
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
manager.killBackgroundProcesses("com.adups.fota");
|
||||
CmdUtil.execute("am force-stop " + "com.adups.fota");
|
||||
}
|
||||
|
||||
public void openOTA() {
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
/**知道要跳转应用的包命与目标Activity*/
|
||||
ComponentName componentName = new ComponentName("com.adups.fota", "com.adups.fota.GoogleOtaClient");
|
||||
intent.setComponent(componentName);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
public int checkSNPlatform(String sn) {
|
||||
String secondChars = sn.substring(1, 2);
|
||||
if ("N".equalsIgnoreCase(secondChars)) {//MTK平台
|
||||
return MTKPlatform;
|
||||
} else if ("R".equalsIgnoreCase(secondChars)) {//展锐平台
|
||||
return ZhanruiPlatform;
|
||||
} else {
|
||||
Log.e(TAG, "checkSNPlatform: " + "sn: " + sn + "没有对应平台");
|
||||
return UnknowPlatform;
|
||||
}
|
||||
}
|
||||
|
||||
public int checkAppPlatform() {
|
||||
String platform = BuildConfig.platform;
|
||||
if ("MTK".equalsIgnoreCase(platform)) {
|
||||
Log.i(TAG, "checkAppPlatform: " + "MTK平台");
|
||||
return MTKPlatform;
|
||||
} else if ("ZhanRui".equalsIgnoreCase(platform)) {
|
||||
Log.i(TAG, "checkAppPlatform: " + "展锐平台");
|
||||
return ZhanruiPlatform;
|
||||
} else {
|
||||
Log.i(TAG, "checkAppPlatform: " + "没有数据");
|
||||
return UnknowPlatform;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSamePlatform(String platform) {
|
||||
String AppPlatform = BuildConfig.platform;
|
||||
if ("ZhanRui".equals(AppPlatform)) {
|
||||
return ZhanruiTag.equals(platform);
|
||||
} else {
|
||||
return AppPlatform.equals(platform);
|
||||
}
|
||||
}
|
||||
|
||||
public interface GetAppPlatformCallback {
|
||||
void AppPlatform(int platform);
|
||||
}
|
||||
|
||||
public void getAppPlatform(GetAppPlatformCallback getAppPlatformCallback) {
|
||||
String platform = BuildConfig.platform;
|
||||
if ("MTK".equalsIgnoreCase(platform)) {
|
||||
getAppPlatformCallback.AppPlatform(MTKPlatform);
|
||||
} else if ("ZhanRui".equalsIgnoreCase(platform)) {
|
||||
getAppPlatformCallback.AppPlatform(ZhanruiPlatform);
|
||||
} else {
|
||||
getAppPlatformCallback.AppPlatform(UnknowPlatform);
|
||||
}
|
||||
}
|
||||
|
||||
public void killBackgroundProcesses(Context context, String processName) {
|
||||
gotoLauncher();
|
||||
// mIsScanning = true;
|
||||
removeTask(processName);
|
||||
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
String packageName = null;
|
||||
try {
|
||||
if (processName.indexOf(":") == -1) {
|
||||
packageName = processName;
|
||||
} else {
|
||||
packageName = processName.split(":")[0];
|
||||
}
|
||||
activityManager.killBackgroundProcesses(packageName);
|
||||
//
|
||||
Method forceStopPackage = activityManager.getClass()
|
||||
.getDeclaredMethod("forceStopPackage", String.class);
|
||||
forceStopPackage.setAccessible(true);
|
||||
forceStopPackage.invoke(activityManager, packageName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有最近记录
|
||||
*/
|
||||
public void removeAllTask(Context context) {
|
||||
List<ActivityManager.RecentTaskInfo> list = getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), getCurrentUserId());
|
||||
|
||||
for (ActivityManager.RecentTaskInfo info : list) {
|
||||
if (info.realActivity != null) {
|
||||
Log.e(TAG, "removeAllTask: " + info.realActivity.getPackageName());
|
||||
//排除自身
|
||||
if (BuildConfig.APPLICATION_ID.equals(info.realActivity.getPackageName())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
ActivityManagerNative.getDefault().removeTask(info.id);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "removeAllTask: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTask(String packageName) {
|
||||
List<ActivityManager.RecentTaskInfo> list = getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), getCurrentUserId());
|
||||
HashMap<String, Integer> taskMap = new HashMap<>();
|
||||
for (ActivityManager.RecentTaskInfo info : list) {
|
||||
taskMap.put(info.realActivity.getPackageName(), info.id);
|
||||
}
|
||||
try {
|
||||
ActivityManagerNative.getDefault().removeTask(taskMap.get(packageName));
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "removeTask: " + e.getMessage());
|
||||
} catch (NullPointerException e) {
|
||||
Log.e(TAG, "removeTask: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果界面正在最近任务列表,有些app可能不会被清理
|
||||
*/
|
||||
private void gotoLauncher() {
|
||||
Intent i = new Intent(Intent.ACTION_MAIN);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //android123提示如果是服务里调用,必须加入new task标识
|
||||
i.addCategory(Intent.CATEGORY_HOME);
|
||||
mContext.startActivity(i);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a list of the recents tasks.
|
||||
* 获取近期任务列表
|
||||
*/
|
||||
public List<ActivityManager.RecentTaskInfo> getRecentTasks(int numTasks, int userId) {
|
||||
try {
|
||||
return ActivityTaskManager.getService().getRecentTasks(numTasks,
|
||||
RECENT_IGNORE_UNAVAILABLE, userId).getList();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to get recent tasks", e);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current user's id.
|
||||
* 获取userId
|
||||
*/
|
||||
public int getCurrentUserId() {
|
||||
UserInfo ui;
|
||||
try {
|
||||
ui = ActivityManager.getService().getCurrentUser();
|
||||
return ui != null ? ui.id : 0;
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import com.info.sn.BuildConfig;
|
||||
* @author Administrator
|
||||
*/
|
||||
public class LogUtils {
|
||||
static boolean isDebug = BuildConfig.LOG_DEBUG;
|
||||
static boolean isDebug = BuildConfig.DEBUG;
|
||||
|
||||
public static void v(String tag, String msg) {
|
||||
if (isDebug) {
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ToastUtil {
|
||||
debugHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (BuildConfig.LOG_DEBUG) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
if (debugToast != null) {
|
||||
debugToast.setText(msg);
|
||||
debugToast.show();
|
||||
|
||||
242
app/src/main/java/com/info/sn/utils/URLUtils.java
Normal file
242
app/src/main/java/com/info/sn/utils/URLUtils.java
Normal file
@@ -0,0 +1,242 @@
|
||||
package com.info.sn.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class URLUtils {
|
||||
private static String TAG = URLUtils.class.getSimpleName();
|
||||
private Context mContext;
|
||||
private List<String> baseURLList = new ArrayList<>();
|
||||
|
||||
public URLUtils(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public void setBrowserList() {
|
||||
String whiteList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray");
|
||||
String homePage = Settings.System.getString(mContext.getContentResolver(), "homepagURL");
|
||||
|
||||
if (TextUtils.isEmpty(whiteList)) {
|
||||
Log.e(TAG, "getBrowserWhiteList: " + "whiteList is empty");
|
||||
} else {
|
||||
List<String> URLList = new ArrayList<>(Arrays.asList(whiteList.split(",")));
|
||||
if (!TextUtils.isEmpty(homePage)) {
|
||||
if (URLList != null && !URLList.contains(homePage)) {
|
||||
URLList.add(homePage);
|
||||
}
|
||||
}
|
||||
Observable.create(new ObservableOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
|
||||
baseURLList.clear();
|
||||
baseURLList.addAll(URLList);
|
||||
for (String url : URLList) {
|
||||
if (url.startsWith("http://")) {
|
||||
String noHttp = url.substring(7);
|
||||
if (!baseURLList.contains(noHttp)) {
|
||||
baseURLList.add(noHttp);
|
||||
}
|
||||
emitter.onNext(getOkHttpURL(url));
|
||||
} else if (url.startsWith("https://")) {
|
||||
String noHttps = url.substring(8);
|
||||
if (!baseURLList.contains(noHttps)) {
|
||||
baseURLList.add(noHttps);
|
||||
}
|
||||
emitter.onNext(getOkHttpURL(url));
|
||||
} else {
|
||||
baseURLList.add("http://" + url);
|
||||
emitter.onNext(getOkHttpURL("http://" + url));
|
||||
baseURLList.add("https://" + url);
|
||||
emitter.onNext(getOkHttpURL("https://" + url));
|
||||
}
|
||||
Log.e(TAG, "subscribe: " + url);
|
||||
}
|
||||
emitter.onComplete();
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<String>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String s) {
|
||||
Log.e(TAG, "onNext: " + s);
|
||||
if (!baseURLList.contains(s)) {
|
||||
baseURLList.add(s);
|
||||
}
|
||||
if (s.startsWith("http://")) {
|
||||
String noHttp = s.substring(7);
|
||||
Log.e(TAG, "onNext: noHttp: " + noHttp);
|
||||
if (!baseURLList.contains(noHttp)) {
|
||||
baseURLList.add(noHttp);
|
||||
}
|
||||
}
|
||||
if (s.startsWith("https://")) {
|
||||
String noHttps = s.substring(8);
|
||||
Log.e(TAG, "onNext: noHttps: " + noHttps);
|
||||
if (!baseURLList.contains(noHttps)) {
|
||||
baseURLList.add(noHttps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG, "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e(TAG, "onComplete: ");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String s : baseURLList) {
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.append(",");
|
||||
}
|
||||
stringBuilder.append(s);
|
||||
}
|
||||
String DeselectBrowserArray = stringBuilder.toString();
|
||||
boolean write = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", DeselectBrowserArray);
|
||||
Log.e(TAG, "onComplete: " + "white list: " + DeselectBrowserArray);
|
||||
Log.e(TAG, "onComplete: " + "write :" + write);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getOkHttpURL(String URL) {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
final Request request = new Request.Builder()
|
||||
.url(URL)
|
||||
.removeHeader("User-Agent")
|
||||
.addHeader("User-Agent", getUserAgent())
|
||||
.get()//默认就是GET请求,可以不写
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
// call.enqueue(new Callback() {
|
||||
// @Override
|
||||
// public void onFailure(Call call, IOException e) {
|
||||
// Log.e(TAG, "onFailure: ");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onResponse(Call call, Response response) throws IOException {
|
||||
// Log.e(TAG, "onResponse: " + getIP(response.request().url().uri()));
|
||||
// }
|
||||
// });
|
||||
try {
|
||||
Response response = call.execute();
|
||||
if (response.isSuccessful()) {
|
||||
Log.e(TAG, "getOkHttpURL: " + response.request().url().toString());
|
||||
return getIP(response.request().url().uri()).toString();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "getOkHttpURL: " + e.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ip.
|
||||
* 通过url获取到域名
|
||||
*
|
||||
* @param url the url
|
||||
* @return the ip
|
||||
*/
|
||||
public String getIP(String url) {
|
||||
//使用正则表达式过滤,
|
||||
String re = "((http|ftp|https)://)(([a-zA-Z0-9._-]+)|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}))(([a-zA-Z]{2,6})|(:[0-9]{1,4})?)";
|
||||
String str = "";
|
||||
// 编译正则表达式
|
||||
Pattern pattern = Pattern.compile(re);
|
||||
// 忽略大小写的写法
|
||||
// Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(url);
|
||||
//若url==http://127.0.0.1:9040或www.baidu.com的,正则表达式表示匹配
|
||||
if (matcher.matches()) {
|
||||
str = url;
|
||||
} else {
|
||||
String[] split2 = url.split(re);
|
||||
if (split2.length > 1) {
|
||||
String substring = url.substring(0, url.length() - split2[1].length());
|
||||
str = substring;
|
||||
} else {
|
||||
str = split2[0];
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
private URI getIP(URI uri) {
|
||||
URI effectiveURI = null;
|
||||
try {
|
||||
// URI(String scheme, String userInfo, String host, int port, String
|
||||
// path, String query,String fragment)
|
||||
effectiveURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
||||
} catch (Throwable var4) {
|
||||
effectiveURI = null;
|
||||
}
|
||||
return effectiveURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 获取浏览器的UA
|
||||
*/
|
||||
private String getUserAgent() {
|
||||
String userAgent = "";
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
try {
|
||||
userAgent = WebSettings.getDefaultUserAgent(mContext);
|
||||
//需要hook webview
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "getUserAgent: " + e.getMessage());
|
||||
userAgent = System.getProperty("http.agent");
|
||||
}
|
||||
} else {
|
||||
userAgent = System.getProperty("http.agent");
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0, length = userAgent.length(); i < length; i++) {
|
||||
char c = userAgent.charAt(i);
|
||||
if (c <= '\u001f' || c >= '\u007f') {
|
||||
sb.append(String.format("\\u%04x", (int) c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "getUserAgent: " + sb.toString());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +1,86 @@
|
||||
package com.info.sn.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.StatFs;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.StatFs;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import com.info.sn.BuildConfig;
|
||||
import com.info.sn.R;
|
||||
import com.info.sn.bean.SystemSettings;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import com.info.sn.BuildConfig;
|
||||
import com.info.sn.R;
|
||||
import com.info.sn.bean.SystemSettings;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.lang.System.getProperty;
|
||||
|
||||
|
||||
public class Utils {
|
||||
@@ -1045,7 +1045,7 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void setIcon(Context mContext,SystemSettings settings) {
|
||||
private static void setIcon(Context mContext, SystemSettings settings) {
|
||||
try {
|
||||
//added:2019.12.6
|
||||
//设置5个app的开关
|
||||
@@ -1090,7 +1090,7 @@ public class Utils {
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param notList 禁止列表
|
||||
* @param notList 禁止列表
|
||||
* @param allowList 允许列表
|
||||
* @return
|
||||
*/
|
||||
@@ -1145,6 +1145,7 @@ public class Utils {
|
||||
*在写入白名单之后和安装完成之后执行
|
||||
*/
|
||||
}
|
||||
|
||||
public static String getIMEI(Context context) {
|
||||
String IMEI = "unknow";
|
||||
String IMEI1, IMEI2, IMEI3;
|
||||
@@ -1258,6 +1259,7 @@ public class Utils {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述:获取可用内存.
|
||||
*
|
||||
@@ -1364,6 +1366,19 @@ public class Utils {
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
String value = defaultValue;
|
||||
try {
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class, String.class);
|
||||
value = (String) (get.invoke(c, key, "unknown"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHardware(Context context) {
|
||||
int electric = getBattery(context);
|
||||
int charging = getIsCharging(context);
|
||||
|
||||
Reference in New Issue
Block a user