Commit cb5187fd authored by topjohnwu's avatar topjohnwu

Finish repo download and flash

parent 160c6e65
...@@ -137,13 +137,14 @@ public class MagiskFragment extends Fragment { ...@@ -137,13 +137,14 @@ public class MagiskFragment extends Fragment {
.setCancelable(true) .setCancelable(true)
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive( .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(
getActivity(), getActivity(),
new DownloadReceiver(getString(R.string.magisk)) { new DownloadReceiver() {
@Override @Override
public void task(Uri uri) { public void task(Uri uri) {
new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
} }
}, },
Utils.magiskLink, "latest_magisk.zip")) Utils.magiskLink,
"Magisk-v" + String.valueOf(Utils.remoteMagiskVersion) + ".zip"))
.setNegativeButton(R.string.no_thanks, null) .setNegativeButton(R.string.no_thanks, null)
.show()); .show());
} else { } else {
...@@ -153,14 +154,14 @@ public class MagiskFragment extends Fragment { ...@@ -153,14 +154,14 @@ public class MagiskFragment extends Fragment {
magiskCheckUpdatesStatus.setTextColor(colorOK); magiskCheckUpdatesStatus.setTextColor(colorOK);
} }
if (Utils.remoteAppVersion > BuildConfig.VERSION_CODE) { if (Utils.remoteAppVersionCode > BuildConfig.VERSION_CODE) {
appCheckUpdatesContainer.setBackgroundColor(colorNeutral); appCheckUpdatesContainer.setBackgroundColor(colorNeutral);
appCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download); appCheckUpdatesIcon.setImageResource(R.drawable.ic_file_download);
appCheckUpdatesStatus.setText(getString(R.string.app_update_available, String.valueOf(Utils.remoteAppVersion))); appCheckUpdatesStatus.setText(getString(R.string.app_update_available, Utils.remoteAppVersion));
appCheckUpdatesStatus.setTextColor(colorNeutral); appCheckUpdatesStatus.setTextColor(colorNeutral);
appUpdateView.setOnClickListener(view -> builder appUpdateView.setOnClickListener(view -> builder
.setTitle(getString(R.string.update_title, getString(R.string.app_name))) .setTitle(getString(R.string.update_title, getString(R.string.app_name)))
.setMessage(getString(R.string.update_msg, getString(R.string.app_name), String.valueOf(Utils.remoteAppVersion), Utils.appChangelog)) .setMessage(getString(R.string.update_msg, getString(R.string.app_name), Utils.remoteAppVersion, Utils.appChangelog))
.setCancelable(true) .setCancelable(true)
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(getActivity(), .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(getActivity(),
new DownloadReceiver() { new DownloadReceiver() {
...@@ -168,11 +169,13 @@ public class MagiskFragment extends Fragment { ...@@ -168,11 +169,13 @@ public class MagiskFragment extends Fragment {
public void task(Uri uri) { public void task(Uri uri) {
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.setData(uri); Uri content = FileProvider.getUriForFile(getActivity(), "com.topjohnwu.magisk.provider", new File(uri.getPath()));
install.setData(content);
mContext.startActivity(install); mContext.startActivity(install);
} }
}, },
Utils.appLink, "latest_manager.apk")) Utils.appLink,
"MagiskManager-v" + Utils.remoteAppVersion + ".apk"))
.setNegativeButton(R.string.no_thanks, null) .setNegativeButton(R.string.no_thanks, null)
.show() .show()
); );
......
...@@ -72,7 +72,7 @@ public class SplashActivity extends AppCompatActivity { ...@@ -72,7 +72,7 @@ public class SplashActivity extends AppCompatActivity {
new Async.CheckUpdates(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); new Async.CheckUpdates(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.LoadModules(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new Async.LoadModules(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Async.LoadRepos(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); new Async.LoadRepos(this).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
new Async.BusyboxEnv(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new Async.constructEnv(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// Start main activity // Start main activity
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
......
...@@ -17,8 +17,7 @@ public abstract class DownloadReceiver extends BroadcastReceiver { ...@@ -17,8 +17,7 @@ public abstract class DownloadReceiver extends BroadcastReceiver {
long downloadID; long downloadID;
public String mName; public String mName;
public DownloadReceiver() { public DownloadReceiver() {}
}
public DownloadReceiver(String name) { public DownloadReceiver(String name) {
mName = name; mName = name;
......
...@@ -49,8 +49,8 @@ import javax.crypto.spec.DESKeySpec; ...@@ -49,8 +49,8 @@ import javax.crypto.spec.DESKeySpec;
public class Utils { public class Utils {
public static int magiskVersion, remoteMagiskVersion = -1, remoteAppVersion = -1; public static int magiskVersion, remoteMagiskVersion = -1, remoteAppVersionCode = -1;
public static String magiskLink, magiskChangelog, appChangelog, appLink, phhLink, supersuLink; public static String magiskLink, magiskChangelog, appLink, appChangelog, remoteAppVersion;
private static final String TAG = "Magisk"; private static final String TAG = "Magisk";
public static final String MAGISK_PATH = "/magisk"; public static final String MAGISK_PATH = "/magisk";
...@@ -99,27 +99,12 @@ public class Utils { ...@@ -99,27 +99,12 @@ public class Utils {
public static boolean createFile(String path) { public static boolean createFile(String path) {
String command = "touch " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo true; else echo false; fi"; String command = "touch " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo true; else echo false; fi";
if (!Shell.rootAccess()) { return Shell.rootAccess() && Boolean.parseBoolean(Shell.su(command).get(0));
return false;
} else {
return Boolean.parseBoolean(Shell.su(command).get(0));
}
} }
public static boolean removeFile(String path) { public static boolean removeFile(String path) {
boolean check;
String command = "rm -f " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo false; else echo true; fi"; String command = "rm -f " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo false; else echo true; fi";
if (!Shell.rootAccess()) { return Shell.rootAccess() && Boolean.parseBoolean(Shell.su(command).get(0));
return false;
} else {
try {
check = Boolean.parseBoolean(Shell.su(command).get(0));
return check;
} catch (NullPointerException e) {
Log.d("Magisk:", "SU error executing removeFile " + e);
return false;
}
}
} }
public static void toggleRoot(Boolean b, Context context) { public static void toggleRoot(Boolean b, Context context) {
...@@ -132,7 +117,7 @@ public class Utils { ...@@ -132,7 +117,7 @@ public class Utils {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("enable_quicktile", false)) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("enable_quicktile", false)) {
SetupQuickSettingsTile(context); SetupQuickSettingsTile(context);
} }
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("root",b).apply(); PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("root", b).apply();
} }
} }
...@@ -183,29 +168,20 @@ public class Utils { ...@@ -183,29 +168,20 @@ public class Utils {
return ret; return ret;
} }
public static void downloadAndReceive(Context context, DownloadReceiver receiver, String link, String file) { public static void downloadAndReceive(Context context, DownloadReceiver receiver, String link, String filename) {
File file = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
return; return;
} }
File downloadFile, dir = new File(Environment.getExternalStorageDirectory() + "/MagiskManager");
downloadFile = new File(dir + "/" + file); if ((!file.getParentFile().exists() && !file.getParentFile().mkdirs()) || (file.exists() && !file.delete())) {
if (!dir.exists()) { Toast.makeText(context, R.string.toast_error_makedir, Toast.LENGTH_LONG).show();
if (!dir.mkdirs()) {
Toast.makeText(context, R.string.toast_error_makedir, Toast.LENGTH_LONG).show();
return;
}
}
if (downloadFile.exists()) {
if (!downloadFile.delete()) {
Toast.makeText(context, R.string.toast_error_removing_files, Toast.LENGTH_LONG).show();
return;
}
} }
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(link)); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(link));
request.setDestinationUri(Uri.fromFile(downloadFile)); request.setDestinationUri(Uri.fromFile(file));
receiver.setDownloadID(downloadManager.enqueue(request)); receiver.setDownloadID(downloadManager.enqueue(request));
context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:card_view="http://schemas.android.com/apk/res-auto"
style="?attr/cardStyle" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" style="?attr/cardStyle"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_gravity="center" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_vertical_margin" android:layout_gravity="center"
android:layout_marginEnd="@dimen/card_horizontal_margin" android:layout_marginBottom="@dimen/card_vertical_margin"
android:layout_marginStart="@dimen/card_horizontal_margin" android:layout_marginEnd="@dimen/card_horizontal_margin"
android:layout_marginTop="@dimen/card_vertical_margin" android:layout_marginStart="@dimen/card_horizontal_margin"
android:minHeight="?android:attr/listPreferredItemHeight" android:layout_marginTop="@dimen/card_vertical_margin"
card_view:cardCornerRadius="@dimen/card_corner_radius" android:minHeight="?android:attr/listPreferredItemHeight"
card_view:cardElevation="@dimen/card_elevation"> card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardElevation="@dimen/card_elevation">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_gravity="center" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_vertical_margin" android:layout_gravity="center"
android:layout_marginEnd="@dimen/card_horizontal_margin" android:layout_marginBottom="@dimen/card_vertical_margin"
android:layout_marginStart="@dimen/card_horizontal_margin" android:layout_marginEnd="@dimen/card_horizontal_margin"
android:layout_marginTop="@dimen/card_vertical_margin" android:layout_marginStart="@dimen/card_horizontal_margin"
android:minHeight="?android:attr/listPreferredItemHeight" android:layout_marginTop="@dimen/card_vertical_margin"
style="?attr/cardStyle" android:minHeight="?android:attr/listPreferredItemHeight"
card_view:cardCornerRadius="@dimen/card_corner_radius" style="?attr/cardStyle"
card_view:cardElevation="@dimen/card_elevation"> card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardElevation="@dimen/card_elevation">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical">
>
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
...@@ -40,15 +39,38 @@ ...@@ -40,15 +39,38 @@
<TextView <TextView
android:id="@+id/version_name" android:id="@+id/version_name"
android:layout_width="wrap_content" android:layout_width="@dimen/card_textview_width"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_below="@id/title" android:layout_below="@id/title"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/no_info_provided"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/author"
android:layout_width="@dimen/card_textview_width"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/version_name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/no_info_provided"
android:textColor="@android:color/tertiary_text_dark" android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false" android:textIsSelectable="false"
android:textStyle="bold|italic" android:textStyle="bold|italic"/>
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/author"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/no_info_provided"
android:textIsSelectable="false" />
<ImageView <ImageView
android:id="@+id/update" android:id="@+id/update"
...@@ -60,19 +82,7 @@ ...@@ -60,19 +82,7 @@
android:background="@drawable/ic_file_download_black" android:background="@drawable/ic_file_download_black"
android:backgroundTint="@color/icon_grey" android:backgroundTint="@color/icon_grey"
android:focusable="false" android:focusable="false"
android:gravity="end" android:gravity="end" />
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/update"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"
/>
<LinearLayout <LinearLayout
...@@ -82,18 +92,7 @@ ...@@ -82,18 +92,7 @@
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_below="@id/description" android:layout_below="@id/description"
android:minHeight="100dp" android:minHeight="100dp"
android:orientation="vertical" android:orientation="vertical">
>
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic"/>
<TextView <TextView
...@@ -146,7 +145,6 @@ ...@@ -146,7 +145,6 @@
android:background="@drawable/ic_support" android:background="@drawable/ic_support"
android:backgroundTint="@color/icon_grey"/> android:backgroundTint="@color/icon_grey"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
...@@ -162,8 +160,7 @@ ...@@ -162,8 +160,7 @@
android:layout_marginStart="@dimen/card_imageview_margin" android:layout_marginStart="@dimen/card_imageview_margin"
android:focusable="false" android:focusable="false"
android:gravity="end" android:gravity="end"
android:visibility="gone" android:visibility="gone" />
/>
</RelativeLayout> </RelativeLayout>
......
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
<string name="download_file_error">Error downloading file</string> <string name="download_file_error">Error downloading file</string>
<string name="install_error">Installation error!</string> <string name="install_error">Installation error!</string>
<string name="manual_install">Error in flashing file, zip file placed in %1$s\nFlash it in recovery manually</string> <string name="manual_install">Error in flashing file, zip file placed in %1$s\nFlash it in recovery manually</string>
<string name="invalid_zip">The zip is not a Magisk Module!!</string>
<string name="reboot_title">Installation succeeded!</string> <string name="reboot_title">Installation succeeded!</string>
<string name="reboot_msg">Do you want to reboot now?</string> <string name="reboot_msg">Do you want to reboot now?</string>
<string name="reboot">Reboot</string> <string name="reboot">Reboot</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment