You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Whoop whoop
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.PrefHelper;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -125,32 +126,33 @@ 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 (rootAction) {
|
||||
|
||||
if (rootAction) {
|
||||
|
||||
Intent intent = new Intent(getApplication(), WelcomeActivity.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";
|
||||
Intent intent = new Intent(getApplication(), WelcomeActivity.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("Auto-root status changed")
|
||||
.setContentText(rootMessage);
|
||||
int mNotificationId = 1;
|
||||
mNotifyMgr.notify(mNotificationId, mBuilder.build());
|
||||
} else {
|
||||
rootMessage = "Root has been disabled for " + packageName;
|
||||
mNotifyMgr.cancelAll();
|
||||
}
|
||||
mBuilder =
|
||||
new NotificationCompat.Builder(getApplicationContext())
|
||||
.setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setContentTitle("Auto-root status changed")
|
||||
.setContentText(rootMessage);
|
||||
int mNotificationId = 1;
|
||||
mNotifyMgr.notify(mNotificationId, mBuilder.build());
|
||||
} else {
|
||||
mNotifyMgr.cancelAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
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.content.pm.PackageManager;
|
||||
import android.os.IBinder;
|
||||
import android.service.quicksettings.Tile;
|
||||
|
||||
import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TileService 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";
|
||||
public static final String ACTION_TILE_CLICK = "com.shovelgrill.magiskmmtile.ACTION_TILE_CLICK";
|
||||
public static final String EXTRA_CLICK_TYPE = "com.shovelgrill.magiskmmtile.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 TileService() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
running = true;
|
||||
root = true;
|
||||
registerClickTileReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
root = Utils.rootEnabled();
|
||||
autoRoot = Utils.autoRootEnabled(getApplicationContext());
|
||||
updateTile();
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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() {
|
||||
Utils.toggleRoot(!root);
|
||||
}
|
||||
|
||||
private void onLongClick() {
|
||||
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
sendBroadcast(it);
|
||||
openApp(this,"com.topjohnwu.magisk");
|
||||
}
|
||||
|
||||
public static boolean openApp(Context context, String packageName) {
|
||||
PackageManager manager = context.getPackageManager();
|
||||
Intent i = manager.getLaunchIntentForPackage(packageName);
|
||||
if (i == null) {
|
||||
return false;
|
||||
//throw new PackageManager.NameNotFoundException();
|
||||
}
|
||||
i.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateTile() {
|
||||
BroadcastTileIntentBuilder broadcastTileIntentBuilder = new BroadcastTileIntentBuilder(this, TILE_ID);
|
||||
if (autoRoot) {
|
||||
broadcastTileIntentBuilder.setLabel("Auto-root");
|
||||
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);
|
||||
running = false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user