Rework AnyKernel install to extend support to most AnyKernel modules

pull/147/head
Fox2Code 2 years ago
parent aa1bdc6706
commit d35489bcc5

@ -58,9 +58,11 @@ public class InstallerActivity extends CompatActivity {
private File toDelete; private File toDelete;
private boolean textWrap; private boolean textWrap;
private boolean canceled; private boolean canceled;
private boolean warnReboot;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
this.warnReboot = false;
this.moduleCache = new File(this.getCacheDir(), "installer"); this.moduleCache = new File(this.getCacheDir(), "installer");
if (!this.moduleCache.exists() && !this.moduleCache.mkdirs()) if (!this.moduleCache.exists() && !this.moduleCache.mkdirs())
Log.e(TAG, "Failed to mkdir module cache dir!"); Log.e(TAG, "Failed to mkdir module cache dir!");
@ -260,48 +262,26 @@ public class InstallerActivity extends CompatActivity {
String moduleId = null; String moduleId = null;
boolean anyKernel = false; boolean anyKernel = false;
boolean magiskModule = false; boolean magiskModule = false;
boolean anyKernelSystemLess = false;
File anyKernelInstallScript = new File(this.moduleCache, "update-binary"); File anyKernelInstallScript = new File(this.moduleCache, "update-binary");
try (ZipFile zipFile = new ZipFile(file)) { try (ZipFile zipFile = new ZipFile(file)) {
ZipEntry anyKernelSh = zipFile.getEntry("anykernel.sh"); // Check if module is AnyKernel module
if (anyKernelSh != null) { // Check if module is AnyKernel module if (zipFile.getEntry("anykernel.sh") != null) {
BufferedReader bufferedReader = new BufferedReader( ZipEntry updateBinary = zipFile.getEntry(
new InputStreamReader(zipFile.getInputStream(anyKernelSh))); "META-INF/com/google/android/update-binary");
String line; if (updateBinary != null) {
// Check if AnyKernel module support system-less BufferedReader bufferedReader = new BufferedReader(
while ((line = bufferedReader.readLine()) != null) { new InputStreamReader(zipFile.getInputStream(updateBinary)));
String trimmedLine = line.trim(); PrintStream printStream = new PrintStream(
if (trimmedLine.equals("do.modules=1")) new FileOutputStream(anyKernelInstallScript));
anyKernel = true; String line;
if (trimmedLine.equals("do.systemless=1")) while ((line = bufferedReader.readLine()) != null) {
anyKernelSystemLess = true; line = line.replace("/sbin/sh", "/system/bin/sh");
} line = line.replace("/data/adb/modules/ak3-helper",
bufferedReader.close(); "/data/adb/modules-update/ak3-helper");
if (anyKernelSystemLess && anyKernel) { printStream.println(line);
anyKernelSystemLess = false;
ZipEntry updateBinary = zipFile.getEntry(
"META-INF/com/google/android/update-binary");
if (updateBinary != null) {
bufferedReader = new BufferedReader(
new InputStreamReader(zipFile.getInputStream(updateBinary)));
PrintStream printStream = new PrintStream(
new FileOutputStream(anyKernelInstallScript));
while ((line = bufferedReader.readLine()) != null) {
String trimmedLine = line.trim();
if (trimmedLine.equals("mount_all;") ||
trimmedLine.equals("umount_all;"))
continue; // Do not mount anything
line = line.replace("/sbin/sh", "/system/bin/sh");
int prePatch = line.length();
line = line.replace("/data/adb/modules/ak3-helper",
"/data/adb/modules-update/ak3-helper");
if (prePatch != line.length()) anyKernelSystemLess = true;
printStream.println(line);
}
printStream.close();
bufferedReader.close();
if (!anyKernelSystemLess) anyKernelInstallScript.delete();
} }
printStream.close();
bufferedReader.close();
} }
anyKernel = true; anyKernel = true;
} }
@ -353,14 +333,12 @@ public class InstallerActivity extends CompatActivity {
String installCommand; String installCommand;
File installExecutable; File installExecutable;
if (anyKernel && moduleId == null) { // AnyKernel modules don't have a moduleId if (anyKernel && moduleId == null) { // AnyKernel modules don't have a moduleId
if (!anyKernelSystemLess) { this.warnReboot = true; // We should probably re-flash magisk...
this.setInstallStateFinished(false,
"! This AnyKernel module only support recovery install", null);
return;
}
installExecutable = anyKernelInstallScript; installExecutable = anyKernelInstallScript;
installCommand = "sh \"" + installExecutable.getAbsolutePath() + "\"" + // "unshare -m" is needed to force mount namespace isolation.
" /dev/null 0 \"" + file.getAbsolutePath() + "\""; // This allow AnyKernel to mess-up with mounts point without crashing the system!
installCommand = "unshare -m sh \"" + installExecutable.getAbsolutePath() + "\"" +
" /dev/null 1 \"" + file.getAbsolutePath() + "\"";
} else if (InstallerInitializer.peekMagiskVersion() >= } else if (InstallerInitializer.peekMagiskVersion() >=
Constants.MAGISK_VER_CODE_INSTALL_COMMAND && Constants.MAGISK_VER_CODE_INSTALL_COMMAND &&
((compatFlags & AppUpdateManager.FLAG_COMPAT_MAGISK_CMD) != 0 || ((compatFlags & AppUpdateManager.FLAG_COMPAT_MAGISK_CMD) != 0 ||
@ -376,7 +354,7 @@ public class InstallerActivity extends CompatActivity {
return; return;
} }
installCommand = "sh \"" + installExecutable.getAbsolutePath() + "\"" + installCommand = "sh \"" + installExecutable.getAbsolutePath() + "\"" +
" /dev/null 0 \"" + file.getAbsolutePath() + "\""; " /dev/null 1 \"" + file.getAbsolutePath() + "\"";
} else { } else {
this.setInstallStateFinished(false, this.setInstallStateFinished(false,
"! Zip file is not a valid Magisk or a AnyKernel module!", null); "! Zip file is not a valid Magisk or a AnyKernel module!", null);
@ -384,15 +362,23 @@ public class InstallerActivity extends CompatActivity {
} }
installerMonitor = new InstallerMonitor(installExecutable); installerMonitor = new InstallerMonitor(installExecutable);
if (moduleId != null) installerMonitor.setForCleanUp(moduleId); if (moduleId != null) installerMonitor.setForCleanUp(moduleId);
if (noExtensions) { if (anyKernel) {
final String adbTmp = "data/adb/tmp";
final String anyKernelHome = // Mirror mounts do not contain nosuid
InstallerInitializer.peekMirrorPath() +
"/" + adbTmp + "/anykernel";
installJob = Shell.cmd(arch32, "export MMM_EXT_SUPPORT=1",
"cd \"" + this.moduleCache.getAbsolutePath() + "\"",
"mkdir " + adbTmp, "export AKHOME=" + anyKernelHome,
installCommand).to(installerController, installerMonitor);
} else if (noExtensions) {
installJob = Shell.cmd(arch32, // No Extensions installJob = Shell.cmd(arch32, // No Extensions
"cd \"" + this.moduleCache.getAbsolutePath() + "\"", "cd \"" + this.moduleCache.getAbsolutePath() + "\"",
installCommand).to(installerController, installerMonitor); installCommand).to(installerController, installerMonitor);
} else { } else {
installJob = Shell.cmd(arch32, "export MMM_EXT_SUPPORT=1", installJob = Shell.cmd(arch32, "export MMM_EXT_SUPPORT=1",
"export MMM_USER_LANGUAGE=" + (MainApplication.isForceEnglish() ? "export MMM_USER_LANGUAGE=" + (MainApplication.isForceEnglish() ? "en-US" :
"en-US" : Resources.getSystem() Resources.getSystem().getConfiguration().locale.toLanguageTag()),
.getConfiguration().locale.toLanguageTag()),
"export MMM_APP_VERSION=" + BuildConfig.VERSION_NAME, "export MMM_APP_VERSION=" + BuildConfig.VERSION_NAME,
"export MMM_TEXT_WRAP=" + (this.textWrap ? "1" : "0"), "export MMM_TEXT_WRAP=" + (this.textWrap ? "1" : "0"),
"cd \"" + this.moduleCache.getAbsolutePath() + "\"", "cd \"" + this.moduleCache.getAbsolutePath() + "\"",
@ -618,8 +604,8 @@ public class InstallerActivity extends CompatActivity {
// This should be improved ? // This should be improved ?
String reboot_cmd = "/system/bin/svc power reboot || /system/bin/reboot"; String reboot_cmd = "/system/bin/svc power reboot || /system/bin/reboot";
rebootFloatingButton.setOnClickListener(_view -> { this.rebootFloatingButton.setOnClickListener(_view -> {
if (MainApplication.shouldPreventReboot()) { if (this.warnReboot || MainApplication.shouldPreventReboot()) {
MaterialAlertDialogBuilder builder = MaterialAlertDialogBuilder builder =
new MaterialAlertDialogBuilder(this); new MaterialAlertDialogBuilder(this);
@ -637,6 +623,7 @@ public class InstallerActivity extends CompatActivity {
Shell.cmd(reboot_cmd).submit(); Shell.cmd(reboot_cmd).submit();
} }
}); });
this.rebootFloatingButton.setVisibility(View.VISIBLE);
if (message != null && !message.isEmpty()) if (message != null && !message.isEmpty())
this.installerTerminal.addLine(message); this.installerTerminal.addLine(message);
@ -647,7 +634,6 @@ public class InstallerActivity extends CompatActivity {
return true; return true;
}); });
} else if (success) { } else if (success) {
this.rebootFloatingButton.setVisibility(View.VISIBLE);
final Intent intent = this.getIntent(); final Intent intent = this.getIntent();
final String config = MainApplication.checkSecret(intent) ? final String config = MainApplication.checkSecret(intent) ?
intent.getStringExtra(Constants.EXTRA_INSTALL_CONFIG) : null; intent.getStringExtra(Constants.EXTRA_INSTALL_CONFIG) : null;

@ -35,6 +35,10 @@ public class InstallerInitializer extends Shell.Initializer {
public static String peekMagiskPath() { public static String peekMagiskPath() {
return InstallerInitializer.MAGISK_PATH; return InstallerInitializer.MAGISK_PATH;
} }
public static String peekMirrorPath() {
return InstallerInitializer.MAGISK_PATH == null ? null :
InstallerInitializer.MAGISK_PATH + "/.magisk/mirror";
}
public static int peekMagiskVersion() { public static int peekMagiskVersion() {
return InstallerInitializer.MAGISK_VERSION_CODE; return InstallerInitializer.MAGISK_VERSION_CODE;
@ -128,8 +132,9 @@ public class InstallerInitializer extends Shell.Initializer {
MAGISK_PATH + "/.magisk/busybox"); MAGISK_PATH + "/.magisk/busybox");
} }
newJob.add("export MAGISKTMP=\"" + MAGISK_PATH + "/.magisk\""); newJob.add("export MAGISKTMP=\"" + MAGISK_PATH + "/.magisk\"");
newJob.add("export BOOTMODE=true");
newJob.add("$(which busybox 2> /dev/null) sh"); newJob.add("$(which busybox 2> /dev/null) sh");
} }
return true; return newJob.exec().isSuccess();
} }
} }

Loading…
Cancel
Save