2016-08-23 05:18:28 +08:00
|
|
|
package com.topjohnwu.magisk.module;
|
2016-08-17 13:00:55 +02:00
|
|
|
|
2016-09-25 21:31:38 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Logger;
|
2017-07-16 01:20:39 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Shell;
|
2016-08-23 05:18:28 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
2016-08-21 16:08:45 +02:00
|
|
|
|
2016-09-19 11:47:52 +08:00
|
|
|
public class Module extends BaseModule {
|
2016-08-17 13:00:55 +02:00
|
|
|
|
2016-09-29 03:37:57 +08:00
|
|
|
private String mRemoveFile, mDisableFile, mUpdateFile;
|
|
|
|
private boolean mEnable, mRemove, mUpdated;
|
2016-08-29 06:35:07 +08:00
|
|
|
|
2017-07-16 01:20:39 +08:00
|
|
|
public Module(Shell shell, String path) throws CacheModException {
|
2016-09-02 13:18:37 -05:00
|
|
|
|
2017-07-16 01:20:39 +08:00
|
|
|
parseProps(Utils.readFile(shell, path + "/module.prop"));
|
2016-09-19 11:47:52 +08:00
|
|
|
|
2016-08-25 05:58:15 +08:00
|
|
|
mRemoveFile = path + "/remove";
|
|
|
|
mDisableFile = path + "/disable";
|
2016-09-29 03:37:57 +08:00
|
|
|
mUpdateFile = path + "/update";
|
2016-08-25 05:58:15 +08:00
|
|
|
|
2017-02-19 08:05:16 +08:00
|
|
|
if (getId() == null) {
|
2016-09-19 11:47:52 +08:00
|
|
|
int sep = path.lastIndexOf('/');
|
2017-02-19 08:05:16 +08:00
|
|
|
setId(path.substring(sep + 1));
|
2016-09-19 11:47:52 +08:00
|
|
|
}
|
2016-08-25 05:58:15 +08:00
|
|
|
|
2017-02-21 03:30:37 +08:00
|
|
|
if (getName() == null) {
|
2017-02-19 08:05:16 +08:00
|
|
|
setName(getId());
|
2017-02-21 03:30:37 +08:00
|
|
|
}
|
2016-09-06 16:54:08 -05:00
|
|
|
|
2017-02-19 08:05:16 +08:00
|
|
|
Logger.dev("Creating Module, id: " + getId());
|
2016-09-06 16:54:08 -05:00
|
|
|
|
2017-07-16 01:20:39 +08:00
|
|
|
mEnable = !Utils.itemExist(shell, mDisableFile);
|
|
|
|
mRemove = Utils.itemExist(shell, mRemoveFile);
|
|
|
|
mUpdated = Utils.itemExist(shell, mUpdateFile);
|
2016-08-17 13:00:55 +02:00
|
|
|
}
|
|
|
|
|
2017-07-16 01:20:39 +08:00
|
|
|
public void createDisableFile(Shell shell) {
|
2017-06-06 03:06:23 +08:00
|
|
|
mEnable = false;
|
2017-07-16 01:20:39 +08:00
|
|
|
Utils.createFile(shell, mDisableFile);
|
2016-08-22 12:30:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-16 01:20:39 +08:00
|
|
|
public void removeDisableFile(Shell shell) {
|
2017-06-06 03:06:23 +08:00
|
|
|
mEnable = true;
|
2017-07-16 01:20:39 +08:00
|
|
|
Utils.removeItem(shell, 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
|
|
|
}
|
|
|
|
|
2017-07-16 01:20:39 +08:00
|
|
|
public void createRemoveFile(Shell shell) {
|
2017-06-06 03:06:23 +08:00
|
|
|
mRemove = true;
|
2017-07-16 01:20:39 +08:00
|
|
|
Utils.createFile(shell, mRemoveFile);
|
2016-08-21 16:08:45 +02:00
|
|
|
}
|
|
|
|
|
2017-07-16 01:20:39 +08:00
|
|
|
public void deleteRemoveFile(Shell shell) {
|
2017-06-06 03:06:23 +08:00
|
|
|
mRemove = false;
|
2017-07-16 01:20:39 +08:00
|
|
|
Utils.removeItem(shell, 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-09-29 03:37:57 +08:00
|
|
|
public boolean isUpdated() {
|
|
|
|
return mUpdated;
|
|
|
|
}
|
|
|
|
|
2016-08-17 13:00:55 +02:00
|
|
|
}
|