You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Synch update - WIP
Not finished, just synchronizing workflows.
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
package com.topjohnwu.magisk.module;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
public class Module {
|
||||
|
||||
private String mRemoveFile;
|
||||
@@ -17,6 +10,7 @@ public class Module {
|
||||
private String mName = null;
|
||||
private String mVersion = "(No version provided)";
|
||||
private String mDescription = "(No description provided)";
|
||||
private String mUrl = null;
|
||||
|
||||
private boolean mEnable;
|
||||
private boolean mRemove;
|
||||
@@ -24,7 +18,6 @@ public class Module {
|
||||
private String mId;
|
||||
private int mVersionCode;
|
||||
|
||||
|
||||
public Module(String path) {
|
||||
mRemoveFile = path + "/remove";
|
||||
mDisableFile = path + "/disable";
|
||||
@@ -74,25 +67,21 @@ public class Module {
|
||||
|
||||
}
|
||||
|
||||
public Module(ModuleRepo.Repo repo) {
|
||||
|
||||
|
||||
|
||||
mName = repo.getName();
|
||||
mVersion = repo.getVersion();
|
||||
mDescription = repo.getDescription();
|
||||
mId = "foo";
|
||||
mVersionCode = 111;
|
||||
|
||||
|
||||
|
||||
|
||||
public Module(Repo repo) {
|
||||
|
||||
mName = repo.getName();
|
||||
mVersion = repo.getVersion();
|
||||
mDescription = repo.getDescription();
|
||||
mId = "foo";
|
||||
mVersionCode = 111;
|
||||
mUrl = repo.getZipUrl();
|
||||
mEnable = true;
|
||||
mRemove = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
package com.topjohnwu.magisk.module;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.utils.WebRequest;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleRepo {
|
||||
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 final String TAG_ID = "id";
|
||||
private static final String TAG_NAME = "name";
|
||||
private Context activityContext;
|
||||
|
||||
|
||||
public List<Repo> listRepos() {
|
||||
MyAsyncTask asynchTask = new MyAsyncTask();
|
||||
Log.d("Magisk", "Gitagent init called");
|
||||
asynchTask.execute();
|
||||
List<String> out = null;
|
||||
|
||||
|
||||
|
||||
return repos;
|
||||
}
|
||||
|
||||
public JSONArray fetchModuleArray() {
|
||||
fetchRepoInfo();
|
||||
parseRepoInfo();
|
||||
JSONArray moduleArray = enumerateModules();
|
||||
return null;
|
||||
}
|
||||
|
||||
private void fetchRepoInfo() {
|
||||
|
||||
}
|
||||
|
||||
private void parseRepoInfo() {
|
||||
|
||||
}
|
||||
|
||||
private JSONArray enumerateModules() {
|
||||
JSONArray enumeratedModules = new JSONArray();
|
||||
return enumeratedModules;
|
||||
}
|
||||
|
||||
class MyAsyncTask extends AsyncTask<String, String, Void> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... params) {
|
||||
Log.d("Magisk", "doInBackground running");
|
||||
// Creating service handler class instance
|
||||
WebRequest webreq = new WebRequest();
|
||||
|
||||
// Making a request to url and getting response
|
||||
String jsonStr = webreq.makeWebServiceCall(url, WebRequest.GET);
|
||||
|
||||
Log.d("Response: ", "> " + jsonStr);
|
||||
|
||||
try {
|
||||
repos.clear();
|
||||
JSONArray jsonArray = new JSONArray(jsonStr);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject jsonobject = jsonArray.getJSONObject(i);
|
||||
String name = jsonobject.getString("name");
|
||||
String urlString = jsonobject.getString("html_url");
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
if (!name.contains("Repo.github.io")) {
|
||||
repos.add(new Repo(name, url));
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
for (int i = 0; i < repos.size(); i++) {
|
||||
Repo repo = repos.get(i);
|
||||
Log.d("Magisk", repo.name + " URL: " + repo.url);
|
||||
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void onPostExecute(Void v) {
|
||||
|
||||
|
||||
} // protected void onPostExecute(Void v)
|
||||
} //class MyAsyncTask extends AsyncTask<String, String, Void>
|
||||
|
||||
protected void onPreExecute() {
|
||||
|
||||
}
|
||||
|
||||
public class Repo {
|
||||
public String name;
|
||||
public URL url;
|
||||
public String manifest, version, moduleName, moduleDescription, moduleAuthor, moduleAuthorUrl;
|
||||
public Boolean usesRoot,usesXposed;
|
||||
|
||||
|
||||
public Repo(String name, URL url) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.manifest = ("https://raw.githubusercontent.com/Magisk-Modules-Repo/" + name + "/master/module.json");
|
||||
WebRequest webreq = new WebRequest();
|
||||
|
||||
// Making a request to url and getting response
|
||||
String manifestString = webreq.makeWebServiceCall(manifest, WebRequest.GET);
|
||||
Log.d("Magisk","Inner fetch: " + manifestString);
|
||||
try {
|
||||
JSONObject jsonobject = new JSONObject(manifestString);
|
||||
Log.d("Magisk","Object: " +jsonobject.toString());
|
||||
version = jsonobject.getString("versionCode");
|
||||
moduleName = jsonobject.getString("moduleName");
|
||||
moduleDescription = jsonobject.getString("moduleDescription");
|
||||
moduleAuthor = jsonobject.getString("moduleAuthor");
|
||||
moduleAuthorUrl = jsonobject.getString("authorUrl");
|
||||
usesRoot = Boolean.getBoolean(jsonobject.getString("usesRoot"));
|
||||
usesXposed = Boolean.getBoolean(jsonobject.getString("usesXposed"));
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Log.d("Magisk","We're in! " + " " + version + " " + moduleName + " " + moduleAuthor + " " + moduleDescription + " " + moduleAuthorUrl);
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return moduleDescription;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.topjohnwu.magisk.module;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.utils.WebRequest;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Repo {
|
||||
public String name;
|
||||
public String baseUrl, zipUrl,manifestUrl, logUrl;
|
||||
public String manifest, version, moduleName, moduleDescription, moduleAuthor, moduleAuthorUrl;
|
||||
public Boolean usesRoot,usesXposed;
|
||||
private Context appContext;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
|
||||
public Repo(String name, String url, Context context) {
|
||||
appContext = context;
|
||||
this.name = name;
|
||||
this.baseUrl = url;
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
|
||||
|
||||
}
|
||||
|
||||
public Repo(String moduleName, String moduleDescription, String zipUrl) {
|
||||
this.zipUrl = zipUrl;
|
||||
this.moduleDescription = moduleDescription;
|
||||
this.moduleName = moduleName;
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
|
||||
}
|
||||
|
||||
public void fetch() {
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
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 + "\","
|
||||
+ "\"logUrl\":\"" + logUrl + "\"}]";
|
||||
editor.putString("module_" + moduleName,prefsString);
|
||||
editor.putBoolean("hasCachedRepos",true);
|
||||
editor.apply();
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
public String getLogUrl() {
|
||||
return logUrl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.topjohnwu.magisk.module;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.utils.WebRequest;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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 final String TAG_ID = "id";
|
||||
private static final String TAG_NAME = "name";
|
||||
private Context activityContext;
|
||||
|
||||
|
||||
public List<Repo> listRepos(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (!prefs.contains("hasCachedRepos")) {
|
||||
activityContext = context;
|
||||
MyAsyncTask asynchTask = new MyAsyncTask();
|
||||
asynchTask.execute();
|
||||
List<String> out = null;
|
||||
} else {
|
||||
Log.d("Magisk", "Building from cache");
|
||||
Map<String,?> map = prefs.getAll();
|
||||
for (Map.Entry<String,?> entry : map.entrySet())
|
||||
{
|
||||
if (entry.getKey().contains("module_")) {
|
||||
String repoString = entry.getValue().toString();
|
||||
JSONArray repoArray = null;
|
||||
try {
|
||||
repoArray = new JSONArray(repoString);
|
||||
|
||||
repos.clear();
|
||||
for (int f = 0; f < repoArray.length(); f++) {
|
||||
JSONObject jsonobject = repoArray.getJSONObject(f);
|
||||
String name = jsonobject.getString("name");
|
||||
String moduleName, moduleDescription, zipUrl;
|
||||
moduleName = jsonobject.getString("moduleName");
|
||||
moduleDescription = jsonobject.getString("moduleDescription");
|
||||
zipUrl = jsonobject.getString("zipUrl");
|
||||
repos.add(new Repo(moduleName,moduleDescription,zipUrl));
|
||||
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println(entry.getKey() + "/" + entry.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return repos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class MyAsyncTask extends AsyncTask<String, String, Void> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... params) {
|
||||
Log.d("Magisk", "doInBackground running");
|
||||
// Creating service handler class instance
|
||||
WebRequest webreq = new WebRequest();
|
||||
|
||||
// Making a request to url and getting response
|
||||
String jsonStr = webreq.makeWebServiceCall(url, WebRequest.GET);
|
||||
|
||||
Log.d("Response: ", "> " + jsonStr);
|
||||
|
||||
try {
|
||||
repos.clear();
|
||||
JSONArray jsonArray = new JSONArray(jsonStr);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject jsonobject = jsonArray.getJSONObject(i);
|
||||
String name = jsonobject.getString("name");
|
||||
String url = jsonobject.getString("url");
|
||||
if (!name.contains("Repo.github.io")) {
|
||||
repos.add(new Repo(name, url, activityContext));
|
||||
}
|
||||
for (int f = 0; f < repos.size(); f++) {
|
||||
repos.get(f).fetch();
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void onPostExecute(Void v) {
|
||||
|
||||
|
||||
} // protected void onPostExecute(Void v)
|
||||
} //class MyAsyncTask extends AsyncTask<String, String, Void>
|
||||
|
||||
protected void onPreExecute() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user