第二篇、Android Supersu 屏蔽許可權請求通知 SuReceiver廣播,supersusureceiver
我們想要去定製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這個就是我們所看到的 許可權提醒介面。