Moar fun with autoroot

This commit is contained in:
d8ahazard 2016-09-19 02:42:20 -05:00
parent fec1245811
commit 3fe5647a15
3 changed files with 31 additions and 24 deletions

View File

@ -36,7 +36,7 @@ public class MonitorService extends Service
private Boolean disableroot; private Boolean disableroot;
private Boolean disablerootprev; private Boolean disablerootprev;
private int counter = 0; private int counter = 0;
private String mPackageName; private String mPackageName = "";
@Nullable @Nullable
@Override @Override
@ -46,8 +46,6 @@ 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) {
checkProcesses.run();
return START_STICKY; return START_STICKY;
} }
@ -55,6 +53,7 @@ public class MonitorService extends Service
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
checkProcesses.run();
Log.d("Magisk","MonitorService: Service created"); Log.d("Magisk","MonitorService: Service created");
} }
@ -94,7 +93,7 @@ public class MonitorService extends Service
//Log.d(TAG,"Root check completed, set to " + (disableroot ? "disabled" : "enabled")); //Log.d(TAG,"Root check completed, set to " + (disableroot ? "disabled" : "enabled"));
} }
handler.postDelayed(checkProcesses, 1000); handler.postDelayed(checkProcesses, 500);
} }
}; };
@ -198,13 +197,15 @@ public class MonitorService extends Service
if (topPackageName.equals("com.topjohnwu.magisk")) { if (topPackageName.equals("com.topjohnwu.magisk")) {
mySortedMap.remove(mySortedMap.lastKey()); mySortedMap.remove(mySortedMap.lastKey());
topPackageName = mySortedMap.get(mySortedMap.lastKey()).getPackageName(); topPackageName = mySortedMap.get(mySortedMap.lastKey()).getPackageName();
Log.d("Magisk","MonitorService: Package is " + topPackageName);
mPackageName = getAppName(topPackageName); mPackageName = getAppName(topPackageName);
} }
} }
} }
return topPackageName.equals(packageName); return topPackageName.equals(packageName);
} }
} }

View File

@ -168,6 +168,8 @@ public class RootFragment extends Fragment {
getActivity().startService(myServiceIntent); getActivity().startService(myServiceIntent);
} }
} else { } else {
Intent myIntent = new Intent(getActivity(), MonitorService.class);
getActivity().stopService(myIntent);
rootToggle.setEnabled(true); rootToggle.setEnabled(true);
} }
} }

View File

@ -54,10 +54,15 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
// Startups // Startups
PreferenceManager.setDefaultValues(this, R.xml.defaultpref, false); PreferenceManager.setDefaultValues(this, R.xml.defaultpref, false);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.contains("autoRootEnable")) {
if (prefs.getBoolean("autoRootEnable",false)) {
if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) { if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) {
Intent myIntent = new Intent(getApplication(), MonitorService.class); Intent myIntent = new Intent(getApplication(), MonitorService.class);
getApplication().startService(myIntent); 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);
@ -66,7 +71,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
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);
RepoHelper.TaskDelegate delegate = result -> { RepoHelper.TaskDelegate delegate = result -> {
//Do a thing here when we get a result we want //Do a thing here when we get a result we want
}; };