Expose Context.sendOrderedBroadcast with appop
Bug: 143100231
Test: atest ContextTest#testSendOrderedBroadcastWithAppOp
atest ContextTest#testSendOrderedBroadcastWithAppOp_NotGranted
Change-Id: Ia75d0db11f337769eaf3cf5436e09a7d38b0564c
Merged-In: Ia75d0db11f337769eaf3cf5436e09a7d38b0564c
This commit is contained in:
@@ -9769,6 +9769,7 @@ package android.content {
|
||||
method @RequiresPermission("android.permission.INTERACT_ACROSS_USERS") public abstract void sendBroadcastAsUser(@RequiresPermission android.content.Intent, android.os.UserHandle, @Nullable String);
|
||||
method public abstract void sendOrderedBroadcast(@RequiresPermission android.content.Intent, @Nullable String);
|
||||
method public abstract void sendOrderedBroadcast(@NonNull @RequiresPermission android.content.Intent, @Nullable String, @Nullable android.content.BroadcastReceiver, @Nullable android.os.Handler, int, @Nullable String, @Nullable android.os.Bundle);
|
||||
method public void sendOrderedBroadcast(@NonNull @RequiresPermission android.content.Intent, @Nullable String, @Nullable String, @Nullable android.content.BroadcastReceiver, @Nullable android.os.Handler, int, @Nullable String, @Nullable android.os.Bundle);
|
||||
method @RequiresPermission("android.permission.INTERACT_ACROSS_USERS") public abstract void sendOrderedBroadcastAsUser(@RequiresPermission android.content.Intent, android.os.UserHandle, @Nullable String, android.content.BroadcastReceiver, @Nullable android.os.Handler, int, @Nullable String, @Nullable android.os.Bundle);
|
||||
method @Deprecated @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY) public abstract void sendStickyBroadcast(@RequiresPermission android.content.Intent);
|
||||
method @Deprecated @RequiresPermission(allOf={"android.permission.INTERACT_ACROSS_USERS", android.Manifest.permission.BROADCAST_STICKY}) public abstract void sendStickyBroadcastAsUser(@RequiresPermission android.content.Intent, android.os.UserHandle);
|
||||
|
||||
@@ -72,6 +72,7 @@ import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.system.OsConstants;
|
||||
import android.system.StructStat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AndroidRuntimeException;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
@@ -1329,6 +1330,19 @@ class ContextImpl extends Context {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOrderedBroadcast(Intent intent, String receiverPermission,
|
||||
String receiverAppOp, BroadcastReceiver resultReceiver, Handler scheduler,
|
||||
int initialCode, String initialData, @Nullable Bundle initialExtras) {
|
||||
int intAppOp = AppOpsManager.OP_NONE;
|
||||
if (!TextUtils.isEmpty(receiverAppOp)) {
|
||||
intAppOp = AppOpsManager.strOpToOp(receiverAppOp);
|
||||
}
|
||||
sendOrderedBroadcastAsUser(intent, getUser(),
|
||||
receiverPermission, intAppOp, resultReceiver, scheduler, initialCode, initialData,
|
||||
initialExtras);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void sendStickyBroadcast(Intent intent) {
|
||||
|
||||
@@ -2392,6 +2392,44 @@ public abstract class Context {
|
||||
BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
|
||||
@Nullable String initialData, @Nullable Bundle initialExtras);
|
||||
|
||||
/**
|
||||
* Version of
|
||||
* {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
|
||||
* Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
|
||||
* the broadcast will be sent to.
|
||||
*
|
||||
* <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
|
||||
*
|
||||
* @param intent The Intent to broadcast; all receivers matching this
|
||||
* Intent will receive the broadcast.
|
||||
* @param receiverPermission String naming a permissions that
|
||||
* a receiver must hold in order to receive your broadcast.
|
||||
* If null, no permission is required.
|
||||
* @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
|
||||
* required. If both receiverAppOp and receiverPermission are non-null,
|
||||
* a receiver must have both of them to
|
||||
* receive the broadcast
|
||||
* @param resultReceiver Your own BroadcastReceiver to treat as the final
|
||||
* receiver of the broadcast.
|
||||
* @param scheduler A custom Handler with which to schedule the
|
||||
* resultReceiver callback; if null it will be
|
||||
* scheduled in the Context's main thread.
|
||||
* @param initialCode An initial value for the result code. Often
|
||||
* Activity.RESULT_OK.
|
||||
* @param initialData An initial value for the result data. Often
|
||||
* null.
|
||||
* @param initialExtras An initial value for the result extras. Often
|
||||
* null.
|
||||
*
|
||||
* @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
|
||||
*/
|
||||
public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
|
||||
@Nullable String receiverPermission, @Nullable String receiverAppOp,
|
||||
@Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
|
||||
int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
|
||||
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,
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package android.content;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
@@ -61,12 +64,12 @@ public class ContextWrapper extends Context {
|
||||
public ContextWrapper(Context base) {
|
||||
mBase = base;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the base context for this ContextWrapper. All calls will then be
|
||||
* delegated to the base context. Throws
|
||||
* IllegalStateException if a base context has already been set.
|
||||
*
|
||||
*
|
||||
* @param base The new base context for this wrapper.
|
||||
*/
|
||||
protected void attachBaseContext(Context base) {
|
||||
@@ -117,7 +120,7 @@ public class ContextWrapper extends Context {
|
||||
public Context getApplicationContext() {
|
||||
return mBase.getApplicationContext();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setTheme(int resid) {
|
||||
mBase.setTheme(resid);
|
||||
@@ -162,7 +165,7 @@ public class ContextWrapper extends Context {
|
||||
public ApplicationInfo getApplicationInfo() {
|
||||
return mBase.getApplicationInfo();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPackageResourcePath() {
|
||||
return mBase.getPackageResourcePath();
|
||||
@@ -202,13 +205,13 @@ public class ContextWrapper extends Context {
|
||||
|
||||
@Override
|
||||
public FileInputStream openFileInput(String name)
|
||||
throws FileNotFoundException {
|
||||
throws FileNotFoundException {
|
||||
return mBase.openFileInput(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOutputStream openFileOutput(String name, int mode)
|
||||
throws FileNotFoundException {
|
||||
throws FileNotFoundException {
|
||||
return mBase.openFileOutput(name, mode);
|
||||
}
|
||||
|
||||
@@ -442,7 +445,7 @@ public class ContextWrapper extends Context {
|
||||
mBase.startIntentSender(intent, fillInIntent, flagsMask,
|
||||
flagsValues, extraFlags, options);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendBroadcast(Intent intent) {
|
||||
mBase.sendBroadcast(intent);
|
||||
@@ -487,9 +490,9 @@ public class ContextWrapper extends Context {
|
||||
|
||||
@Override
|
||||
public void sendOrderedBroadcast(
|
||||
Intent intent, String receiverPermission, BroadcastReceiver resultReceiver,
|
||||
Handler scheduler, int initialCode, String initialData,
|
||||
Bundle initialExtras) {
|
||||
Intent intent, String receiverPermission, BroadcastReceiver resultReceiver,
|
||||
Handler scheduler, int initialCode, String initialData,
|
||||
Bundle initialExtras) {
|
||||
mBase.sendOrderedBroadcast(intent, receiverPermission,
|
||||
resultReceiver, scheduler, initialCode,
|
||||
initialData, initialExtras);
|
||||
@@ -499,7 +502,8 @@ public class ContextWrapper extends Context {
|
||||
@SystemApi
|
||||
@Override
|
||||
public void sendOrderedBroadcast(
|
||||
Intent intent, String receiverPermission, Bundle options, BroadcastReceiver resultReceiver,
|
||||
Intent intent, String receiverPermission, Bundle options,
|
||||
BroadcastReceiver resultReceiver,
|
||||
Handler scheduler, int initialCode, String initialData,
|
||||
Bundle initialExtras) {
|
||||
mBase.sendOrderedBroadcast(intent, receiverPermission,
|
||||
@@ -510,9 +514,9 @@ public class ContextWrapper extends Context {
|
||||
/** @hide */
|
||||
@Override
|
||||
public void sendOrderedBroadcast(
|
||||
Intent intent, String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
|
||||
Handler scheduler, int initialCode, String initialData,
|
||||
Bundle initialExtras) {
|
||||
Intent intent, String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
|
||||
Handler scheduler, int initialCode, String initialData,
|
||||
Bundle initialExtras) {
|
||||
mBase.sendOrderedBroadcast(intent, receiverPermission, appOp,
|
||||
resultReceiver, scheduler, initialCode,
|
||||
initialData, initialExtras);
|
||||
@@ -569,6 +573,15 @@ public class ContextWrapper extends Context {
|
||||
resultReceiver, scheduler, initialCode, initialData, initialExtras);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
|
||||
@Nullable String receiverPermission, @Nullable String receiverAppOp,
|
||||
@Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
|
||||
int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
|
||||
mBase.sendOrderedBroadcast(intent, receiverPermission, receiverAppOp, resultReceiver,
|
||||
scheduler, initialCode, initialData, initialExtras);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void sendStickyBroadcast(Intent intent) {
|
||||
|
||||
@@ -462,6 +462,13 @@ public class MockContext extends Context {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOrderedBroadcast(Intent intent, String receiverPermission,
|
||||
String receiverAppOp, BroadcastReceiver resultReceiver, Handler scheduler,
|
||||
int initialCode, String initialData, Bundle initialExtras) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStickyBroadcast(Intent intent) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
Reference in New Issue
Block a user