2929import com .fox2code .mmm .utils .Http ;
3030import com .fox2code .mmm .utils .IntentHelper ;
3131import com .fox2code .mmm .utils .PropUtils ;
32+ import com .google .android .material .dialog .MaterialAlertDialogBuilder ;
3233import com .google .android .material .floatingactionbutton .ExtendedFloatingActionButton ;
3334import com .google .android .material .progressindicator .LinearProgressIndicator ;
3435import com .topjohnwu .superuser .CallbackList ;
@@ -64,7 +65,8 @@ protected void onCreate(Bundle savedInstanceState) {
6465 this .setDisplayHomeAsUpEnabled (true );
6566 setActionBarBackground (null );
6667 this .setOnBackPressedCallback (a -> {
67- this .canceled = true ; return false ;
68+ this .canceled = true ;
69+ return false ;
6870 });
6971 final Intent intent = this .getIntent ();
7072 final String target ;
@@ -97,7 +99,7 @@ protected void onCreate(Bundle savedInstanceState) {
9799 setTitle (name );
98100 this .textWrap = MainApplication .isTextWrapEnabled ();
99101 setContentView (this .textWrap ?
100- R .layout .installer_wrap :R .layout .installer );
102+ R .layout .installer_wrap : R .layout .installer );
101103 int background ;
102104 int foreground ;
103105 if (MainApplication .getINSTANCE ().isLightTheme () &&
@@ -133,7 +135,7 @@ protected void onCreate(Bundle savedInstanceState) {
133135 String errMessage = "Failed to download module zip" ;
134136 try {
135137 Log .i (TAG , "Downloading: " + target );
136- byte [] rawModule = Http .doHttpGet (target ,(progress , max , done ) -> {
138+ byte [] rawModule = Http .doHttpGet (target , (progress , max , done ) -> {
137139 if (max <= 0 && this .progressIndicator .isIndeterminate ())
138140 return ;
139141 this .runOnUiThread (() -> {
@@ -240,7 +242,7 @@ protected void onCreate(Bundle savedInstanceState) {
240242 }
241243
242244
243- private void doInstall (File file ,boolean noExtensions ,boolean rootless ) {
245+ private void doInstall (File file , boolean noExtensions , boolean rootless ) {
244246 if (this .canceled ) return ;
245247 UiThreadHandler .runAndWait (() -> {
246248 this .setOnBackPressedCallback (DISABLE_BACK_BUTTON );
@@ -278,7 +280,8 @@ private void doInstall(File file,boolean noExtensions,boolean rootless) {
278280 }
279281 moduleId = PropUtils .readModuleId (zipFile
280282 .getInputStream (zipFile .getEntry ("module.prop" )));
281- } catch (IOException ignored ) {}
283+ } catch (IOException ignored ) {
284+ }
282285 int compatFlags = AppUpdateManager .getFlagsForModule (moduleId );
283286 if ((compatFlags & AppUpdateManager .FLAG_COMPAT_NEED_32BIT ) != 0 )
284287 needs32bit = true ;
@@ -344,7 +347,8 @@ private void doInstall(File file,boolean noExtensions,boolean rootless) {
344347 }
345348 boolean success = installJob .exec ().isSuccess ();
346349 // Wait one UI cycle before disabling controller or processing results
347- UiThreadHandler .runAndWait (() -> {}); // to avoid race conditions
350+ UiThreadHandler .runAndWait (() -> {
351+ }); // to avoid race conditions
348352 installerController .disable ();
349353 String message = "- Install successful" ;
350354 if (!success ) {
@@ -368,7 +372,7 @@ public static class InstallerController extends CallbackList<String> {
368372 private String supportLink = "" ;
369373
370374 private InstallerController (LinearProgressIndicator progressIndicator ,
371- InstallerTerminal terminal ,File moduleFile ,
375+ InstallerTerminal terminal , File moduleFile ,
372376 boolean noExtension ) {
373377 this .progressIndicator = progressIndicator ;
374378 this .terminal = terminal ;
@@ -451,7 +455,8 @@ private void processCommand(String rawCommand) {
451455 try {
452456 this .progressIndicator .setProgressCompat (
453457 Short .parseShort (arg ), true );
454- } catch (Exception ignored ) {}
458+ } catch (Exception ignored ) {
459+ }
455460 break ;
456461 case "hideLoading" :
457462 this .progressIndicator .setVisibility (View .GONE );
@@ -544,7 +549,7 @@ private File extractInstallScript(String script) {
544549 }
545550
546551 @ SuppressWarnings ("SameParameterValue" )
547- private void setInstallStateFinished (boolean success , String message ,String optionalLink ) {
552+ private void setInstallStateFinished (boolean success , String message , String optionalLink ) {
548553 if (success && toDelete != null && !toDelete .delete ()) {
549554 SuFile suFile = new SuFile (toDelete .getAbsolutePath ());
550555 if (suFile .exists () && !suFile .delete ())
@@ -558,17 +563,36 @@ private void setInstallStateFinished(boolean success, String message,String opti
558563 this .progressIndicator .setVisibility (View .GONE );
559564
560565 // This should be improved ?
561- rebootFloatingButton .setOnClickListener (_view -> Shell .cmd ("/system/bin/svc power reboot || /system/bin/reboot" ).submit ());
566+ String reboot_cmd = "/system/bin/svc power reboot || /system/bin/reboot" ;
567+ rebootFloatingButton .setOnClickListener (_view -> {
568+ if (MainApplication .shouldPreventReboot ()) {
569+ MaterialAlertDialogBuilder builder =
570+ new MaterialAlertDialogBuilder (this );
571+
572+ builder
573+ .setTitle (R .string .install_terminal_reboot_now )
574+ .setCancelable (false )
575+ .setIcon (R .drawable .ic_reboot_24 )
576+ .setPositiveButton (R .string .yes , (x , y ) -> {
577+ Shell .cmd (reboot_cmd ).submit ();
578+ })
579+ .setNegativeButton (R .string .no , (x , y ) -> {
580+ x .dismiss ();
581+ }).show ();
582+ } else {
583+ Shell .cmd (reboot_cmd ).submit ();
584+ }
585+ });
562586 this .rebootFloatingButton .setVisibility (View .VISIBLE );
563587
564588 if (message != null && !message .isEmpty ())
565589 this .installerTerminal .addLine (message );
566590 if (!optionalLink .isEmpty ()) {
567591 this .setActionBarExtraMenuButton (ActionButtonType .supportIconForUrl (optionalLink ),
568592 menu -> {
569- IntentHelper .openUrl (this , optionalLink );
570- return true ;
571- });
593+ IntentHelper .openUrl (this , optionalLink );
594+ return true ;
595+ });
572596 } else if (success ) {
573597 final Intent intent = this .getIntent ();
574598 final String config = MainApplication .checkSecret (intent ) ?
0 commit comments