mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-13 06:21:47 +00:00
Migrate to new endpoints
This commit is contained in:
@@ -4,7 +4,6 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -18,9 +17,8 @@ public class DelegateApplication extends Application {
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
|
||||
// Only dynamic load full APK if hidden and supported
|
||||
dynLoad = Build.VERSION.SDK_INT >= 21 &&
|
||||
!base.getPackageName().equals(BuildConfig.APPLICATION_ID);
|
||||
// Only dynamic load full APK if hidden
|
||||
dynLoad = !base.getPackageName().equals(BuildConfig.APPLICATION_ID);
|
||||
|
||||
receiver = InjectAPK.setup(this);
|
||||
if (receiver != null) try {
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.topjohnwu.magisk.net.Request;
|
||||
import com.topjohnwu.magisk.utils.APKInstall;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -31,21 +30,23 @@ import static com.topjohnwu.magisk.R.string.upgrade_msg;
|
||||
public class DownloadActivity extends Activity {
|
||||
|
||||
private static final String APP_NAME = "Magisk";
|
||||
private static final String CDN_URL = "https://cdn.jsdelivr.net/gh/topjohnwu/magisk_files@%s/%s";
|
||||
private static final String CANARY_URL = "https://topjohnwu.github.io/magisk-files/canary.json";
|
||||
|
||||
private String apkLink;
|
||||
private String sha;
|
||||
private String apkLink = BuildConfig.APK_URL;
|
||||
private Context themed;
|
||||
private ProgressDialog dialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Networking.init(this);
|
||||
themed = new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault);
|
||||
|
||||
if (Networking.checkNetworkStatus(this)) {
|
||||
fetchAPKURL();
|
||||
if (apkLink == null) {
|
||||
fetchCanary();
|
||||
} else {
|
||||
showDialog();
|
||||
}
|
||||
} else {
|
||||
new AlertDialog.Builder(themed)
|
||||
.setCancelable(false)
|
||||
@@ -56,21 +57,6 @@ public class DownloadActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchAPKURL() {
|
||||
dialog = ProgressDialog.show(themed, "", "", true);
|
||||
String url;
|
||||
if (BuildConfig.DEV_CHANNEL != null) {
|
||||
url = BuildConfig.DEV_CHANNEL;
|
||||
} else if (!BuildConfig.CANARY) {
|
||||
url = "https://topjohnwu.github.io/magisk_files/stable.json";
|
||||
} else {
|
||||
url = "https://api.github.com/repos/topjohnwu/magisk_files/branches/canary";
|
||||
request(url).getAsJSONObject(this::handleCanary);
|
||||
return;
|
||||
}
|
||||
request(url).getAsJSONObject(this::handleJSON);
|
||||
}
|
||||
|
||||
private void error(Throwable e) {
|
||||
Log.e(getClass().getSimpleName(), "", e);
|
||||
finish();
|
||||
@@ -80,32 +66,27 @@ public class DownloadActivity extends Activity {
|
||||
return Networking.get(url).setErrorHandler((conn, e) -> error(e));
|
||||
}
|
||||
|
||||
private void handleCanary(JSONObject json) {
|
||||
try {
|
||||
sha = json.getJSONObject("commit").getString("sha");
|
||||
String url = String.format(CDN_URL, sha, "canary.json");
|
||||
request(url).getAsJSONObject(this::handleJSON);
|
||||
} catch (JSONException e) {
|
||||
error(e);
|
||||
}
|
||||
private void showDialog() {
|
||||
new AlertDialog.Builder(themed)
|
||||
.setCancelable(false)
|
||||
.setTitle(APP_NAME)
|
||||
.setMessage(getString(upgrade_msg))
|
||||
.setPositiveButton(yes, (d, w) -> dlAPK())
|
||||
.setNegativeButton(no, (d, w) -> finish())
|
||||
.show();
|
||||
}
|
||||
|
||||
private void handleJSON(JSONObject json) {
|
||||
dialog.dismiss();
|
||||
try {
|
||||
apkLink = json.getJSONObject("app").getString("link");
|
||||
if (!apkLink.startsWith("http"))
|
||||
apkLink = String.format(CDN_URL, sha, apkLink);
|
||||
new AlertDialog.Builder(themed)
|
||||
.setCancelable(false)
|
||||
.setTitle(APP_NAME)
|
||||
.setMessage(getString(upgrade_msg))
|
||||
.setPositiveButton(yes, (d, w) -> dlAPK())
|
||||
.setNegativeButton(no, (d, w) -> finish())
|
||||
.show();
|
||||
} catch (JSONException e) {
|
||||
error(e);
|
||||
}
|
||||
private void fetchCanary() {
|
||||
dialog = ProgressDialog.show(themed, "", "", true);
|
||||
request(CANARY_URL).getAsJSONObject(json -> {
|
||||
dialog.dismiss();
|
||||
try {
|
||||
apkLink = json.getJSONObject("magisk").getString("link");
|
||||
showDialog();
|
||||
} catch (JSONException e) {
|
||||
error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void dlAPK() {
|
||||
|
||||
Reference in New Issue
Block a user