Skip to content

Commit

Permalink
Add Context.sendOrderedBroadcastMultiplePermissions
Browse files Browse the repository at this point in the history
Flag: com.android.bluetooth.ordered_broadcast_multiple_permissions
Test: mma -j68
Bug: 344915071
Change-Id: I8ecf003dc5e1babdbb4e104f548eef9d3562174e
  • Loading branch information
Jakub Pawlowski committed Jul 2, 2024
1 parent 8919ed0 commit d5d8c6e
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/api/system-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3775,6 +3775,7 @@ package android.content {
method @Nullable @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public android.content.Intent registerReceiverForAllUsers(@Nullable android.content.BroadcastReceiver, @NonNull android.content.IntentFilter, @Nullable String, @Nullable android.os.Handler, int);
method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public abstract void sendBroadcastAsUser(@RequiresPermission android.content.Intent, android.os.UserHandle, @Nullable String, @Nullable android.os.Bundle);
method public void sendBroadcastMultiplePermissions(@NonNull android.content.Intent, @NonNull String[], @Nullable android.app.BroadcastOptions);
method @FlaggedApi("android.os.ordered_broadcast_multiple_permissions") public void sendOrderedBroadcastMultiplePermissions(@NonNull android.content.Intent, @NonNull String[], @Nullable String, @Nullable android.content.BroadcastReceiver, @Nullable android.os.Handler, int, @Nullable String, @Nullable android.os.Bundle, @Nullable android.os.Bundle);
method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public void startActivityAsUser(@NonNull @RequiresPermission android.content.Intent, @NonNull android.os.UserHandle);
method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public void startActivityAsUser(@NonNull @RequiresPermission android.content.Intent, @Nullable android.os.Bundle, @NonNull android.os.UserHandle);
field public static final String AMBIENT_CONTEXT_SERVICE = "ambient_context";
Expand Down
27 changes: 25 additions & 2 deletions core/java/android/app/ContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,17 @@ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
String receiverPermission, int appOp, Bundle options, BroadcastReceiver resultReceiver,
Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
String[] receiverPermissions = receiverPermission == null ? null
: new String[] {receiverPermission};
sendOrderedBroadcastAsUserMultiplePermissions(intent, user, receiverPermissions, appOp,
options, resultReceiver, scheduler, initialCode, initialData, initialExtras);
}

@Override
public void sendOrderedBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
String[] receiverPermissions, int appOp, Bundle options,
BroadcastReceiver resultReceiver, Handler scheduler, int initialCode,
String initialData, Bundle initialExtras) {
IIntentReceiver rd = null;
if (resultReceiver != null) {
if (mPackageInfo != null) {
Expand All @@ -1571,8 +1582,6 @@ resultReceiver, getOuterContext(), scheduler, null, false)
}
}
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
String[] receiverPermissions = receiverPermission == null ? null
: new String[] {receiverPermission};
try {
intent.prepareToLeaveProcess(this);
ActivityManager.getService().broadcastIntentWithFeature(
Expand All @@ -1598,6 +1607,20 @@ public void sendOrderedBroadcast(Intent intent, String receiverPermission,
initialExtras);
}

@Override
public void sendOrderedBroadcastMultiplePermissions(Intent intent, String[] receiverPermissions,
String receiverAppOp, BroadcastReceiver resultReceiver, Handler scheduler,
int initialCode, String initialData, @Nullable Bundle initialExtras,
@Nullable Bundle options) {
int intAppOp = AppOpsManager.OP_NONE;
if (!TextUtils.isEmpty(receiverAppOp)) {
intAppOp = AppOpsManager.strOpToOp(receiverAppOp);
}
sendOrderedBroadcastAsUserMultiplePermissions(intent, getUser(), receiverPermissions,
intAppOp, options, resultReceiver, scheduler, initialCode, initialData,
initialExtras);
}

@Override
public void sendOrderedBroadcast(Intent intent, int initialCode, String receiverPermission,
String receiverAppOp, BroadcastReceiver resultReceiver, Handler scheduler,
Expand Down
30 changes: 30 additions & 0 deletions core/java/android/content/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -2915,6 +2915,21 @@ public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
@Nullable String initialData, @Nullable Bundle initialExtras);

/**
* Similar to above but takes array of names of permissions that a receiver must hold in order
* to receive your broadcast. If empty, no permissions are required.
*
* @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
* BroadcastReceiver, Handler, int, String, Bundle)
* @hide
*/
@SuppressWarnings("HiddenAbstractMethod")
@RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract void sendOrderedBroadcastAsUserMultiplePermissions(Intent intent,
UserHandle user, String[] receiverPermissions, int appOp, Bundle options,
BroadcastReceiver resultReceiver, Handler scheduler, int initialCode,
String initialData, Bundle initialExtras);

/**
* Version of
* {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
Expand Down Expand Up @@ -2996,6 +3011,21 @@ public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, int
throw new RuntimeException("Not implemented. Must override in a subclass.");
}

/**
* Like {@link #sendOrderedBroadcast(Intent, String, String, BroadcastReceiver, Handler, int,
* String, Bundle)}, but also allows specification of a list of multiple permissions.
* @hide
*/
@FlaggedApi(Flags.FLAG_ORDERED_BROADCAST_MULTIPLE_PERMISSIONS)
@SystemApi
public void sendOrderedBroadcastMultiplePermissions(
@NonNull Intent intent, @NonNull String[] receiverPermissions,
@Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
@Nullable Handler scheduler, int initialCode, @Nullable String initialData,
@Nullable Bundle initialExtras, @Nullable Bundle options) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
}

