Better support for low API levels

This commit is contained in:
topjohnwu 2019-02-03 09:50:49 -05:00
parent 72270825c1
commit c7301a5161
6 changed files with 43 additions and 22 deletions

View File

@ -15,7 +15,7 @@ dependencies {
api project(':signing') api project(':signing')
api 'org.kamranzafar:jtar:2.3' 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:core:${libsuVersion}"
api "com.github.topjohnwu.libsu:io:${libsuVersion}" api "com.github.topjohnwu.libsu:io:${libsuVersion}"
} }

View File

@ -1,5 +1,6 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; 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.LocaleManager;
import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.net.Networking; import com.topjohnwu.net.Networking;
import com.topjohnwu.superuser.ContainerApp;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
public class App extends ContainerApp { public class App extends Application {
public static App self; public static App self;
public static ThreadPoolExecutor THREAD_POOL; public static ThreadPoolExecutor THREAD_POOL;

View File

@ -7,11 +7,14 @@ env_check() {
fix_env() { fix_env() {
cd /data/adb/magisk cd /data/adb/magisk
local OLDPATH="$PATH"
PATH=/sbin:/system/bin:/vendor/bin
sh update-binary extract 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 rm -f update-binary magisk.apk
cd / cd /
rm -rf /sbin/.magisk/busybox/*
/sbin/.magisk/mirror/bin/busybox --install -s /sbin/.magisk/busybox
} }
direct_install() { direct_install() {

View File

@ -23,6 +23,22 @@ public class SplashActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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); String pkg = Config.get(Config.Key.SU_MANAGER);
if (pkg != null && getPackageName().equals(BuildConfig.APPLICATION_ID)) { if (pkg != null && getPackageName().equals(BuildConfig.APPLICATION_ID)) {
Config.remove(Config.Key.SU_MANAGER); Config.remove(Config.Key.SU_MANAGER);
@ -36,19 +52,6 @@ public class SplashActivity extends BaseActivity {
} catch (PackageManager.NameNotFoundException ignored) {} } 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 // Dynamic detect all locales
LocaleManager.loadAvailableLocales(R.string.app_changelog); LocaleManager.loadAvailableLocales(R.string.app_changelog);

View File

@ -2,14 +2,19 @@ package com.topjohnwu.magisk.dialogs;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Intent;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.ClassMap;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.SplashActivity;
import com.topjohnwu.magisk.tasks.MagiskInstaller; import com.topjohnwu.magisk.tasks.MagiskInstaller;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.io.SuFile; import com.topjohnwu.superuser.io.SuFile;
import java.io.IOException;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
public class EnvFixDialog extends CustomAlertDialog { public class EnvFixDialog extends CustomAlertDialog {
@ -35,6 +40,17 @@ public class EnvFixDialog extends CustomAlertDialog {
protected void onResult(boolean success) { protected void onResult(boolean success) {
pd.dismiss(); pd.dismiss();
Utils.toast(success ? R.string.setup_done : R.string.setup_fail, Toast.LENGTH_LONG); 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(); }.exec();
}); });

View File

@ -1,11 +1,10 @@
#!/sbin/sh #!/sbin/sh
X86_CNT=__X86_CNT__ X86_CNT=__X86_CNT__
extract_bb() { extract_bb() {
case `uname -m` in touch "$BBBIN"
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
chmod 755 "$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() { setup_bb() {
BBDIR=$TMPDIR/bin BBDIR=$TMPDIR/bin