2018-12-02 04:47:57 -05:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Application;
|
|
|
|
import android.os.Bundle;
|
2019-10-12 03:57:56 -04:00
|
|
|
import android.util.Log;
|
2018-12-02 04:47:57 -05:00
|
|
|
|
|
|
|
import com.topjohnwu.magisk.utils.APKInstall;
|
2019-08-04 14:28:04 -07:00
|
|
|
import com.topjohnwu.magisk.net.Networking;
|
|
|
|
import com.topjohnwu.magisk.net.ResponseListener;
|
2018-12-02 04:47:57 -05:00
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
public class MainActivity extends Activity {
|
|
|
|
|
2019-10-12 03:57:56 -04:00
|
|
|
private static final String TAG = "MMStub";
|
|
|
|
private static final boolean IS_CANARY = BuildConfig.VERSION_NAME.contains("-");
|
2018-12-02 04:47:57 -05:00
|
|
|
private static final String URL =
|
2019-10-12 03:57:56 -04:00
|
|
|
"https://raw.githubusercontent.com/topjohnwu/magisk_files/" +
|
|
|
|
(IS_CANARY ? "canary/release.json" : "master/stable.json");
|
2018-12-02 04:47:57 -05:00
|
|
|
|
|
|
|
private String apkLink;
|
|
|
|
|
|
|
|
private void dlAPK() {
|
|
|
|
Application app = getApplication();
|
2018-12-12 05:51:45 -05:00
|
|
|
Networking.get(apkLink)
|
2019-10-12 03:57:56 -04:00
|
|
|
.getAsFile(new File(getFilesDir(), "manager.apk"),
|
|
|
|
apk -> APKInstall.install(app, apk));
|
2018-12-02 04:47:57 -05:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2018-12-27 14:35:55 +08:00
|
|
|
Networking.init(this);
|
|
|
|
if (Networking.checkNetworkStatus(this)) {
|
2018-12-12 05:51:45 -05:00
|
|
|
Networking.get(URL)
|
2019-10-12 03:57:56 -04:00
|
|
|
.setErrorHandler(((conn, e) -> {
|
|
|
|
Log.d(TAG, "network error", e);
|
|
|
|
finish();
|
|
|
|
}))
|
2018-12-12 05:51:45 -05:00
|
|
|
.getAsJSONObject(new JSONLoader());
|
2018-12-02 04:47:57 -05:00
|
|
|
} else {
|
2019-10-12 03:57:56 -04:00
|
|
|
new AlertDialog.Builder(this)
|
2018-12-02 04:47:57 -05:00
|
|
|
.setCancelable(false)
|
|
|
|
.setTitle(R.string.app_name)
|
|
|
|
.setMessage(R.string.no_internet_msg)
|
|
|
|
.setNegativeButton(R.string.ok, (d, w) -> finish())
|
|
|
|
.show();
|
|
|
|
}
|
2018-12-12 05:51:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class JSONLoader implements ResponseListener<JSONObject> {
|
2018-12-02 04:47:57 -05:00
|
|
|
|
2018-12-12 05:51:45 -05:00
|
|
|
@Override
|
|
|
|
public void onResponse(JSONObject json) {
|
|
|
|
try {
|
|
|
|
JSONObject manager = json.getJSONObject("app");
|
|
|
|
apkLink = manager.getString("link");
|
2019-10-12 03:57:56 -04:00
|
|
|
new AlertDialog.Builder(MainActivity.this)
|
2018-12-12 05:51:45 -05:00
|
|
|
.setCancelable(false)
|
|
|
|
.setTitle(R.string.app_name)
|
|
|
|
.setMessage(R.string.upgrade_msg)
|
|
|
|
.setPositiveButton(R.string.yes, (d, w) -> dlAPK())
|
|
|
|
.setNegativeButton(R.string.no_thanks, (d, w) -> finish())
|
|
|
|
.show();
|
|
|
|
} catch (JSONException e) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
2018-12-02 04:47:57 -05:00
|
|
|
}
|
|
|
|
}
|