From c7301a516123f065c114978d2988b1c57a01ac26 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 3 Feb 2019 09:50:49 -0500 Subject: [PATCH] Better support for low API levels --- app-core/build.gradle | 2 +- .../main/java/com/topjohnwu/magisk/App.java | 4 +-- app-core/src/main/res/raw/utils.sh | 7 +++-- .../com/topjohnwu/magisk/SplashActivity.java | 29 ++++++++++--------- .../magisk/dialogs/EnvFixDialog.java | 16 ++++++++++ scripts/update_binary.sh | 7 ++--- 6 files changed, 43 insertions(+), 22 deletions(-) diff --git a/app-core/build.gradle b/app-core/build.gradle index 6334dc55e..90fb92abe 100644 --- a/app-core/build.gradle +++ b/app-core/build.gradle @@ -15,7 +15,7 @@ dependencies { api project(':signing') api 'org.kamranzafar:jtar:2.3' - def libsuVersion = 'd99f481563' + def libsuVersion = '2.3.0' api "com.github.topjohnwu.libsu:core:${libsuVersion}" api "com.github.topjohnwu.libsu:io:${libsuVersion}" } diff --git a/app-core/src/main/java/com/topjohnwu/magisk/App.java b/app-core/src/main/java/com/topjohnwu/magisk/App.java index 2ae8bb53b..5d63f0b5e 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/App.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/App.java @@ -1,5 +1,6 @@ package com.topjohnwu.magisk; +import android.app.Application; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -12,12 +13,11 @@ import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.net.Networking; -import com.topjohnwu.superuser.ContainerApp; import com.topjohnwu.superuser.Shell; import java.util.concurrent.ThreadPoolExecutor; -public class App extends ContainerApp { +public class App extends Application { public static App self; public static ThreadPoolExecutor THREAD_POOL; diff --git a/app-core/src/main/res/raw/utils.sh b/app-core/src/main/res/raw/utils.sh index 81f6c36cb..107149bd2 100644 --- a/app-core/src/main/res/raw/utils.sh +++ b/app-core/src/main/res/raw/utils.sh @@ -7,11 +7,14 @@ env_check() { fix_env() { cd /data/adb/magisk + local OLDPATH="$PATH" + PATH=/sbin:/system/bin:/vendor/bin sh update-binary extract + PATH="$OLDPATH" + ./busybox rm -f /sbin/.magisk/busybox/* + /sbin/.magisk/mirror/bin/busybox --install -s /sbin/.magisk/busybox rm -f update-binary magisk.apk cd / - rm -rf /sbin/.magisk/busybox/* - /sbin/.magisk/mirror/bin/busybox --install -s /sbin/.magisk/busybox } direct_install() { diff --git a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java index bbb4d5e66..fdc400842 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java @@ -23,6 +23,22 @@ public class SplashActivity extends BaseActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Shell.getShell(shell -> { + if (Config.magiskVersionCode > 0 && + Config.magiskVersionCode < Const.MAGISK_VER.MIN_SUPPORT) { + new AlertDialog.Builder(this) + .setTitle(R.string.unsupport_magisk_title) + .setMessage(R.string.unsupport_magisk_message) + .setNegativeButton(R.string.ok, null) + .setOnDismissListener(dialog -> finish()) + .show(); + } else { + initAndStart(); + } + }); + } + + private void initAndStart() { String pkg = Config.get(Config.Key.SU_MANAGER); if (pkg != null && getPackageName().equals(BuildConfig.APPLICATION_ID)) { Config.remove(Config.Key.SU_MANAGER); @@ -36,19 +52,6 @@ public class SplashActivity extends BaseActivity { } catch (PackageManager.NameNotFoundException ignored) {} } - if (Config.magiskVersionCode > 0 && Config.magiskVersionCode < Const.MAGISK_VER.MIN_SUPPORT) { - new AlertDialog.Builder(this) - .setTitle(R.string.unsupport_magisk_title) - .setMessage(R.string.unsupport_magisk_message) - .setNegativeButton(R.string.ok, null) - .setOnDismissListener(dialog -> finish()) - .show(); - } else { - initAndStart(); - } - } - - private void initAndStart() { // Dynamic detect all locales LocaleManager.loadAvailableLocales(R.string.app_changelog); diff --git a/app/src/full/java/com/topjohnwu/magisk/dialogs/EnvFixDialog.java b/app/src/full/java/com/topjohnwu/magisk/dialogs/EnvFixDialog.java index 1f7874db9..684e88d57 100644 --- a/app/src/full/java/com/topjohnwu/magisk/dialogs/EnvFixDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/dialogs/EnvFixDialog.java @@ -2,14 +2,19 @@ package com.topjohnwu.magisk.dialogs; import android.app.Activity; import android.app.ProgressDialog; +import android.content.Intent; import android.widget.Toast; +import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.SplashActivity; import com.topjohnwu.magisk.tasks.MagiskInstaller; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.io.SuFile; +import java.io.IOException; + import androidx.annotation.NonNull; public class EnvFixDialog extends CustomAlertDialog { @@ -35,6 +40,17 @@ public class EnvFixDialog extends CustomAlertDialog { protected void onResult(boolean success) { pd.dismiss(); Utils.toast(success ? R.string.setup_done : R.string.setup_fail, Toast.LENGTH_LONG); + if (success) { + // Relaunch the app + try { + Shell.getShell().close(); + } catch (IOException ignored) {} + Intent intent = new Intent(activity, ClassMap.get(SplashActivity.class)); + intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME | Intent.FLAG_ACTIVITY_NEW_TASK); + activity.startActivity(intent); + activity.finish(); + } + } }.exec(); }); diff --git a/scripts/update_binary.sh b/scripts/update_binary.sh index 8b2bda69d..6052fde98 100644 --- a/scripts/update_binary.sh +++ b/scripts/update_binary.sh @@ -1,11 +1,10 @@ #!/sbin/sh X86_CNT=__X86_CNT__ extract_bb() { - case `uname -m` in - x*) dd if="$0" of="$BBBIN" bs=1024 skip=1 count=$X86_CNT ;; - *) dd if="$0" of="$BBBIN" bs=1024 skip=$(($X86_CNT + 1));; - esac + touch "$BBBIN" chmod 755 "$BBBIN" + dd if="$0" of="$BBBIN" bs=1024 skip=$(($X86_CNT + 1)) + "./$BBBIN" >/dev/null || dd if="$0" of="$BBBIN" bs=1024 skip=1 count=$X86_CNT } setup_bb() { BBDIR=$TMPDIR/bin