Break/Fix

Wheeeeee
This commit is contained in:
d8ahazard
2016-09-06 16:54:08 -05:00
parent bef4361736
commit f404fe0570
16 changed files with 607 additions and 222 deletions
@@ -17,58 +17,117 @@ public class Module {
private String mName = null;
private String mVersion = "(No version provided)";
private String mDescription = "(No description provided)";
private String mUrl = null;
private String mUrl,mSupportUrl,mDonateUrl,mZipUrl,mBaseUrl,mManifestUrl,mAuthor;
private boolean mEnable, mRemove,mUpdateAvailable,mIsOnline;
private boolean mEnable;
private boolean mRemove;
private String mId;
private int mVersionCode;
public Module(String path, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Map<String,?> keys = prefs.getAll();
for(Map.Entry<String,?> entry : keys.entrySet()){
if(entry.getValue().toString().contains(path)) {
Log.d("Magisk", "Hey, look a matching path, this guy's name is " + entry.getKey().replace("path_",""));
}
}
mRemoveFile = path + "/remove";
mDisableFile = path + "/disable";
for (String line : Utils.readFile(path + "/module.prop")) {
String[] parts = line.split("=", 2);
if (parts.length != 2) {
String[] props = line.split("=", 2);
if (props.length != 2) {
continue;
}
String key = parts[0].trim();
String key = props[0].trim();
if (key.charAt(0) == '#') {
continue;
}
String value = parts[1].trim();
switch (key) {
String value = props[1].trim();
switch (props[0]) {
case "versionCode":
this.mVersionCode = Integer.valueOf(props[1]);
break;
case "name":
mName = value;
this.mName = props[1];
break;
case "version":
mVersion = value;
break;
case "description":
mDescription = value;
case "author":
this.mAuthor = props[1];
break;
case "id":
mId = value;
this.mId = props[1];
break;
case "versionCode":
try {
mVersionCode = Integer.parseInt(value);
} catch (NumberFormatException e) {
mVersionCode = 0;
case "version":
this.mVersion = props[1];
break;
case "description":
this.mDescription = props[1];
break;
case "donate":
this.mDonateUrl = props[1];
break;
case "support":
this.mSupportUrl = props[1];
break;
case "donateUrl":
this.mDonateUrl = props[1];
break;
case "zipUrl":
this.mZipUrl = props[1];
break;
case "baseUrl":
this.mBaseUrl = props[1];
break;
case "manifestUrl":
this.mManifestUrl = props[1];
break;
default:
Log.d("Magisk", "Manifest string not recognized: " + props[0]);
break;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (mId != null) {
Log.d("Magisk", "Module: Checking for preference named repo_" + mId);
if (prefs.contains("repo_" + mId)) {
String entryString = prefs.getString("repo_" + mId, "");
String entryName = "repo" + mId;
String[] subStrings = entryString.split("\n");
for (String subKeys : subStrings) {
String[] idEntry = subKeys.split("=", 2);
Log.d("Magisk", "Module: Checking entry strings. Key is " + idEntry[0] + " and value is " + idEntry[1]);
if (idEntry[0].equals("id")) {
if (idEntry.length != 2) {
continue;
}
if (idEntry[1].equals(mId)) {
Log.d("Magisk", "Module: Hey, I know I'm online...");
mIsOnline = true;
} else mIsOnline = false;
}
if (idEntry[0].equals("versionCode")) {
if (idEntry.length != 2) {
continue;
}
if (Integer.valueOf(idEntry[1]) > mVersionCode) {
mUpdateAvailable = true;
Log.d("Magisk", "Module: Hey, I have an update...");
} else mUpdateAvailable = false;
}
}
break;
}
SharedPreferences.Editor editor = prefs.edit();
if (mIsOnline) {
editor.putBoolean("repo_isInstalled_" + mId, true);
} else {
editor.putBoolean("repo_isInstalled_" + mId, false);
}
editor.apply();
}
}
@@ -86,11 +145,11 @@ public class Module {
public Module(Repo repo) {
mName = repo.getName();
mVersion = repo.getVersion();
mVersion = repo.getmVersion();
mDescription = repo.getDescription();
mId = "foo";
mVersionCode = 111;
mUrl = repo.getZipUrl();
mUrl = repo.getmZipUrl();
mEnable = true;
mRemove = false;
@@ -134,4 +193,8 @@ public class Module {
return mRemove;
}
public boolean isOnline() {return mIsOnline; }
public boolean isUpdateAvailable() { return mUpdateAvailable; };
}
@@ -15,53 +15,76 @@ import java.text.SimpleDateFormat;
import java.util.Date;
public class Repo {
public String name;
public String baseUrl, zipUrl, manifestUrl, logUrl, manifest, version, moduleName, moduleDescription, moduleAuthor, moduleAuthorUrl;
public Date lastUpdate;
public Boolean usesRoot, usesXposed;
private String mBaseUrl;
private String mZipUrl;
private String mLogUrl;
private String mManifestUrl;
private String mVersion;
private String mName;
private String mDescription;
private String mAuthor;
public String mAuthorUrl;
private String mId;
private String mVersionCode;
private String mSupportUrl;
private String mDonateUrl;
private Date lastUpdate;
private Context appContext;
private SharedPreferences prefs;
private boolean mIsInstalled;
public Repo(String manifestString, Context context) {
ParseProps(manifestString);
appContext = context;
}
public Repo(String name, String url, Date updated, Context context) {
appContext = context;
this.name = name;
this.baseUrl = url;
this.mName = name;
this.mBaseUrl = url;
this.lastUpdate = updated;
this.fetch();
}
public Repo(String moduleName, String moduleDescription, String zipUrl, Date lastUpdated, Context context) {
Log.d("Magisk", "Hey, I'm a repo! My name is " + moduleName);
appContext = context;
this.zipUrl = zipUrl;
this.moduleDescription = moduleDescription;
this.moduleName = moduleName;
this.mZipUrl = zipUrl;
this.mDescription = moduleDescription;
this.mName = moduleName;
this.lastUpdate = lastUpdated;
this.fetch();
}
public void fetch() {
prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
private void fetch() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
if (prefs.contains("repo_" + this.mId)) {
String repoString = prefs.getString("repo_" + this.mId,"");
if (!repoString.equals("")) {
ParseProps(repoString);
}
}
if (prefs.contains("repo_isInstalled_" + this.mId)) {
mIsInstalled = prefs.getBoolean("repo_isInstalled_" + this.mId,false);
}
WebRequest webreq = new WebRequest();
// Construct initial url for contents
Log.d("Magisk", "Manifest string is: " + baseUrl + "/contents/");
String repoString = webreq.makeWebServiceCall(baseUrl + "/contents/", WebRequest.GET);
Log.d("Magisk", "Manifest string is: " + mBaseUrl + "/contents/");
String repoString = webreq.makeWebServiceCall(mBaseUrl + "/contents/", WebRequest.GET);
try {
JSONArray repoArray = new JSONArray(repoString);
for (int f = 0; f < repoArray.length(); f++) {
JSONObject jsonobject = repoArray.getJSONObject(f);
String name = jsonobject.getString("name");
if (name.contains(".zip")) {
this.zipUrl = jsonobject.getString("download_url");
} else if (name.equals("module.json")) {
this.manifestUrl = jsonobject.getString("download_url");
} else if (name.equals("Changelog.txt")) {
this.logUrl = jsonobject.getString("download_url");
this.mZipUrl = jsonobject.getString("download_url");
} else if (name.equals("module.prop")) {
this.mManifestUrl = jsonobject.getString("download_url");
} else if (name.equals("changelog.txt")) {
this.mLogUrl = jsonobject.getString("download_url");
}
}
} catch (JSONException e) {
@@ -69,60 +92,159 @@ public class Repo {
}
Log.d("Magisk", "Inner fetch: " + repoString);
try {
WebRequest jsonReq = new WebRequest();
// Construct initial url for contents
String manifestString = webreq.makeWebServiceCall(this.manifestUrl, WebRequest.GET);
JSONObject manifestObject = new JSONObject(manifestString);
Log.d("Magisk", "Object: " + manifestObject.toString());
version = manifestObject.getString("versionCode");
moduleName = manifestObject.getString("moduleName");
moduleDescription = manifestObject.getString("moduleDescription");
moduleAuthor = manifestObject.getString("moduleAuthor");
usesRoot = Boolean.getBoolean(manifestObject.getString("usesRoot"));
usesXposed = Boolean.getBoolean(manifestObject.getString("usesXposed"));
SharedPreferences.Editor editor = prefs.edit();
String prefsString = "[{\"moduleDescription\":\"" + moduleDescription + "\","
+ "\"moduleName\":\"" + moduleName + "\","
+ "\"moduleAuthor\":\"" + moduleAuthor + "\","
+ "\"moduleAuthorUrl\":\"" + moduleAuthorUrl + "\","
+ "\"usesRoot\":\"" + usesRoot + "\","
+ "\"usesXposed\":\"" + usesXposed + "\","
+ "\"zipUrl\":\"" + zipUrl + "\","
+ "\"lastUpdate\":\"" + lastUpdate + "\","
+ "\"logUrl\":\"" + logUrl + "\"}]";
editor.putString("module_" + moduleName, prefsString);
editor.putBoolean("hasCachedRepos", true);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
editor.putString("updated", sdf.toString());
Log.d("Magisk", "Storing Preferences: " + prefsString);
editor.apply();
} catch (JSONException e) {
e.printStackTrace();
WebRequest propReq = new WebRequest();
String manifestString = propReq.makeWebServiceCall(this.mManifestUrl,WebRequest.GET,true);
if (ParseProps(manifestString)) {
PutProps(manifestString);
}
}
public String getName() {
return moduleName;
private void PutProps(String manifestString) {
manifestString = manifestString + "zipUrl=" + mZipUrl + "\nbaseUrl=" + mBaseUrl + "\nlogUrl=" + mLogUrl + "\nmanifestUrl=" + mManifestUrl;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("repo_" + mId, manifestString);
editor.putBoolean("hasCachedRepos", true);
editor.putString("updated_" + mId, this.lastUpdate.toString());
Log.d("Magisk", "Storing Preferences: " + manifestString);
editor.apply();
}
private boolean ParseProps(String string) {
Log.d("Magisk","Repo: parseprops called for string " + string);
if ((string.length() <= 1) | (!string.contains("id"))) {
return false;
} else {
String lines[] = string.split("\\n");
for (String line : lines) {
if (line != "") {
String props[] = line.split("=");
Log.d("Magisk", "Repo: Split values are " + props[0] + " and " + props[1]);
switch (props[0]) {
case "versionCode":
this.mVersionCode = props[1];
break;
case "name":
this.mName = props[1];
break;
case "author":
this.mAuthor = props[1];
break;
case "id":
this.mId = props[1];
break;
case "version":
this.mVersion = props[1];
break;
case "description":
this.mDescription = props[1];
break;
case "donate":
this.mDonateUrl = props[1];
break;
case "support":
this.mSupportUrl = props[1];
break;
case "donateUrl":
this.mDonateUrl = props[1];
break;
case "zipUrl":
this.mZipUrl = props[1];
break;
case "baseUrl":
this.mBaseUrl = props[1];
break;
case "manifestUrl":
this.mManifestUrl = props[1];
break;
default:
Log.d("Magisk", "Manifest string not recognized: " + props[0]);
break;
}
}
}
return this.mName != null;
}
}
public String getVersion() {
return version;
public String getStringProperty(String mValue) {
switch (mValue) {
case "author":
return mAuthor;
case "id":
return mId;
case "version":
return mVersion;
case "description":
return mDescription;
case "supportUrl":
return mSupportUrl;
case "donateUrl":
return mDonateUrl;
case "baseeUrl":
return mBaseUrl;
case "zipUrl":
return mZipUrl;
default:
return null;
}
}
public String getName() {
return mName;
}
public String getmVersion() {
return mVersion;
}
public int getmVersionCode() {
return Integer.valueOf(mVersionCode);
}
public String getDescription() {
return moduleDescription;
return mDescription;
}
public String getZipUrl() {
return zipUrl;
public String getId() {
return mId;
}
public String getLogUrl() {
return logUrl;
public String getmZipUrl() {
return mZipUrl;
}
public String getmBaseUrl() {
return mBaseUrl;
}
public String getmLogUrl() {
return mLogUrl;
}
}
public String getmAuthor() {
return mAuthor;
}
public String getmDonateUrl() {
return mDonateUrl;
}
public String getmManifestUrl() {
return mManifestUrl;
}
public String getmSupportUrl() {
return mSupportUrl;
}
public Date getLastUpdate() {
return lastUpdate;
}
public boolean isInstalled() { return mIsInstalled; }
}
@@ -3,29 +3,39 @@ package com.topjohnwu.magisk.module;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.Toast;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class RepoAdapter {
private String[] result;
private static String url = "https://api.github.com/orgs/Magisk-Modules-Repo/repos";
private static List<Repo> repos = new ArrayList<Repo>();
private static List<Repo> repos = new ArrayList<Repo>() {
};
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static String TAG = "Magisk";
private Context activityContext;
private Date updatedDate, currentDate;
@@ -36,39 +46,17 @@ public class RepoAdapter {
new MyAsyncTask().execute();
List<String> out = null;
} else {
Log.d("Magisk", "Building from cache");
Log.d(TAG, "Building from cache");
Map<String, ?> map = prefs.getAll();
repos.clear();
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getKey().contains("module_")) {
String repoString = entry.getValue().toString().replace("&quot;", "\"");
JSONArray repoArray = null;
try {
repoArray = new JSONArray(repoString);
for (int f = 0; f < repoArray.length(); f++) {
JSONObject jsonobject = repoArray.getJSONObject(f);
String name = entry.getKey().replace("module_", "");
name = name.replace(" ", "");
String moduleName, moduleDescription, zipUrl;
moduleName = jsonobject.getString("moduleName");
moduleDescription = jsonobject.getString("moduleDescription");
zipUrl = jsonobject.getString("zipUrl");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
updatedDate = format.parse(jsonobject.getString("lastUpdate"));
} catch (ParseException e) {
e.printStackTrace();
}
repos.add(new Repo(name, moduleDescription, zipUrl, updatedDate, activityContext));
}
} catch (JSONException e) {
e.printStackTrace();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
map.entrySet().stream().filter(entry -> entry.getKey().contains("repo_")).forEach(entry -> {
String repoString = entry.getValue().toString();
if (repoString.length() >= 0) {
repos.add(new Repo(repoString,context));
}
}
});
}
}
@@ -120,8 +108,8 @@ public class RepoAdapter {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!name.contains("Repo.github.io")) {
if ((!name.contains("Repo.github.io"))) {
//if (!name.contains("Repo.github.io") && name.contains("template")) {
repos.add(new Repo(name, url, updatedDate, activityContext));
}
}