adapterView, View view, int i, lon
//获取在后台运行的程序
private void getRunning(int ss){
- ProgressDialog show = showMyDialog(context,"正在获取后台应用,请稍后(可能会出现无响应,请耐心等待)....");
+ ProgressDialog show = du.showMyDialog(context,"正在获取后台应用,请稍后(可能会出现无响应,请耐心等待)....");
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
if(msg.what==0){
- showPKGS(context,lv1,pkginfos,checkboxs);
+ du.showPKGS(context,lv1,pkginfos,checkboxs);
show.dismiss();
}
}
};
Activity activity = this;
Context context =this;
+ processUtils pu = new processUtils();
new Thread(new Runnable() {
@Override
public void run() {
@@ -223,33 +216,21 @@ public void run() {
pkginfos.clear();
//这里是设置了一个阈值参数,如果等于1,就默认列出用户安装的应用,否则就列出所有应用
if(ss == 1){
- multiFunc.queryRunningPKGS(activity,pkginfos,checkboxs,0);
+ pu.queryRunningPKGS(activity,pkginfos,checkboxs,0);
}else{
- multiFunc.queryAllRunningPKGS(activity,pkginfos,checkboxs,0);
+ pu.queryAllRunningPKGS(activity,pkginfos,checkboxs,0);
}
checkRunningPKG(context);
- sendHandlerMSG(handler,0);
+ du.sendHandlerMSG(handler,0);
}
}).start();
}
- /**
- *
- * 进行字符串正则提取
- */
- public String getByString(String src, String regex, String re_str) {
- StringBuilder tmp = new StringBuilder();
- Matcher m = Pattern.compile(regex).matcher(src);
- while (m.find()) {
- tmp.append(m.group().replaceAll(re_str, "") + "\n");
- }
- return tmp.toString();
- }
-
private void checkRunningPKG(Context context){
+ fileTools ft = new fileTools();
String datab="/data/local/tmp/busybox";
- String filesPath = getMyHomeFilesPath(context);
+ String filesPath = ft.getMyHomeFilesPath(context);
if(isADB){
filesPath=context.getExternalCacheDir().toString();
}
@@ -260,14 +241,15 @@ private void checkRunningPKG(Context context){
filesP.mkdirs();
}
if(!busyF.exists()){
- extactAssetsFile(this,"busybox",busyboxFile);
+ ft.extactAssetsFile(this,"busybox",busyboxFile);
}
String cmdstr="chmod 755 "+busyboxFile +" && "+busyboxFile+" ps";
+ shellUtils su = new shellUtils();
if(isADB){
- CMD cmd = getCMD( "cp " + busyboxFile + " "+datab+" && chmod 777 "+datab, false);
+ CMD cmd = su.getCMD( "cp " + busyboxFile + " "+datab+" && chmod 777 "+datab, false);
cmdstr="chmod 777 "+datab+" && "+datab+" ps";
}
- CMD cmd = getCMD(cmdstr,isRoot);
+ CMD cmd = su.getCMD(cmdstr,isRoot);
if(cmd.getResultCode() == 0){
String[] split = cmd.getResult().split("\n");
for (int i = 0; i < pkginfos.size(); i++) {
@@ -283,7 +265,7 @@ private void checkRunningPKG(Context context){
pid=pid.replaceAll("\\s+","");
if(!pid.isEmpty()){
String proc_pid_status_cmd="cat /proc/"+pid+"/status |grep 'VmRSS' | "+(isADB?datab:busyboxFile)+" awk '{print $2}'";
- CMD cmd1 = getCMD(proc_pid_status_cmd,isRoot);
+ CMD cmd1 = su.getCMD(proc_pid_status_cmd,isRoot);
if(cmd1.getResultCode() == 0){
pkginfos.get(i).setFilesize((Long.parseLong(cmd1.getResult().trim())*1024));
}
@@ -297,10 +279,10 @@ private void checkRunningPKG(Context context){
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(Menu.NONE,0,0,"显示所有进程");
- menu.add(Menu.NONE,1,1,"显示用户进程(用户安装的应用)");
- menu.add(Menu.NONE,2,2,"帮助");
- menu.add(Menu.NONE,3,3,"退出");
+ menu.add(Menu.NONE, 0, 0, "显示所有进程");
+ menu.add(Menu.NONE, 1, 1, "显示用户进程(用户安装的应用)");
+ menu.add(Menu.NONE, 2, 2, "帮助");
+ menu.add(Menu.NONE, 3, 3, "退出");
return super.onCreateOptionsMenu(menu);
}
@@ -310,14 +292,12 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (itemId){
case 0 :
getRunning(2);
- showPKGS(context,lv1,pkginfos,checkboxs);
break;
case 1:
getRunning(1);
- showPKGS(context,lv1,pkginfos,checkboxs);
break;
case 2:
- showInfoMsg(this,"帮助信息","该页面是用于后台进程终止,需要root授权。\r\n" +
+ du.showInfoMsg(this,"帮助信息","该页面是用于后台进程终止,需要root授权。\r\n" +
"1.右上角三个点,显示所有进程,会列出所有在后台运行的程序,包括系统应用进程。\r\n" +
"2.右上角三个点,显示用户进程,会列出所有在后台运行的程序,不包括系统应用进程,仅列出用户安装的。\r\n" +
"3.全选,不管有没有勾选,都会操作当前列表所有应用.\r\n" +
diff --git a/app/src/main/java/org/fqaosp/myActivitys/mountLocalImageActivity.java b/app/src/main/java/org/fqaosp/myActivitys/mountLocalImageActivity.java
index b8f946e..68d0493 100644
--- a/app/src/main/java/org/fqaosp/myActivitys/mountLocalImageActivity.java
+++ b/app/src/main/java/org/fqaosp/myActivitys/mountLocalImageActivity.java
@@ -1,11 +1,5 @@
package org.fqaosp.myActivitys;
-import static org.fqaosp.utils.fileTools.extactAssetsFile;
-import static org.fqaosp.utils.fileTools.getMyHomeFilesPath;
-import static org.fqaosp.utils.multiFunc.sendHandlerMSG;
-import static org.fqaosp.utils.multiFunc.showInfoMsg;
-import static org.fqaosp.utils.multiFunc.showMyDialog;
-
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
@@ -34,6 +28,8 @@
import org.fqaosp.R;
import org.fqaosp.adapter.USERAdapter;
import org.fqaosp.utils.CMD;
+import org.fqaosp.utils.dialogUtils;
+import org.fqaosp.utils.fileTools;
import org.fqaosp.utils.fuckActivity;
import org.fqaosp.utils.makeImgToPC;
import org.fqaosp.utils.permissionRequest;
@@ -64,6 +60,8 @@ public class mountLocalImageActivity extends AppCompatActivity {
private Integer filetype2Index=0,sizetypeCMDIndex=0,filetypeIndex=0;
private boolean isRoot = false,isADB=false;
+ private dialogUtils du = new dialogUtils();
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -77,7 +75,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
initBt();
permissionRequest.getExternalStorageManager(mountLocalImageActivity.this);
}else{
- showInfoMsg(this,"提示","本功能需要root才能正常使用");
+ du.showInfoMsg(this,"提示","本功能需要root才能正常使用");
}
}
@@ -114,7 +112,7 @@ public void onClick(View view) {
mliab2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- ProgressDialog show = showMyDialog(context,"正在扫描本地镜像文件,请稍后(可能会出现无响应,请耐心等待)....");
+ ProgressDialog show = du.showMyDialog(context,"正在扫描本地镜像文件,请稍后(可能会出现无响应,请耐心等待)....");
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
@@ -128,7 +126,7 @@ public void handleMessage(@NonNull Message msg) {
@Override
public void run() {
getImgs();
- sendHandlerMSG(handler,0);
+ du.sendHandlerMSG(handler,0);
}
}).start();
}
@@ -144,11 +142,12 @@ public void onClick(View view) {
}
private void checkBusybox(Context context){
- String filesDir =getMyHomeFilesPath(context);
+ fileTools ft = new fileTools();
+ String filesDir =ft.getMyHomeFilesPath(context);
String busyboxFile = filesDir+"/busybox";
File busyF = new File(busyboxFile);
if(!busyF.exists()){
- extactAssetsFile(context,"busybox",busyboxFile);
+ ft.extactAssetsFile(context,"busybox",busyboxFile);
}
}
@@ -204,7 +203,7 @@ public void onNothingSelected(AdapterView> adapterView) {
ab.setNegativeButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
- String filesDir =getMyHomeFilesPath(context);
+ String filesDir =new fileTools().getMyHomeFilesPath(context);
String busyboxFile = filesDir+"/busybox";
String fileName = mlicifaet1.getText().toString().trim();
String fileSize = mlicifaet2.getText().toString().trim();
@@ -277,7 +276,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
switch (itemId){
case 0:
- showInfoMsg(this,"帮助信息","该页面是用于挂载手机上的镜像文件,让电脑识别的,可以当U盘使用,可以给电脑安装系统,需要root权限授权。\r\n" +
+ du.showInfoMsg(this,"帮助信息","该页面是用于挂载手机上的镜像文件,让电脑识别的,可以当U盘使用,可以给电脑安装系统,需要root权限授权。\r\n" +
"1.挂载选中的镜像文件,勾选一个镜像文件,然后手机连接电脑,手机进入开发者模式,选择usb默认配置为存储,然后再点击挂载,然后电脑就会有反应,你就可以进行之后的操作了。\r\n" +
"2.扫描本地镜像文件,点击后,会申请root权限,通过find命令来查找当前设备里面的镜像文件(img/iso)。\r\n" +
"3.创建镜像文件,点击后,会弹出一个窗口,里面有几个必须要填的选项,填完后按“确定”即可生成对应镜像文件。生成后的镜像文件默认存放在内部存储根目录的/Download文件夹里面。\r\n" +
diff --git a/app/src/main/java/org/fqaosp/myActivitys/otherToolsActivity.java b/app/src/main/java/org/fqaosp/myActivitys/otherToolsActivity.java
index e05b35f..dc48bed 100644
--- a/app/src/main/java/org/fqaosp/myActivitys/otherToolsActivity.java
+++ b/app/src/main/java/org/fqaosp/myActivitys/otherToolsActivity.java
@@ -1,12 +1,5 @@
package org.fqaosp.myActivitys;
-import static org.fqaosp.utils.multiFunc.getCMD;
-import static org.fqaosp.utils.multiFunc.isADB;
-import static org.fqaosp.utils.multiFunc.sendHandlerMSG;
-import static org.fqaosp.utils.multiFunc.showCMDInfoMSG;
-import static org.fqaosp.utils.multiFunc.showInfoMsg;
-import static org.fqaosp.utils.multiFunc.showMyDialog;
-
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
@@ -36,8 +29,10 @@
import org.fqaosp.R;
import org.fqaosp.utils.CMD;
+import org.fqaosp.utils.dialogUtils;
import org.fqaosp.utils.fuckActivity;
import org.fqaosp.utils.netUtils;
+import org.fqaosp.utils.shellUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -47,6 +42,8 @@ public class otherToolsActivity extends AppCompatActivity {
private Button otabt1,otabt2,otabt3,otabt4,otabt5,otabt6;
int otrrasp1_index=0,otrrasp2_index=0,otnsasp1_index=0;
private boolean isRoot=false,isADB=false;
+ private dialogUtils du = new dialogUtils();
+ private shellUtils su = new shellUtils();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -74,7 +71,7 @@ private void clickBt(){
Context context = this;
otabt1.setOnClickListener((v)->{
- ProgressDialog show = showMyDialog(context,"正在获取网络时间,请稍后(可能会出现无响应,请耐心等待)....");
+ ProgressDialog show = du.showMyDialog(context,"正在获取网络时间,请稍后(可能会出现无响应,请耐心等待)....");
Handler handler = new Handler(){
@SuppressLint("HandlerLeak")
@Override
@@ -92,9 +89,9 @@ public void handleMessage(@NonNull Message msg) {
try {
String fulltime=year+"-"+formatStr(month)+"-"+formatStr(day)+" "+formatStr(hrs)+":"+formatStr(min)+":"+formatStr(sec);
CMD cmd = new CMD("setprop persist.sys.timezone Asia/Shanghai && date \"" + fulltime + "\";");
- showInfoMsg(context,"信息","执行完毕: \r\n"+cmd.getResultCode()+" -----> "+cmd.getResult()+" \r\n\r\n "+str);
+ du.showInfoMsg(context,"信息","执行完毕: \r\n"+cmd.getResultCode()+" -----> "+cmd.getResult()+" \r\n\r\n "+str);
}catch (Exception e){
- showInfoMsg(context,"错误","执行出错: \r\n"+e.toString()+" \r\n\r\n "+str);
+ du.showInfoMsg(context,"错误","执行出错: \r\n"+e.toString()+" \r\n\r\n "+str);
}
}
@@ -122,7 +119,7 @@ public void run() {
otabt2.setOnClickListener((v)->{
if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.R){
- ProgressDialog show = showMyDialog(context,"正在开启墓碑模式,请稍后(可能会出现无响应,请耐心等待)....");
+ ProgressDialog show = du.showMyDialog(context,"正在开启墓碑模式,请稍后(可能会出现无响应,请耐心等待)....");
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
@@ -151,7 +148,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
@Override
public void run() {
String cmdstr = "device_config put activity_manager_native_boot use_freezer true";
- CMD cmd = getCMD(cmdstr,isRoot);
+ CMD cmd = su.getCMD(cmdstr,isRoot);
Message msg = new Message();
msg.obj=cmd.getResultCode()+" -----> "+cmd.getResult();
msg.what=0;
@@ -159,7 +156,7 @@ public void run() {
}
}).start();
}else{
- showInfoMsg(context,"错误","当前安卓版本不支持该功能,需要安卓11以上才行!");
+ du.showInfoMsg(context,"错误","当前安卓版本不支持该功能,需要安卓11以上才行!");
}
});
@@ -204,7 +201,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
if(sdkInt >=Build.VERSION_CODES.R){
cmdstr = "settings put global captive_portal_mode 0 && settings put global captive_portal_https_url https://www.google.cn/generate_204";
}
- showCMDInfoMSG(context,false,cmdstr,isRoot,"正在去掉信号栏X标记,请稍后(可能会出现无响应,请耐心等待)....","运行结束.");
+ du.showCMDInfoMSG(context,false,cmdstr,isRoot,"正在去掉信号栏X标记,请稍后(可能会出现无响应,请耐心等待)....","运行结束.");
});
@@ -280,7 +277,7 @@ private void checkBts(){
private void checkBt(Button button , boolean needRoot , boolean needADB){
if(isRoot|| (needRoot == false && needADB == false)){
button.setBackgroundColor(Color.rgb(17,179,98));
- }else if(needADB && isADB()){
+ }else if(needADB && su.isADB()){
button.setBackgroundColor(Color.rgb(176,198,39));
}else{
button.setBackgroundColor(Color.rgb(223,90,90));
@@ -323,7 +320,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
}
private void showPriCmdInfoMsg(Context context,DialogInterface dialogInterface ,String cmdstr, String msg){
- ProgressDialog show = showMyDialog(context,msg);
+ ProgressDialog show = du.showMyDialog(context,msg);
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
@@ -331,15 +328,15 @@ public void handleMessage(@NonNull Message msg) {
if(msg.what == 0){
show.dismiss();
dialogInterface.cancel();
- showInfoMsg(context,"信息","已执行结束!\r\n\r\n"+msg.obj.toString());
+ du.showInfoMsg(context,"信息","已执行结束!\r\n\r\n"+msg.obj.toString());
}
}
};
new Thread(new Runnable() {
@Override
public void run() {
- CMD cmd = getCMD(cmdstr,isRoot);
- sendHandlerMSG(handler,0,cmd.getResultCode()+" -----> "+cmd.getResult());
+ CMD cmd = su.getCMD(cmdstr,isRoot);
+ du.sendHandlerMSG(handler,0,cmd.getResultCode()+" -----> "+cmd.getResult());
}
}).start();
}
@@ -369,7 +366,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
switch (itemId){
case 0:
- showInfoMsg(this,"帮助信息","该页面是小工具的合集(部分功能需要重启设备才能生效),有需要root或adb授权的功能,红色是必须root权限才能使用的,黄色则是可以通过adb权限使用。\r\n" +
+ du.showInfoMsg(this,"帮助信息","该页面是小工具的合集(部分功能需要重启设备才能生效),有需要root或adb授权的功能,红色是必须root权限才能使用的,黄色则是可以通过adb权限使用。\r\n" +
"1.同步北京时间: 会联网获取当前北京时间,并且设置本地系统的时间为获取到的时间.\r\n" +
"2.开启墓碑模式: 会通过命令调用系统自带的墓碑模式(cached-apps-freezer),需要重启设备生效.\r\n" +
"3.调整刷新率: 会通过命令调用系统自带的刷新率参数进行设置,用户可以使用固定的几个选项来调整设备的刷新率.\r\n" +
diff --git a/app/src/main/java/org/fqaosp/myActivitys/romToolsActivity.java b/app/src/main/java/org/fqaosp/myActivitys/romToolsActivity.java
index b6d4f5d..5271960 100644
--- a/app/src/main/java/org/fqaosp/myActivitys/romToolsActivity.java
+++ b/app/src/main/java/org/fqaosp/myActivitys/romToolsActivity.java
@@ -1,16 +1,5 @@
package org.fqaosp.myActivitys;
-import static org.fqaosp.utils.fileTools.getMyHomeFilesPath;
-import static org.fqaosp.utils.fileTools.getMyStorageHomePath;
-import static org.fqaosp.utils.multiFunc.checkTools;
-import static org.fqaosp.utils.multiFunc.sendHandlerMSG;
-import static org.fqaosp.utils.multiFunc.showImportToolsDialog;
-import static org.fqaosp.utils.multiFunc.showInfoMsg;
-import static org.fqaosp.utils.multiFunc.showLowMemDialog;
-import static org.fqaosp.utils.multiFunc.showMyDialog;
-import static org.fqaosp.utils.multiFunc.showProcessBarDialogByCMD;
-import static org.fqaosp.utils.multiFunc.showUsers;
-
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
@@ -37,6 +26,8 @@
import org.fqaosp.adapter.FILESHARINGVIEWPAGERAdapter;
import org.fqaosp.entity.PKGINFO;
import org.fqaosp.utils.CMD;
+import org.fqaosp.utils.dialogUtils;
+import org.fqaosp.utils.fileTools;
import org.fqaosp.utils.fuckActivity;
import java.io.File;
@@ -64,6 +55,9 @@ public class romToolsActivity extends AppCompatActivity {
private Context context ;
+ private fileTools ft = new fileTools();
+ private dialogUtils du = new dialogUtils();
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -75,16 +69,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
isRoot = intent.getBooleanExtra("isRoot",false);
isADB = intent.getBooleanExtra("isADB",false);
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT){
- showInfoMsg(this,"警告","该功能暂时不支持安卓4.x设备.");
+ du.showInfoMsg(this,"警告","该功能暂时不支持安卓4.x设备.");
}else{
- String filesDir =getMyHomeFilesPath(this);
- checkTools(this,isADB);
+ String filesDir =ft.getMyHomeFilesPath(this);
+ ft.checkTools(this,isADB);
String fqtoolsusr = filesDir+"/usr";
File fqtoolsusrdir = new File(fqtoolsusr);
if(!fqtoolsusrdir.exists()){
- showImportToolsDialog(this,"fqtools核心无法获取,请退出重试或者重新安装app","fqtools工具包没有找到,功能使用将受到限制或者异常,要继续使用吗?",isRoot,isADB);
+ du.showImportToolsDialog(this,"fqtools核心无法获取,请退出重试或者重新安装app","fqtools工具包没有找到,功能使用将受到限制或者异常,要继续使用吗?",isRoot,isADB);
}
- showLowMemDialog(context);
+ du.showLowMemDialog(context);
initViews();
}
}
@@ -137,12 +131,12 @@ public void onNothingSelected(AdapterView> adapterView) {
});
rrab1.setOnClickListener((v)->{
- ProgressDialog show = showMyDialog(context,"正在扫描本地IMG镜像文件,请稍后(可能会出现无响应,请耐心等待)....");
+ ProgressDialog show = du.showMyDialog(context,"正在扫描本地IMG镜像文件,请稍后(可能会出现无响应,请耐心等待)....");
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
if(msg.what==0){
- showUsers(context,rralv1,list,checkboxs);
+ du.showUsers(context,rralv1,list,checkboxs);
show.dismiss();
}
}
@@ -151,7 +145,7 @@ public void handleMessage(@NonNull Message msg) {
@Override
public void run() {
findROMImgs();
- sendHandlerMSG(handler,0);
+ du.sendHandlerMSG(handler,0);
}
}).start();
@@ -182,12 +176,12 @@ public void onNothingSelected(AdapterView> adapterView) {
});
ruab1.setOnClickListener((v)->{
- ProgressDialog show = showMyDialog(context,"正在扫描本地ROM镜像文件,请稍后(可能会出现无响应,请耐心等待)....");
+ ProgressDialog show = du.showMyDialog(context,"正在扫描本地ROM镜像文件,请稍后(可能会出现无响应,请耐心等待)....");
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
if(msg.what==0){
- showUsers(context,rualv1,list,checkboxs);
+ du.showUsers(context,rualv1,list,checkboxs);
show.dismiss();
}
}
@@ -196,7 +190,7 @@ public void handleMessage(@NonNull Message msg) {
@Override
public void run() {
findROMImgs();
- sendHandlerMSG(handler,0);
+ du.sendHandlerMSG(handler,0);
}
}).start();
@@ -217,7 +211,7 @@ private void btClicked(Context context,View v,int mode){
}
}
- showProcessBarDialogByCMD(context,pplist,"正在"+(mode ==0?"解":"打")+"包ROM","当前正在"+(mode ==0?"解":"打")+"包ROM: ",9,
+ du.showProcessBarDialogByCMD(context,pplist,"正在"+(mode ==0?"解":"打")+"包ROM","当前正在"+(mode ==0?"解":"打")+"包ROM: ",9,
null ,false,false,"0",mode,null,
null, new String[]{getRomType() ,mode==0?getRomPartType():String.valueOf((rom_img_index2_ver+1))});
}
@@ -273,7 +267,7 @@ private void findROMImgs(){
list.clear();
checkboxs.clear();
String storage = Environment.getExternalStorageDirectory().toString();
- String myStorageHomePath = getMyStorageHomePath(this);
+ String myStorageHomePath = ft.getMyStorageHomePath(this);
String cmdstr = "find " + storage + "/ -path \""+storage+"/Android\" -prune -o -name '"+rom_imgs[rom_img_index]+"' -print";
String cmdstr2 = "find " + storage + "/ -path \""+storage+"/Android\" -prune -o -name '*.img' -print && find "+myStorageHomePath+"/ -name '*.img' -print";
CMD cmd = new CMD(viewPageIndex==0? cmdstr:cmdstr2,false);
@@ -296,13 +290,13 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (itemId){
case 0:
if(viewPageIndex == 0){
- showInfoMsg(this,"帮助信息","该功能主要是用于rom包解包,支持payload.bin/system.new.dat/system.new.dat.br/super.img等文件解包。\r\n" +
+ du.showInfoMsg(this,"帮助信息","该功能主要是用于rom包解包,支持payload.bin/system.new.dat/system.new.dat.br/super.img等文件解包。\r\n" +
"1.选择左边下拉栏的文件类型,然后点击右边的扫描选项,即会开始扫描本地匹配的选项。\r\n" +
"2.搜索出结果后,会在下面显示,勾选左边选框再点击解包,就会开始解包当前镜像类型,支持批量解包.\r\n" +
"3.注意,一定要保持rom包本来的结构再使用这个工具,目前还处于测试阶段,后续会逐渐完善.\r\n"
);
}else{
- showInfoMsg(this,"帮助信息","该功能主要是用于本地IMG打包,暂时支持system.new.dat/system.new.dat.br文件格式打包。\r\n" +
+ du.showInfoMsg(this,"帮助信息","该功能主要是用于本地IMG打包,暂时支持system.new.dat/system.new.dat.br文件格式打包。\r\n" +
"1.点击右边的扫描即会开始扫描本地所有匹配的img文件,并在下面列出所有匹配项。\r\n" +
"2.左边下拉框的内容是目前支持的打包格式,例如:system.new.dat,默认会将勾选中的目标img文件打包成system.new.dat类型,下面的br类型同理.\r\n" +
"3.右边下拉框的内容是设置打包的安卓版本,支持安卓5.x至安卓7以上.\r\n" +
diff --git a/app/src/main/java/org/fqaosp/myActivitys/sqliteManageActivity.java b/app/src/main/java/org/fqaosp/myActivitys/sqliteManageActivity.java
index 6bc570e..a625235 100644
--- a/app/src/main/java/org/fqaosp/myActivitys/sqliteManageActivity.java
+++ b/app/src/main/java/org/fqaosp/myActivitys/sqliteManageActivity.java
@@ -1,7 +1,5 @@
package org.fqaosp.myActivitys;
-import static org.fqaosp.utils.multiFunc.showInfoMsg;
-import static org.fqaosp.utils.multiFunc.showMyDialog;
import android.app.Activity;
import android.app.ProgressDialog;
@@ -26,8 +24,8 @@
import org.fqaosp.R;
import org.fqaosp.sql.killAppDB;
+import org.fqaosp.utils.dialogUtils;
import org.fqaosp.utils.fuckActivity;
-import org.fqaosp.utils.multiFunc;
import java.util.ArrayList;
import java.util.HashMap;
@@ -51,6 +49,8 @@ public class sqliteManageActivity extends AppCompatActivity {
private int mode;
+ private dialogUtils du = new dialogUtils();
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -80,7 +80,7 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
ExecutorService cacheThreadPool = Executors.newFixedThreadPool(4);
- ProgressDialog show = showMyDialog(sqliteManageActivity.this,"正在更新数据库,请稍后(可能会出现无响应,请耐心等待)....");
+ ProgressDialog show = du.showMyDialog(sqliteManageActivity.this,"正在更新数据库,请稍后(可能会出现无响应,请耐心等待)....");
new Thread(new Runnable() {
@Override
public void run() {
@@ -234,7 +234,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
mode=0;
break;
case 1:
- showInfoMsg(this,"帮助信息","该页面是用于编辑该软件产生的数据库文件。\r\n" +
+ du.showInfoMsg(this,"帮助信息","该页面是用于编辑该软件产生的数据库文件。\r\n" +
"1.killapp(后台管理),即保存的默认后台进程信息.\r\n" +
"2.应用分身,即保存的应用分身信息。\r\n"
);
diff --git a/app/src/main/java/org/fqaosp/myActivitys/workProfileMenuActivity.java b/app/src/main/java/org/fqaosp/myActivitys/workProfileMenuActivity.java
index 62030c2..b14cdf0 100644
--- a/app/src/main/java/org/fqaosp/myActivitys/workProfileMenuActivity.java
+++ b/app/src/main/java/org/fqaosp/myActivitys/workProfileMenuActivity.java
@@ -1,23 +1,8 @@
package org.fqaosp.myActivitys;
-import static org.fqaosp.utils.multiFunc.getCMD;
-import static org.fqaosp.utils.multiFunc.getProcessBarDialogHandler;
-import static org.fqaosp.utils.multiFunc.getUID;
-import static org.fqaosp.utils.multiFunc.isADB;
-import static org.fqaosp.utils.multiFunc.isSuEnable;
-import static org.fqaosp.utils.multiFunc.preventDismissDialog;
-import static org.fqaosp.utils.multiFunc.sendHandlerMSG;
-import static org.fqaosp.utils.multiFunc.sendHandlerMsg;
-import static org.fqaosp.utils.multiFunc.sendProcessBarHandlerSum;
-import static org.fqaosp.utils.multiFunc.showInfoMsg;
-import static org.fqaosp.utils.multiFunc.showLowMemDialog;
-import static org.fqaosp.utils.multiFunc.showMyDialog;
-import static org.fqaosp.utils.multiFunc.showPKGS;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
-import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherActivityInfo;
@@ -38,7 +23,6 @@
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
-import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -50,9 +34,13 @@
import org.fqaosp.adapter.FILESHARINGVIEWPAGERAdapter;
import org.fqaosp.entity.PKGINFO;
import org.fqaosp.utils.CMD;
+import org.fqaosp.utils.dialogUtils;
import org.fqaosp.utils.fuckActivity;
import org.fqaosp.utils.makeWP;
-import org.fqaosp.utils.multiFunc;
+import org.fqaosp.utils.packageUtils;
+import org.fqaosp.utils.shellUtils;
+import org.fqaosp.utils.textUtils;
+import org.fqaosp.utils.userUtils;
import java.util.ArrayList;
import java.util.HashMap;
@@ -81,6 +69,10 @@ public class workProfileMenuActivity extends AppCompatActivity {
private Context context;
private Activity activity;
+ private dialogUtils du = new dialogUtils();
+ private userUtils uu = new userUtils();
+ private shellUtils su = new shellUtils();
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -89,13 +81,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setTitle("分身部分");
context=this;
activity=this;
- isRoot=isSuEnable();
- if((isRoot || isADB()) && Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT){
+ isRoot=su.isSuEnable();
+ if((isRoot || su.isADB()) && Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT){
initViews();
}else{
- showInfoMsg(this,"提示","本功能需要root或者shizuku授权才能正常使用,不支持安卓4.x设备.");
+ du.showInfoMsg(this,"提示","本功能需要root或者shizuku授权才能正常使用,不支持安卓4.x设备.");
}
- showLowMemDialog(context);
+ du.showLowMemDialog(context);
}
private void initViews() {
@@ -133,7 +125,7 @@ private void initwpf() {
wp.setInitsize(Integer.valueOf(getMaxUserNum().trim()));
}
editText1.setHint("请输入需要开启的数量,默认最高"+wp.getInitsize()+"个");
- showInfoMsg(context,"警告","分身部分不能一次性开启太多,不然的话会闪退或者无响应");
+ du.showInfoMsg(context,"警告","分身部分不能一次性开启太多,不然的话会闪退或者无响应");
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -146,22 +138,19 @@ public void onClick(View view) {
sb.append("i=0;while((i<"+num+"));do ((i++)); "+wp.getCreateWPCMD()+";done");
showProcessDialogCMDByWP(context,addPKGS(0,false),checkboxsByUser,wpfmUserList,sb.toString(),"正在创建分身空间","当前正在安装: ",0,0,isRoot);
}else{
- showInfoMsg(context,"警告","请输入 " + wp.getInitsize() + " 以内并且大于0的数值");
+ du.showInfoMsg(context,"警告","请输入 " + wp.getInitsize() + " 以内并且大于0的数值");
}
}
});
b2.setOnClickListener((v)->{
- searchStr(editText2,activity,wpfLv);
+ du.showIndexOfPKGSDialog(context,activity,wpfLv,editText2,pkginfos,null,checkboxs);
});
wpfLv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView> adapterView, View view, int i, long l) {
- PKGINFO pkginfo = pkginfos.get(i);
- ClipboardManager cpm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
- cpm.setText(pkginfo.toString());
- Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
+ new textUtils().copyText(context,pkginfos.get(i).toString());
return false;
}
});
@@ -193,12 +182,6 @@ private ArrayList addPKGS(int wpmode,Boolean isDel){
return pplist;
}
- private void searchStr(EditText editText2,Activity activity,ListView lv){
- String searchStr = editText2.getText().toString();
- pkginfos = multiFunc.indexOfPKGS(activity, searchStr, pkginfos, checkboxs, 0);
- showPKGS(context,lv,pkginfos,checkboxs);
- }
-
//分身管理
private void initwpfm() {
Button b1 = wpfm.findViewById(R.id.wpmanageab1);
@@ -217,7 +200,7 @@ private void initwpfm() {
});
b3.setOnClickListener((v)->{
- searchStr(et1,activity,wpfmLv2);
+ du.showIndexOfPKGSDialog(context,activity,wpfmLv2,et1,pkginfos,null,checkboxs);
});
wpfmLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@@ -255,33 +238,14 @@ private void wpfrBtClicked(Context context,View view,boolean delall){
private String getMaxUserNum(){
String cmdstr = "pm get-max-users|cut -d':' -f2";
- CMD cmd = getCMD( cmdstr, isRoot);
+ CMD cmd = su.getCMD( cmdstr, isRoot);
return cmd.getResult();
}
- private void getUserEnablePKGS() {
- multiFunc.queryUserEnablePKGS(this, pkginfos, checkboxs, 0);
- }
-
- //获取启用的应用程序
- private void getEnablePKGS() {
- multiFunc.queryEnablePKGS(this, pkginfos, checkboxs, 0);
- }
-
- private void getPKGS() {
- //提取所有已安装的应用列表
- multiFunc.queryPKGS(this, pkginfos, checkboxs, 0);
- }
-
- private void getUserPKGS() {
- //提取所有已安装的应用列表
- multiFunc.queryUserPKGS(this, pkginfos, checkboxs, 0);
- }
-
private void getUsers() {
clearUser();
//查询用户
- multiFunc.queryUSERS(this, wpfmUserList, checkboxsByUser);
+ uu.queryUSERS(activity, wpfmUserList, checkboxsByUser);
}
//启动已经创建好的分身用户
@@ -297,12 +261,12 @@ private void getPKGByUID(Integer state) {
if (wpfmUserList.size() == 0) {
getUsers();
}
- ProgressDialog show = showMyDialog(context, "正在检索用户下安装的应用,请稍后(可能会出现无响应,请耐心等待)....");
+ ProgressDialog show = du.showMyDialog(context, "正在检索用户下安装的应用,请稍后(可能会出现无响应,请耐心等待)....");
Handler handler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
if (msg.what == 0) {
- showPKGS(context,wpfmLv2,pkginfos,checkboxs);
+ du.showPKGS(context,wpfmLv2,pkginfos,checkboxs);
show.dismiss();
}
}
@@ -316,7 +280,7 @@ public void run() {
if (state == 1) {
cmdstr = wp.getUserPkgByUIDCMD(uid);
}
- multiFunc.getPKGByUID(context,cmdstr,pkginfos,pkginfoHashMap,checkboxs,isRoot);
+ new packageUtils().getPKGByUID(context,cmdstr,pkginfos,pkginfoHashMap,checkboxs,isRoot);
}
pkginfos.clear();
checkboxs.clear();
@@ -324,7 +288,7 @@ public void run() {
for (PKGINFO pkginfo : pkginfos) {
checkboxs.add(false);
}
- sendHandlerMSG(handler, 0);
+ du.sendHandlerMSG(handler, 0);
}
}).start();
}
@@ -384,23 +348,19 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
case 0:
switch (itemId) {
case 0:
- getEnablePKGS();
- showPKGS(context,wpfLv,pkginfos,checkboxs);
+ du.queryPKGProcessDialog(context,activity,wpfLv,pkginfos,checkboxs,0,null,isRoot);
break;
case 1:
- getPKGS();
- showPKGS(context,wpfLv,pkginfos,checkboxs);
+ du.queryPKGProcessDialog(context,activity,wpfLv,pkginfos,checkboxs,1,null,isRoot);
break;
case 2:
- getUserPKGS();
- showPKGS(context,wpfLv,pkginfos,checkboxs);
+ du.queryPKGProcessDialog(context,activity,wpfLv,pkginfos,checkboxs,2,null,isRoot);
break;
case 3:
- getUserEnablePKGS();
- showPKGS(context,wpfLv,pkginfos,checkboxs);
+ du.queryPKGProcessDialog(context,activity,wpfLv,pkginfos,checkboxs,3,null,isRoot);
break;
case 4:
- showInfoMsg(this, "帮助信息", "该页面是用于应用分身的,需要root授权。\r\n" +
+ du.showInfoMsg(this, "帮助信息", "该页面是用于应用分身的,需要root授权。\r\n" +
"1.右上角三个点,显示安装应用,会列出当前用户已经安装的应用。\r\n" +
"2.开启数量,由用户自己输入,但不能超过默认的最高1024个,不然会出错。\r\n" +
"3.搜索框支持中英文搜索,不区分大小写.\r\n" +
@@ -415,20 +375,16 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
case 1:
switch (itemId) {
case 0:
- getEnablePKGS();
- showPKGS(context,wpfmLv2,pkginfos,checkboxs);
+ du.queryPKGProcessDialog(context,activity,wpfmLv2,pkginfos,checkboxs,0,null,isRoot);
break;
case 1:
- getPKGS();
- showPKGS(context,wpfmLv2,pkginfos,checkboxs);
+ du.queryPKGProcessDialog(context,activity,wpfmLv2,pkginfos,checkboxs,1,null,isRoot);
break;
case 2:
- getUserPKGS();
- showPKGS(context,wpfmLv2,pkginfos,checkboxs);
+ du.queryPKGProcessDialog(context,activity,wpfmLv2,pkginfos,checkboxs,2,null,isRoot);
break;
case 3:
- getUserEnablePKGS();
- showPKGS(context,wpfmLv2,pkginfos,checkboxs);
+ du.queryPKGProcessDialog(context,activity,wpfmLv2,pkginfos,checkboxs,3,null,isRoot);
break;
case 4:
getPKGByUID(0);
@@ -437,14 +393,29 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
getPKGByUID(1);
break;
case 6:
- getUsers();
- multiFunc.showUsers(context,wpfmLv,wpfmUserList,checkboxsByUser);
+ ProgressDialog show = du.showMyDialog(context,"正在获取其它用户(请稍后...)");
+ Handler handler = new Handler(){
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ if(msg.what==0){
+ show.dismiss();
+ du.showUsers(context,wpfmLv,wpfmUserList,checkboxsByUser);
+ }
+ }
+ };
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ getUsers();
+ du.sendHandlerMSG(handler,0);
+ }
+ }).start();
break;
case 7:
startupUsers();
break;
case 8:
- showInfoMsg(this, "帮助信息", "该页面是用于管理分身应用的,需要root授权。\r\n" +
+ du.showInfoMsg(this, "帮助信息", "该页面是用于管理分身应用的,需要root授权。\r\n" +
"1.右上角三个点,显示主用户安装应用,会列出当前用户已经安装的应用。\r\n" +
"2.右上角三个点,显示其它用户安装应用,会列出当其它分身用户已经安装的应用,但是不会显示多余的,遇到重复的会只列出一个。\r\n" +
"3.同步安装一个应用到分身,从当前主用户已安装的应用当中,批量勾选安装到其它分身用户下面。\r\n" +
@@ -463,11 +434,26 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
case 2:
switch (itemId) {
case 0:
- getUsers();
- multiFunc.showUsers(context,wpfrLv,wpfmUserList,checkboxsByUser);
+ ProgressDialog show = du.showMyDialog(context,"正在获取其它用户(请稍后...)");
+ Handler handler = new Handler(){
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ if(msg.what==0){
+ show.dismiss();
+ du.showUsers(context,wpfrLv,wpfmUserList,checkboxsByUser);
+ }
+ }
+ };
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ getUsers();
+ du.sendHandlerMSG(handler,0);
+ }
+ }).start();
break;
case 1:
- showInfoMsg(this, "帮助信息", "该页面是用于删除分身的,需要root授权。\r\n" +
+ du.showInfoMsg(this, "帮助信息", "该页面是用于删除分身的,需要root授权。\r\n" +
"1.右上角三个点,显示分身用户,会列出除了当前主用户外的其它用户。\r\n" +
"2.全删了,点击后,会删除列表里所有用户。\r\n" +
"3.删除分身,需要勾选相应分身才能删除,不勾选就不删除。\r\n"
@@ -496,8 +482,8 @@ private void showProcessDialogCMDByWP(Context context , ArrayList pplis
dpbtv2.setText("1");
AlertDialog alertDialog = builder.create();
alertDialog.show();
- preventDismissDialog(alertDialog);
- Handler mUpdateProgressHandler = getProcessBarDialogHandler(context,mProgressBar,alertDialog,dpbtv1,dpbtv2,dpbtv3,text);
+ du.preventDismissDialog(alertDialog);
+ Handler mUpdateProgressHandler = du.getProcessBarDialogHandler(context,mProgressBar,alertDialog,dpbtv1,dpbtv2,dpbtv3,text);
new Thread(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@@ -508,12 +494,12 @@ public void run() {
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
ArrayList userList = getExistsUsers(um);
//初始化初始用户数量
- CMD cmd = getCMD(sb,isRoot);
+ CMD cmd = su.getCMD(sb,isRoot);
if(cmd.getResultCode()==0){
- sendHandlerMsg(mUpdateProgressHandler,4,"现在正在安装应用到分身空间里面");
- sendHandlerMsg(mUpdateProgressHandler,5,size+"");
+ du.sendHandlerMsg(mUpdateProgressHandler,4,"现在正在安装应用到分身空间里面");
+ du.sendHandlerMsg(mUpdateProgressHandler,5,size+"");
for (UserHandle userHandle : um.getUserProfiles()) {
- String uid = getUID(userHandle.toString());
+ String uid = uu.getUID(userHandle.toString());
//如果用户不在之前获取的列表里面,那么就开始同步选中的应用程序到新建的用户空间下
if(haveUser(userList,uid)){
hidePKGS(userHandle,isRoot);
@@ -522,13 +508,13 @@ public void run() {
for (int i = 0; i < pplist.size(); i++) {
PKGINFO pkginfo = pplist.get(i);
- sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
+ du.sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
for (UserHandle userHandle : um.getUserProfiles()) {
- String uid = getUID(userHandle.toString());
+ String uid = uu.getUID(userHandle.toString());
//如果用户不在之前获取的列表里面,那么就开始同步选中的应用程序到新建的用户空间下
if(haveUser(userList,uid)){
String cmdstr = wp.getInstallPkgCMD(uid, pkginfo.getPkgname())+" && "+wp.getStartWPCMD(uid);
- CMD getcmd = getCMD(cmdstr, isRoot);
+ CMD getcmd = su.getCMD(cmdstr, isRoot);
}
}
}
@@ -536,10 +522,10 @@ public void run() {
}
if(wpmode == 1){
- sendHandlerMsg(mUpdateProgressHandler,5,size+"");
+ du.sendHandlerMsg(mUpdateProgressHandler,5,size+"");
for (int i = 0; i < pplist.size(); i++) {
PKGINFO pkginfo = pplist.get(i);
- sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
+ du.sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
for (int i1 = 0; i1 < checkboxsByUser.size(); i1++) {
if (checkboxsByUser.get(i1)) {
String cmdstr = null;
@@ -549,7 +535,7 @@ public void run() {
if(wpmode2 ==1){
cmdstr = wp.getUninstallPkgByUIDCMD(wpfmUserList.get(i1), pkginfo.getPkgname());
}
- CMD getcmd = getCMD(cmdstr, isRoot);
+ CMD getcmd = su.getCMD(cmdstr, isRoot);
}
}
}
@@ -557,22 +543,22 @@ public void run() {
}
if(wpmode == 2){
- sendHandlerMsg(mUpdateProgressHandler,5,size+"");
+ du.sendHandlerMsg(mUpdateProgressHandler,5,size+"");
for (int i = 0; i < pplist.size(); i++) {
PKGINFO pkginfo = pplist.get(i);
- sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
+ du.sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
String cmdstr = "pm remove-user "+pkginfo.getPkgname();
- CMD getcmd = getCMD(cmdstr, isRoot);
+ CMD getcmd = su.getCMD(cmdstr, isRoot);
}
}
if(wpmode == 3){
- sendHandlerMsg(mUpdateProgressHandler,5,size+"");
+ du.sendHandlerMsg(mUpdateProgressHandler,5,size+"");
for (int i = 0; i < pplist.size(); i++) {
PKGINFO pkginfo = pplist.get(i);
- sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
+ du.sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
String cmdstr = "am start-user "+pkginfo.getPkgname();
- CMD getcmd = getCMD(cmdstr, isRoot);
+ CMD getcmd = su.getCMD(cmdstr, isRoot);
}
}
@@ -592,8 +578,8 @@ private void hidePKGS(UserHandle userHandle,Boolean isRoot){
for (LauncherActivityInfo launcherActivityInfo : activityList) {
sb.append("\""+launcherActivityInfo.getApplicationInfo().packageName+"\" ");
}
- sb.append(");for aa in ${aaa[@]};do pm hide --user "+getUID(userHandle.toString())+" $aa ;done;");
- CMD cmd = getCMD( sb.toString(), isRoot);
+ sb.append(");for aa in ${aaa[@]};do pm hide --user "+uu.getUID(userHandle.toString())+" $aa ;done;");
+ CMD cmd = su.getCMD( sb.toString(), isRoot);
}
}
@@ -601,7 +587,7 @@ private ArrayList getExistsUsers(UserManager um){
ArrayList userList = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
for (UserHandle userHandle : um.getUserProfiles()) {
- userList.add(getUID(userHandle.toString()));
+ userList.add(uu.getUID(userHandle.toString()));
}
}
return userList;
diff --git a/app/src/main/java/org/fqaosp/utils/appopsCmdStr.java b/app/src/main/java/org/fqaosp/utils/appopsCmdStr.java
index fa8f5b6..b1d2196 100644
--- a/app/src/main/java/org/fqaosp/utils/appopsCmdStr.java
+++ b/app/src/main/java/org/fqaosp/utils/appopsCmdStr.java
@@ -2,12 +2,18 @@
import android.os.Build;
+import org.fqaosp.entity.PKGINFO;
+
+import java.util.ArrayList;
+
public class appopsCmdStr {
private String localTmpFile="/data/local/tmp/fqaosp.apk";
private String rm_local_tmp_file="rm -rf "+localTmpFile;
private String install_cmd_head=rm_local_tmp_file+" && cp \"";
private String install_cmd_end="\" " + localTmpFile +" && chmod 777 "+localTmpFile;
+ public appopsCmdStr(){}
+
public String getInstallLocalPkgCMD(String uid , String apkPath){
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT){
return install_cmd_head+apkPath+install_cmd_end+" && pm install " + localTmpFile+" && "+rm_local_tmp_file;
@@ -63,4 +69,280 @@ public String enableAppByAPPUIDCMD(int pkguid){
return cmd;
}
+ public static String getRunTraverseCMDStr(ArrayList pkginfos, ArrayList checkboxs , String cmdstr){
+ int hit=0;
+ StringBuilder sb = new StringBuilder();
+ sb.append("aaa=(");
+ for (int i = 0; i < checkboxs.size(); i++) {
+ if(checkboxs.get(i)){
+ sb.append("\""+pkginfos.get(i).getPkgname()+"\" ");
+ hit++;
+ }
+ }
+ if(hit == 0){
+ for (PKGINFO pkginfo : pkginfos) {
+ sb.append("\""+pkginfo.getPkgname()+"\" ");
+ }
+ }
+
+ sb.append(");for pp in ${aaa[@]};do "+cmdstr+";done;");
+ return sb.toString();
+ }
+
+
+ //调用命令对选项进行相应授权、撤销操作
+ public String getRunAppopsCMD(String pkgname,String pkgcate , int ss ,String uid){
+ String cmdstr = "";
+ if(pkgcate.indexOf("$") != -1){
+ pkgcate = pkgcate.replaceAll("\\$","\\\\\\$");
+ }
+ switch (ss){
+ case 0:
+ if(uid == null){
+ cmdstr="pm revoke "+pkgname + " " + pkgcate;
+ }else{
+ cmdstr="pm revoke --user "+uid + " "+pkgname + " " + pkgcate;
+ }
+ break;
+ case 1:
+ case 2:
+ if(uid == null){
+ cmdstr="pm disable \"" +pkgname+"/"+ pkgcate+"\"";
+ }else{
+ cmdstr="pm disable --user "+uid+" \"" +pkgname+"/"+ pkgcate+"\"";
+ }
+
+ break;
+ case 3:
+ if(uid == null){
+ cmdstr="pm grant "+pkgname + " " + pkgcate;
+ }else{
+ cmdstr="pm grant --user " + uid + " " +pkgname + " " + pkgcate;
+ }
+ break;
+ case 4:
+ case 5:
+ if(uid == null){
+ cmdstr="pm enable " +pkgname+"/"+ pkgcate;
+ }else{
+ cmdstr="pm enable --user "+uid + " \"" +pkgname+"/"+ pkgcate+"\"";
+ }
+ break;
+ }
+ return cmdstr;
+ }
+
+ public String getRunAppopsBySwtichCMD(Boolean b,int mode ,String pkgname,String pkgcate , String uid){
+ String cmdstr = null;
+ if(b){
+ switch (mode){
+ case 0:
+ case 1:
+ cmdstr = getRunAppopsCMD(pkgname,pkgcate,4,uid);
+ break;
+ case 2:
+ cmdstr = getRunAppopsCMD(pkgname,pkgcate,3,uid);
+ break;
+ }
+ }else{
+ switch (mode){
+ case 0:
+ case 1:
+ cmdstr = getRunAppopsCMD(pkgname,pkgcate,1,uid);
+ break;
+ case 2:
+ cmdstr = getRunAppopsCMD(pkgname,pkgcate,0,uid);
+ break;
+ }
+ }
+ return cmdstr;
+ }
+
+
+ //拼接命令参数字符串
+ public String spliceCMDStr(PKGINFO pkginfo,int mode , int apops_opt_index,int apops_permis_index){
+ StringBuilder sb = new StringBuilder();
+ String cmdHead = "appops set --uid "+pkginfo.getPkgname()+" ";
+ String cmdWrite = "appops write-settings ";
+ String modestr="";
+
+ if(mode == 0){
+ switch (apops_opt_index){
+ case 0:
+ modestr = "default";
+ break;
+ case 1:
+ modestr = "ignore";
+ break;
+ case 2:
+ modestr = "allow";
+ break;
+ case 3:
+ modestr = "foreground";
+ break;
+ }
+ }
+ if(mode ==1){
+ switch (apops_opt_index){
+ case 0:
+ modestr = "true";
+ break;
+ case 1:
+ modestr = "false";
+ break;
+ }
+ }
+ if(mode ==2){
+ switch (apops_opt_index){
+ case 0:
+ modestr = "active";
+ break;
+ case 1:
+ modestr = "working_set";
+ break;
+ case 2:
+ modestr = "frequent";
+ break;
+ case 3:
+ modestr = "rare";
+ break;
+ case 4:
+ modestr = "restricted";
+ break;
+ }
+ }
+
+ switch (apops_permis_index){
+ case 0 :
+ sb.append(cmdHead+" READ_PHONE_STATE "+modestr+";");
+ sb.append(cmdHead+" READ_CONTACTS "+modestr+";");
+ sb.append(cmdHead+" WRITE_CONTACTS "+modestr+";");
+ sb.append(cmdHead+" READ_CALL_LOG "+modestr+";");
+ sb.append(cmdHead+" WRITE_CALL_LOG "+modestr+";");
+ sb.append(cmdHead+" CALL_PHONE "+modestr+";");
+ sb.append(cmdHead+" READ_SMS "+modestr+";");
+ sb.append(cmdHead+" WRITE_SMS "+modestr+";");
+ sb.append(cmdHead+" SEND_SMS "+modestr+";");
+ sb.append(cmdHead+" RECEIVE_SMS "+modestr+";");
+ sb.append(cmdHead+" RECEIVE_EMERGECY_SMS "+modestr+";");
+ sb.append(cmdHead+" RECEIVE_MMS "+modestr+";");
+ sb.append(cmdHead+" RECEIVE_WAP_PUSH "+modestr+";");
+ sb.append(cmdHead+" READ_ICC_SMS "+modestr+";");
+ sb.append(cmdHead+" WRITE_ICC_SMS "+modestr+";");
+ sb.append(cmdHead+" PROCESS_OUTGOING_CALLS "+modestr+";");
+ sb.append(cmdHead+" READ_CELL_BROADCASTS "+modestr+";");
+ sb.append(cmdHead+" android:add_voicemail "+modestr+";");
+ sb.append(cmdHead+" android:answer_phone_calls "+modestr+";");
+ sb.append(cmdHead+" android:call_phone "+modestr+";");
+ sb.append(cmdHead+" android:read_call_log "+modestr+";");
+ sb.append(cmdHead+" android:read_contacts "+modestr+";");
+ sb.append(cmdHead+" android:read_cell_broadcasts "+modestr+";");
+ sb.append(cmdHead+" android:read_phone_numbers "+modestr+";");
+ sb.append(cmdHead+" android:read_phone_state "+modestr+";");
+ sb.append(cmdHead+" android:read_sms "+modestr+";");
+ sb.append(cmdHead+" android:receive_mms "+modestr+";");
+ sb.append(cmdHead+" android:receive_sms "+modestr+";");
+ sb.append(cmdHead+" android:receive_wap_push "+modestr+";");
+ sb.append(cmdHead+" android:send_sms "+modestr+";");
+ sb.append(cmdHead+" android:write_call_log "+modestr+";");
+ sb.append(cmdHead+" android:write_contacts "+modestr+";");
+ sb.append(cmdHead+" android:process_outgoing_calls "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.CALL_LOG "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.CONTACTS "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.PHONE "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.SMS "+modestr+";");
+ break;
+ case 1:
+ sb.append(cmdHead+" READ_EXTERNAL_STORAGE "+modestr+";");
+ sb.append(cmdHead+" WRITE_EXTERNAL_STORAGE "+modestr+";");
+ sb.append(cmdHead+" ACCESS_MEDIA_LOCATION "+modestr+";");
+ sb.append(cmdHead+" LEGACY_STORAGE "+modestr+";");
+ sb.append(cmdHead+" WRITE_MEDIA_AUDIO "+modestr+";");
+ sb.append(cmdHead+" READ_MEDIA_AUDIO "+modestr+";");
+ sb.append(cmdHead+" WRITE_MEDIA_VIDEO "+modestr+";");
+ sb.append(cmdHead+" READ_MEDIA_VIDEO "+modestr+";");
+ sb.append(cmdHead+" READ_MEDIA_IMAGES "+modestr+";");
+ sb.append(cmdHead+" WRITE_MEDIA_IMAGES "+modestr+";");
+ sb.append(cmdHead+" MANAGE_EXTERNAL_STORAGE "+modestr+";");
+ sb.append(cmdHead+" android:picture_in_picture "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.READ_MEDIA_AURAL "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.READ_MEDIA_VISUAL "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.READ_MEDIA_VISUAL "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.STORAGE "+modestr+";");
+ break;
+ case 2:
+ sb.append(cmdHead+" READ_CLIPBOARD "+modestr+";");
+ sb.append(cmdHead+" WRITE_CLIPBOARD "+modestr+";");
+ break;
+ case 3:
+ sb.append(cmdHead+" RUN_ANY_IN_BACKGROUND "+modestr+";");
+ break;
+ case 4:
+ sb.append(cmdHead+" RUN_IN_BACKGROUND "+modestr+";");
+ break;
+ case 5:
+ sb.append(cmdHead+" CAMERA "+modestr+";");
+ sb.append(cmdHead+" android:camera "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.CAMERA "+modestr+";");
+ break;
+ case 6:
+ sb.append(cmdHead+" RECORD_AUDIO "+modestr+";");
+ sb.append(cmdHead+" android:record_audio "+modestr+";");
+ sb.append(cmdHead+" TAKE_AUDIO_FOCUS "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.MICROPHONE "+modestr+";");
+ break;
+ case 7:
+ sb.append(cmdHead+" COARSE_LOCATION "+modestr+";");
+ sb.append(cmdHead+" FINE_LOCATION "+modestr+";");
+ sb.append(cmdHead+" android:coarse_location "+modestr+";");
+ sb.append(cmdHead+" android:fine_location "+modestr+";");
+ sb.append(cmdHead+" android:mock_location "+modestr+";");
+ sb.append(cmdHead+" android:monitor_location_high_power "+modestr+";");
+ sb.append(cmdHead+" android:monitor_location "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.LOCATION "+modestr+";");
+ break;
+ case 8:
+ sb.append(cmdHead+" READ_CALENDAR "+modestr+";");
+ sb.append(cmdHead+" WRITE_CALENDAR "+modestr+";");
+ sb.append(cmdHead+" android:write_calendar "+modestr+";");
+ sb.append(cmdHead+" android:read_calendar "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.CALENDAR "+modestr+";");
+ break;
+ case 9:
+ sb.append(cmdHead+" WIFI_SCAN "+modestr+";");
+ sb.append(cmdHead+" android:use_sip "+modestr+";");
+ sb.append(cmdHead+" BLUETOOTH_SCAN "+modestr+";");
+ sb.append(cmdHead+" BLUETOOTH_ADVERTISE "+modestr+";");
+ sb.append(cmdHead+" BLUETOOTH_CONNECT "+modestr+";");
+ sb.append(cmdHead+" BLUETOOTH_ADMIN "+modestr+";");
+ sb.append(cmdHead+" BLUETOOTH "+modestr+";");
+ sb.append(cmdHead+" NEARBY_DEVICES "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.NEARBY_DEVICES "+modestr+";");
+ sb.append(cmdHead+" android.permission-group.SENSORS "+modestr+";");
+ break;
+ case 10:
+ sb.append(cmdHead+" android.permission-group.NOTIFICATIONS "+modestr+";");
+ sb.append(cmdHead+" ACCESS_NOTIFICATIONS "+modestr+";");
+ sb.append(cmdHead+" POST_NOTIFICATION "+modestr+";");
+ sb.append(cmdHead+" android.permission.POST_NOTIFICATIONS "+modestr+";");
+ break;
+ case 11:
+ sb.append("am set-inactive "+pkginfo.getPkgname()+" "+modestr);
+ break;
+ case 12:
+ sb.append("am set-standby-bucket "+pkginfo.getPkgname()+" " + modestr );
+ break;
+ case 13:
+ appopsCmdStr acs = new appopsCmdStr();
+ sb.append(modestr.equals("true")?acs.enableAppByAPPUIDCMD(Integer.valueOf(pkginfo.getApkuid().trim())):acs.disableAppByAPPUIDCMD(Integer.valueOf(pkginfo.getApkuid().trim())));
+ break;
+ }
+ if(apops_permis_index < 11){
+ sb.append(cmdWrite);
+ }
+ return sb.toString();
+ }
+
+
+
}
diff --git a/app/src/main/java/org/fqaosp/utils/dialogUtils.java b/app/src/main/java/org/fqaosp/utils/dialogUtils.java
new file mode 100644
index 0000000..f451f48
--- /dev/null
+++ b/app/src/main/java/org/fqaosp/utils/dialogUtils.java
@@ -0,0 +1,481 @@
+package org.fqaosp.utils;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+
+import org.fqaosp.R;
+import org.fqaosp.adapter.PKGINFOAdapter;
+import org.fqaosp.adapter.USERAdapter;
+import org.fqaosp.entity.PKGINFO;
+import org.fqaosp.myActivitys.importToolsActivity;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class dialogUtils {
+
+ private fileTools ft = new fileTools();
+
+ public dialogUtils(){}
+
+ public void queryPKGProcessDialog(Context context,Activity activity,ListView lv1 , ArrayList pkginfos,ArrayList checkboxs,Integer mode,String cmdstr,boolean isRoot) {
+ queryPKGProcessDialog(context,activity,"正在获取本地应用列表(请稍后...)",lv1,pkginfos,null,checkboxs,mode,cmdstr,isRoot);
+ }
+
+ public void queryPKGProcessDialog(Context context,Activity activity,ListView lv1 , ArrayList pkginfos,HashMap pkginfoHashMap,ArrayList checkboxs,Integer mode,String cmdstr,boolean isRoot) {
+ queryPKGProcessDialog(context,activity,"正在获取本地应用列表(请稍后...)",lv1,pkginfos,pkginfoHashMap,checkboxs,mode,cmdstr,isRoot);
+ }
+
+ public void queryPKGProcessDialog(Context context, Activity activity, String msg, ListView lv1 , ArrayList pkginfos, HashMap pkginfoHashMap, ArrayList checkboxs, Integer mode, String cmdstr, boolean isRoot){
+ packageUtils pkgutils = new packageUtils();
+ ProgressDialog show = showMyDialog(context,msg);
+ Handler handler = new Handler(){
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ if(msg.what==0){
+ show.dismiss();
+ showPKGS(context,lv1,pkginfos,checkboxs);
+ }
+ }
+ };
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+
+ if(mode != null){
+ switch (mode){
+ case 0:
+ pkgutils.queryEnablePKGS(activity,pkginfos,checkboxs,0);
+ break;
+ case 1:
+ pkgutils.queryPKGS(activity,pkginfos,checkboxs,0);
+ break;
+ case 2:
+ pkgutils.queryUserEnablePKGS(activity,pkginfos,checkboxs,0);
+ break;
+ case 3:
+ pkgutils.queryUserPKGS(activity,pkginfos,checkboxs,0);
+ break;
+ case 4:
+ pkgutils.queryDisablePKGS(activity,pkginfos,checkboxs,0);
+ break;
+ }
+ }else if(cmdstr != null && mode == null ){
+ pkgutils.getPKGByUID(context,cmdstr,pkginfos,pkginfoHashMap,checkboxs,isRoot);
+ }
+
+ pkgutils.sortPKGINFOS(pkginfos);
+ sendHandlerMSG(handler,0);
+ }
+ }).start();
+
+ }
+
+
+ public void showIndexOfPKGSDialog(Context context , Activity activity, ListView lv1 , EditText editText , ArrayList pkginfos, ArrayList strList, ArrayList checkboxs) {
+ showIndexOfPKGSDialog(context,activity,lv1,"正在搜索(请稍后....)",editText,pkginfos,strList,checkboxs);
+ }
+
+ public void showIndexOfPKGSDialog(Context context , Activity activity,ListView lv1,String msg , EditText editText , ArrayList pkginfos,ArrayList strList,ArrayList checkboxs){
+ ProgressDialog show = showMyDialog(context,msg);
+ Handler handler = new Handler(){
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ if(msg.what==0){
+ if(strList == null){
+ showPKGS(context,lv1,pkginfos,checkboxs);
+ }else{
+ showUsers(context,lv1,strList,checkboxs);
+ }
+ show.dismiss();
+ }
+ }
+ };
+ textUtils txtutils = new textUtils();
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ if(strList == null){
+ pkginfos.addAll(txtutils.indexOfPKGS(activity,editText.getText().toString(),pkginfos,checkboxs,0));
+ }else{
+ strList.addAll(txtutils.indexOfLIST(strList,checkboxs,editText.getText().toString()));
+ }
+ sendHandlerMSG(handler,0);
+ }
+ }).start();
+
+ }
+
+ public Handler dismissDialogHandler(int value,ProgressDialog show){
+ return new Handler(){
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ if(msg.what==value){
+ show.dismiss();
+ }
+ }
+ };
+ }
+
+
+
+ public void showCMDInfoMSG(Context context,boolean isOutLog,String cmdstr,Boolean isRoot,String msg,String msg2){
+ ProgressDialog progressDialog = showMyDialog(context, msg);
+ Handler handler = new Handler(){
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ super.handleMessage(msg);
+ if(msg.what == 0){
+ progressDialog.dismiss();
+ if(isOutLog){
+ showInfoMsg(context,"提示",msg2+" : \r\n\r\n"+msg.obj.toString());
+ }else{
+ showInfoMsg(context,"提示",msg2);
+ }
+
+ }
+ }
+ };
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ CMD cmd = new shellUtils().getCMD(cmdstr,isRoot);
+ sendHandlerMSG(handler,0,cmd.getResultCode()+"---->"+cmd.getResult());
+ }
+ }).start();
+
+ }
+
+ public void sendHandlerMSG(Handler handler , int value){
+ Message msg = new Message();
+ msg.what=value;
+ handler.sendMessage(msg);
+ }
+
+ public void sendHandlerMSG(Handler handler , int value,Object obj){
+ Message msg = new Message();
+ msg.what=value;
+ msg.obj=obj;
+ handler.sendMessage(msg);
+ }
+
+
+ //显示提示框
+ public ProgressDialog showMyDialog(Context context, String msg){
+ ProgressDialog pd = new ProgressDialog(context);//初始化等待条
+ pd.setMessage(msg);//等待显示条的信息
+ pd.setCanceledOnTouchOutside(false);
+ pd.setCancelable(false);
+ pd.show();//等待显示条
+ return pd;
+ }
+
+
+ public void showImportToolsDialog(Context context,String toastMsg , String msg,Boolean isRoot,Boolean isADB){
+ Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
+ AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
+ alertDialog.setTitle("警告");
+ alertDialog.setMessage(msg);
+ alertDialog.setPositiveButton("继续", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ dialogInterface.dismiss();
+ }
+ });
+ alertDialog.setNegativeButton("补全功能组件", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ dialogInterface.dismiss();
+ multiFunc m = new multiFunc();
+ m.jump(context, importToolsActivity.class,isRoot,isADB);
+ }
+ });
+ alertDialog.show();
+ }
+
+ public void sendHandlerMsg(Handler handler,int n,Object obj){
+ Message message = new Message();
+ message.what=n;
+ message.obj=obj;
+ handler.sendMessage(message);
+ }
+
+ public Handler getProcessBarDialogHandler(Context context , ProgressBar mProgressBar, AlertDialog alertDialog, TextView dpbtv1, TextView dpbtv2, TextView dpbtv3, String text){
+ return new Handler() {
+
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case 0:
+ // 设置进度条
+ mProgressBar.setProgress((int)msg.obj);
+ break;
+ case 1:
+ // 隐藏当前下载对话框
+ permittedDismissDialog(alertDialog);
+ showInfoMsg(context,"提示","已运行完毕,请手动刷新.");
+ break;
+ case 2:
+ PKGINFO pkginfo = (PKGINFO) msg.obj;
+ dpbtv3.setText(text+(pkginfo.getAppname()==null?pkginfo.getPkgname():pkginfo.getAppname()));
+ break;
+ case 3:
+ dpbtv1.setText(((int)(msg.obj))+"");
+ break;
+ case 4:
+ alertDialog.setTitle(msg.obj.toString());
+ break;
+ case 5:
+ dpbtv2.setText(msg.obj.toString());
+ break;
+ case 6:
+ permittedDismissDialog(alertDialog);
+ showInfoMsg(context,"错误",msg.obj.toString());
+ break;
+ }
+ }
+ };
+ }
+
+ public void sendProcessBarHandlerSum(Handler handler,int i , int size , PKGINFO pkginfo){
+ // 计算进度条当前位置
+ sendHandlerMsg(handler,0,(int) (((float) i / size) * 100));
+ sendHandlerMsg(handler,3,i);
+ sendHandlerMsg(handler,2,pkginfo);
+ }
+
+ public void showProcessBarDialogByCMD(Context context, ArrayList list,String title,String text , int ppmode,Integer install_mode,Boolean isDisable,Boolean isRoot,String uid,Integer mode , Integer apops_opt_index,Integer apops_permis_index,String...parm){
+ String app_cache_storage = context.getExternalCacheDir().toString();
+ String scriptName="fqtools.sh";
+ makeWP makewp = new makeWP();
+ StringBuilder sb = new StringBuilder();
+ sb.append(" ");
+ if(parm !=null && parm.length > 0){
+ for (int i = 0; i < parm.length; i++) {
+ sb.append(parm[i]+" ");
+ }
+ }
+ if(ppmode == 9){
+ sb.setLength(0);
+ }
+ int size = list.size();
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(title);
+ View vvv = LayoutInflater.from(context).inflate(R.layout.download_process_bar, null);
+ ProgressBar mProgressBar = (ProgressBar) vvv.findViewById(R.id.dpbpb);
+ TextView dpbtv1 = vvv.findViewById(R.id.dpbtv1);
+ TextView dpbtv2 = vvv.findViewById(R.id.dpbtv2);
+ TextView dpbtv3 = vvv.findViewById(R.id.dpbtv3);
+ builder.setView(vvv);
+ AlertDialog alertDialog = builder.create();
+ alertDialog.show();
+ preventDismissDialog(alertDialog);
+ dpbtv2.setText(size+"");
+ Handler mUpdateProgressHandler = getProcessBarDialogHandler(context,mProgressBar,alertDialog,dpbtv1,dpbtv2,dpbtv3,text);
+ appopsCmdStr acs = new appopsCmdStr();
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ String outDir=null;
+ String filesDir =ft.getMyHomeFilesPath(context);
+ if(isRoot == false){
+ filesDir=context.getExternalFilesDir(null).toString();
+ }
+ String barfile = filesDir+"/"+scriptName;
+ for (int i = 1; i <= size; i++) {
+ PKGINFO pkginfo = list.get(i - 1);
+ sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
+ String cmdstr=null;
+ switch (ppmode){
+ case 0:
+ cmdstr = isDisable?makewp.getChangePkgOnEnableByUIDCMD(uid, pkginfo.getPkgname()):makewp.getChangePkgOnDisableByUIDCMD(uid,pkginfo.getPkgname());
+ break;
+ case 1:
+ cmdstr = makewp.getUninstallPkgByUIDCMD(uid, pkginfo.getPkgname());
+ break;
+ case 2:
+ cmdstr = acs.spliceCMDStr(pkginfo,mode,apops_opt_index,apops_permis_index);
+ break;
+ case 3:
+ switch (install_mode){
+ case 0:
+ cmdstr = acs.getInstallLocalPkgCMD(uid, pkginfo.getApkpath());
+ break;
+ case 1:
+ cmdstr = acs.getInstallLocalPkgOnDowngradeCMD(uid, pkginfo.getApkpath());
+ break;
+ case 2:
+ cmdstr = acs.getInstallLocalPkgOnDebugCMD(uid, pkginfo.getApkpath());
+ break;
+ case 3:
+ cmdstr = acs.getInstallLocalPkgOnExistsCMD(uid, pkginfo.getApkpath());
+ break;
+ }
+ break;
+ case 4:
+ cmdstr = acs.getInstallLocalPkgOnExistsCMD(uid,pkginfo.getApkpath());
+ break;
+ case 5:
+ cmdstr = "am force-stop "+pkginfo.getPkgname();
+ break;
+ case 6:
+ cmdstr = "sh "+barfile+" backup "+pkginfo.getPkgname() +" "+sb.toString()+ " "+uid;
+ break;
+ case 7:
+ cmdstr = "sh "+barfile+" restory "+pkginfo.getPkgname() +" "+sb.toString()+ " "+uid;
+ break;
+ case 8:
+ if(mode == 0){
+ String filePath = pkginfo.getApkpath();
+ String outname = new File(filePath).getName();
+ outDir = app_cache_storage + "/recompile";
+ File file = new File(outDir);
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+ String outFile = outDir + "/" + outname + ".apk";
+ cmdstr = "cd " + filesDir + " && sh fqtools.sh apktool reapk "+ filePath+ " " + outFile ;
+ }
+
+ if(mode == 1){
+ String filePath = pkginfo.getApkpath();
+ PackageManager packageManager = context.getPackageManager();
+ PackageInfo archiveInfo = packageManager.getPackageArchiveInfo(filePath, 0);
+ String pkgname = archiveInfo.packageName;
+ outDir = app_cache_storage + "/decompile/" + pkgname;
+ cmdstr = "cd " + filesDir + " && sh fqtools.sh apktool deapk " + filePath+ " " + outDir ;
+ }
+ break;
+ case 9:
+ outDir = app_cache_storage+"/"+(mode ==0 ?"romunpack":"romrepack");
+ String path = pkginfo.getApkpath();
+ String outdir = outDir+"/"+System.currentTimeMillis();
+ File file = new File(outdir);
+ if(!file.exists()){
+ file.mkdirs();
+ }
+ if(mode ==0){
+ cmdstr = "cd "+filesDir+" && sh fqtools.sh unpackrom "+parm[0] + " " +path + " " + outdir + " " + parm[1];
+ }
+ if(mode ==1){
+ cmdstr = "cd "+filesDir+" && sh fqtools.sh repackrom "+path+ " " + outdir + " " +parm[0] + " " + parm[1];
+ }
+ sb.append(path+" -----> "+outdir+".\r\n");
+ break;
+ case 11:
+ String outpath = app_cache_storage+"/"+pkginfo.getPkgname()+".apk";
+ ft.copyFile(pkginfo.getApkpath(),outpath);
+ break;
+ }
+ if(ppmode == 8 || ppmode == 9){
+ CMD cmd = new CMD(cmdstr, false);
+ int code = cmd.getResultCode();
+ if(ppmode == 9 && code != 0){
+ String ff=outDir+"/"+System.currentTimeMillis()+".log";
+ ft.writeDataToPath(cmd.toString(),ff,false);
+ sendHandlerMSG(mUpdateProgressHandler,6,(mode==0?"解":"打")+"包失败,日志存放在 >> "+ff);
+ }
+ }else if(ppmode == 10){
+ CMD cmd = new CMD(acs.getRunAppopsBySwtichCMD(pkginfo.getAppversionname().equals("true")?true:false,mode,pkginfo.getPkgname(),pkginfo.getAppname(),uid));
+ }else{
+ CMD cmd = new shellUtils().getCMD(cmdstr, isRoot);
+ }
+
+ }
+ mUpdateProgressHandler.sendEmptyMessage(1);
+ }
+ }).start();
+ }
+
+
+
+ /**
+ * 通过反射 阻止关闭对话框
+ */
+ public void preventDismissDialog(AlertDialog ddd) {
+ try {
+ Field field = ddd.getClass().getSuperclass().getDeclaredField("mShowing");
+ field.setAccessible(true);
+ //设置mShowing值,欺骗android系统
+ field.set(ddd, false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 关闭对话框
+ */
+ public void permittedDismissDialog(AlertDialog ddd) {
+ try {
+ Field field = ddd.getClass().getSuperclass().getDeclaredField("mShowing");
+ field.setAccessible(true);
+ field.set(ddd, true);
+ } catch (Exception e) {
+ }
+ ddd.dismiss();
+ }
+
+ public void showLowMemDialog(Context context){
+ showLowMemDialog(context,"警告","当前设备配置较低,运行此页面功能会出现问题!");
+ }
+
+ public void showLowMemDialog(Context context,String title , String msg){
+ ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
+ ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
+ activityManager.getMemoryInfo(memoryInfo);
+ if(activityManager.isLowRamDevice() || (memoryInfo != null && (memoryInfo.totalMem*1.0/(1024*1024)) < 4096)){
+ showInfoMsg(context,title,msg);
+ }
+ }
+
+ //显示一个弹窗
+ public void showInfoMsg(Context con,String title , String msg){
+ AlertDialog.Builder ab = new AlertDialog.Builder(con);
+ ab.setTitle(title);
+ ab.setMessage(msg);
+ ab.setNegativeButton("确定", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ dialogInterface.cancel();
+ }
+ });
+
+ AlertDialog alertDialog = ab.create();
+ alertDialog.show();
+ TextView tv = alertDialog.getWindow().getDecorView().findViewById(android.R.id.message);
+ tv.setTextIsSelectable(true);
+ }
+
+ //显示检索完毕后的应用列表
+ public void showPKGS(Context context , ListView listView,ArrayList pkginfos,ArrayList checkboxs) {
+ PKGINFOAdapter pkginfoAdapter = new PKGINFOAdapter(pkginfos, context, checkboxs);
+ listView.setAdapter(pkginfoAdapter);
+ }
+
+ //显示检索完毕后的字符串列表
+ public void showUsers(Context context ,ListView listView,ArrayList userList,ArrayList checkboxsByUser) {
+ USERAdapter userAdapter = new USERAdapter(userList, context, checkboxsByUser);
+ listView.setAdapter(userAdapter);
+ }
+
+}
diff --git a/app/src/main/java/org/fqaosp/utils/fileTools.java b/app/src/main/java/org/fqaosp/utils/fileTools.java
index 6248c88..863947f 100644
--- a/app/src/main/java/org/fqaosp/utils/fileTools.java
+++ b/app/src/main/java/org/fqaosp/utils/fileTools.java
@@ -1,6 +1,8 @@
package org.fqaosp.utils;
+
import android.app.Activity;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
@@ -8,6 +10,7 @@
import android.os.Build;
import android.os.Environment;
import android.util.Log;
+import android.webkit.MimeTypeMap;
import android.widget.Toast;
import androidx.documentfile.provider.DocumentFile;
@@ -33,23 +36,49 @@
public class fileTools {
- private final static String TAG = "fileTools";
+ private String TAG = "fileTools";
+ public fileTools(){
- //获取文件大小,带单位
- public static String getSize(double size, int count) {
- String size_type[] = {"b", "KB", "MB", "GB", "TB", "PB"};
- if (size > 1024) {
- double d_size = size / 1024;
- count = count + 1;
- return getSize(d_size, count);
+ }
+
+
+ public void checkTools(Context context,boolean isADB){
+ fileTools ft = new fileTools();
+ String filesDir = ft.getMyHomeFilesPath(context);
+ if(isADB){
+ filesDir=context.getExternalFilesDir(null).toString();
}
- String sizestr = String.format("%.2f", size) + size_type[count];
- return sizestr;
+ String scriptName = "fqtools.sh";
+ String barfile = filesDir+"/"+scriptName;
+ String busyFile = filesDir+"/busybox";
+ String extractScriptFile = filesDir+"/extract.sh";
+ File busyfile = new File(busyFile);
+ File barFile = new File(barfile);
+ File extractScriptFilef = new File(extractScriptFile);
+ if(!busyfile.exists()){
+ if(Build.CPU_ABI.equals("arm64-v8a")){
+ ft.extactAssetsFile(context,"busybox",busyFile);
+ }else if(Build.CPU_ABI.equals("armeabi-v7a") || Build.CPU_ABI2.equals("armeabi")){
+ ft.extactAssetsFile(context,"busybox_arm",busyFile);
+ }
+ }
+ if(!barFile.exists()){
+ ft.extactAssetsFile(context,scriptName,barfile);
+ }
+
+ if(!extractScriptFilef.exists()) {
+ ft.extactAssetsFile(context, "extract.sh", extractScriptFile);
+ }
+
+ if(isADB){
+ CMD cmd = new shellUtils().getCMD("cp " + busyFile + " /data/local/tmp/", false);
+ }
+
}
//读取文件
- public static String readFileToPath(String filePath) {
+ public String readFileToPath(String filePath) {
StringBuilder stringBuilder = new StringBuilder();
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath));
@@ -65,7 +94,7 @@ public static String readFileToPath(String filePath) {
}
//读取文件
- public static Boolean writeDataToPath(String data, String filePath, Boolean isApp) {
+ public Boolean writeDataToPath(String data, String filePath, Boolean isApp) {
try {
FileWriter writer = null;
if (isApp) {
@@ -83,7 +112,7 @@ public static Boolean writeDataToPath(String data, String filePath, Boolean isAp
}
//释放资源文件
- public static void extactAssetsFile(Context context, String fileName, String toPath) {
+ public void extactAssetsFile(Context context, String fileName, String toPath) {
AssetManager assets = context.getAssets();
InputStream stream = null;
try {
@@ -96,7 +125,7 @@ public static void extactAssetsFile(Context context, String fileName, String toP
}
//根据路径获得document文件
- public static DocumentFile getDoucmentFileOnData(Context context, String path) {
+ public DocumentFile getDoucmentFileOnData(Context context, String path) {
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
@@ -105,7 +134,7 @@ public static DocumentFile getDoucmentFileOnData(Context context, String path) {
}
//根据路径获得document文件
- public static DocumentFile getDoucmentFileOnObb(Context context, String path) {
+ public DocumentFile getDoucmentFileOnObb(Context context, String path) {
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
@@ -114,7 +143,7 @@ public static DocumentFile getDoucmentFileOnObb(Context context, String path) {
}
//调用系统文件选择器选择一个文件夹
- public static void execDirSelect(Context context, Activity activity, String msg) {
+ public void execDirSelect(Context context, Activity activity, String msg) {
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT){
execFileSelect(context,activity,msg,43);
@@ -124,11 +153,11 @@ public static void execDirSelect(Context context, Activity activity, String msg)
}
}
- public static void execFileSelect(Context context, Activity activity, String msg){
+ public void execFileSelect(Context context, Activity activity, String msg){
execFileSelect(context,activity,msg,0);
}
//调用系统文件选择器
- public static void execFileSelect(Context context, Activity activity, String msg,int code) {
+ public void execFileSelect(Context context, Activity activity, String msg,int code) {
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
@@ -139,19 +168,19 @@ public static void execFileSelect(Context context, Activity activity, String msg
}
//获取在内部存储的自家路径
- public static String getMyStorageHomePath(Context context) {
+ public String getMyStorageHomePath(Context context) {
return context.getExternalFilesDir(null).getParent();
}
//获取自家data的files路径
- public static String getMyHomeFilesPath(Context context) {
+ public String getMyHomeFilesPath(Context context) {
return context.getFilesDir().toString();
}
//选择文件时,判断是否为理想类型
- public static void selectFile(Context context, String storage, Uri uri, ArrayList list, ArrayList checkboxs, String msg, String equalstr) {
+ public void selectFile(Context context, String storage, Uri uri, ArrayList list, ArrayList checkboxs, String msg, String equalstr) {
String filePath = storage + "/" + uri.getPath().replaceAll("/document/primary:", "");
- String fileName = getPathByLastNameType(filePath);
+ String fileName = new stringUtils().getPathByLastNameType(filePath);
if (fileName.equals(equalstr)) {
// filePath=filePath.substring(0,filePath.lastIndexOf("/"));
list.add(filePath);
@@ -161,23 +190,13 @@ public static void selectFile(Context context, String storage, Uri uri, ArrayLis
}
}
- //获取文件结尾类型
- public static String getPathByLastNameType(String filePath) {
- return filePath.substring(filePath.lastIndexOf(".") + 1);
- }
-
- //获取路径文件名称
- public static String getPathByLastName(String filePath) {
- return filePath.substring(filePath.lastIndexOf("/") + 1);
- }
-
//复制文件
- public static Boolean copyFile(InputStream is, String outfile) {
+ public Boolean copyFile(InputStream is, String outfile) {
return copyFile(is, new File(outfile));
}
//复制文件
- public static Boolean copyFile(InputStream is, File outFile) {
+ public Boolean copyFile(InputStream is, File outFile) {
try {
return copyFile(is, new FileOutputStream(outFile));
} catch (FileNotFoundException e) {
@@ -187,7 +206,7 @@ public static Boolean copyFile(InputStream is, File outFile) {
}
//复制文件
- public static Boolean copyFile(InputStream is, OutputStream os) {
+ public Boolean copyFile(InputStream is, OutputStream os) {
try {
byte[] buffer = new byte[1024];
int length;
@@ -204,12 +223,12 @@ public static Boolean copyFile(InputStream is, OutputStream os) {
}
//复制文件
- public static Boolean copyFile(String srcFile, String outFile) {
+ public Boolean copyFile(String srcFile, String outFile) {
return copyFile(new File(srcFile), new File(outFile));
}
//复制文件
- public static Boolean copyFile(File srcFile, File outFile) {
+ public Boolean copyFile(File srcFile, File outFile) {
try {
return copyFile(new FileInputStream(srcFile), outFile);
} catch (FileNotFoundException e) {
@@ -219,7 +238,7 @@ public static Boolean copyFile(File srcFile, File outFile) {
}
//判断docum是否等于name,如果有等于的,就直接返回匹配项
- public static DocumentFile checkDocum(DocumentFile dd2, String name) {
+ public DocumentFile checkDocum(DocumentFile dd2, String name) {
for (DocumentFile documentFile : dd2.listFiles()) {
if (documentFile.getName().equals(name)) {
return documentFile;
@@ -229,7 +248,7 @@ public static DocumentFile checkDocum(DocumentFile dd2, String name) {
}
// 目标SD路径:/storage/emulated/0
- public static String getSDPath(Context context){
+ public String getSDPath(Context context){
String sdPath = "";
boolean isSDExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); //判断SD卡是否存在
if (isSDExist) {
@@ -248,7 +267,7 @@ public static String getSDPath(Context context){
return sdPath;
}
- public static void getAllFileByEndName(String filePath, String file_end_name,List files){
+ public void getAllFileByEndName(String filePath, String file_end_name,List files){
//获取指定目录下的所有文件或者目录的File数组
File[] fileArray = new File(filePath).listFiles();
@@ -270,4 +289,46 @@ public static void getAllFileByEndName(String filePath, String file_end_name,Lis
}
}
+ //获取文件大小,带单位
+ public String getSize(double size, int count) {
+ String size_type[] = {"b", "KB", "MB", "GB", "TB", "PB"};
+ if (size > 1024) {
+ double d_size = size / 1024;
+ count = count + 1;
+ return getSize(d_size, count);
+ }
+ String sizestr = String.format("%.2f", size) + size_type[count];
+ return sizestr;
+ }
+
+ public String uriToFilePath(Uri uri, Context context) {
+ File file = null;
+ if(uri == null) return file.toString();
+ //android10以上转换
+ if (uri.getScheme().equals(ContentResolver.SCHEME_FILE)) {
+ file = new File(uri.getPath());
+ } else if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
+ //把文件复制到沙盒目录
+ ContentResolver contentResolver = context.getContentResolver();
+ String displayName = System.currentTimeMillis()+ Math.round((Math.random() + 1) * 1000)
+ +"."+ MimeTypeMap.getSingleton().getExtensionFromMimeType(contentResolver.getType(uri));
+
+// 注释掉的方法可以获取到原文件的文件名,但是比较耗时
+// Cursor cursor = contentResolver.query(uri, null, null, null, null);
+// if (cursor.moveToFirst()) {
+// String displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));}
+
+ try {
+ InputStream is = contentResolver.openInputStream(uri);
+ File cache = new File(context.getExternalCacheDir().getAbsolutePath(), displayName);
+ FileOutputStream fos = new FileOutputStream(cache);
+ file = cache;
+ copyFile(is, fos);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return file.toString();
+ }
+
}
diff --git a/app/src/main/java/org/fqaosp/utils/makeWP.java b/app/src/main/java/org/fqaosp/utils/makeWP.java
index 0d3ae3c..768d3e4 100644
--- a/app/src/main/java/org/fqaosp/utils/makeWP.java
+++ b/app/src/main/java/org/fqaosp/utils/makeWP.java
@@ -1,9 +1,5 @@
package org.fqaosp.utils;
-import static org.fqaosp.utils.multiFunc.checkBoxs;
-import static org.fqaosp.utils.multiFunc.getMyUID;
-import static org.fqaosp.utils.multiFunc.queryUSERS;
-
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -44,7 +40,7 @@ public Boolean init(){
}
public String getCreateWPCMD(){
- return "pm create-user --profileOf "+getMyUID()+" --managed fqaosop";
+ return "pm create-user --profileOf "+new userUtils().getMyUID()+" --managed fqaosop";
}
//创建一个工作空间
@@ -111,7 +107,7 @@ public void addCMDResult(String cmdstr , Activity activity,ArrayList pk
for (String s : cmd.getResult().split("\n")) {
PackageManager pm = activity.getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(s, 0);
- checkBoxs(pkginfos,checkboxs,packageInfo,pm);
+ new packageUtils().checkBoxs(pkginfos,checkboxs,packageInfo,pm);
}
}
} catch (PackageManager.NameNotFoundException e) {
diff --git a/app/src/main/java/org/fqaosp/utils/multiFunc.java b/app/src/main/java/org/fqaosp/utils/multiFunc.java
index 48cb701..f60de50 100644
--- a/app/src/main/java/org/fqaosp/utils/multiFunc.java
+++ b/app/src/main/java/org/fqaosp/utils/multiFunc.java
@@ -1,58 +1,9 @@
package org.fqaosp.utils;
-import static org.fqaosp.utils.fileTools.copyFile;
-import static org.fqaosp.utils.fileTools.extactAssetsFile;
-import static org.fqaosp.utils.fileTools.getMyHomeFilesPath;
-import static org.fqaosp.utils.fileTools.writeDataToPath;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.AlertDialog;
-import android.app.ProgressDialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.os.Build;
-import android.os.Handler;
-import android.os.Message;
-import android.os.Process;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.util.Log;
-import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
-import android.widget.ListView;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-
-import org.fqaosp.R;
-import org.fqaosp.adapter.PKGINFOAdapter;
-import org.fqaosp.adapter.USERAdapter;
-import org.fqaosp.entity.PKGINFO;
-import org.fqaosp.entity.ProcessEntity;
-import org.fqaosp.myActivitys.importToolsActivity;
-import org.fqaosp.myActivitys.workProfileMenuActivity;
-import org.fqaosp.service.adbSocketClient;
-
-import java.io.File;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* 通用功能函数集合
@@ -60,64 +11,20 @@
public class multiFunc {
- public final static Integer QUERY_ALL_USER_ENABLE_PKG=2;
- public final static Integer QUERY_ALL_ENABLE_PKG=0;
- public final static Integer QUERY_ALL_USER_PKG=3;
- public final static Integer QUERY_ALL_DISABLE_PKG=1;
- public final static Integer QUERY_ALL_DEFAULT_PKG=4;
- private static String TAG="multiFunc";
+ public multiFunc(){
+
+ }
//页面布局跳转
- public static void jump(Context srcA , Class> cls,Boolean isRoot,Boolean isADB){
+ public void jump(Context srcA , Class> cls,Boolean isRoot,Boolean isADB){
Intent intent = new Intent(srcA, cls);
intent.putExtra("isRoot", isRoot);
intent.putExtra("isADB",isADB);
srcA.startActivity(intent);
}
- /**
- * 是否存在su命令,并且有执行权限
- *
- * @return 存在su命令,并且有执行权限返回true
- */
- public static boolean isSuEnable() {
- File file = null;
- String[] paths = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/"};
- try {
- for (String path : paths) {
- file = new File(path + "su");
- if (file.exists() && file.canExecute()) {
- return testRoot();
- }
- }
- } catch (Exception x) {
- x.printStackTrace();
- }
- return false;
- }
-
- public static boolean testRoot(){
- CMD cmd = new CMD("id");
- return cmd.getResultCode() == 0;
- }
-
- public static boolean isADB(){
- CMD cmd = runADBCmd("id|grep shell");
- return !cmd.toString().isEmpty();
- }
-
- public static CMD runADBCmd(String cmdstr){
- adbSocketClient adbSocketClient2 = new adbSocketClient(cmdstr,new adbSocketClient.SocketListener() {
- @Override
- public void getCMD(CMD cmd) {
-// Log.d("runADBCMD",cmd.toString());
- }
- });
- return adbSocketClient2.getCMD();
- }
-
//页面布局跳转
- public static void jump(Button b , Context srcA , Class> cls,Boolean isRoot,Boolean isADB){
+ public void jump(Button b , Context srcA , Class> cls,Boolean isRoot,Boolean isADB){
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -126,974 +33,6 @@ public void onClick(View view) {
});
}
- public static void checkTools(Context context,boolean isADB){
- String filesDir =getMyHomeFilesPath(context);
- if(isADB){
- filesDir=context.getExternalCacheDir().toString();
- }
- String scriptName = "fqtools.sh";
- String barfile = filesDir+"/"+scriptName;
- String busyFile = filesDir+"/busybox";
- String extractScriptFile = filesDir+"/extract.sh";
- File busyfile = new File(busyFile);
- File barFile = new File(barfile);
- File extractScriptFilef = new File(extractScriptFile);
- if(!busyfile.exists()){
- if(Build.CPU_ABI.equals("arm64-v8a")){
- extactAssetsFile(context,"busybox",busyFile);
- }else if(Build.CPU_ABI.equals("armeabi-v7a") || Build.CPU_ABI2.equals("armeabi")){
- extactAssetsFile(context,"busybox_arm",busyFile);
- }
- }
- if(!barFile.exists()){
- extactAssetsFile(context,scriptName,barfile);
- }
-
- if(!extractScriptFilef.exists()) {
- extactAssetsFile(context, "extract.sh", extractScriptFile);
- }
-
- if(isADB){
- CMD cmd = getCMD("cp " + busyFile + " /data/local/tmp/", false);
- }
-
- }
-
- //显示一个弹窗
- public static void showInfoMsg(Context con,String title , String msg){
- AlertDialog.Builder ab = new AlertDialog.Builder(con);
- ab.setTitle(title);
- ab.setMessage(msg);
- ab.setNegativeButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.cancel();
- }
- });
-
- AlertDialog alertDialog = ab.create();
- alertDialog.show();
- TextView tv = alertDialog.getWindow().getDecorView().findViewById(android.R.id.message);
- tv.setTextIsSelectable(true);
- }
-
- //移除uid多余字符串
- public static String getUID(String str){
- return str.replaceAll("UserHandle|\\{|\\}","");
- }
-
- //获取自己当前应用的uid
- public static String getMyUID(){
- return getUID(Process.myUserHandle().toString());
- }
-
- //查询用户,默认
- public static void queryUSERS(Activity activity , ArrayList us){
- queryUSERS(activity,us,null);
- }
-
- //查询用户
- public static void queryUSERS(Activity activity , ArrayList us , ArrayList checkboxs){
- us.clear();
- UserManager um = (UserManager) activity.getSystemService(Context.USER_SERVICE);
- if(checkboxs != null){
- checkboxs.clear();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- for (UserHandle userHandle : um.getUserProfiles()) {
- String uid = getUID(userHandle.toString());
- if(!uid.equals(getMyUID())){
- us.add(uid);
- checkboxs.add(false);
- }
- }
- }
- }else{
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- for (UserHandle userHandle : um.getUserProfiles()) {
- String uid = getUID(userHandle.toString());
- if(!uid.equals(getMyUID())){
- us.add(uid);
- }
- }
- }
- }
-
- Collections.sort(us,String::compareTo);
-
- }
-
- //查询当前机主安装的应用
- public static void queryPKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
- clearList(pkginfos,checkboxs);
- queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_DEFAULT_PKG);
- }
-
- //查询当前机主安装的应用,用户部分
- public static void queryUserPKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
- clearList(pkginfos,checkboxs);
- queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_USER_PKG);
-
- }
-
- //查询当前机主安装的应用,用户启用部分
- public static void queryUserEnablePKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
- clearList(pkginfos,checkboxs);
- queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_USER_ENABLE_PKG);
- }
-
- //查询当前机主安装的应用,禁用部分
- public static void queryDisablePKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
- clearList(pkginfos,checkboxs);
- queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_DISABLE_PKG);
-
- }
-
- public static void showPKGS(Context context , ListView listView,ArrayList pkginfos,ArrayList checkboxs) {
- PKGINFOAdapter pkginfoAdapter = new PKGINFOAdapter(pkginfos, context, checkboxs);
- listView.setAdapter(pkginfoAdapter);
- }
-
- public static void showUsers(Context context ,ListView listView,ArrayList userList,ArrayList checkboxsByUser) {
- USERAdapter userAdapter = new USERAdapter(userList, context, checkboxsByUser);
- listView.setAdapter(userAdapter);
- }
-
- public static void getPKGByUID(Context context, String cmdstr,ArrayList pkginfos,HashMap pkginfoHashMap,ArrayList checkboxs,boolean isRoot){
- pkginfos.clear();
- checkboxs.clear();
- CMD cmd = getCMD(cmdstr,isRoot);
- String result = cmd.getResult();
- String[] split = result.split("\n");
- if(split != null){
- PackageManager pm = context.getPackageManager();
- for (String s : cmd.getResult().split("\n")) {
- PackageInfo packageInfo = null;
- try {
- packageInfo = pm.getPackageInfo(s, 0);
- if(pkginfoHashMap!=null){
- checkBoxsHashMap(pkginfoHashMap, checkboxs, packageInfo, pm);
- }else{
- checkBoxs(pkginfos, checkboxs, packageInfo, pm);
- }
-
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
-
- }
-
- public static CMD getCMD(String cmdstr,Boolean isRoot){
- if(isRoot){
- return new CMD(cmdstr);
- }else{
- return runADBCmd(cmdstr);
- }
- }
-
- //搜索列表匹配项
- public static ArrayList indexOfPKGS(Activity activity,String findStr, ArrayList pkginfos , ArrayList checkboxs,Integer types){
- if(pkginfos.size() == 0){
- queryEnablePKGS(activity,pkginfos,checkboxs,types);
- }
- return indexOfPKGS(pkginfos,checkboxs,findStr);
- }
-
- public static Boolean isIndexOfStr(String str,String instr){
- return str.toLowerCase(Locale.ROOT).indexOf(instr.toLowerCase(Locale.ROOT)) != -1;
- }
-
- //搜索列表匹配项
- public static ArrayList indexOfPKGS(ArrayList pkginfos , ArrayList checkboxs,String findStr){
- checkboxs.clear();
- ArrayList pkginfos2 = new ArrayList<>();
- for (PKGINFO pkginfo : pkginfos) {
- if(isIndexOfStr(pkginfo.getAppname(),findStr) || isIndexOfStr(pkginfo.getPkgname(),findStr)){
- pkginfos2.add(pkginfo);
- checkboxs.add(false);
- }
- }
- return pkginfos2;
- }
-
- //搜索列表匹配项
- public static ArrayList indexOfLIST(ArrayList list , ArrayList checkboxs,String findStr){
- checkboxs.clear();
- ArrayList strings = new ArrayList<>();
- for (String s : list) {
- if(isIndexOfStr(s,findStr)){
- strings.add(s);
- checkboxs.add(false);
- }
- }
- return strings;
- }
-
- public static void checkBoxs(ArrayList pkginfos,ArrayList checkboxs,PackageInfo packageInfo,PackageManager packageManager){
- if(checkboxs != null){
- checkboxs.add(false);
- }
- ApplicationInfo applicationInfo = packageInfo.applicationInfo;
- pkginfos.add(new PKGINFO(applicationInfo.packageName, applicationInfo.loadLabel(packageManager).toString(), applicationInfo.sourceDir,applicationInfo.uid+"",packageInfo.versionName, applicationInfo.loadIcon(packageManager),new File(applicationInfo.sourceDir).length())) ;
- }
-
- public static void checkBoxsHashMap(HashMap pkginfos, ArrayList checkboxs, PackageInfo packageInfo, PackageManager packageManager){
- if(checkboxs != null){
- checkboxs.add(false);
- }
- ApplicationInfo applicationInfo = packageInfo.applicationInfo;
- pkginfos.put(applicationInfo.packageName,
- new PKGINFO(applicationInfo.packageName, applicationInfo.loadLabel(packageManager).toString(), applicationInfo.sourceDir,applicationInfo.uid+"",packageInfo.versionName, applicationInfo.loadIcon(packageManager),new File(applicationInfo.sourceDir).length())) ;
- }
-
- public static void appInfoAdd(PackageManager packageManager,PackageInfo packageInfo,ArrayList pkginfos , ArrayList checkboxs,Integer state){
- ApplicationInfo applicationInfo = packageInfo.applicationInfo;
- switch (state){
- case 0:
- if(applicationInfo.enabled){
- checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
- }
- break;
- case 1:
- if(!applicationInfo.enabled){
- checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
- }
- break;
- case 2:
- if((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && applicationInfo.enabled){
- checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
- }
- break;
- case 3:
- if((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0){
- checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
- }
- break;
- case 4:
- checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
- break;
- }
-
- }
-
- public static void sortPKGINFOS(ArrayList pkginfos){
- Collections.sort(pkginfos, new Comparator() {
- @Override
- public int compare(PKGINFO pkginfo, PKGINFO t1) {
- return pkginfo.getAppname().compareTo(t1.getAppname());
- }
- });
- }
-
- public static void queryPKGSCore(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types,Integer state){
- PackageManager packageManager = activity.getPackageManager();
- List installedPackages = packageManager.getInstalledPackages(types);
- for (PackageInfo packageInfo : installedPackages) {
- appInfoAdd(packageManager,packageInfo,pkginfos,checkboxs,state);
- }
- sortPKGINFOS(pkginfos);
- }
-
- //查询当前机主安装的应用,启用部分
- public static void queryEnablePKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
- clearList(pkginfos,checkboxs);
- queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_ENABLE_PKG);
- }
-
- public static void clearList(ArrayList pkginfos , ArrayList checkboxs){
- checkboxs.clear();
- pkginfos.clear();
- }
-
- public static Handler dismissDialogHandler(int value,ProgressDialog show){
- return new Handler(){
- @Override
- public void handleMessage(@NonNull Message msg) {
- if(msg.what==value){
- show.dismiss();
- }
- }
- };
- }
-
- public static String getRunTraverseCMDStr(ArrayList pkginfos,ArrayList checkboxs ,String cmdstr){
- int hit=0;
- StringBuilder sb = new StringBuilder();
- sb.append("aaa=(");
- for (int i = 0; i < checkboxs.size(); i++) {
- if(checkboxs.get(i)){
- sb.append("\""+pkginfos.get(i).getPkgname()+"\" ");
- hit++;
- }
- }
- if(hit == 0){
- for (PKGINFO pkginfo : pkginfos) {
- sb.append("\""+pkginfo.getPkgname()+"\" ");
- }
- }
-
- sb.append(");for pp in ${aaa[@]};do "+cmdstr+";done;");
- return sb.toString();
- }
-
- public static void checkCMDResult(Context context, CMD cmd,String msg , String msg2){
- if( cmd.getResultCode() ==0){
- Log.d("checkCMDResult",msg);
- showInfoMsg(context,"提示",msg);
- }else{
- Log.d("checkCMDResult",msg2+" :: "+cmd.getResult());
- showInfoMsg(context,"错误",msg2 + " -- " + cmd.getResult());
- }
- }
-
- public static void showCMDInfoMSG(Context context,boolean isOutLog,String cmdstr,Boolean isRoot,String msg,String msg2){
- ProgressDialog progressDialog = showMyDialog(context, msg);
- Handler handler = new Handler(){
- @Override
- public void handleMessage(@NonNull Message msg) {
- super.handleMessage(msg);
- if(msg.what == 0){
- progressDialog.dismiss();
- if(isOutLog){
- showInfoMsg(context,"提示",msg2+" : \r\n\r\n"+msg.obj.toString());
- }else{
- showInfoMsg(context,"提示",msg2);
- }
-
- }
- }
- };
- new Thread(new Runnable() {
- @Override
- public void run() {
- CMD cmd = getCMD(cmdstr,isRoot);
- sendHandlerMSG(handler,0,cmd.getResultCode()+"---->"+cmd.getResult());
- }
- }).start();
-
- }
-
- public static void sendHandlerMSG(Handler handler , int value){
- Message msg = new Message();
- msg.what=value;
- handler.sendMessage(msg);
- }
-
- public static void sendHandlerMSG(Handler handler , int value,Object obj){
- Message msg = new Message();
- msg.what=value;
- msg.obj=obj;
- handler.sendMessage(msg);
- }
-
- //调用命令对选项进行相应授权、撤销操作
- public static String getRunAppopsCMD(String pkgname,String pkgcate , int ss ,String uid){
- String cmdstr = "";
- if(pkgcate.indexOf("$") != -1){
- pkgcate = pkgcate.replaceAll("\\$","\\\\\\$");
- }
- switch (ss){
- case 0:
- if(uid == null){
- cmdstr="pm revoke "+pkgname + " " + pkgcate;
- }else{
- cmdstr="pm revoke --user "+uid + " "+pkgname + " " + pkgcate;
- }
- break;
- case 1:
- case 2:
- if(uid == null){
- cmdstr="pm disable \"" +pkgname+"/"+ pkgcate+"\"";
- }else{
- cmdstr="pm disable --user "+uid+" \"" +pkgname+"/"+ pkgcate+"\"";
- }
-
- break;
- case 3:
- if(uid == null){
- cmdstr="pm grant "+pkgname + " " + pkgcate;
- }else{
- cmdstr="pm grant --user " + uid + " " +pkgname + " " + pkgcate;
- }
- break;
- case 4:
- case 5:
- if(uid == null){
- cmdstr="pm enable " +pkgname+"/"+ pkgcate;
- }else{
- cmdstr="pm enable --user "+uid + " \"" +pkgname+"/"+ pkgcate+"\"";
- }
- break;
- }
- return cmdstr;
- }
-
- public static String getRunAppopsBySwtichCMD(Boolean b,int mode ,String pkgname,String pkgcate , String uid){
- String cmdstr = null;
- if(b){
- switch (mode){
- case 0:
- case 1:
- cmdstr = getRunAppopsCMD(pkgname,pkgcate,4,uid);
- break;
- case 2:
- cmdstr = getRunAppopsCMD(pkgname,pkgcate,3,uid);
- break;
- }
- }else{
- switch (mode){
- case 0:
- case 1:
- cmdstr = getRunAppopsCMD(pkgname,pkgcate,1,uid);
- break;
- case 2:
- cmdstr = getRunAppopsCMD(pkgname,pkgcate,0,uid);
- break;
- }
- }
- return cmdstr;
- }
-
- public static void queryRunningPKGS(Activity activity, ArrayList pkginfos){
- queryRunningPKGS(activity,pkginfos,null,0);
- }
-
- public static void queryRunningPKGSCore(List installedPackages,ArrayList pkginfos , ArrayList checkboxs,PackageManager packageManager,boolean isAll){
- for (PackageInfo packageInfo : installedPackages) {
- ApplicationInfo applicationInfo = packageInfo.applicationInfo;
- if (isAll) {
- if (((ApplicationInfo.FLAG_STOPPED & applicationInfo.flags) == 0)) {
- checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
- }
- } else {
- if (((ApplicationInfo.FLAG_SYSTEM & applicationInfo.flags) == 0)
- && ((ApplicationInfo.FLAG_UPDATED_SYSTEM_APP & applicationInfo.flags) == 0)
- && ((ApplicationInfo.FLAG_STOPPED & applicationInfo.flags) == 0)) {
- checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
- }
-
- }
- }
- sortPKGINFOS(pkginfos);
- }
-
- /**
- *
- * 进行字符串正则提取
- */
- public static String getByString(String src, String regex, String re_str) {
- StringBuilder tmp = new StringBuilder();
- Matcher m = Pattern.compile(regex).matcher(src);
- if (m.find()) {
- tmp.append(m.group().replaceAll(re_str, "") + "\n");
- }
- return tmp.toString();
- }
-
- /**
- *
- * 进行字符串正则提取
- */
- public static String getByAllString(String src, String regex, String re_str) {
- StringBuilder tmp = new StringBuilder();
- Matcher m = Pattern.compile(regex).matcher(src);
- while (m.find()) {
- tmp.append(m.group().replaceAll(re_str, "") + "\n");
- }
- return tmp.toString();
- }
-
- public static String getProcessValue(String src,String key){
- return getByString(src,key+":(.+?\\n)",key+":");
- }
-
- //查询/proc路径下所有进程
- public static Set queryAllProcess(Context context , boolean isRoot){
- Set set = new HashSet<>();
- String cmdstr = "for p in `ls /proc |grep -E \"[0-9]\"`;do cat \"/proc/$p/status\";echo \"FQAOSPLINE\";done";
- CMD cmd = getCMD( cmdstr, isRoot);
- if(cmd.getResultCode()==0){
- for (String s : getByAllString(cmd.getResult(), "Name:([\\s\\S]*)FQAOSPLINE", "").split("FQAOSPLINE")) {
- if(!s.trim().isEmpty()){
- set.add(new ProcessEntity(getProcessValue(s,"Name"),getProcessValue(s,"Umask"),getProcessValue(s,"State"),getProcessValue(s,"Tgid"),
- getProcessValue(s,"Ngid"),getProcessValue(s,"Pid"),getProcessValue(s,"PPid"),getProcessValue(s,"TracerPid"),getProcessValue(s,"Uid"),
- getProcessValue(s,"Gid"),getProcessValue(s,"FDSize"),getProcessValue(s,"Groups"),getProcessValue(s,"VmPeak"),getProcessValue(s,"VmSize"),getProcessValue(s,"VmLck"),
- getProcessValue(s,"VmPin"),getProcessValue(s,"VmHWM"),getProcessValue(s,"VmRSS"),getProcessValue(s,"RssAnon"),getProcessValue(s,"RssFile"),
- getProcessValue(s,"RssShmem"),getProcessValue(s,"VmData"),getProcessValue(s,"VmStk"),getProcessValue(s,"VmExe"),getProcessValue(s,"VmLib"),getProcessValue(s,"VmPTE"),
- getProcessValue(s,"VmSwap"),getProcessValue(s,"CoreDumping"),getProcessValue(s,"Threads"),getProcessValue(s,"SigQ"),getProcessValue(s,"SigPnd"),getProcessValue(s,"ShdPnd"),
- getProcessValue(s,"SigBlk"),getProcessValue(s,"SigIgn"),getProcessValue(s,"SigCgt"),getProcessValue(s,"CapInh"),getProcessValue(s,"CapPrm"),getProcessValue(s,"CapEff"),getProcessValue(s,"CapBnd"),
- getProcessValue(s,"CapAmb"),getProcessValue(s,"NoNewPrivs"),getProcessValue(s,"Seccomp"),getProcessValue(s,"Speculation_Store_Bypass"),getProcessValue(s,"Cpus_allowed"),getProcessValue(s,"Cpus_allowed_list"),getProcessValue(s,"Mems_allowed"),getProcessValue(s,"Mems_allowed_list"),
- getProcessValue(s,"voluntary_ctxt_switches"),getProcessValue(s,"nonvoluntary_ctxt_switches")
- ));
- }
- }
- }
- return set;
- }
-
-
- //查询当前运行在后台的应用,用户安装部分
- public static void queryRunningPKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
- PackageManager packageManager = activity.getPackageManager();
- List installedPackages = packageManager.getInstalledPackages(types);
- queryRunningPKGSCore(installedPackages,pkginfos,checkboxs,packageManager,false);
- }
-
- //查询当前运行在后台的应用,所有
- public static void queryAllRunningPKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
- PackageManager packageManager = activity.getPackageManager();
- List installedPackages = packageManager.getInstalledPackages(types);
- queryRunningPKGSCore(installedPackages,pkginfos,checkboxs,packageManager,true);
- }
-
- //显示提示框
- public static ProgressDialog showMyDialog(Context context, String msg){
- ProgressDialog pd = new ProgressDialog(context);//初始化等待条
- pd.setMessage(msg);//等待显示条的信息
- pd.setCanceledOnTouchOutside(false);
- pd.setCancelable(false);
- pd.show();//等待显示条
- return pd;
- }
-
-
- public static void showImportToolsDialog(Context context,String toastMsg , String msg,Boolean isRoot,Boolean isADB){
- Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
- AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
- alertDialog.setTitle("警告");
- alertDialog.setMessage(msg);
- alertDialog.setPositiveButton("继续", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- });
- alertDialog.setNegativeButton("补全功能组件", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- jump(context, importToolsActivity.class,isRoot,isADB);
- }
- });
- alertDialog.show();
- }
-
- public static void sendHandlerMsg(Handler handler,int n,Object obj){
- Message message = new Message();
- message.what=n;
- message.obj=obj;
- handler.sendMessage(message);
- }
-
- public static Handler getProcessBarDialogHandler(Context context ,ProgressBar mProgressBar,AlertDialog alertDialog,TextView dpbtv1,TextView dpbtv2,TextView dpbtv3,String text){
- return new Handler() {
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 0:
- // 设置进度条
- mProgressBar.setProgress((int)msg.obj);
- break;
- case 1:
- // 隐藏当前下载对话框
- permittedDismissDialog(alertDialog);
- showInfoMsg(context,"提示","已运行完毕,请手动刷新.");
- break;
- case 2:
- PKGINFO pkginfo = (PKGINFO) msg.obj;
- dpbtv3.setText(text+(pkginfo.getAppname()==null?pkginfo.getPkgname():pkginfo.getAppname()));
- break;
- case 3:
- dpbtv1.setText(((int)(msg.obj))+"");
- break;
- case 4:
- alertDialog.setTitle(msg.obj.toString());
- break;
- case 5:
- dpbtv2.setText(msg.obj.toString());
- break;
- case 6:
- permittedDismissDialog(alertDialog);
- showInfoMsg(context,"错误",msg.obj.toString());
- break;
- }
- }
- };
- }
-
- //拼接命令参数字符串
- public static String spliceCMDStr(PKGINFO pkginfo,int mode , int apops_opt_index,int apops_permis_index){
- StringBuilder sb = new StringBuilder();
- String cmdHead = "appops set --uid "+pkginfo.getPkgname()+" ";
- String cmdWrite = "appops write-settings ";
- String modestr="";
-
- if(mode == 0){
- switch (apops_opt_index){
- case 0:
- modestr = "default";
- break;
- case 1:
- modestr = "ignore";
- break;
- case 2:
- modestr = "allow";
- break;
- case 3:
- modestr = "foreground";
- break;
- }
- }
- if(mode ==1){
- switch (apops_opt_index){
- case 0:
- modestr = "true";
- break;
- case 1:
- modestr = "false";
- break;
- }
- }
- if(mode ==2){
- switch (apops_opt_index){
- case 0:
- modestr = "active";
- break;
- case 1:
- modestr = "working_set";
- break;
- case 2:
- modestr = "frequent";
- break;
- case 3:
- modestr = "rare";
- break;
- case 4:
- modestr = "restricted";
- break;
- }
- }
-
- switch (apops_permis_index){
- case 0 :
- sb.append(cmdHead+" READ_PHONE_STATE "+modestr+";");
- sb.append(cmdHead+" READ_CONTACTS "+modestr+";");
- sb.append(cmdHead+" WRITE_CONTACTS "+modestr+";");
- sb.append(cmdHead+" READ_CALL_LOG "+modestr+";");
- sb.append(cmdHead+" WRITE_CALL_LOG "+modestr+";");
- sb.append(cmdHead+" CALL_PHONE "+modestr+";");
- sb.append(cmdHead+" READ_SMS "+modestr+";");
- sb.append(cmdHead+" WRITE_SMS "+modestr+";");
- sb.append(cmdHead+" SEND_SMS "+modestr+";");
- sb.append(cmdHead+" RECEIVE_SMS "+modestr+";");
- sb.append(cmdHead+" RECEIVE_EMERGECY_SMS "+modestr+";");
- sb.append(cmdHead+" RECEIVE_MMS "+modestr+";");
- sb.append(cmdHead+" RECEIVE_WAP_PUSH "+modestr+";");
- sb.append(cmdHead+" READ_ICC_SMS "+modestr+";");
- sb.append(cmdHead+" WRITE_ICC_SMS "+modestr+";");
- sb.append(cmdHead+" PROCESS_OUTGOING_CALLS "+modestr+";");
- sb.append(cmdHead+" READ_CELL_BROADCASTS "+modestr+";");
- sb.append(cmdHead+" android:add_voicemail "+modestr+";");
- sb.append(cmdHead+" android:answer_phone_calls "+modestr+";");
- sb.append(cmdHead+" android:call_phone "+modestr+";");
- sb.append(cmdHead+" android:read_call_log "+modestr+";");
- sb.append(cmdHead+" android:read_contacts "+modestr+";");
- sb.append(cmdHead+" android:read_cell_broadcasts "+modestr+";");
- sb.append(cmdHead+" android:read_phone_numbers "+modestr+";");
- sb.append(cmdHead+" android:read_phone_state "+modestr+";");
- sb.append(cmdHead+" android:read_sms "+modestr+";");
- sb.append(cmdHead+" android:receive_mms "+modestr+";");
- sb.append(cmdHead+" android:receive_sms "+modestr+";");
- sb.append(cmdHead+" android:receive_wap_push "+modestr+";");
- sb.append(cmdHead+" android:send_sms "+modestr+";");
- sb.append(cmdHead+" android:write_call_log "+modestr+";");
- sb.append(cmdHead+" android:write_contacts "+modestr+";");
- sb.append(cmdHead+" android:process_outgoing_calls "+modestr+";");
- sb.append(cmdHead+" android.permission-group.CALL_LOG "+modestr+";");
- sb.append(cmdHead+" android.permission-group.CONTACTS "+modestr+";");
- sb.append(cmdHead+" android.permission-group.PHONE "+modestr+";");
- sb.append(cmdHead+" android.permission-group.SMS "+modestr+";");
- break;
- case 1:
- sb.append(cmdHead+" READ_EXTERNAL_STORAGE "+modestr+";");
- sb.append(cmdHead+" WRITE_EXTERNAL_STORAGE "+modestr+";");
- sb.append(cmdHead+" ACCESS_MEDIA_LOCATION "+modestr+";");
- sb.append(cmdHead+" LEGACY_STORAGE "+modestr+";");
- sb.append(cmdHead+" WRITE_MEDIA_AUDIO "+modestr+";");
- sb.append(cmdHead+" READ_MEDIA_AUDIO "+modestr+";");
- sb.append(cmdHead+" WRITE_MEDIA_VIDEO "+modestr+";");
- sb.append(cmdHead+" READ_MEDIA_VIDEO "+modestr+";");
- sb.append(cmdHead+" READ_MEDIA_IMAGES "+modestr+";");
- sb.append(cmdHead+" WRITE_MEDIA_IMAGES "+modestr+";");
- sb.append(cmdHead+" MANAGE_EXTERNAL_STORAGE "+modestr+";");
- sb.append(cmdHead+" android:picture_in_picture "+modestr+";");
- sb.append(cmdHead+" android.permission-group.READ_MEDIA_AURAL "+modestr+";");
- sb.append(cmdHead+" android.permission-group.READ_MEDIA_VISUAL "+modestr+";");
- sb.append(cmdHead+" android.permission-group.READ_MEDIA_VISUAL "+modestr+";");
- sb.append(cmdHead+" android.permission-group.STORAGE "+modestr+";");
- break;
- case 2:
- sb.append(cmdHead+" READ_CLIPBOARD "+modestr+";");
- sb.append(cmdHead+" WRITE_CLIPBOARD "+modestr+";");
- break;
- case 3:
- sb.append(cmdHead+" RUN_ANY_IN_BACKGROUND "+modestr+";");
- break;
- case 4:
- sb.append(cmdHead+" RUN_IN_BACKGROUND "+modestr+";");
- break;
- case 5:
- sb.append(cmdHead+" CAMERA "+modestr+";");
- sb.append(cmdHead+" android:camera "+modestr+";");
- sb.append(cmdHead+" android.permission-group.CAMERA "+modestr+";");
- break;
- case 6:
- sb.append(cmdHead+" RECORD_AUDIO "+modestr+";");
- sb.append(cmdHead+" android:record_audio "+modestr+";");
- sb.append(cmdHead+" TAKE_AUDIO_FOCUS "+modestr+";");
- sb.append(cmdHead+" android.permission-group.MICROPHONE "+modestr+";");
- break;
- case 7:
- sb.append(cmdHead+" COARSE_LOCATION "+modestr+";");
- sb.append(cmdHead+" FINE_LOCATION "+modestr+";");
- sb.append(cmdHead+" android:coarse_location "+modestr+";");
- sb.append(cmdHead+" android:fine_location "+modestr+";");
- sb.append(cmdHead+" android:mock_location "+modestr+";");
- sb.append(cmdHead+" android:monitor_location_high_power "+modestr+";");
- sb.append(cmdHead+" android:monitor_location "+modestr+";");
- sb.append(cmdHead+" android.permission-group.LOCATION "+modestr+";");
- break;
- case 8:
- sb.append(cmdHead+" READ_CALENDAR "+modestr+";");
- sb.append(cmdHead+" WRITE_CALENDAR "+modestr+";");
- sb.append(cmdHead+" android:write_calendar "+modestr+";");
- sb.append(cmdHead+" android:read_calendar "+modestr+";");
- sb.append(cmdHead+" android.permission-group.CALENDAR "+modestr+";");
- break;
- case 9:
- sb.append(cmdHead+" WIFI_SCAN "+modestr+";");
- sb.append(cmdHead+" android:use_sip "+modestr+";");
- sb.append(cmdHead+" BLUETOOTH_SCAN "+modestr+";");
- sb.append(cmdHead+" BLUETOOTH_ADVERTISE "+modestr+";");
- sb.append(cmdHead+" BLUETOOTH_CONNECT "+modestr+";");
- sb.append(cmdHead+" BLUETOOTH_ADMIN "+modestr+";");
- sb.append(cmdHead+" BLUETOOTH "+modestr+";");
- sb.append(cmdHead+" NEARBY_DEVICES "+modestr+";");
- sb.append(cmdHead+" android.permission-group.NEARBY_DEVICES "+modestr+";");
- sb.append(cmdHead+" android.permission-group.SENSORS "+modestr+";");
- break;
- case 10:
- sb.append(cmdHead+" android.permission-group.NOTIFICATIONS "+modestr+";");
- sb.append(cmdHead+" ACCESS_NOTIFICATIONS "+modestr+";");
- sb.append(cmdHead+" POST_NOTIFICATION "+modestr+";");
- sb.append(cmdHead+" android.permission.POST_NOTIFICATIONS "+modestr+";");
- break;
- case 11:
- sb.append("am set-inactive "+pkginfo.getPkgname()+" "+modestr);
- break;
- case 12:
- sb.append("am set-standby-bucket "+pkginfo.getPkgname()+" " + modestr );
- break;
- case 13:
- appopsCmdStr acs = new appopsCmdStr();
- sb.append(modestr.equals("true")?acs.enableAppByAPPUIDCMD(Integer.valueOf(pkginfo.getApkuid().trim())):acs.disableAppByAPPUIDCMD(Integer.valueOf(pkginfo.getApkuid().trim())));
- break;
- }
- if(apops_permis_index < 11){
- sb.append(cmdWrite);
- }
- return sb.toString();
- }
-
- public static void sendProcessBarHandlerSum(Handler handler,int i , int size , PKGINFO pkginfo){
- // 计算进度条当前位置
- sendHandlerMsg(handler,0,(int) (((float) i / size) * 100));
- sendHandlerMsg(handler,3,i);
- sendHandlerMsg(handler,2,pkginfo);
- }
-
- public static void showProcessBarDialogByCMD(Context context, ArrayList list,String title,String text , int ppmode,Integer install_mode,Boolean isDisable,Boolean isRoot,String uid,Integer mode , Integer apops_opt_index,Integer apops_permis_index,String...parm){
- String app_cache_storage = context.getExternalCacheDir().toString();
- String scriptName="fqtools.sh";
- String filesDir =getMyHomeFilesPath(context);
- String barfile = filesDir+"/"+scriptName;
- makeWP makewp = new makeWP();
- StringBuilder sb = new StringBuilder();
- sb.append(" ");
- if(parm !=null && parm.length > 0){
- for (int i = 0; i < parm.length; i++) {
- sb.append(parm[i]+" ");
- }
- }
- if(ppmode == 9){
- sb.setLength(0);
- }
- int size = list.size();
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(title);
- View vvv = LayoutInflater.from(context).inflate(R.layout.download_process_bar, null);
- ProgressBar mProgressBar = (ProgressBar) vvv.findViewById(R.id.dpbpb);
- TextView dpbtv1 = vvv.findViewById(R.id.dpbtv1);
- TextView dpbtv2 = vvv.findViewById(R.id.dpbtv2);
- TextView dpbtv3 = vvv.findViewById(R.id.dpbtv3);
- builder.setView(vvv);
- AlertDialog alertDialog = builder.create();
- alertDialog.show();
- preventDismissDialog(alertDialog);
- dpbtv2.setText(size+"");
- Handler mUpdateProgressHandler = getProcessBarDialogHandler(context,mProgressBar,alertDialog,dpbtv1,dpbtv2,dpbtv3,text);
- appopsCmdStr acs = new appopsCmdStr();
- new Thread(new Runnable() {
- @Override
- public void run() {
- String outDir=null;
- for (int i = 1; i <= size; i++) {
- PKGINFO pkginfo = list.get(i - 1);
- sendProcessBarHandlerSum(mUpdateProgressHandler,i,size,pkginfo);
- String cmdstr=null;
- switch (ppmode){
- case 0:
- cmdstr = isDisable?makewp.getChangePkgOnEnableByUIDCMD(uid, pkginfo.getPkgname()):makewp.getChangePkgOnDisableByUIDCMD(uid,pkginfo.getPkgname());
- break;
- case 1:
- cmdstr = makewp.getUninstallPkgByUIDCMD(uid, pkginfo.getPkgname());
- break;
- case 2:
- cmdstr = spliceCMDStr(pkginfo,mode,apops_opt_index,apops_permis_index);
- break;
- case 3:
- switch (install_mode){
- case 0:
- cmdstr = acs.getInstallLocalPkgCMD(uid, pkginfo.getApkpath());
- break;
- case 1:
- cmdstr = acs.getInstallLocalPkgOnDowngradeCMD(uid, pkginfo.getApkpath());
- break;
- case 2:
- cmdstr = acs.getInstallLocalPkgOnDebugCMD(uid, pkginfo.getApkpath());
- break;
- case 3:
- cmdstr = acs.getInstallLocalPkgOnExistsCMD(uid, pkginfo.getApkpath());
- break;
- }
- break;
- case 4:
- cmdstr = acs.getInstallLocalPkgOnExistsCMD(uid,pkginfo.getApkpath());
- break;
- case 5:
- cmdstr = "am force-stop "+pkginfo.getPkgname();
- break;
- case 6:
- cmdstr = "sh "+barfile+" backup "+pkginfo.getPkgname() +" "+sb.toString()+ " "+uid;
- break;
- case 7:
- cmdstr = "sh "+barfile+" restory "+pkginfo.getPkgname() +" "+sb.toString()+ " "+uid;
- break;
- case 8:
- if(mode == 0){
- String filePath = pkginfo.getApkpath();
- String outname = new File(filePath).getName();
- outDir = app_cache_storage + "/recompile";
- File file = new File(outDir);
- if (!file.exists()) {
- file.mkdirs();
- }
- String outFile = outDir + "/" + outname + ".apk";
- cmdstr = "cd " + filesDir + " && sh fqtools.sh apktool reapk "+ filePath+ " " + outFile ;
- }
-
- if(mode == 1){
- String filePath = pkginfo.getApkpath();
- PackageManager packageManager = context.getPackageManager();
- PackageInfo archiveInfo = packageManager.getPackageArchiveInfo(filePath, 0);
- String pkgname = archiveInfo.packageName;
- outDir = app_cache_storage + "/decompile/" + pkgname;
- cmdstr = "cd " + filesDir + " && sh fqtools.sh apktool deapk " + filePath+ " " + outDir ;
- }
- break;
- case 9:
- outDir = app_cache_storage+"/"+(mode ==0 ?"romunpack":"romrepack");
- String path = pkginfo.getApkpath();
- String outdir = outDir+"/"+System.currentTimeMillis();
- String filesDir = getMyHomeFilesPath(context);
- File file = new File(outdir);
- if(!file.exists()){
- file.mkdirs();
- }
- if(mode ==0){
- cmdstr = "cd "+filesDir+" && sh fqtools.sh unpackrom "+parm[0] + " " +path + " " + outdir + " " + parm[1];
- }
- if(mode ==1){
- cmdstr = "cd "+filesDir+" && sh fqtools.sh repackrom "+path+ " " + outdir + " " +parm[0] + " " + parm[1];
- }
- sb.append(path+" -----> "+outdir+".\r\n");
- break;
- case 11:
- String outpath = context.getExternalCacheDir().getAbsolutePath()+"/"+pkginfo.getPkgname()+".apk";
- copyFile(pkginfo.getApkpath(),outpath);
- break;
- }
- if(ppmode == 8 || ppmode == 9){
- CMD cmd = new CMD(cmdstr, false);
- int code = cmd.getResultCode();
- if(ppmode == 9 && code != 0){
- String ff=outDir+"/"+System.currentTimeMillis()+".log";
- writeDataToPath(cmd.toString(),ff,false);
- sendHandlerMSG(mUpdateProgressHandler,6,(mode==0?"解":"打")+"包失败,日志存放在 >> "+ff);
- }
- }else if(ppmode == 10){
- CMD cmd = new CMD(getRunAppopsBySwtichCMD(pkginfo.getAppversionname().equals("true")?true:false,mode,pkginfo.getPkgname(),pkginfo.getAppname(),uid));
- }else{
- CMD cmd = getCMD(cmdstr, isRoot);
- }
-
- }
- mUpdateProgressHandler.sendEmptyMessage(1);
- }
- }).start();
- }
-
-
-
- /**
- * 通过反射 阻止关闭对话框
- */
- public static void preventDismissDialog(AlertDialog ddd) {
- try {
- Field field = ddd.getClass().getSuperclass().getDeclaredField("mShowing");
- field.setAccessible(true);
- //设置mShowing值,欺骗android系统
- field.set(ddd, false);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * 关闭对话框
- */
- public static void permittedDismissDialog(AlertDialog ddd) {
- try {
- Field field = ddd.getClass().getSuperclass().getDeclaredField("mShowing");
- field.setAccessible(true);
- field.set(ddd, true);
- } catch (Exception e) {
- }
- ddd.dismiss();
- }
-
- public static void showLowMemDialog(Context context){
- showLowMemDialog(context,"警告","当前设备配置较低,运行此页面功能会出现问题!");
- }
-
- public static void showLowMemDialog(Context context,String title , String msg){
- ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
- ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
- activityManager.getMemoryInfo(memoryInfo);
- if(activityManager.isLowRamDevice() || (memoryInfo != null && (memoryInfo.totalMem*1.0/(1024*1024)) < 4096)){
- showInfoMsg(context,title,msg);
- }
- }
}
diff --git a/app/src/main/java/org/fqaosp/utils/packageUtils.java b/app/src/main/java/org/fqaosp/utils/packageUtils.java
new file mode 100644
index 0000000..786dc1f
--- /dev/null
+++ b/app/src/main/java/org/fqaosp/utils/packageUtils.java
@@ -0,0 +1,161 @@
+package org.fqaosp.utils;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+
+import org.fqaosp.entity.PKGINFO;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+
+public class packageUtils {
+
+ public Integer QUERY_ALL_USER_ENABLE_PKG=2;
+ public Integer QUERY_ALL_ENABLE_PKG=0;
+ public Integer QUERY_ALL_USER_PKG=3;
+ public Integer QUERY_ALL_DISABLE_PKG=1;
+ public Integer QUERY_ALL_DEFAULT_PKG=4;
+
+ public packageUtils(){}
+
+ //查询当前机主安装的应用
+ public void queryPKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs, Integer types){
+ clearList(pkginfos,checkboxs);
+ queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_DEFAULT_PKG);
+ }
+
+ //查询当前机主安装的应用,用户部分
+ public void queryUserPKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
+ clearList(pkginfos,checkboxs);
+ queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_USER_PKG);
+ }
+
+ //查询当前机主安装的应用,用户启用部分
+ public void queryUserEnablePKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
+ clearList(pkginfos,checkboxs);
+ queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_USER_ENABLE_PKG);
+ }
+
+ //查询当前机主安装的应用,禁用部分
+ public void queryDisablePKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
+ clearList(pkginfos,checkboxs);
+ queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_DISABLE_PKG);
+ }
+
+
+ public void getPKGByUID(Context context, String cmdstr, ArrayList pkginfos, HashMap pkginfoHashMap, ArrayList checkboxs, boolean isRoot){
+ pkginfos.clear();
+ checkboxs.clear();
+ CMD cmd = new shellUtils().getCMD(cmdstr,isRoot);
+ String result = cmd.getResult();
+ String[] split = result.split("\n");
+ if(split != null){
+ PackageManager pm = context.getPackageManager();
+ for (String s : cmd.getResult().split("\n")) {
+ PackageInfo packageInfo = null;
+ try {
+ packageInfo = pm.getPackageInfo(s, 0);
+ if(pkginfoHashMap!=null){
+ checkBoxsHashMap(pkginfoHashMap, checkboxs, packageInfo, pm);
+ }else{
+ checkBoxs(pkginfos, checkboxs, packageInfo, pm);
+ }
+
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+
+
+ public void checkBoxs(ArrayList pkginfos,ArrayList checkboxs,PackageInfo packageInfo,PackageManager packageManager){
+ if(checkboxs != null){
+ checkboxs.add(false);
+ }
+ ApplicationInfo applicationInfo = packageInfo.applicationInfo;
+ pkginfos.add(new PKGINFO(applicationInfo.packageName, applicationInfo.loadLabel(packageManager).toString(), applicationInfo.sourceDir,applicationInfo.uid+"",packageInfo.versionName, applicationInfo.loadIcon(packageManager),new File(applicationInfo.sourceDir).length())) ;
+ }
+
+ public void checkBoxsHashMap(HashMap pkginfos, ArrayList checkboxs, PackageInfo packageInfo, PackageManager packageManager){
+ if(checkboxs != null){
+ checkboxs.add(false);
+ }
+ ApplicationInfo applicationInfo = packageInfo.applicationInfo;
+ pkginfos.put(applicationInfo.packageName,
+ new PKGINFO(applicationInfo.packageName, applicationInfo.loadLabel(packageManager).toString(), applicationInfo.sourceDir,applicationInfo.uid+"",packageInfo.versionName, applicationInfo.loadIcon(packageManager),new File(applicationInfo.sourceDir).length())) ;
+ }
+
+ public void appInfoAdd(PackageManager packageManager,PackageInfo packageInfo,ArrayList pkginfos , ArrayList checkboxs,Integer state){
+ ApplicationInfo applicationInfo = packageInfo.applicationInfo;
+ switch (state){
+ case 0:
+ if(applicationInfo.enabled){
+ checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
+ }
+ break;
+ case 1:
+ if(!applicationInfo.enabled){
+ checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
+ }
+ break;
+ case 2:
+ if((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && applicationInfo.enabled){
+ checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
+ }
+ break;
+ case 3:
+ if((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0){
+ checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
+ }
+ break;
+ case 4:
+ checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
+ break;
+ }
+
+ }
+
+ public void sortPKGINFOS(ArrayList pkginfos){
+ if(pkginfos != null && pkginfos.size()>0){
+ Collections.sort(pkginfos, new Comparator() {
+ @Override
+ public int compare(PKGINFO pkginfo, PKGINFO t1) {
+ return pkginfo.getAppname().compareTo(t1.getAppname());
+ }
+ });
+ }
+ }
+
+ public void queryPKGSCore(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types,Integer state){
+ PackageManager packageManager = activity.getPackageManager();
+ List installedPackages = packageManager.getInstalledPackages(types);
+ for (PackageInfo packageInfo : installedPackages) {
+ appInfoAdd(packageManager,packageInfo,pkginfos,checkboxs,state);
+ }
+ sortPKGINFOS(pkginfos);
+ }
+
+ //查询当前机主安装的应用,启用部分
+ public void queryEnablePKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
+ clearList(pkginfos,checkboxs);
+ queryPKGSCore(activity,pkginfos,checkboxs,types,QUERY_ALL_ENABLE_PKG);
+ }
+
+ public void clearList(ArrayList pkginfos , ArrayList checkboxs){
+ checkboxs.clear();
+ pkginfos.clear();
+ }
+
+
+
+}
diff --git a/app/src/main/java/org/fqaosp/utils/permissionRequest.java b/app/src/main/java/org/fqaosp/utils/permissionRequest.java
index 6bd8542..713fb0c 100644
--- a/app/src/main/java/org/fqaosp/utils/permissionRequest.java
+++ b/app/src/main/java/org/fqaosp/utils/permissionRequest.java
@@ -1,15 +1,12 @@
package org.fqaosp.utils;
-import static org.fqaosp.utils.multiFunc.showInfoMsg;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
-import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.UriPermission;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
@@ -22,9 +19,6 @@
import androidx.core.content.ContextCompat;
import androidx.documentfile.provider.DocumentFile;
-import java.io.File;
-import java.util.List;
-
public class permissionRequest {
public static void grantAndroidData(Activity context){
@@ -99,7 +93,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
grantAndroidObb(that);
}
dialogInterface.cancel();
- showInfoMsg(that, "提示", "授权完成后,重启应用");
+ new dialogUtils().showInfoMsg(that, "提示", "授权完成后,重启应用");
}
});
ab.setPositiveButton("取消", new DialogInterface.OnClickListener() {
diff --git a/app/src/main/java/org/fqaosp/utils/processUtils.java b/app/src/main/java/org/fqaosp/utils/processUtils.java
new file mode 100644
index 0000000..4118e6a
--- /dev/null
+++ b/app/src/main/java/org/fqaosp/utils/processUtils.java
@@ -0,0 +1,85 @@
+package org.fqaosp.utils;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+
+import org.fqaosp.entity.PKGINFO;
+import org.fqaosp.entity.ProcessEntity;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class processUtils {
+
+ private packageUtils pkgutils = new packageUtils();
+ private stringUtils su = new stringUtils();
+
+ public processUtils(){}
+ public void queryRunningPKGSCore(List installedPackages, ArrayList pkginfos , ArrayList checkboxs, PackageManager packageManager, boolean isAll){
+ for (PackageInfo packageInfo : installedPackages) {
+ ApplicationInfo applicationInfo = packageInfo.applicationInfo;
+ if (isAll) {
+ if (((ApplicationInfo.FLAG_STOPPED & applicationInfo.flags) == 0)) {
+ pkgutils.checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
+ }
+ } else {
+ if (((ApplicationInfo.FLAG_SYSTEM & applicationInfo.flags) == 0)
+ && ((ApplicationInfo.FLAG_UPDATED_SYSTEM_APP & applicationInfo.flags) == 0)
+ && ((ApplicationInfo.FLAG_STOPPED & applicationInfo.flags) == 0)) {
+ pkgutils.checkBoxs(pkginfos,checkboxs,packageInfo,packageManager);
+ }
+
+ }
+ }
+ pkgutils.sortPKGINFOS(pkginfos);
+ }
+
+ public String getProcessValue(String src,String key){
+ return su.getByString(src,key+":(.+?\\n)",key+":");
+ }
+
+ //查询/proc路径下所有进程
+ public Set queryAllProcess(Context context , boolean isRoot){
+ Set set = new HashSet<>();
+ String cmdstr = "for p in `ls /proc |grep -E \"[0-9]\"`;do cat \"/proc/$p/status\";echo \"FQAOSPLINE\";done";
+ CMD cmd = new shellUtils().getCMD( cmdstr, isRoot);
+ if(cmd.getResultCode()==0){
+ for (String s : su.getByAllString(cmd.getResult(), "Name:([\\s\\S]*)FQAOSPLINE", "").split("FQAOSPLINE")) {
+ if(!s.trim().isEmpty()){
+ set.add(new ProcessEntity(getProcessValue(s,"Name"),getProcessValue(s,"Umask"),getProcessValue(s,"State"),getProcessValue(s,"Tgid"),
+ getProcessValue(s,"Ngid"),getProcessValue(s,"Pid"),getProcessValue(s,"PPid"),getProcessValue(s,"TracerPid"),getProcessValue(s,"Uid"),
+ getProcessValue(s,"Gid"),getProcessValue(s,"FDSize"),getProcessValue(s,"Groups"),getProcessValue(s,"VmPeak"),getProcessValue(s,"VmSize"),getProcessValue(s,"VmLck"),
+ getProcessValue(s,"VmPin"),getProcessValue(s,"VmHWM"),getProcessValue(s,"VmRSS"),getProcessValue(s,"RssAnon"),getProcessValue(s,"RssFile"),
+ getProcessValue(s,"RssShmem"),getProcessValue(s,"VmData"),getProcessValue(s,"VmStk"),getProcessValue(s,"VmExe"),getProcessValue(s,"VmLib"),getProcessValue(s,"VmPTE"),
+ getProcessValue(s,"VmSwap"),getProcessValue(s,"CoreDumping"),getProcessValue(s,"Threads"),getProcessValue(s,"SigQ"),getProcessValue(s,"SigPnd"),getProcessValue(s,"ShdPnd"),
+ getProcessValue(s,"SigBlk"),getProcessValue(s,"SigIgn"),getProcessValue(s,"SigCgt"),getProcessValue(s,"CapInh"),getProcessValue(s,"CapPrm"),getProcessValue(s,"CapEff"),getProcessValue(s,"CapBnd"),
+ getProcessValue(s,"CapAmb"),getProcessValue(s,"NoNewPrivs"),getProcessValue(s,"Seccomp"),getProcessValue(s,"Speculation_Store_Bypass"),getProcessValue(s,"Cpus_allowed"),getProcessValue(s,"Cpus_allowed_list"),getProcessValue(s,"Mems_allowed"),getProcessValue(s,"Mems_allowed_list"),
+ getProcessValue(s,"voluntary_ctxt_switches"),getProcessValue(s,"nonvoluntary_ctxt_switches")
+ ));
+ }
+ }
+ }
+ return set;
+ }
+
+
+ //查询当前运行在后台的应用,用户安装部分
+ public void queryRunningPKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs, Integer types){
+ PackageManager packageManager = activity.getPackageManager();
+ List installedPackages = packageManager.getInstalledPackages(types);
+ queryRunningPKGSCore(installedPackages,pkginfos,checkboxs,packageManager,false);
+ }
+
+ //查询当前运行在后台的应用,所有
+ public void queryAllRunningPKGS(Activity activity, ArrayList pkginfos , ArrayList checkboxs,Integer types){
+ PackageManager packageManager = activity.getPackageManager();
+ List installedPackages = packageManager.getInstalledPackages(types);
+ queryRunningPKGSCore(installedPackages,pkginfos,checkboxs,packageManager,true);
+ }
+
+}
diff --git a/app/src/main/java/org/fqaosp/utils/shellUtils.java b/app/src/main/java/org/fqaosp/utils/shellUtils.java
new file mode 100644
index 0000000..79771e8
--- /dev/null
+++ b/app/src/main/java/org/fqaosp/utils/shellUtils.java
@@ -0,0 +1,60 @@
+package org.fqaosp.utils;
+
+import org.fqaosp.service.adbSocketClient;
+
+import java.io.File;
+
+public class shellUtils {
+
+ public shellUtils(){}
+
+ public CMD runADBCmd(String cmdstr){
+ adbSocketClient adbSocketClient2 = new adbSocketClient(cmdstr,new adbSocketClient.SocketListener() {
+ @Override
+ public void getCMD(CMD cmd) {
+// Log.d("runADBCMD",cmd.toString());
+ }
+ });
+ return adbSocketClient2.getCMD();
+ }
+
+ /**
+ * 是否存在su命令,并且有执行权限
+ *
+ * @return 存在su命令,并且有执行权限返回true
+ */
+ public boolean isSuEnable() {
+ File file = null;
+ String[] paths = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/"};
+ try {
+ for (String path : paths) {
+ file = new File(path + "su");
+ if (file.exists() && file.canExecute()) {
+ return testRoot();
+ }
+ }
+ } catch (Exception x) {
+ x.printStackTrace();
+ }
+ return false;
+ }
+
+ public boolean testRoot(){
+ CMD cmd = new CMD("id");
+ return cmd.getResultCode() == 0;
+ }
+
+ public boolean isADB(){
+ CMD cmd = runADBCmd("id|grep shell");
+ return !cmd.toString().isEmpty();
+ }
+
+ public CMD getCMD(String cmdstr,Boolean isRoot){
+ if(isRoot){
+ return new CMD(cmdstr);
+ }else{
+ return runADBCmd(cmdstr);
+ }
+ }
+
+}
diff --git a/app/src/main/java/org/fqaosp/utils/stringUtils.java b/app/src/main/java/org/fqaosp/utils/stringUtils.java
new file mode 100644
index 0000000..035a187
--- /dev/null
+++ b/app/src/main/java/org/fqaosp/utils/stringUtils.java
@@ -0,0 +1,46 @@
+package org.fqaosp.utils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class stringUtils {
+
+ public stringUtils(){}
+
+ /**
+ *
+ * 进行字符串正则提取
+ */
+ public String getByString(String src, String regex, String re_str) {
+ StringBuilder tmp = new StringBuilder();
+ Matcher m = Pattern.compile(regex).matcher(src);
+ if (m.find()) {
+ tmp.append(m.group().replaceAll(re_str, "") + "\n");
+ }
+ return tmp.toString();
+ }
+
+ /**
+ *
+ * 进行字符串正则提取
+ */
+ public String getByAllString(String src, String regex, String re_str) {
+ StringBuilder tmp = new StringBuilder();
+ Matcher m = Pattern.compile(regex).matcher(src);
+ while (m.find()) {
+ tmp.append(m.group().replaceAll(re_str, "") + "\n");
+ }
+ return tmp.toString();
+ }
+
+ //获取文件结尾类型
+ public String getPathByLastNameType(String filePath) {
+ return filePath.substring(filePath.lastIndexOf(".") + 1);
+ }
+
+ //获取路径文件名称
+ public String getPathByLastName(String filePath) {
+ return filePath.substring(filePath.lastIndexOf("/") + 1);
+ }
+
+}
diff --git a/app/src/main/java/org/fqaosp/utils/textUtils.java b/app/src/main/java/org/fqaosp/utils/textUtils.java
new file mode 100644
index 0000000..5a737e9
--- /dev/null
+++ b/app/src/main/java/org/fqaosp/utils/textUtils.java
@@ -0,0 +1,71 @@
+package org.fqaosp.utils;
+
+import android.app.Activity;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.widget.Toast;
+
+import org.fqaosp.entity.PKGINFO;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+public class textUtils {
+
+ public textUtils(){}
+
+ public void copyText(Context context, String str){
+ ClipboardManager cpm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
+ cpm.setText(str);
+ Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
+ }
+
+
+ //搜索列表匹配项
+ public ArrayList indexOfPKGS(Activity activity, String findStr, ArrayList pkginfos , ArrayList checkboxs, Integer types){
+ if(pkginfos.size() == 0){
+ packageUtils pkgutils = new packageUtils();
+ pkgutils.queryPKGS(activity,pkginfos,checkboxs,types);
+ }
+ return indexOfPKGS(pkginfos,checkboxs,findStr);
+ }
+
+
+ public Boolean isIndexOfStr(String str,String instr){
+ return str.toLowerCase(Locale.ROOT).indexOf(instr.toLowerCase(Locale.ROOT)) != -1;
+ }
+
+
+ //搜索列表匹配项
+ public ArrayList indexOfPKGS(ArrayList pkginfos , ArrayList checkboxs,String findStr){
+ checkboxs.clear();
+ ArrayList pkginfos2 = new ArrayList<>();
+ for (PKGINFO pkginfo : pkginfos) {
+ if(isIndexOfStr(pkginfo.getAppname(),findStr) || isIndexOfStr(pkginfo.getPkgname(),findStr)){
+ pkginfos2.add(pkginfo);
+ checkboxs.add(false);
+ }
+ }
+ pkginfos.clear();
+ return pkginfos2;
+ }
+
+ //搜索列表匹配项
+ public ArrayList indexOfLIST(ArrayList list , ArrayList checkboxs,String findStr){
+ checkboxs.clear();
+ ArrayList strings = new ArrayList<>();
+ if(findStr==null || findStr.isEmpty()){
+ return list;
+ }
+ for (String s : list) {
+ if(isIndexOfStr(s,findStr)){
+ strings.add(s);
+ checkboxs.add(false);
+ }
+ }
+ list.clear();
+ return strings;
+ }
+
+
+}
diff --git a/app/src/main/java/org/fqaosp/utils/userUtils.java b/app/src/main/java/org/fqaosp/utils/userUtils.java
new file mode 100644
index 0000000..f9fc18a
--- /dev/null
+++ b/app/src/main/java/org/fqaosp/utils/userUtils.java
@@ -0,0 +1,65 @@
+package org.fqaosp.utils;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Build;
+import android.os.Process;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+public class userUtils {
+
+ public userUtils(){}
+
+ //查询用户,默认
+ public void queryUSERS(Activity activity , ArrayList us){
+ queryUSERS(activity,us,null);
+ }
+
+ //查询用户
+ public void queryUSERS(Activity activity , ArrayList us , ArrayList checkboxs){
+ us.clear();
+ UserManager um = (UserManager) activity.getSystemService(Context.USER_SERVICE);
+ if(checkboxs != null){
+ checkboxs.clear();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ for (UserHandle userHandle : um.getUserProfiles()) {
+ String uid = getUID(userHandle.toString());
+ if(!uid.equals(getMyUID())){
+ us.add(uid);
+ checkboxs.add(false);
+ }
+ }
+ }
+ }else{
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ for (UserHandle userHandle : um.getUserProfiles()) {
+ String uid = getUID(userHandle.toString());
+ if(!uid.equals(getMyUID())){
+ us.add(uid);
+ }
+ }
+ }
+ }
+
+ Collections.sort(us,String::compareTo);
+
+ }
+
+
+
+ //移除uid多余字符串
+ public String getUID(String str){
+ return str.replaceAll("UserHandle|\\{|\\}","");
+ }
+
+ //获取自己当前应用的uid
+ public String getMyUID(){
+ return getUID(Process.myUserHandle().toString());
+ }
+
+
+}