第二篇、Android Supersu 屏蔽許可權請求通知 SuReceiver廣播,supersusureceiver

來源:互聯網
上載者:User

第二篇、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這個就是我們所看到的 許可權提醒介面。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.