Skip to content

Commit 10a0df8

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Relax permission requirement for sending broadcasts to other users" into jb-mr1-dev
2 parents bf3218f + 8bf06ed commit 10a0df8

File tree

3 files changed

+22
-48
lines changed

3 files changed

+22
-48
lines changed

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10988,7 +10988,7 @@ public Intent registerReceiver(IApplicationThread caller, String callerPackage,
1098810988
BroadcastQueue queue = broadcastQueueForIntent(intent);
1098910989
BroadcastRecord r = new BroadcastRecord(queue, intent, null,
1099010990
null, -1, -1, null, receivers, null, 0, null, null,
10991-
false, true, true, false, -1);
10991+
false, true, true, -1);
1099210992
queue.enqueueParallelBroadcastLocked(r);
1099310993
queue.scheduleBroadcastsLocked();
1099410994
}
@@ -11081,29 +11081,27 @@ private final int broadcastIntentLocked(ProcessRecord callerApp,
1108111081
Slog.w(TAG, "Broadcast " + intent + " not ordered but result callback requested!");
1108211082
}
1108311083

11084-
boolean onlySendToCaller = false;
11085-
1108611084
// If the caller is trying to send this broadcast to a different
1108711085
// user, verify that is allowed.
1108811086
if (UserHandle.getUserId(callingUid) != userId) {
1108911087
if (checkComponentPermission(
11090-
android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
11091-
callingPid, callingUid, -1, true)
11092-
!= PackageManager.PERMISSION_GRANTED) {
11093-
if (checkComponentPermission(
11094-
android.Manifest.permission.INTERACT_ACROSS_USERS,
11095-
callingPid, callingUid, -1, true)
11096-
== PackageManager.PERMISSION_GRANTED) {
11097-
onlySendToCaller = true;
11098-
} else {
11099-
String msg = "Permission Denial: " + intent.getAction()
11100-
+ " broadcast from " + callerPackage
11101-
+ " asks to send as user " + userId
11102-
+ " but is calling from user " + UserHandle.getUserId(callingUid)
11103-
+ "; this requires "
11104-
+ android.Manifest.permission.INTERACT_ACROSS_USERS;
11105-
Slog.w(TAG, msg);
11106-
throw new SecurityException(msg);
11088+
android.Manifest.permission.INTERACT_ACROSS_USERS,
11089+
callingPid, callingUid, -1, true) != PackageManager.PERMISSION_GRANTED
11090+
&& checkComponentPermission(
11091+
android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
11092+
callingPid, callingUid, -1, true)
11093+
!= PackageManager.PERMISSION_GRANTED) {
11094+
String msg = "Permission Denial: " + intent.getAction()
11095+
+ " broadcast from " + callerPackage
11096+
+ " asks to send as user " + userId
11097+
+ " but is calling from user " + UserHandle.getUserId(callingUid)
11098+
+ "; this requires "
11099+
+ android.Manifest.permission.INTERACT_ACROSS_USERS;
11100+
Slog.w(TAG, msg);
11101+
throw new SecurityException(msg);
11102+
} else {
11103+
if (userId == UserHandle.USER_CURRENT) {
11104+
userId = mCurrentUserId;
1110711105
}
1110811106
}
1110911107
}
@@ -11294,7 +11292,7 @@ private final int broadcastIntentLocked(ProcessRecord callerApp,
1129411292
BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,
1129511293
callerPackage, callingPid, callingUid, requiredPermission,
1129611294
registeredReceivers, resultTo, resultCode, resultData, map,
11297-
ordered, sticky, false, onlySendToCaller, userId);
11295+
ordered, sticky, false, userId);
1129811296
if (DEBUG_BROADCAST) Slog.v(
1129911297
TAG, "Enqueueing parallel broadcast " + r);
1130011298
final boolean replaced = replacePending && queue.replaceParallelBroadcastLocked(r);
@@ -11384,7 +11382,7 @@ private final int broadcastIntentLocked(ProcessRecord callerApp,
1138411382
BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,
1138511383
callerPackage, callingPid, callingUid, requiredPermission,
1138611384
receivers, resultTo, resultCode, resultData, map, ordered,
11387-
sticky, false, onlySendToCaller, userId);
11385+
sticky, false, userId);
1138811386
if (DEBUG_BROADCAST) Slog.v(
1138911387
TAG, "Enqueueing ordered broadcast " + r
1139011388
+ ": prev had " + queue.mOrderedBroadcasts.size());

