2017-02-12 19:49:46 +08:00
|
|
|
package com.topjohnwu.magisk.asyncs;
|
|
|
|
|
2017-02-17 08:51:51 +08:00
|
|
|
import android.content.Context;
|
2017-02-12 19:49:46 +08:00
|
|
|
|
2017-06-07 02:19:23 +08:00
|
|
|
import com.topjohnwu.magisk.BuildConfig;
|
2017-07-19 18:01:22 +08:00
|
|
|
import com.topjohnwu.magisk.MagiskManager;
|
2017-10-15 23:54:34 +08:00
|
|
|
import com.topjohnwu.magisk.utils.ShowUI;
|
2017-02-12 19:49:46 +08:00
|
|
|
import com.topjohnwu.magisk.utils.WebService;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
|
|
|
|
2017-08-29 01:34:42 +08:00
|
|
|
public static final int STABLE_CHANNEL = 0;
|
|
|
|
public static final int BETA_CHANNEL = 1;
|
|
|
|
|
|
|
|
private static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
|
|
|
|
private static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json";
|
2017-06-07 02:19:23 +08:00
|
|
|
|
2017-02-17 08:51:51 +08:00
|
|
|
private boolean showNotification = false;
|
|
|
|
|
2017-07-19 18:01:22 +08:00
|
|
|
public CheckUpdates(Context context) {
|
|
|
|
super(context);
|
2017-02-17 08:51:51 +08:00
|
|
|
}
|
|
|
|
|
2017-07-19 18:01:22 +08:00
|
|
|
public CheckUpdates(Context context, boolean b) {
|
|
|
|
super(context);
|
|
|
|
showNotification = b;
|
2017-02-12 19:49:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... voids) {
|
2017-09-03 15:35:14 +08:00
|
|
|
MagiskManager mm = getMagiskManager();
|
|
|
|
if (mm == null) return null;
|
2017-08-29 01:34:42 +08:00
|
|
|
String jsonStr;
|
2017-09-03 15:35:14 +08:00
|
|
|
switch (mm.updateChannel) {
|
2017-08-29 01:34:42 +08:00
|
|
|
case STABLE_CHANNEL:
|
|
|
|
jsonStr = WebService.getString(STABLE_URL);
|
|
|
|
break;
|
|
|
|
case BETA_CHANNEL:
|
|
|
|
jsonStr = WebService.getString(BETA_URL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
jsonStr = null;
|
|
|
|
}
|
2017-02-12 19:49:46 +08:00
|
|
|
try {
|
|
|
|
JSONObject json = new JSONObject(jsonStr);
|
|
|
|
JSONObject magisk = json.getJSONObject("magisk");
|
2017-09-03 15:35:14 +08:00
|
|
|
mm.remoteMagiskVersionString = magisk.getString("version");
|
|
|
|
mm.remoteMagiskVersionCode = magisk.getInt("versionCode");
|
|
|
|
mm.magiskLink = magisk.getString("link");
|
|
|
|
mm.releaseNoteLink = magisk.getString("note");
|
2017-06-07 02:19:23 +08:00
|
|
|
JSONObject manager = json.getJSONObject("app");
|
2017-09-03 15:35:14 +08:00
|
|
|
mm.remoteManagerVersionString = manager.getString("version");
|
|
|
|
mm.remoteManagerVersionCode = manager.getInt("versionCode");
|
|
|
|
mm.managerLink = manager.getString("link");
|
2017-05-12 02:25:07 +08:00
|
|
|
} catch (JSONException ignored) {}
|
2017-02-12 19:49:46 +08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void v) {
|
2017-09-03 15:35:14 +08:00
|
|
|
MagiskManager mm = getMagiskManager();
|
|
|
|
if (mm == null) return;
|
|
|
|
if (showNotification && mm.updateNotification) {
|
|
|
|
if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) {
|
2017-10-15 23:54:34 +08:00
|
|
|
ShowUI.showManagerUpdateNotification(mm);
|
2017-09-03 15:35:14 +08:00
|
|
|
} else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) {
|
2017-10-15 23:54:34 +08:00
|
|
|
ShowUI.showMagiskUpdateNotification(mm);
|
2017-06-07 02:19:23 +08:00
|
|
|
}
|
2017-02-17 08:51:51 +08:00
|
|
|
}
|
2017-09-03 15:35:14 +08:00
|
|
|
mm.updateCheckDone.publish();
|
2017-06-06 03:06:23 +08:00
|
|
|
super.onPostExecute(v);
|
2017-02-12 19:49:46 +08:00
|
|
|
}
|
|
|
|
}
|