@@ -58,9 +58,11 @@ public class InstallerActivity extends CompatActivity {
5858 private File toDelete ;
5959 private boolean textWrap ;
6060 private boolean canceled ;
61+ private boolean warnReboot ;
6162
6263 @ Override
6364 protected void onCreate (Bundle savedInstanceState ) {
65+ this .warnReboot = false ;
6466 this .moduleCache = new File (this .getCacheDir (), "installer" );
6567 if (!this .moduleCache .exists () && !this .moduleCache .mkdirs ())
6668 Log .e (TAG , "Failed to mkdir module cache dir!" );
@@ -260,48 +262,26 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
260262 String moduleId = null ;
261263 boolean anyKernel = false ;
262264 boolean magiskModule = false ;
263- boolean anyKernelSystemLess = false ;
264265 File anyKernelInstallScript = new File (this .moduleCache , "update-binary" );
265266 try (ZipFile zipFile = new ZipFile (file )) {
266- ZipEntry anyKernelSh = zipFile .getEntry ("anykernel.sh" );
267- if (anyKernelSh != null ) { // Check if module is AnyKernel module
268- BufferedReader bufferedReader = new BufferedReader (
269- new InputStreamReader (zipFile .getInputStream (anyKernelSh )));
270- String line ;
271- // Check if AnyKernel module support system-less
272- while ((line = bufferedReader .readLine ()) != null ) {
273- String trimmedLine = line .trim ();
274- if (trimmedLine .equals ("do.modules=1" ))
275- anyKernel = true ;
276- if (trimmedLine .equals ("do.systemless=1" ))
277- anyKernelSystemLess = true ;
278- }
279- bufferedReader .close ();
280- if (anyKernelSystemLess && anyKernel ) {
281- anyKernelSystemLess = false ;
282- ZipEntry updateBinary = zipFile .getEntry (
283- "META-INF/com/google/android/update-binary" );
284- if (updateBinary != null ) {
285- bufferedReader = new BufferedReader (
286- new InputStreamReader (zipFile .getInputStream (updateBinary )));
287- PrintStream printStream = new PrintStream (
288- new FileOutputStream (anyKernelInstallScript ));
289- while ((line = bufferedReader .readLine ()) != null ) {
290- String trimmedLine = line .trim ();
291- if (trimmedLine .equals ("mount_all;" ) ||
292- trimmedLine .equals ("umount_all;" ))
293- continue ; // Do not mount anything
294- line = line .replace ("/sbin/sh" , "/system/bin/sh" );
295- int prePatch = line .length ();
296- line = line .replace ("/data/adb/modules/ak3-helper" ,
297- "/data/adb/modules-update/ak3-helper" );
298- if (prePatch != line .length ()) anyKernelSystemLess = true ;
299- printStream .println (line );
300- }
301- printStream .close ();
302- bufferedReader .close ();
303- if (!anyKernelSystemLess ) anyKernelInstallScript .delete ();
267+ // Check if module is AnyKernel module
268+ if (zipFile .getEntry ("anykernel.sh" ) != null ) {
269+ ZipEntry updateBinary = zipFile .getEntry (
270+ "META-INF/com/google/android/update-binary" );
271+ if (updateBinary != null ) {
272+ BufferedReader bufferedReader = new BufferedReader (
273+ new InputStreamReader (zipFile .getInputStream (updateBinary )));
274+ PrintStream printStream = new PrintStream (
275+ new FileOutputStream (anyKernelInstallScript ));
276+ String line ;
277+ while ((line = bufferedReader .readLine ()) != null ) {
278+ line = line .replace ("/sbin/sh" , "/system/bin/sh" );
279+ line = line .replace ("/data/adb/modules/ak3-helper" ,
280+ "/data/adb/modules-update/ak3-helper" );
281+ printStream .println (line );
304282 }
283+ printStream .close ();
284+ bufferedReader .close ();
305285 }
306286 anyKernel = true ;
307287 }
@@ -353,14 +333,12 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
353333 String installCommand ;
354334 File installExecutable ;
355335 if (anyKernel && moduleId == null ) { // AnyKernel modules don't have a moduleId
356- if (!anyKernelSystemLess ) {
357- this .setInstallStateFinished (false ,
358- "! This AnyKernel module only support recovery install" , null );
359- return ;
360- }
336+ this .warnReboot = true ; // We should probably re-flash magisk...
361337 installExecutable = anyKernelInstallScript ;
362- installCommand = "sh \" " + installExecutable .getAbsolutePath () + "\" " +
363- " /dev/null 0 \" " + file .getAbsolutePath () + "\" " ;
338+ // "unshare -m" is needed to force mount namespace isolation.
339+ // This allow AnyKernel to mess-up with mounts point without crashing the system!
340+ installCommand = "unshare -m sh \" " + installExecutable .getAbsolutePath () + "\" " +
341+ " /dev/null 1 \" " + file .getAbsolutePath () + "\" " ;
364342 } else if (InstallerInitializer .peekMagiskVersion () >=
365343 Constants .MAGISK_VER_CODE_INSTALL_COMMAND &&
366344 ((compatFlags & AppUpdateManager .FLAG_COMPAT_MAGISK_CMD ) != 0 ||
@@ -376,23 +354,31 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
376354 return ;
377355 }
378356 installCommand = "sh \" " + installExecutable .getAbsolutePath () + "\" " +
379- " /dev/null 0 \" " + file .getAbsolutePath () + "\" " ;
357+ " /dev/null 1 \" " + file .getAbsolutePath () + "\" " ;
380358 } else {
381359 this .setInstallStateFinished (false ,
382360 "! Zip file is not a valid Magisk or a AnyKernel module!" , null );
383361 return ;
384362 }
385363 installerMonitor = new InstallerMonitor (installExecutable );
386364 if (moduleId != null ) installerMonitor .setForCleanUp (moduleId );
387- if (noExtensions ) {
365+ if (anyKernel ) {
366+ final String adbTmp = "data/adb/tmp" ;
367+ final String anyKernelHome = // Mirror mounts do not contain nosuid
368+ InstallerInitializer .peekMirrorPath () +
369+ "/" + adbTmp + "/anykernel" ;
370+ installJob = Shell .cmd (arch32 , "export MMM_EXT_SUPPORT=1" ,
371+ "cd \" " + this .moduleCache .getAbsolutePath () + "\" " ,
372+ "mkdir " + adbTmp , "export AKHOME=" + anyKernelHome ,
373+ installCommand ).to (installerController , installerMonitor );
374+ } else if (noExtensions ) {
388375 installJob = Shell .cmd (arch32 , // No Extensions
389376 "cd \" " + this .moduleCache .getAbsolutePath () + "\" " ,
390377 installCommand ).to (installerController , installerMonitor );
391378 } else {
392379 installJob = Shell .cmd (arch32 , "export MMM_EXT_SUPPORT=1" ,
393- "export MMM_USER_LANGUAGE=" + (MainApplication .isForceEnglish () ?
394- "en-US" : Resources .getSystem ()
395- .getConfiguration ().locale .toLanguageTag ()),
380+ "export MMM_USER_LANGUAGE=" + (MainApplication .isForceEnglish () ? "en-US" :
381+ Resources .getSystem ().getConfiguration ().locale .toLanguageTag ()),
396382 "export MMM_APP_VERSION=" + BuildConfig .VERSION_NAME ,
397383 "export MMM_TEXT_WRAP=" + (this .textWrap ? "1" : "0" ),
398384 "cd \" " + this .moduleCache .getAbsolutePath () + "\" " ,
@@ -618,8 +604,8 @@ private void setInstallStateFinished(boolean success, String message, String opt
618604
619605 // This should be improved ?
620606 String reboot_cmd = "/system/bin/svc power reboot || /system/bin/reboot" ;
621- rebootFloatingButton .setOnClickListener (_view -> {
622- if (MainApplication .shouldPreventReboot ()) {
607+ this . rebootFloatingButton .setOnClickListener (_view -> {
608+ if (this . warnReboot || MainApplication .shouldPreventReboot ()) {
623609 MaterialAlertDialogBuilder builder =
624610 new MaterialAlertDialogBuilder (this );
625611
@@ -637,6 +623,7 @@ private void setInstallStateFinished(boolean success, String message, String opt
637623 Shell .cmd (reboot_cmd ).submit ();
638624 }
639625 });
626+ this .rebootFloatingButton .setVisibility (View .VISIBLE );
640627
641628 if (message != null && !message .isEmpty ())
642629 this .installerTerminal .addLine (message );
@@ -647,7 +634,6 @@ private void setInstallStateFinished(boolean success, String message, String opt
647634 return true ;
648635 });
649636 } else if (success ) {
650- this .rebootFloatingButton .setVisibility (View .VISIBLE );
651637 final Intent intent = this .getIntent ();
652638 final String config = MainApplication .checkSecret (intent ) ?
653639 intent .getStringExtra (Constants .EXTRA_INSTALL_CONFIG ) : null ;
0 commit comments