1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java public Intent registerReceiver(IApplicationThread caller, String callerPackage, IIntentReceiver receiver, IntentFilter filter, String permission, int userId, int flags) { return registerReceiverWithFeature(caller, callerPackage, null, null, receiver, filter, permission, userId, flags); }
public Intent registerReceiverWithFeature(IApplicationThread caller, String callerPackage, String callerFeatureId, String receiverId, IIntentReceiver receiver, IntentFilter filter, String permission, int userId, int flags) { ... ArrayList<StickyBroadcast> stickyBroadcasts = null; ProcessRecord callerApp = null; ...
int callingUid; int callingPid; boolean instantApp; synchronized(this) { callerApp = getRecordForAppLOSP(caller); ... Iterator<String> actions = filter.actionsIterator(); if (actions == null) { ArrayList<String> noAction = new ArrayList<String>(1); noAction.add(null); actions = noAction.iterator(); } boolean onlyProtectedBroadcasts = true;
int[] userIds = { UserHandle.USER_ALL, UserHandle.getUserId(callingUid) }; while (actions.hasNext()) { String action = actions.next(); for (int id : userIds) { ArrayMap<String, ArrayList<StickyBroadcast>> stickies = mStickyBroadcasts.get(id); if (stickies != null) { ArrayList<StickyBroadcast> broadcasts = stickies.get(action); if (broadcasts != null) { if (stickyBroadcasts == null) { stickyBroadcasts = new ArrayList<>(); } stickyBroadcasts.addAll(broadcasts); } } } ... } ... }
final boolean exported = (flags & Context.RECEIVER_EXPORTED) != 0;
ArrayList<StickyBroadcast> allSticky = null; if (stickyBroadcasts != null) { final ContentResolver resolver = mContext.getContentResolver(); for (int i = 0, N = stickyBroadcasts.size(); i < N; i++) { final StickyBroadcast broadcast = stickyBroadcasts.get(i); Intent intent = broadcast.intent; if (instantApp && (intent.getFlags() & Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS) == 0) { continue; } if (filter.match(resolver, intent, true, TAG) >= 0) { if (allSticky == null) { allSticky = new ArrayList<>(); } allSticky.add(broadcast); } } }
...
synchronized (this) { ... ReceiverList rl = mRegisteredReceivers.get(receiver.asBinder()); if (rl == null) { rl = new ReceiverList(this, callerApp, callingPid, callingUid, userId, receiver); if (rl.app != null) { ... rl.app.mReceivers.addReceiver(rl); } else { ... } mRegisteredReceivers.put(receiver.asBinder(), rl); } else if (rl.uid != callingUid) { ... } else if (rl.pid != callingPid) { ... } else if (rl.userId != userId) { ... } BroadcastFilter bf = new BroadcastFilter(filter, rl, callerPackage, callerFeatureId, receiverId, permission, callingUid, userId, instantApp, visibleToInstantApps, exported); if (rl.containsFilter(filter)) { ... } else { rl.add(bf); ... mReceiverResolver.addFilter(getPackageManagerInternal().snapshot(), bf); } ... return sticky; } }
|