update:2020.12.25

fix:新后台对接完成
add:
This commit is contained in:
2020-12-25 11:09:47 +08:00
parent 4d1eafae8c
commit 79ea8888c1
80 changed files with 3636 additions and 12151 deletions

View File

@@ -38,11 +38,6 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class ApkUtils {
@@ -215,94 +210,94 @@ public class ApkUtils {
}
public static void installRx(final Context context, final String packageName, final String filePath) {
Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> subscriber) {
File file = new File(filePath);
if (filePath == null || filePath.length() == 0 || file == null) {
Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
subscriber.onNext(0);
return;
}
// String[] args = { "pm", "install", "-r", filePath };
String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
// String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
Log.e("fanhuitong", "argss====" + args);
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder();
try {
process = processBuilder.start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
Log.e("mjhseng", "successResult----------" + s);
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
Log.e("mjhseng", "errorResult----------" + s);
errorMsg.append(s);
}
} catch (IOException e1) {
Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
e1.printStackTrace();
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (IOException e1) {
Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
e1.printStackTrace();
}
if (process != null) {
process.destroy();
}
}
if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
subscriber.onNext(2);
} else {
Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
subscriber.onNext(1);
}
}
}).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Integer>() {
@Override
public void onNext(Integer value) {
if (value == 2) {
//安装成功
ToastUtil.show("安装成功");
Log.e("fanhuitong", "-----------安装成功-----------");
} else {
//安装错误
Log.e("fanhuitong", "------------安装错误-----------");
ToastUtil.show("安装失败");
}
}
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
//安装错误
}
});
}
// public static void installRx(final Context context, final String packageName, final String filePath) {
//
// Observable.create(new Observable.OnSubscribe<Integer>() {
// @Override
// public void call(Subscriber<? super Integer> subscriber) {
// File file = new File(filePath);
// if (filePath == null || filePath.length() == 0 || file == null) {
// Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
// subscriber.onNext(0);
// return;
// }
// // String[] args = { "pm", "install", "-r", filePath };
// String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
// // String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
// Log.e("fanhuitong", "argss====" + args);
// ProcessBuilder processBuilder = new ProcessBuilder(args);
// Process process = null;
// BufferedReader successResult = null;
// BufferedReader errorResult = null;
// StringBuilder successMsg = new StringBuilder();
// StringBuilder errorMsg = new StringBuilder();
// try {
// process = processBuilder.start();
// successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
// errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// String s;
// while ((s = successResult.readLine()) != null) {
// Log.e("mjhseng", "successResult----------" + s);
// successMsg.append(s);
// }
// while ((s = errorResult.readLine()) != null) {
// Log.e("mjhseng", "errorResult----------" + s);
// errorMsg.append(s);
// }
// } catch (IOException e1) {
// Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
// e1.printStackTrace();
// } finally {
// try {
// if (successResult != null) {
// successResult.close();
// }
// if (errorResult != null) {
// errorResult.close();
// }
// } catch (IOException e1) {
// Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
// e1.printStackTrace();
// }
// if (process != null) {
// process.destroy();
// }
// }
// if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
// subscriber.onNext(2);
// } else {
// Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
// subscriber.onNext(1);
// }
// }
// }).subscribeOn(Schedulers.newThread())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new Observer<Integer>() {
//
// @Override
// public void onNext(Integer value) {
// if (value == 2) {
// //安装成功
// ToastUtil.show("安装成功");
// Log.e("fanhuitong", "-----------安装成功-----------");
// } else {
// //安装错误
// Log.e("fanhuitong", "------------安装错误-----------");
// ToastUtil.show("安装失败");
// }
// }
//
// @Override
// public void onCompleted() {
//
// }
//
// @Override
// public void onError(Throwable e) {
// //安装错误
// }
// });
// }
// public static void installApp(final String path, final String packageNames){
// File apkFile = new File(path);
@@ -643,4 +638,25 @@ public class ApkUtils {
}
public static int getAppVersionCode(Context context, String packageName) {
PackageManager pm = context.getPackageManager();
PackageInfo info = null;
try {
info = pm.getPackageInfo(packageName, 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;
}
return (int) appVersionCode;
} else {
return 0;
}
}
}

View File

