Improve notification support

This commit is contained in:
topjohnwu 2017-07-20 01:44:32 +08:00
parent c11a3dc95c
commit 668d85d14e
6 changed files with 63 additions and 42 deletions

View File

@ -2,7 +2,9 @@ package com.topjohnwu.magisk;
import android.animation.Animator; import android.animation.Animator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.app.NotificationManager;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -49,7 +51,8 @@ import butterknife.Unbinder;
public class MagiskFragment extends Fragment public class MagiskFragment extends Fragment
implements CallbackEvent.Listener<Void>, SwipeRefreshLayout.OnRefreshListener { implements CallbackEvent.Listener<Void>, SwipeRefreshLayout.OnRefreshListener {
private static boolean noDialog = false; public static final String SHOW_DIALOG = "dialog";
private static int expandHeight = 0; private static int expandHeight = 0;
private static boolean mExpanded = false; private static boolean mExpanded = false;
@ -126,7 +129,9 @@ public class MagiskFragment extends Fragment
.setMessage(getString(R.string.repo_install_msg, filename)) .setMessage(getString(R.string.repo_install_msg, filename))
.setCancelable(true) .setCancelable(true)
.setPositiveButton(Shell.rootAccess() ? R.string.install : R.string.download, .setPositiveButton(Shell.rootAccess() ? R.string.install : R.string.download,
(d, i) -> (d, i) -> {
((NotificationManager) getActivity()
.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
Utils.dlAndReceive( Utils.dlAndReceive(
getActivity(), getActivity(),
new DownloadReceiver() { new DownloadReceiver() {
@ -150,7 +155,9 @@ public class MagiskFragment extends Fragment
} }
}, },
magiskManager.magiskLink, magiskManager.magiskLink,
Utils.getLegalFilename(filename))) Utils.getLegalFilename(filename));
}
)
.setNeutralButton(R.string.release_notes, (d, i) -> { .setNeutralButton(R.string.release_notes, (d, i) -> {
if (magiskManager.releaseNoteLink != null) { if (magiskManager.releaseNoteLink != null) {
Intent openReleaseNoteLink = new Intent(Intent.ACTION_VIEW, Uri.parse(magiskManager.releaseNoteLink)); Intent openReleaseNoteLink = new Intent(Intent.ACTION_VIEW, Uri.parse(magiskManager.releaseNoteLink));
@ -241,19 +248,11 @@ public class MagiskFragment extends Fragment
mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setOnRefreshListener(this);
if (magiskManager.magiskVersionCode < 0 && Shell.rootAccess() && !noDialog) {
noDialog = true;
new AlertDialogBuilder(getActivity())
.setTitle(R.string.no_magisk_title)
.setMessage(R.string.no_magisk_msg)
.setCancelable(true)
.setPositiveButton(R.string.goto_install, (d, i) -> {})
.setNegativeButton(R.string.no_thanks, null)
.show();
}
updateUI(); updateUI();
if (getArguments() != null && getArguments().getBoolean(SHOW_DIALOG))
install();
return v; return v;
} }
@ -272,7 +271,6 @@ public class MagiskFragment extends Fragment
magiskManager.remoteMagiskVersionString = null; magiskManager.remoteMagiskVersionString = null;
magiskManager.remoteMagiskVersionCode = -1; magiskManager.remoteMagiskVersionCode = -1;
collapse(); collapse();
noDialog = false;
// Trigger state check // Trigger state check
if (Utils.checkNetworkStatus(magiskManager)) { if (Utils.checkNetworkStatus(magiskManager)) {
@ -410,6 +408,9 @@ public class MagiskFragment extends Fragment
magiskUpdateProgress.setVisibility(View.GONE); magiskUpdateProgress.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
if (magiskManager.remoteMagiskVersionCode > magiskManager.magiskVersionCode)
install();
} }
private void updateSafetyNetUI() { private void updateSafetyNetUI() {

View File

@ -32,6 +32,8 @@ public class MagiskManager extends Application {
public static final String UNINSTALLER = "magisk_uninstaller.sh"; public static final String UNINSTALLER = "magisk_uninstaller.sh";
public static final String UTIL_FUNCTIONS= "util_functions.sh"; public static final String UTIL_FUNCTIONS= "util_functions.sh";
public static final String INTENT_SECTION = "section"; public static final String INTENT_SECTION = "section";
public static final String INTENT_VERSION = "version";
public static final String INTENT_LINK = "link";
public static final String BUSYBOX_VERSION = "1.26.2"; public static final String BUSYBOX_VERSION = "1.26.2";
public static final String MAGISKHIDE_PROP = "persist.magisk.hide"; public static final String MAGISKHIDE_PROP = "persist.magisk.hide";
public static final String DISABLE_INDICATION_PROP = "ro.magisk.disable"; public static final String DISABLE_INDICATION_PROP = "ro.magisk.disable";

View File

@ -140,9 +140,11 @@ public class MainActivity extends Activity
if (item != null) { if (item != null) {
switch (item) { switch (item) {
case "magisk": case "magisk":
case "install":
itemId = R.id.magisk; itemId = R.id.magisk;
break; break;
case "install":
itemId = -1;
break;
case "superuser": case "superuser":
itemId = R.id.superuser; itemId = R.id.superuser;
break; break;
@ -174,6 +176,13 @@ public class MainActivity extends Activity
mDrawerItem = itemId; mDrawerItem = itemId;
navigationView.setCheckedItem(itemId); navigationView.setCheckedItem(itemId);
switch (itemId) { switch (itemId) {
case -1:
Bundle args = new Bundle();
args.putBoolean(MagiskFragment.SHOW_DIALOG, true);
Fragment frag = new MagiskFragment();
frag.setArguments(args);
displayFragment(frag, "magisk", true);
break;
case R.id.magisk: case R.id.magisk:
displayFragment(new MagiskFragment(), "magisk", true); displayFragment(new MagiskFragment(), "magisk", true);
break; break;

View File

@ -24,8 +24,14 @@ public class SplashActivity extends Activity{
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
MagiskManager magiskManager = getApplicationContext();
// Init the info and configs and root sh // Init the info and configs and root sh
getApplicationContext().init(); magiskManager.init();
// Get possible additional info from intent
magiskManager.remoteMagiskVersionString = getIntent().getStringExtra(MagiskManager.INTENT_VERSION);
magiskManager.magiskLink = getIntent().getStringExtra(MagiskManager.INTENT_LINK);
// Now fire all async tasks // Now fire all async tasks
new LoadModules(this) new LoadModules(this)

View File

@ -7,6 +7,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File; import java.io.File;
@ -34,8 +35,8 @@ public class ManagerUpdate extends BroadcastReceiver {
} }
} }
}, },
intent.getStringExtra("link"), intent.getStringExtra(MagiskManager.INTENT_LINK),
Utils.getLegalFilename("MagiskManager-v" + Utils.getLegalFilename("MagiskManager-v" +
intent.getStringExtra("version") + ".apk")); intent.getStringExtra(MagiskManager.INTENT_VERSION) + ".apk"));
} }
} }

View File

@ -196,6 +196,8 @@ public class Utils {
.setAutoCancel(true); .setAutoCancel(true);
Intent intent = new Intent(magiskManager, SplashActivity.class); Intent intent = new Intent(magiskManager, SplashActivity.class);
intent.putExtra(MagiskManager.INTENT_SECTION, "install"); intent.putExtra(MagiskManager.INTENT_SECTION, "install");
intent.putExtra(MagiskManager.INTENT_VERSION, magiskManager.remoteMagiskVersionString);
intent.putExtra(MagiskManager.INTENT_LINK, magiskManager.magiskLink);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(magiskManager); TaskStackBuilder stackBuilder = TaskStackBuilder.create(magiskManager);
stackBuilder.addParentStack(SplashActivity.class); stackBuilder.addParentStack(SplashActivity.class);
stackBuilder.addNextIntent(intent); stackBuilder.addNextIntent(intent);
@ -216,8 +218,8 @@ public class Utils {
.setVibrate(new long[]{0, 100, 100, 100}) .setVibrate(new long[]{0, 100, 100, 100})
.setAutoCancel(true); .setAutoCancel(true);
Intent intent = new Intent(magiskManager, ManagerUpdate.class); Intent intent = new Intent(magiskManager, ManagerUpdate.class);
intent.putExtra("link", magiskManager.managerLink); intent.putExtra(MagiskManager.INTENT_LINK, magiskManager.managerLink);
intent.putExtra("version", magiskManager.remoteManagerVersionString); intent.putExtra(MagiskManager.INTENT_VERSION, magiskManager.remoteManagerVersionString);
PendingIntent pendingIntent = PendingIntent.getBroadcast(magiskManager, PendingIntent pendingIntent = PendingIntent.getBroadcast(magiskManager,
APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent); builder.setContentIntent(pendingIntent);