mirror of
https://github.com/Fox2Code/FoxMagiskModuleManager
synced 2024-10-30 15:20:15 +00:00
Add reboot protection
This commit is contained in:
parent
1cc6f8e771
commit
996a50f61e
@ -91,6 +91,10 @@ public class MainApplication extends CompatApplication {
|
||||
return getSharedPreferences().getBoolean("pref_showcase_mode", false);
|
||||
}
|
||||
|
||||
public static boolean shouldPreventReboot() {
|
||||
return getSharedPreferences().getBoolean("pref_prevent_reboot", false);
|
||||
}
|
||||
|
||||
public static boolean isShowIncompatibleModules() {
|
||||
return getSharedPreferences().getBoolean("pref_show_incompatible", false);
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.fox2code.mmm.utils.Hashes;
|
||||
import com.fox2code.mmm.utils.Http;
|
||||
import com.fox2code.mmm.utils.IntentHelper;
|
||||
import com.fox2code.mmm.utils.PropUtils;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator;
|
||||
import com.topjohnwu.superuser.CallbackList;
|
||||
@ -64,7 +65,8 @@ public class InstallerActivity extends CompatActivity {
|
||||
this.setDisplayHomeAsUpEnabled(true);
|
||||
setActionBarBackground(null);
|
||||
this.setOnBackPressedCallback(a -> {
|
||||
this.canceled = true; return false;
|
||||
this.canceled = true;
|
||||
return false;
|
||||
});
|
||||
final Intent intent = this.getIntent();
|
||||
final String target;
|
||||
@ -97,7 +99,7 @@ public class InstallerActivity extends CompatActivity {
|
||||
setTitle(name);
|
||||
this.textWrap = MainApplication.isTextWrapEnabled();
|
||||
setContentView(this.textWrap ?
|
||||
R.layout.installer_wrap :R.layout.installer);
|
||||
R.layout.installer_wrap : R.layout.installer);
|
||||
int background;
|
||||
int foreground;
|
||||
if (MainApplication.getINSTANCE().isLightTheme() &&
|
||||
@ -133,7 +135,7 @@ public class InstallerActivity extends CompatActivity {
|
||||
String errMessage = "Failed to download module zip";
|
||||
try {
|
||||
Log.i(TAG, "Downloading: " + target);
|
||||
byte[] rawModule = Http.doHttpGet(target,(progress, max, done) -> {
|
||||
byte[] rawModule = Http.doHttpGet(target, (progress, max, done) -> {
|
||||
if (max <= 0 && this.progressIndicator.isIndeterminate())
|
||||
return;
|
||||
this.runOnUiThread(() -> {
|
||||
@ -240,7 +242,7 @@ public class InstallerActivity extends CompatActivity {
|
||||
}
|
||||
|
||||
|
||||
private void doInstall(File file,boolean noExtensions,boolean rootless) {
|
||||
private void doInstall(File file, boolean noExtensions, boolean rootless) {
|
||||
if (this.canceled) return;
|
||||
UiThreadHandler.runAndWait(() -> {
|
||||
this.setOnBackPressedCallback(DISABLE_BACK_BUTTON);
|
||||
@ -278,7 +280,8 @@ public class InstallerActivity extends CompatActivity {
|
||||
}
|
||||
moduleId = PropUtils.readModuleId(zipFile
|
||||
.getInputStream(zipFile.getEntry("module.prop")));
|
||||
} catch (IOException ignored) {}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
int compatFlags = AppUpdateManager.getFlagsForModule(moduleId);
|
||||
if ((compatFlags & AppUpdateManager.FLAG_COMPAT_NEED_32BIT) != 0)
|
||||
needs32bit = true;
|
||||
@ -344,7 +347,8 @@ public class InstallerActivity extends CompatActivity {
|
||||
}
|
||||
boolean success = installJob.exec().isSuccess();
|
||||
// Wait one UI cycle before disabling controller or processing results
|
||||
UiThreadHandler.runAndWait(() -> {}); // to avoid race conditions
|
||||
UiThreadHandler.runAndWait(() -> {
|
||||
}); // to avoid race conditions
|
||||
installerController.disable();
|
||||
String message = "- Install successful";
|
||||
if (!success) {
|
||||
@ -368,7 +372,7 @@ public class InstallerActivity extends CompatActivity {
|
||||
private String supportLink = "";
|
||||
|
||||
private InstallerController(LinearProgressIndicator progressIndicator,
|
||||
InstallerTerminal terminal,File moduleFile,
|
||||
InstallerTerminal terminal, File moduleFile,
|
||||
boolean noExtension) {
|
||||
this.progressIndicator = progressIndicator;
|
||||
this.terminal = terminal;
|
||||
@ -451,7 +455,8 @@ public class InstallerActivity extends CompatActivity {
|
||||
try {
|
||||
this.progressIndicator.setProgressCompat(
|
||||
Short.parseShort(arg), true);
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
break;
|
||||
case "hideLoading":
|
||||
this.progressIndicator.setVisibility(View.GONE);
|
||||
@ -544,7 +549,7 @@ public class InstallerActivity extends CompatActivity {
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private void setInstallStateFinished(boolean success, String message,String optionalLink) {
|
||||
private void setInstallStateFinished(boolean success, String message, String optionalLink) {
|
||||
if (success && toDelete != null && !toDelete.delete()) {
|
||||
SuFile suFile = new SuFile(toDelete.getAbsolutePath());
|
||||
if (suFile.exists() && !suFile.delete())
|
||||
@ -558,7 +563,26 @@ public class InstallerActivity extends CompatActivity {
|
||||
this.progressIndicator.setVisibility(View.GONE);
|
||||
|
||||
// This should be improved ?
|
||||
rebootFloatingButton.setOnClickListener(_view -> Shell.cmd("/system/bin/svc power reboot || /system/bin/reboot").submit());
|
||||
String reboot_cmd = "/system/bin/svc power reboot || /system/bin/reboot";
|
||||
rebootFloatingButton.setOnClickListener(_view -> {
|
||||
if (MainApplication.shouldPreventReboot()) {
|
||||
MaterialAlertDialogBuilder builder =
|
||||
new MaterialAlertDialogBuilder(this);
|
||||
|
||||
builder
|
||||
.setTitle(R.string.install_terminal_reboot_now)
|
||||
.setCancelable(false)
|
||||
.setIcon(R.drawable.ic_reboot_24)
|
||||
.setPositiveButton(R.string.yes, (x, y) -> {
|
||||
Shell.cmd(reboot_cmd).submit();
|
||||
})
|
||||
.setNegativeButton(R.string.no, (x, y) -> {
|
||||
x.dismiss();
|
||||
}).show();
|
||||
} else {
|
||||
Shell.cmd(reboot_cmd).submit();
|
||||
}
|
||||
});
|
||||
this.rebootFloatingButton.setVisibility(View.VISIBLE);
|
||||
|
||||
if (message != null && !message.isEmpty())
|
||||
@ -566,9 +590,9 @@ public class InstallerActivity extends CompatActivity {
|
||||
if (!optionalLink.isEmpty()) {
|
||||
this.setActionBarExtraMenuButton(ActionButtonType.supportIconForUrl(optionalLink),
|
||||
menu -> {
|
||||
IntentHelper.openUrl(this, optionalLink);
|
||||
return true;
|
||||
});
|
||||
IntentHelper.openUrl(this, optionalLink);
|
||||
return true;
|
||||
});
|
||||
} else if (success) {
|
||||
final Intent intent = this.getIntent();
|
||||
final String config = MainApplication.checkSecret(intent) ?
|
||||
|
@ -25,6 +25,8 @@
|
||||
<string name="submit_modules">Submit a module</string>
|
||||
<string name="require_android_6">Require Android 6.0+</string>
|
||||
<string name="install_terminal_reboot_now">Reboot</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
|
||||
<!-- Module section translation -->
|
||||
<string name="module_last_update">Last update:</string>
|
||||
@ -38,6 +40,8 @@
|
||||
<string name="manage_repos_pref">Manage repos</string>
|
||||
<string name="showcase_mode_pref">Lockdown mode</string>
|
||||
<string name="showcase_mode_desc">Lockdown mode prevent manager to do action on modules</string>
|
||||
<string name="prevent_reboot_pref">Prevent reboot</string>
|
||||
<string name="prevent_reboot_desc">Prevents unexpected reboots</string>
|
||||
<string name="pref_category_settings">Settings</string>
|
||||
<string name="pref_category_info">Info</string>
|
||||
<string name="show_licenses">Show licenses</string>
|
||||
|
@ -47,6 +47,14 @@
|
||||
app:summary="@string/showcase_mode_desc"
|
||||
app:singleLineTitle="false" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:key="pref_prevent_reboot"
|
||||
app:icon="@drawable/ic_reboot_24"
|
||||
app:title="@string/prevent_reboot_pref"
|
||||
app:summary="@string/prevent_reboot_desc"
|
||||
app:singleLineTitle="false" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:key="pref_wrap_text"
|
||||
|
Loading…
Reference in New Issue
Block a user