From 147055e4a95dee204ae772489339255e645ea660 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Fri, 11 Feb 2022 15:25:41 +0100 Subject: [PATCH] Fix installing module depending on now removed `ARCH32` variable. (Also clean up code) --- .../com/fox2code/mmm/ActionButtonType.java | 4 -- .../com/fox2code/mmm/MainApplication.java | 4 -- .../mmm/installer/InstallerActivity.java | 43 +++++++++++++++---- .../fox2code/mmm/manager/LocalModuleInfo.java | 2 - .../mmm/settings/SettingsActivity.java | 3 -- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/ActionButtonType.java b/app/src/main/java/com/fox2code/mmm/ActionButtonType.java index 7e13986..91e31de 100644 --- a/app/src/main/java/com/fox2code/mmm/ActionButtonType.java +++ b/app/src/main/java/com/fox2code/mmm/ActionButtonType.java @@ -15,12 +15,9 @@ import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.manager.LocalModuleInfo; import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.manager.ModuleManager; -import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.IntentHelper; import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import java.nio.charset.StandardCharsets; - import io.noties.markwon.Markwon; public enum ActionButtonType { @@ -78,7 +75,6 @@ public enum ActionButtonType { builder.setTitle(moduleInfo.name).setCancelable(true) .setIcon(R.drawable.ic_baseline_extension_24); CharSequence desc = moduleInfo.description; - final boolean noPatch; if (moduleInfo instanceof LocalModuleInfo) { LocalModuleInfo localModuleInfo = (LocalModuleInfo) moduleInfo; if (!localModuleInfo.updateChangeLog.isEmpty()) { diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index 11bf3ee..e03cdbc 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -4,7 +4,6 @@ import android.annotation.SuppressLint; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Color; @@ -26,12 +25,9 @@ import com.fox2code.mmm.utils.Http; import com.topjohnwu.superuser.Shell; import java.text.SimpleDateFormat; -import java.util.Arrays; import java.util.Date; -import java.util.HashSet; import java.util.Locale; import java.util.Random; -import java.util.Set; import io.noties.markwon.Markwon; import io.noties.markwon.html.HtmlPlugin; diff --git a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java index 91448a1..f5487fb 100644 --- a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java +++ b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java @@ -5,6 +5,7 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; +import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; @@ -37,6 +38,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; public class InstallerActivity extends CompatActivity { @@ -87,8 +89,8 @@ public class InstallerActivity extends CompatActivity { boolean urlMode = target.startsWith("http://") || target.startsWith("https://"); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setTitle(name); - setContentView((this.textWrap = - MainApplication.isTextWrapEnabled()) ? + this.textWrap = MainApplication.isTextWrapEnabled(); + setContentView(this.textWrap ? R.layout.installer_wrap :R.layout.installer); int background; int foreground; @@ -252,6 +254,30 @@ public class InstallerActivity extends CompatActivity { " /dev/null 1 \"" + file.getAbsolutePath() + "\"") .to(installerController, installerMonitor); } else { + String arch32 = "true"; // Do nothing by default + if (Build.SUPPORTED_32_BIT_ABIS.length == 0) { + boolean needs32bit = false; + try (ZipFile zipFile = new ZipFile(file)) { + if (zipFile.getEntry( // Check if module hard require 32bit support + "common/addon/Volume-Key-Selector/tools/arm64/keycheck") == null && + zipFile.getEntry( + "common/addon/Volume-Key-Selector/install.sh") != null) { + needs32bit = true; + } + } catch (IOException ignored) {} + if (needs32bit) { + this.setInstallStateFinished(false, + "! This module can't be installed on a 64bit only system", + null); + return; + } + } else { + // Restore Magisk legacy stuff for retro compatibility + if (Build.SUPPORTED_32_BIT_ABIS[0].contains("arm")) + arch32 = "export ARCH32=arm"; + if (Build.SUPPORTED_32_BIT_ABIS[0].contains("x86")) + arch32 = "export ARCH32=x86"; + } String installCommand; File installExecutable; if (InstallerInitializer.peekMagiskVersion() >= @@ -272,11 +298,11 @@ public class InstallerActivity extends CompatActivity { } installerMonitor = new InstallerMonitor(installExecutable); if (noExtensions) { - installJob = Shell.su( // No Extensions + installJob = Shell.su(arch32, // No Extensions "cd \"" + this.moduleCache.getAbsolutePath() + "\"", installCommand).to(installerController, installerMonitor); } else { - installJob = Shell.su("export MMM_EXT_SUPPORT=1", + installJob = Shell.su(arch32, "export MMM_EXT_SUPPORT=1", "export MMM_USER_LANGUAGE=" + (MainApplication.isForceEnglish() ? "en-US" : Resources.getSystem() .getConfiguration().locale.toLanguageTag()), @@ -428,12 +454,14 @@ public class InstallerActivity extends CompatActivity { public static class InstallerMonitor extends CallbackList { private static final String DEFAULT_ERR = "! Install failed"; - private final String installScriptPath; + private final String installScriptErr; public String lastCommand = ""; public InstallerMonitor(File installScript) { super(Runnable::run); - this.installScriptPath = installScript.getAbsolutePath(); + this.installScriptErr = + installScript.getAbsolutePath() + + ": /data/adb/modules_update/"; } @Override @@ -443,8 +471,7 @@ public class InstallerActivity extends CompatActivity { } private String doCleanUp() { - String installScriptErr = - this.installScriptPath + ": /data/adb/modules_update/"; + String installScriptErr = this.installScriptErr; // This block is mainly to help fixing customize.sh syntax errors if (this.lastCommand.startsWith(installScriptErr)) { installScriptErr = this.lastCommand.substring(installScriptErr.length()); diff --git a/app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java b/app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java index 8547c5f..ee4c52e 100644 --- a/app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java +++ b/app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java @@ -11,8 +11,6 @@ import org.json.JSONObject; import java.io.IOException; import java.nio.charset.StandardCharsets; -import io.noties.markwon.Markwon; - public class LocalModuleInfo extends ModuleInfo { public String updateVersion; public long updateVersionCode = Long.MIN_VALUE; diff --git a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java index 1a7f402..2732836 100644 --- a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java +++ b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java @@ -3,15 +3,12 @@ package com.fox2code.mmm.settings; import android.os.Bundle; import android.widget.Toast; -import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.SwitchPreference; -import androidx.preference.SwitchPreferenceCompat; import com.fox2code.mmm.AppUpdateManager; import com.fox2code.mmm.BuildConfig;