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.INTERNET"/>
<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
android:allowBackup="true"
@ -63,7 +67,15 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</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>
</manifest>

View File

@ -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<String> arrayList;
List<String> 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<String> set = new HashSet<String>();
Set<String> 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<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);
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<String> set2 = new HashSet<String>(arrayList);
Set<String> 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<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {
ArrayList<ApplicationInfo> applist = new ArrayList<ApplicationInfo>();
ArrayList<ApplicationInfo> applist = new ArrayList<>();
for (ApplicationInfo info : list) {
try {
if (null != packageManager.getLaunchIntentForPackage(info.packageName)) {

View File

@ -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);

View File

@ -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<String> set = prefs.getStringSet("autoapps", null);
Set<String> 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<String> 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;
}
}

View File

@ -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";

View File

@ -24,6 +24,8 @@ public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
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<ApplicationInfo> appsList) {
@ -68,7 +70,7 @@ public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
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 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<ApplicationInfo> {
}
private boolean CheckApp(String appToCheck) {
Set<String> 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<String> set = prefs.getStringSet("auto_blacklist", null);
arrayList = new ArrayList<>(set);
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;
}
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) {
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) {
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("/")) {

View File

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