Skip to content

Commit d1bcf62

Browse files
David SuAndroid (Google) Code Review
authored andcommitted
Merge "Backport sendBroadcastAsUserMultiplePermissions to oc-dev" into oc-dev
2 parents b392903 + e57c25a commit d1bcf62

6 files changed

Lines changed: 69 additions & 0 deletions

File tree

core/java/android/app/ContextImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,22 @@ public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPer
992992
}
993993
}
994994

995+
@Override
996+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
997+
String[] receiverPermissions) {
998+
warnIfCallingFromSystemProcess();
999+
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
1000+
try {
1001+
intent.prepareToLeaveProcess(this);
1002+
ActivityManager.getService().broadcastIntent(
1003+
mMainThread.getApplicationThread(), intent, resolvedType, null,
1004+
Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE,
1005+
null, false, false, user.getIdentifier());
1006+
} catch (RemoteException e) {
1007+
throw e.rethrowFromSystemServer();
1008+
}
1009+
}
1010+
9951011
@Override
9961012
public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) {
9971013
warnIfCallingFromSystemProcess();

core/java/android/content/Context.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,33 @@ public abstract void sendBroadcast(@RequiresPermission Intent intent,
19471947
public abstract void sendBroadcastMultiplePermissions(Intent intent,
19481948
String[] receiverPermissions);
19491949

1950+
/**
1951+
* Broadcast the given intent to all interested BroadcastReceivers, allowing
1952+
* an array of required permissions to be enforced. This call is asynchronous; it returns
1953+
* immediately, and you will continue executing while the receivers are run. No results are
1954+
* propagated from receivers and receivers can not abort the broadcast. If you want to allow
1955+
* receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1956+
* using {@link #sendOrderedBroadcast(Intent, String)}.
1957+
*
1958+
* <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1959+
*
1960+
* @param intent The Intent to broadcast; all receivers matching this
1961+
* Intent will receive the broadcast.
1962+
* @param user The user to send the broadcast to.
1963+
* @param receiverPermissions Array of names of permissions that a receiver must hold
1964+
* in order to receive your broadcast.
1965+
* If null or empty, no permissions are required.
1966+
*
1967+
* @see android.content.BroadcastReceiver
1968+
* @see #registerReceiver
1969+
* @see #sendBroadcast(Intent)
1970+
* @see #sendOrderedBroadcast(Intent, String)
1971+
* @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1972+
* @hide
1973+
*/
1974+
public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
1975+
String[] receiverPermissions);
1976+
19501977
/**
19511978
* Broadcast the given intent to all interested BroadcastReceivers, allowing
19521979
* an optional required permission to be enforced. This

core/java/android/content/ContextWrapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,13 @@ public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPer
442442
mBase.sendBroadcastMultiplePermissions(intent, receiverPermissions);
443443
}
444444

445+
/** @hide */
446+
@Override
447+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
448+
String[] receiverPermissions) {
449+
mBase.sendBroadcastAsUserMultiplePermissions(intent, user, receiverPermissions);
450+
}
451+
445452
/** @hide */
446453
@SystemApi
447454
@Override

services/tests/servicestests/src/com/android/server/devicepolicy/DpmMockContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,12 @@ public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPer
646646
spiedContext.sendBroadcastMultiplePermissions(intent, receiverPermissions);
647647
}
648648

649+
@Override
650+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
651+
String[] receiverPermissions) {
652+
spiedContext.sendBroadcastAsUserMultiplePermissions(intent, user, receiverPermissions);
653+
}
654+
649655
@Override
650656
public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) {
651657
spiedContext.sendBroadcast(intent, receiverPermission, options);

test-runner/src/android/test/mock/MockContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPer
352352
throw new UnsupportedOperationException();
353353
}
354354

355+
/** @hide */
356+
@Override
357+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
358+
String[] receiverPermissions) {
359+
throw new UnsupportedOperationException();
360+
}
361+
355362
/** @hide */
356363
@SystemApi
357364
@Override

tests/utils/testutils/java/com/android/internal/util/test/BroadcastInterceptingContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPer
174174
sendBroadcast(intent);
175175
}
176176

177+
@Override
178+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
179+
String[] receiverPermissions) {
180+
sendBroadcast(intent);
181+
}
182+
177183
@Override
178184
public void sendBroadcastAsUser(Intent intent, UserHandle user) {
179185
sendBroadcast(intent);

0 commit comments

Comments
 (0)