我们想要去定制Supersu 让其,过滤掉我们自己的应用,不显示权限提醒。我们可以来看看这个su调用系统发送广播。然后我们的Supersu.apk会收到弹窗的广播。我们可以在这里进行拦截过滤。
public class SuReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { if (intent == null) return; String command = intent.getStringExtra("command"); if (command == null) return; int uid = intent.getIntExtra("uid", -1); if (uid == -1) return; int desiredUid = intent.getIntExtra("desired_uid", -1); if (desiredUid == -1) return; String action = intent.getStringExtra("action"); if (action == null) return; String fromName = intent.getStringExtra("from_name"); String desiredName = intent.getStringExtra("desired_name"); final LogEntry le = new LogEntry(); le.uid = uid; le.command = command; le.action = action; le.desiredUid = desiredUid; le.desiredName = desiredName; le.username = fromName; le.date = (int)(System.currentTimeMillis() / 1000); le.getPackageInfo(context); //这里可以对super日志输出的拦截,过滤掉不想打印日志的应用 UidPolicy u = SuperuserDatabaseHelper.addLog(context, le); String toast; if (UidPolicy.ALLOW.equals(action)) {//这里将会弹窗超级应用授权,我们可以在这里判断,让他不显示Toast提示 toast = context.getString(R.string.superuser_granted, le.getName()); } else { toast = context.getString(R.string.superuser_denied, le.getName());//拒绝用户的请求 } if (u != null && !u.notification) return; switch (Settings.getNotificationType(context)) {//是否显示弹窗等。 case Settings.NOTIFICATION_TYPE_NOTIFICATION: NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setTicker(toast) .setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)) .setContentTitle(context.getString(R.string.superuser)) .setContentText(toast) .setSmallIcon(R.drawable.ic_stat_notification); NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, builder.getNotification()); break; case Settings.NOTIFICATION_TYPE_TOAST: Toast.makeText(context, toast, Toast.LENGTH_SHORT).show(); break; } } private static final int NOTIFICATION_ID = 4545; }
下一篇,
下一篇将介绍如何屏蔽授权Acitivty的确认通知
通过su.c
#include "su.h"
/* intent actions */
#define ACTION_REQUEST "start", "-n", REQUESTOR "/" REQUESTOR_PREFIX ".RequestActivity"
#define ACTION_NOTIFY "start", "-n", REQUESTOR "/" REQUESTOR_PREFIX ".NotifyActivity"
#define ACTION_RESULT "broadcast", "-n", REQUESTOR "/" REQUESTOR_PREFIX ".SuReceiver"
#define AM_PATH "/system/bin/app_process", "/system/bin", "com.android.commands.am.Am"
这个我发现,su是通过,shell命令来启动一个权限请求的Acitivty这个就是我们所看到的 权限提醒界面。
时间: 2024-12-23 04:19:02