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;
|
|
|
|
|
|
|
|
import com.topjohnwu.magisk.utils.APKInstall;
|
|
|
|
import com.topjohnwu.magisk.utils.Download;
|
2018-12-12 05:51:45 -05:00
|
|
|
import com.topjohnwu.net.Networking;
|
|
|
|
import com.topjohnwu.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 {
|
|
|
|
|
|
|
|
private static final String URL =
|
|
|
|
"https://raw.githubusercontent.com/topjohnwu/magisk_files/master/stable.json";
|
|
|
|
|
|
|
|
private String apkLink;
|
|
|
|
|
|
|
|
private void dlAPK() {
|
|
|
|
Application app = getApplication();
|
2018-12-12 05:51:45 -05:00
|
|
|
Networking.get(apkLink)
|
|
|
|
.getAsFile(apk -> APKInstall.install(app, apk), new File(getFilesDir(), "manager.apk"));
|
2018-12-02 04:47:57 -05:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
if (Download.checkNetworkStatus(this)) {
|
2018-12-12 05:51:45 -05:00
|
|
|
Networking.get(URL)
|
|
|
|
.setErrorHandler(((conn, e) -> finish()))
|
|
|
|
.getAsJSONObject(new JSONLoader());
|
2018-12-02 04:47:57 -05:00
|
|
|
} else {
|
|
|
|
new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
|
|
|
|
.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");
|
|
|
|
new AlertDialog.Builder(MainActivity.this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
|
|
|
|
.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
|
|
|
}
|
|
|
|
}
|