Magisk/app/src/main/java/com/topjohnwu/magisk/container/Module.java

79 lines
1.9 KiB
Java
Raw Normal View History

2019-01-30 09:10:12 +01:00
package com.topjohnwu.magisk.container;
2016-08-17 13:00:55 +02:00
import android.os.Parcel;
import android.os.Parcelable;
2018-02-12 16:07:35 +01:00
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.io.SuFile;
public class Module extends BaseModule {
2016-08-17 13:00:55 +02:00
2018-02-12 16:07:35 +01:00
private SuFile mRemoveFile, mDisableFile, mUpdateFile;
2016-09-28 21:37:57 +02:00
private boolean mEnable, mRemove, mUpdated;
2016-08-29 00:35:07 +02:00
2017-10-15 17:02:44 +02:00
public Module(String path) {
2016-09-02 20:18:37 +02:00
try {
2018-11-13 06:21:42 +01:00
parseProps(Shell.su("dos2unix < " + path + "/module.prop").exec().getOut());
} catch (NumberFormatException ignored) {}
2018-07-26 22:48:32 +02:00
mRemoveFile = new SuFile(path, "remove");
mDisableFile = new SuFile(path, "disable");
mUpdateFile = new SuFile(path, "update");
if (getId().isEmpty()) {
int sep = path.lastIndexOf('/');
setId(path.substring(sep + 1));
}
if (getName().isEmpty()) {
setName(getId());
}
2016-09-06 23:54:08 +02:00
2018-02-12 16:07:35 +01:00
mEnable = !mDisableFile.exists();
mRemove = mRemoveFile.exists();
mUpdated = mUpdateFile.exists();
2016-08-17 13:00:55 +02:00
}
public static final Parcelable.Creator<Module> CREATOR = new Creator<Module>() {
/* It won't be used at any place */
@Override
public Module createFromParcel(Parcel source) {
return null;
}
@Override
public Module[] newArray(int size) {
return null;
}
};
2017-10-15 17:02:44 +02:00
public void createDisableFile() {
2018-11-13 06:21:42 +01:00
mEnable = !mDisableFile.createNewFile();
}
2017-10-15 17:02:44 +02:00
public void removeDisableFile() {
2018-11-13 06:21:42 +01:00
mEnable = mDisableFile.delete();
}
public boolean isEnabled() {
return mEnable;
}
2017-10-15 17:02:44 +02:00
public void createRemoveFile() {
2018-11-13 06:21:42 +01:00
mRemove = mRemoveFile.createNewFile();
}
2017-10-15 17:02:44 +02:00
public void deleteRemoveFile() {
2018-11-13 06:21:42 +01:00
mRemove = !mRemoveFile.delete();
}
public boolean willBeRemoved() {
return mRemove;
}
2016-09-28 21:37:57 +02:00
public boolean isUpdated() {
return mUpdated;
}
2016-08-17 13:00:55 +02:00
}