Android13 Context sendOrderedBroadcast流程分析

Context的sendOrderedBroadcast用于发送有序广播,代码如下:

//frameworks/base/core/java/android/content/Context.java
public abstract class Context {
    public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
            @Nullable String receiverPermission);
}

Context是抽象类,由其子类ContextImpl实现:

//frameworks/base/core/java/android/content/ContextImpl.java
class ContextImpl extends Context {
    public void sendOrderedBroadcast(Intent intent, String receiverPermission) {
        warnIfCallingFromSystemProcess();
        String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
        String[] receiverPermissions = receiverPermission == null ? null
                : new String[] {receiverPermission};
        try {
            intent.prepareToLeaveProcess(this);
            ActivityManager.getService().broadcastIntentWithFeature(
                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
                    null, Activity.RESULT_OK, null, null, receiverPermissions,
                    null /*excludedPermissions=*/, null, AppOpsManager.OP_NONE, null, true, false,
                    getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}

 调用ActivityManager的getService获取IActivityManager接口,然后调用IActivityManager的broadcastIntentWithFeature方法,ActivityManager的getService方法如下:

public class ActivityManager {
    public static IActivityManager getService() {
        return IActivityManagerSingleton.get();
    }
}

ActivityManagerService broadcastIntentWithFeature

调用IActivityManager的broadcastIntentWithFeature方法,IActivityManager是一个接口由ActivityManagerService实现,调用ActivityManagerService的broadcastIntentWithFeature方法:

Android13 ActivityManagerService broadcastIntentWithFeature流程分析-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值