services/java/com/android/server/am/BroadcastQueue.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,7 @@ private static void performReceiveLocked(ProcessRecord app, IIntentReceiver rece
372372
private final void deliverToRegisteredReceiverLocked(BroadcastRecord r,
373373
BroadcastFilter filter, boolean ordered) {
374374
boolean skip = false;
375-
if (r.onlySendToCaller) {
376-
if (!UserHandle.isSameApp(r.callingUid, filter.owningUid)) {
377-
Slog.w(TAG, "Permission Denial: broadcasting "
378-
+ r.intent.toString()
379-
+ " from " + r.callerPackage + " (pid="
380-
+ r.callingPid + ", uid=" + r.callingUid + ")"
381-
+ " not allowed to go to different app " + filter.owningUid);
382-
skip = true;
383-
}
384-
}
385-
if (!skip && filter.requiredPermission != null) {
375+
if (filter.requiredPermission != null) {
386376
int perm = mService.checkComponentPermission(filter.requiredPermission,
387377
r.callingPid, r.callingUid, -1, true);
388378
if (perm != PackageManager.PERMISSION_GRANTED) {
@@ -667,18 +657,6 @@ final void processNextBroadcast(boolean fromMsg) {
667657
info.activityInfo.name);
668658

669659
boolean skip = false;
670-
if (r.onlySendToCaller) {
671-
if (!UserHandle.isSameApp(r.callingUid, info.activityInfo.applicationInfo.uid)) {
672-
Slog.w(TAG, "Permission Denial: broadcasting "
673-
+ r.intent.toString()
674-
+ " from " + r.callerPackage + " (pid="
675-
+ r.callingPid + ", uid=" + r.callingUid + ")"
676-
+ " to " + component.flattenToShortString()
677-
+ " not allowed to go to different app "
678-
+ info.activityInfo.applicationInfo.uid);
679-
skip = true;
680-
}
681-
}
682660
int perm = mService.checkComponentPermission(info.activityInfo.permission,
683661
r.callingPid, r.callingUid, info.activityInfo.applicationInfo.uid,
684662
info.activityInfo.exported);

services/java/com/android/server/am/BroadcastRecord.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class BroadcastRecord extends Binder {
4444
final boolean ordered; // serialize the send to receivers?
4545
final boolean sticky; // originated from existing sticky data?
4646
final boolean initialSticky; // initial broadcast from register to sticky?
47-
final boolean onlySendToCaller; // only allow receipt by sender's components?
4847
final int userId; // user id this broadcast was for
4948
final String requiredPermission; // a permission the caller has required
5049
final List receivers; // contains BroadcastFilter and ResolveInfo
@@ -170,7 +169,7 @@ else if (o instanceof ResolveInfo)
170169
int _callingPid, int _callingUid, String _requiredPermission,
171170
List _receivers, IIntentReceiver _resultTo, int _resultCode,
172171
String _resultData, Bundle _resultExtras, boolean _serialized,
173-
boolean _sticky, boolean _initialSticky, boolean _onlySendToCaller,
172+
boolean _sticky, boolean _initialSticky,
174173
int _userId) {
175174
queue = _queue;
176175
intent = _intent;
@@ -187,7 +186,6 @@ else if (o instanceof ResolveInfo)
187186
ordered = _serialized;
188187
sticky = _sticky;
189188
initialSticky = _initialSticky;
190-
onlySendToCaller = _onlySendToCaller;
191189
userId = _userId;
192190
nextReceiver = 0;
193191
state = IDLE;

0 commit comments

Comments
 (0)