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

Commit

Permalink
Add KernelSU Support
Browse files Browse the repository at this point in the history
* This is an initial support for KernelSU, I am not sure it's works well
  or not, If it doesn't work well, please tell me.
* Because of Substratum is no longer update now, I will not make a pull request to
  the upstream.
* Still need improve, the way to detect KernelSU is not good as I
  expect.
  • Loading branch information
ShionKanagawa committed Oct 6, 2023
1 parent 83f0847 commit 7becd96
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
36 changes: 26 additions & 10 deletions app/src/main/java/projekt/substratum/common/References.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,35 @@ public static String getSystemDir() {
return getMagiskDirectory() + "/system";
}

public static boolean isInteger(String str) {
try {
Integer.parseInt(str);
return true;
} catch (NumberFormatException e) {
return false;
}
}

public static String getMagiskDirectory() {
final int magiskVer = Integer.parseInt(Root.runCommand("su -V"));
final int suVer = Integer.parseInt(Root.runCommand("su -V"));
if (magiskDir != null)
return magiskDir;
if (magiskVer >= 18000 && magiskVer <= 18100) {
magiskDir = "/sbin/.magisk/img/substratum";
} else if (magiskVer >= 18101) {
return magiskDir;
String result = Root.runCommand("su -c \"magisk -V\"");
if (isInteger(result)){
final int magiskVer = Integer.parseInt(Root.runCommand("su -c \"magisk -V\""));
if (magiskVer >= 18000 && magiskVer <= 18100) {
magiskDir = "/sbin/.magisk/img/substratum";
} else if (magiskVer >= 18101) {
magiskDir = "/data/adb/modules/substratum";
} else {
Log.d("MagiskCheck", "Magisk version cannot be lesser than 18.0, switching to system-installation");
magiskDir = "/";
}
}
else {
magiskDir = "/data/adb/modules/substratum";
} else {
Log.d("MagiskCheck", "Magisk version cannot be lesser than 18.0, switching to system-installation");
magiskDir = "/";
}
Log.d("MagiskCheck", String.format("Detected directory %s for version %d", magiskDir, magiskVer));
Log.d("MagiskCheck", String.format("Detected directory %s for version %d", magiskDir, suVer));
return magiskDir;
}

Expand Down Expand Up @@ -954,4 +970,4 @@ protected Void doInBackground(Void... sUrl) {
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public class MagiskHelper {
private static void installModule(final Context context) {
// Return if not using Magisk, when directory is "/" it means the version
// is unsupported and we're falling back to modifying system.
if (!checkMagisk() || MAGISK_DIR.equals("/"))
if ((!checkMagisk() &&!checkKernelSU())|| MAGISK_DIR.equals("/"))
return;

Substratum.log(TAG, "Magisk module does not exist, creating!");
String command = "set -ex \n" +
String.format("mkdir -p %s; ", MAGISK_DIR) +
String.format(
"printf 'name=substratum\nversion=%s\nversionCode=%s\nauthor=substratum development team\ndescription=Systemless overlays for Substratum\nminMagisk=1500\n' > %s/module.prop; ",
"printf 'id=substratum\nname=substratum\nversion=%s\nversionCode=%s\nauthor=substratum development team\ndescription=Systemless overlays for Substratum\nminMagisk=1500\n' > %s/module.prop; ",
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE,
MAGISK_DIR
Expand All @@ -49,7 +49,9 @@ public static void handleModule(final Context context) {
private static boolean checkMagisk() {
return Root.runCommand("su --version").contains("MAGISKSU");
}

private static boolean checkKernelSU() {
return Root.runCommand("su --version").contains("KernelSU");
}
private static boolean moduleExists() {
return Root.runCommand(String.format("test -d %s && echo '1'", MAGISK_DIR)).equals("1");
}
Expand Down

0 comments on commit 7becd96

Please sign in to comment.