version:4.3

fix:安装应用时不清除桌面缓存,锁定状态改变时不恢复出厂设置
update:在获取sn没有刷写的状态时,获取IMEI作为别名
This commit is contained in:
2022-04-19 09:24:45 +08:00
parent 2339e1484d
commit 69a8934bd4
24 changed files with 514 additions and 263 deletions

View File

@@ -5,6 +5,7 @@ import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.ActivityTaskManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
@@ -102,6 +103,8 @@ public class JGYUtils {
@SuppressLint("StaticFieldLeak")
private static JGYUtils sInstance;
private Context mContext;
private ContentResolver crv;
public static int MTKPlatform = 1;
public static int ZhanruiPlatform = 2;
public static int UnknowPlatform = 0;
@@ -121,6 +124,7 @@ public class JGYUtils {
throw new RuntimeException("Context is NULL");
}
this.mContext = context;
this.crv = context.getContentResolver();
this.cacheHelper = new CacheHelper(context);
}
@@ -180,7 +184,7 @@ public class JGYUtils {
}
public boolean getDeviceIsLocked() {
int locked = Settings.System.getInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED);
int locked = Settings.System.getInt(crv, JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED);
return locked == JGYActions.FRAME_CODE_LOCKED;
}
@@ -265,11 +269,11 @@ public class JGYUtils {
if (disallowSlide.size() != 0) {
String slide_not = String.join(",", disallowSlide);
boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", slide_not);
boolean writeSucceed = Settings.System.putString(crv, "qch_disable_slide", slide_not);
Log.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not);
} else {
String slide_ok = String.join(",", allowSlide);
boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid");
boolean writeSucceed = Settings.System.putString(crv, "qch_disable_slide", "Invalid");
Log.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok);
}
@@ -283,19 +287,18 @@ public class JGYUtils {
Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on);
if (TextUtils.isEmpty(qch_app_power_on)) {
//当 qch_app_power_on 的值为空时,会造成系统所有应用断网
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "Invalid");
Settings.System.putString(crv, "qch_app_power_on", "Invalid");
Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + "Invalid");
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", qch_app_power_on);
Settings.System.putString(crv, "qch_app_power_on", qch_app_power_on);
Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on);
}
// if (BuildConfig.DEBUG) {
// TODO: 2021/7/2 测试写入为空是否断网
// boolean w = Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "");
// boolean w = Settings.System.putString(crv, "qch_app_power_on", "");
// Log.e(TAG, "setNetAndlaunch: 测试写入: " + w);
// }
setAppNetwork(mContext, disallowNetApp);
BaseApplication.getInstance().setFinished(true);
}
private void checkPackageAndVersion(HashSet<String> disallowUpgrade, List<AppListInfo> appListInfos) {
@@ -372,11 +375,11 @@ public class JGYUtils {
if (disallowSlide.size() != 0) {
String slide_not = String.join(",", disallowSlide);
boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", slide_not);
boolean writeSucceed = Settings.System.putString(crv, "qch_disable_slide", slide_not);
Log.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not);
} else {
String slide_ok = String.join(",", allowSlide);
boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid");
boolean writeSucceed = Settings.System.putString(crv, "qch_disable_slide", "Invalid");
Log.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok);
}
@@ -389,19 +392,18 @@ public class JGYUtils {
Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on);
if (TextUtils.isEmpty(qch_app_power_on)) {
//当 qch_app_power_on 的值为空时,会造成系统所有应用断网
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "Invalid");
Settings.System.putString(crv, "qch_app_power_on", "Invalid");
Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + "Invalid");
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", qch_app_power_on);
Settings.System.putString(crv, "qch_app_power_on", qch_app_power_on);
Log.e(TAG, "setNetAndlaunch: qch_app_power_on: " + qch_app_power_on);
}
// if (BuildConfig.DEBUG) {
// TODO: 2021/7/2 测试写入为空是否断网
// boolean w = Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "");
// boolean w = Settings.System.putString(crv, "qch_app_power_on", "");
// Log.e(TAG, "setNetAndlaunch: 测试写入: " + w);
// }
setAppNetwork(mContext, disallowNetApp);
BaseApplication.getInstance().setFinished(true);
}
@SuppressLint("NewApi")
@@ -482,7 +484,7 @@ public class JGYUtils {
String net_not = String.join(",", blackList);
SPUtils.put(context, JGYActions.ACTION_HRRECEIVER_JGY_DIS, net_not);
//Settings.System.putString(mContext.getContentResolver(), JGYActions.ACTION_HrReceiver_JGY_DIS, net_not);
//Settings.System.putString(crv, JGYActions.ACTION_HrReceiver_JGY_DIS, net_not);
Log.e("fht", "not::" + net_not);
//Intent netControlIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY_DIS);
@@ -546,17 +548,17 @@ public class JGYUtils {
}
String olddeselectViewArray = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid_id");
String olddeselectViewArray = Settings.System.getString(crv, "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());
Settings.System.putString(crv, "qch_app_forbid_id", packageStringBuilder.toString());
Settings.System.putString(crv, "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", "");
Settings.System.putString(crv, "qch_app_forbid_id", "");
Settings.System.putString(crv, "DeselectViewArray", "");
}
}
@@ -963,8 +965,8 @@ public class JGYUtils {
pkgSet.removeIf(TextUtils::isEmpty);
String qch_app_forbid = String.join(",", pkgSet);
Log.e(TAG, "writeAppPackageList: " + qch_app_forbid);
boolean b = Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid", qch_app_forbid);
Log.e("writeAppPackageList: ", "qch_app_forbid is :" + b + " " + Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid"));
boolean b = Settings.System.putString(crv, "qch_app_forbid", qch_app_forbid);
Log.e("writeAppPackageList: ", "qch_app_forbid is :" + b + " " + Settings.System.getString(crv, "qch_app_forbid"));
}
public void checkForceDownload() {
@@ -1151,10 +1153,10 @@ public class JGYUtils {
versionCode = info.versionCode;
}
if (app_version_code > versionCode) {
Utils.ariaDownload(mContext, app_url, jsonObject);
Utils.ariaDownload(mContext, app_url, jsonObject);
}
} else {
Utils.ariaDownload(mContext, app_url, jsonObject);
Utils.ariaDownload(mContext, app_url, jsonObject);
}
}
@@ -1162,7 +1164,7 @@ public class JGYUtils {
//删除用户除了在应用市场的其他应用
public void deleteOtherApp() {
int locked = Settings.System.getInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, 0);
int locked = Settings.System.getInt(crv, JGYActions.ACTION_QCH_UNLOCK_IPAD, 0);
if (locked == 1) {
return;
}
@@ -1170,12 +1172,12 @@ public class JGYUtils {
String[] result_white = new String[]{};
String[] result_forbid = new String[]{};
//获取后台应用白名单
String only_jgy_shortcut_list = Settings.System.getString(mContext.getContentResolver(), JGYActions.ACTION_JGY_SHORTCUTLIST);
String only_jgy_shortcut_list = Settings.System.getString(crv, JGYActions.ACTION_JGY_SHORTCUTLIST);
if (!TextUtils.isEmpty(only_jgy_shortcut_list)) {
result_white = only_jgy_shortcut_list.split(",");
}
//获取可以被安装的包名
String qch_app_forbid = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid");
String qch_app_forbid = Settings.System.getString(crv, "qch_app_forbid");
if (!TextUtils.isEmpty(qch_app_forbid)) {
result_forbid = qch_app_forbid.split(",");
}
@@ -1397,7 +1399,11 @@ public class JGYUtils {
public void setDeveloperOptions(int state) {
Log.e(TAG, "getDeveloper: " + state);
if (!BuildConfig.DEBUG) {
Settings.System.putInt(mContext.getContentResolver(), "qch_Developeroptions", state);
Settings.System.putInt(crv, "qch_Developeroptions", state);
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
Settings.Global.putInt(crv, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, state == 1 ? 0 : 1);
Settings.Global.putInt(crv, Settings.Global.ADB_ENABLED, state == 1 ? 0 : 1);
}
if (state == 1) {
Intent intent = new Intent();
intent.setAction("qch_developeroptions_close");
@@ -1411,8 +1417,13 @@ public class JGYUtils {
}
}
private String chromium_pkg = "org.chromium.browser";
public void hookWebView() {
int sdkInt = Build.VERSION.SDK_INT;
if (!ApkUtils.isAvailable(mContext, chromium_pkg)) {
return;
}
try {
Class<?> factoryClass = Class.forName("android.webkit.WebViewFactory");
Field field = factoryClass.getDeclaredField("sProviderInstance");
@@ -1463,7 +1474,7 @@ public class JGYUtils {
Log.i(TAG, "Hook failed!");
}
} catch (Throwable e) {
Log.w(TAG, e.getMessage());
Log.w(TAG, "hookWebView: " + e.getMessage());
}
}
@@ -1908,9 +1919,9 @@ public class JGYUtils {
Log.e(TAG, "setDefaultDesktop: " + pkg + ":" + className);
}
public String getMacJson() {
public String getMacJson(Context context) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("sn", Utils.getSerial());
jsonObject.addProperty("sn", Utils.getSerial(context));
jsonObject.addProperty("mac", Utils.getAndroid10MAC(mContext));
// jsonObject.addProperty("jpush_id", JPushInterface.getRegistrationID(mContext));
jsonObject.addProperty("jpush_id", "0000");
@@ -1937,28 +1948,6 @@ public class JGYUtils {
}
}
public static final String PACKAGE_DEVICEINFO = "com.aoleyun.sn";
public static final String PACKAGE_APPSTORE = "com.aoleyun.appstore";
public static final String CLASS_DEVICEINFO = "com.aoleyun.sn.receiver.BootReceiver";
public static final String CLASS_APPSTORE = "com.aoleyun.appstore.receiver.BootReceiver";
public void wakeUpDeviceInfo() {
//启动设备信息
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName(PACKAGE_DEVICEINFO, CLASS_DEVICEINFO));
mContext.sendBroadcast(bootIntent);
}
public void wakeUpAppstore() {
//启动应用市场
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName(PACKAGE_APPSTORE, CLASS_APPSTORE));
mContext.sendBroadcast(bootIntent);
}
/**
* 判断网络连接状态
*
@@ -1990,8 +1979,59 @@ public class JGYUtils {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.aoleyun.os");
} catch (Exception e) {
Log.e(TAG, "onReceive: " + e.getMessage());
Log.e(TAG, "cleanAoleLauncher3Cache: " + e.getMessage());
e.printStackTrace();
}
}
public void cleanAoleAppCache() {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.aoleyun.os");
new CacheUtils().cleanApplicationUserData(mContext, "com.aoleyun.appstore");
new CacheUtils().cleanApplicationUserData(mContext, "com.aoleyun.info");
new CacheUtils().cleanApplicationUserData(mContext, "com.aoleyun.browser");
} catch (Exception e) {
Log.e(TAG, "cleanAoleAppCache: " + e.getMessage());
e.printStackTrace();
}
}
public static final String PACKAGE_DEVICEINFO = "com.aoleyun.sn";
public static final String CLASS_DEVICEINFO = "com.aoleyun.sn.receiver.BootReceiver";
public void wakeUpDeviceInfo() {
Log.e(TAG, "wakeUpDeviceInfo: ");
//启动设备信息
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName(PACKAGE_DEVICEINFO, CLASS_DEVICEINFO));
mContext.sendBroadcast(bootIntent);
}
public static final String PACKAGE_APPSTORE = "com.aoleyun.appstore";
public static final String CLASS_APPSTORE = "com.aoleyun.appstore.receiver.BootReceiver";
public void wakeUpAppstore() {
Log.e(TAG, "wakeUpAppstore: ");
//启动应用市场
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName(PACKAGE_APPSTORE, CLASS_APPSTORE));
mContext.sendBroadcast(bootIntent);
}
public static final String PACKAGE_NOTIFY = "com.aoleyun.info";
public static final String CLASS_NOTIFY = "com.aoleyun.info.receiver.BootReceiver";
public void wakeUpNotify() {
Log.e(TAG, "wakeUpNotify: ");
//启动通知
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName(PACKAGE_NOTIFY, CLASS_NOTIFY));
mContext.sendBroadcast(bootIntent);
}
public void wakeUpAoleyunAPP() {
wakeUpAppstore();
wakeUpNotify();
}
}

View File

@@ -56,6 +56,7 @@ import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.arialyy.aria.core.Aria;
import com.blankj.utilcode.util.FileUtils;
import com.google.gson.JsonObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
@@ -73,6 +74,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InetAddress;
@@ -688,12 +690,41 @@ public class Utils {
return t1;
}
public static String NOSN = "012345679ABCDEF";
/**
* 获取设备序列号
*
* @return
*/
@SuppressLint("MissingPermission")
@SuppressLint({"MissingPermission", "HardwareIds"})
public static String getSerial(Context context) {
String serial = "unknow";
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
serial = Build.getSerial();
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {//8.0+
serial = Build.SERIAL;
} else {//8.0-
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
}
} catch (Exception e) {
e.printStackTrace();
Log.e("getSerial", "读取设备序列号异常:" + e.toString());
}
if (BuildConfig.DEBUG) {
// return "QNG2DKB00463";
// serial = "012345679ABCDEF";
}
if (NOSN.equalsIgnoreCase(serial)) {
return getIMEI(context);
}
return serial;
}
@SuppressLint({"MissingPermission", "HardwareIds"})
public static String getSerial() {
String serial = "unknow";
try {
@@ -928,7 +959,7 @@ public class Utils {
}
}
/**
/**
* 更新应用白名单禁止升级
*
* @param context
@@ -1163,7 +1194,7 @@ public class Utils {
try {
interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface networkInterface : interfaces) {
if (networkInterface != null && TextUtils.isEmpty(networkInterface.getName()) == false) {
if (networkInterface != null && !TextUtils.isEmpty(networkInterface.getName())) {
if ("wlan0".equalsIgnoreCase(networkInterface.getName())) {
byte[] macBytes = networkInterface.getHardwareAddress();
if (macBytes != null && macBytes.length > 0) {
@@ -1185,16 +1216,25 @@ public class Utils {
return "unknown";
}
@SuppressLint("HardwareIds")
public static String getIMEI(Context context, int slotIndex) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return tm.getImei(slotIndex);
} else {
return tm.getDeviceId(slotIndex);
}
}
@SuppressLint("HardwareIds")
public static String getIMEI(Context context) {
String IMEI = "unknow";
String IMEI1, IMEI2, IMEI3;
//获取手机设备号
TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//8.0及以后版本获取
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
IMEI = TelephonyMgr.getDeviceId();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// try {
// Method method = TelephonyMgr.getClass().getMethod("getImei");
// IMEI = (String) method.invoke(TelephonyMgr);
@@ -1205,7 +1245,7 @@ public class Utils {
// IMEI = TelephonyMgr.getDeviceId();
// } else {//9.0到10.0获取
IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
// IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Log.e("IMEI:", "IMEI: " + IMEI);
if (null == IMEI) {
@@ -1213,9 +1253,40 @@ public class Utils {
} else {
return IMEI.toUpperCase();
}
}
/**
* IMEI 1号
*
* @param context
* @return
*/
// public static String getIMEI_1(Context context) {
// TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// return tm != null ? tm.getDeviceId() : "";
// }
/**
* IMEI 2号
*
* @param context
* @return
*/
// public static String getIMEI_2(Context context) {
// TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Class clazz = tm.getClass();
// try {
// Method getImei = clazz.getDeclaredMethod("getImei", int.class);
// return getImei.invoke(tm, 1).toString();
// } catch (NoSuchMethodException e) {
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// }
// return "";
// }
public static String getMachine(Context context) {
String device = Build.MODEL;//机型
String imei = getIMEI(context);
@@ -1259,6 +1330,21 @@ public class Utils {
return jsonString;
}
public static String getAddressJsonString(Context context) {
String address = String.valueOf(SPUtils.get(context, "AmapAddress", "-"));
if ("-".equals(address)) {
address = "定位失败";
}
String longitude = String.valueOf(SPUtils.get(context, "longitude", "0"));
String latitude = String.valueOf(SPUtils.get(context, "latitude", "0"));
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("address", address);
jsonObject.addProperty("longitude", longitude);
jsonObject.addProperty("latitude", latitude);
String jsonString = jsonObject.toString();
return jsonString;
}
private static int getNumCores() {
// Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter {