version:
update:2021.03.29 fix:修改为mvp架构,顺序执行,优化连接的次数 add:
This commit is contained in:
@@ -34,8 +34,8 @@ import com.google.gson.Gson;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.mjsheng.myappstore.R;
|
||||
import com.mjsheng.myappstore.bean.UploadAppInfo;
|
||||
import com.mjsheng.myappstore.manager.NetInterfaceManager;
|
||||
import com.mjsheng.myappstore.network.URLAddress;
|
||||
import com.mjsheng.myappstore.network.Network;
|
||||
import com.mjsheng.myappstore.network.api.UploadAppInfoApi;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -1072,8 +1072,8 @@ public class ApkUtils {
|
||||
String jsonString = gson.toJson(appList);
|
||||
// Log.e("mjsheng", "json========" + jsonString);
|
||||
|
||||
UploadAppInfoApi uploadAppInfoApi = Network.getUploadAppInfoApi();
|
||||
uploadAppInfoApi.getUploadAppInfoApi(URLAddress.HTTP_KEY, Utils.getSerial(), jsonString)
|
||||
UploadAppInfoApi uploadAppInfoApi = NetInterfaceManager.getUploadAppInfoApi();
|
||||
uploadAppInfoApi.getUploadAppInfoApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial(), jsonString)
|
||||
.subscribeOn(io.reactivex.schedulers.Schedulers.io())
|
||||
.observeOn(io.reactivex.android.schedulers.AndroidSchedulers.mainThread())
|
||||
.subscribe(new io.reactivex.Observer<ResponseBody>() {
|
||||
@@ -1085,7 +1085,7 @@ public class ApkUtils {
|
||||
@Override
|
||||
public void onNext(ResponseBody responseBody) {
|
||||
try {
|
||||
Log.e("mjhseng", "上传的结果" + responseBody.string());
|
||||
Log.e("getAppInfo", "上传的结果" + responseBody.string());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1093,7 +1093,7 @@ public class ApkUtils {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("mjsheng", "UploadAppInfoApi=onError:");
|
||||
Log.e("getAppInfo", "UploadAppInfoApi=onError:");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,11 +7,19 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Looper;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -129,4 +137,116 @@ public class ExampleUtil {
|
||||
public static String getDeviceId(Context context) {
|
||||
return JPushInterface.getUdid(context);
|
||||
}
|
||||
|
||||
public static class StorageUtils {
|
||||
|
||||
|
||||
// 获取存储空间 false 内置sd卡路径,true 外置sd卡路径
|
||||
public static File getStoragePath(Context mContext, boolean isSDcard) {
|
||||
StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
|
||||
Class<?> storageVolumeClazz = null;
|
||||
try {
|
||||
storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
|
||||
Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
|
||||
Method getPath = storageVolumeClazz.getMethod("getPath");
|
||||
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
|
||||
Object result = getVolumeList.invoke(mStorageManager);
|
||||
final int length = Array.getLength(result);
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object storageVolumeElement = Array.get(result, i);
|
||||
String path = (String) getPath.invoke(storageVolumeElement);
|
||||
boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
|
||||
if (isSDcard == removable) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}else {
|
||||
if (!isSDcard) {
|
||||
return Environment.getExternalStorageDirectory();
|
||||
} else {
|
||||
File file1 = new File("root/storage/sdcard1");
|
||||
if (file1.exists()){
|
||||
return file1;
|
||||
}else {
|
||||
File file2 = new File("storage/sdcard1");
|
||||
if (file2.exists()){
|
||||
return file2;
|
||||
}else {
|
||||
File file3 = new File("/storage/emulated/0");
|
||||
if (file3.exists()){
|
||||
return file3;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getFileCache(Context context, String s) {
|
||||
return getExternalFilesDir(context, s).getAbsolutePath();
|
||||
}
|
||||
|
||||
public static String getFileRoot(Context context) {
|
||||
return getExternalFilesDir(context, "Download").getAbsolutePath();
|
||||
}
|
||||
|
||||
public static File getExternalFilesDir(Context context, String s) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
|
||||
File path = context.getExternalFilesDir(s);
|
||||
if (path != null) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
final String cacheDir = "/Android/data/" + context.getPackageName() + "/files/" + s;
|
||||
return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
|
||||
}
|
||||
|
||||
|
||||
// 检测文件是否存在
|
||||
public static boolean isFileIsExists(String filePath){
|
||||
try{
|
||||
File f=new File(filePath);
|
||||
if(!f.exists()){
|
||||
return false;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static String size(long size) {
|
||||
if (size / (1024 * 1024) > 0) {
|
||||
float tmpSize = (float) (size) / (float) (1024 * 1024 );
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
return "" + df.format(tmpSize) + "GB";
|
||||
} else if (size / 1024 > 0) {
|
||||
float tmpSize = (float) (size) / (float) 1024 ;
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
return "" + df.format(tmpSize) + "MB";
|
||||
} else if (size > 0) {
|
||||
return "" + (size ) + "KB";
|
||||
} else {
|
||||
return "" + (size) + "KB";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
577
app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java
Normal file
577
app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java
Normal file
@@ -0,0 +1,577 @@
|
||||
package com.mjsheng.myappstore.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.mjsheng.myappstore.base.BaseApplication;
|
||||
import com.mjsheng.myappstore.bean.Appground;
|
||||
import com.mjsheng.myappstore.bean.BaseResponse;
|
||||
import com.mjsheng.myappstore.bean.ForceDownloadData;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchData;
|
||||
import com.mjsheng.myappstore.comm.CommonDatas;
|
||||
import com.mjsheng.myappstore.server.InitJpushServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class JGYUtils {
|
||||
private static final String TAG = JGYUtils.class.getSimpleName();
|
||||
private static JGYUtils sInstance;
|
||||
private Context mContext;
|
||||
public static final String ROOT_URL = BuildConfig.ROOT_URL;
|
||||
|
||||
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 void resetDevice() {
|
||||
boolean isReset = MySQLData.GetBooleanData(mContext, CommonDatas.IS_RESET);
|
||||
int batteryLevel = getBatteryLevel();
|
||||
Log.e(TAG, "batteryLevel:" + batteryLevel + " isReset" + isReset);
|
||||
if (isReset && batteryLevel >= CommonDatas.MIN_POWER) {
|
||||
Utils.doMasterClear(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 netAndLaunchBean
|
||||
*/
|
||||
public void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean) {
|
||||
Log.e(TAG, "setNetAndlaunch: ");
|
||||
String net_ok = "";
|
||||
String net_not = "";
|
||||
String launch = "";
|
||||
String camera_ok = "";
|
||||
String camera_not = "";
|
||||
String upgrade_ok = "";
|
||||
String upgrade_not = "";
|
||||
String slide_ok = "";
|
||||
String slide_not = "";
|
||||
|
||||
List<NetAndLaunchData> data = netAndLaunchBean.getData();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
NetAndLaunchData netAndLaunchData = data.get(i);
|
||||
String app_package = netAndLaunchData.getApp_package();
|
||||
int is_auto = netAndLaunchData.getIs_auto();
|
||||
int is_network = netAndLaunchData.getIs_network();
|
||||
int is_camera = netAndLaunchData.getIs_camera();
|
||||
int is_upgrade = netAndLaunchData.getIs_upgrade();
|
||||
int is_slide = netAndLaunchData.getIs_slide();
|
||||
|
||||
|
||||
if (is_auto == 1) {
|
||||
launch += app_package + ",";
|
||||
}
|
||||
if (is_network == 1) {
|
||||
net_ok += app_package + ",";
|
||||
} else {
|
||||
net_not += app_package + ",";
|
||||
}
|
||||
|
||||
if (is_camera == 1) {
|
||||
camera_ok += app_package + ",";
|
||||
} else {
|
||||
camera_not += app_package + ",";
|
||||
}
|
||||
if (is_upgrade == 1) {
|
||||
upgrade_ok += app_package + ",";
|
||||
} else {
|
||||
upgrade_not += app_package + ",";
|
||||
}
|
||||
if (is_slide == 1) {
|
||||
slide_ok += app_package + ",";
|
||||
} else {
|
||||
slide_not += app_package + ",";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!TextUtils.isEmpty(launch)) {
|
||||
launch = launch.substring(0, launch.length() - 1);
|
||||
}
|
||||
if (!TextUtils.isEmpty(net_ok)) {
|
||||
net_ok = net_ok.substring(0, net_ok.length() - 1);
|
||||
}
|
||||
if (!TextUtils.isEmpty(net_not)) {
|
||||
net_not = net_not.substring(0, net_not.length() - 1);
|
||||
}
|
||||
if (!TextUtils.isEmpty(camera_ok)) {
|
||||
camera_ok = camera_ok.substring(0, camera_ok.length() - 1);
|
||||
}
|
||||
if (!TextUtils.isEmpty(camera_not)) {
|
||||
camera_not = camera_not.substring(0, camera_not.length() - 1);
|
||||
}
|
||||
if (!TextUtils.isEmpty(upgrade_ok)) {
|
||||
upgrade_ok = upgrade_ok.substring(0, upgrade_ok.length() - 1);
|
||||
}
|
||||
if (!TextUtils.isEmpty(upgrade_not)) {
|
||||
upgrade_not = upgrade_not.substring(0, upgrade_not.length() - 1);
|
||||
}
|
||||
if (!TextUtils.isEmpty(slide_ok)) {
|
||||
slide_ok = slide_ok.substring(0, slide_ok.length() - 1);
|
||||
}
|
||||
if (!TextUtils.isEmpty(slide_not)) {
|
||||
slide_not = slide_not.substring(0, slide_not.length() - 1);
|
||||
boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", slide_not);
|
||||
Log.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not);
|
||||
} else {
|
||||
boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid");
|
||||
Log.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok);
|
||||
}
|
||||
|
||||
Utils.writeDisableUpdateList(mContext, upgrade_not.split(","), upgrade_ok.split(","));
|
||||
boolean qch_app_power_on = Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", launch);
|
||||
// Intent netControlIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY_DIS);
|
||||
// netControlIntent.putExtra("package_name", net_not);
|
||||
// sendBroadcast(netControlIntent);
|
||||
//
|
||||
// Intent netControlNotIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY);
|
||||
// netControlNotIntent.putExtra("package_name", net_ok);
|
||||
// sendBroadcast(netControlNotIntent);
|
||||
if (!net_not.equals("")) {
|
||||
String[] bans = net_not.split(",");
|
||||
Settings.System.putString(mContext.getContentResolver(), "qch_jgy_network_disallow", net_not);
|
||||
Log.e("fht", "ban::" + net_not);
|
||||
|
||||
}
|
||||
BaseApplication.getInstance().setFinished(true);
|
||||
if (!net_ok.equals("")) {
|
||||
String[] nots = net_ok.split(",");
|
||||
Settings.System.putString(mContext.getContentResolver(), "qch_jgy_network_allow", net_ok);
|
||||
Log.e("fht", "not::" + net_ok);
|
||||
}
|
||||
|
||||
// Intent intent2 = new Intent("qch_camera_forbid");
|
||||
// intent2.putExtra("camera_package_name", camera_not).setPackage("com.android.settings");
|
||||
// sendBroadcast(intent2);
|
||||
// Intent intent1 = new Intent("qch_camera_open");
|
||||
// intent1.putExtra("camera_package_name", camera_ok).setPackage("com.android.settings");
|
||||
// sendBroadcast(intent1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s1 需要管控的ID
|
||||
* @param result 应用程序包名
|
||||
*/
|
||||
public void writeDeselectIDtoSystem(String s1, String result) {
|
||||
if (!TextUtils.isEmpty(s1) && !TextUtils.isEmpty(result)) {
|
||||
String appstore = "com.jiaoguanyi.appstore";
|
||||
String store = "com.jiaoguanyi.store";
|
||||
Log.e("writeDeselectIDtoSystem", "result: " + result);
|
||||
if (!result.contains(appstore)) {
|
||||
result = result + "," + appstore;
|
||||
}
|
||||
if (!result.contains(store)) {
|
||||
result = result + "," + store;
|
||||
}
|
||||
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", result);
|
||||
Settings.System.putString(mContext.getContentResolver(), "DeselectViewArray", s1);
|
||||
Log.e("writeDeselectIDtoSystem", "qch_app_forbid_id" + result);
|
||||
Log.e("writeDeselectIDtoSystem", "deselectViewArray" + s1);
|
||||
} else {
|
||||
Log.e("writeDeselectIDtoSystem", "writeDeselectIDtoSystem is null:");
|
||||
Settings.System.putString(mContext.getContentResolver(), "DeselectViewArray", "Invalid");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setAppinsideWeb(BaseResponse<List<Appground>> response) {
|
||||
if (response.code == 200) {
|
||||
List<Appground> appgrounds = response.data;
|
||||
if (appgrounds != null && appgrounds.size() > 0) {
|
||||
String strings = "";
|
||||
String packageList = "";//单条管控名单
|
||||
for (Appground appground : appgrounds) {
|
||||
if (appground.getAddress().equals("")) {
|
||||
packageList += appground.getPackages() + ",";
|
||||
} else {
|
||||
strings += appground.toString() + ";";
|
||||
}
|
||||
}
|
||||
if (packageList.length() > 0) {
|
||||
//app内所有的网页禁止
|
||||
//packageList = packageList.substring(0, packageList.length() - 1);
|
||||
//去掉多余的,
|
||||
Log.e("setAppinsideWeb ", "packageList:" + packageList);
|
||||
Intent qch_app_website = new Intent("qch_app_website")
|
||||
.setPackage("com.android.settings");
|
||||
qch_app_website.putExtra("package_name", packageList);
|
||||
mContext.sendBroadcast(qch_app_website);
|
||||
} else {
|
||||
sendAllweb(mContext);
|
||||
}
|
||||
if (strings.length() > 0) {
|
||||
//app内单个网页地址禁止打开
|
||||
//strings = strings.substring(0, strings.length() - 1);
|
||||
//去掉多余的;
|
||||
Log.e("setAppinsideWeb ", "strings:" + strings);
|
||||
Intent intent = new Intent("qch_app_inside_website")
|
||||
.setPackage("com.android.settings");
|
||||
intent.putExtra("websitelist", strings);
|
||||
mContext.sendBroadcast(intent);
|
||||
} else {
|
||||
sendwebUrl(mContext);
|
||||
}
|
||||
}
|
||||
} else if (response.code == 400) {
|
||||
//列表为空的情况
|
||||
sendAllweb(mContext);
|
||||
sendwebUrl(mContext);
|
||||
//ToastUtil.show(msg);
|
||||
Log.e("setAppinsideWeb", "setAppinsideWeb: " + response.msg);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void SettingSysData(String data) {
|
||||
SPUtils.put(mContext, "first_connect", 1);
|
||||
SysSettingUtils.setSystemSetting(mContext, data);
|
||||
}
|
||||
|
||||
public void writeAppPackageList(String result) {
|
||||
String appstore = "com.jiaoguanyi.appstore";
|
||||
String store = "com.jiaoguanyi.store";
|
||||
String info = "com.info.sn";
|
||||
// String iflytek = "com.estrongs.android.pop";
|
||||
String jgy1 = "com.uiuios.jgy1";
|
||||
String jgy2 = "com.uiuios.jgy2";
|
||||
if (!TextUtils.isEmpty(result)) {
|
||||
Log.e("writeAppPackageList", "result: " + result);
|
||||
if (!result.contains(appstore)) {
|
||||
result = result + "," + appstore;
|
||||
}
|
||||
if (!result.contains(store)) {
|
||||
result = result + "," + store;
|
||||
}
|
||||
if (!result.contains(jgy1)) {
|
||||
result = result + "," + jgy1;
|
||||
}
|
||||
if (!result.contains(jgy2)) {
|
||||
result = result + "," + jgy2;
|
||||
}
|
||||
if (!result.contains(info)) {
|
||||
result = result + "," + info;
|
||||
}
|
||||
boolean b = Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid", result);
|
||||
Log.e("mjsheng", "qch_app_forbid is :" + b + Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid"));
|
||||
|
||||
} else {
|
||||
Log.e("mjsheng", "writeAppPackageList is null:");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void forceDownload(List<ForceDownloadData> data) {
|
||||
if (data == null || data.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
getSelfDownload(data);
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
ForceDownloadData forceDownloadData = data.get(i);
|
||||
String app_name = forceDownloadData.getApp_name();
|
||||
String app_package = forceDownloadData.getApp_package();
|
||||
String app_url = forceDownloadData.getApp_url();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("app_name", app_name);
|
||||
jsonObject.put("app_package", app_package);
|
||||
int app_version_code = forceDownloadData.getApp_version_code();
|
||||
Log.e("fht ", "packageName=" + app_package + ",URL= " + app_url + ",app_version_code=" + app_version_code);
|
||||
if (data.get(i).getApp_package().equals("com.jiaoguanyi.appstore")) {
|
||||
continue;//为自身的跳过下载
|
||||
}
|
||||
if (!list.contains(app_package)) {
|
||||
list.add(app_package);
|
||||
}
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = pm.getPackageInfo(app_package, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("fht", "forceDownload=" + e.getMessage());
|
||||
}
|
||||
if (packageInfo != null) {
|
||||
long appVersionCode;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
appVersionCode = packageInfo.getLongVersionCode();
|
||||
} else {
|
||||
appVersionCode = packageInfo.versionCode;
|
||||
}
|
||||
if (app_version_code > appVersionCode) {
|
||||
Log.e("fht ", "download URL " + app_url);
|
||||
// Aria.download(this)
|
||||
// .load(app_url) //读取下载地址
|
||||
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(app_package) + ".apk", true)
|
||||
// .setExtendField(jsonObject.toJSONString())
|
||||
// .create(); //启动下载}
|
||||
Utils.ariaDownload(mContext, app_url, jsonObject);
|
||||
}
|
||||
} else {
|
||||
Log.e("fht ", "download URL " + app_url);
|
||||
// if (!SaveListUtils.isDownLoading(app_package)) {
|
||||
// Aria.download(this)
|
||||
// .load(app_url) //读取下载地址
|
||||
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(app_package) + ".apk", true)
|
||||
// .setExtendField(jsonObject.toJSONString())
|
||||
// .create(); //启动下载}
|
||||
Utils.ariaDownload(mContext, app_url, jsonObject);
|
||||
|
||||
// SaveListUtils.addDownLoadList(app_package);
|
||||
// }
|
||||
}
|
||||
}
|
||||
SaveListUtils.setList(list);
|
||||
SaveListUtils.sendForceAPP(mContext);
|
||||
}
|
||||
|
||||
private void getSelfDownload(List<ForceDownloadData> forceDownloadDataList) {
|
||||
for (ForceDownloadData forceDownloadData : forceDownloadDataList) {
|
||||
if ("com.jiaoguanyi.store".equals(forceDownloadData.getApp_package())) {
|
||||
if (!ApkUtils.isAvailable(mContext, "com.jiaoguanyi.store")) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("app_name", forceDownloadData.getApp_name());
|
||||
jsonObject.put("app_package", forceDownloadData.getApp_package());
|
||||
// Aria.download(this)
|
||||
// .load(forceDownloadData.getApp_url()) //读取下载地址
|
||||
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.store") + ".apk", true)
|
||||
// .setExtendField(jsonObject.toJSONString())
|
||||
// .create(); //启动下载}
|
||||
Utils.ariaDownload(mContext, forceDownloadData.getApp_url(), jsonObject);
|
||||
|
||||
}
|
||||
} else {
|
||||
// Log.e("fht", "未上传应用");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param jsonObject 安装应用
|
||||
*/
|
||||
public void installAPK(JsonObject jsonObject) {
|
||||
final String url = jsonObject.get("url").getAsString();
|
||||
int versionCode = jsonObject.get("version_code").getAsInt();
|
||||
final String packageName = jsonObject.get("package").getAsString();
|
||||
String app_name = jsonObject.get("app_name").getAsString();
|
||||
final JSONObject object = new JSONObject();
|
||||
object.put("app_name", app_name);
|
||||
object.put("app_package", packageName);
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = pm.getPackageInfo(packageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (packageInfo == null || packageInfo.versionCode < versionCode) {
|
||||
Utils.ariaDownload(mContext, url, object);
|
||||
} else {
|
||||
Log.e("installAPK", "已是最新版本");
|
||||
}
|
||||
}
|
||||
|
||||
public void installTestAPK(JsonObject jsonObject) {
|
||||
final String url = jsonObject.get("app_url").getAsString();
|
||||
int versionCode = jsonObject.get("app_version_code").getAsInt();
|
||||
final String packageName = jsonObject.get("app_package").getAsString();
|
||||
String app_name = jsonObject.get("app_name").getAsString();
|
||||
final JSONObject object = new JSONObject();
|
||||
object.put("app_name", app_name);
|
||||
object.put("app_package", packageName);
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = pm.getPackageInfo(packageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (packageInfo == null || packageInfo.versionCode < versionCode) {
|
||||
Utils.ariaDownload(mContext, url, object);
|
||||
} else {
|
||||
Log.e("installTestAPK", "TestAPK: " + "无更新");
|
||||
}
|
||||
}
|
||||
|
||||
public void installDesktop(JSONObject jsonObject) {
|
||||
String app_name = jsonObject.getString("app_name");
|
||||
String app_url = jsonObject.getString("app_url");
|
||||
String app_package = jsonObject.getString("app_package");
|
||||
int app_version_code = jsonObject.getInteger("app_version_code");
|
||||
PackageInfo info = null;
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
if (null != packageManager) {
|
||||
try {
|
||||
info = packageManager.getPackageInfo(app_package, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("fht", "installDesktop: " + e.getMessage());
|
||||
}
|
||||
if (null != info) {
|
||||
long versionCode;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
versionCode = info.getLongVersionCode();
|
||||
} else {
|
||||
versionCode = info.versionCode;
|
||||
}
|
||||
if (app_version_code > versionCode) {
|
||||
if (!SaveListUtils.isDownLoading(app_url)) {
|
||||
Utils.ariaDownload(mContext, app_url, jsonObject);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!SaveListUtils.isDownLoading(app_url)) {
|
||||
Utils.ariaDownload(mContext, app_url, jsonObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//删除用户除了在应用市场的其他应用
|
||||
public void deleteOtherApp(String packageList) {
|
||||
Log.e("deleteOtherApp", "packageList:" + packageList);
|
||||
String[] result = packageList.split(",");
|
||||
List<String> resultList = new ArrayList<>(Arrays.asList(result));
|
||||
List<String> packageLists = ApkUtils.queryFilterAppInfo(mContext);
|
||||
|
||||
Log.e("deleteOtherApp", "packageLists:" + packageLists.toString());
|
||||
if (resultList.size() > 0) {
|
||||
for (final String packageName : packageLists) {
|
||||
if (Utils.isSystemApp(mContext, packageName)) {
|
||||
Log.e("deleteOtherApp", "is systemApp:" + packageName);
|
||||
continue;
|
||||
}
|
||||
if (ApkUtils.canremove_systemapp.contains(packageName)) {
|
||||
continue;
|
||||
}
|
||||
if (!resultList.contains(packageName)) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
ApkUtils.uninstall(mContext, packageName);
|
||||
} else {
|
||||
ApkUtils.deleteApkInSilence(packageName);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
Log.e("deleteOtherApp", "uninstall apkName:" + packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从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;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,6 @@ import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mjsheng.myappstore.MyApplication;
|
||||
|
||||
public class ServiceAliveUtils {
|
||||
public static boolean isServiceAlice(Context mContext) {
|
||||
boolean isServiceRunning = false;
|
||||
|
||||
@@ -6,7 +6,7 @@ import androidx.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
||||
import com.mjsheng.myappstore.server.InitJpushServer;
|
||||
import com.mjsheng.myappstore.server.MainService;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
@@ -82,7 +82,7 @@ public class TimeUtils {
|
||||
SPUtils.put(context, START_TIME_KEY, "00:00");
|
||||
SPUtils.put(context, END_TIME_KEY, "00:00");
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(InitJpushServer.TimeChangedReceiver.ACTION_UPDATE);
|
||||
intent.setAction(MainService.TimeChangedReceiver.ACTION_UPDATE);
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ public class ToastUtil {
|
||||
public void run() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
time2 = System.currentTimeMillis();
|
||||
if ((time2 - time1) > 3499) {
|
||||
showToast(mContext, msg, Toast.LENGTH_LONG);
|
||||
if ((time2 - time1) > 3500) {
|
||||
showToast(mContext, msg, Toast.LENGTH_SHORT);
|
||||
Log.e("fht", "LENGTH_LONG");
|
||||
time1 = time2;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,9 @@ import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
@@ -57,7 +59,7 @@ import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.mjsheng.myappstore.R;
|
||||
import com.mjsheng.myappstore.MyApplication;
|
||||
import com.mjsheng.myappstore.base.BaseApplication;
|
||||
import com.mjsheng.myappstore.comm.CommonDatas;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -441,14 +443,14 @@ public class Utils {
|
||||
public static void unInstallAPP(Context context, String packageName) {
|
||||
if (!TextUtils.isEmpty(packageName) && !AppsManagerUtils.isSystemApp(context, packageName)) {
|
||||
if (AppsManagerUtils.isSystemApp(context, packageName)) {
|
||||
Toast.makeText(MyApplication.getAppContext(), R.string.system_unistall_error, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(BaseApplication.getAppContext(), R.string.system_unistall_error, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Uri packageURI = Uri.parse("package:" + packageName);
|
||||
Intent intent = new Intent(Intent.ACTION_DELETE, packageURI);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(MyApplication.getAppContext(), R.string.unistall_error, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(BaseApplication.getAppContext(), R.string.unistall_error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,6 +674,20 @@ public class Utils {
|
||||
return "";
|
||||
}
|
||||
|
||||
//获取教管易版本号
|
||||
public static synchronized String getAPPVersionName(Context context) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
String versionName;
|
||||
try {
|
||||
PackageInfo packageInfo = pm.getPackageInfo("com.jiaoguanyi.store", 0);
|
||||
versionName = packageInfo.versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
versionName = "0";
|
||||
}
|
||||
return versionName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
|
||||
|
||||
Reference in New Issue
Block a user