Commit 630f2b7d authored by topjohnwu's avatar topjohnwu

Support fixing Magisk environment

parent dde0a4a7
......@@ -8,7 +8,7 @@ android {
applicationId "com.topjohnwu.magisk"
minSdkVersion 21
targetSdkVersion rootProject.ext.compileSdkVersion
versionCode 115
versionCode 117
versionName "5.7.0"
javaCompileOptions {
annotationProcessorOptions {
......@@ -46,7 +46,7 @@ dependencies {
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.atlassian.commonmark:commonmark:0.10.0'
implementation 'com.atlassian.commonmark:commonmark:0.11.0'
implementation 'org.kamranzafar:jtar:2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
......@@ -259,17 +259,22 @@ public class MagiskFragment extends Fragment
}
}
if (!shownDialog && (mm.remoteMagiskVersionCode > mm.magiskVersionCode
|| mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE)) {
install();
}
magiskUpdateIcon.setImageResource(image);
magiskUpdateIcon.setColorFilter(color);
magiskUpdateIcon.setVisibility(View.VISIBLE);
magiskUpdateProgress.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
if (!shownDialog) {
if (mm.remoteMagiskVersionCode > mm.magiskVersionCode
|| mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
install();
} else if (mm.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV &&
!Utils.cmdResult("env_check")) {
ShowUI.envFixDialog(getActivity());
}
}
}
private void updateSafetyNetUI(int response) {
......
......@@ -105,10 +105,11 @@ public class MagiskManager extends Shell.ContainerApp {
Shell.setInitializer(new Shell.Initializer() {
@Override
public void onRootShellInit(@NonNull Shell shell) {
try (InputStream utils = getAssets().open(Const.UTIL_FUNCTIONS);
InputStream magiskDB = getResources().openRawResource(R.raw.magiskdb)) {
shell.loadInputStream(null, null, utils);
shell.loadInputStream(null, null, magiskDB);
try (InputStream magiskUtils = getAssets().open(Const.UTIL_FUNCTIONS);
InputStream managerUtils = getResources().openRawResource(R.raw.utils)
) {
shell.loadInputStream(null, null, magiskUtils);
shell.loadInputStream(null, null, managerUtils);
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -80,6 +80,7 @@ public class Const {
public static final int HIDDEN_PATH = 1460;
public static final int REMOVE_LEGACY_LINK = 1630;
public static final int SEPOL_REFACTOR = 1640;
public static final int FIX_ENV = 1650;
}
public static class ID {
......
......@@ -17,6 +17,7 @@ import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.SplashActivity;
import com.topjohnwu.magisk.asyncs.InstallMagisk;
import com.topjohnwu.magisk.asyncs.RestoreImages;
import com.topjohnwu.magisk.components.AlertDialogBuilder;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
......@@ -100,6 +101,26 @@ public class ShowUI {
notificationManager.notify(Const.ID.DTBO_NOTIFICATION_ID, builder.build());
}
public static void envFixDialog(Activity activity) {
MagiskManager mm = Utils.getMagiskManager(activity);
String filename = Utils.fmt("Magisk-v%s(%d).zip",
mm.remoteMagiskVersionString, mm.remoteMagiskVersionCode);
new AlertDialogBuilder(activity)
.setTitle(R.string.env_fix_title)
.setMessage(R.string.env_fix_msg)
.setCancelable(true)
.setPositiveButton(R.string.yes, (d, i) -> {
Utils.dlAndReceive(activity, new DownloadReceiver() {
@Override
public void onDownloadDone(Uri uri) {
new InstallMagisk(activity, uri).exec();
}
}, mm.magiskLink, filename);
})
.setNegativeButton(R.string.no_thanks, null)
.show();
}
public static void magiskInstallDialog(Activity activity) {
MagiskManager mm = Utils.getMagiskManager(activity);
String filename = Utils.fmt("Magisk-v%s(%d).zip",
......
......@@ -51,6 +51,10 @@ public class Utils {
return ShellUtils.fastCmd(Shell.getShell(), cmd);
}
public static boolean cmdResult(String cmd) {
return ShellUtils.fastCmdResult(Shell.getShell(), cmd);
}
public static void uninstallPkg(String pkg) {
Shell.Sync.su("db_clean " + Const.USER_ID, "pm uninstall " + pkg);
}
......
package com.topjohnwu.magisk.utils;
import com.topjohnwu.superuser.ShellUtils;
import com.topjohnwu.superuser.io.SuFile;
import com.topjohnwu.superuser.io.SuFileOutputStream;
import com.topjohnwu.utils.JarMap;
import com.topjohnwu.utils.SignAPK;
......@@ -9,6 +11,7 @@ import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
......@@ -16,13 +19,13 @@ import java.util.zip.ZipInputStream;
public class ZipUtils {
public static void unzip(File zip, File folder, String path, boolean junkPath) throws Exception {
public static void unzip(File zip, File folder, String path, boolean junkPath) throws IOException {
InputStream in = new BufferedInputStream(new FileInputStream(zip));
unzip(in, folder, path, junkPath);
in.close();
}
public static void unzip(InputStream zip, File folder, String path, boolean junkPath) throws Exception {
public static void unzip(InputStream zip, File folder, String path, boolean junkPath) throws IOException {
try {
ZipInputStream zipfile = new ZipInputStream(zip);
ZipEntry entry;
......@@ -37,13 +40,14 @@ public class ZipUtils {
} else {
name = entry.getName();
}
File dest = new File(folder, name);
SuFile dest = new SuFile(folder, name);
dest.getParentFile().mkdirs();
try (FileOutputStream out = new FileOutputStream(dest)) {
try (OutputStream out = new SuFileOutputStream(dest)) {
ShellUtils.pump(zipfile, out);
}
}
} catch(Exception e) {
}
catch(IOException e) {
e.printStackTrace();
throw e;
}
......
......@@ -36,3 +36,10 @@ db_setup() {
chown $USER.$USER $DIR
chmod 666 $DIR/*
}
env_check() {
for file in busybox magisk magiskboot magiskinit util_functions.sh boot_patch.sh; do
[ -e /data/adb/magisk/$file ] || return 1
done
return 0
}
......@@ -125,6 +125,10 @@
<string name="su_db_corrupt">SU database is corrupted, will recreate new db</string>
<string name="cannot_check_sn_title">Cannot check SafetyNet</string>
<string name="cannot_check_sn_notice">Due to some changes in Google Play Services, it is not possible to check SafetyNet on repackaged Magisk Manager</string>
<string name="setup_done">Setup done</string>
<string name="setup_fail">Setup failed</string>
<string name="env_fix_title">Require Additional Setup</string>
<string name="env_fix_msg">Your device need additional setup for Magisk to work properly. It will download the Magisk setup zip, do you want to proceed now?</string>
<!--Settings Activity -->
<string name="settings_general_category">General</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment