diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index f2bb203cb..274cbacc2 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -71,6 +71,11 @@ + + + + + = 1300 - && prefs.getBoolean(Const.Key.MAGISKHIDE, false)); + && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)); menu.findItem(R.id.modules).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) && Shell.rootAccess() && mm.magiskVersionCode >= 0); menu.findItem(R.id.downloads).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) diff --git a/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/src/main/java/com/topjohnwu/magisk/SplashActivity.java index fa5fb0555..43e54b61e 100644 --- a/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -11,6 +11,7 @@ import com.topjohnwu.magisk.asyncs.LoadModules; import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.components.Activity; +import com.topjohnwu.magisk.receivers.ShortcutReceiver; import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; @@ -37,6 +38,9 @@ public class SplashActivity extends Activity { getSystemService(NotificationManager.class).createNotificationChannel(channel); } + // Setup shortcuts + sendBroadcast(new Intent(this, ShortcutReceiver.class)); + LoadModules loadModuleTask = new LoadModules(); if (Utils.checkNetworkStatus()) { diff --git a/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java b/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java index 4745fb1ed..f9efe1777 100644 --- a/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java @@ -3,7 +3,6 @@ package com.topjohnwu.magisk.adapters; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.support.design.widget.Snackbar; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.LayoutInflater; @@ -16,7 +15,6 @@ import android.widget.TextView; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.asyncs.ParallelTask; -import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Utils; diff --git a/src/main/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java b/src/main/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java new file mode 100644 index 000000000..8dba2d7b3 --- /dev/null +++ b/src/main/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java @@ -0,0 +1,83 @@ +package com.topjohnwu.magisk.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ShortcutInfo; +import android.content.pm.ShortcutManager; +import android.graphics.drawable.Icon; +import android.os.Build; +import android.support.annotation.RequiresApi; +import android.text.TextUtils; + +import com.topjohnwu.magisk.MagiskManager; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.SplashActivity; +import com.topjohnwu.magisk.utils.Const; +import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.superuser.Shell; + +import java.util.ArrayList; + +public class ShortcutReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { + MagiskManager mm = Utils.getMagiskManager(context); + ShortcutManager manager = context.getSystemService(ShortcutManager.class); + if (TextUtils.equals(intent.getAction(), Intent.ACTION_LOCALE_CHANGED)) { + // It is triggered with locale change, manual load Magisk info + mm.loadMagiskInfo(); + } + manager.setDynamicShortcuts(getShortCuts(mm)); + } + } + + @RequiresApi(api = Build.VERSION_CODES.N_MR1) + private ArrayList getShortCuts(MagiskManager mm) { + ArrayList shortCuts = new ArrayList<>(); + if (Shell.rootAccess() && + !(Const.USER_ID > 0 && + mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { + shortCuts.add(new ShortcutInfo.Builder(mm, "superuser") + .setShortLabel(mm.getString(R.string.superuser)) + .setIntent(new Intent(mm, SplashActivity.class) + .putExtra(Const.Key.OPEN_SECTION, "superuser") + .setAction(Intent.ACTION_VIEW) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)) + .setIcon(Icon.createWithResource(mm, R.drawable.sc_superuser)) + .build()); + } + if (Shell.rootAccess() && mm.magiskVersionCode >= 1300 + && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)) { + shortCuts.add(new ShortcutInfo.Builder(mm, "magiskhide") + .setShortLabel(mm.getString(R.string.magiskhide)) + .setIntent(new Intent(mm, SplashActivity.class) + .putExtra(Const.Key.OPEN_SECTION, "magiskhide") + .setAction(Intent.ACTION_VIEW) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)) + .setIcon(Icon.createWithResource(mm, R.drawable.sc_magiskhide)) + .build()); + } + if (!mm.prefs.getBoolean(Const.Key.COREONLY, false) && + Shell.rootAccess() && mm.magiskVersionCode >= 0) { + shortCuts.add(new ShortcutInfo.Builder(mm, "modules") + .setShortLabel(mm.getString(R.string.modules)) + .setIntent(new Intent(mm, SplashActivity.class) + .putExtra(Const.Key.OPEN_SECTION, "modules") + .setAction(Intent.ACTION_VIEW) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)) + .setIcon(Icon.createWithResource(mm, R.drawable.sc_extension)) + .build()); + shortCuts.add(new ShortcutInfo.Builder(mm, "downloads") + .setShortLabel(mm.getString(R.string.download)) + .setIntent(new Intent(mm, SplashActivity.class) + .putExtra(Const.Key.OPEN_SECTION, "downloads") + .setAction(Intent.ACTION_VIEW) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)) + .setIcon(Icon.createWithResource(mm, R.drawable.sc_cloud_download)) + .build()); + } + return shortCuts; + } +} diff --git a/src/main/res/drawable-v26/sc_cloud_download.xml b/src/main/res/drawable-v26/sc_cloud_download.xml new file mode 100644 index 000000000..734f23865 --- /dev/null +++ b/src/main/res/drawable-v26/sc_cloud_download.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable-v26/sc_extension.xml b/src/main/res/drawable-v26/sc_extension.xml new file mode 100644 index 000000000..a7a98ef76 --- /dev/null +++ b/src/main/res/drawable-v26/sc_extension.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable-v26/sc_magiskhide.xml b/src/main/res/drawable-v26/sc_magiskhide.xml new file mode 100644 index 000000000..02a59ce4e --- /dev/null +++ b/src/main/res/drawable-v26/sc_magiskhide.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable-v26/sc_superuser.xml b/src/main/res/drawable-v26/sc_superuser.xml new file mode 100644 index 000000000..505088495 --- /dev/null +++ b/src/main/res/drawable-v26/sc_superuser.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/ic_autoroot.xml b/src/main/res/drawable/ic_autoroot.xml deleted file mode 100644 index a8f96a803..000000000 --- a/src/main/res/drawable/ic_autoroot.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/src/main/res/drawable/ic_cloud_download.xml b/src/main/res/drawable/ic_cloud_download.xml index 261c31217..4aaf5ebc1 100644 --- a/src/main/res/drawable/ic_cloud_download.xml +++ b/src/main/res/drawable/ic_cloud_download.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/src/main/res/drawable/ic_extension.xml b/src/main/res/drawable/ic_extension.xml index 80d25de23..549fdce23 100644 --- a/src/main/res/drawable/ic_extension.xml +++ b/src/main/res/drawable/ic_extension.xml @@ -4,6 +4,6 @@ android:viewportHeight="24.0" android:viewportWidth="24.0"> diff --git a/src/main/res/drawable/ic_magiskhide.xml b/src/main/res/drawable/ic_magiskhide.xml new file mode 100644 index 000000000..6a3ce181d --- /dev/null +++ b/src/main/res/drawable/ic_magiskhide.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/main/res/drawable/ic_superuser.xml b/src/main/res/drawable/ic_superuser.xml index c7a3bc010..01fb6a803 100644 --- a/src/main/res/drawable/ic_superuser.xml +++ b/src/main/res/drawable/ic_superuser.xml @@ -3,5 +3,7 @@ android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"> - + \ No newline at end of file diff --git a/src/main/res/drawable/sc_cloud_download.xml b/src/main/res/drawable/sc_cloud_download.xml new file mode 100644 index 000000000..1a7dae048 --- /dev/null +++ b/src/main/res/drawable/sc_cloud_download.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/sc_extension.xml b/src/main/res/drawable/sc_extension.xml new file mode 100644 index 000000000..21e823a39 --- /dev/null +++ b/src/main/res/drawable/sc_extension.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/sc_magiskhide.xml b/src/main/res/drawable/sc_magiskhide.xml new file mode 100644 index 000000000..b388a2f3f --- /dev/null +++ b/src/main/res/drawable/sc_magiskhide.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/sc_superuser.xml b/src/main/res/drawable/sc_superuser.xml new file mode 100644 index 000000000..0e6c58937 --- /dev/null +++ b/src/main/res/drawable/sc_superuser.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/menu/drawer.xml b/src/main/res/menu/drawer.xml index 847612d5a..654f0937c 100644 --- a/src/main/res/menu/drawer.xml +++ b/src/main/res/menu/drawer.xml @@ -17,7 +17,7 @@ android:visible="false"/>