diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 941bc7281..b0ce8ab3a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,6 +6,10 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java b/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java
index 2823ead75..eefb4b93d 100644
--- a/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java
+++ b/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java
@@ -1,7 +1,6 @@
package com.topjohnwu.magisk;
import android.app.ProgressDialog;
-import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -29,7 +28,7 @@ public class AutoRootFragment extends ListFragment {
private ApplicationAdapter listadaptor = null;
public ListView listView;
public SharedPreferences prefs;
- List arrayList;
+ List arrayBlackList,arrayWhiteList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -42,11 +41,14 @@ public class AutoRootFragment extends ListFragment {
listView = getListView();
packageManager = getActivity().getPackageManager();
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
- if (!prefs.contains("autoapps")) {
+ if (!prefs.contains("auto_blacklist")) {
SharedPreferences.Editor editor = prefs.edit();
- Set set = new HashSet();
+ Set set = new HashSet<>();
set.add("com.google.android.apps.walletnfcrel");
- editor.putStringSet("autoapps", set);
+ editor.putStringSet("auto_blacklist", set);
+ set.clear();
+ set.add("com.kermidas.TitaniumBackupPro");
+ editor.putStringSet("auto_whitelist",set);
editor.apply();
}
new LoadApplications().execute();
@@ -70,28 +72,43 @@ public class AutoRootFragment extends ListFragment {
private void ToggleApp(String appToCheck, int position, View v) {
- Set set = prefs.getStringSet("autoapps", null);
+ Set blackListSet = prefs.getStringSet("auto_blacklist", null);
+ Set whiteListSet = prefs.getStringSet("auto_whitelist", null);
- arrayList = new ArrayList<>(set);
- Log.d("Magisk", "Trying to toggle for " + appToCheck + " stringset is " + arrayList.toString());
- SharedPreferences.Editor editor = prefs.edit();
+ assert blackListSet != null;
+ arrayBlackList = new ArrayList<>(blackListSet);
+ assert whiteListSet != null;
+ arrayWhiteList = new ArrayList<>(whiteListSet);
+ Log.d("Magisk", "Trying to toggle for " + appToCheck + " stringset is " + arrayBlackList.toString());
- if (arrayList.contains(appToCheck)) {
- Log.d("Magisk", "App is in array, removing");
+ if ((!arrayBlackList.contains(appToCheck)) && (!arrayWhiteList.contains(appToCheck))) {
+ Log.d("Magisk", "App is not in any array, adding to whitelist");
+ arrayWhiteList.add(appToCheck);
- for (int i = 0; i < arrayList.size(); i++) {
- if (appToCheck.equals(arrayList.get(i))) {
- arrayList.remove(i);
+
+ } else if (arrayWhiteList.contains(appToCheck)) {
+ Log.d("Magisk", "App is in whitelist, moving to blacklist");
+ for (int i = 0; i < arrayWhiteList.size(); i++) {
+ if (appToCheck.equals(arrayWhiteList.get(i))) {
+ arrayWhiteList.remove(i);
+ }
+ }
+ arrayBlackList.add(appToCheck);
+
+ } else if (arrayBlackList.contains(appToCheck)) {
+ Log.d("Magisk", "App is in Blacklist, removing");
+ for (int i = 0; i < arrayBlackList.size(); i++) {
+ if (appToCheck.equals(arrayBlackList.get(i))) {
+ arrayBlackList.remove(i);
}
}
- } else {
- arrayList.add(appToCheck);
-
}
- Set set2 = new HashSet(arrayList);
+ Set set2 = new HashSet<>(arrayBlackList);
Log.d("Magisk", "Committing set, value is: " + set2);
- editor.putStringSet("autoapps", set2);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putStringSet("auto_blacklist", new HashSet<>(arrayBlackList));
+ editor.putStringSet("auto_whitelist", new HashSet<>(arrayWhiteList));
editor.apply();
listadaptor.UpdateRootStatusView(position,v);
@@ -99,7 +116,7 @@ public class AutoRootFragment extends ListFragment {
}
private List checkForLaunchIntent(List list) {
- ArrayList applist = new ArrayList();
+ ArrayList applist = new ArrayList<>();
for (ApplicationInfo info : list) {
try {
if (null != packageManager.getLaunchIntentForPackage(info.packageName)) {
diff --git a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
index 3ecfcc69b..3c3f0c357 100644
--- a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
+++ b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
@@ -1,13 +1,9 @@
package com.topjohnwu.magisk;
-import android.app.Activity;
import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
@@ -87,7 +83,7 @@ public class ModulesFragment extends Fragment {
// Get the URI of the selected file
final Uri uri = data.getData();
Log.i("Magisk", "ModulesFragment: Uri = " + uri.toString() + " or ");
- new Utils.FlashZIP(getActivity(),uri).execute();
+ new Utils.FlashZIP(getActivity(), uri).execute();
try {
// Get the file path from the URI
FileInfo fileInfo = FileUtils.getFileInfo(getActivity(), uri);
diff --git a/app/src/main/java/com/topjohnwu/magisk/MonitorService.java b/app/src/main/java/com/topjohnwu/magisk/MonitorService.java
index 186087186..4d6fe8281 100644
--- a/app/src/main/java/com/topjohnwu/magisk/MonitorService.java
+++ b/app/src/main/java/com/topjohnwu/magisk/MonitorService.java
@@ -31,10 +31,9 @@ public class MonitorService extends Service
{
private static final String TAG = "Magisk";
- Handler handler = new Handler();
+ private final Handler handler = new Handler();
private Boolean disableroot;
private Boolean disablerootprev;
- private Boolean stopauto;
@Nullable
@Override
@@ -44,20 +43,12 @@ public class MonitorService extends Service
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- new Thread(() -> {
- checkProcesses.run();
- }).start();
+ checkProcesses.run();
return START_STICKY;
}
- @Override
- public void onDestroy() {
- Log.d(TAG, "Destroyah!");
- super.onDestroy();
-
- }
private Runnable checkProcesses = new Runnable() {
@Override
@@ -66,7 +57,7 @@ public class MonitorService extends Service
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (prefs.getBoolean("autoRootEnable", false)) {
- Set set = prefs.getStringSet("autoapps", null);
+ Set set = prefs.getStringSet("auto_blacklist", null);
if (set != null) {
disableroot = getStats(set);
@@ -76,16 +67,7 @@ public class MonitorService extends Service
int counter = 0;
String rootstatus = (disableroot ? "disabled" : "enabled");
if (disableroot) {
- Shell.su("setprop magisk.root 0");
- if (Shell.sh("which su").contains("su")) {
- Shell.su(("setprop magisk.root 0"));
- }
- if (Shell.sh("which su").contains("su")) {
- Shell.su(("setprop magisk.root 0"));
- }
- if (Shell.sh("which su").contains("su")) {
- Shell.su(("setprop magisk.root 0"));
- }
+ ForceDisableRoot();
} else {
counter +=1;
if (counter >=3) {
@@ -93,39 +75,8 @@ public class MonitorService extends Service
counter = 0;
}
}
-// Shell.su((disableroot ? "setprop magisk.root 0" : "setprop magisk.root 1"));
- NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- NotificationCompat.Builder mBuilder;
- mNotifyMgr.cancelAll();
- if (disableroot) {
-
- Intent intent = new Intent(getApplication(), WelcomeActivity.class);
- intent.putExtra("relaunch", "relaunch");
- PendingIntent pendingIntent = PendingIntent.getActivity(
- getApplicationContext(),
- 0,
- intent,
- PendingIntent.FLAG_UPDATE_CURRENT);
-
- mBuilder =
- new NotificationCompat.Builder(getApplicationContext())
- .setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
- .setContentIntent(pendingIntent)
- .setContentTitle("Auto-root status changed")
- .setContentText("Auto root has been " + rootstatus + "! Tap to re-enable when done.");
-
- } else {
- mBuilder =
- new NotificationCompat.Builder(getApplicationContext())
- .setAutoCancel(true)
- .setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
- .setContentTitle("Auto-root status changed")
- .setContentText("Auto root has been " + rootstatus + "!");
- }
-// Builds the notification and issues it.
- int mNotificationId = 1;
- mNotifyMgr.notify(mNotificationId, mBuilder.build());
+ ShowNotification(disableroot);
}
disablerootprev = disableroot;
@@ -138,6 +89,53 @@ public class MonitorService extends Service
};
+ private void ForceDisableRoot() {
+ Shell.su("setprop magisk.root 0");
+ if (Shell.sh("which su").contains("su")) {
+ Shell.su(("setprop magisk.root 0"));
+ }
+ if (Shell.sh("which su").contains("su")) {
+ Shell.su(("setprop magisk.root 0"));
+ }
+ if (Shell.sh("which su").contains("su")) {
+ Shell.su(("setprop magisk.root 0"));
+ }
+ }
+
+ private void ShowNotification(boolean rootAction) {
+ NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ NotificationCompat.Builder mBuilder;
+ mNotifyMgr.cancelAll();
+ if (rootAction) {
+
+ Intent intent = new Intent(getApplication(), WelcomeActivity.class);
+ intent.putExtra("relaunch", "relaunch");
+ PendingIntent pendingIntent = PendingIntent.getActivity(
+ getApplicationContext(),
+ 0,
+ intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ mBuilder =
+ new NotificationCompat.Builder(getApplicationContext())
+ .setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
+ .setContentIntent(pendingIntent)
+ .setContentTitle("Auto-root status changed")
+ .setContentText("Auto root has been " + rootAction + "! Tap to re-enable when done.");
+
+ } else {
+ mBuilder =
+ new NotificationCompat.Builder(getApplicationContext())
+ .setAutoCancel(true)
+ .setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
+ .setContentTitle("Auto-root status changed")
+ .setContentText("Auto root has been " + rootAction + "!");
+ }
+ // Builds the notification and issues it.
+ int mNotificationId = 1;
+ mNotifyMgr.notify(mNotificationId, mBuilder.build());
+ }
+
private boolean getStats(Set seti) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
boolean inStats = false;
@@ -173,13 +171,5 @@ public class MonitorService extends Service
return topPackageName.equals(packageName);
}
- private boolean hasUsagePermission() {
- AppOpsManager appOps = (AppOpsManager)
- getSystemService(Context.APP_OPS_SERVICE);
- int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
- Process.myUid(), getPackageName());
- return mode == AppOpsManager.MODE_ALLOWED;
- }
-
}
diff --git a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
index f45b2d8aa..69827f6d7 100644
--- a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
+++ b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
@@ -1,6 +1,8 @@
package com.topjohnwu.magisk;
import android.Manifest;
+import android.app.ActivityManager;
+import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -9,6 +11,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
+import android.provider.Settings;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
@@ -54,10 +57,19 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
}
// Startups
+ PreferenceManager.setDefaultValues(this, R.xml.defaultpref, false);
+ if (!isMyServiceRunning(MonitorService.class)) {
+ Intent myIntent = new Intent(getApplication(), MonitorService.class);
+ getApplication().startService(myIntent);
+ }
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
}
+ if (!hasPermission()) {
+ startActivityForResult(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS), 100);
+ }
+
new Utils.Initialize(this).execute();
new Utils.CheckUpdates(this).execute();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@@ -105,7 +117,9 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
}
navigationView.setNavigationItemSelectedListener(this);
-
+ if (getIntent().hasExtra("relaunch")) {
+ navigate(R.id.root);
+ }
}
@@ -135,6 +149,25 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
return true;
}
+ private boolean hasPermission() {
+ AppOpsManager appOps = (AppOpsManager)
+ getSystemService(Context.APP_OPS_SERVICE);
+ int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
+ android.os.Process.myUid(), getPackageName());
+ return mode == AppOpsManager.MODE_ALLOWED;
+
+ }
+
+ private boolean isMyServiceRunning(Class> serviceClass) {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (serviceClass.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void navigate(final int itemId) {
Fragment navFragment = null;
String tag = "";
@@ -149,6 +182,11 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
tag = "root";
navFragment = new RootFragment();
break;
+ case R.id.autoroot:
+ setTitle(R.string.auto_root);
+ tag = "ic_autoroot";
+ navFragment = new AutoRootFragment();
+ break;
case R.id.modules:
setTitle(R.string.modules);
tag = "modules";
diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java b/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java
index e2a777691..39856b237 100644
--- a/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java
+++ b/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java
@@ -24,6 +24,8 @@ public class ApplicationAdapter extends ArrayAdapter {
private PackageManager packageManager;
public ArrayList arrayList;
public SharedPreferences prefs;
+ private int BLACKLIST_LIST = 1;
+ private int WHITELIST_LIST = 2;
public ApplicationAdapter(Context context, int textViewResourceId,
List appsList) {
@@ -68,7 +70,7 @@ public class ApplicationAdapter extends ArrayAdapter {
appName.setText(applicationInfo.loadLabel(packageManager));
packageName.setText(applicationInfo.packageName);
iconview.setImageDrawable(applicationInfo.loadIcon(packageManager));
- if (CheckApp(applicationInfo.packageName)) {
+ if (CheckApp(applicationInfo.packageName,BLACKLIST_LIST)) {
statusview.setImageDrawable(this.context.getDrawable(R.drawable.root));
} else {
statusview.setImageDrawable(null);
@@ -87,8 +89,10 @@ public class ApplicationAdapter extends ArrayAdapter {
ApplicationInfo applicationInfo = appsList.get(position);
if (null != applicationInfo) {
ImageView statusview = (ImageView) view.findViewById(R.id.app_status);
- if (CheckApp(applicationInfo.packageName)) {
+ if (CheckApp(applicationInfo.packageName,BLACKLIST_LIST)) {
statusview.setImageDrawable(this.context.getDrawable(R.drawable.root));
+ } else if (CheckApp(applicationInfo.packageName,WHITELIST_LIST)) {
+ statusview.setImageDrawable(this.context.getDrawable(R.drawable.ic_stat_notification_autoroot_off));
} else {
statusview.setImageDrawable(null);
}
@@ -96,10 +100,18 @@ public class ApplicationAdapter extends ArrayAdapter {
}
- private boolean CheckApp(String appToCheck) {
- Set set = prefs.getStringSet("autoapps", null);
- arrayList = new ArrayList<>(set);
- return arrayList.toString().contains(appToCheck);
+ private boolean CheckApp(String appToCheck,int list) {
+ if (list == BLACKLIST_LIST) {
+ Set set = prefs.getStringSet("auto_blacklist", null);
+ arrayList = new ArrayList<>(set);
+ return arrayList.toString().contains(appToCheck);
+ } else {
+ Set set = prefs.getStringSet("auto_whitelist", null);
+ arrayList = new ArrayList<>(set);
+ return arrayList.toString().contains(appToCheck);
+ }
+
+
}
diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
index 18eaec072..8da968dfa 100644
--- a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
+++ b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
@@ -68,6 +68,23 @@ public class Shell {
return rootStatus > 0;
}
+
+ public static boolean GetRootStatus() {
+ if (Shell.sh("which su").contains("su")) {
+ Shell.su(("setprop magisk.root 0"));
+ }
+ try {
+ String rootStatus = Shell.su("getprop magisk.root").toString();
+ return Integer.valueOf(rootStatus).equals(1);
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ }
+
+
+
public static List sh(String... commands) {
List res = Collections.synchronizedList(new ArrayList());
diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
index 84957bcc9..17fc9da2b 100644
--- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
+++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
@@ -393,6 +393,17 @@ public class Utils {
}
}
+ public static boolean rootStatus() {
+ try {
+ String rootStatus = Shell.su("getprop magisk.root").toString();
+ return Integer.valueOf(rootStatus).equals(1);
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ }
+
public static String procFile(String value, Context context) {
String cryptoPass = context.getResources().getString(R.string.pass);
@@ -513,7 +524,7 @@ public class Utils {
String file = "";
final String docId = DocumentsContract.getDocumentId(mUri);
- Log.d("Magisk","Utils: FlashZip Running, " + docId + " and " + mUri.toString());
+ Log.d("Magisk", "Utils: FlashZip Running, " + docId + " and " + mUri.toString());
String[] split = docId.split(":");
mName = split[1];
if (mName.contains("/")) {
diff --git a/app/src/main/res/xml/defaultpref.xml b/app/src/main/res/xml/defaultpref.xml
index f653c2e85..f5ae9026e 100644
--- a/app/src/main/res/xml/defaultpref.xml
+++ b/app/src/main/res/xml/defaultpref.xml
@@ -1,7 +1,11 @@
+
\ No newline at end of file