@@ -0,0 +1,88 @@
package com.info.sn.utils;
import android.content.Context;
import android.os.Environment;
import android.util.Log;
import com.alibaba.fastjson.JSONObject;
import com.arialyy.aria.core.Aria;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
public class FileUtils {
public static String getFileNamefromURL(String url) {
int position = url.lastIndexOf("/");
return url.substring(position + 1);
}
public static String getMD5fromFileName(String fileName) {
int position = fileName.lastIndexOf("/");
return fileName.substring(position + 9, fileName.length() - 4);
}
/**
* 获取单个文件的MD5值
*
* @param file 文件
* @return
*/
public static String getFileMD5s(File file) {
if (!file.isFile()) {
return null;
}
MessageDigest digest = null;
FileInputStream in = null;
byte buffer[] = new byte[1024];
int len;
try {
digest = MessageDigest.getInstance("MD5");
in = new FileInputStream(file);
while ((len = in.read(buffer, 0, 1024)) != -1) {
digest.update(buffer, 0, len);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
BigInteger bigInt = new BigInteger(1, digest.digest());
return bigInt.toString(32);
}
public static void ariaDownload(Context context, String url, JSONObject jsonObject) {
String fileName = getFileNamefromURL(url);
String urlMD5 = jsonObject.getString("MD5");
Log.e("ariaDownload", "urlMD5=" + urlMD5);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName);
if (file.exists() && !file.isDirectory()) {
String filenameMD5 = getMD5fromFileName(url);
String fileMD5 = getFileMD5s(file);
Log.e("ariaDownload", "filenameMD5=" + filenameMD5);
Log.e("ariaDownload", "fileMD5=" + fileMD5);
//后端还没有完成json字段的MD5暂时用文件名获取
if (fileMD5.equalsIgnoreCase(filenameMD5)) {
ApkUtils.installApp(context, file.getAbsolutePath());
} else {
Aria.download(context)
.load(url) //读取下载地址
.setFilePath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName, true)
.setExtendField(jsonObject.toJSONString())
.create(); //启动下载}
// SaveListUtils.addDownLoadList(app_package);
// }
}
} else {
Aria.download(context)
.load(url) //读取下载地址
.setFilePath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName, true)
.setExtendField(jsonObject.toJSONString())
.create(); //启动下载}
}
}
}

View File

