Skip to content

Commit 3d92e37

Browse files
David SuAndroid (Google) Code Review
authored andcommitted
Merge "Backport sendBroadcastAsUserMultiplePermissions to oc-dev" into oc-mr1-dev
2 parents 286aa8b + ea7ef4a commit 3d92e37

7 files changed

Lines changed: 70 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
@@ -1008,6 +1008,22 @@ public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPer
10081008
}
10091009
}
10101010

1011+
@Override
1012+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
1013+
String[] receiverPermissions) {
1014+
warnIfCallingFromSystemProcess();
1015+
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
1016+
try {
1017+
intent.prepareToLeaveProcess(this);
1018+
ActivityManager.getService().broadcastIntent(
1019+
mMainThread.getApplicationThread(), intent, resolvedType, null,
1020+
Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE,
1021+
null, false, false, user.getIdentifier());
1022+
} catch (RemoteException e) {
1023+
throw e.rethrowFromSystemServer();
1024+
}
1025+
}
1026+
10111027
@Override
10121028
public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) {
10131029
warnIfCallingFromSystemProcess();

core/java/android/content/Context.java

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

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

451+
/** @hide */
452+
@Override
453+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
454+
String[] receiverPermissions) {
455+
mBase.sendBroadcastAsUserMultiplePermissions(intent, user, receiverPermissions);
456+
}
457+
451458
/** @hide */
452459
@SystemApi
453460
@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
@@ -234,6 +234,12 @@ public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPer
234234
spiedContext.sendBroadcastMultiplePermissions(intent, receiverPermissions);
235235
}
236236

237+
@Override
238+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
239+
String[] receiverPermissions) {
240+
spiedContext.sendBroadcastAsUserMultiplePermissions(intent, user, receiverPermissions);
241+
}
242+
237243
@Override
238244
public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) {
239245
spiedContext.sendBroadcast(intent, receiverPermission, options);

test-runner/api/android-test-mock-current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ package android.test.mock {
133133
method public void sendBroadcastAsUser(android.content.Intent, android.os.UserHandle, java.lang.String);
134134
method public void sendBroadcastAsUser(android.content.Intent, android.os.UserHandle, java.lang.String, android.os.Bundle);
135135
method public void sendBroadcastAsUser(android.content.Intent, android.os.UserHandle, java.lang.String, int);
136+
method public void sendBroadcastAsUserMultiplePermissions(android.content.Intent, android.os.UserHandle, java.lang.String[]);
136137
method public void sendBroadcastMultiplePermissions(android.content.Intent, java.lang.String[]);
137138
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String);
138139
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);

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

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

361+
/** @hide */
362+
@Override
363+
public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
364+
String[] receiverPermissions) {
365+
throw new UnsupportedOperationException();
366+
}
367+
361368
/** @hide */
362369
@SystemApi
363370
@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)