From 8a8aaf32970242a5b9f4bb3d0c148efb2ea8cf3f Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Wed, 21 Sep 2016 23:36:28 -0500 Subject: [PATCH] More fixes, more breaks... --- app/build.gradle | 6 +- app/src/main/AndroidManifest.xml | 2 +- .../topjohnwu/magisk/AutoRootFragment.java | 28 ++++- .../com/topjohnwu/magisk/RootFragment.java | 59 ++++----- .../com/topjohnwu/magisk/WelcomeActivity.java | 6 + .../magisk/receivers/AutoStartReceiver.java | 4 +- .../magisk/receivers/TileReceiver.java | 4 +- .../magisk/services/MonitorService.java | 33 +++-- ...ileService.java => TileServiceCompat.java} | 9 +- ...ileService.java => TileServiceNewApi.java} | 65 ++++++---- .../magisk/utils/ApplicationAdapter.java | 15 +-- .../com/topjohnwu/magisk/utils/Logger.java | 19 ++- .../topjohnwu/magisk/utils/PrefHelper.java | 14 +-- .../com/topjohnwu/magisk/utils/Utils.java | 19 +-- app/src/main/res/layout/app_list_row.xml | 114 ++++++++++-------- .../main/res/layout/auto_root_fragment.xml | 19 ++- 16 files changed, 238 insertions(+), 178 deletions(-) rename app/src/main/java/com/topjohnwu/magisk/services/{TileService.java => TileServiceCompat.java} (95%) rename app/src/main/java/com/topjohnwu/magisk/services/{QuickSettingTileService.java => TileServiceNewApi.java} (52%) diff --git a/app/build.gradle b/app/build.gradle index eebc46c62..442597aa7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,9 +32,9 @@ repositories { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:recyclerview-v7:24.2.1' - compile 'com.android.support:cardview-v7:24.2.1' - compile 'com.android.support:design:24.2.1' + compile 'com.android.support:recyclerview-v7:24.2.0' + compile 'com.android.support:cardview-v7:24.2.0' + compile 'com.android.support:design:24.2.0' compile 'com.github.d8ahazard:BroadcastTileSupportUpdate:master' compile 'com.jakewharton:butterknife:8.4.0' compile 'com.github.michalis-vitos:aFileChooser:master' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d8f5677ca..06805420f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ android:resource="@xml/accessibilityservice"/> diff --git a/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java b/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java index 8ec9d8852..64f049e9d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java @@ -10,12 +10,15 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.Nullable; +import android.util.Log; +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; @@ -34,7 +37,17 @@ public class AutoRootFragment extends ListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.auto_root_fragment, container, false); + 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 @@ -44,6 +57,7 @@ public class AutoRootFragment extends ListFragment { packageManager = getActivity().getPackageManager(); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (!prefs.contains("auto_blacklist")) { + Logger.dh("AutoRootFragment: Setting default preferences for application"); SharedPreferences.Editor editor = prefs.edit(); Set set = new HashSet<>(); set.add("com.google.android.apps.walletnfcrel"); @@ -63,6 +77,7 @@ public class AutoRootFragment extends ListFragment { @Override public void onListItemClick(ListView l, View v, int position, long id) { + Logger.dh("Click"); super.onListItemClick(l, v, position, id); ApplicationInfo app = applist.get(position); ToggleApp(app.packageName, position, v); @@ -70,10 +85,8 @@ public class AutoRootFragment extends ListFragment { } private void ToggleApp(String appToCheck, int position, View v) { - + Logger.dh("Magisk","AutoRootFragment: ToggleApp called for " + appToCheck); Set blackListSet = prefs.getStringSet("auto_blacklist", null); - - assert blackListSet != null; arrayBlackList = new ArrayList<>(blackListSet); @@ -88,7 +101,10 @@ public class AutoRootFragment extends ListFragment { } } - prefs.edit().putStringSet("auto_blacklist", new HashSet<>(arrayBlackList)).apply(); + Logger.dh("Committing set, value is: " + arrayBlackList.toString()); + SharedPreferences.Editor editor = prefs.edit(); + editor.putStringSet("auto_blacklist", new HashSet<>(arrayBlackList)); + editor.apply(); listadaptor.UpdateRootStatusView(position, v); } @@ -113,7 +129,7 @@ public class AutoRootFragment extends ListFragment { @Override public int compare(ApplicationInfo o1, ApplicationInfo o2) { packageManager = getActivity().getPackageManager(); - return o1.loadLabel(packageManager).toString().compareTo(o2.loadLabel(packageManager).toString()); + return o1.loadLabel(packageManager).toString().compareToIgnoreCase(o2.loadLabel(packageManager).toString()); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java index 6c4bde17a..095a3270b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java @@ -1,10 +1,7 @@ package com.topjohnwu.magisk; -import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; +import android.app.Fragment; import android.content.Intent; -import android.content.IntentFilter; import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.PorterDuff; @@ -12,8 +9,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.Nullable; -import android.app.Fragment; -import android.support.v4.content.LocalBroadcastManager; +import android.support.design.widget.Snackbar; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -23,11 +19,10 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.Switch; import android.widget.TextView; -import android.widget.Toast; import com.topjohnwu.magisk.receivers.Receiver; -import com.topjohnwu.magisk.receivers.RootFragmentReceiver; import com.topjohnwu.magisk.services.MonitorService; +import com.topjohnwu.magisk.utils.PrefHelper; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; @@ -38,7 +33,7 @@ import butterknife.BindColor; import butterknife.BindView; import butterknife.ButterKnife; -public class RootFragment extends Fragment implements Receiver{ +public class RootFragment extends Fragment implements Receiver { public SharedPreferences prefs; @BindView(R.id.progressBar) @@ -91,21 +86,22 @@ public class RootFragment extends Fragment implements Receiver{ int statusUnknown = R.drawable.ic_help; private boolean autoRootStatus; + private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.root_fragment, container, false); + view = inflater.inflate(R.layout.root_fragment, container, false); ButterKnife.bind(this, view); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + autoRootStatus = prefs.getBoolean("autoRootEnable", false); - if (prefs.contains("autoRootEnable")) { - autoRootStatus = prefs.getBoolean("autoRootEnable", false); - rootToggle.setEnabled(false); - } else { - autoRootStatus = false; - rootToggle.setEnabled(true); + if (autoRootStatus) { + if (!Utils.hasServicePermission(getActivity())) { + autoRootStatus = false; + } } + rootToggle.setEnabled(!autoRootStatus); autoRootToggle.setChecked(autoRootStatus); new updateUI().execute(); @@ -115,10 +111,15 @@ public class RootFragment extends Fragment implements Receiver{ }); autoRootToggle.setOnClickListener(toggle -> { - ToggleAutoRoot(autoRootToggle.isChecked()); - new updateUI().execute(); + if (!Utils.hasServicePermission(getActivity())) { + Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); + startActivityForResult(intent, 100); + } else { + ToggleAutoRoot(autoRootToggle.isChecked()); - }); + } + } + ); selinuxToggle.setOnClickListener(toggle -> { Shell.su(((CompoundButton) toggle).isChecked() ? "setenforce 1" : "setenforce 0"); @@ -147,14 +148,12 @@ public class RootFragment extends Fragment implements Receiver{ // Check which request we're responding to Log.d("Magisk", "Got result: " + requestCode + " and " + resultCode); if (requestCode == 100) { - // Make sure the request was successful - if (resultCode == Activity.RESULT_OK) { + if (Utils.hasServicePermission(getActivity())) { Log.d("Magisk", "Got result code OK for permissions"); - + ToggleAutoRoot(true); } else { - autoRootToggle.setEnabled(false); - Toast.makeText(getActivity(), "Auto-root disabled, permissions required.", Toast.LENGTH_LONG).show(); - + autoRootToggle.setChecked(false); + Snackbar.make(view, "Auto-root disabled, permissions required.", Snackbar.LENGTH_LONG).show(); } } else if (requestCode == 420) { @@ -169,10 +168,6 @@ public class RootFragment extends Fragment implements Receiver{ editor.putBoolean("autoRootEnable", (toggleState)); editor.apply(); if (toggleState) { - if (!Utils.hasServicePermission(getActivity())) { - Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); - startActivityForResult(intent, 100); - } Intent myIntent = new Intent(getActivity(), MonitorService.class); getActivity().startService(myIntent); rootToggle.setEnabled(false); @@ -187,6 +182,8 @@ public class RootFragment extends Fragment implements Receiver{ rootToggle.setEnabled(true); } + new updateUI().execute(); + } @Override @@ -206,6 +203,10 @@ public class RootFragment extends Fragment implements Receiver{ protected Void doInBackground(Void... voids) { // Make sure static block invoked Shell.rootAccess(); + // Set up Tile on UI Refresh + if (PrefHelper.CheckBool("enable_quicktile",getActivity())) { + Utils.SetupQuickSettingsTile(getActivity()); + } return null; } diff --git a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java index 67a2ae011..99eef78eb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java @@ -114,6 +114,12 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView } } + @Override + protected void onDestroy() { + super.onDestroy(); + + } + @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/AutoStartReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/AutoStartReceiver.java index 543b3cd23..a8b54fc1b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/AutoStartReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/AutoStartReceiver.java @@ -15,10 +15,10 @@ public class AutoStartReceiver extends BroadcastReceiver { Log.d("Magisk", "Received Boot call, attempting to start service"); Intent myIntent = new Intent(context, MonitorService.class); context.startService(myIntent); - if (PrefHelper.CheckBool("keep_root_off")) { + if (PrefHelper.CheckBool("keep_root_off",context)) { Utils.toggleRoot(false); } - if (PrefHelper.CheckBool("enable_quicktile")) { + if (PrefHelper.CheckBool("enable_quicktile",context)) { Utils.SetupQuickSettingsTile(context); } diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/TileReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/TileReceiver.java index d9fd9a59c..c3023caa5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/TileReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/TileReceiver.java @@ -5,7 +5,7 @@ import android.content.Context; import android.content.Intent; import android.util.Log; -import com.topjohnwu.magisk.services.TileService; +import com.topjohnwu.magisk.services.TileServiceCompat; public class TileReceiver extends BroadcastReceiver { private static final String TAG = "MainReceiver"; @@ -18,7 +18,7 @@ public class TileReceiver extends BroadcastReceiver { String action = intent.getAction(); if (action.equals(Intent.ACTION_BOOT_COMPLETED) || action.equals(Intent.ACTION_USER_PRESENT) || action.equals(Intent.ACTION_SCREEN_ON)) { - context.startService(new Intent(context,TileService.class)); + context.startService(new Intent(context,TileServiceCompat.class)); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java b/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java index f746269d3..93a72b714 100644 --- a/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java +++ b/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java @@ -18,6 +18,7 @@ import android.view.accessibility.AccessibilityEvent; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.WelcomeActivity; +import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.PrefHelper; import com.topjohnwu.magisk.utils.Utils; @@ -50,6 +51,12 @@ public class MonitorService extends AccessibilityService { 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) { @@ -71,11 +78,7 @@ public class MonitorService extends AccessibilityService { if (setBlackList != null) { disableroot = setBlackList.contains(mPackage); - if (disableroot) { - ForceDisableRoot(); - } else { - ForceEnableRoot(); - } + ForceRoot(!disableroot); String appFriendly = getAppName(mPackage); ShowNotification(disableroot, appFriendly); } @@ -105,14 +108,18 @@ public class MonitorService extends AccessibilityService { } } - private void ForceDisableRoot() { - Log.d("Magisk", "MonitorService: Forcedisable called."); - Utils.toggleRoot(false); - if (Utils.rootEnabled()) { - Utils.toggleRoot(false); - Log.d(TAG, "MonitorService: FORCING."); + private void ForceRoot(Boolean rootToggle) { + + String rootString = rootToggle ? "on" : "off"; + if (Utils.rootEnabled() != rootToggle) { + Logger.dh("MonitorService: toggling root " + rootString); + Utils.toggleRoot(rootToggle); + if (Utils.rootEnabled() != rootToggle) { + Utils.toggleRoot(rootToggle); + Logger.dh("MonitorService: FORCING to " + rootString); + } + } - Log.d("Magisk", "MonitorService: Forcedisable called. " + Utils.rootEnabled()); } private void ForceEnableRoot() { @@ -126,7 +133,7 @@ public class MonitorService extends AccessibilityService { private void ShowNotification(boolean rootAction, String packageName) { NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder; - if (!PrefHelper.CheckBool("hide_root_notification")) { + if (!PrefHelper.CheckBool("hide_root_notification", getApplicationContext())) { if (rootAction) { Intent intent = new Intent(getApplication(), WelcomeActivity.class); diff --git a/app/src/main/java/com/topjohnwu/magisk/services/TileService.java b/app/src/main/java/com/topjohnwu/magisk/services/TileServiceCompat.java similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/services/TileService.java rename to app/src/main/java/com/topjohnwu/magisk/services/TileServiceCompat.java index bb09602a6..ab9bd71a4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/services/TileService.java +++ b/app/src/main/java/com/topjohnwu/magisk/services/TileServiceCompat.java @@ -16,10 +16,9 @@ import com.topjohnwu.magisk.utils.Utils; import java.util.List; -public class TileService extends Service { +public class TileServiceCompat extends Service { private static BroadcastReceiver clickTileReceiver; - private static boolean running = false; private static boolean root, autoRoot; public static final String TILE_ID = "com.shovelgrill.magiskmmtile.TILE"; @@ -29,7 +28,7 @@ public class TileService extends Service { public static final int CLICK_TYPE_SIMPLE = 0; public static final int CLICK_TYPE_LONG = 1; - public TileService() { + public TileServiceCompat() { } @Override @@ -40,7 +39,6 @@ public class TileService extends Service { @Override public void onCreate() { super.onCreate(); - running = true; root = true; registerClickTileReceiver(); } @@ -82,7 +80,7 @@ public class TileService extends Service { private void onLongClick() { Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); sendBroadcast(it); - openApp(this,"com.topjohnwu.magisk"); + Utils.toggleAutoRoot(!Utils.autoRootEnabled(getApplicationContext()),getApplicationContext()); } public static boolean openApp(Context context, String packageName) { @@ -133,7 +131,6 @@ public class TileService extends Service { public void onDestroy() { super.onDestroy(); unregisterReceiver(clickTileReceiver); - running = false; } } diff --git a/app/src/main/java/com/topjohnwu/magisk/services/QuickSettingTileService.java b/app/src/main/java/com/topjohnwu/magisk/services/TileServiceNewApi.java similarity index 52% rename from app/src/main/java/com/topjohnwu/magisk/services/QuickSettingTileService.java rename to app/src/main/java/com/topjohnwu/magisk/services/TileServiceNewApi.java index c6cfaf864..814ac1045 100644 --- a/app/src/main/java/com/topjohnwu/magisk/services/QuickSettingTileService.java +++ b/app/src/main/java/com/topjohnwu/magisk/services/TileServiceNewApi.java @@ -1,75 +1,92 @@ package com.topjohnwu.magisk.services; import android.annotation.SuppressLint; +import android.content.SharedPreferences; import android.graphics.drawable.Icon; +import android.preference.PreferenceManager; import android.service.quicksettings.Tile; -import android.service.quicksettings.TileService; import android.util.Log; import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Utils; @SuppressLint("NewApi") -public class QuickSettingTileService extends TileService { +public class TileServiceNewApi extends android.service.quicksettings.TileService implements + SharedPreferences.OnSharedPreferenceChangeListener { private int STATE_CURRENT; - public QuickSettingTileService() { + public TileServiceNewApi() { } + + @Override public void onTileAdded() { super.onTileAdded(); setupState(); + this.getQsTile().updateTile(); } @Override public void onClick() { switchState(); + this.getQsTile().updateTile(); } private void setupState() { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + preferences.registerOnSharedPreferenceChangeListener(this); + Logger.dh("TileService(New): SetupState"); Icon iconRoot = Icon.createWithResource(getApplicationContext(), R.drawable.root); Icon iconAuto = Icon.createWithResource(getApplicationContext(), R.drawable.ic_autoroot); Tile tile = this.getQsTile(); boolean autoRootStatus = Utils.autoRootEnabled(getApplicationContext()); boolean rootStatus = Utils.rootEnabled(); - Log.d("Magisk", "QST: Auto and root are " + autoRootStatus + " and " + rootStatus); - if (autoRootStatus) { + int rootsStatus = Utils.CheckRootsState(getApplicationContext()); + Log.d("Magisk", "QST: Auto and root are " + autoRootStatus + " and " + rootStatus + Utils.CheckRootsState(getApplicationContext())); + if (rootsStatus == 2) { tile.setLabel("Auto-root"); tile.setIcon(iconAuto); tile.setState(Tile.STATE_ACTIVE); - STATE_CURRENT = 0; + + } else if (rootsStatus == 1) { + tile.setLabel("Root enabled"); + tile.setIcon(iconRoot); + tile.setState(Tile.STATE_ACTIVE); + + } else { - if (rootStatus) { - tile.setLabel("Root enabled"); - tile.setIcon(iconRoot); - tile.setState(Tile.STATE_ACTIVE); - STATE_CURRENT = 1; + tile.setLabel("Root disabled"); + tile.setIcon(iconRoot); + tile.setState(Tile.STATE_INACTIVE); - } else { - tile.setLabel("Root disabled"); - tile.setIcon(iconRoot); - tile.setState(Tile.STATE_INACTIVE); - STATE_CURRENT = 2; - } } + tile.updateTile(); } + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) + { + Logger.dh("TileService: Key Change registered for " + key); + if (key.equals("autoRootEnable")) { + + } + } + private void switchState() { - Log.d("Magisk", "QST: Switching state to " + STATE_CURRENT); - switch (STATE_CURRENT) { - case 0: - Utils.toggleRoot(false); + switch (Utils.CheckRootsState(getApplicationContext())) { + case 2: + Utils.toggleRoot(true); Utils.toggleAutoRoot(false, getApplicationContext()); break; case 1: - Utils.toggleAutoRoot(true, getApplicationContext()); + Utils.toggleRoot(false); break; - case 2: - Utils.toggleRoot(true); + case 0: + Utils.toggleAutoRoot(true, getApplicationContext()); break; } setupState(); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java b/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java index 9a108f591..b883dac41 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java @@ -15,7 +15,6 @@ import android.widget.TextView; import com.topjohnwu.magisk.R; -import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -23,7 +22,6 @@ public class ApplicationAdapter extends ArrayAdapter { private List appsList = null; private Context context; private PackageManager packageManager; - public ArrayList arrayList; public SharedPreferences prefs; public ApplicationAdapter(Context context, int textViewResourceId, @@ -99,15 +97,14 @@ public class ApplicationAdapter extends ArrayAdapter { private boolean CheckApp(String appToCheck) { boolean starter = false; - Set set = prefs.getStringSet("auto_blacklist", null); - if (set != null) { - arrayList = new ArrayList<>(set); - for (String string : set) { - if (string.equals(appToCheck)) { - starter = true; - } + Set set = prefs.getStringSet("auto_blacklist", null); + if (set != null) { + for (String string : set) { + if (string.equals(appToCheck)) { + starter = true; } } + } return starter; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java index 9eb6b66a8..296799509 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java @@ -1,15 +1,21 @@ package com.topjohnwu.magisk.utils; +import android.app.Application; +import android.content.Context; import android.util.Log; - - public class Logger { - private static final String LOG_TAG = "Magisk"; + private static final String LOG_TAG = "Magisk: DH"; public static void dh(String msg, Object... args) { - if (PrefHelper.CheckBool("developer_logging")) { + Context context = null; + try { + context = getApplicationUsingReflection(); + } catch (Exception e) { + e.printStackTrace(); + } + if (PrefHelper.CheckBool("developer_logging", context)) { if (args.length == 1 && args[0] instanceof Throwable) { Log.d(LOG_TAG, msg, (Throwable) args[0]); } else { @@ -17,4 +23,9 @@ public class Logger { } } } + + private static Application getApplicationUsingReflection() throws Exception { + return (Application) Class.forName("android.app.AppGlobals") + .getMethod("getInitialApplication").invoke(null, (Object[]) null); + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/PrefHelper.java b/app/src/main/java/com/topjohnwu/magisk/utils/PrefHelper.java index 8a9e93533..2d956ebd4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/PrefHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/PrefHelper.java @@ -10,19 +10,11 @@ public class PrefHelper { } - public static boolean CheckBool(String key) { - Context context = null; - try { - context = getApplicationUsingReflection(); - } catch (Exception e) { - e.printStackTrace(); - } + public static boolean CheckBool(String key, Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(key, false); } - private static Application getApplicationUsingReflection() throws Exception { - return (Application) Class.forName("android.app.AppGlobals") - .getMethod("getInitialApplication").invoke(null, (Object[]) null); - } + } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 8d2b59008..f7e965470 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -30,8 +30,8 @@ import com.topjohnwu.magisk.RootFragment; import com.topjohnwu.magisk.module.BaseModule; import com.topjohnwu.magisk.receivers.PrivateBroadcastReceiver; import com.topjohnwu.magisk.services.MonitorService; -import com.topjohnwu.magisk.services.QuickSettingTileService; -import com.topjohnwu.magisk.services.TileService; +import com.topjohnwu.magisk.services.TileServiceNewApi; +import com.topjohnwu.magisk.services.TileServiceCompat; import java.io.File; import java.io.UnsupportedEncodingException; @@ -71,10 +71,10 @@ public class Utils { if (!Shell.rootAccess()) { Snackbar.make(((Activity) context).findViewById(android.R.id.content), R.string.no_root_access, Snackbar.LENGTH_LONG).show(); } - if (PrefHelper.CheckBool("keep_root_off")) { + if (PrefHelper.CheckBool("keep_root_off",context)) { Utils.toggleRoot(false); } - if (PrefHelper.CheckBool("enable_quicktile")) { + if (PrefHelper.CheckBool("enable_quicktile",context)) { Utils.SetupQuickSettingsTile(context); } } @@ -129,6 +129,7 @@ public class Utils { } else { Shell.su("rm -rf /magisk/.core/bin", "setprop magisk.root 0"); } + } } @@ -212,7 +213,7 @@ public class Utils { public static void SetupQuickSettingsTile(Context mContext) { Logger.dh("Utils: SetupQuickSettings called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - Intent serviceIntent = new Intent(mContext, QuickSettingTileService.class); + Intent serviceIntent = new Intent(mContext, TileServiceNewApi.class); mContext.startService(serviceIntent); } if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { @@ -266,7 +267,7 @@ public class Utils { public static void installTile(Context context) { - String qsTileId = "intent(" + TileService.TILE_ID + ")"; + String qsTileId = "intent(" + TileServiceCompat.TILE_ID + ")"; List lines = Shell.su("settings get secure sysui_qs_tiles"); if (lines != null && lines.size() == 1) { List tiles = new LinkedList(Arrays.asList(lines.get(0).split(","))); @@ -289,7 +290,7 @@ public class Utils { public static void uninstallTile(Context context) { - String qsTileId = "intent(" + TileService.TILE_ID + ")"; + String qsTileId = "intent(" + TileServiceCompat.TILE_ID + ")"; List lines = Shell.su("settings get secure sysui_qs_tiles"); if (lines != null && lines.size() == 1) { List tiles = new LinkedList(Arrays.asList(lines.get(0).split(","))); @@ -318,7 +319,7 @@ public class Utils { private void refreshService(Context context) { - context.startService(new Intent(context, TileService.class)); + context.startService(new Intent(context, TileServiceCompat.class)); } @@ -448,7 +449,7 @@ public class Utils { public static class ModuleComparator implements Comparator { @Override public int compare(BaseModule o1, BaseModule o2) { - return o1.getName().compareTo(o2.getName()); + return o1.getName().compareToIgnoreCase(o2.getName()); } } } \ No newline at end of file diff --git a/app/src/main/res/layout/app_list_row.xml b/app/src/main/res/layout/app_list_row.xml index 793f481a3..8fbea9f7e 100644 --- a/app/src/main/res/layout/app_list_row.xml +++ b/app/src/main/res/layout/app_list_row.xml @@ -1,69 +1,85 @@ + android:background="?android:attr/selectableItemBackground" + card_view:cardCornerRadius="2dp" + card_view:cardElevation="2dp"> + android:scaleType="centerCrop"/> - - + + + + + + + + - - - - - + android:layout_centerVertical="true"> + + diff --git a/app/src/main/res/layout/auto_root_fragment.xml b/app/src/main/res/layout/auto_root_fragment.xml index 3984d2a31..558642cb2 100644 --- a/app/src/main/res/layout/auto_root_fragment.xml +++ b/app/src/main/res/layout/auto_root_fragment.xml @@ -1,15 +1,14 @@ + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical" + android:id="@+id/Top"> + android:divider="@android:color/transparent" + android:dividerHeight="5.0sp" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_margin="15dp"/> \ No newline at end of file