mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-04 23:07:38 +00:00
[WIP] Update checker
TODO: change download file path to internal storage
This commit is contained in:
parent
ef13b3a36c
commit
dabb222511
@ -9,7 +9,7 @@ android {
|
|||||||
applicationId "com.topjohnwu.magisk"
|
applicationId "com.topjohnwu.magisk"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 24
|
targetSdkVersion 24
|
||||||
versionCode 4
|
versionCode 3
|
||||||
versionName "2.0"
|
versionName "2.0"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
@ -14,11 +14,9 @@ import android.widget.Switch;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import butterknife.BindColor;
|
import butterknife.BindColor;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@ -56,7 +54,7 @@ public class MagiskFragment extends Fragment {
|
|||||||
@BindColor(R.color.red500) int red500;
|
@BindColor(R.color.red500) int red500;
|
||||||
@BindColor(R.color.green500) int green500;
|
@BindColor(R.color.green500) int green500;
|
||||||
@BindColor(R.color.grey500) int grey500;
|
@BindColor(R.color.grey500) int grey500;
|
||||||
@BindColor(R.color.lime500) int lime500;
|
@BindColor(R.color.accent) int accent;
|
||||||
|
|
||||||
int statusOK = R.drawable.ic_check_circle;
|
int statusOK = R.drawable.ic_check_circle;
|
||||||
int statusError = R.drawable.ic_error;
|
int statusError = R.drawable.ic_error;
|
||||||
@ -184,9 +182,9 @@ public class MagiskFragment extends Fragment {
|
|||||||
// Proper root
|
// Proper root
|
||||||
if (new File("/system/xbin/su").exists()) {
|
if (new File("/system/xbin/su").exists()) {
|
||||||
// Mounted
|
// Mounted
|
||||||
rootStatusContainer.setBackgroundColor(lime500);
|
rootStatusContainer.setBackgroundColor(accent);
|
||||||
rootStatusIcon.setImageResource(statusError);
|
rootStatusIcon.setImageResource(statusError);
|
||||||
rootStatus.setTextColor(lime500);
|
rootStatus.setTextColor(accent);
|
||||||
rootStatus.setText(R.string.root_mounted);
|
rootStatus.setText(R.string.root_mounted);
|
||||||
rootToggle.setChecked(true);
|
rootToggle.setChecked(true);
|
||||||
safetyNetStatusIcon.setImageResource(statusError);
|
safetyNetStatusIcon.setImageResource(statusError);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@ -20,6 +21,7 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
|||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.text.Html;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -30,16 +32,18 @@ import com.topjohnwu.magisk.utils.Shell;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -47,7 +51,8 @@ import butterknife.ButterKnife;
|
|||||||
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
||||||
private static final String JSON_UPDATE_CHECK = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/master/app/magisk_update.xml";
|
private static final String JSON_UPDATE_CHECK = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updater/app/magisk_update.json";
|
||||||
|
|
||||||
private final Handler mDrawerHandler = new Handler();
|
private final Handler mDrawerHandler = new Handler();
|
||||||
|
|
||||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||||
@ -105,6 +110,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
|
|
||||||
navigationView.setNavigationItemSelectedListener(this);
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
|
|
||||||
|
new CheckUpdates(this).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -176,6 +182,12 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
|
|
||||||
private class CheckUpdates extends AsyncTask<Void, Void, String> {
|
private class CheckUpdates extends AsyncTask<Void, Void, String> {
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
public CheckUpdates(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Void... voids) {
|
protected String doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
@ -222,7 +234,10 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
showUpdateDialog(true, appVersionCode, appLink, appChangelog);
|
showUpdateDialog(true, appVersionCode, appLink, appChangelog);
|
||||||
}
|
}
|
||||||
|
|
||||||
String version = Shell.sh("getprop magisk.version").get(0);
|
List<String> versionSh = Shell.sh("getprop magisk.version");
|
||||||
|
|
||||||
|
String version = versionSh.isEmpty() ? "" : versionSh.get(0);
|
||||||
|
|
||||||
int versionInt = TextUtils.isEmpty(version) ? 0 : Integer.parseInt(version);
|
int versionInt = TextUtils.isEmpty(version) ? 0 : Integer.parseInt(version);
|
||||||
|
|
||||||
if (Integer.parseInt(magiskVersionCode) > versionInt) {
|
if (Integer.parseInt(magiskVersionCode) > versionInt) {
|
||||||
@ -249,14 +264,14 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
String text = app ? getString(R.string.app_name) : getString(R.string.magisk);
|
String text = app ? getString(R.string.app_name) : getString(R.string.magisk);
|
||||||
String msg = getString(R.string.update_available_message, text, versionCode, changelog);
|
String msg = getString(R.string.update_available_message, text, versionCode, changelog);
|
||||||
|
|
||||||
new AlertDialog.Builder(getApplicationContext())
|
new AlertDialog.Builder(context)
|
||||||
.setTitle(R.string.update_available)
|
.setTitle(R.string.update_available)
|
||||||
.setMessage(msg)
|
.setMessage(Html.fromHtml(msg))
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
new DownloadFile(link, app);
|
new DownloadFile(context, link, app);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.no_thanks, null)
|
.setNegativeButton(R.string.no_thanks, null)
|
||||||
@ -267,18 +282,19 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DownloadFile extends AsyncTask<Void, Integer, Boolean> {
|
private class DownloadFile extends AsyncTask<Void, Integer, Boolean> {
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
private final String link;
|
private final String link;
|
||||||
private final File downloadFile;
|
private final File downloadFile;
|
||||||
private final ProgressDialog progress;
|
private final ProgressDialog progress;
|
||||||
|
|
||||||
public DownloadFile(String link, boolean apk) {
|
public DownloadFile(Context context, String link, boolean apk) {
|
||||||
this.link = link;
|
this.link = link;
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
if (apk) {
|
if (apk) {
|
||||||
downloadFile = new File(getFilesDir() + "/MagiskManager.apk");
|
downloadFile = new File(getFilesDir() + "/MagiskManager.apk");
|
||||||
@ -286,7 +302,9 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
downloadFile = new File(getFilesDir() + "/Magisk.zip");
|
downloadFile = new File(getFilesDir() + "/Magisk.zip");
|
||||||
}
|
}
|
||||||
|
|
||||||
progress = ProgressDialog.show(getApplicationContext(), null, getString(R.string.loading), true, false);
|
Toast.makeText(context, downloadFile.getPath(), Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
progress = ProgressDialog.show(context, null, getString(R.string.loading), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -294,30 +312,48 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
try {
|
try {
|
||||||
URL u = new URL(link);
|
URL u = new URL(link);
|
||||||
URLConnection conn = u.openConnection();
|
URLConnection conn = u.openConnection();
|
||||||
int contentLength = conn.getContentLength();
|
conn.connect();
|
||||||
|
|
||||||
DataInputStream stream = new DataInputStream(u.openStream());
|
int length = conn.getContentLength();
|
||||||
|
|
||||||
byte[] buffer = new byte[contentLength];
|
InputStream input = new BufferedInputStream(u.openStream(), 8192);
|
||||||
stream.readFully(buffer);
|
OutputStream output = new FileOutputStream(downloadFile);
|
||||||
stream.close();
|
|
||||||
|
byte data[] = new byte[1024];
|
||||||
|
long total = 0;
|
||||||
|
|
||||||
|
int count;
|
||||||
|
while ((count = input.read(data)) != -1) {
|
||||||
|
total += count;
|
||||||
|
output.write(data, 0, count);
|
||||||
|
|
||||||
|
publishProgress((int) ((total * 100) / length));
|
||||||
|
}
|
||||||
|
|
||||||
|
output.flush();
|
||||||
|
|
||||||
|
output.close();
|
||||||
|
input.close();
|
||||||
|
|
||||||
DataOutputStream fos = new DataOutputStream(new FileOutputStream(downloadFile));
|
|
||||||
fos.write(buffer);
|
|
||||||
fos.flush();
|
|
||||||
fos.close();
|
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Integer... values) {
|
||||||
|
super.onProgressUpdate(values);
|
||||||
|
|
||||||
|
progress.setMessage(getString(R.string.loading) + values[0] + "%");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Boolean result) {
|
protected void onPostExecute(Boolean result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.error_download_file, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, R.string.error_download_file, Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +363,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getApplicationContext(), R.string.flash_recovery, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, R.string.flash_recovery, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,5 @@
|
|||||||
<color name="red500">#F44336</color>
|
<color name="red500">#F44336</color>
|
||||||
<color name="green500">#4CAF50</color>
|
<color name="green500">#4CAF50</color>
|
||||||
<color name="grey500">#9E9E9E</color>
|
<color name="grey500">#9E9E9E</color>
|
||||||
<color name="lime500">#CDDC39</color>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user