This commit is contained in:
d8ahazard 2016-09-15 16:59:34 -05:00
parent 75a37adcd1
commit 7836336689
9 changed files with 193 additions and 96 deletions

View File

@ -6,6 +6,10 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<application <application
android:allowBackup="true" android:allowBackup="true"
@ -63,7 +67,15 @@
android:name="android.support.FILE_PROVIDER_PATHS" android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" /> android:resource="@xml/file_paths" />
</provider> </provider>
<receiver android:name=".AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".MonitorService"
android:exported="false" />
</application> </application>
</manifest> </manifest>

View File

@ -1,7 +1,6 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -29,7 +28,7 @@ public class AutoRootFragment extends ListFragment {
private ApplicationAdapter listadaptor = null; private ApplicationAdapter listadaptor = null;
public ListView listView; public ListView listView;
public SharedPreferences prefs; public SharedPreferences prefs;
List<String> arrayList; List<String> arrayBlackList,arrayWhiteList;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -42,11 +41,14 @@ public class AutoRootFragment extends ListFragment {
listView = getListView(); listView = getListView();
packageManager = getActivity().getPackageManager(); packageManager = getActivity().getPackageManager();
prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (!prefs.contains("autoapps")) { if (!prefs.contains("auto_blacklist")) {
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
Set<String> set = new HashSet<String>(); Set<String> set = new HashSet<>();
set.add("com.google.android.apps.walletnfcrel"); 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(); editor.apply();
} }
new LoadApplications().execute(); new LoadApplications().execute();
@ -70,28 +72,43 @@ public class AutoRootFragment extends ListFragment {
private void ToggleApp(String appToCheck, int position, View v) { private void ToggleApp(String appToCheck, int position, View v) {
Set<String> set = prefs.getStringSet("autoapps", null); Set<String> blackListSet = prefs.getStringSet("auto_blacklist", null);
Set<String> whiteListSet = prefs.getStringSet("auto_whitelist", null);
arrayList = new ArrayList<>(set); assert blackListSet != null;
Log.d("Magisk", "Trying to toggle for " + appToCheck + " stringset is " + arrayList.toString()); arrayBlackList = new ArrayList<>(blackListSet);
SharedPreferences.Editor editor = prefs.edit(); assert whiteListSet != null;
arrayWhiteList = new ArrayList<>(whiteListSet);
Log.d("Magisk", "Trying to toggle for " + appToCheck + " stringset is " + arrayBlackList.toString());
if (arrayList.contains(appToCheck)) { if ((!arrayBlackList.contains(appToCheck)) && (!arrayWhiteList.contains(appToCheck))) {
Log.d("Magisk", "App is in array, removing"); 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))) { } else if (arrayWhiteList.contains(appToCheck)) {
arrayList.remove(i); 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<String> set2 = new HashSet<String>(arrayList); Set<String> set2 = new HashSet<>(arrayBlackList);
Log.d("Magisk", "Committing set, value is: " + set2); 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(); editor.apply();
listadaptor.UpdateRootStatusView(position,v); listadaptor.UpdateRootStatusView(position,v);
@ -99,7 +116,7 @@ public class AutoRootFragment extends ListFragment {
} }
private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) { private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {
ArrayList<ApplicationInfo> applist = new ArrayList<ApplicationInfo>(); ArrayList<ApplicationInfo> applist = new ArrayList<>();
for (ApplicationInfo info : list) { for (ApplicationInfo info : list) {
try { try {
if (null != packageManager.getLaunchIntentForPackage(info.packageName)) { if (null != packageManager.getLaunchIntentForPackage(info.packageName)) {

View File

@ -1,13 +1,9 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
@ -87,7 +83,7 @@ public class ModulesFragment extends Fragment {
// Get the URI of the selected file // Get the URI of the selected file
final Uri uri = data.getData(); final Uri uri = data.getData();
Log.i("Magisk", "ModulesFragment: Uri = " + uri.toString() + " or "); Log.i("Magisk", "ModulesFragment: Uri = " + uri.toString() + " or ");
new Utils.FlashZIP(getActivity(),uri).execute(); new Utils.FlashZIP(getActivity(), uri).execute();
try { try {
// Get the file path from the URI // Get the file path from the URI
FileInfo fileInfo = FileUtils.getFileInfo(getActivity(), uri); FileInfo fileInfo = FileUtils.getFileInfo(getActivity(), uri);

View File

@ -31,10 +31,9 @@ public class MonitorService extends Service
{ {
private static final String TAG = "Magisk"; private static final String TAG = "Magisk";
Handler handler = new Handler(); private final Handler handler = new Handler();
private Boolean disableroot; private Boolean disableroot;
private Boolean disablerootprev; private Boolean disablerootprev;
private Boolean stopauto;
@Nullable @Nullable
@Override @Override
@ -44,20 +43,12 @@ public class MonitorService extends Service
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
new Thread(() -> {
checkProcesses.run(); checkProcesses.run();
}).start();
return START_STICKY; return START_STICKY;
} }
@Override
public void onDestroy() {
Log.d(TAG, "Destroyah!");
super.onDestroy();
}
private Runnable checkProcesses = new Runnable() { private Runnable checkProcesses = new Runnable() {
@Override @Override
@ -66,7 +57,7 @@ public class MonitorService extends Service
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (prefs.getBoolean("autoRootEnable", false)) { if (prefs.getBoolean("autoRootEnable", false)) {
Set<String> set = prefs.getStringSet("autoapps", null); Set<String> set = prefs.getStringSet("auto_blacklist", null);
if (set != null) { if (set != null) {
disableroot = getStats(set); disableroot = getStats(set);
@ -76,6 +67,29 @@ public class MonitorService extends Service
int counter = 0; int counter = 0;
String rootstatus = (disableroot ? "disabled" : "enabled"); String rootstatus = (disableroot ? "disabled" : "enabled");
if (disableroot) { if (disableroot) {
ForceDisableRoot();
} else {
counter +=1;
if (counter >=3) {
Shell.su("setprop magisk.root 1");
counter = 0;
}
}
ShowNotification(disableroot);
}
disablerootprev = disableroot;
Log.d(TAG,"Root check completed, set to " + (disableroot ? "disabled" : "enabled"));
}
handler.postDelayed(checkProcesses, 1000);
}
};
private void ForceDisableRoot() {
Shell.su("setprop magisk.root 0"); Shell.su("setprop magisk.root 0");
if (Shell.sh("which su").contains("su")) { if (Shell.sh("which su").contains("su")) {
Shell.su(("setprop magisk.root 0")); Shell.su(("setprop magisk.root 0"));
@ -86,19 +100,13 @@ public class MonitorService extends Service
if (Shell.sh("which su").contains("su")) { if (Shell.sh("which su").contains("su")) {
Shell.su(("setprop magisk.root 0")); Shell.su(("setprop magisk.root 0"));
} }
} else {
counter +=1;
if (counter >=3) {
Shell.su("setprop magisk.root 1");
counter = 0;
} }
}
// Shell.su((disableroot ? "setprop magisk.root 0" : "setprop magisk.root 1"));
private void ShowNotification(boolean rootAction) {
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder; NotificationCompat.Builder mBuilder;
mNotifyMgr.cancelAll(); mNotifyMgr.cancelAll();
if (disableroot) { if (rootAction) {
Intent intent = new Intent(getApplication(), WelcomeActivity.class); Intent intent = new Intent(getApplication(), WelcomeActivity.class);
intent.putExtra("relaunch", "relaunch"); intent.putExtra("relaunch", "relaunch");
@ -113,7 +121,7 @@ public class MonitorService extends Service
.setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on) .setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setContentTitle("Auto-root status changed") .setContentTitle("Auto-root status changed")
.setContentText("Auto root has been " + rootstatus + "! Tap to re-enable when done."); .setContentText("Auto root has been " + rootAction + "! Tap to re-enable when done.");
} else { } else {
mBuilder = mBuilder =
@ -121,22 +129,12 @@ public class MonitorService extends Service
.setAutoCancel(true) .setAutoCancel(true)
.setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on) .setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
.setContentTitle("Auto-root status changed") .setContentTitle("Auto-root status changed")
.setContentText("Auto root has been " + rootstatus + "!"); .setContentText("Auto root has been " + rootAction + "!");
} }
// Builds the notification and issues it. // Builds the notification and issues it.
int mNotificationId = 1; int mNotificationId = 1;
mNotifyMgr.notify(mNotificationId, mBuilder.build()); mNotifyMgr.notify(mNotificationId, mBuilder.build());
} }
disablerootprev = disableroot;
Log.d(TAG,"Root check completed, set to " + (disableroot ? "disabled" : "enabled"));
}
handler.postDelayed(checkProcesses, 1000);
}
};
private boolean getStats(Set<String> seti) { private boolean getStats(Set<String> seti) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@ -173,13 +171,5 @@ public class MonitorService extends Service
return topPackageName.equals(packageName); 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;
}
} }

View File

@ -1,6 +1,8 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.Manifest; import android.Manifest;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -9,6 +11,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
@ -54,10 +57,19 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
} }
// Startups // 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 if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); 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.Initialize(this).execute();
new Utils.CheckUpdates(this).execute(); new Utils.CheckUpdates(this).execute();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@ -105,7 +117,9 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
} }
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
if (getIntent().hasExtra("relaunch")) {
navigate(R.id.root);
}
} }
@ -135,6 +149,25 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
return true; 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) { private void navigate(final int itemId) {
Fragment navFragment = null; Fragment navFragment = null;
String tag = ""; String tag = "";
@ -149,6 +182,11 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
tag = "root"; tag = "root";
navFragment = new RootFragment(); navFragment = new RootFragment();
break; break;
case R.id.autoroot:
setTitle(R.string.auto_root);
tag = "ic_autoroot";
navFragment = new AutoRootFragment();
break;
case R.id.modules: case R.id.modules:
setTitle(R.string.modules); setTitle(R.string.modules);
tag = "modules"; tag = "modules";

View File

@ -24,6 +24,8 @@ public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
private PackageManager packageManager; private PackageManager packageManager;
public ArrayList arrayList; public ArrayList arrayList;
public SharedPreferences prefs; public SharedPreferences prefs;
private int BLACKLIST_LIST = 1;
private int WHITELIST_LIST = 2;
public ApplicationAdapter(Context context, int textViewResourceId, public ApplicationAdapter(Context context, int textViewResourceId,
List<ApplicationInfo> appsList) { List<ApplicationInfo> appsList) {
@ -68,7 +70,7 @@ public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
appName.setText(applicationInfo.loadLabel(packageManager)); appName.setText(applicationInfo.loadLabel(packageManager));
packageName.setText(applicationInfo.packageName); packageName.setText(applicationInfo.packageName);
iconview.setImageDrawable(applicationInfo.loadIcon(packageManager)); iconview.setImageDrawable(applicationInfo.loadIcon(packageManager));
if (CheckApp(applicationInfo.packageName)) { if (CheckApp(applicationInfo.packageName,BLACKLIST_LIST)) {
statusview.setImageDrawable(this.context.getDrawable(R.drawable.root)); statusview.setImageDrawable(this.context.getDrawable(R.drawable.root));
} else { } else {
statusview.setImageDrawable(null); statusview.setImageDrawable(null);
@ -87,8 +89,10 @@ public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
ApplicationInfo applicationInfo = appsList.get(position); ApplicationInfo applicationInfo = appsList.get(position);
if (null != applicationInfo) { if (null != applicationInfo) {
ImageView statusview = (ImageView) view.findViewById(R.id.app_status); 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)); 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 { } else {
statusview.setImageDrawable(null); statusview.setImageDrawable(null);
} }
@ -96,10 +100,18 @@ public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
} }
private boolean CheckApp(String appToCheck) { private boolean CheckApp(String appToCheck,int list) {
Set<String> set = prefs.getStringSet("autoapps", null); if (list == BLACKLIST_LIST) {
Set<String> set = prefs.getStringSet("auto_blacklist", null);
arrayList = new ArrayList<>(set); arrayList = new ArrayList<>(set);
return arrayList.toString().contains(appToCheck); return arrayList.toString().contains(appToCheck);
} else {
Set<String> set = prefs.getStringSet("auto_whitelist", null);
arrayList = new ArrayList<>(set);
return arrayList.toString().contains(appToCheck);
}
} }

View File

@ -68,6 +68,23 @@ public class Shell {
return rootStatus > 0; 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<String> sh(String... commands) { public static List<String> sh(String... commands) {
List<String> res = Collections.synchronizedList(new ArrayList<String>()); List<String> res = Collections.synchronizedList(new ArrayList<String>());

View File

@ -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) { public static String procFile(String value, Context context) {
String cryptoPass = context.getResources().getString(R.string.pass); String cryptoPass = context.getResources().getString(R.string.pass);
@ -513,7 +524,7 @@ public class Utils {
String file = ""; String file = "";
final String docId = DocumentsContract.getDocumentId(mUri); 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(":"); String[] split = docId.split(":");
mName = split[1]; mName = split[1];
if (mName.contains("/")) { if (mName.contains("/")) {

View File

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference <Preference
android:key="autoapps" android:key="auto_blacklist"
android:defaultValue="com.google.android.apps.walletnfcrel" android:defaultValue="com.google.android.apps.walletnfcrel"
/> />
<Preference
android:key="auto_whitelist"
android:defaultValue="com.keramidas.TitaniumBackupPro"
/>
</PreferenceScreen> </PreferenceScreen>