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博客