2016-08-23 05:18:28 +08:00
|
|
|
package com.topjohnwu.magisk.module;
|
2016-08-17 13:00:55 +02:00
|
|
|
|
2016-08-25 05:58:15 +08:00
|
|
|
import android.util.Log;
|
|
|
|
|
2016-08-23 05:18:28 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
2016-08-21 16:08:45 +02:00
|
|
|
|
2016-08-17 13:00:55 +02:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
|
|
|
public class Module {
|
|
|
|
|
2016-08-25 05:58:15 +08:00
|
|
|
private String mRemoveFile;
|
|
|
|
private String mDisableFile;
|
2016-08-17 13:00:55 +02:00
|
|
|
|
|
|
|
private String mName;
|
|
|
|
private String mVersion;
|
|
|
|
private String mDescription;
|
|
|
|
|
2016-08-25 05:58:15 +08:00
|
|
|
private boolean mEnable;
|
|
|
|
private boolean mRemove;
|
2016-08-17 13:00:55 +02:00
|
|
|
|
2016-08-21 16:08:45 +02:00
|
|
|
|
2016-08-25 05:58:15 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
String key = parts[0].trim();
|
|
|
|
if (key.charAt(0) == '#') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String value = parts[1].trim();
|
|
|
|
switch (key) {
|
|
|
|
case "name":
|
|
|
|
mName = value;
|
|
|
|
break;
|
|
|
|
case "version":
|
|
|
|
mVersion = value;
|
|
|
|
break;
|
|
|
|
case "description":
|
|
|
|
mDescription = value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mEnable = !Utils.fileExist(mDisableFile);
|
|
|
|
mRemove = Utils.fileExist(mRemoveFile);
|
2016-08-17 13:00:55 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getVersion() {
|
|
|
|
return mVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDescription() {
|
|
|
|
return mDescription;
|
|
|
|
}
|
|
|
|
|
2016-08-22 12:30:13 +02:00
|
|
|
public void createDisableFile() {
|
2016-08-25 05:58:15 +08:00
|
|
|
mEnable = !Utils.createFile(mDisableFile);
|
2016-08-22 12:30:13 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 01:44:34 +08:00
|
|
|
public void removeDisableFile() {
|
2016-08-25 05:58:15 +08:00
|
|
|
mEnable = Utils.removeFile(mDisableFile);
|
2016-08-22 12:30:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEnabled() {
|
2016-08-25 05:58:15 +08:00
|
|
|
return mEnable;
|
2016-08-22 12:30:13 +02:00
|
|
|
}
|
|
|
|
|
2016-08-21 16:08:45 +02:00
|
|
|
public void createRemoveFile() {
|
2016-08-25 05:58:15 +08:00
|
|
|
mRemove = Utils.createFile(mRemoveFile);
|
2016-08-21 16:08:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 01:44:34 +08:00
|
|
|
public void deleteRemoveFile() {
|
2016-08-25 05:58:15 +08:00
|
|
|
mRemove = !Utils.removeFile(mRemoveFile);
|
2016-08-22 12:30:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean willBeRemoved() {
|
2016-08-25 05:58:15 +08:00
|
|
|
return mRemove;
|
2016-08-21 16:08:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 13:00:55 +02:00
|
|
|
}
|