Skip to content
This repository has been archived by the owner on Jul 19, 2018. It is now read-only.

Commit

Permalink
Update to libsu 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Jun 19, 2018
1 parent 1df4100 commit 4ff39f8
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 77 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android {

productFlavors {
full {
versionCode 118
versionCode 120
versionName "5.7.0"
}
stub {
Expand Down Expand Up @@ -57,7 +57,7 @@ dependencies {
fullImplementation "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
fullImplementation "com.android.support:cardview-v7:${rootProject.ext.supportLibVersion}"
fullImplementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
fullImplementation 'com.github.topjohnwu:libsu:1.1.1'
fullImplementation 'com.github.topjohnwu:libsu:1.2.0'
fullImplementation 'com.atlassian.commonmark:commonmark:0.11.0'
fullImplementation 'org.kamranzafar:jtar:2.3'
fullImplementation 'com.jakewharton:butterknife:8.8.1'
Expand Down
4 changes: 2 additions & 2 deletions src/full/java/com/topjohnwu/magisk/MagiskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import com.topjohnwu.magisk.components.Fragment;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.ShowUI;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;

import butterknife.BindColor;
import butterknife.BindView;
Expand Down Expand Up @@ -265,7 +265,7 @@ private void updateCheckUI() {
|| mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
install();
} else if (mm.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV &&
!RootUtils.cmdResult("env_check")) {
!ShellUtils.fastCmdResult("env_check")) {
ShowUI.envFixDialog(getActivity());
}
}
Expand Down
42 changes: 11 additions & 31 deletions src/full/java/com/topjohnwu/magisk/MagiskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Xml;
Expand All @@ -20,10 +19,11 @@
import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.ShellInitializer;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.BusyBox;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;
import com.topjohnwu.superuser.io.SuFile;
import com.topjohnwu.superuser.io.SuFileInputStream;

Expand All @@ -32,7 +32,6 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -111,26 +110,7 @@ public void onCreate() {

Shell.setFlags(Shell.FLAG_MOUNT_MASTER);
Shell.verboseLogging(BuildConfig.DEBUG);
BusyBox.BB_PATH = new File(Const.BUSYBOX_PATH);
Shell.setInitializer(new Shell.Initializer() {
@Override
public void onRootShellInit(@NonNull Shell shell) {
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();
}
shell.run(null, null,
"mount_partitions",
"find_boot_image",
"find_dtbo_image",
"get_flags",
"run_migrations");
}
});
Shell.setInitializer(ShellInitializer.class);

prefs = PreferenceManager.getDefaultSharedPreferences(this);
mDB = MagiskDatabaseHelper.getInstance(this);
Expand Down Expand Up @@ -207,19 +187,19 @@ public void writeConfig() {

public void loadMagiskInfo() {
try {
magiskVersionString = RootUtils.cmd("magisk -v").split(":")[0];
magiskVersionCode = Integer.parseInt(RootUtils.cmd("magisk -V"));
String s = RootUtils.cmd((magiskVersionCode >= Const.MAGISK_VER.RESETPROP_PERSIST ? "resetprop -p " : "getprop ")
+ Const.MAGISKHIDE_PROP);
magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0];
magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V"));
String s = ShellUtils.fastCmd((magiskVersionCode >= Const.MAGISK_VER.RESETPROP_PERSIST ?
"resetprop -p " : "getprop ") + Const.MAGISKHIDE_PROP);
magiskHide = s == null || Integer.parseInt(s) != 0;
} catch (Exception ignored) {}

bootBlock = RootUtils.cmd("echo \"$BOOTIMAGE\"");
bootBlock = ShellUtils.fastCmd("echo \"$BOOTIMAGE\"");
}

public void getDefaultInstallFlags() {
keepVerity = Boolean.parseBoolean(RootUtils.cmd("echo $KEEPVERITY"));
keepEnc = Boolean.parseBoolean(RootUtils.cmd("echo $KEEPFORCEENCRYPT"));
keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY"));
keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT"));
}

public void setupUpdateCheck() {
Expand Down Expand Up @@ -250,7 +230,7 @@ public void dumpPrefs() {
}

public void loadPrefs() {
SuFile config = new SuFile(Utils.fmt("/data/user/%d/%s", Const.USER_ID, Const.MANAGER_CONFIGS), true);
SuFile config = new SuFile(Utils.fmt("/data/user/%d/%s", Const.USER_ID, Const.MANAGER_CONFIGS));
if (config.exists()) {
SharedPreferences.Editor editor = prefs.edit();
try {
Expand Down
3 changes: 2 additions & 1 deletion src/full/java/com/topjohnwu/magisk/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;

import java.io.IOException;
import java.util.Locale;
Expand Down Expand Up @@ -172,7 +173,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@Override
public void onDownloadDone(Context context, Uri uri) {
mm.dumpPrefs();
if (RootUtils.cmdResult("pm install " + uri.getPath()))
if (ShellUtils.fastCmdResult("pm install " + uri.getPath()))
RootUtils.uninstallPkg(context.getPackageName());
}
},
Expand Down
3 changes: 1 addition & 2 deletions src/full/java/com/topjohnwu/magisk/asyncs/FlashZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.components.SnackbarMaker;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils;
import com.topjohnwu.superuser.Shell;
Expand Down Expand Up @@ -41,7 +40,7 @@ public FlashZip(Activity context, Uri uri, List<String> console, List<String> lo

private boolean unzipAndCheck() throws Exception {
ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android", true);
String s = RootUtils.cmd("head -n 1 " + new File(mCachedFile.getParentFile(), "updater-script"));
String s = ShellUtils.fastCmd("head -n 1 " + new File(mCachedFile.getParentFile(), "updater-script"));
return s != null && s.contains("#MAGISK");
}

Expand Down
2 changes: 1 addition & 1 deletion src/full/java/com/topjohnwu/magisk/asyncs/HideManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected Boolean doInBackground(Void... voids) {
MagiskManager mm = MagiskManager.get();

// Generate a new app with random package name
SuFile repack = new SuFile("/data/local/tmp/repack.apk", true);
SuFile repack = new SuFile("/data/local/tmp/repack.apk");
String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length());

try {
Expand Down
9 changes: 4 additions & 5 deletions src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.TarEntry;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils;
import com.topjohnwu.superuser.Shell;
Expand Down Expand Up @@ -148,9 +147,8 @@ private boolean dumpBoot(File boot) throws IOException {
case DIRECT_MODE:
console.add("- Patch boot/ramdisk image: " + mBootLocation);
if (mm.remoteMagiskVersionCode >= 1463) {
highCompression = Integer.parseInt(RootUtils.cmd(Utils.fmt(
"%s/magiskboot --parse %s; echo $?",
install, mBootLocation))) == 2;
highCompression = Integer.parseInt(ShellUtils.fastCmd(Utils.fmt(
"%s/magiskboot --parse %s; echo $?", install, mBootLocation))) == 2;
if (highCompression)
console.add("! Insufficient boot partition size detected");
}
Expand Down Expand Up @@ -263,6 +261,7 @@ protected Boolean doInBackground(Void... voids) {
.getFilesDir().getParent()
, "install");
Shell.Sync.sh("rm -rf " + install);
install.mkdirs();
}

List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
Expand Down Expand Up @@ -294,7 +293,7 @@ protected Boolean doInBackground(Void... voids) {
);
} else {
File boot = new File(install, "boot.img");
SuFile patched_boot = new SuFile(install.getParent() + "/new-boot.img", true);
SuFile patched_boot = new SuFile(install.getParent(), "new-boot.img");

if (!dumpBoot(boot) || !patchBoot(boot, patched_boot))
return false;
Expand Down
8 changes: 3 additions & 5 deletions src/full/java/com/topjohnwu/magisk/asyncs/RestoreImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@

import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;

public class RestoreImages extends ParallelTask<Void, Void, Boolean> {

@Override
protected Boolean doInBackground(Void... voids) {
String sha1;
sha1 = RootUtils.cmd("cat /.backup/.sha1");
sha1 = ShellUtils.fastCmd("cat /.backup/.sha1");
if (sha1 == null) {
sha1 = RootUtils.cmd("cat /init.magisk.rc | grep STOCKSHA1");
sha1 = ShellUtils.fastCmd("cat /init.magisk.rc | grep STOCKSHA1");
if (sha1 == null)
return false;
sha1 = sha1.substring(sha1.indexOf('=') + 1);
}

return ShellUtils.fastCmdResult(Shell.getShell(), "restore_imgs " + sha1);
return ShellUtils.fastCmdResult("restore_imgs " + sha1);
}

@Override
Expand Down
16 changes: 5 additions & 11 deletions src/full/java/com/topjohnwu/magisk/container/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.io.SuFile;

import java.io.IOException;

public class Module extends BaseModule {

private SuFile mRemoveFile, mDisableFile, mUpdateFile;
Expand All @@ -16,9 +14,9 @@ public Module(String path) {
parseProps(Shell.Sync.su("dos2unix < " + path + "/module.prop"));
} catch (NumberFormatException ignored) {}

mRemoveFile = new SuFile(path + "/remove", true);
mDisableFile = new SuFile(path + "/disable", true);
mUpdateFile = new SuFile(path + "/update", true);
mRemoveFile = new SuFile(path + "/remove");
mDisableFile = new SuFile(path + "/disable");
mUpdateFile = new SuFile(path + "/update");

if (getId() == null) {
int sep = path.lastIndexOf('/');
Expand All @@ -36,9 +34,7 @@ public Module(String path) {

public void createDisableFile() {
mEnable = false;
try {
mDisableFile.createNewFile();
} catch (IOException ignored) {}
mDisableFile.createNewFile();
}

public void removeDisableFile() {
Expand All @@ -52,9 +48,7 @@ public boolean isEnabled() {

public void createRemoveFile() {
mRemove = true;
try {
mRemoveFile.createNewFile();
} catch (IOException ignored) {}
mRemoveFile.createNewFile();
}

public void deleteRemoveFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private SQLiteDatabase openDatabase(MagiskManager mm) {
return de.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null);
} else {
// Global database
final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db", true);
final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db");
mm.deleteDatabase("su.db");
de.deleteDatabase("su.db");
if (mm.magiskVersionCode < Const.MAGISK_VER.SEPOL_REFACTOR) {
Expand Down
16 changes: 4 additions & 12 deletions src/full/java/com/topjohnwu/magisk/utils/RootUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,18 @@
public class RootUtils {

public static void init() {
Const.MAGISK_DISABLE_FILE = new SuFile("/cache/.disable_magisk", true);
SuFile file = new SuFile("/sbin/.core/img", true);
Const.MAGISK_DISABLE_FILE = new SuFile("/cache/.disable_magisk");
SuFile file = new SuFile("/sbin/.core/img");
if (file.exists()) {
Const.MAGISK_PATH = file;
} else if ((file = new SuFile("/dev/magisk/img", true)).exists()) {
} else if ((file = new SuFile("/dev/magisk/img")).exists()) {
Const.MAGISK_PATH = file;
} else {
Const.MAGISK_PATH = new SuFile("/magisk", true);
Const.MAGISK_PATH = new SuFile("/magisk");
}
Const.MAGISK_HOST_FILE = new SuFile(Const.MAGISK_PATH + "/.core/hosts");
}

public static String cmd(String cmd) {
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);
}
Expand Down
32 changes: 32 additions & 0 deletions src/full/java/com/topjohnwu/magisk/utils/ShellInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.topjohnwu.magisk.utils;

import android.content.Context;
import android.support.annotation.NonNull;

import com.topjohnwu.magisk.R;
import com.topjohnwu.superuser.BusyBox;
import com.topjohnwu.superuser.Shell;

import java.io.File;
import java.io.InputStream;

public class ShellInitializer extends Shell.Initializer {

@Override
public boolean onRootShellInit(Context context, @NonNull Shell shell) throws Exception {
BusyBox.BB_PATH = new File(Const.BUSYBOX_PATH);
try (InputStream magiskUtils = context.getAssets().open(Const.UTIL_FUNCTIONS);
InputStream managerUtils = context.getResources().openRawResource(R.raw.utils)
) {
shell.loadInputStream(null, null, magiskUtils);
shell.loadInputStream(null, null, managerUtils);
}
shell.run(null, null,
"mount_partitions",
"find_boot_image",
"find_dtbo_image",
"get_flags",
"run_migrations");
return true;
}
}
8 changes: 4 additions & 4 deletions src/full/java/com/topjohnwu/magisk/utils/ShowUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static void magiskInstallDialog(Activity activity) {
if (Shell.rootAccess()) {
options.add(mm.getString(R.string.direct_install));
}
String s = RootUtils.cmd("echo $SLOT");
String s = ShellUtils.fastCmd("echo $SLOT");
if (s != null) {
options.add(mm.getString(R.string.install_second_slot));
}
Expand Down Expand Up @@ -211,9 +211,9 @@ public void onDownloadDone(Context context, Uri uri) {
if (slot[1] == 'a') slot[1] = 'b';
else slot[1] = 'a';
// Then find the boot image again
boot = RootUtils.cmd(
"SLOT=" + String.valueOf(slot) +
"; find_boot_image;" +
boot = ShellUtils.fastCmd(
"SLOT=" + String.valueOf(slot),
"find_boot_image",
"echo \"$BOOTIMAGE\""
);
Shell.Async.su("mount_partitions");
Expand Down

0 comments on commit 4ff39f8

Please sign in to comment.