diff options
| author | Fyodor Kupolov <fkupolov@google.com> | 2015-07-13 19:19:25 -0700 |
|---|---|---|
| committer | Fyodor Kupolov <fkupolov@google.com> | 2015-07-14 17:25:42 -0700 |
| commit | d4fd8c766da8a70e3359bbc7efbbc79496efe71a (patch) | |
| tree | 971bad23792d3f9486e1ef7a0b0fe6f2952c84b9 /core/java/android | |
| parent | b42cb352a350bac198470f65125aa151ecacff13 (diff) | |
Added sendBroadcastMultiplePermissions method
Added Context.sendBroadcastMultiplePermissions(Intent intent, String[]
receiverPermissions) method, which allows an array of required permissions
to be enforced.
Bug: 21852542
Change-Id: I27c9130e8f004b428452501ebc8a36aabde1f343
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ActivityManagerNative.java | 8 | ||||
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 49 | ||||
| -rw-r--r-- | core/java/android/app/IActivityManager.java | 2 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 27 | ||||
| -rw-r--r-- | core/java/android/content/ContextWrapper.java | 6 |
5 files changed, 77 insertions, 15 deletions
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index cc93ac906d06..fc408a8158b6 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -456,14 +456,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM int resultCode = data.readInt(); String resultData = data.readString(); Bundle resultExtras = data.readBundle(); - String perm = data.readString(); + String[] perms = data.readStringArray(); int appOp = data.readInt(); Bundle options = data.readBundle(); boolean serialized = data.readInt() != 0; boolean sticky = data.readInt() != 0; int userId = data.readInt(); int res = broadcastIntent(app, intent, resolvedType, resultTo, - resultCode, resultData, resultExtras, perm, appOp, + resultCode, resultData, resultExtras, perms, appOp, options, serialized, sticky, userId); reply.writeNoException(); reply.writeInt(res); @@ -3007,7 +3007,7 @@ class ActivityManagerProxy implements IActivityManager public int broadcastIntent(IApplicationThread caller, Intent intent, String resolvedType, IIntentReceiver resultTo, int resultCode, String resultData, Bundle map, - String requiredPermission, int appOp, Bundle options, boolean serialized, + String[] requiredPermissions, int appOp, Bundle options, boolean serialized, boolean sticky, int userId) throws RemoteException { Parcel data = Parcel.obtain(); @@ -3020,7 +3020,7 @@ class ActivityManagerProxy implements IActivityManager data.writeInt(resultCode); data.writeString(resultData); data.writeBundle(map); - data.writeString(requiredPermission); + data.writeStringArray(requiredPermissions); data.writeInt(appOp); data.writeBundle(options); data.writeInt(serialized ? 1 : 0); diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 75dd35c5243f..c07140c176c7 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -180,7 +180,7 @@ class ContextImpl extends Context { @GuardedBy("mSync") private File[] mExternalMediaDirs; - private static final String[] EMPTY_FILE_LIST = {}; + private static final String[] EMPTY_STRING_ARRAY = {}; // The system service cache for the system services that are cached per-ContextImpl. final Object[] mServiceCache = SystemServiceRegistry.createServiceCache(); @@ -552,7 +552,7 @@ class ContextImpl extends Context { @Override public String[] fileList() { final String[] list = getFilesDir().list(); - return (list != null) ? list : EMPTY_FILE_LIST; + return (list != null) ? list : EMPTY_STRING_ARRAY; } @Override @@ -591,7 +591,7 @@ class ContextImpl extends Context { @Override public String[] databaseList() { final String[] list = getDatabasesDir().list(); - return (list != null) ? list : EMPTY_FILE_LIST; + return (list != null) ? list : EMPTY_STRING_ARRAY; } @@ -777,11 +777,28 @@ class ContextImpl extends Context { public void sendBroadcast(Intent intent, String receiverPermission) { warnIfCallingFromSystemProcess(); String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); + String[] receiverPermissions = receiverPermission == null ? null + : new String[] {receiverPermission}; try { intent.prepareToLeaveProcess(); ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, - Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, + Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE, + null, false, false, getUserId()); + } catch (RemoteException e) { + throw new RuntimeException("Failure from system", e); + } + } + + @Override + public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPermissions) { + warnIfCallingFromSystemProcess(); + String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); + try { + intent.prepareToLeaveProcess(); + ActivityManagerNative.getDefault().broadcastIntent( + mMainThread.getApplicationThread(), intent, resolvedType, null, + Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE, null, false, false, getUserId()); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); @@ -792,11 +809,13 @@ class ContextImpl extends Context { public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) { warnIfCallingFromSystemProcess(); String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); + String[] receiverPermissions = receiverPermission == null ? null + : new String[] {receiverPermission}; try { intent.prepareToLeaveProcess(); ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, - Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, + Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE, options, false, false, getUserId()); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); @@ -807,11 +826,13 @@ class ContextImpl extends Context { public void sendBroadcast(Intent intent, String receiverPermission, int appOp) { warnIfCallingFromSystemProcess(); String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); + String[] receiverPermissions = receiverPermission == null ? null + : new String[] {receiverPermission}; try { intent.prepareToLeaveProcess(); ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, - Activity.RESULT_OK, null, null, receiverPermission, appOp, null, false, false, + Activity.RESULT_OK, null, null, receiverPermissions, appOp, null, false, false, getUserId()); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); @@ -822,11 +843,13 @@ class ContextImpl extends Context { public void sendOrderedBroadcast(Intent intent, String receiverPermission) { warnIfCallingFromSystemProcess(); String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); + String[] receiverPermissions = receiverPermission == null ? null + : new String[] {receiverPermission}; try { intent.prepareToLeaveProcess(); ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, - Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, + Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE, null, true, false, getUserId()); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); @@ -883,11 +906,13 @@ class ContextImpl extends Context { } } String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); + String[] receiverPermissions = receiverPermission == null ? null + : new String[] {receiverPermission}; try { intent.prepareToLeaveProcess(); ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, rd, - initialCode, initialData, initialExtras, receiverPermission, appOp, + initialCode, initialData, initialExtras, receiverPermissions, appOp, options, true, false, getUserId()); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); @@ -917,11 +942,13 @@ class ContextImpl extends Context { public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, int appOp) { String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); + String[] receiverPermissions = receiverPermission == null ? null + : new String[] {receiverPermission}; try { intent.prepareToLeaveProcess(); ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, - Activity.RESULT_OK, null, null, receiverPermission, appOp, null, false, false, + Activity.RESULT_OK, null, null, receiverPermissions, appOp, null, false, false, user.getIdentifier()); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); @@ -959,11 +986,13 @@ class ContextImpl extends Context { } } String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); + String[] receiverPermissions = receiverPermission == null ? null + : new String[] {receiverPermission}; try { intent.prepareToLeaveProcess(); ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, rd, - initialCode, initialData, initialExtras, receiverPermission, + initialCode, initialData, initialExtras, receiverPermissions, appOp, null, true, false, user.getIdentifier()); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index acce81c9fe5d..1d87d77957fc 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -106,7 +106,7 @@ public interface IActivityManager extends IInterface { public void unregisterReceiver(IIntentReceiver receiver) throws RemoteException; public int broadcastIntent(IApplicationThread caller, Intent intent, String resolvedType, IIntentReceiver resultTo, int resultCode, - String resultData, Bundle map, String requiredPermission, + String resultData, Bundle map, String[] requiredPermissions, int appOp, Bundle options, boolean serialized, boolean sticky, int userId) throws RemoteException; public void unbroadcastIntent(IApplicationThread caller, Intent intent, int userId) throws RemoteException; public void finishReceiver(IBinder who, int resultCode, String resultData, Bundle map, diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 675515b5d12c..0bfe10884906 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -1516,6 +1516,33 @@ public abstract class Context { public abstract void sendBroadcast(Intent intent, @Nullable String receiverPermission); + + /** + * Broadcast the given intent to all interested BroadcastReceivers, allowing + * an array of required permissions to be enforced. This call is asynchronous; it returns + * immediately, and you will continue executing while the receivers are run. No results are + * propagated from receivers and receivers can not abort the broadcast. If you want to allow + * receivers to propagate results or abort the broadcast, you must send an ordered broadcast + * using {@link #sendOrderedBroadcast(Intent, String)}. + * + * <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 receiverPermissions Array of names of permissions that a receiver must hold + * in order to receive your broadcast. + * If null or empty, no permissions are required. + * + * @see android.content.BroadcastReceiver + * @see #registerReceiver + * @see #sendBroadcast(Intent) + * @see #sendOrderedBroadcast(Intent, String) + * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) + * @hide + */ + public abstract void sendBroadcastMultiplePermissions(Intent intent, + String[] receiverPermissions); + /** * Broadcast the given intent to all interested BroadcastReceivers, allowing * an optional required permission to be enforced. This diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java index 4e7c832cff44..8ad3d2163fe7 100644 --- a/core/java/android/content/ContextWrapper.java +++ b/core/java/android/content/ContextWrapper.java @@ -402,6 +402,12 @@ public class ContextWrapper extends Context { } /** @hide */ + @Override + public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPermissions) { + mBase.sendBroadcastMultiplePermissions(intent, receiverPermissions); + } + + /** @hide */ @SystemApi @Override public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) { |
