You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
More fixes, more breaks...
This commit is contained in:
@@ -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);
|
||||
|
||||
+3
-6
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
+41
-24
@@ -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();
|
||||
Reference in New Issue
Block a user