Rewrite all root method with own su library

This commit is contained in:
topjohnwu
2016-08-25 05:58:15 +08:00
parent e18f4c843a
commit a5ea214553
10 changed files with 411 additions and 237 deletions
@@ -1,5 +1,7 @@
package com.topjohnwu.magisk.module;
import android.util.Log;
import com.topjohnwu.magisk.utils.Utils;
import java.io.BufferedReader;
@@ -8,71 +10,21 @@ import java.io.FileReader;
public class Module {
private final boolean isValid;
private File mRemoveFile;
private File mDisableFile;
private File mPropFile;
private String mRemoveFile;
private String mDisableFile;
private String mName;
private String mVersion;
private String mDescription;
public Module(File file) {
this.isValid = new File(file + "/module.prop").exists();
private boolean mEnable;
private boolean mRemove;
if (!isValid) return;
mPropFile = new File(file + "/module.prop");
mRemoveFile = new File(file + "/remove");
mDisableFile = new File(file + "/disable");
}
public boolean isValid() {
return isValid && mPropFile != null;
}
public String getName() {
return mName;
}
public String getVersion() {
return mVersion;
}
public String getDescription() {
return mDescription;
}
public void createDisableFile() {
Utils.su("touch " + mDisableFile.getPath());
}
public void removeDisableFile() {
Utils.su("rm -f " + mDisableFile.getPath());
}
public boolean isEnabled() {
return ! mDisableFile.exists();
}
public void createRemoveFile() {
Utils.su("touch " + mRemoveFile.getPath());
}
public void deleteRemoveFile() {
Utils.su("rm -f " + mRemoveFile.getPath());
}
public boolean willBeRemoved() {
return mRemoveFile.exists();
}
public void parse() throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(mPropFile));
String line;
while ((line = reader.readLine()) != null) {
public Module(String path) {
mRemoveFile = path + "/remove";
mDisableFile = path + "/disable";
for (String line : Utils.readFile(path + "/module.prop")) {
String[] parts = line.split("=", 2);
if (parts.length != 2) {
continue;
@@ -96,6 +48,46 @@ public class Module {
break;
}
}
reader.close();
mEnable = !Utils.fileExist(mDisableFile);
mRemove = Utils.fileExist(mRemoveFile);
}
public String getName() {
return mName;
}
public String getVersion() {
return mVersion;
}
public String getDescription() {
return mDescription;
}
public void createDisableFile() {
mEnable = !Utils.createFile(mDisableFile);
}
public void removeDisableFile() {
mEnable = Utils.removeFile(mDisableFile);
}
public boolean isEnabled() {
return mEnable;
}
public void createRemoveFile() {
mRemove = Utils.createFile(mRemoveFile);
}
public void deleteRemoveFile() {
mRemove = !Utils.removeFile(mRemoveFile);
}
public boolean willBeRemoved() {
return mRemove;
}
}