update:2020.05.26

fix:
add:禁止应用升级功能
This commit is contained in:
2020-05-26 17:23:25 +08:00
parent 8976698729
commit a1b5f7e510
4 changed files with 65 additions and 5 deletions

View File

@@ -83,6 +83,8 @@ public class MyJPushReceiver extends BroadcastReceiver {
private final String APP_WEBSITE = "16";//app内网页管控
private final String DISABLE_APPUPDATE = "17";//禁止app升级
private Context mContext;
@@ -557,7 +559,24 @@ public class MyJPushReceiver extends BroadcastReceiver {
case APP_WEBSITE:
setAPPinsideWebsite(extras);
break;
case DISABLE_APPUPDATE:
Log.e("fht", extras);
setDisableUpdateList(extras);
break;
}
}
private void setDisableUpdateList(String s) {
try {
JSONObject jsonObject = new JSONObject(s);
String ban = jsonObject.getString("ban");
String not = jsonObject.getString("not");
String[] banList = ban.split(",");
String[] notList = not.split(",");
boolean b = Utils.writeDisableUpdateList(mContext, banList, notList);
} catch (JSONException e) {
e.printStackTrace();
}
}

View File

@@ -671,7 +671,7 @@ public class InitJpushServer extends Service {
// Settings.System.putString(getApplicationContext().getContentResolver(), "DeselectBrowserArray", "http://www.baidu.com");
String ss = Settings.System.getString(getApplicationContext().getContentResolver(), "DeselectBrowserArray");
Log.e("jpttlocked2", "DeselectBrowserArray---------" + ss);
getAppLimitApi();
getAppLimitApi();//获取可以写入的app包名
getDeselectID();
// getDeselectBrowerID();
getNetAndLaunchSetting();

View File

@@ -57,6 +57,8 @@ import java.net.NetworkInterface;
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;
@@ -887,7 +889,7 @@ public class Utils {
}
}
synchronized public static void doMasterClear(Context context) {
synchronized public static void doMasterClear(Context context) {
if (getBatteryLevel(context) >= CommonDatas.MIN_POWER) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
Intent intent = new Intent("android.intent.action.FACTORY_RESET");
@@ -907,11 +909,50 @@ public class Utils {
}
}
synchronized private static int getBatteryLevel(Context mContext) {
synchronized private static int getBatteryLevel(Context mContext) {
if (Build.VERSION.SDK_INT >= 21)
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
Intent intent = (new ContextWrapper(mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
}
static synchronized public boolean writeDisableUpdateList(Context context, String[] banList, String[] notList) {
String now = Settings.System.getString(context.getContentResolver(), "qch_app_forbid");
String[] nowList = now.split(",");
List<String> allList = new ArrayList<>(Arrays.asList(nowList));//已经写入的列表
boolean writeSucceed = false;
if (banList != null && banList.length > 0) {
for (String s : banList) {
if (ApkUtils.isAvailable(context, s)) {
allList.remove(s);
//去掉已经安装的
}
}
}
for (String s : notList) {
if (allList.indexOf(s) == -1) {
allList.add(s);
//没找到元素添加到白名单
}
}
if (allList.size() > 0) {
String list = "";
for (String str : allList) {
list += str + ",";
}
list = list.substring(0, list.length() - 1);
Log.e("fht", list);
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", list);
} else {
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", "Invalid");
}
return writeSucceed;
/*功能和应用安装白名单一样首先会写入所有的app名单。
*如果已经安装就从白名单删除,没有安装的不用删除
*不然会出现安装不上的情况
*在写入白名单之后和安装完成之后执行
*/
}
}