From c9f6e2e257946eea88846a0ba27891ca0dd87c8c Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 19 Sep 2016 11:47:52 +0800 Subject: [PATCH] Create BaseModule (for future merging with repo) --- .../topjohnwu/magisk/module/BaseModule.java | 103 ++++++++++++++ .../com/topjohnwu/magisk/module/Module.java | 131 +++--------------- app/src/main/res/values/strings.xml | 1 + 3 files changed, 124 insertions(+), 111 deletions(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java diff --git a/app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java b/app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java new file mode 100644 index 000000000..707ee371e --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java @@ -0,0 +1,103 @@ +package com.topjohnwu.magisk.module; + + +import android.util.Log; + +import java.util.List; + +public abstract class BaseModule { + + protected String mId, mName, mVersion, mDescription, mSupportUrl, mDonateUrl, mAuthor; + protected boolean mIsCacheModule = false; + + protected int mVersionCode = 0; + + public BaseModule(List props) { + this(props.toArray(new String[props.size()])); + } + + public BaseModule(String[] props) { + for (String line : props) { + String[] prop = line.split("=", 2); + if (prop.length != 2) { + continue; + } + + String key = prop[0].trim(); + if (key.charAt(0) == '#') { + continue; + } + + switch (key) { + case "id": + this.mId = prop[1]; + break; + case "name": + this.mName = prop[1]; + break; + case "version": + this.mVersion = prop[1]; + break; + case "versionCode": + this.mVersionCode = Integer.parseInt(prop[1]); + break; + case "author": + this.mAuthor = prop[1]; + break; + case "description": + this.mDescription = prop[1]; + break; + case "support": + this.mSupportUrl = prop[1]; + break; + case "donate": + this.mDonateUrl = prop[1]; + break; + case "cacheModule": + this.mIsCacheModule = Boolean.parseBoolean(prop[1]); + break; + default: + Log.d("Magisk", "Module: Manifest string not recognized: " + prop[0]); + break; + } + } + } + + public String getName() { + return mName; + } + + public String getVersion() { + return mVersion; + } + + public String getAuthor() { + return mAuthor; + } + + public String getId() {return mId; } + + public String getDescription() { + return mDescription; + } + + public boolean isCache() { + return mIsCacheModule; + } + + public void setCache() { + mIsCacheModule = true; + } + + public int getVersionCode() { + return mVersionCode; + } + + public String getmDonateUrl() { + return mDonateUrl; + } + + public String getmSupportUrl() { + return mSupportUrl; + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/module/Module.java b/app/src/main/java/com/topjohnwu/magisk/module/Module.java index 490056fdc..2e3dc3d35 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Module.java @@ -5,75 +5,39 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; +import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Utils; -public class Module { +public class Module extends BaseModule { private String mRemoveFile; private String mDisableFile; - private String mName = null; - private String mVersion = "(No version provided)"; - private String mDescription = "(No description provided)"; - private String mSupportUrl, mDonateUrl, mZipUrl, mAuthor, mLogUrl; - private boolean mEnable = false, mRemove = false, mUpdateAvailable = false, mIsInstalled, - mIsCacheModule = false; - - - private String mId; - private int mVersionCode; + private String mZipUrl, mLogUrl; + private boolean mEnable, mRemove, mUpdateAvailable = false, mIsInstalled; public Module(String path, Context context) { + super(Utils.readFile(path + "/module.prop")); + mRemoveFile = path + "/remove"; mDisableFile = path + "/disable"; - for (String line : Utils.readFile(path + "/module.prop")) { - String[] props = line.split("=", 2); - if (props.length != 2) { - continue; - } - - String key = props[0].trim(); - if (key.charAt(0) == '#') { - continue; - } - - switch (props[0]) { - case "id": - this.mId = props[1]; - break; - case "name": - this.mName = props[1]; - break; - case "version": - this.mVersion = props[1]; - break; - case "versionCode": - this.mVersionCode = Integer.parseInt(props[1]); - break; - case "author": - this.mAuthor = props[1]; - break; - case "description": - this.mDescription = props[1]; - break; - case "support": - this.mSupportUrl = props[1]; - break; - case "donate": - this.mDonateUrl = props[1]; - break; - case "cacheModule": - this.mIsCacheModule = Boolean.parseBoolean(props[1]); - break; - default: - Log.d("Magisk", "Module: Manifest string not recognized: " + props[0]); - break; - } - + if (mId == null) { + int sep = path.lastIndexOf('/'); + mId = path.substring(sep + 1); } - Log.d("Magisk","Module: Loaded module with ID of " + this.mId + " or " + mId); + + if (mName == null) + mName = mId; + + if (mDescription == null) + mDescription = context.getString(R.string.no_info_provided); + + if (mVersion == null) + mVersion = context.getString(R.string.no_info_provided); + + Log.d("Magisk","Module: Loaded module with ID of " + mId ); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); @@ -140,52 +104,13 @@ public class Module { editor.apply(); } - if (mName == null) { - int sep = path.lastIndexOf('/'); - mName = path.substring(sep + 1); - mId = mName; - } - mEnable = !Utils.fileExist(mDisableFile); mRemove = Utils.fileExist(mRemoveFile); } -// public Module(Repo repo) { -// -// mName = repo.getName(); -// mVersion = repo.getmVersion(); -// mDescription = repo.getDescription(); -// mId = repo.getId(); -// mVersionCode = repo.getmVersionCode(); -// mUrl = repo.getmZipUrl(); -// mEnable = true; -// mRemove = false; -// -// } - - - - public String getName() { - return mName; - } - - public String getVersion() { - return mVersion; - } - - public String getAuthor() { - return mAuthor; - } - - public String getId() {return mId; } - public String getmLogUrl() {return mLogUrl; } - public String getDescription() { - return mDescription; - } - public void createDisableFile() { mEnable = !Utils.createFile(mDisableFile); } @@ -210,24 +135,8 @@ public class Module { return mRemove; } - public boolean isCache() { - return mIsCacheModule; - } - - public void setCache() { - mIsCacheModule = true; - } - - public String getmDonateUrl() { - return mDonateUrl; - } - public String getmZipUrl() { return mZipUrl; } - public String getmSupportUrl() { - return mSupportUrl; - } - public boolean isUpdateAvailable() { return mUpdateAvailable; } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a9fb49f67..dacfca5b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -40,6 +40,7 @@ Samsung need custom kernel for switching SELinux status! + (No info provided) Cache modules No modules found An update is available!