version:2.0.2.1

update:2020.08.14
fix:修复管控日历隐藏失效,优化待机亮屏卡顿
add:
This commit is contained in:
2020-08-14 18:29:41 +08:00
parent c803fd6353
commit 0dc74d4c41
9 changed files with 455 additions and 38 deletions

View File

@@ -601,6 +601,14 @@ public class ApkUtils {
this.add("com.android.musicfx");
this.add("com.android.email");
}};
public static List<String> show_canremove_systemapp = new ArrayList<String>() {{
//需要管控的系统可以卸载的应用
this.add("com.android.calendar");
this.add("com.android.email");
}};
public static List<String> systemapp = new ArrayList<String>() {{
//需要管控的系统应用
this.add("com.android.gallery3d");//图库
@@ -622,21 +630,72 @@ public class ApkUtils {
// 查询所有已经安装的应用程序
List<PackageInfo> packages = pm.getInstalledPackages(0);
for (PackageInfo packageInfo : packages) {
if (ApkUtils.canremove_systemapp.contains(packageInfo.packageName)) {
//如果是自带可以卸载的,除开不需要管控的
if (canremove_systemapp.contains(packageInfo.packageName)
&& !show_canremove_systemapp.contains(packageInfo.packageName)
) {
continue;
}
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1
&& !systemapp.contains(packageInfo.packageName)
) {
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1 && !systemapp.contains(packageInfo.packageName)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
//10.0上日历和电子邮件是可卸载的
//7.0是系统应用
if (show_canremove_systemapp.contains(packageInfo.packageName)) {
Log.e("showAllAPP2", "packageName:" + packageInfo.packageName);
pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
}
}
} else {
Log.e("showAllAPP", "packageName:" + packageInfo.applicationInfo.packageName);
pm.setApplicationEnabledSetting(packageInfo.applicationInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
Log.e("showAllAPP", "packageName:" + packageInfo.packageName);
hideSystemSettingAPP(context, packageInfo.packageName);
}
}
}
public static void hideSystemSettingAPP(Context context, String pkage) {
int hide = 0;
//后台0显示1隐藏
try {
if (pkage.equalsIgnoreCase("com.mediatek.camera")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_camera") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.deskclock")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_deskclock") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.soundrecorder")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_soundrecorder") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.music")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_music") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.gallery3d")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_gallery") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.documentsui")
|| pkage.equalsIgnoreCase("com.mediatek.filemanager")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_filemanager") == 1) {
hide = 1;
}
}
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
PackageManager pm = context.getPackageManager();
if (hide == 0) {
pm.setApplicationEnabledSetting(pkage, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
} else {
pm.setApplicationEnabledSetting(pkage, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
}
}
public static synchronized void uninstallAllApp(Context context) {
List<String> appList = ApkUtils.queryFilterAppInfo(context);

View File

@@ -0,0 +1,103 @@
package com.mjsheng.myappstore.utils;
import android.text.TextUtils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class CmdUtil {
private static final String TAG = "CmdUtil";
private static final String COMMAND_SH = "sh";
private static final String COMMAND_EXIT = "exit\n";
private static final String COMMAND_LINE_END = "\n";
/**
* 运行命令
*
* @param command 命令
* @return 结果
*/
public static Result execute(String command) {
Log.i(TAG, "execute() command = " + command);
Result result = new Result();
if (TextUtils.isEmpty(command)) {
Log.w(TAG, "WARNING: command should not be null or empty");
return result;
}
Process process = null;
DataOutputStream dos = null;
try {
process = Runtime.getRuntime().exec(COMMAND_SH);
dos = new DataOutputStream(process.getOutputStream());
dos.write(command.trim().getBytes());
dos.writeBytes(COMMAND_LINE_END);
dos.flush();
dos.writeBytes(COMMAND_EXIT);
dos.flush();
result.code = process.waitFor();
result.success = readBuffer(new BufferedReader(new InputStreamReader(process.getInputStream())));
result.error = readBuffer(new BufferedReader(new InputStreamReader(process.getErrorStream())));
Log.i(TAG, "result = " + result);
} catch (IOException ioe) {
ioe.printStackTrace();
Log.e(TAG, ioe.getMessage());
} catch (InterruptedException ie) {
ie.printStackTrace();
Log.e(TAG, ie.getMessage());
} finally {
try {
if (null != dos) {
dos.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
Log.e(TAG, ioe.getMessage());
}
if (null != process) {
process.destroy();
}
}
return result;
}
private static String readBuffer(BufferedReader bufferedReader) throws IOException {
StringBuilder sb = new StringBuilder();
String s;
while ((s = bufferedReader.readLine()) != null) {
sb.append(s);
}
return sb.toString();
}
/**
* Command执行结果
*/
public static final class Result {
public static final int SUCCESS = 0;
public static final int ERROR = -1;
public int code = ERROR;
String error;
String success;
@Override
public String toString() {
return "Result{" +
"code=" + code +
", error='" + error + '\'' +
", success='" + success + '\'' +
'}';
}
}
}

View File

@@ -54,8 +54,10 @@ import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.comm.CommonDatas;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Reader;
@@ -1025,5 +1027,58 @@ public class Utils {
}
}
/**
* 屏幕截图
* 适用于lanucher版
*/
public static void shotScreen() {
//adb截图方法
new Thread(new Runnable() {
@Override
public void run() {
Log.e("whh0914", "开始屏幕截图...");
String filepath = "/sdcard/screenShot.png";
try {
execRootCmdSilent("screencap -p " + filepath);
} catch (Exception e) {
Log.e("whh0914", "屏幕截图出现异常:" + e.toString());
}
}
}).start();
}
/**
* 执行命令但不关注结果输出
*/
public static int execRootCmdSilent(String cmd) {
int result = -1;
DataOutputStream dos = null;
try {
Process p = Runtime.getRuntime().exec("su");
dos = new DataOutputStream(p.getOutputStream());
dos.writeBytes(cmd + "\n");
dos.flush();
dos.writeBytes("exit\n");
dos.flush();
p.waitFor();
result = p.exitValue();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (dos != null) {
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
}