diff --git a/app/build.gradle b/app/build.gradle
index 329e31bb1..054ffa779 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -25,7 +25,6 @@ dependencies {
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
- compile 'com.github.javiersantos:AppUpdater:2.3'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
diff --git a/app/magisk_update.json b/app/magisk_update.json
new file mode 100644
index 000000000..117353449
--- /dev/null
+++ b/app/magisk_update.json
@@ -0,0 +1,12 @@
+{
+ "app": {
+ "versionCode": "4",
+ "link": "http://forum.xda-developers.com/devdb/project/dl/?id=19924&task=get",
+ "changelog": "Version 2.0!"
+ },
+ "magisk": {
+ "versionCode": "6",
+ "link": "http://forum.xda-developers.com/devdb/project/dl/?id=19960&task=get",
+ "changelog": "Version 6!"
+ }
+}
\ No newline at end of file
diff --git a/app/magisk_update.xml b/app/magisk_update.xml
deleted file mode 100644
index 1f5881a12..000000000
--- a/app/magisk_update.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
- 2.0
-
- http://forum.xda-developers.com/android/software/mod-magisk-v1-universal-systemless-t3432382
-
-
- - Version 4.0!
-
-
-
\ No newline at end of file
diff --git a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
index 2196d6262..5b9092b06 100644
--- a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
+++ b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
@@ -1,6 +1,11 @@
package com.topjohnwu.magisk;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -12,13 +17,29 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
+import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
+import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
+import android.widget.Toast;
-import com.github.javiersantos.appupdater.AppUpdater;
-import com.github.javiersantos.appupdater.enums.UpdateFrom;
+import com.topjohnwu.magisk.utils.Shell;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -26,7 +47,7 @@ import butterknife.ButterKnife;
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
- private static final String XML_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/master/app/magisk_update.xml";
private final Handler mDrawerHandler = new Handler();
@BindView(R.id.toolbar) Toolbar toolbar;
@@ -84,7 +105,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
navigationView.setNavigationItemSelectedListener(this);
- new AppUpdater(this).setUpdateFrom(UpdateFrom.XML).setUpdateXML(XML_UPDATE_CHECK).start();
}
@Override
@@ -153,4 +173,163 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
}
}
}
+
+ private class CheckUpdates extends AsyncTask {
+
+ @Override
+ protected String doInBackground(Void... voids) {
+ try {
+ HttpURLConnection c = (HttpURLConnection) new URL(JSON_UPDATE_CHECK).openConnection();
+ c.setRequestMethod("GET");
+ c.setInstanceFollowRedirects(false);
+ c.setDoOutput(false);
+ c.connect();
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
+ StringBuilder sb = new StringBuilder();
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ br.close();
+ return sb.toString();
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(String result) {
+ super.onPostExecute(result);
+
+ if (result == null) return;
+
+ try {
+ JSONObject json = new JSONObject(result);
+
+ JSONObject app = json.getJSONObject("app");
+ JSONObject magisk = json.getJSONObject("magisk");
+
+ String appVersionCode = app.getString("versionCode");
+ String appLink = app.getString("link");
+ String appChangelog = app.getString("changelog");
+
+ String magiskVersionCode = magisk.getString("versionCode");
+ String magiskLink = magisk.getString("link");
+ String magiskChangelog = magisk.getString("changelog");
+
+ if (Integer.parseInt(appVersionCode) > BuildConfig.VERSION_CODE) {
+ showUpdateDialog(true, appVersionCode, appLink, appChangelog);
+ }
+
+ String version = Shell.sh("getprop magisk.version").get(0);
+ int versionInt = TextUtils.isEmpty(version) ? 0 : Integer.parseInt(version);
+
+ if (Integer.parseInt(magiskVersionCode) > versionInt) {
+ showUpdateDialog(false, magiskVersionCode, magiskLink, magiskChangelog);
+ }
+
+ } catch (JSONException ignored) {
+ }
+ }
+
+ private boolean isUpdateIgnored(String version) {
+ SharedPreferences prefs = getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE);
+ return prefs.getBoolean("update_ignored_" + version, false);
+ }
+
+ private void setUpdateIgnored(String version) {
+ SharedPreferences prefs = getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE);
+ prefs.edit().putBoolean("update_ignored_" + version, true).apply();
+ }
+
+ private void showUpdateDialog(final boolean app, final String versionCode, final String link, String changelog) {
+ if (isUpdateIgnored(versionCode)) return;
+
+ String text = app ? getString(R.string.app_name) : getString(R.string.magisk);
+ String msg = getString(R.string.update_available_message, text, versionCode, changelog);
+
+ new AlertDialog.Builder(getApplicationContext())
+ .setTitle(R.string.update_available)
+ .setMessage(msg)
+ .setCancelable(false)
+ .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ new DownloadFile(link, app);
+ }
+ })
+ .setNegativeButton(R.string.no_thanks, null)
+ .setNeutralButton(R.string.never_show_again, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ setUpdateIgnored(versionCode);
+ }
+ })
+ .show();
+
+ }
+ }
+
+ private class DownloadFile extends AsyncTask {
+
+ private final String link;
+ private final File downloadFile;
+ private final ProgressDialog progress;
+
+ public DownloadFile(String link, boolean apk) {
+ this.link = link;
+
+ if (apk) {
+ downloadFile = new File(getFilesDir() + "/MagiskManager.apk");
+ } else {
+ downloadFile = new File(getFilesDir() + "/Magisk.zip");
+ }
+
+ progress = ProgressDialog.show(getApplicationContext(), null, getString(R.string.loading), true, false);
+ }
+
+ @Override
+ protected Boolean doInBackground(Void... voids) {
+ try {
+ URL u = new URL(link);
+ URLConnection conn = u.openConnection();
+ int contentLength = conn.getContentLength();
+
+ DataInputStream stream = new DataInputStream(u.openStream());
+
+ byte[] buffer = new byte[contentLength];
+ stream.readFully(buffer);
+ stream.close();
+
+ DataOutputStream fos = new DataOutputStream(new FileOutputStream(downloadFile));
+ fos.write(buffer);
+ fos.flush();
+ fos.close();
+ return true;
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ super.onPostExecute(result);
+ progress.dismiss();
+ if (!result) {
+ Toast.makeText(getApplicationContext(), R.string.error_download_file, Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ if (downloadFile.getPath().contains("apk")) {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(Uri.fromFile(downloadFile), "application/vnd.android.package-archive");
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ } else {
+ Toast.makeText(getApplicationContext(), R.string.flash_recovery, Toast.LENGTH_LONG).show();
+ }
+
+ }
+ }
}
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index 952db7b72..1a5252c7c 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -43,8 +43,12 @@
SD card non trovata o non scrivibile
SELinux è forzato
SELinux è permissivo\nSpegni SELinux solamente se necessario!
- Samsung non supporta la modifica dello stato di SELinux
+ Samsung non supporta la modifica dello stato di SELinux
SeLinux Toggle
Thread di supporto
dvdandroid
+ Hai installato Magisk?
+ Errore root
+ Stato Safety Net sconosciuto
+ Stato SELinux sconosciuto
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index bf10b08c2..5718ead00 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -57,5 +57,12 @@
Refresh
No modules found
Loading…
+ Update available!
+ Update
+ A new update of %1$s is available.\nChangelog version %2$s: \n%3$s
+ No, thanks
+ Don\'t show again
+ Error downloading file
+ File downloaded, you can flash it in recovery