4444public class MainActivity extends AppCompatActivity {
4545
4646 private long rootKey = 0x7F6766F8 ;
47-
4847 private String suBasePath = "/data/local/tmp" ;
4948
5049 //保存的本地配置信息
@@ -193,26 +192,51 @@ public void onClick(View v) {
193192 }
194193 });
195194
196- Button su_env_inject_btn = findViewById (R .id .su_env_inject_btn );
197- su_env_inject_btn .setOnClickListener (new View .OnClickListener () {
195+ Button su_env_inject_btn1 = findViewById (R .id .su_env_inject_btn1 );
196+ su_env_inject_btn1 .setOnClickListener (new View .OnClickListener () {
197+ @ Override
198+ public void onClick (View v ) {
199+ if (!guideOpenUsbDebugSwitch ()) {
200+ return ;
201+ }
202+ //1.获取su工具文件路径
203+ String suToolsFilePath = WirteSuToolsFilePath ("simple_su" , MainActivity .this );
204+ showConsoleMsg (suToolsFilePath );
205+
206+ //2.安装su工具
207+ String suFolderHeadFlag = "su_ver1" ;
208+ String insRet = installSuTools (rootKey , suBasePath , suToolsFilePath , suFolderHeadFlag );
209+ showConsoleMsg (insRet );
210+ if (insRet .indexOf ("installSuTools done." ) == -1 ) {
211+ return ;
212+ }
213+
214+ //3.选择APP进程
215+ showSelectAppWindow (suFolderHeadFlag );
216+
217+ }
218+ });
219+ Button su_env_inject_btn2 = findViewById (R .id .su_env_inject_btn2 );
220+ su_env_inject_btn2 .setOnClickListener (new View .OnClickListener () {
198221 @ Override
199222 public void onClick (View v ) {
200223 if (!guideOpenUsbDebugSwitch ()) {
201224 return ;
202225 }
203226 //1.获取su工具文件路径
204- String suToolsFilePath = WirteSuToolsFilePath (MainActivity .this );
227+ String suToolsFilePath = WirteSuToolsFilePath ("su" , MainActivity .this );
205228 showConsoleMsg (suToolsFilePath );
206229
207230 //2.安装su工具
208- String insRet = installSuTools (rootKey , suBasePath , suToolsFilePath );
231+ String suFolderHeadFlag = "su_ver2" ;
232+ String insRet = installSuTools (rootKey , suBasePath , suToolsFilePath ,suFolderHeadFlag );
209233 showConsoleMsg (insRet );
210234 if (insRet .indexOf ("installSuTools done." ) == -1 ) {
211235 return ;
212236 }
213237
214238 //3.选择APP进程
215- showSelectAppWindow ();
239+ showSelectAppWindow (suFolderHeadFlag );
216240
217241 }
218242 });
@@ -221,7 +245,9 @@ public void onClick(View v) {
221245 clean_su_btn .setOnClickListener (new View .OnClickListener () {
222246 @ Override
223247 public void onClick (View v ) {
224- showConsoleMsg (uninstallSuTools (rootKey ,suBasePath ));
248+ //让adbd自我重启
249+ showConsoleMsg (killAdbdProcess (rootKey ));
250+ showConsoleMsg (uninstallSuTools (rootKey ,suBasePath , "su" ));
225251 }
226252 });
227253
@@ -279,7 +305,7 @@ public boolean guideOpenUsbDebugSwitch() {
279305 AlertDialog .Builder builder = new AlertDialog .Builder (MainActivity .this )
280306 .setTitle ("提示" )
281307 .setCancelable (false )
282- .setMessage ("请先到开发者选项页面里打开【USB调试 】开关(提示:在手机关于页面里连续点击系统版本号可启用开发者选项页面)" )
308+ .setMessage ("请先到开发者选项页面里【打开USB调试 】开关(提示:在手机关于页面里连续点击系统版本号可启用开发者选项页面)" )
283309 .setOnDismissListener (new DialogInterface .OnDismissListener () {
284310 @ Override
285311 public void onDismiss (DialogInterface dialog ) {
@@ -311,7 +337,7 @@ public boolean guideCloseUsbDebugSwitch() {
311337 AlertDialog .Builder builder = new AlertDialog .Builder (MainActivity .this )
312338 .setTitle ("提示" )
313339 .setCancelable (false )
314- .setMessage ("请先到开发者选项页面里关闭【USB调试 】开关" )
340+ .setMessage ("请先到开发者选项页面里【关闭USB调试 】开关" )
315341 .setOnDismissListener (new DialogInterface .OnDismissListener () {
316342 @ Override
317343 public void onDismiss (DialogInterface dialog ) {
@@ -352,7 +378,7 @@ public void handleMessage(@NonNull Message msg) {
352378
353379 new Thread () {
354380 public void run () {
355- String ret = autoSuEnvInject (rootKey , appItem .getPackageName (), suBasePath );
381+ String ret = autoSuEnvInject (rootKey , appItem .getPackageName (), suBasePath , appItem . getSuFolderHeadFlag () );
356382 runOnUiThread (new Runnable () {
357383 public void run () {
358384 showConsoleMsg (ret );
@@ -388,7 +414,7 @@ public void onClick(DialogInterface dialog, int which) {
388414 };
389415
390416 //显示选择应用程序窗口
391- public void showSelectAppWindow () {
417+ public void showSelectAppWindow (String suFolderHeadFlag ) {
392418 final PopupWindow popupWindow = new PopupWindow (this );
393419
394420 View view = View .inflate (this , R .layout .select_app_wnd , null );
@@ -456,7 +482,8 @@ public void onDismiss() { //窗口即将关闭
456482 appList .add (new SelectAppRecyclerItem (
457483 icon ,
458484 showName ,
459- packageName ));
485+ packageName ,
486+ suFolderHeadFlag ));
460487 }
461488 for (int i = 0 ; i < packages .size (); i ++) {
462489 PackageInfo packageInfo = packages .get (i );
@@ -476,7 +503,8 @@ public void onDismiss() { //窗口即将关闭
476503 appList .add (new SelectAppRecyclerItem (
477504 icon ,
478505 showName ,
479- packageName ));
506+ packageName ,
507+ suFolderHeadFlag ));
480508 }
481509
482510 SelectAppRecyclerAdapter adapter = new SelectAppRecyclerAdapter (
@@ -491,18 +519,17 @@ public void onDismiss() { //窗口即将关闭
491519
492520 }
493521
494- public static String WirteSuToolsFilePath (Context context ) {
495- String suFileName = "su" ;
522+ public static String WirteSuToolsFilePath (String suName , Context context ) {
496523 String suFilePath = "" ;
497524 try {
498- suFilePath = context .getFilesDir ().getPath () + "/" + suFileName ;
525+ suFilePath = context .getFilesDir ().getPath () + "/" + suName ;
499526 File file = new File (suFilePath );
500527 if (!file .exists ()) {
501528 if (!file .getParentFile ().exists ()) file .getParentFile ().mkdirs ();
502529 file .createNewFile ();
503530 }
504531 if (file .exists ()) {
505- InputStream inputStream = context .getAssets ().open (suFileName );
532+ InputStream inputStream = context .getAssets ().open (suName );
506533 FileOutputStream outputStream = new FileOutputStream (file );
507534 byte [] content = new byte [1024 ];
508535 while (inputStream .read (content ) > 0 ) {
@@ -532,9 +559,11 @@ public static String WirteSuToolsFilePath(Context context) {
532559
533560 public native String adbRoot (long rootKey );
534561
535- public native String installSuTools (long rootKey , String basePath , String suToolsFilePath );
562+ public native String installSuTools (long rootKey , String basePath , String suToolsFilePath , String suToolsFileFolderHeadFlags );
563+
564+ public native String uninstallSuTools (long rootKey , String basePath , String suToolsFileFolderHeadFlags );
536565
537- public native String uninstallSuTools (long rootKey , String basePath );
566+ public native String killAdbdProcess (long rootKey );
538567
539- public native String autoSuEnvInject (long rootKey , String targetProcessCmdline , String basePath );
568+ public native String autoSuEnvInject (long rootKey , String targetProcessCmdline , String basePath , String suToolsFileFolderHeadFlags );
540569}
0 commit comments