diff --git a/README.md b/README.md index afd90be..373d1f1 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,20 @@ 如果有新功能或建议,可以在GitHub提issue! -当前软件最新版本为:V1.3.6 +当前软件最新版本为:V1.3.6t + +# V1.3.6t + +1.修复安卓13应用恢复后,打开无法读取之前备份的数据,或者闪退问题. + +2.优化弹窗进度显示. + +3.优化获取组件、应用列表、扫描本地文件的界面交互. + +4.优化应用内存占用. + +5.修改版本号为V1.3.6t. + # V1.3.6 diff --git a/app/build.gradle b/app/build.gradle index 0bb2f5e..ece9470 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.fqaosp" minSdk 19 targetSdk 28 - versionCode 39 - versionName "1.3.6" + versionCode 40 + versionName "1.3.6t" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 70bd7f6..604e03f 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index a314e47..d730600 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -11,8 +11,8 @@ "type": "SINGLE", "filters": [], "attributes": [], - "versionCode": 39, - "versionName": "1.3.6", + "versionCode": 40, + "versionName": "1.3.6t", "outputFile": "app-release.apk" } ], diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 680a186..e358265 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,18 @@ tools:ignore="ProtectedPermissions" /> + + + + + + + + + adapterView, View view, int i, long l) { - jump(activity, menuEntities.get(i).getClassz(),isRoot,isADB); + new multiFunc().jump(activity, menuEntities.get(i).getClassz(),isRoot,isADB); return false; } }); @@ -195,7 +193,7 @@ public void onClick(View view) { Log.e("PKGMFQAOSP",e.toString()); } - String myStorageHomePath = getMyStorageHomePath(activity); + String myStorageHomePath = ft.getMyStorageHomePath(activity); String outDir = myStorageHomePath + "/cache/update"; File file = new File(outDir); if(!file.exists()){ @@ -203,7 +201,7 @@ public void onClick(View view) { } //如果有更新,那就直接获取更新日志与下载连接 if(haveupdate){ - ProgressDialog show = showMyDialog(MainActivity.this,"正在获取更新内容,请稍后(可能会出现无响应,请耐心等待)...."); + ProgressDialog show = du.showMyDialog(MainActivity.this,"正在获取更新内容,请稍后(可能会出现无响应,请耐心等待)...."); AlertDialog.Builder ab = new AlertDialog.Builder(context); View view2 = activity.getLayoutInflater().inflate(R.layout.update_activity, null); TextView updateatv1 = view2.findViewById(R.id.updateatv1); @@ -238,7 +236,7 @@ public void run() { Log.e("UPFQAOSP",e.toString()); } - sendHandlerMSG(handler,0); + du.sendHandlerMSG(handler,0); } }).start(); updateabt1.setOnClickListener(new View.OnClickListener() { @@ -331,8 +329,8 @@ public void onCheckedChanged(RadioGroup radioGroup, int i) { ab.setNegativeButton("检测", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - ProgressDialog show = showMyDialog(MainActivity.this,"正在检查更新,请稍后(可能会出现无响应,请耐心等待)...."); - Handler handler = dismissDialogHandler(0,show); + ProgressDialog show = du.showMyDialog(MainActivity.this,"正在检查更新,请稍后(可能会出现无响应,请耐心等待)...."); + Handler handler = du.dismissDialogHandler(0,show); new Thread(new Runnable() { @Override public void run() { @@ -354,7 +352,7 @@ public void run() { Log.e("MFQAOSP",e.toString()); } dialogInterface.dismiss(); - sendHandlerMSG(handler,0); + du.sendHandlerMSG(handler,0); } }).start(); } diff --git a/app/src/main/java/org/fqaosp/adapter/APPOPSINFOAdapter.java b/app/src/main/java/org/fqaosp/adapter/APPOPSINFOAdapter.java index 04de3b2..d37f61e 100644 --- a/app/src/main/java/org/fqaosp/adapter/APPOPSINFOAdapter.java +++ b/app/src/main/java/org/fqaosp/adapter/APPOPSINFOAdapter.java @@ -12,6 +12,7 @@ import org.fqaosp.R; import org.fqaosp.utils.CMD; +import org.fqaosp.utils.appopsCmdStr; import org.fqaosp.utils.multiFunc; import java.util.ArrayList; @@ -63,7 +64,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { switbs.set(i,b); switchbbb.setChecked(switbs.get(i)); String pkgcate = list.get(i); - CMD cmd = new CMD(multiFunc.getRunAppopsBySwtichCMD(b, mode, pkgname, pkgcate, uid)); + CMD cmd = new CMD(new appopsCmdStr().getRunAppopsBySwtichCMD(b, mode, pkgname, pkgcate, uid)); } }); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { diff --git a/app/src/main/java/org/fqaosp/myActivitys/apkDecompileMenuActivity.java b/app/src/main/java/org/fqaosp/myActivitys/apkDecompileMenuActivity.java index 4d05375..65150c2 100644 --- a/app/src/main/java/org/fqaosp/myActivitys/apkDecompileMenuActivity.java +++ b/app/src/main/java/org/fqaosp/myActivitys/apkDecompileMenuActivity.java @@ -1,19 +1,5 @@ package org.fqaosp.myActivitys; -import static org.fqaosp.utils.fileTools.execFileSelect; -import static org.fqaosp.utils.fileTools.getMyHomeFilesPath; -import static org.fqaosp.utils.fileTools.selectFile; -import static org.fqaosp.utils.multiFunc.checkTools; -import static org.fqaosp.utils.multiFunc.jump; -import static org.fqaosp.utils.multiFunc.queryUserPKGS; -import static org.fqaosp.utils.multiFunc.sendHandlerMSG; -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 static org.fqaosp.utils.multiFunc.showProcessBarDialogByCMD; -import static org.fqaosp.utils.multiFunc.showUsers; - import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; @@ -40,6 +26,8 @@ import org.fqaosp.R; import org.fqaosp.adapter.FILESHARINGVIEWPAGERAdapter; import org.fqaosp.entity.PKGINFO; +import org.fqaosp.utils.dialogUtils; +import org.fqaosp.utils.fileTools; import org.fqaosp.utils.fuckActivity; import org.fqaosp.utils.multiFunc; import org.fqaosp.utils.permissionRequest; @@ -63,6 +51,9 @@ public class apkDecompileMenuActivity extends AppCompatActivity implements View. private Context context; + private fileTools ft = new fileTools(); + private dialogUtils du = new dialogUtils(); + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -74,18 +65,19 @@ 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{ extractAssetsFiles(context,isRoot,isADB); initViews(); } - showLowMemDialog(context); + du.showLowMemDialog(context); } private void extractAssetsFiles(Context context , boolean isRoot , boolean isADB) { try { - checkTools(context,isADB); - String filesDir = getMyHomeFilesPath(context); + multiFunc m = new multiFunc(); + ft.checkTools(context,isADB); + String filesDir = ft.getMyHomeFilesPath(context); String jdkDir = filesDir + "/usr/opt/openjdk"; String apktoolFile = filesDir + "/usr/apktool.jar"; File file1 = new File(filesDir); @@ -95,15 +87,15 @@ private void extractAssetsFiles(Context context , boolean isRoot , boolean isADB file1.mkdirs(); } if (!jdkD.exists() ) { - showInfoMsg(context,"错误","未找到jdk,请重新导入工具包后再执行此项"); - jump(context, importToolsActivity.class,isRoot,isADB); + du.showInfoMsg(context,"错误","未找到jdk,请重新导入工具包后再执行此项"); + m.jump(context, importToolsActivity.class,isRoot,isADB); } if (!apkToolF.exists()) { - showInfoMsg(context,"错误","未找到apktool.jar,请重新导入工具包后再执行此项"); - jump(context, importToolsActivity.class,isRoot,isADB); + du.showInfoMsg(context,"错误","未找到apktool.jar,请重新导入工具包后再执行此项"); + m.jump(context, importToolsActivity.class,isRoot,isADB); } } catch (Exception e) { - showInfoMsg(context,"错误",e.toString()); + du.showInfoMsg(context,"错误",e.toString()); } } @@ -163,7 +155,7 @@ private void btClick(Context context , View view ,Activity activity , int mode){ } } - showProcessBarDialogByCMD(context,pplist,"正在"+(mode == 0 ? "回" : "反")+"编译中","当前正在"+(mode == 0 ? "回" : "反")+"编译: ",8, + du.showProcessBarDialogByCMD(context,pplist,"正在"+(mode == 0 ? "回" : "反")+"编译中","当前正在"+(mode == 0 ? "回" : "反")+"编译: ",8, null ,null,isRoot,"0",mode,null, null); } @@ -174,23 +166,6 @@ private void clearList() { list.clear(); } - 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() { - queryUserPKGS(this, pkginfos, checkboxs, 0); - } - @Override public boolean onMenuOpened(int featureId, Menu menu) { menu.clear(); @@ -222,27 +197,24 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(@NonNull MenuItem item) { int itemId = item.getItemId(); viewPageIndex = admavp.getCurrentItem(); + Activity activity = this; switch (viewPageIndex) { case 0: switch (itemId) { case 0: - getEnablePKGS(); - showPKGS(context,delv,pkginfos,checkboxs); + du.queryPKGProcessDialog(context,activity,delv,pkginfos,checkboxs,0,null,isRoot); break; case 1: - getPKGS(); - showPKGS(context,delv,pkginfos,checkboxs); + du.queryPKGProcessDialog(context,activity,delv,pkginfos,checkboxs,1,null,isRoot); break; case 2: - getUserPKGS(); - showPKGS(context,delv,pkginfos,checkboxs); + du.queryPKGProcessDialog(context,activity,delv,pkginfos,checkboxs,2,null,isRoot); break; case 3: - getUserEnablePKGS(); - showPKGS(context,delv,pkginfos,checkboxs); + du.queryPKGProcessDialog(context,activity,delv,pkginfos,checkboxs,3,null,isRoot); break; case 4: - showInfoMsg(this, "帮助信息", "该页面是用于apk反编译操作的,需要安装jdk与fqtools,采用传统apktool进行反编译操作,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + + du.showInfoMsg(this, "帮助信息", "该页面是用于apk反编译操作的,需要安装jdk与fqtools,采用传统apktool进行反编译操作,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + "1.点击右上角三个点,可以列出与之相匹配的应用列表,支持直接批量反编译它们.\r\n" + "2.点击选择本地文件,可以批量反编译用户本地的apk文件。\r\n" + "3.上面有个搜索框,支持中英文搜索,无大小写限制.\r\n"); @@ -255,7 +227,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { case 1: switch (itemId) { case 0: - showInfoMsg(this, "帮助信息", "该页面是用于apk回编译操作的,需要安装jdk与fqtools,采用传统apktool进行回编译操作,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + + du.showInfoMsg(this, "帮助信息", "该页面是用于apk回编译操作的,需要安装jdk与fqtools,采用传统apktool进行回编译操作,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + "1.点击选择本地文件夹,可以回编译用户本地反编译后的内容(需要选择带apktool.yml文件的项目工程)。\r\n" + "2.点击加载默认,可以列出所有从该应用反编译后的项目名称(推荐这个)。\r\n" + "3.点击上面开始回编译就会开始进行回编译操作.\r\n"); @@ -291,19 +263,19 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten int count = data.getClipData().getItemCount(); for (int i = 0; i < count; i++) { Uri uri = data.getClipData().getItemAt(i).getUri(); - selectFile(apkDecompileMenuActivity.this, storage, uri, list, checkboxs,msg,eq); + ft.selectFile(apkDecompileMenuActivity.this, storage, uri, list, checkboxs,msg,eq); } } else if (data.getData() != null) {//只有一个文件咯 Uri uri = data.getData(); - selectFile(apkDecompileMenuActivity.this, storage, uri, list, checkboxs, msg,eq); + ft.selectFile(apkDecompileMenuActivity.this, storage, uri, list, checkboxs, msg,eq); } if(viewPageIndex == 0) { - showUsers(context,delv,list,checkboxs); + du.showUsers(context,delv,list,checkboxs); } if(viewPageIndex == 1) { - showUsers(context,relv,list,checkboxs); + du.showUsers(context,relv,list,checkboxs); } } @@ -321,28 +293,29 @@ public void onClick(View view) { btClick(context,view,activity,0); break; case R.id.arab3: - execFileSelect(context, activity, "请选择 apktool.yml 文件"); + ft.execFileSelect(context, activity, "请选择 apktool.yml 文件"); break; case R.id.adab3: - execFileSelect(context, activity, "请选择.apk文件"); + ft.execFileSelect(context, activity, "请选择.apk文件"); break; case R.id.adab2: - getUserEnablePKGS(); - showPKGS(context,delv,pkginfos,checkboxs); + du.queryPKGProcessDialog(context,activity,delv,pkginfos,checkboxs,2,null,isRoot); break; case R.id.adab4: - String searchStr = adaet1.getText().toString(); - pkginfos = multiFunc.indexOfPKGS(activity, searchStr, pkginfos, checkboxs, 0); - showPKGS(context,delv,pkginfos,checkboxs); + du.showIndexOfPKGSDialog(context,activity,delv,adaet1,pkginfos,null,checkboxs); break; case R.id.arab2: - ProgressDialog show = showMyDialog(context,"正在扫描默认路径内容,请稍后(可能会出现无响应,请耐心等待)...."); + ProgressDialog show = du.showMyDialog(context,"正在扫描默认路径内容,请稍后(可能会出现无响应,请耐心等待)...."); Handler handler = new Handler(){ @Override public void handleMessage(@NonNull Message msg) { if(msg.what == 0){ show.dismiss(); - showUsers(context,relv,list,checkboxs); + du.showUsers(context,relv,list,checkboxs); + } + if(msg.what == 1){ + show.dismiss(); + Toast.makeText(context, "默认路径没有反编译后的内容", Toast.LENGTH_SHORT).show(); } } }; @@ -363,9 +336,9 @@ public void run() { Toast.makeText(context, "默认路径没有反编译后的内容", Toast.LENGTH_SHORT).show(); } } else { - Toast.makeText(context, "默认路径没有反编译后的内容", Toast.LENGTH_SHORT).show(); + du.sendHandlerMSG(handler,1); } - sendHandlerMSG(handler,0); + du.sendHandlerMSG(handler,0); } }).start(); break; diff --git a/app/src/main/java/org/fqaosp/myActivitys/appopsActivity.java b/app/src/main/java/org/fqaosp/myActivitys/appopsActivity.java index 51277f6..605584c 100644 --- a/app/src/main/java/org/fqaosp/myActivitys/appopsActivity.java +++ b/app/src/main/java/org/fqaosp/myActivitys/appopsActivity.java @@ -8,25 +8,7 @@ * * */ -import static org.fqaosp.utils.fileTools.execDirSelect; -import static org.fqaosp.utils.fileTools.execFileSelect; -import static org.fqaosp.utils.fileTools.getAllFileByEndName; -import static org.fqaosp.utils.fileTools.getPathByLastName; -import static org.fqaosp.utils.fileTools.getPathByLastNameType; -import static org.fqaosp.utils.fileTools.getSDPath; -import static org.fqaosp.utils.multiFunc.checkTools; -import static org.fqaosp.utils.multiFunc.clearList; -import static org.fqaosp.utils.multiFunc.getMyUID; -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 static org.fqaosp.utils.multiFunc.showPKGS; -import static org.fqaosp.utils.multiFunc.showProcessBarDialogByCMD; - import android.app.Activity; -import android.app.ProgressDialog; -import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -35,8 +17,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import android.provider.Settings; import android.view.ContextMenu; import android.view.Menu; @@ -57,17 +37,19 @@ import org.fqaosp.R; import org.fqaosp.entity.PKGINFO; +import org.fqaosp.utils.dialogUtils; import org.fqaosp.utils.fileTools; import org.fqaosp.utils.fuckActivity; import org.fqaosp.utils.makeWP; -import org.fqaosp.utils.multiFunc; +import org.fqaosp.utils.packageUtils; import org.fqaosp.utils.permissionRequest; +import org.fqaosp.utils.stringUtils; +import org.fqaosp.utils.textUtils; +import org.fqaosp.utils.userUtils; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; public class appopsActivity extends AppCompatActivity { @@ -91,6 +73,11 @@ public class appopsActivity extends AppCompatActivity { private Context con; private Activity activity; + private packageUtils pkgutils = new packageUtils(); + private dialogUtils du = new dialogUtils(); + private userUtils uu = new userUtils(); + private fileTools ft = new fileTools(); + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -112,7 +99,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { * */ uid = intent.getStringExtra("uid"); if(uid == null){ - uid=getMyUID(); + uid=uu.getMyUID(); } initBt(); } @@ -126,7 +113,7 @@ private void initBt(){ apopsasp2 = findViewById(R.id.apopsasp2); apopsasp1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, apops_permis)); apopsasp2.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, apops_opt)); - checkTools(this,isADB); + ft.checkTools(con,isADB); clickedBt(); } @@ -168,9 +155,7 @@ public void onNothingSelected(AdapterView adapterView) { appopsab2.setOnClickListener((v)->{ - String searchStr = apopsaet1.getText().toString(); - pkginfos = multiFunc.indexOfPKGS(activity,searchStr,pkginfos,checkboxs,0); - showPKGS(con,lv1,pkginfos,checkboxs); + du.showIndexOfPKGSDialog(con,activity,lv1,apopsaet1,pkginfos,null,checkboxs); }); @@ -202,7 +187,7 @@ public boolean onItemLongClick(AdapterView adapterView, View view, int i, lon //应用appops权限更改 apopsab6.setOnClickListener((v)->{ - showProcessBarDialogByCMD(con,addPkginfos(),"正在应用更改中...","当前应用更改的应用: ",2,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); + du.showProcessBarDialogByCMD(con,addPkginfos(),"正在应用更改中...","当前应用更改的应用: ",2,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); }); } @@ -268,22 +253,22 @@ public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu. //安装本地文件 private void installLocalPKG(int install_mode){ - showProcessBarDialogByCMD(con,addPkginfos(),"正在安装本地应用中...","当前正在安装: ",3,install_mode ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); + du.showProcessBarDialogByCMD(con,addPkginfos(),"正在安装本地应用中...","当前正在安装: ",3,install_mode ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); } //卸载应用 private void uninstallPKG(){ - showProcessBarDialogByCMD(con,addPkginfos(),"正在卸载应用...","当前正在卸载: ",1,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); + du.showProcessBarDialogByCMD(con,addPkginfos(),"正在卸载应用...","当前正在卸载: ",1,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); } //修改应用状态,禁用或者启用 private void changePKGState(){ - showProcessBarDialogByCMD(con,addPkginfos(),"正在修改应用状态中...","当前正在更改的应用: ",0,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); + du.showProcessBarDialogByCMD(con,addPkginfos(),"正在修改应用状态中...","当前正在更改的应用: ",0,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); } //提取apk文件 private void extractPKGFileToLocal(){ - showProcessBarDialogByCMD(con,addPkginfos(),"正在提取应用中...","当前正在提取的应用: ",11,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); + du.showProcessBarDialogByCMD(con,addPkginfos(),"正在提取应用中...","当前正在提取的应用: ",11,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); } //导出包名列表到本地 @@ -314,10 +299,10 @@ private void extractPKGList(Boolean isApp){ } catch (IOException e) { e.printStackTrace(); } - if(fileTools.writeDataToPath(sb.toString(),outFile,isApp)){ - showInfoMsg(appopsActivity.this,"提示","保存在: " + outFile); + if(ft.writeDataToPath(sb.toString(),outFile,isApp)){ + du.showInfoMsg(appopsActivity.this,"提示","保存在: " + outFile); }else{ - showInfoMsg(appopsActivity.this,"错误","导出包名列表失败"); + du.showInfoMsg(appopsActivity.this,"错误","导出包名列表失败"); } } } @@ -327,9 +312,7 @@ public boolean onContextItemSelected(@NonNull MenuItem item) { switch(item.getItemId()){ case 0: PKGINFO pkginfo = pkginfos.get(nowItemIndex); - ClipboardManager cpm = (ClipboardManager) appopsActivity.this.getSystemService(Context.CLIPBOARD_SERVICE); - cpm.setText(pkginfo.toString()); - Toast.makeText(appopsActivity.this, "已复制", Toast.LENGTH_SHORT).show(); + new textUtils().copyText(con,pkginfo.toString()); break; case 1: intoSYSApp(nowItemIndex); @@ -381,43 +364,14 @@ public boolean onCreateOptionsMenu(Menu menu) { return super.onCreateOptionsMenu(menu); } - private void getPKGByUID(String cmdstr){ - ProgressDialog show = showMyDialog(con,"正在检索用户 "+uid+" 下安装的应用,请稍后(可能会出现无响应,请耐心等待)...."); - Handler handler = new Handler(){ - @Override - public void handleMessage(@NonNull Message msg) { - if(msg.what==0){ - showPKGS(con,lv1,pkginfos,checkboxs); - show.dismiss(); - } - } - }; - new Thread(new Runnable() { - @Override - public void run() { - pkginfos.clear(); - checkboxs.clear(); - multiFunc.getPKGByUID(con,cmdstr,pkginfos,null,checkboxs,isRoot); - Collections.sort(pkginfos, new Comparator() { - @Override - public int compare(PKGINFO pkginfo, PKGINFO t1) { - return pkginfo.getAppname().compareTo(t1.getAppname()); - } - }); - sendHandlerMSG(handler,0); - } - }).start(); - - } - private void selectLocalFile(){ permissionRequest.getExternalStorageManager(appopsActivity.this); - execFileSelect(appopsActivity.this,appopsActivity.this,"请选择要安装的文件"); + ft.execFileSelect(appopsActivity.this,appopsActivity.this,"请选择要安装的文件"); } private void selectLocalDir(){ permissionRequest.getExternalStorageManager(appopsActivity.this); - execDirSelect(appopsActivity.this,appopsActivity.this,"请选择要安装的文件"); + ft.execDirSelect(appopsActivity.this,appopsActivity.this,"请选择要安装的文件"); } @Override @@ -427,48 +381,40 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { makeWP wp = new makeWP(); switch (itemId){ case 0: - if(uid == null || uid.equals(getMyUID())){ - multiFunc.queryEnablePKGS(this,pkginfos,checkboxs,0); - showPKGS(con,lv1,pkginfos,checkboxs); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,0,null,isRoot); }else{ - getPKGByUID(wp.getPkgByUIDCMD(uid)); + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,null,wp.getPkgByUIDCMD(uid),isRoot); } break; case 1: - if(uid == null || uid.equals(getMyUID())){ - multiFunc.queryPKGS(this,pkginfos,checkboxs,0); - showPKGS(con,lv1,pkginfos,checkboxs); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,1,null,isRoot); }else{ - getPKGByUID(wp.getPkgByUIDCMD(uid)); + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,null,wp.getPkgByUIDCMD(uid),isRoot); } - break; case 2: - if(uid == null|| uid.equals(getMyUID())){ - multiFunc.queryUserEnablePKGS(this,pkginfos,checkboxs,0); - showPKGS(con,lv1,pkginfos,checkboxs); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,2,null,isRoot); }else{ - getPKGByUID(wp.getUserPkgByUIDCMD(uid)); + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,null,wp.getUserPkgByUIDCMD(uid),isRoot); } - break; case 3: - if(uid == null|| uid.equals(getMyUID())){ - multiFunc.queryUserPKGS(this,pkginfos,checkboxs,0); - showPKGS(con,lv1,pkginfos,checkboxs); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,3,null,isRoot); }else{ - getPKGByUID(wp.getUserPkgByUIDCMD(uid)); + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,null,wp.getUserPkgByUIDCMD(uid),isRoot); } break; case 4: isDisable=true; - if(uid == null || uid.equals(getMyUID())){ - multiFunc.queryDisablePKGS(this,pkginfos,checkboxs,0); - showPKGS(con,lv1,pkginfos,checkboxs); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,4,null,isRoot); }else{ - getPKGByUID(wp.getDisablePkgByUIDCMD(uid)); + du.queryPKGProcessDialog(con,activity,lv1,pkginfos,checkboxs,null,wp.getDisablePkgByUIDCMD(uid),isRoot); } - break; case 5: selectLocalFile(); @@ -477,7 +423,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { selectLocalDir(); break; case 7: - showInfoMsg(this,"帮助信息","该页面是用于应用管理的,支持应用提取、详情跳转、卸载应用、导出应用信息、安装apks/apk应用,需要安装fqtools,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + + du.showInfoMsg(this,"帮助信息","该页面是用于应用管理的,支持应用提取、详情跳转、卸载应用、导出应用信息、安装apks/apk应用,需要安装fqtools,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + "1.搜索框,支持中英文搜索,无大小写限制.\r\n" + "2.长按应用列表会出现相关操作菜单,根据自己需求点击即可。支持批量操作。\r\n" + "3.右上角\"选择本地应用\",支持选择apks进行安装,传统apk文件可以加载出图标。\r\n" + @@ -500,13 +446,15 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis private void addPKGINFO(PackageManager pm,Uri uri , String storage){ String path = uri.getPath(); String filePath = null; - if(path.indexOf("document/primary") != -1){ + if(path.indexOf("document/msf") != -1){ + filePath = ft.uriToFilePath(uri,con); + }else if(path.indexOf("document/primary") != -1){ filePath = storage + "/" +uri.getPath().replaceAll("/document/primary:",""); }else{ filePath=uri.getPath(); } - - String nameType = getPathByLastNameType(filePath); + stringUtils su = new stringUtils(); + String nameType = su.getPathByLastNameType(filePath); if(nameType.equals("apk")){ PackageInfo packageInfo = pm.getPackageArchiveInfo(filePath, PackageManager.GET_PERMISSIONS); ApplicationInfo applicationInfo = packageInfo.applicationInfo; @@ -514,7 +462,7 @@ private void addPKGINFO(PackageManager pm,Uri uri , String storage){ checkboxs.add(false); }else if(nameType.equals("apks")){ Drawable d = ContextCompat.getDrawable(appopsActivity.this,R.drawable.ic_launcher_foreground); - pkginfos.add(new PKGINFO(getPathByLastName(filePath),"未知",filePath,"未知","未知", d,new File(filePath).length())); + pkginfos.add(new PKGINFO(su.getPathByLastName(filePath),"未知",filePath,"未知","未知", d,new File(filePath).length())); checkboxs.add(false); } } @@ -522,10 +470,10 @@ private void addPKGINFO(PackageManager pm,Uri uri , String storage){ @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - String storage = getSDPath(con); + String storage = ft.getSDPath(con); + PackageManager pm = getPackageManager(); if(requestCode == 0){ - clearList(pkginfos,checkboxs); - PackageManager pm = getPackageManager(); + pkgutils.clearList(pkginfos,checkboxs); if(data != null && data.getClipData() != null) {//有选择多个文件 int count = data.getClipData().getItemCount(); for(int i =0;i files = new ArrayList<>(); - getAllFileByEndName(filePath,".apk",files); + ft.getAllFileByEndName(filePath,".apk",files); for (File listFile : files) { addPKGINFO(pm,Uri.fromFile(listFile),storage); } - showPKGS(con,lv1,pkginfos,checkboxs); - showProcessBarDialogByCMD(con,pkginfos,"正在安装 [ "+filePath+" ] 文件夹里面的内容...","当前正在安装: ",4,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); + du.showPKGS(con,lv1,pkginfos,checkboxs); + du.showProcessBarDialogByCMD(con,pkginfos,"正在安装 [ "+filePath+" ] 文件夹里面的内容...","当前正在安装: ",4,null ,isDisable,isRoot,uid,null,apops_opt_index,apops_permis_index); }catch (Exception e){ - String filesDir = getExternalCacheDir().getAbsolutePath(); + String filesDir = getExternalFilesDir(null).toString(); + if(isRoot){ + filesDir = ft.getMyHomeFilesPath(con); + } String barfile = filesDir+"/"+script_name; String cmdstr = "sh "+barfile+" inapkonpath " + filePath; - showCMDInfoMSG(con,true,cmdstr,isRoot,"正在安装"+filePath+"路径下的应用,请稍后(可能会出现无响应,请耐心等待)....","安装"+filePath+"路径下的应用结束."); + du.showCMDInfoMSG(con,true,cmdstr,isRoot,"正在安装"+filePath+"路径下的应用,请稍后(可能会出现无响应,请耐心等待)....","安装"+filePath+"路径下的应用结束."); } }else{ - showInfoMsg(con,"错误","该功能需要adb或者root权限才能使用!!!!"); + du.showInfoMsg(con,"错误","该功能需要adb或者root权限才能使用!!!!"); } } } diff --git a/app/src/main/java/org/fqaosp/myActivitys/appopsInfoActivity.java b/app/src/main/java/org/fqaosp/myActivitys/appopsInfoActivity.java index a6d66ce..d4ba7c8 100644 --- a/app/src/main/java/org/fqaosp/myActivitys/appopsInfoActivity.java +++ b/app/src/main/java/org/fqaosp/myActivitys/appopsInfoActivity.java @@ -8,12 +8,9 @@ * * */ -import static org.fqaosp.utils.multiFunc.sendHandlerMSG; -import static org.fqaosp.utils.multiFunc.showInfoMsg; -import static org.fqaosp.utils.multiFunc.showProcessBarDialogByCMD; - import android.app.Activity; import android.app.AppOpsManager; +import android.app.ProgressDialog; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -45,8 +42,9 @@ import org.fqaosp.R; import org.fqaosp.adapter.APPOPSINFOAdapter; import org.fqaosp.entity.PKGINFO; +import org.fqaosp.utils.dialogUtils; import org.fqaosp.utils.fuckActivity; -import org.fqaosp.utils.multiFunc; +import org.fqaosp.utils.textUtils; import java.util.ArrayList; @@ -67,6 +65,7 @@ public class appopsInfoActivity extends AppCompatActivity { private Boolean apasb1Bool,apasb2Bool; private int mode; private boolean isRoot = false,isADB=false; + private dialogUtils du = new dialogUtils(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -92,10 +91,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { tv1.setText(appInfo.packageName); tv2.setText(appInfo.loadLabel(pm)); } catch (PackageManager.NameNotFoundException e) { - showInfoMsg(this,e.getClass().getName(),e.toString()); + du.showInfoMsg(this,e.getClass().getName(),e.toString()); } if(!isRoot){ - showInfoMsg(this,"提示","本功能需要root才能正常使用"); + du.showInfoMsg(this,"提示","本功能需要root才能正常使用"); } } @@ -114,25 +113,35 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { int itemId = item.getItemId(); + ProgressDialog show = du.showMyDialog(this,"正在获取组件信息中(请稍后...)"); + Handler handler = new Handler(){ + @Override + public void handleMessage(@NonNull Message msg) { + if(msg.what ==0){ + show.dismiss(); + showListView(lv1); + }else{ + show.dismiss(); + } + } + }; switch (itemId){ case 0: getPKGActivitys(packageInfo); - showListView(lv1); + break; case 1: getPKGServices(pm,appInfo); - showListView(lv1); break; case 2: getPKGPermission(packageInfo); - showListView(lv1); break; case 3: getPKGReceivers(pm,appInfo); - showListView(lv1); break; case 4: - showInfoMsg(this,"帮助信息","该页面是用于应用配置的,支持应用权限设置、服务禁/启用、活动项禁/启用,需要安装fqtools,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + + du.sendHandlerMSG(handler,1); + du.showInfoMsg(this,"帮助信息","该页面是用于应用配置的,支持应用权限设置、服务禁/启用、活动项禁/启用,需要安装fqtools,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + "1.右上角三个点,活动项,列出该应用的所有可修改的活动项,支持批量启动或者禁用.\r\n" + "2.右上角三个点,服务项,列出该应用的所有可修改的服务项,支持批量启动或者禁用.\r\n"+ "3.右上角三个点,权限列表,列出该应用的所有可修改的权限列表,支持批量启动或者禁用.\r\n"+ @@ -143,9 +152,11 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { ); break; case 5: + du.sendHandlerMSG(handler,1); fuckActivity.getIns().killall(); ; } + du.sendHandlerMSG(handler,0); return super.onOptionsItemSelected(item); } @@ -344,7 +355,7 @@ public void onClick(View view) { pplist.add(new PKGINFO(pkgname,list.get(i),list.get(i),null,switbs.get(i)?"false":"true",null,null)); } } - showProcessBarDialogByCMD(appopsInfoActivity.this,pplist,"正在修改组件状态中...","当前正在修改的组件名称: ",10,null ,null,isRoot,uid,mode,null,null); + du.showProcessBarDialogByCMD(appopsInfoActivity.this,pplist,"正在修改组件状态中...","当前正在修改的组件名称: ",10,null ,null,isRoot,uid,mode,null,null); } }); @@ -369,7 +380,7 @@ public void handleMessage(@NonNull Message msg) { checkboxs.clear(); for (int i = 0; i < list.size(); i++) { String s=list.get(i); - if(multiFunc.isIndexOfStr(s,searchStr)){ + if(new textUtils().isIndexOfStr(s,searchStr)){ strings.add(s); switbs2.add(switbs.get(i)); checkboxs.add(false); @@ -377,7 +388,7 @@ public void handleMessage(@NonNull Message msg) { } list=strings; switbs=switbs2; - sendHandlerMSG(handler,0); + du.sendHandlerMSG(handler,0); } }); diff --git a/app/src/main/java/org/fqaosp/myActivitys/backupRestoreActivity.java b/app/src/main/java/org/fqaosp/myActivitys/backupRestoreActivity.java index bd75dfb..20d663f 100644 --- a/app/src/main/java/org/fqaosp/myActivitys/backupRestoreActivity.java +++ b/app/src/main/java/org/fqaosp/myActivitys/backupRestoreActivity.java @@ -1,23 +1,7 @@ package org.fqaosp.myActivitys; -import static org.fqaosp.utils.fileTools.getMyHomeFilesPath; -import static org.fqaosp.utils.fileTools.getPathByLastName; -import static org.fqaosp.utils.fileTools.getSDPath; -import static org.fqaosp.utils.multiFunc.checkTools; -import static org.fqaosp.utils.multiFunc.getMyUID; -import static org.fqaosp.utils.multiFunc.getPKGByUID; -import static org.fqaosp.utils.multiFunc.getUID; -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.Activity; import android.app.ProgressDialog; -import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.os.Build; @@ -48,10 +32,14 @@ import org.fqaosp.R; import org.fqaosp.adapter.FILESHARINGVIEWPAGERAdapter; import org.fqaosp.entity.PKGINFO; +import org.fqaosp.utils.dialogUtils; +import org.fqaosp.utils.fileTools; import org.fqaosp.utils.fuckActivity; import org.fqaosp.utils.makeWP; -import org.fqaosp.utils.multiFunc; import org.fqaosp.utils.permissionRequest; +import org.fqaosp.utils.stringUtils; +import org.fqaosp.utils.textUtils; +import org.fqaosp.utils.userUtils; import java.io.File; import java.util.ArrayList; @@ -95,6 +83,9 @@ public class backupRestoreActivity extends AppCompatActivity { private boolean isRoot = false,isADB=false; + private fileTools ft = new fileTools(); + private dialogUtils du = new dialogUtils(); + @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -109,11 +100,11 @@ public void onCreate(@Nullable Bundle savedInstanceState) { if(isRoot){ userList = getLocalExistsUsers(); initViews(); - checkTools(context,isADB); + ft.checkTools(context,isADB); }else{ - showInfoMsg(context,"提示","本功能需要root才能正常使用"); + du.showInfoMsg(context,"提示","本功能需要root才能正常使用"); } - showLowMemDialog(context); + du.showLowMemDialog(context); } private void initViews(){ @@ -159,8 +150,8 @@ public void onClick(View view) { @Override public void onClick(View view) { String searchStr = braet1.getText().toString(); - list=multiFunc.indexOfLIST(list,checkboxs,searchStr); - showPKGS(restoreLv1); + list=new textUtils().indexOfLIST(list,checkboxs,searchStr); + du.showUsers(context,restoreLv1,list,checkboxs); } }); @@ -168,7 +159,7 @@ public void onClick(View view) { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { String str = list.get(i); - copyText(str); + new textUtils().copyText(context,str); return false; } }); @@ -202,18 +193,14 @@ public void onClick(View view) { brasearchb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - String searchStr = braet1.getText().toString(); - pkginfos = multiFunc.indexOfPKGS(backupRestoreActivity.this,searchStr,pkginfos,checkboxs,0); - showPKGS(backupLv1); + du.showIndexOfPKGSDialog(context,backupRestoreActivity.this,backupLv1,braet1,pkginfos,null,checkboxs); } }); backupLv1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { - PKGINFO pkginfo = pkginfos.get(i); - String str = pkginfo.toString(); - copyText(str); + new textUtils().copyText(context,pkginfos.get(i).toString()); return false; } }); @@ -222,12 +209,6 @@ public boolean onItemLongClick(AdapterView adapterView, View view, int i, lon } - private void copyText(String str){ - ClipboardManager cpm = (ClipboardManager) backupRestoreActivity.this.getSystemService(Context.CLIPBOARD_SERVICE); - cpm.setText(str); - Toast.makeText(backupRestoreActivity.this, "已复制", Toast.LENGTH_SHORT).show(); - } - private void initSpinnerBt(Spinner brasp,Spinner brasp2,Spinner brasp3){ brasp.setAdapter(new ArrayAdapter(context, android.R.layout.simple_list_item_1,mode)); brasp2.setAdapter(new ArrayAdapter(context, android.R.layout.simple_list_item_1,fileEnd)); @@ -239,7 +220,7 @@ private ArrayList getLocalExistsUsers(){ 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(new userUtils().getUID(userHandle.toString())); } } return userList; @@ -323,15 +304,15 @@ private void initBool(){ private void listLocalBackupFiles(){ file_end=fileEnd2[fileEnd_index]; permissionRequest.getExternalStorageManager(context); - String s = getSDPath(context); + String s = ft.getSDPath(context); String localBackupDir= s+"/backup_app"; File file = new File(localBackupDir); - 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(restoreLv1); + du.showUsers(context,restoreLv1,list,checkboxs); show.dismiss(); } } @@ -350,7 +331,7 @@ public void run() { } } } - sendHandlerMSG(handler,0); + du.sendHandlerMSG(handler,0); } }).start(); } @@ -361,14 +342,6 @@ private void clearlist(){ checkboxs.clear(); } - private void showPKGS(ListView listView){ - if(isBackup){ - multiFunc.showPKGS(context,listView,pkginfos,checkboxs); - }else{ - showUsers(context,listView,list,checkboxs); - } - } - @Override public boolean onMenuOpened(int featureId, Menu menu) { menu.clear(); @@ -402,7 +375,9 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(@NonNull MenuItem item) { int itemId = item.getItemId(); makeWP mw = new makeWP(); + Activity activity = this; clearlist(); + userUtils uu = new userUtils(); uid = userList!=null && userList.size()>0?userList.get(uid_index):"0"; viewPageIndex=brmavp.getCurrentItem(); switch (viewPageIndex) { @@ -410,47 +385,42 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { isBackup=true; switch (itemId){ case 0: - if(uid.equals(getMyUID())){ - multiFunc.queryEnablePKGS(this,pkginfos,checkboxs,0); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,0,null,isRoot); }else{ - getPKGByUID(context,mw.getPkgByUIDCMD(uid),pkginfos,null,checkboxs,isRoot); + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,null,mw.getPkgByUIDCMD(uid),isRoot); } - showPKGS(backupLv1); break; case 1: - if(uid.equals(getMyUID())){ - multiFunc.queryPKGS(this,pkginfos,checkboxs,0); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,1,null,isRoot); }else{ - getPKGByUID(context,mw.getPkgByUIDCMD(uid),pkginfos,null,checkboxs,isRoot); + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,null,mw.getPkgByUIDCMD(uid),isRoot); } - showPKGS(backupLv1); break; case 2: - if(uid.equals(getMyUID())){ - multiFunc.queryUserEnablePKGS(this,pkginfos,checkboxs,0); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,2,null,isRoot); }else{ - getPKGByUID(context,mw.getUserPkgByUIDCMD(uid),pkginfos,null,checkboxs,isRoot); + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,null,mw.getUserPkgByUIDCMD(uid),isRoot); } - showPKGS(backupLv1); break; case 3: - if(uid.equals(getMyUID())){ - multiFunc.queryUserPKGS(this,pkginfos,checkboxs,0); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,3,null,isRoot); }else{ - getPKGByUID(context,mw.getUserPkgByUIDCMD(uid),pkginfos,null,checkboxs,isRoot); + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,null,mw.getUserPkgByUIDCMD(uid),isRoot); } - showPKGS(backupLv1); break; case 4: - if(uid.equals(getMyUID())){ - multiFunc.queryDisablePKGS(this,pkginfos,checkboxs,0); + if(uid == null || uid.equals(uu.getMyUID())){ + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,4,null,isRoot); }else{ - getPKGByUID(context,mw.getDisablePkgByUIDCMD(uid),pkginfos,null,checkboxs,isRoot); + du.queryPKGProcessDialog(context,activity,backupLv1,pkginfos,checkboxs,null,mw.getDisablePkgByUIDCMD(uid),isRoot); } - showPKGS(backupLv1); break; case 5: - showInfoMsg(this,"帮助信息","该页面是用于应用备份与恢复的,支持应用备份与恢复,可选择只备份数据、安装包、安装包+数据,也支持仅恢复数据、安装包、安装包+数据,需要安装fqtools,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + + du.showInfoMsg(context,"帮助信息","该页面是用于应用备份与恢复的,支持应用备份与恢复,可选择只备份数据、安装包、安装包+数据,也支持仅恢复数据、安装包、安装包+数据,需要安装fqtools,如果没有安装,则会自动跳转安装页面,按照页面提示安装即可。\r\n" + "1.右上角三个点,显示本地备份文件,会列出默认目录下所有通过该软件备份的应用压缩包。\r\n" + "2.备份,备份应用.\r\n" + "3.全选,不管有没有勾选,都会操作当前列表所有应用.\r\n" + @@ -458,7 +428,8 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { "5.未勾选,仅操作勾选以外的应用.\r\n" + "6.{数据+安装包,数据,安装包},默认是全部,即备份该应用所有数据包括安装包。\r\n" + "7.{tgz,tbz,txz,tbr},默认是采用tar.gz压缩格式,这个速度最快,tbr模式速度最慢但解压速度接近gzip,txz速度仅次于tbr但是压缩率最高.\r\n" + - "8.搜索框支持中英文搜索,不区分大小写.\r\n" + "8.搜索框支持中英文搜索,不区分大小写.\r\n" + + "9.用户id,可以选择当前设备上存在的用户id,并使用备份或者恢复功能.\r\n" ); break; case 6: @@ -474,7 +445,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { listLocalBackupFiles(); break; case 1: - showInfoMsg(this,"帮助信息","\r\n" + + du.showInfoMsg(this,"帮助信息","\r\n" + "1.右上角三个点,显示本地备份文件,会列出默认目录下所有通过该软件备份的应用压缩包。\r\n" + "2.恢复,恢复应用.\r\n" + "3.全选,不管有没有勾选,都会操作当前列表所有应用.\r\n" + @@ -482,7 +453,8 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { "5.未勾选,仅操作勾选以外的应用.\r\n" + "6.{数据+安装包,数据,安装包},默认是全部,即备份该应用所有数据包括安装包。\r\n" + "7.{tgz,tbz,txz,tbr},默认是采用tar.gz压缩格式,这个速度最快,tbr模式速度最慢但解压速度接近gzip,txz速度仅次于tbr但是压缩率最高.\r\n" + - "8.搜索框支持中英文搜索,不区分大小写.\r\n" + "8.搜索框支持中英文搜索,不区分大小写.\r\n" + + "9.用户id,可以选择当前设备上存在的用户id,并使用备份或者恢复功能.\r\n" ); break; case 2: @@ -524,7 +496,7 @@ private void backup(Context context, ArrayList pkginfos, ArrayList pkginfos, ArrayList checkboxs,ArrayList plist = new ArrayList<>(); if(b[2] == false){ for (int i = 0; i < checkboxs.size(); i++) { - String s = getPathByLastName(list.get(i)); + String s = new stringUtils().getPathByLastName(list.get(i)); if(b[5] && !checkboxs.get(i)){ plist.add(new PKGINFO(getRestoryFileName(s,fileEnd2),null,null,null,null,null,new File(list.get(i)).length())); } @@ -556,7 +528,7 @@ private void restory(Context context, ArrayList checkboxs,ArrayList checkboxs,ArrayList 0 && filesize2 > 0 && time1 > 0 && time2 > 0) { @@ -557,8 +558,8 @@ public void onItemClick(AdapterView adapterView, View view, int i, long l) { DocumentFile dou = dd; DocumentFile dou2 = obb; String s = flist.get(i); - dou = checkDocum(dd, s); - dou2 = checkDocum(obb, s); + dou = ft.checkDocum(dd, s); + dou2 = ft.checkDocum(obb, s); showSelectFile(extstorage, finalPath + "/" + flist.get(i), dou, dou2, context); } }); @@ -694,7 +695,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { int itemId = item.getItemId(); switch (itemId) { case 0: - showInfoMsg(a, "帮助信息", "该页面是用于文件搜索的,你可以搜索/Android/data或者obb或者/sdcard/里面的文件。\r\n" + + du.showInfoMsg(a, "帮助信息", "该页面是用于文件搜索的,你可以搜索/Android/data或者obb或者/sdcard/里面的文件。\r\n" + "1.如果你需要搜索某个文件,可以直接在搜索框里面输入,然后点击搜索即可,默认是从内置存储目录开始搜索。\r\n" + "2.如果你需要搜索某个类型的文件,可以在\"文件类型\" 一栏输入文件类型的后缀名即可,比如需要搜索\"zip\"压缩包,直接输入zip然后再点击搜索即可.\r\n" + "3.如果你需要搜索某个大小范围内的文件,可以在\"小\"里面输入文件最小值,在\"大\"里面输入文件最大的值,右边有个单位选择,默认是byte(字节),可以选择最高pb,然后再点击搜索即可.\r\n" + diff --git a/app/src/main/java/org/fqaosp/myActivitys/fileSharingActivity.java b/app/src/main/java/org/fqaosp/myActivitys/fileSharingActivity.java index 5c7246b..da0bad0 100644 --- a/app/src/main/java/org/fqaosp/myActivitys/fileSharingActivity.java +++ b/app/src/main/java/org/fqaosp/myActivitys/fileSharingActivity.java @@ -1,9 +1,5 @@ package org.fqaosp.myActivitys; -import static org.fqaosp.utils.fileTools.getSize; -import static org.fqaosp.utils.multiFunc.sendHandlerMSG; -import static org.fqaosp.utils.multiFunc.showInfoMsg; -import static org.fqaosp.utils.multiFunc.showMyDialog; import static org.fqaosp.utils.permissionRequest.requestExternalStoragePermission; import android.app.Activity; @@ -34,10 +30,10 @@ import org.fqaosp.R; import org.fqaosp.adapter.FILESELECTAdapter; import org.fqaosp.adapter.FILESHARINGVIEWPAGERAdapter; -import org.fqaosp.adapter.PKGINFOAdapter; import org.fqaosp.entity.PKGINFO; +import org.fqaosp.utils.dialogUtils; +import org.fqaosp.utils.fileTools; import org.fqaosp.utils.fuckActivity; -import org.fqaosp.utils.multiFunc; import java.io.File; import java.io.FileInputStream; @@ -68,6 +64,10 @@ public class fileSharingActivity extends AppCompatActivity { private Button fsab1; private boolean isRoot=false , isADB=false; + private fileTools ft = new fileTools(); + private dialogUtils du = new dialogUtils(); + + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -99,7 +99,7 @@ private void initLayout() { fsaet1.setText("当前未连接WiFi或开启热点"); fsab1.setEnabled(false); } else { - ProgressDialog show = showMyDialog(this, "正在加载内容,请稍后(可能会出现无响应,请耐心等待)...."); + ProgressDialog show = du.showMyDialog(this, "正在加载内容,请稍后(可能会出现无响应,请耐心等待)...."); // preventDismissDialog(show); Handler handler = new Handler() { @Override @@ -117,7 +117,7 @@ public void run() { fsaet1.setText(ipAddress); initFileView(); initAppView(); - sendHandlerMSG(handler, 0); + du.sendHandlerMSG(handler, 0); } }).start(); @@ -196,8 +196,7 @@ public void onItemClick(AdapterView adapterView, View view, int i, long l) { } }); - getUserPKGS(); - showPKGS(fsalv); + du.queryPKGProcessDialog(this,this,fsalv,pkginfos,checkboxs,2,null,isRoot); } private void checkPeer(Activity that) { @@ -269,16 +268,6 @@ public void onItemClick(AdapterView adapterView, View view, int i, long l) { } - //获取对应的应用程序 - private void getUserPKGS() { - multiFunc.queryUserPKGS(this, pkginfos, checkboxs, 0); - } - - private void showPKGS(ListView listView) { - PKGINFOAdapter pkginfoAdapter = new PKGINFOAdapter(pkginfos, fileSharingActivity.this, checkboxs); - listView.setAdapter(pkginfoAdapter); - } - @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(Menu.NONE, 0, 0, "帮助"); @@ -292,7 +281,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { int itemId = item.getItemId(); switch (itemId) { case 0: - showInfoMsg(a, "帮助信息", "该页面是用于文件、应用网络共享的,当有人跟你同处在一个局域网的时候,就可以通过这个功能来分享文件给对方,该功能不需要root权限。\r\n" + + du.showInfoMsg(a, "帮助信息", "该页面是用于文件、应用网络共享的,当有人跟你同处在一个局域网的时候,就可以通过这个功能来分享文件给对方,该功能不需要root权限。\r\n" + "1.如何选择文件?长按你想要分享的文件名称即可加入分享队列,分享队列是全局的,也就是说,你这里选择完文件,还可以继续选择添加已经安装的应用程序,然后统一分享出去。\r\n" + "2.如何让别人访问我分享的内容?让其它人在浏览器输入你界面上那个ip地址跟端口,即可访问你分享的内容,只要在同一个局域网下,任何设备,只要支持网络连接都可以访问。\r\n" + "3.如何分享?选择完需要分享的文件或者应用后,点击开始分享即可开始运行。不允许后台挂着,此程序杜绝后台残留,故而没有加入后台常驻。\r\n" + @@ -505,7 +494,7 @@ public void returnFileList(ArrayList slist, String httpStatus, Socket so if (file.isDirectory() || file.toString().equals("上一页")) { sb.append(""); } else { - sb.append("
" + file.getName() + "" + getSize(file.length(), 0) + "
"); + sb.append("
" + file.getName() + "" + ft.getSize(file.length(), 0) + "
"); } } } diff --git a/app/src/main/java/org/fqaosp/myActivitys/imgMenuActivity.java b/app/src/main/java/org/fqaosp/myActivitys/imgMenuActivity.java index 97efff7..81aea2e 100644 --- a/app/src/main/java/org/fqaosp/myActivitys/imgMenuActivity.java +++ b/app/src/main/java/org/fqaosp/myActivitys/imgMenuActivity.java @@ -1,12 +1,6 @@ package org.fqaosp.myActivitys; -import static org.fqaosp.utils.multiFunc.getCMD; -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 static org.fqaosp.utils.multiFunc.showUsers; - +import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; @@ -34,8 +28,9 @@ import org.fqaosp.R; import org.fqaosp.adapter.FILESHARINGVIEWPAGERAdapter; import org.fqaosp.utils.CMD; +import org.fqaosp.utils.dialogUtils; import org.fqaosp.utils.fuckActivity; -import org.fqaosp.utils.multiFunc; +import org.fqaosp.utils.shellUtils; import java.io.File; import java.util.ArrayList; @@ -59,6 +54,9 @@ public class imgMenuActivity extends AppCompatActivity { private boolean isRoot = false,isADB=false; private String bootdev="/dev/block/bootdevice"; private String mapperdev="/dev/block/mapper"; + private Activity activity; + + private dialogUtils du = new dialogUtils(); @Override @@ -67,18 +65,19 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.apk_decompile_menu_activity); fuckActivity.getIns().add(this); setTitle("分区管理"); + context=this; + activity = this; Intent intent = getIntent(); isRoot = intent.getBooleanExtra("isRoot",false); isADB = intent.getBooleanExtra("isADB",false); if(isRoot){ initViews(); }else{ - showInfoMsg(this,"提示","本功能需要root才能正常使用"); + du.showInfoMsg(this,"提示","本功能需要root才能正常使用"); } } private void initViews() { - context=this; admavp = findViewById(R.id.admavp); dumpImgView = getLayoutInflater().inflate(R.layout.dump_img_activity, null); flashImgView = getLayoutInflater().inflate(R.layout.flash_img_activity, null); @@ -107,13 +106,10 @@ private void initFlashImgView() { b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - String searchStr = editText.getText().toString(); if(switchBool1){ - flashList2= multiFunc.indexOfLIST(flashList2,flashCheckboxs2,searchStr); - showUsers(context,flashLv2,flashList2,flashCheckboxs2); + du.showIndexOfPKGSDialog(context,activity,flashLv2,editText,null,flashList2,flashCheckboxs2); }else{ - flashList1= multiFunc.indexOfLIST(flashList1,flashCheckboxs1,searchStr); - showUsers(context,flashLv1,flashList1,flashCheckboxs1); + du.showIndexOfPKGSDialog(context,activity,flashLv1,editText,null,flashList1,flashCheckboxs1); } } }); @@ -127,13 +123,13 @@ public void onClick(View view) { ab.setNeutralButton("继续", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - ProgressDialog show = showMyDialog(context,"正在刷入,请稍后(可能会出现无响应,请耐心等待)...."); + ProgressDialog show = du.showMyDialog(context,"正在刷入,请稍后(可能会出现无响应,请耐心等待)...."); Handler handler = new Handler(){ @Override public void handleMessage(@NonNull Message msg) { if(msg.what==0){ show.dismiss(); - showInfoMsg(context,"信息",msg.obj.toString()); + du.showInfoMsg(context,"信息",msg.obj.toString()); } } }; @@ -157,8 +153,8 @@ public void run() { String booter=bootdev+"/by-name/"+partname; String cmdhead="dd if="+localImgPath; String cmdstr = "if [ -b "+mpper+" ];then "+cmdhead+" of="+mpper+" ; elif [ -b "+booter +" ];then "+cmdhead+" of="+booter +"; else echo 'error !';fi"; - CMD cmd = getCMD(cmdstr, true); - sendHandlerMSG(handler,0,"分区已刷入完毕: \r\n"+localImgPath+" ------>>>>> "+partname+"\r\n\r\n"+cmd.getResultCode()+" -- " + cmd.getResult()); + CMD cmd = new shellUtils().getCMD(cmdstr, true); + du.sendHandlerMSG(handler,0,"分区已刷入完毕: \r\n"+localImgPath+" ------>>>>> "+partname+"\r\n\r\n"+cmd.getResultCode()+" -- " + cmd.getResult()); } }).start(); } @@ -190,9 +186,7 @@ private void initDumpImgView() { b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - String searchStr = editText.getText().toString(); - dumpList= multiFunc.indexOfLIST(dumpList,dumpCheckboxs,searchStr); - showUsers(context,dumpLv1,dumpList,dumpCheckboxs); + du.showIndexOfPKGSDialog(context,activity,dumpLv1,editText,null,dumpList,dumpCheckboxs); } }); b2.setOnClickListener(new View.OnClickListener() { @@ -228,7 +222,7 @@ public void onClick(View view) { String booter=bootdev+"/by-name/${pp}"; String cmdstr = "if [ -b "+mpper+" ];then dd if="+mpper+" "+outCmd+";else dd if="+booter+" "+outCmd+";fi"; sb.append(");for pp in ${aaaa[@]};do "+cmdstr+";done;"); - showCMDInfoMSG(context,false,sb.toString(),true,"正在提取分区,请稍后(可能会出现无响应,请耐心等待)...","提取完成,文件存放在 : "+outDir); + du.showCMDInfoMSG(context,false,sb.toString(),true,"正在提取分区,请稍后(可能会出现无响应,请耐心等待)...","提取完成,文件存放在 : "+outDir); } }); @@ -321,7 +315,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { listLocalPartitionName(); break; case 1: - showInfoMsg(context,"帮助信息","该页面是用于提取系统分区文件的,可以提取by-name下所有分区文件,需要root权限授权。\r\n" + + du.showInfoMsg(context,"帮助信息","该页面是用于提取系统分区文件的,可以提取by-name下所有分区文件,需要root权限授权。\r\n" + "1.点击显示本机分区,则会开始扫描/dev/block/by-name下的所有文件内容,过一会就会展示在界面。\r\n" + "2.当分区列表出现数据时,你可以勾选分区名称进行提取操作。提取的数据保存在/storage/emulated/0/Android/data/org.fqaosp/cache/dumpimg路径下。\r\n" + "3-1.全选,无论你是否有勾选列表的选项,都默认列表全部的内容,点击提取则会全部提取出来。\r\n"+ @@ -345,7 +339,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { listLocalPartitionName(); break; case 2: - showInfoMsg(context,"帮助信息","该页面是用于将本地系统分区文件刷入对应分区的,默认将本地镜像文件刷入by-name下对应的分区名称,需要root权限授权。\r\n" + + du.showInfoMsg(context,"帮助信息","该页面是用于将本地系统分区文件刷入对应分区的,默认将本地镜像文件刷入by-name下对应的分区名称,需要root权限授权。\r\n" + "1.点击扫描本地镜像文件,则会开始扫描本地的所有img或者iso文件。\r\n" + "2.点击显示本机分区,则会开始扫描/dev/block/by-name下的所有文件内容,过一会就会展示在右边界面。\r\n" + "3.刷入,当分区列表出现数据时,你可以勾选本地镜像文件跟分区名称进行刷入操作。只会刷入左边第一个勾选的本地文件,只会刷入右边第一个勾选的分区名称,要注意一下。\r\n" + @@ -365,12 +359,12 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { private void listLocalImgName(){ clearFlash1List(); - ProgressDialog show = showMyDialog(context,"正在扫描本地镜像文件,请稍后(可能会出现无响应,请耐心等待)...."); + ProgressDialog show = du.showMyDialog(context,"正在扫描本地镜像文件,请稍后(可能会出现无响应,请耐心等待)...."); Handler handler = new Handler(){ @Override public void handleMessage(@NonNull Message msg) { if(msg.what==0){ - showUsers(context,flashLv1,flashList1,flashCheckboxs1); + du.showUsers(context,flashLv1,flashList1,flashCheckboxs1); show.dismiss(); } } @@ -388,7 +382,7 @@ public void run() { flashList1.add(s1); flashCheckboxs1.add(false); } - sendHandlerMSG(handler,0); + du.sendHandlerMSG(handler,0); } }).start(); } @@ -400,15 +394,15 @@ private void listLocalPartitionName() { }else{ clearFlash2List(); } - AlertDialog show = showMyDialog(context,"正在扫描本地分区系统,请稍后(可能会出现无响应,请耐心等待)...."); + AlertDialog show = du.showMyDialog(context,"正在扫描本地分区系统,请稍后(可能会出现无响应,请耐心等待)...."); Handler handler = new Handler(){ @Override public void handleMessage(@NonNull Message msg) { if(msg.what==0){ if(viewPageIndex == 0){ - showUsers(context,dumpLv1,dumpList,dumpCheckboxs); + du.showUsers(context,dumpLv1,dumpList,dumpCheckboxs); }else{ - showUsers(context,flashLv2,flashList2,flashCheckboxs2); + du.showUsers(context,flashLv2,flashList2,flashCheckboxs2); } show.dismiss(); } @@ -427,7 +421,7 @@ public void run() { flashCheckboxs2.add(false); } } - sendHandlerMSG(handler,0); + du.sendHandlerMSG(handler,0); } }).start(); } diff --git a/app/src/main/java/org/fqaosp/myActivitys/importToolsActivity.java b/app/src/main/java/org/fqaosp/myActivitys/importToolsActivity.java index 6138132..ece2ea2 100644 --- a/app/src/main/java/org/fqaosp/myActivitys/importToolsActivity.java +++ b/app/src/main/java/org/fqaosp/myActivitys/importToolsActivity.java @@ -1,17 +1,5 @@ package org.fqaosp.myActivitys; -import static org.fqaosp.utils.fileTools.copyFile; -import static org.fqaosp.utils.fileTools.execFileSelect; -import static org.fqaosp.utils.fileTools.extactAssetsFile; -import static org.fqaosp.utils.fileTools.getMyHomeFilesPath; -import static org.fqaosp.utils.fileTools.selectFile; -import static org.fqaosp.utils.fileTools.writeDataToPath; -import static org.fqaosp.utils.multiFunc.checkTools; -import static org.fqaosp.utils.multiFunc.dismissDialogHandler; -import static org.fqaosp.utils.multiFunc.sendHandlerMSG; -import static org.fqaosp.utils.multiFunc.showInfoMsg; -import static org.fqaosp.utils.multiFunc.showMyDialog; - import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; @@ -29,6 +17,8 @@ import org.fqaosp.R; import org.fqaosp.utils.CMD; +import org.fqaosp.utils.dialogUtils; +import org.fqaosp.utils.fileTools; import org.fqaosp.utils.fuckActivity; import org.fqaosp.utils.netUtils; import org.fqaosp.utils.permissionRequest; @@ -44,6 +34,8 @@ public class importToolsActivity extends Activity { private Button itab1 , itab2,itab5,itab6,itab7,itab8; private String fqfile="fqtools.tar.xz"; private boolean isRoot=false , isADB=false; + private fileTools ft = new fileTools(); + private dialogUtils du = new dialogUtils(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -74,14 +66,14 @@ private void clickButton(){ Activity activity = this; itab1.setOnClickListener((v)->{ - String filesPath = getMyHomeFilesPath(importToolsActivity.this); + String filesPath = ft.getMyHomeFilesPath(importToolsActivity.this); String fqtoolsd = filesPath+"/fqtools"; File file = new File(fqtoolsd); itatv1.setText(file.exists() ? "fqtools已经安装" : "fqtools未安装,请前往 https://github.com/MrsEWE44/FQAOSP/releases 下载最新工具包"); }); itab2.setOnClickListener((v)->{ - execFileSelect(importToolsActivity.this,importToolsActivity.this,"请选择 "+fqfile+" 文件"); + ft.execFileSelect(importToolsActivity.this,importToolsActivity.this,"请选择 "+fqfile+" 文件"); }); @@ -94,18 +86,18 @@ private void clickButton(){ String myStorageHomeCachePath = context.getExternalCacheDir().toString(); String filepath = myStorageHomeCachePath+"/"+new File(url).getName(); new netUtils().downloadFileOnUrlByAndorid(context,filepath,url); - showInfoMsg(context,"提示","等待下载完成之后,就可以手动安装了!下载完成后的文件,会保存在 "+filepath); + du.showInfoMsg(context,"提示","等待下载完成之后,就可以手动安装了!下载完成后的文件,会保存在 "+filepath); }); itab7.setOnClickListener((v)->{ - String filesPath = getMyHomeFilesPath(context); + String filesPath = ft.getMyHomeFilesPath(context); String s = Environment.getExternalStorageDirectory().toString(); String makeFQTOOLSScriptFile = filesPath+"/makefqtools.sh"; File makeFQTOOLSScriptF = new File(makeFQTOOLSScriptFile); if(makeFQTOOLSScriptF.exists()){ makeFQTOOLSScriptF.delete(); } - extactAssetsFile(this,"makefqtools.sh",makeFQTOOLSScriptFile); + ft.extactAssetsFile(this,"makefqtools.sh",makeFQTOOLSScriptFile); String outPath = s+"/Download/FQTOOLS"; String fqtools = filesPath+"/makefqtools.sh"; String outFile = outPath+"/makefqtools.sh"; @@ -113,7 +105,7 @@ private void clickButton(){ if(!file.exists()){ file.mkdirs(); } - if(copyFile(fqtools,outFile)){ + if(ft.copyFile(fqtools,outFile)){ File file1 = new File(outFile); if(file1.exists()){ itatv1.setText("你只需要复制下面这段命令在termux里边执行,随后等待出现\"make fqtools ok !\" 字样,然后选择本地安装即可.工具包在Downloads文件夹里面.\r\nsh storage/downloads/FQTOOLS/makefqtools.sh\r\n"); @@ -124,7 +116,7 @@ private void clickButton(){ }); itab8.setOnClickListener((v)->{ - String filesPath = getMyHomeFilesPath(context); + String filesPath = ft.getMyHomeFilesPath(context); String s = Environment.getExternalStorageDirectory().toString(); String scriptName="startADBServiceByFQAOSP.sh"; String makeFQTOOLSScriptFile = filesPath+"/"+scriptName; @@ -134,7 +126,7 @@ private void clickButton(){ String cmdstr ="killall FQAOSPADB\n" + "exec app_process -Djava.class.path=\""+context.getApplicationInfo().sourceDir+"\" /system/bin --nice-name=FQAOSPADB org.fqaosp.service.startADBService >>/dev/null 2>&1 &\n" + "echo \"run fqtools ok\""; - writeDataToPath(cmdstr,makeFQTOOLSScriptFile,false); + ft.writeDataToPath(cmdstr,makeFQTOOLSScriptFile,false); } String outPath = s+"/Download/FQTOOLS"; String fqtools = filesPath+"/"+scriptName; @@ -143,7 +135,7 @@ private void clickButton(){ if(!file.exists()){ file.mkdirs(); } - if(copyFile(fqtools,outFile)){ + if(ft.copyFile(fqtools,outFile)){ File file1 = new File(outFile); if(file1.exists()){ itatv1.setText("你只需要复制下面这段命令在adb shell里边执行,随后等待出现\"run fqtools ok !\" 字样即可.\r\nsh "+outFile+"\r\n"); @@ -162,20 +154,20 @@ private void clearList(){ private void extractFile(String s, String fff){ String myuid = Process.myUid()+""; - String filesPath = getMyHomeFilesPath(importToolsActivity.this); + String filesPath = ft.getMyHomeFilesPath(importToolsActivity.this); new File(filesPath).mkdirs(); String outName = filesPath+"/"+fff; - if(copyFile(s,outName)){ - checkTools(this,isADB); + if(ft.copyFile(s,outName)){ + ft.checkTools(this,isADB); String cmd = "cd " + filesPath + " && sh extract.sh && cd ../ && chown -R "+myuid+":"+myuid+ " files/"; - ProgressDialog show = showMyDialog(importToolsActivity.this,"正在安装插件,请稍后(可能会出现无响应,请耐心等待)...."); - Handler handler = dismissDialogHandler(0,show); + ProgressDialog show = du.showMyDialog(importToolsActivity.this,"正在安装插件,请稍后(可能会出现无响应,请耐心等待)...."); + Handler handler = du.dismissDialogHandler(0,show); new Thread(new Runnable() { @Override public void run() { CMD cmd1 = new CMD(cmd,false); Log.d("importTools",cmd1.getResultCode() +" -- " + cmd1.getResult()); - sendHandlerMSG(handler,0); + du.sendHandlerMSG(handler,0); } }).start(); }else{ @@ -193,11 +185,11 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten int count = data.getClipData().getItemCount(); for(int i =0;i 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()); + } + + +}