mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 21:27:41 +02:00
Remove Auto Root Code
Revert this commit after things are sorted out
This commit is contained in:
@ -26,7 +26,7 @@ import java.io.InputStream;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
|
||||
private static final String SOURCE_CODE_URL = "https://github.com/topjohnwu/MagiskManager";
|
||||
private static final String XDA_THREAD = "http://forum.xda-developers.com/showthread.php?t=3432382";
|
||||
|
@ -1,172 +0,0 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.ListFragment;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.topjohnwu.magisk.utils.ApplicationAdapter;
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class AutoRootFragment extends ListFragment {
|
||||
private PackageManager packageManager = null;
|
||||
private List<ApplicationInfo> applist = null;
|
||||
private ApplicationAdapter listadaptor = null;
|
||||
public ListView listView;
|
||||
public SharedPreferences prefs;
|
||||
List<String> arrayBlackList;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
View view = inflater.inflate(R.layout.auto_root_fragment, container, false);
|
||||
int horizontalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
|
||||
int verticalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
|
||||
TypedValue tv = new TypedValue();
|
||||
int actionBarHeight = 130;
|
||||
if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
|
||||
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
view.setPadding(horizontalMargin, actionBarHeight, horizontalMargin, verticalMargin);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
initializeElements();
|
||||
super.onResume();
|
||||
getActivity().setTitle(R.string.auto_toggle);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initializeElements() {
|
||||
listView = getListView();
|
||||
packageManager = getActivity().getPackageManager();
|
||||
new LoadApplications().execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Logger.dev("Click");
|
||||
super.onListItemClick(l, v, position, id);
|
||||
ApplicationInfo app = applist.get(position);
|
||||
ToggleApp(app.packageName, position, v);
|
||||
|
||||
}
|
||||
|
||||
private void ToggleApp(String appToCheck, int position, View v) {
|
||||
Logger.dev("Magisk", "AutoRootFragment: ToggleApp called for " + appToCheck);
|
||||
Set<String> blackListSet = prefs.getStringSet("auto_blacklist", null);
|
||||
assert blackListSet != null;
|
||||
arrayBlackList = new ArrayList<>(blackListSet);
|
||||
|
||||
if (!arrayBlackList.contains(appToCheck)) {
|
||||
arrayBlackList.add(appToCheck);
|
||||
|
||||
} else {
|
||||
for (int i = 0; i < arrayBlackList.size(); i++) {
|
||||
if (appToCheck.equals(arrayBlackList.get(i))) {
|
||||
arrayBlackList.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Logger.dev("Committing set, value is: " + arrayBlackList.toString());
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putStringSet("auto_blacklist", new HashSet<>(arrayBlackList));
|
||||
editor.apply();
|
||||
listadaptor.UpdateRootStatusView(position, v);
|
||||
|
||||
}
|
||||
|
||||
private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {
|
||||
ArrayList<ApplicationInfo> applist = new ArrayList<>();
|
||||
for (ApplicationInfo info : list) {
|
||||
try {
|
||||
if (null != packageManager.getLaunchIntentForPackage(info.packageName)) {
|
||||
if (!info.packageName.contains("magisk")) {
|
||||
applist.add(info);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Collections.sort(applist, new CustomComparator());
|
||||
|
||||
return applist;
|
||||
}
|
||||
|
||||
public class CustomComparator implements Comparator<ApplicationInfo> {
|
||||
@Override
|
||||
public int compare(ApplicationInfo o1, ApplicationInfo o2) {
|
||||
return o1.loadLabel(packageManager).toString().compareToIgnoreCase(o2.loadLabel(packageManager).toString());
|
||||
}
|
||||
}
|
||||
|
||||
private class LoadApplications extends AsyncTask<Void, Void, Void> {
|
||||
private ProgressDialog progress = null;
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
applist = checkForLaunchIntent(packageManager.getInstalledApplications(PackageManager.GET_META_DATA));
|
||||
listadaptor = new ApplicationAdapter(getActivity(),
|
||||
R.layout.list_item_app, applist);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
super.onCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
setListAdapter(listadaptor);
|
||||
progress.dismiss();
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progress = ProgressDialog.show(getActivity(), null,
|
||||
"Loading application info...");
|
||||
super.onPreExecute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Void... values) {
|
||||
super.onProgressUpdate(values);
|
||||
}
|
||||
}
|
||||
}
|
@ -150,11 +150,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
tag = "root";
|
||||
navFragment = new RootFragment();
|
||||
break;
|
||||
case R.id.autoroot:
|
||||
setTitle(R.string.auto_toggle);
|
||||
tag = "autoroot";
|
||||
navFragment = new AutoRootFragment();
|
||||
break;
|
||||
case R.id.modules:
|
||||
setTitle(R.string.modules);
|
||||
tag = "modules";
|
||||
|
@ -22,7 +22,6 @@ import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
@ -39,13 +38,11 @@ public class RootFragment extends Fragment {
|
||||
|
||||
@BindView(R.id.progressBar) ProgressBar progressBar;
|
||||
@BindView(R.id.rootSwitchView) View rootToggleView;
|
||||
@BindView(R.id.autoRootSwitchView) View autoRootToggleView;
|
||||
@BindView(R.id.selinuxSwitchView) View selinuxToggleView;
|
||||
@BindView(R.id.rootStatusView) View rootStatusView;
|
||||
@BindView(R.id.safetynetStatusView) View safetynetStatusView;
|
||||
@BindView(R.id.selinuxStatusView) View selinuxStatusView;
|
||||
@BindView(R.id.root_toggle) Switch rootToggle;
|
||||
@BindView(R.id.auto_root_toggle) Switch autoRootToggle;
|
||||
@BindView(R.id.selinux_toggle) Switch selinuxToggle;
|
||||
@BindView(R.id.root_status_container) View rootStatusContainer;
|
||||
@BindView(R.id.root_status_icon) ImageView rootStatusIcon;
|
||||
@ -57,19 +54,17 @@ public class RootFragment extends Fragment {
|
||||
@BindView(R.id.safety_net_icon) ImageView safetyNetStatusIcon;
|
||||
|
||||
int statusOK = R.drawable.ic_check_circle;
|
||||
int statusAuto = R.drawable.ic_autoroot;
|
||||
int statusError = R.drawable.ic_error;
|
||||
int statusUnknown = R.drawable.ic_help;
|
||||
|
||||
private int colorOK, colorFail, colorNeutral, colorWarn;
|
||||
private boolean autoRootStatus;
|
||||
//private boolean autoRootStatus;
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener listener;
|
||||
private View view;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
view = inflater.inflate(R.layout.root_fragment, container, false);
|
||||
View view = inflater.inflate(R.layout.root_fragment, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
int[] attrs0 = {R.attr.ColorOK};
|
||||
int[] attrs1 = {R.attr.ColorFail};
|
||||
@ -87,17 +82,9 @@ public class RootFragment extends Fragment {
|
||||
ta1.recycle();
|
||||
ta2.recycle();
|
||||
ta3.recycle();
|
||||
autoRootStatus = Utils.autoToggleEnabled(getActivity());
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
|
||||
if (autoRootStatus) {
|
||||
if (!Utils.hasServicePermission(getActivity())) {
|
||||
autoRootStatus = false;
|
||||
}
|
||||
}
|
||||
rootToggle.setEnabled(!autoRootStatus);
|
||||
autoRootToggle.setChecked(autoRootStatus);
|
||||
updateUI();
|
||||
|
||||
rootToggle.setOnClickListener(toggle -> {
|
||||
@ -111,19 +98,6 @@ public class RootFragment extends Fragment {
|
||||
|
||||
});
|
||||
|
||||
autoRootToggle.setOnClickListener(toggle -> {
|
||||
if (!Utils.hasServicePermission(getActivity())) {
|
||||
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||
Toast.makeText(getActivity(), "Please enable accessibility access for Magisk's auto-toggle feature to work.", Toast.LENGTH_LONG).show();
|
||||
startActivityForResult(intent, 100);
|
||||
} else {
|
||||
toggleAutoRoot(autoRootToggle.isChecked());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
selinuxToggle.setOnClickListener(toggle -> {
|
||||
|
||||
new AsyncTask<Boolean, Void, Void>() {
|
||||
@ -148,10 +122,8 @@ public class RootFragment extends Fragment {
|
||||
super.onResume();
|
||||
getActivity().setTitle(R.string.root);
|
||||
listener = (pref, key) -> {
|
||||
|
||||
if ((key.contains("autoRootEnable")) || (key.equals("root"))) {
|
||||
Logger.dev("RootFragmnet, keychange detected for " + key);
|
||||
//new updateUI().execute();
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@ -166,45 +138,7 @@ public class RootFragment extends Fragment {
|
||||
prefs.unregisterOnSharedPreferenceChangeListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// Check which request we're responding to
|
||||
Log.d("Magisk", "Got result: " + requestCode + " and " + resultCode);
|
||||
if (requestCode == 100) {
|
||||
if (Utils.hasServicePermission(getActivity())) {
|
||||
toggleAutoRoot(true);
|
||||
Snackbar.make(view, getActivity().getString(R.string.auto_toggle) + " has been enabled.", Snackbar.LENGTH_LONG).show();
|
||||
|
||||
} else {
|
||||
autoRootToggle.setChecked(false);
|
||||
Snackbar.make(view, getActivity().getString(R.string.auto_toggle) + " disabled, permissions required.", Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleAutoRoot(boolean toggleState) {
|
||||
autoRootStatus = toggleState;
|
||||
Utils.toggleAutoRoot(toggleState, getActivity());
|
||||
if (toggleState) {
|
||||
Intent myIntent = new Intent(getActivity(), MonitorService.class);
|
||||
getActivity().startService(myIntent);
|
||||
rootToggle.setEnabled(false);
|
||||
boolean boo = Utils.isMyServiceRunning(MonitorService.class, getActivity());
|
||||
if (boo) {
|
||||
Intent myServiceIntent = new Intent(getActivity(), MonitorService.class);
|
||||
getActivity().startService(myServiceIntent);
|
||||
}
|
||||
} else {
|
||||
Intent myIntent = new Intent(getActivity(), MonitorService.class);
|
||||
getActivity().stopService(myIntent);
|
||||
rootToggle.setEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
autoRootToggle.setChecked(autoRootStatus);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
rootStatusView.setVisibility(View.VISIBLE);
|
||||
safetynetStatusView.setVisibility(View.VISIBLE);
|
||||
@ -212,7 +146,6 @@ public class RootFragment extends Fragment {
|
||||
|
||||
if (Shell.rootAccess()) {
|
||||
rootToggleView.setVisibility(View.VISIBLE);
|
||||
autoRootToggleView.setVisibility(View.VISIBLE);
|
||||
selinuxToggleView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@ -268,40 +201,27 @@ public class RootFragment extends Fragment {
|
||||
break;
|
||||
case 1:
|
||||
// Proper root
|
||||
if (autoRootStatus) {
|
||||
rootStatusContainer.setBackgroundColor(colorOK);
|
||||
rootStatusIcon.setImageResource(statusAuto);
|
||||
rootStatusIcon.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
|
||||
rootStatus.setTextColor(colorOK);
|
||||
rootStatus.setText(R.string.root_auto_unmounted);
|
||||
rootToggle.setEnabled(false);
|
||||
autoRootToggle.setChecked(true);
|
||||
safetyNetStatusIcon.setImageResource(statusOK);
|
||||
safetyNetStatus.setText(R.string.root_auto_unmounted_info);
|
||||
rootToggle.setEnabled(true);
|
||||
if (Utils.rootEnabled()) {
|
||||
// Mounted
|
||||
rootStatusContainer.setBackgroundColor(colorWarn);
|
||||
rootStatusIcon.setImageResource(statusError);
|
||||
rootStatus.setTextColor(colorWarn);
|
||||
rootStatus.setText(R.string.root_enabled);
|
||||
rootToggle.setChecked(true);
|
||||
safetyNetStatusIcon.setImageResource(statusError);
|
||||
safetyNetStatus.setText(R.string.root_enabled_info);
|
||||
break;
|
||||
} else {
|
||||
rootToggle.setEnabled(true);
|
||||
if (Utils.rootEnabled()) {
|
||||
// Mounted
|
||||
rootStatusContainer.setBackgroundColor(colorWarn);
|
||||
rootStatusIcon.setImageResource(statusError);
|
||||
rootStatus.setTextColor(colorWarn);
|
||||
rootStatus.setText(R.string.root_enabled);
|
||||
rootToggle.setChecked(true);
|
||||
safetyNetStatusIcon.setImageResource(statusError);
|
||||
safetyNetStatus.setText(R.string.root_enabled_info);
|
||||
break;
|
||||
} else {
|
||||
// Disabled
|
||||
rootStatusContainer.setBackgroundColor(colorOK);
|
||||
rootStatusIcon.setImageResource(statusOK);
|
||||
rootStatus.setTextColor(colorOK);
|
||||
rootStatus.setText(R.string.root_disabled);
|
||||
rootToggle.setChecked(false);
|
||||
safetyNetStatusIcon.setImageResource(statusOK);
|
||||
safetyNetStatus.setText(R.string.root_disabled_info);
|
||||
break;
|
||||
}
|
||||
// Disabled
|
||||
rootStatusContainer.setBackgroundColor(colorOK);
|
||||
rootStatusIcon.setImageResource(statusOK);
|
||||
rootStatus.setTextColor(colorOK);
|
||||
rootStatus.setText(R.string.root_disabled);
|
||||
rootToggle.setChecked(false);
|
||||
safetyNetStatusIcon.setImageResource(statusOK);
|
||||
safetyNetStatus.setText(R.string.root_disabled_info);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
// Improper root
|
||||
@ -312,7 +232,6 @@ public class RootFragment extends Fragment {
|
||||
rootToggle.setChecked(true);
|
||||
safetyNetStatusIcon.setImageResource(statusError);
|
||||
safetyNetStatus.setText(R.string.root_system_info);
|
||||
autoRootToggleView.setVisibility(View.GONE);
|
||||
rootToggleView.setVisibility(View.GONE);
|
||||
selinuxToggleView.setVisibility(View.GONE);
|
||||
break;
|
||||
|
@ -51,21 +51,12 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
themePreference = (ListPreference) findPreference("theme");
|
||||
CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox");
|
||||
CheckBoxPreference quickTilePreference = (CheckBoxPreference) findPreference("enable_quicktile");
|
||||
busyboxPreference.setChecked(Utils.commandExists("unzip"));
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(this);
|
||||
CheckBoxPreference keepRootOffPreference = (CheckBoxPreference) findPreference("keep_root_off");
|
||||
CheckBoxPreference hideRootNotificationPreference = (CheckBoxPreference) findPreference("hide_root_notification");
|
||||
themePreference.setSummary(themePreference.getValue());
|
||||
if (MagiskFragment.magiskVersion == -1) {
|
||||
quickTilePreference.setEnabled(false);
|
||||
keepRootOffPreference.setEnabled(false);
|
||||
hideRootNotificationPreference.setEnabled(false);
|
||||
busyboxPreference.setEnabled(false);
|
||||
} else {
|
||||
quickTilePreference.setEnabled(true);
|
||||
keepRootOffPreference.setEnabled(true);
|
||||
hideRootNotificationPreference.setEnabled(true);
|
||||
busyboxPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
@ -88,65 +79,35 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Logger.dev("Settings: NewValue is " + key);
|
||||
|
||||
if (key.equals("theme")) {
|
||||
String pref = sharedPreferences.getString(key, "");
|
||||
switch (key) {
|
||||
case "theme":
|
||||
String pref = sharedPreferences.getString(key, "");
|
||||
|
||||
themePreference.setSummary(pref);
|
||||
if (pref.equals("Dark")) {
|
||||
getActivity().getApplication().setTheme(R.style.AppTheme_dh);
|
||||
} else {
|
||||
getActivity().getApplication().setTheme(R.style.AppTheme);
|
||||
}
|
||||
Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("Relaunch", "Settings");
|
||||
startActivity(intent);
|
||||
themePreference.setSummary(pref);
|
||||
if (pref.equals("Dark")) {
|
||||
getActivity().getApplication().setTheme(R.style.AppTheme_dh);
|
||||
} else {
|
||||
getActivity().getApplication().setTheme(R.style.AppTheme);
|
||||
}
|
||||
Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("Relaunch", "Settings");
|
||||
startActivity(intent);
|
||||
|
||||
Logger.dev("SettingsFragment: theme is " + pref);
|
||||
Logger.dev("SettingsFragment: theme is " + pref);
|
||||
|
||||
} else if (key.equals("enable_quicktile")) {
|
||||
boolean checked = sharedPreferences.getBoolean("enable_quicktile", false);
|
||||
if (checked) {
|
||||
new AsyncTask<Void, Void, Boolean> () {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
return Utils.installTile(getActivity());
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
super.onPostExecute(result);
|
||||
if (result) {
|
||||
Toast.makeText(getActivity(), "Tile installed", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "Tile installation error", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
} else {
|
||||
new AsyncTask<Void, Void, Boolean> () {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
return Utils.uninstallTile(getActivity());
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
super.onPostExecute(result);
|
||||
if (result) {
|
||||
Toast.makeText(getActivity(), "Tile uninstalled", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "Tile uninstallation error", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
}
|
||||
} else if (key.equals("busybox")) {
|
||||
boolean checked = sharedPreferences.getBoolean("busybox", false);
|
||||
new Async.LinkBusyBox(checked).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
} else if (key.equals("developer_logging")) {
|
||||
Logger.devLog = sharedPreferences.getBoolean("developer_logging", false);
|
||||
} else if (key.equals("shell_logging")) {
|
||||
Logger.logShell = sharedPreferences.getBoolean("shell_logging", false);
|
||||
break;
|
||||
case "busybox":
|
||||
boolean checked = sharedPreferences.getBoolean("busybox", false);
|
||||
new Async.LinkBusyBox(checked).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
break;
|
||||
case "developer_logging":
|
||||
Logger.devLog = sharedPreferences.getBoolean("developer_logging", false);
|
||||
break;
|
||||
case "shell_logging":
|
||||
Logger.logShell = sharedPreferences.getBoolean("shell_logging", false);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.utils.Async;
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
@ -28,38 +27,6 @@ public class SplashActivity extends AppCompatActivity {
|
||||
Logger.devLog = defaultPrefs.getBoolean("developer_logging", false);
|
||||
Logger.logShell = defaultPrefs.getBoolean("shell_logging", false);
|
||||
|
||||
// Set up default preferences,make sure we add "extra" blacklist entries.
|
||||
if (!defaultPrefs.contains("auto_blacklist")) {
|
||||
Logger.dev("SplashActivity: Setting default preferences for application");
|
||||
SharedPreferences.Editor editor = defaultPrefs.edit();
|
||||
Set<String> set = new HashSet<>();
|
||||
set.add("com.google.android.apps.walletnfcrel");
|
||||
set.add("com.google.android.gms");
|
||||
set.add("com.google.commerce.tapandpay");
|
||||
editor.putStringSet("auto_blacklist", set);
|
||||
editor.putBoolean("autoRootEnable", false);
|
||||
editor.putBoolean("root", Utils.rootEnabled());
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
// Set up toggle states based on preferences, start services, disable root if set
|
||||
if (Utils.autoToggleEnabled(getApplicationContext())) {
|
||||
if (!Utils.hasServicePermission(getApplicationContext())) {
|
||||
Utils.toggleAutoRoot(false, getApplicationContext());
|
||||
}
|
||||
}
|
||||
if (Utils.autoToggleEnabled(getApplicationContext())) {
|
||||
if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) {
|
||||
Intent myIntent = new Intent(getApplication(), MonitorService.class);
|
||||
getApplication().startService(myIntent);
|
||||
}
|
||||
} else if (defaultPrefs.getBoolean("keep_root_off", false)) {
|
||||
Utils.toggleRoot(false, getApplication());
|
||||
}
|
||||
|
||||
// Set up quick settings tile
|
||||
Utils.setupQuickSettingsTile(getApplicationContext());
|
||||
|
||||
// Initialize
|
||||
Utils.init(this);
|
||||
|
||||
@ -67,6 +34,7 @@ public class SplashActivity extends AppCompatActivity {
|
||||
.putBoolean("module_done", false)
|
||||
.putBoolean("repo_done", false)
|
||||
.putBoolean("update_check_done", false)
|
||||
.putBoolean("root", Utils.rootEnabled())
|
||||
.apply();
|
||||
|
||||
new Async.CheckUpdates(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
@ -1,27 +0,0 @@
|
||||
package com.topjohnwu.magisk.receivers;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
public class AutoStartReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d("Magisk", "Received Boot call, attempting to start service");
|
||||
Intent myIntent = new Intent(context, MonitorService.class);
|
||||
context.startService(myIntent);
|
||||
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("keep_root_off", false)) {
|
||||
Utils.toggleRoot(false, context);
|
||||
}
|
||||
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("enable_quicktile", false)) {
|
||||
Utils.setupQuickSettingsTile(context);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.topjohnwu.magisk.receivers;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
/**
|
||||
* Receiver for click events on the custom M Quick Settings tile
|
||||
*/
|
||||
public final class PrivateBroadcastReceiver extends BroadcastReceiver {
|
||||
public static final String ACTION_AUTOROOT = "com.topjohnwu.magisk.CUSTOMTILE_ACTION_AUTOROOT";
|
||||
public static final String ACTION_DISABLEROOT = "com.topjohnwu.magisk.CUSTOMTILE_ACTION_DISABLEROOT";
|
||||
public static final String ACTION_ENABLEROOT = "com.topjohnwu.magisk.CUSTOMTILE_ACTION_ENABLEROOT";
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
Log.d("Magisk","Broadcast Receiver, Made it this far! We're trying to " + action);
|
||||
if (ACTION_AUTOROOT.equals(action)) {
|
||||
Utils.toggleAutoRoot(!Utils.autoToggleEnabled(context),context);
|
||||
}
|
||||
if (ACTION_ENABLEROOT.equals(action)) {
|
||||
Utils.toggleAutoRoot(false, context);
|
||||
Utils.toggleRoot(true, context);
|
||||
}
|
||||
if (ACTION_DISABLEROOT.equals(action)) {
|
||||
Utils.toggleAutoRoot(false, context);
|
||||
Utils.toggleRoot(false, context);
|
||||
}
|
||||
|
||||
Utils.setupQuickSettingsTile(context);
|
||||
}
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
package com.topjohnwu.magisk.services;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.topjohnwu.magisk.MainActivity;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class MonitorService extends AccessibilityService {
|
||||
private Boolean disableroot;
|
||||
|
||||
@Override
|
||||
protected void onServiceConnected() {
|
||||
super.onServiceConnected();
|
||||
|
||||
//Configure these here for compatibility with API 13 and below.
|
||||
AccessibilityServiceInfo config = new AccessibilityServiceInfo();
|
||||
config.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
|
||||
config.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
|
||||
disableroot = false;
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
//Just in case this helps
|
||||
config.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
|
||||
|
||||
setServiceInfo(config);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.d("Magisk", "MonitorService: Service created");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.d("Magisk", "MonitorService: Service destroyed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccessibilityEvent(AccessibilityEvent event) {
|
||||
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
|
||||
ComponentName componentName = new ComponentName(
|
||||
event.getPackageName().toString(),
|
||||
event.getClassName().toString()
|
||||
);
|
||||
ActivityInfo activityInfo = tryGetActivity(componentName);
|
||||
boolean isActivity = activityInfo != null;
|
||||
if (isActivity) {
|
||||
Logger.dev("MonitorService: CurrentActivity: " + event.getPackageName());
|
||||
|
||||
String mPackage = componentName.getPackageName();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
if (Utils.autoToggleEnabled(getApplicationContext())) {
|
||||
Set<String> setBlackList = prefs.getStringSet("auto_blacklist", null);
|
||||
|
||||
if (setBlackList != null) {
|
||||
disableroot = setBlackList.contains(mPackage);
|
||||
ForceRoot(!disableroot);
|
||||
String appFriendly = getAppName(mPackage);
|
||||
ShowNotification(disableroot, appFriendly);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ActivityInfo tryGetActivity(ComponentName componentName) {
|
||||
try {
|
||||
return getPackageManager().getActivityInfo(componentName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getAppName(String packageName) {
|
||||
PackageManager pkManager = getPackageManager();
|
||||
ApplicationInfo appInfo;
|
||||
String appName;
|
||||
try {
|
||||
appInfo = pkManager.getApplicationInfo(packageName, 0);
|
||||
appName = (String) ((appInfo != null) ? pkManager.getApplicationLabel(appInfo) : "???");
|
||||
return appName;
|
||||
} catch (final PackageManager.NameNotFoundException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private void ForceRoot(Boolean rootToggle) {
|
||||
|
||||
String rootString = rootToggle ? "on" : "off";
|
||||
if (Utils.rootEnabled() != rootToggle) {
|
||||
Logger.dev("MonitorService: toggling root " + rootString);
|
||||
Utils.toggleRoot(rootToggle, getApplicationContext());
|
||||
if (Utils.rootEnabled() != rootToggle) {
|
||||
Utils.toggleRoot(rootToggle, getApplicationContext());
|
||||
Logger.dev("MonitorService: FORCING to " + rootString);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowNotification(boolean rootAction, String packageName) {
|
||||
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
NotificationCompat.Builder mBuilder;
|
||||
if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("hide_root_notification", false)) {
|
||||
if (rootAction) {
|
||||
|
||||
Intent intent = new Intent(getApplication(), MainActivity.class);
|
||||
intent.putExtra("relaunch", "relaunch");
|
||||
String rootMessage;
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(
|
||||
getApplicationContext(),
|
||||
0,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
if (packageName.equals("")) {
|
||||
rootMessage = "Root has been disabled";
|
||||
} else {
|
||||
rootMessage = "Root has been disabled for " + packageName;
|
||||
}
|
||||
mBuilder =
|
||||
new NotificationCompat.Builder(getApplicationContext())
|
||||
.setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setContentTitle(getApplicationContext().getString(R.string.auto_toggle) + " status changed")
|
||||
.setContentText(rootMessage);
|
||||
int mNotificationId = 1;
|
||||
mNotifyMgr.notify(mNotificationId, mBuilder.build());
|
||||
} else {
|
||||
mNotifyMgr.cancelAll();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterrupt() {
|
||||
}
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
package com.topjohnwu.magisk.services;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
public class TileServiceCompat extends Service {
|
||||
private static BroadcastReceiver clickTileReceiver;
|
||||
|
||||
private static boolean root, autoRoot;
|
||||
|
||||
public static final String TILE_ID = "Magisk";
|
||||
public static final String ACTION_TILE_CLICK = "magisk.ACTION_TILE_CLICK";
|
||||
public static final String EXTRA_CLICK_TYPE = "magisk.EXTRA_CLICK_TYPE";
|
||||
public static final int CLICK_TYPE_UNKNOWN = -1;
|
||||
public static final int CLICK_TYPE_SIMPLE = 0;
|
||||
public static final int CLICK_TYPE_LONG = 1;
|
||||
|
||||
public TileServiceCompat() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
root = true;
|
||||
registerClickTileReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
updateRoots();
|
||||
updateTile();
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
private void updateRoots() {
|
||||
root = Utils.rootEnabled();
|
||||
autoRoot = Utils.autoToggleEnabled(getApplicationContext());
|
||||
}
|
||||
|
||||
|
||||
private void registerClickTileReceiver() {
|
||||
clickTileReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int clickType = intent.getIntExtra(EXTRA_CLICK_TYPE, CLICK_TYPE_UNKNOWN);
|
||||
switch (clickType) {
|
||||
case CLICK_TYPE_SIMPLE:
|
||||
onSimpleClick();
|
||||
break;
|
||||
case CLICK_TYPE_LONG:
|
||||
onLongClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
registerReceiver(clickTileReceiver, new IntentFilter(ACTION_TILE_CLICK));
|
||||
}
|
||||
|
||||
|
||||
private void onSimpleClick() {
|
||||
updateRoots();
|
||||
updateTile();
|
||||
if (autoRoot) {
|
||||
|
||||
Utils.toggleAutoRoot(false, getApplicationContext());
|
||||
if (!Utils.hasServicePermission(getApplicationContext())) {
|
||||
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
sendBroadcast(it);
|
||||
}
|
||||
} else {
|
||||
Utils.toggleRoot(!root, getApplicationContext());
|
||||
}
|
||||
}
|
||||
|
||||
private void onLongClick() {
|
||||
updateRoots();
|
||||
updateTile();
|
||||
Utils.toggleAutoRoot(!autoRoot,getApplicationContext());
|
||||
if (!Utils.hasServicePermission(getApplicationContext())) {
|
||||
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
sendBroadcast(it);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTile() {
|
||||
BroadcastTileIntentBuilder broadcastTileIntentBuilder = new BroadcastTileIntentBuilder(this, TILE_ID);
|
||||
if (autoRoot) {
|
||||
broadcastTileIntentBuilder.setLabel(getApplicationContext().getString(R.string.auto_toggle));
|
||||
broadcastTileIntentBuilder.setIconResource(R.drawable.ic_autoroot_white);
|
||||
|
||||
} else {
|
||||
if (root) {
|
||||
broadcastTileIntentBuilder.setLabel("Root enabled");
|
||||
broadcastTileIntentBuilder.setIconResource(R.drawable.root_white);
|
||||
|
||||
} else {
|
||||
broadcastTileIntentBuilder.setLabel("Root disabled");
|
||||
broadcastTileIntentBuilder.setIconResource(R.drawable.root_grey);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Intent simpleClick = new Intent(ACTION_TILE_CLICK);
|
||||
simpleClick.putExtra(EXTRA_CLICK_TYPE, CLICK_TYPE_SIMPLE);
|
||||
Intent longClick = new Intent(ACTION_TILE_CLICK);
|
||||
longClick.putExtra(EXTRA_CLICK_TYPE, CLICK_TYPE_LONG);
|
||||
|
||||
broadcastTileIntentBuilder.setVisible(true);
|
||||
broadcastTileIntentBuilder.setOnClickBroadcast(simpleClick);
|
||||
broadcastTileIntentBuilder.setOnLongClickBroadcast(longClick);
|
||||
this.sendBroadcast(broadcastTileIntentBuilder.build());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(clickTileReceiver);
|
||||
}
|
||||
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
package com.topjohnwu.magisk.services;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.service.quicksettings.Tile;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public class TileServiceNewApi extends android.service.quicksettings.TileService {
|
||||
private int mRootsState;
|
||||
|
||||
public TileServiceNewApi() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Logger.dev("QST (New): Service start");
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTileAdded() {
|
||||
super.onTileAdded();
|
||||
Logger.dev("QST (New): Tile added");
|
||||
setupState();
|
||||
this.getQsTile().updateTile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
mRootsState = Utils.CheckRootsState(getApplicationContext());
|
||||
switchState(mRootsState);
|
||||
Logger.dev("QST (New): Tile clicked");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStartListening() {
|
||||
super.onStartListening();
|
||||
setupState();
|
||||
Logger.dev("QST (New): Tile is listening");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopListening() {
|
||||
super.onStopListening();
|
||||
Logger.dev("QST (New): Tile stopped listening");
|
||||
}
|
||||
|
||||
private void setupState() {
|
||||
if (!Utils.hasServicePermission(getApplicationContext())) {
|
||||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("autoRootEnable",false).apply();
|
||||
}
|
||||
mRootsState = Utils.CheckRootsState(getApplicationContext());
|
||||
Logger.dev("QST (New): SetupState");
|
||||
Icon iconRoot = Icon.createWithResource(getApplicationContext(), R.drawable.root);
|
||||
Icon iconAuto = Icon.createWithResource(getApplicationContext(), R.drawable.ic_autoroot);
|
||||
Tile tile = getQsTile();
|
||||
Logger.dev("QST: State is " + mRootsState);
|
||||
|
||||
switch (mRootsState) {
|
||||
case 2:
|
||||
tile.setLabel(getApplicationContext().getString(R.string.auto_toggle));
|
||||
tile.setIcon(iconAuto);
|
||||
tile.setState(Tile.STATE_ACTIVE);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
tile.setLabel("Root enabled");
|
||||
tile.setIcon(iconRoot);
|
||||
tile.setState(Tile.STATE_ACTIVE);
|
||||
break;
|
||||
|
||||
default:
|
||||
tile.setLabel("Root disabled");
|
||||
tile.setIcon(iconRoot);
|
||||
tile.setState(Tile.STATE_INACTIVE);
|
||||
break;
|
||||
}
|
||||
|
||||
tile.updateTile();
|
||||
}
|
||||
|
||||
private void switchState(int rootsState) {
|
||||
|
||||
switch (rootsState) {
|
||||
case 2:
|
||||
Utils.toggleRoot(true, getApplicationContext());
|
||||
if (!Utils.hasServicePermission(getApplicationContext())) {
|
||||
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
sendBroadcast(it);
|
||||
}
|
||||
Utils.toggleAutoRoot(false, getApplicationContext());
|
||||
break;
|
||||
case 1:
|
||||
Utils.toggleRoot(false, getApplicationContext());
|
||||
break;
|
||||
case 0:
|
||||
if (!Utils.hasServicePermission(getApplicationContext())) {
|
||||
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
sendBroadcast(it);
|
||||
}
|
||||
Utils.toggleAutoRoot(true, getApplicationContext());
|
||||
break;
|
||||
}
|
||||
this.onStartListening();
|
||||
setupState();
|
||||
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
|
||||
private List<ApplicationInfo> appsList = null;
|
||||
private Context context;
|
||||
private PackageManager packageManager;
|
||||
public SharedPreferences prefs;
|
||||
|
||||
public ApplicationAdapter(Context context, int textViewResourceId,
|
||||
List<ApplicationInfo> appsList) {
|
||||
super(context, textViewResourceId, appsList);
|
||||
this.context = context;
|
||||
this.appsList = appsList;
|
||||
packageManager = context.getPackageManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return ((null != appsList) ? appsList.size() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationInfo getItem(int position) {
|
||||
return ((null != appsList) ? appsList.get(position) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
if (null == view) {
|
||||
LayoutInflater layoutInflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = layoutInflater.inflate(R.layout.list_item_app, null);
|
||||
}
|
||||
|
||||
ApplicationInfo applicationInfo = appsList.get(position);
|
||||
if (null != applicationInfo) {
|
||||
TextView appName = (TextView) view.findViewById(R.id.app_name);
|
||||
TextView packageName = (TextView) view.findViewById(R.id.app_paackage);
|
||||
ImageView iconview = (ImageView) view.findViewById(R.id.app_icon);
|
||||
CheckBox statusview = (CheckBox) view.findViewById(R.id.checkbox);
|
||||
appName.setText(applicationInfo.loadLabel(packageManager));
|
||||
packageName.setText(applicationInfo.packageName);
|
||||
iconview.setImageDrawable(applicationInfo.loadIcon(packageManager));
|
||||
if (CheckApp(applicationInfo.packageName)) {
|
||||
statusview.setChecked(true);
|
||||
} else {
|
||||
statusview.setChecked(false);
|
||||
}
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public void UpdateRootStatusView(int position, View convertView) {
|
||||
View view = convertView;
|
||||
if (null == view) {
|
||||
LayoutInflater layoutInflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = layoutInflater.inflate(R.layout.list_item_app, null);
|
||||
}
|
||||
ApplicationInfo applicationInfo = appsList.get(position);
|
||||
if (null != applicationInfo) {
|
||||
CheckBox statusview = (CheckBox) view.findViewById(R.id.checkbox);
|
||||
if (CheckApp(applicationInfo.packageName)) {
|
||||
statusview.setChecked(true);
|
||||
} else {
|
||||
statusview.setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean CheckApp(String appToCheck) {
|
||||
boolean starter = false;
|
||||
Set<String> set = prefs.getStringSet("auto_blacklist", null);
|
||||
if (set != null) {
|
||||
for (String string : set) {
|
||||
if (string.equals(appToCheck)) {
|
||||
starter = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return starter;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -24,10 +24,6 @@ import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;
|
||||
import com.topjohnwu.magisk.MagiskFragment;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
||||
import com.topjohnwu.magisk.receivers.PrivateBroadcastReceiver;
|
||||
import com.topjohnwu.magisk.services.MonitorService;
|
||||
import com.topjohnwu.magisk.services.TileServiceCompat;
|
||||
import com.topjohnwu.magisk.services.TileServiceNewApi;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@ -88,13 +84,6 @@ public class Utils {
|
||||
return commandExists("su");
|
||||
}
|
||||
|
||||
public static boolean autoToggleEnabled(Context context) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Logger.dev("Utils: AutoRootEnableCheck is " + preferences.getBoolean("autoRootEnable", false));
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("autoRootEnable", false);
|
||||
|
||||
}
|
||||
|
||||
public static boolean createFile(String path) {
|
||||
String command = "touch " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo true; else echo false; fi";
|
||||
return Shell.rootAccess() && Boolean.parseBoolean(Shell.su(command).get(0));
|
||||
@ -112,38 +101,13 @@ public class Utils {
|
||||
} else {
|
||||
Shell.su("rm -rf /magisk/.core/bin", "setprop magisk.root 0");
|
||||
}
|
||||
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("enable_quicktile", false)) {
|
||||
setupQuickSettingsTile(context);
|
||||
}
|
||||
// if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("enable_quicktile", false)) {
|
||||
// setupQuickSettingsTile(context);
|
||||
// }
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("root", b).apply();
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggleAutoRoot(Boolean b, Context context) {
|
||||
Logger.dev("Utils: toggleAutocalled for " + b );
|
||||
if (MagiskFragment.magiskVersion != -1) {
|
||||
if (!Utils.hasServicePermission(context)) {
|
||||
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||
Toast.makeText(context, "Please enable Magisk in accessibility for auto-toggle work.", Toast.LENGTH_LONG).show();
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Logger.dev("Utils: toggleAuto checks passed, setting" + b );
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("autoRootEnable", b).apply();
|
||||
Intent myServiceIntent = new Intent(context, MonitorService.class);
|
||||
myServiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
if (b) {
|
||||
context.startService(myServiceIntent);
|
||||
} else {
|
||||
context.stopService(myServiceIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("enable_quicktile", false)) {
|
||||
setupQuickSettingsTile(context);
|
||||
}
|
||||
}
|
||||
|
||||
static List<String> getModList(String path) {
|
||||
List<String> ret;
|
||||
String command = "find " + path + " -type d -maxdepth 1 ! -name \"*.core\" ! -name \"*lost+found\" ! -name \"*magisk\"";
|
||||
@ -208,195 +172,6 @@ public class Utils {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public static void setupQuickSettingsTile(Context mContext) {
|
||||
Logger.dev("Utils: SetupQuickSettings called");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
Logger.dev("Utils: Starting N quick settings service");
|
||||
Intent serviceIntent = new Intent(mContext, TileServiceNewApi.class);
|
||||
mContext.startService(serviceIntent);
|
||||
|
||||
}
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
||||
Logger.dev("Utils: Marshmallow build detected");
|
||||
String mLabelString;
|
||||
int mRootIcon = R.drawable.root_white;
|
||||
int mAutoRootIcon = R.drawable.ic_autoroot_white;
|
||||
int mRootDisabled = R.drawable.root_grey;
|
||||
int mRootsState = CheckRootsState(mContext);
|
||||
Logger.dev("Utils: Root State returned as " + mRootsState);
|
||||
final Intent enableBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_ENABLEROOT);
|
||||
final Intent disableBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_DISABLEROOT);
|
||||
final Intent autoBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_AUTOROOT);
|
||||
Intent intent;
|
||||
|
||||
int mIcon;
|
||||
switch (mRootsState) {
|
||||
case 2:
|
||||
mLabelString = mContext.getString(R.string.auto_toggle);
|
||||
mIcon = mAutoRootIcon;
|
||||
intent = autoBroadcast;
|
||||
break;
|
||||
case 1:
|
||||
mLabelString = "Root enabled";
|
||||
mIcon = mRootIcon;
|
||||
intent = disableBroadcast;
|
||||
break;
|
||||
case 0:
|
||||
mLabelString = "Root disabled";
|
||||
mIcon = mRootDisabled;
|
||||
intent = enableBroadcast;
|
||||
break;
|
||||
default:
|
||||
mLabelString = "Root disabled";
|
||||
mIcon = mRootDisabled;
|
||||
intent = disableBroadcast;
|
||||
break;
|
||||
}
|
||||
|
||||
Intent tileConfigurationIntent = new BroadcastTileIntentBuilder(mContext, "Magisk")
|
||||
.setLabel(mLabelString)
|
||||
.setIconResource(mIcon)
|
||||
.setOnClickBroadcast(intent)
|
||||
.setOnLongClickBroadcast(autoBroadcast)
|
||||
.setVisible(true)
|
||||
.build();
|
||||
mContext.sendBroadcast(tileConfigurationIntent);
|
||||
mContext.startService(new Intent(mContext, TileServiceCompat.class));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean installTile(Context context) {
|
||||
String qsTileId;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
qsTileId = "custom(com.topjohnwu.magisk/.services.TileServiceNewApi)";
|
||||
} else {
|
||||
qsTileId = "intent(Magisk)";
|
||||
}
|
||||
|
||||
List<String> lines = Shell.su("settings get secure sysui_qs_tiles");
|
||||
if (lines != null && lines.size() == 1) {
|
||||
List<String> tiles = new LinkedList<>(Arrays.asList(lines.get(0).split(",")));
|
||||
Logger.dev("Utils: Current Tile String is " + tiles);
|
||||
if (tiles.size() > 1) {
|
||||
for (String tile : tiles) {
|
||||
if (tile.equals(qsTileId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
tiles.add(Math.round(tiles.size() / 2), qsTileId);
|
||||
String newTiles = TextUtils.join(",", tiles);
|
||||
Logger.dev("Utils: NewtilesString is " + newTiles);
|
||||
Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\"");
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
||||
Utils.refreshService(context);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean uninstallTile(Context context) {
|
||||
|
||||
String qsTileId;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
qsTileId = "custom(com.topjohnwu.magisk/.services.TileServiceNewApi)";
|
||||
} else {
|
||||
qsTileId = "intent(Magisk)";
|
||||
}
|
||||
List<String> lines = Shell.su("settings get secure sysui_qs_tiles");
|
||||
if (lines != null && lines.size() == 1) {
|
||||
List<String> tiles = new LinkedList<>(Arrays.asList(lines.get(0).split(",")));
|
||||
if (tiles.size() > 1) {
|
||||
boolean isPresent = false;
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
if (tiles.get(i).equals(qsTileId)) {
|
||||
isPresent = true;
|
||||
tiles.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isPresent) {
|
||||
String newTiles = TextUtils.join(",", tiles);
|
||||
Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\"");
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
||||
Utils.refreshService(context);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void refreshService(Context context) {
|
||||
context.startService(new Intent(context, TileServiceCompat.class));
|
||||
}
|
||||
|
||||
// Gets an overall state for the quick settings tile
|
||||
// 0 for root disabled, 1 for root enabled (no auto), 2 for auto-root
|
||||
public static int CheckRootsState(Context mContext) {
|
||||
if (autoToggleEnabled(mContext)) {
|
||||
return 2;
|
||||
} else {
|
||||
if (rootEnabled()) {
|
||||
return 1;
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// To check if service is enabled
|
||||
public static boolean hasServicePermission(Context mContext) {
|
||||
int accessibilityEnabled = 0;
|
||||
final String service = mContext.getPackageName() + "/" + MonitorService.class.getCanonicalName();
|
||||
try {
|
||||
accessibilityEnabled = Settings.Secure.getInt(
|
||||
mContext.getApplicationContext().getContentResolver(),
|
||||
android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
|
||||
} catch (Settings.SettingNotFoundException e) {
|
||||
Log.e(TAG, "Error finding setting, default accessibility to not found: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
|
||||
|
||||
if (accessibilityEnabled == 1) {
|
||||
String settingValue = Settings.Secure.getString(
|
||||
mContext.getApplicationContext().getContentResolver(),
|
||||
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
|
||||
if (settingValue != null) {
|
||||
mStringColonSplitter.setString(settingValue);
|
||||
while (mStringColonSplitter.hasNext()) {
|
||||
String accessibilityService = mStringColonSplitter.next();
|
||||
|
||||
if (accessibilityService.equalsIgnoreCase(service)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.v(TAG, "***ACCESSIBILITY IS DISABLED***");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isMyServiceRunning(Class<?> serviceClass, Context context) {
|
||||
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (serviceClass.getName().equals(service.service.getClassName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
|
||||
void onItemClick(View view, int position);
|
||||
|
Reference in New Issue
Block a user