2016-08-23 05:18:28 +08:00
|
|
|
package com.topjohnwu.magisk.module;
|
2016-08-17 13:00:55 +02:00
|
|
|
|
2016-09-02 13:18:37 -05:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2016-09-19 11:47:52 +08:00
|
|
|
import com.topjohnwu.magisk.R;
|
2016-09-25 21:31:38 +08:00
|
|
|
import com.topjohnwu.magisk.utils.Logger;
|
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-08-25 05:58:15 +08:00
|
|
|
private String mRemoveFile;
|
|
|
|
private String mDisableFile;
|
2016-08-17 13:00:55 +02:00
|
|
|
|
2016-09-19 11:47:52 +08:00
|
|
|
private String mZipUrl, mLogUrl;
|
2016-09-25 21:31:38 +08:00
|
|
|
private boolean mEnable, mRemove, mUpdateAvailable = false;
|
2016-08-29 06:35:07 +08:00
|
|
|
|
2016-09-21 11:29:43 +08:00
|
|
|
public Module(Context context, String path) {
|
2016-09-02 13:18:37 -05:00
|
|
|
|
2016-09-21 11:29:43 +08:00
|
|
|
super();
|
|
|
|
parseProps(Utils.readFile(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-19 11:47:52 +08:00
|
|
|
if (mId == null) {
|
|
|
|
int sep = path.lastIndexOf('/');
|
|
|
|
mId = path.substring(sep + 1);
|
|
|
|
}
|
2016-08-25 05:58:15 +08:00
|
|
|
|
2016-09-19 11:47:52 +08:00
|
|
|
if (mName == null)
|
|
|
|
mName = mId;
|
2016-09-06 16:54:08 -05:00
|
|
|
|
2016-09-19 11:47:52 +08:00
|
|
|
if (mDescription == null)
|
|
|
|
mDescription = context.getString(R.string.no_info_provided);
|
2016-09-06 16:54:08 -05:00
|
|
|
|
2016-09-19 11:47:52 +08:00
|
|
|
if (mVersion == null)
|
|
|
|
mVersion = context.getString(R.string.no_info_provided);
|
|
|
|
|
2016-09-25 21:31:38 +08:00
|
|
|
Logger.dh("Module id: " + mId);
|
2016-09-06 16:54:08 -05:00
|
|
|
|
2016-09-25 21:31:38 +08:00
|
|
|
mEnable = !Utils.itemExist(mDisableFile);
|
|
|
|
mRemove = Utils.itemExist(mRemoveFile);
|
2016-08-17 13:00:55 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-23 17:12:29 +08:00
|
|
|
public void checkUpdate() {
|
|
|
|
Repo repo = RepoHelper.repoMap.get(mId);
|
|
|
|
if (repo != null) {
|
|
|
|
repo.setInstalled();
|
|
|
|
if (repo.getVersionCode() > mVersionCode) {
|
|
|
|
repo.setUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-13 15:44:07 -05:00
|
|
|
public String getmLogUrl() {return mLogUrl; }
|
2016-09-12 16:47:32 -05:00
|
|
|
|
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-09-13 15:44:07 -05:00
|
|
|
public String getmZipUrl() { return mZipUrl; }
|
|
|
|
|
2016-09-09 23:40:57 -05:00
|
|
|
public boolean isUpdateAvailable() { return mUpdateAvailable; }
|
2016-09-06 16:54:08 -05:00
|
|
|
|
2016-08-17 13:00:55 +02:00
|
|
|
}
|