@@ -4,9 +4,11 @@ import android.util.Log;
import com.info.sn.BuildConfig;
/**
* @author Administrator
*/
public class LogUtils {
static boolean isDebug = BuildConfig.LOG_DEBUG;
// static boolean isDebug = BuildConfig.LOG_DEBUG;
public static void v(String tag, String msg) {
if (isDebug) {

View File

@@ -17,7 +17,7 @@ import java.util.Map;
/**
* 作者 mjsheng
* 日期 2018/10/9 18:41
* 邮箱 278359328@qq.com
* 邮箱 501802639@qq.com
* 来自:
*/
@@ -86,22 +86,23 @@ public class SPUtils {
SharedPreferencesCompat.apply(editor);
}
/**
* 清除所有数据
*/
public static void clear(Context context) {
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.clear();
SharedPreferencesCompat.apply(editor);
reductFirstEnter(context);
}
// /**
// * 清除所有数据
// */
// public static void clear(Context context) {
// SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
// Context.MODE_PRIVATE);
// SharedPreferences.Editor editor = sp.edit();
// editor.clear();
// SharedPreferencesCompat.apply(editor);
// reductFirstEnter(context);
// }
// //还原状态firstEnter信息
// private static void reductFirstEnter(Context context){
// put(context, CommonDatas.FLAG_FIRST_ENTER,CommonDatas.FLAG_FIRST_ENTER);
// }
//还原状态firstEnter信息
private static void reductFirstEnter(Context context){
put(context, CommonData.FLAG_FIRST_ENTER,CommonData.FLAG_FIRST_ENTER);
}
/**
* 查询某个key是否已经存在

View File

@@ -3,14 +3,14 @@ package com.info.sn.utils;
import android.app.ActivityManager;
import android.content.Context;
import com.info.sn.MyApplication;
import com.info.sn.base.MyApplication;
public class ServiceAliveUtils {
public static boolean isServiceAlice() {
boolean isServiceRunning = false;
ActivityManager manager =
(ActivityManager) MyApplication.getInstance().getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
(ActivityManager) MyApplication.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
if (manager == null) {
return true;
}

View File

@@ -1,11 +1,15 @@
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;
@@ -24,133 +28,63 @@ 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.MyApplication;
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 static java.lang.System.getProperty;
public class Utils {
public static final String PACKAGE = "appstore";
public static final String DOWNLOAD_STARTALL_ACTION = PACKAGE + "_startall"; // 开始所有任务
public static final String DOWNLOAD_DELETE_UPDATE_ACTION = PACKAGE + "_download_update_delete"; // 删除应用更新文件
public static final String DOWNLOAD_DELETEALL_ACTION = PACKAGE + "_deleteall_alltask"; // 删除所有任务
public static final String DOWNLOAD_ALLTASK_ACTION = PACKAGE + "_download_alltask"; // 获取所有任务
public static final String DOWNLOAD_START_ACTION = PACKAGE + "_download_start"; // 下载标识
public static final String DOWNLOAD_STOP_ACTION = PACKAGE + "_download_stop"; // 暂停标识
public static final String DOWNLOAD_DELETE_PACKAGENAME_ACTION = PACKAGE + "_download_packagename_delete"; // 删除标识 根据包名
public static final String DOWNLOAD_DELETE_URL_ACTION = PACKAGE + "_download_url_delete"; // 删除标识 根据下载地址
public static final String DOWNLOAD_INITIALIZE_ACTION = PACKAGE + "_download_initialize"; // item初始化状态
public static final String DOWNLOAD_PACKAGENAME_ACTION = PACKAGE + "_download_packagename"; // item初始化状态 包名
public static final String DOWNLOAD_SERVICE_ACTION = PACKAGE + "_download_service"; // 下载状态回调服务
public static final String DOWNLOAD_ALLSERVICE_ACTION = PACKAGE + "_download_allservice"; // 返回所有下载任务
public static final String DOWNLOAD_NEWSERVICE_ACTION = PACKAGE + "_download_newservice"; // 一个新的下载任务
// JPush 推送消息
public static final String MESSAGE_RECEIVED_ACTION = "com.appstore.jpushdemo.MESSAGE_RECEIVED_ACTION";
public static final String KEY_TITLE = "title"; // 消息标题
public static final String KEY_MESSAGE = "message"; // 消息内容
public static final String KEY_EXTRAS = "extras"; // 消息内容类型
public static final String KEY_TYPE = "type"; // 消息内容类型
public static final String ACTION_PACKAGE_REPLACED = PACKAGE + "PACKAGE_REPLACED"; // 替换应用
public static final String ACTION_PACKAGE_REMOVED = PACKAGE + "PACKAGE_REMOVED"; // 卸载应用
public static final String ACTION_PACKAGE_ADDED = PACKAGE + "PACKAGE_ADDED"; // 安装应用
// public static int[] babyImage = {R.drawable.language, R.drawable.habit, R.drawable.knowledge, R.drawable.security, R.drawable.promotion};
// public static int[] childImage = {R.drawable.yuwen, R.drawable.shuxue, R.drawable.yingyu, R.drawable.qingshang, R.drawable.yishu, R.drawable.promotion};
// public static int[] youngImage = {R.drawable.yuwen, R.drawable.shuxue, R.drawable.yingyu, R.drawable.promotion};
// 学习日志上传标识
public static final String APP_LRARNLOG = "com.colorflykids.alarm";
// 学习日志下载标识
public static final String APP_DOWNLOADLEARNLOG = "com.colorflykids.downloadlearnlog";
// 账号注销标识
public static final String APP_USERLOGOUT = "com.colorflykids.userlogout";
public static final String UPDATE_SYSTEMUI = "cn.colorflykids.UPDATE_SYSTEMUI";
public static final int COUNT_ONE_PAGE = 8;
public static final int COUNT_ONE_PAGE2 = 10;
public static final String YOUNGSYSTEM_APP_TONGBU = "com.school.app.syn"; // 小学系统 同步教材app
/**
*
*/
public static final String number[] = {
"1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "0", "11"};
public static final String STORE = "store";
public static final String CATEGORY_THREE = "3";
public static final String CATEGORY_SIX = "6";
public static final String CATEGORY_UPSIX = "10";
public static final String CLOSE_REST_WINDOW = "colse_rest_window";
public static final String STOP_LOOPING_TIMER = "stop_looping_timer";
public static final String START_LOOPING_TIMER = "start_looping_timer";
public static String DOWNLOADAPP_CALLBACK = "com.colorflykids.downloadapp"; // 子界面下载回调 提示更新UI
public static String MENU_YOUYOU = "youyou";
public static String MENU_LANGUAGE = "语言启蒙";
public static String MENU_HABIT = "行为习惯";
public static String MENU_KNOWLEDGE = "生活认知";
public static String MENU_SECURITY = "安全自理";
public static String MENU_PROMOTION = "入园-综合提升";
public static String MENU_LY = "优优乐园";
public static String MENU_YW = "语文知识";
public static String MENU_SX = "数理逻辑";
public static String MENU_YY = "英语启蒙";
public static String MENU_QS = "情商培养";
public static String MENU_YS = "艺术提升";
public static String MENU_ZH = "学前-综合提升";
public static String MENU_TONGBUJIAOCAI = "同步教材";
public static String MENU_YUWEN = "语文";
public static String MENU_SHUXUE = "数学";
public static String MENU_YINGYU = "英语";
public static String MENU_ZONGHETISHEGN = "小学-综合提升";
public static String[] babySystem = {MENU_LANGUAGE, MENU_HABIT, MENU_KNOWLEDGE, MENU_SECURITY, MENU_PROMOTION};
public static String[] childSystem = {MENU_LY, MENU_YW, MENU_SX, MENU_YY, MENU_QS, MENU_YS, MENU_ZH};
public static String[] youngSystem = {MENU_YUWEN, MENU_SHUXUE, MENU_YINGYU, MENU_ZONGHETISHEGN};
public static String[] sonSystem = {MENU_HABIT, MENU_SECURITY, MENU_LANGUAGE, MENU_KNOWLEDGE, MENU_PROMOTION,
MENU_LY, MENU_YW, MENU_SX, MENU_YY, MENU_QS, MENU_YS, MENU_ZH,
MENU_TONGBUJIAOCAI, MENU_YUWEN, MENU_SHUXUE, MENU_YINGYU, MENU_YINGYU, MENU_ZONGHETISHEGN};
public static String[][] tagList = {babySystem, childSystem, youngSystem};
public static String subcategories[][] = {babySystem, childSystem, youngSystem};
public static String system[] = {"入园系统", "学前系统", "小学系统"};
public static String systemandno[] = {"入园系统", "学前系统", "小学系统", "未分配"};
private static final String TAG = "Utils";
protected static Toast toast = null;
private static String oldMsg;
private static long oneTime = 0;
@@ -299,7 +233,6 @@ public class Utils {
}
private static String getSimSerialNumber(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
@SuppressLint("MissingPermission") String simSerialNumber = tm.getSimSerialNumber();
@@ -743,9 +676,9 @@ public class Utils {
}
public static String getSn() {
return Build.SERIAL;
}
// public static String getSn() {
// return Build.SERIAL;
// }
public static Bitmap createQRImage(String content, int widthPix, int heightPix) {
try {
@@ -873,5 +806,599 @@ public class Utils {
// return bgBitmap;
}
private static int changeNum(int status) {
return status == 0 ? 1 : 0;
}
public static void setSystemSetting(Context context, String data) {
if (TextUtils.isEmpty(data)) {
return;
}
SystemSettings settings = JSON.parseObject(data, SystemSettings.class);
if (null != settings) {
setPhoneList(context, settings);
setUSBstate(context, settings);
setBluetooth(context, settings);
setHotspot(context, settings);
setBar(context, settings);
setCamera(context, settings);
setTF(context, settings);
setIcon(context, settings);
}
}
private static void setPhoneList(Context mContext, SystemSettings settings) {
//设置电话功能,电话白名单
int setting_call = changeNum(settings.getSetting_call());
boolean qch_call_forbid = Settings.System.putInt(mContext.getContentResolver(), "qch_call_forbid", setting_call);
Log.e("SystemSetting", "qch_call_forbid:" + qch_call_forbid);
int setting_phone = changeNum(settings.getSetting_phone());
boolean qch_white_list_on = Settings.System.putInt(mContext.getContentResolver(), "qch_white_list_on", setting_phone);
Log.e("SystemSetting", "qch_white_list_on:" + qch_white_list_on);
String setting_phones = settings.getSetting_phones();
boolean qch_white_list_Array = Settings.System.putString(mContext.getContentResolver(), "qch_white_list_Array", setting_phones);
Log.e("SystemSetting", "qch_white_list_Array:" + qch_white_list_Array + "=" + setting_phones);
int setting_memory = changeNum(settings.getSetting_memory());
boolean qch_sdcard_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_sdcard_forbid_on", setting_memory);
Log.e("SystemSetting", "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on);
}
private static void setUSBstate(Context mContext, SystemSettings settings) {
//USB数据功能管控
//仅充电usb_charge
//MTP模式usb_mtp
//Midi模式usb_midi
String setting_usb = settings.getSetting_usb();
if (!BuildConfig.DEBUG) {
try {
boolean qch_usb_choose = Settings.System.putString(mContext.getContentResolver(), "qch_usb_choose", setting_usb);
Log.e("SystemSetting", "qch_usb_choose:" + qch_usb_choose);
String usbStatus = "";
switch (setting_usb) {
case "usb_charge":
usbStatus = "qch_action_usb_usb_charge";
break;
case "usb_mtp":
usbStatus = "qch_action_usb_usb_mtp";
break;
case "usb_midi":
usbStatus = "qch_action_usb_usb_midi";
break;
}
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
mContext.sendBroadcast(usbIntent);
} catch (Exception e) {
Log.e(TAG, "setUSBstate: " + e.getMessage());
}
}
}
private static void setBluetooth(Context mContext, SystemSettings settings) {
try {
//蓝牙开关
int setting_bht = changeNum(settings.getSetting_bht());
//总开关
int setting_bhtvideo = changeNum(settings.getSetting_bhtvideo());
//蓝牙音频开关
int setting_bluetooth = changeNum(settings.getSetting_bluetooth());
//蓝牙传输开关
boolean qch_bht_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_bht_forbid_on", setting_bht);
//写入系统数据库
Log.e("SystemSetting", "qch_bht_forbid_on:" + qch_bht_forbid_on);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (qch_bht_forbid_on) {
//成功
if (null == mBluetoothAdapter) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
//获取默认蓝牙适配器
}
if (setting_bht == 0) {
//蓝牙总开关开启
String setting_context = settings.getSetting_context();
if (setting_bhtvideo == 0) {
if (null != setting_context && !setting_context.equals("") && !setting_context.equals(" ") && !setting_context.equals("null")) {
Log.e("SystemSetting", "setting_context:" + setting_context);
Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", setting_context);
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
}
} else if (setting_bhtvideo == 1) {
Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
}
Settings.System.putInt(mContext.getContentResolver(), "qch_bt_forbid_on", setting_bluetooth);
} else {
mBluetoothAdapter.disable();
//设置关闭时关闭蓝牙
}
}
} catch (Exception e) {
Log.e(TAG, "setBluetooth: " + e.getMessage());
}
}
private static void setHotspot(Context mContext, SystemSettings settings) {
try {
int setting_hotspot = changeNum(settings.getSetting_hotspot());//热点
if (setting_hotspot == 1) {
Intent intent = new Intent();
intent.setAction("qch_hotspot_close");
intent.setPackage("com.android.settings");
mContext.sendStickyBroadcast(intent);
}
boolean qch_hotspot_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_hotspot_forbid_on", setting_hotspot);//写入系统数据库
Log.e("SystemSetting", "qch_hotspot_forbid_on:" + setting_hotspot);
Log.e("SystemSetting", "qch_hotspot_forbid_on:" + qch_hotspot_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setHotspot: " + e.getMessage());
}
}
private static void setBar(Context mContext, SystemSettings settings) {
//系统导航条显示开关
int setting_navigation = changeNum(settings.getSetting_navigation());
boolean qch_hide_navigationBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_NavigationBar", setting_navigation);
Log.e("SystemSetting", "qch_hide_navigationBar:" + qch_hide_navigationBar);
String navigationStatus = "";
switch (setting_navigation) {
case 0:
navigationStatus = "qch_show_NavigationBar";
break;
case 1:
navigationStatus = "qch_hide_NavigationBar";
break;
}
Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(navIntent);
//状态栏显示开关
int setting_statusbar = changeNum(settings.getSetting_statusbar());
int oldNum = Settings.System.getInt(mContext.getContentResolver(), "qch_hide_statusBar", 0);
if (oldNum != setting_statusbar) {
boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar);
Log.e("SystemSetting", "qch_hide_statusBar:" + qch_hide_statusBar);
String statusbarStatus = "";
switch (setting_statusbar) {
case 0:
statusbarStatus = "qch_show_statusBar";
break;
case 1:
statusbarStatus = "qch_hide_statusBar";
break;
}
Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(statusIntent);
}
}
private static void setCamera(Context mContext, SystemSettings settings) {
try {
//摄像头开关
int setting_camera = changeNum(settings.getSetting_camera());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_camera", setting_camera);
// ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.camera");
Log.e("SystemSetting", "setting_camera:" + setting_camera);
String cameraStatus = "";
switch (setting_camera) {
case 0:
cameraStatus = "qch_camera_open";
break;
case 1:
cameraStatus = "qch_camera_forbid";
break;
}
Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings");
mContext.sendBroadcast(cameraIntent);
} catch (Exception e) {
Log.e(TAG, "setCamera: " + e.getMessage());
}
}
private static void setTF(Context mContext, SystemSettings settings) {
try {
//tfmedia开关
int setting_tfmedia = changeNum(settings.getSetting_tfmedia());
boolean qch_tfmedia_forbid = Settings.System.putInt(mContext.getContentResolver(),
"qch_tfmedia_forbid", setting_tfmedia);
Log.e("SystemSetting", "setting_tfmedia:" + qch_tfmedia_forbid);
String tfmediaStatus = "";
switch (setting_tfmedia) {
case 0:
tfmediaStatus = "qch_tfmedia_open";
break;
case 1:
tfmediaStatus = "qch_tfmedia_forbid";
break;
}
Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings");
mContext.sendBroadcast(tfmediaIntent);
if (setting_tfmedia == 1) {
JSONArray jSONArray = null;
jSONArray = JSON.parseArray(settings.getSetting_tfmedia_format());
int i = 0;
StringBuffer stringBuffer = new StringBuffer();
while (!jSONArray.isEmpty()) {
stringBuffer.append(jSONArray.getString(i));
stringBuffer.append(",");
i++;
}
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
Settings.System.putString(mContext.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控
Log.e("SystemSetting", "qch_tfmedia_filetypes---------" + stringBuffer.toString());
} else {
Settings.System.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", 0);
}
} catch (Exception e) {
Log.e(TAG, "setTF: " + e.getMessage());
}
}
private static void setIcon(Context mContext,SystemSettings settings) {
try {
//added:2019.12.6
//设置5个app的开关
//时钟
int deskclock = changeNum(settings.getSetting_clock());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_deskclock", deskclock);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock");
Log.e("SystemSetting", "qch_app_deskclock:" + deskclock);
//录音机
int soundrecorder = changeNum(settings.getSetting_recording());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_soundrecorder", soundrecorder);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder");
Log.e("SystemSetting", "qch_app_soundrecorder:" + soundrecorder);
//音乐
int music = changeNum(settings.getSetting_music());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_music", music);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.music");
Log.e("SystemSetting", "qch_app_music:" + music);
//图库
int gallery = changeNum(settings.getSetting_picture());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_gallery", gallery);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d");
Log.e("SystemSetting", "qch_app_gallery:" + gallery);
//壁纸
int wallpaper = changeNum(settings.getSetting_wallpaper());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_wallpaper", wallpaper);
Log.e("SystemSetting", "qch_app_wallpaper:" + wallpaper);
//文件管理器
int filemanager = changeNum(settings.getSetting_file());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_filemanager", filemanager);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.filemanager");
} else {
ApkUtils.hideSystemSettingAPP(mContext, "com.android.documentsui");
}
Log.e("SystemSetting", "qch_app_filemanager:" + filemanager);
} catch (Exception e) {
Log.e(TAG, "setIcon: " + e.getMessage());
}
}
static synchronized public boolean writeDisableUpdateList(Context context, String[] notList, String[] allowList) {
String now = Settings.System.getString(context.getContentResolver(), "qch_app_forbid");
String[] nowList;
List<String> allList;
if (now == null || now.equalsIgnoreCase("")) {
allList = new ArrayList<>();
} else {
nowList = now.split(",");
allList = new ArrayList<>(Arrays.asList(nowList));//已经写入的列表
}
boolean writeSucceed = false;
if (notList != null && notList.length > 0) {
for (String s : notList) {
if (ApkUtils.isAvailable(context, s)) {
allList.remove(s);
//去掉已经安装的
} else {
if (allList.indexOf(s) == -1) {
allList.add(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);
Log.e("fht", "qch_app_forbid:" + list);
} else {
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", "Invalid");
}
return writeSucceed;
/*功能和应用安装白名单一样首先会写入所有的app名单。
*如果已经安装就从白名单删除,没有安装的不用删除
*不然会出现安装不上的情况
*在写入白名单之后和安装完成之后执行
*/
}
public static String getIMEI(Context context) {
String IMEI = "unknow";
String IMEI1, IMEI2, IMEI3;
//获取手机设备号
TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//8.0及以后版本获取
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
IMEI = TelephonyMgr.getDeviceId();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// try {
// Method method = TelephonyMgr.getClass().getMethod("getImei");
// IMEI = (String) method.invoke(TelephonyMgr);
// } catch (Exception e) {
// e.printStackTrace();
// Log.e("getIMEI", e.getMessage());
// }
// IMEI = TelephonyMgr.getDeviceId();
// } else {//9.0到10.0获取
IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Log.e("IMEI:", "IMEI: " + IMEI);
if (null == IMEI) {
return "-";
} else {
return IMEI.toUpperCase();
}
}
public static String getAndroiodScreenProperty(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getRealMetrics(dm);
int width = dm.widthPixels; // 屏幕宽度(像素)
int height = dm.heightPixels; // 屏幕高度(像素)
float density = dm.density; // 屏幕密度0.75 / 1.0 / 1.5
int densityDpi = dm.densityDpi; // 屏幕密度dpi120 / 160 / 240
// 屏幕宽度算法:屏幕宽度(像素)/屏幕密度
int screenWidth = (int) (width / density); // 屏幕宽度(dp)
int screenHeight = (int) (height / density);// 屏幕高度(dp)
// Log.e("h_bl", "屏幕宽度(像素):" + width);
// Log.e("h_bl", "屏幕高度(像素):" + height);
// Log.e("h_bl", "屏幕密度0.75 / 1.0 / 1.5" + density);
// Log.e("h_bl", "屏幕密度dpi120 / 160 / 240" + densityDpi);
// Log.e("h_bl", "屏幕宽度dp" + screenWidth);
// Log.e("h_bl", "屏幕高度dp" + screenHeight);
return width + "×" + height;
}
public static String getMacAddress() {
List<NetworkInterface> interfaces = null;
try {
interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface networkInterface : interfaces) {
if (networkInterface != null && TextUtils.isEmpty(networkInterface.getName()) == false) {
if ("wlan0".equalsIgnoreCase(networkInterface.getName())) {
byte[] macBytes = networkInterface.getHardwareAddress();
if (macBytes != null && macBytes.length > 0) {
StringBuilder str = new StringBuilder();
for (byte b : macBytes) {
str.append(String.format("%02X:", b));
}
if (str.length() > 0) {
str.deleteCharAt(str.length() - 1);
}
return str.toString();
}
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return "unknown";
}
public static int getBattery(Context context) {
try {
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} catch (Exception e) {
Log.e("getBattery", "getBattery" + e.getMessage());
}
return 0;
}
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);
}
public static int getIsCharging(Context context) {
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
// Are we charging / charged?
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
// How are we charging?
// int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
// boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
// boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
if (isCharging) {
return 1;
} else {
return 0;
}
}
/**
* 描述:获取可用内存.
*
* @param context
* @return
*/
public static long getAvailMemory(Context context) {
// 获取android当前可用内存大小
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
// 当前系统可用内存 ,将获得的内存大小规格化
return memoryInfo.availMem;
}
/**
* 描述:总内存.
*
* @param context
* @return
*/
public static long getTotalMemory(Context context) {
// 系统内存信息文件
String file = "/proc/meminfo";
String memInfo;
String[] strs;
long memory = 0;
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader, 8192);
// 读取meminfo第一行系统内存大小
memInfo = bufferedReader.readLine();
strs = memInfo.split("\\s+");
// for (String str : strs) {
// L.d(AppUtil.class, str + "\t");
// }
// 获得系统总内存单位KB
memory = Integer.valueOf(strs[1]).intValue();
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
// Byte转位KB或MB
return memory * 1024;
}
public static String getRemnantSize(Context context) {
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
long availableSize = sf.getAvailableBytes();
return Formatter.formatFileSize(context, availableSize);
}
public static String getDataTotalSize(Context context) {
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
long blockSize = sf.getBlockSize();
long totalBlocks = sf.getBlockCount();
return Formatter.formatFileSize(context, blockSize * totalBlocks);
}
private static int getNumCores() {
// Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
// Check if filename is "cpu", followed by a single digit number
if (Pattern.matches("cpu[0-9]", pathname.getName())) {
return true;
}
return false;
}
}
try {
// Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
// Filter to only list the devices we care about
File[] files = dir.listFiles(new CpuFilter());
// Return the number of cores (virtual CPU devices)
return files.length;
} catch (Exception e) {
// Default to return 1 core
return 1;
}
}
public static String getMachine(Context context) {
String device = Build.MODEL;//机型
String imei = getIMEI(context);
String system_version = Build.VERSION.RELEASE;
String firmware_version = getProperty("ro.build.display.id", "获取失败");
String rom = getProperty("ro.custom.build.version", "获取失败");
String screen_rate = getAndroiodScreenProperty(context);
JSONObject jsonObject = new JSONObject();
jsonObject.put("device", device);
jsonObject.put("imei", imei);
jsonObject.put("system_version", system_version);
jsonObject.put("firmware_version", firmware_version);
jsonObject.put("rom", rom);
jsonObject.put("screen_rate", screen_rate);
return jsonObject.toJSONString();
}
public static String getHardware(Context context) {
int electric = getBattery(context);
int charging = getIsCharging(context);
String memory = Formatter.formatFileSize(context, getAvailMemory(context)) + "\t 已用" + "/" + "" + Formatter.formatFileSize(context, getTotalMemory(context));
String storage = getRemnantSize(context) + "/" + getDataTotalSize(context);
int CPU = getNumCores();
JSONObject jsonObject = new JSONObject();
jsonObject.put("electric", electric);
jsonObject.put("charging", charging);
jsonObject.put("memory", memory);
jsonObject.put("storage", storage);
jsonObject.put("CPU", CPU + "");
return jsonObject.toJSONString();
}
public static void rebootDevices(Context context) {
Intent iReboot = new Intent(Intent.ACTION_REBOOT);
iReboot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(iReboot);
}
synchronized public static void doMasterClear(Context context) {
if (BuildConfig.DEBUG) {
ToastUtil.show("收到重置设备推送消息");
return;
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
Intent intent = new Intent("android.intent.action.FACTORY_RESET");
intent.setPackage("android");
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.putExtra("android.intent.extra.REASON", "MasterClearConfirm");
intent.putExtra("android.intent.extra.WIPE_EXTERNAL_STORAGE", false);
intent.putExtra("com.android.internal.intent.extra.WIPE_ESIMS", false);
context.sendBroadcast(intent);
} else {
//10.0的不需要最小电量
// if (getBatteryLevel(context) >= CommonDatas.MIN_POWER) {
Intent intent = new Intent("android.intent.action.MASTER_CLEAR");
// intent.setPackage("com.android.settings");
context.sendBroadcast(intent);
// } else {
// MySQLData.SetBooleanData(context, CommonDatas.IS_RESET, true);
// }
}
}
}