/**
* <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
* Intent you are sending stays around after the broadcast is complete,
Expand Down
21 changes: 21 additions & 0 deletions core/java/android/content/ContextWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,16 @@ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
resultReceiver, scheduler, initialCode, initialData, initialExtras);
}

/** @hide */
@Override
public void sendOrderedBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
@Nullable String[] receiverPermission, int appOp, @Nullable Bundle options,
@Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
mBase.sendOrderedBroadcastAsUserMultiplePermissions(intent, user, receiverPermission, appOp,
options, resultReceiver, scheduler, initialCode, initialData, initialExtras);
}

@Override
public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
@Nullable String receiverPermission, @Nullable String receiverAppOp,
Expand All @@ -661,6 +671,17 @@ public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
scheduler, initialCode, initialData, initialExtras);
}

/** @hide */
@Override
public void sendOrderedBroadcastMultiplePermissions(
@NonNull Intent intent, @NonNull String[] receiverPermissions,
@Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
@Nullable Handler scheduler, int initialCode, @Nullable String initialData,
@Nullable Bundle initialExtras, @Nullable Bundle options) {
mBase.sendOrderedBroadcastMultiplePermissions(intent, receiverPermissions, receiverAppOp,
resultReceiver, scheduler, initialCode, initialData, initialExtras, options);
}

@Override
public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, int initialCode,
@Nullable String receiverPermission, @Nullable String receiverAppOp,
Expand Down
8 changes: 8 additions & 0 deletions core/java/android/os/flags.aconfig
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ flag {
bug: "302189431"
}

flag {
name: "ordered_broadcast_multiple_permissions"
is_exported: true
namespace: "bluetooth"
description: "Guards the Context.sendOrderedBroadcastMultiplePermissions API"
bug: "345802719"
}

flag {
name: "battery_saver_supported_check_api"
is_exported: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
throw notSupported();
}

@Override
public void sendOrderedBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
String[] receiverPermissions, int appOp, Bundle options,
BroadcastReceiver resultReceiver, Handler scheduler, int initialCode,
String initialData, Bundle initialExtras) {
throw notSupported();
}

@Override
public void sendStickyBroadcast(Intent intent) {
throw notSupported();
Expand Down
9 changes: 9 additions & 0 deletions test-mock/src/android/test/mock/MockContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,15 @@ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
throw new UnsupportedOperationException();
}

/** @hide */
@Override
public void sendOrderedBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
String[] receiverPermissions, int appOp, Bundle options,
BroadcastReceiver resultReceiver, Handler scheduler, int initialCode,
String initialData, Bundle initialExtras) {
throw new UnsupportedOperationException();
}

@Override
public void sendOrderedBroadcast(Intent intent, String receiverPermission,
String receiverAppOp, BroadcastReceiver resultReceiver, Handler scheduler,
Expand Down

0 comments on commit d5d8c6e

Please sign in to comment.