diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-08-31 14:05:51 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-08-31 15:11:13 -0700 |
commit | 4120375d46091df8527bb701882e056fbb0e6b06 (patch) | |
tree | 30a3e6bb32f1912b8ab687e2ede8cb1cb18fe908 /core | |
parent | 176d105d2f71198966b566d36d4e856a797695c7 (diff) | |
download | frameworks_base-4120375d46091df8527bb701882e056fbb0e6b06.zip frameworks_base-4120375d46091df8527bb701882e056fbb0e6b06.tar.gz frameworks_base-4120375d46091df8527bb701882e056fbb0e6b06.tar.bz2 |
Remove Binder.getOrigCallingUid().
Replaced all remaining places that used it with explicit user
specification.
While doing this, I ran into stuff that was creating PendingIntent
objects (that now need to specify the explicit user they are for),
which are also posting notifications... but have no way to specify
the user for the notification.
So the notification manager in the system process now also gets a
formal concept of a user associated with the notification, which
is passed in to all the necessary aidl calls. I also removed the
old deprecated aidl interface for posting/cancelling notifications,
since we now always need a user supplied.
There is more work that needs to be done here, though. For example
I think we need to be able to specify USER_ALL for a notification that
should be shown to all users (such as low storage or low battery).
Along with that, the PendingIntent creation needs to be tweaked to
be able to handle USER_CURRENT by evaluating the user at the point the
pending intent is sent.
That's for another change, however.
Change-Id: I468e14dce8def0e13e0870571e7c31ed32b6310c
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/accounts/AccountManagerService.java | 23 | ||||
-rw-r--r-- | core/java/android/app/Activity.java | 3 | ||||
-rw-r--r-- | core/java/android/app/ActivityManager.java | 28 | ||||
-rw-r--r-- | core/java/android/app/ActivityManagerNative.java | 134 | ||||
-rw-r--r-- | core/java/android/app/ContextImpl.java | 14 | ||||
-rw-r--r-- | core/java/android/app/IActivityManager.java | 20 | ||||
-rw-r--r-- | core/java/android/app/INotificationManager.aidl | 11 | ||||
-rw-r--r-- | core/java/android/app/NotificationManager.java | 41 | ||||
-rw-r--r-- | core/java/android/app/PendingIntent.java | 31 | ||||
-rw-r--r-- | core/java/android/content/SyncManager.java | 25 | ||||
-rw-r--r-- | core/java/android/os/Binder.java | 28 | ||||
-rw-r--r-- | core/jni/android_util_Binder.cpp | 6 | ||||
-rw-r--r-- | core/tests/coretests/src/android/app/activity/BroadcastTest.java | 4 |
13 files changed, 185 insertions, 183 deletions
diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java index 7a9f285..b749d8e 100644 --- a/core/java/android/accounts/AccountManagerService.java +++ b/core/java/android/accounts/AccountManagerService.java @@ -1052,7 +1052,7 @@ public class AccountManagerService if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); checkBinderPermission(Manifest.permission.USE_CREDENTIALS); - UserAccounts accounts = getUserAccountsForCaller(); + final UserAccounts accounts = getUserAccountsForCaller(); AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo = mAuthenticatorCache.getServiceInfo( AuthenticatorDescription.newKey(account.type)); @@ -1141,7 +1141,7 @@ public class AccountManagerService if (intent != null && notifyOnAuthFailure && !customTokens) { doNotification(mAccounts, account, result.getString(AccountManager.KEY_AUTH_FAILED_MESSAGE), - intent); + intent, accounts.userId); } } super.onResult(result); @@ -1152,7 +1152,8 @@ public class AccountManagerService } } - private void createNoCredentialsPermissionNotification(Account account, Intent intent) { + private void createNoCredentialsPermissionNotification(Account account, Intent intent, + int userId) { int uid = intent.getIntExtra( GrantCredentialsPermissionActivity.EXTRAS_REQUESTING_UID, -1); String authTokenType = intent.getStringExtra( @@ -1172,9 +1173,10 @@ public class AccountManagerService title = titleAndSubtitle.substring(0, index); subtitle = titleAndSubtitle.substring(index + 1); } - n.setLatestEventInfo(mContext, - title, subtitle, - PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); + n.setLatestEventInfo(mContext, title, subtitle, + PendingIntent.getActivityAsUser(mContext, 0, intent, + PendingIntent.FLAG_CANCEL_CURRENT, + null, new UserHandle(userId))); installNotification(getCredentialPermissionNotificationId(account, authTokenType, uid), n); } @@ -2083,7 +2085,7 @@ public class AccountManagerService } private void doNotification(UserAccounts accounts, Account account, CharSequence message, - Intent intent) { + Intent intent, int userId) { long identityToken = clearCallingIdentity(); try { if (Log.isLoggable(TAG, Log.VERBOSE)) { @@ -2093,7 +2095,7 @@ public class AccountManagerService if (intent.getComponent() != null && GrantCredentialsPermissionActivity.class.getName().equals( intent.getComponent().getClassName())) { - createNoCredentialsPermissionNotification(account, intent); + createNoCredentialsPermissionNotification(account, intent, userId); } else { final Integer notificationId = getSigninRequiredNotificationId(accounts, account); intent.addCategory(String.valueOf(notificationId)); @@ -2103,8 +2105,9 @@ public class AccountManagerService mContext.getText(R.string.notification_title).toString(); n.setLatestEventInfo(mContext, String.format(notificationTitleFormat, account.name), - message, PendingIntent.getActivity( - mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); + message, PendingIntent.getActivityAsUser( + mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, + null, new UserHandle(userId))); installNotification(notificationId, n); } } finally { diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index d5580b7..99dfccb 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -4278,7 +4278,8 @@ public class Activity extends ContextThemeWrapper ActivityManagerNative.getDefault().getIntentSender( ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, mParent == null ? mToken : mParent.mToken, - mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null); + mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null, + UserHandle.myUserId()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { // Empty diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 26d8c17..cd22aad 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -27,6 +27,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.ConfigurationInfo; import android.content.pm.IPackageDataObserver; import android.content.pm.PackageManager; +import android.content.pm.UserInfo; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Point; @@ -1225,7 +1226,7 @@ public class ActivityManager { public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { try { return ActivityManagerNative.getDefault().clearApplicationUserData(packageName, - observer, Binder.getOrigCallingUser()); + observer, UserHandle.myUserId()); } catch (RemoteException e) { return false; } @@ -1902,6 +1903,31 @@ public class ActivityManager { return PackageManager.PERMISSION_DENIED; } + /** @hide */ + public static int handleIncomingUser(int callingPid, int callingUid, int userId, + boolean allowAll, boolean requireFull, String name, String callerPackage) { + if (UserHandle.getUserId(callingUid) == userId) { + return userId; + } + try { + return ActivityManagerNative.getDefault().handleIncomingUser(callingPid, + callingUid, userId, allowAll, requireFull, name, callerPackage); + } catch (RemoteException e) { + throw new SecurityException("Failed calling activity manager", e); + } + } + + /** @hide */ + public static int getCurrentUser() { + UserInfo ui; + try { + ui = ActivityManagerNative.getDefault().getCurrentUser(); + return ui != null ? ui.id : 0; + } catch (RemoteException e) { + return 0; + } + } + /** * Returns the usage statistics of each installed package. * diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index 16b7c2a..14ba537 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -199,8 +199,9 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM Configuration config = Configuration.CREATOR.createFromParcel(data); Bundle options = data.readInt() != 0 ? Bundle.CREATOR.createFromParcel(data) : null; + int userId = data.readInt(); int result = startActivityWithConfig(app, intent, resolvedType, - resultTo, resultWho, requestCode, startFlags, config, options); + resultTo, resultWho, requestCode, startFlags, config, options, userId); reply.writeNoException(); reply.writeInt(result); return true; @@ -897,9 +898,10 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM int fl = data.readInt(); Bundle options = data.readInt() != 0 ? Bundle.CREATOR.createFromParcel(data) : null; + int userId = data.readInt(); IIntentSender res = getIntentSender(type, packageName, token, resultWho, requestCode, requestIntents, - requestResolvedTypes, fl, options); + requestResolvedTypes, fl, options, userId); reply.writeNoException(); reply.writeStrongBinder(res != null ? res.asBinder() : null); return true; @@ -934,6 +936,22 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } + case HANDLE_INCOMING_USER_TRANSACTION: { + data.enforceInterface(IActivityManager.descriptor); + int callingPid = data.readInt(); + int callingUid = data.readInt(); + int userId = data.readInt(); + boolean allowAll = data.readInt() != 0 ; + boolean requireFull = data.readInt() != 0; + String name = data.readString(); + String callerPackage = data.readString(); + int res = handleIncomingUser(callingPid, callingUid, userId, allowAll, + requireFull, name, callerPackage); + reply.writeNoException(); + reply.writeInt(res); + return true; + } + case SET_PROCESS_LIMIT_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); int max = data.readInt(); @@ -1304,25 +1322,6 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } - case START_ACTIVITY_IN_PACKAGE_TRANSACTION: - { - data.enforceInterface(IActivityManager.descriptor); - int uid = data.readInt(); - Intent intent = Intent.CREATOR.createFromParcel(data); - String resolvedType = data.readString(); - IBinder resultTo = data.readStrongBinder(); - String resultWho = data.readString(); - int requestCode = data.readInt(); - int startFlags = data.readInt(); - Bundle options = data.readInt() != 0 - ? Bundle.CREATOR.createFromParcel(data) : null; - int result = startActivityInPackage(uid, intent, resolvedType, - resultTo, resultWho, requestCode, startFlags, options); - reply.writeNoException(); - reply.writeInt(result); - return true; - } - case KILL_APPLICATION_WITH_UID_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); String pkg = data.readString(); @@ -1489,22 +1488,6 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } - case START_ACTIVITIES_IN_PACKAGE_TRANSACTION: - { - data.enforceInterface(IActivityManager.descriptor); - int uid = data.readInt(); - Intent[] intents = data.createTypedArray(Intent.CREATOR); - String[] resolvedTypes = data.createStringArray(); - IBinder resultTo = data.readStrongBinder(); - Bundle options = data.readInt() != 0 - ? Bundle.CREATOR.createFromParcel(data) : null; - int result = startActivitiesInPackage(uid, intents, resolvedTypes, - resultTo, options); - reply.writeNoException(); - reply.writeInt(result); - return true; - } - case START_ACTIVITIES_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); @@ -1877,7 +1860,7 @@ class ActivityManagerProxy implements IActivityManager public int startActivityWithConfig(IApplicationThread caller, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, Configuration config, - Bundle options) throws RemoteException { + Bundle options, int userId) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); @@ -1895,6 +1878,7 @@ class ActivityManagerProxy implements IActivityManager } else { data.writeInt(0); } + data.writeInt(userId); mRemote.transact(START_ACTIVITY_TRANSACTION, data, reply, 0); reply.readException(); int result = reply.readInt(); @@ -2840,7 +2824,7 @@ class ActivityManagerProxy implements IActivityManager public IIntentSender getIntentSender(int type, String packageName, IBinder token, String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, int flags, - Bundle options) throws RemoteException { + Bundle options, int userId) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); @@ -2863,6 +2847,7 @@ class ActivityManagerProxy implements IActivityManager } else { data.writeInt(0); } + data.writeInt(userId); mRemote.transact(GET_INTENT_SENDER_TRANSACTION, data, reply, 0); reply.readException(); IIntentSender res = IIntentSender.Stub.asInterface( @@ -2905,6 +2890,25 @@ class ActivityManagerProxy implements IActivityManager reply.recycle(); return res; } + public int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll, + boolean requireFull, String name, String callerPackage) throws RemoteException { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + data.writeInterfaceToken(IActivityManager.descriptor); + data.writeInt(callingPid); + data.writeInt(callingUid); + data.writeInt(userId); + data.writeInt(allowAll ? 1 : 0); + data.writeInt(requireFull ? 1 : 0); + data.writeString(name); + data.writeString(callerPackage); + mRemote.transact(HANDLE_INCOMING_USER_TRANSACTION, data, reply, 0); + reply.readException(); + int res = reply.readInt(); + data.recycle(); + reply.recycle(); + return res; + } public void setProcessLimit(int max) throws RemoteException { Parcel data = Parcel.obtain(); @@ -3360,34 +3364,6 @@ class ActivityManagerProxy implements IActivityManager data.recycle(); } - public int startActivityInPackage(int uid, - Intent intent, String resolvedType, IBinder resultTo, - String resultWho, int requestCode, int startFlags, Bundle options) - throws RemoteException { - Parcel data = Parcel.obtain(); - Parcel reply = Parcel.obtain(); - data.writeInterfaceToken(IActivityManager.descriptor); - data.writeInt(uid); - intent.writeToParcel(data, 0); - data.writeString(resolvedType); - data.writeStrongBinder(resultTo); - data.writeString(resultWho); - data.writeInt(requestCode); - data.writeInt(startFlags); - if (options != null) { - data.writeInt(1); - options.writeToParcel(data, 0); - } else { - data.writeInt(0); - } - mRemote.transact(START_ACTIVITY_IN_PACKAGE_TRANSACTION, data, reply, 0); - reply.readException(); - int result = reply.readInt(); - reply.recycle(); - data.recycle(); - return result; - } - public void killApplicationWithUid(String pkg, int uid) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); @@ -3655,30 +3631,6 @@ class ActivityManagerProxy implements IActivityManager return result; } - public int startActivitiesInPackage(int uid, - Intent[] intents, String[] resolvedTypes, IBinder resultTo, - Bundle options) throws RemoteException { - Parcel data = Parcel.obtain(); - Parcel reply = Parcel.obtain(); - data.writeInterfaceToken(IActivityManager.descriptor); - data.writeInt(uid); - data.writeTypedArray(intents, 0); - data.writeStringArray(resolvedTypes); - data.writeStrongBinder(resultTo); - if (options != null) { - data.writeInt(1); - options.writeToParcel(data, 0); - } else { - data.writeInt(0); - } - mRemote.transact(START_ACTIVITIES_IN_PACKAGE_TRANSACTION, data, reply, 0); - reply.readException(); - int result = reply.readInt(); - reply.recycle(); - data.recycle(); - return result; - } - public int getFrontActivityScreenCompatMode() throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 1b6f84b..408820d 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -994,7 +994,7 @@ class ContextImpl extends Context { ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, Activity.RESULT_OK, null, null, null, false, false, - Binder.getOrigCallingUser()); + UserHandle.myUserId()); } catch (RemoteException e) { } } @@ -1007,7 +1007,7 @@ class ContextImpl extends Context { ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, Activity.RESULT_OK, null, null, receiverPermission, false, false, - Binder.getOrigCallingUser()); + UserHandle.myUserId()); } catch (RemoteException e) { } } @@ -1021,7 +1021,7 @@ class ContextImpl extends Context { ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, Activity.RESULT_OK, null, null, receiverPermission, true, false, - Binder.getOrigCallingUser()); + UserHandle.myUserId()); } catch (RemoteException e) { } } @@ -1054,7 +1054,7 @@ class ContextImpl extends Context { ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, rd, initialCode, initialData, initialExtras, receiverPermission, - true, false, Binder.getOrigCallingUser()); + true, false, UserHandle.myUserId()); } catch (RemoteException e) { } } @@ -1125,7 +1125,7 @@ class ContextImpl extends Context { ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, null, Activity.RESULT_OK, null, null, null, false, true, - Binder.getOrigCallingUser()); + UserHandle.myUserId()); } catch (RemoteException e) { } } @@ -1158,7 +1158,7 @@ class ContextImpl extends Context { ActivityManagerNative.getDefault().broadcastIntent( mMainThread.getApplicationThread(), intent, resolvedType, rd, initialCode, initialData, initialExtras, null, - true, true, Binder.getOrigCallingUser()); + true, true, UserHandle.myUserId()); } catch (RemoteException e) { } } @@ -1173,7 +1173,7 @@ class ContextImpl extends Context { try { intent.setAllowFds(false); ActivityManagerNative.getDefault().unbroadcastIntent( - mMainThread.getApplicationThread(), intent, Binder.getOrigCallingUser()); + mMainThread.getApplicationThread(), intent, UserHandle.myUserId()); } catch (RemoteException e) { } } diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index 70d8445..f7c7013 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -66,7 +66,7 @@ public interface IActivityManager extends IInterface { public int startActivityWithConfig(IApplicationThread caller, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, Configuration newConfig, - Bundle options) throws RemoteException; + Bundle options, int userId) throws RemoteException; public int startActivityIntentSender(IApplicationThread caller, IntentSender intent, Intent fillInIntent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, @@ -177,13 +177,16 @@ public interface IActivityManager extends IInterface { public IIntentSender getIntentSender(int type, String packageName, IBinder token, String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, - int flags, Bundle options) throws RemoteException; + int flags, Bundle options, int userId) throws RemoteException; public void cancelIntentSender(IIntentSender sender) throws RemoteException; public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer, int userId) throws RemoteException; public String getPackageForIntentSender(IIntentSender sender) throws RemoteException; public int getUidForIntentSender(IIntentSender sender) throws RemoteException; + public int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll, + boolean requireFull, String name, String callerPackage) throws RemoteException; + public void setProcessLimit(int max) throws RemoteException; public int getProcessLimit() throws RemoteException; @@ -272,11 +275,6 @@ public interface IActivityManager extends IInterface { public void stopAppSwitches() throws RemoteException; public void resumeAppSwitches() throws RemoteException; - public int startActivityInPackage(int uid, - Intent intent, String resolvedType, IBinder resultTo, - String resultWho, int requestCode, int startFlags, Bundle options) - throws RemoteException; - public void killApplicationWithUid(String pkg, int uid) throws RemoteException; public void closeSystemDialogs(String reason) throws RemoteException; @@ -316,9 +314,6 @@ public interface IActivityManager extends IInterface { public int startActivities(IApplicationThread caller, Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle options) throws RemoteException; - public int startActivitiesInPackage(int uid, - Intent[] intents, String[] resolvedTypes, IBinder resultTo, - Bundle options) throws RemoteException; public int getFrontActivityScreenCompatMode() throws RemoteException; public void setFrontActivityScreenCompatMode(int mode) throws RemoteException; @@ -551,9 +546,8 @@ public interface IActivityManager extends IInterface { int BACKUP_AGENT_CREATED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+90; int UNBIND_BACKUP_AGENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+91; int GET_UID_FOR_INTENT_SENDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+92; + int HANDLE_INCOMING_USER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+93; - - int START_ACTIVITY_IN_PACKAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+94; int KILL_APPLICATION_WITH_UID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+95; int CLOSE_SYSTEM_DIALOGS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+96; int GET_PROCESS_MEMORY_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+97; @@ -580,7 +574,7 @@ public interface IActivityManager extends IInterface { int CHECK_GRANT_URI_PERMISSION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+118; int DUMP_HEAP_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+119; int START_ACTIVITIES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+120; - int START_ACTIVITIES_IN_PACKAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+121; + int ACTIVITY_SLEPT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+122; int GET_FRONT_ACTIVITY_SCREEN_COMPAT_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+123; int SET_FRONT_ACTIVITY_SCREEN_COMPAT_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+124; diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 6f95e26..62d4962 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -24,16 +24,13 @@ import android.content.Intent; /** {@hide} */ interface INotificationManager { - /** @deprecated use {@link #enqueueNotificationWithTag} instead */ - void enqueueNotification(String pkg, int id, in Notification notification, inout int[] idReceived); - /** @deprecated use {@link #cancelNotificationWithTag} instead */ - void cancelNotification(String pkg, int id); - void cancelAllNotifications(String pkg); + void cancelAllNotifications(String pkg, int userId); void enqueueToast(String pkg, ITransientNotification callback, int duration); void cancelToast(String pkg, ITransientNotification callback); - void enqueueNotificationWithTag(String pkg, String tag, int id, in Notification notification, inout int[] idReceived); - void cancelNotificationWithTag(String pkg, String tag, int id); + void enqueueNotificationWithTag(String pkg, String tag, int id, + in Notification notification, inout int[] idReceived, int userId); + void cancelNotificationWithTag(String pkg, String tag, int id, int userId); void setNotificationsEnabledForPackage(String pkg, boolean enabled); boolean areNotificationsEnabledForPackage(String pkg); diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index 69c20b0..c095280 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -21,6 +21,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.UserHandle; import android.util.Log; /** @@ -125,7 +126,27 @@ public class NotificationManager String pkg = mContext.getPackageName(); if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")"); try { - service.enqueueNotificationWithTag(pkg, tag, id, notification, idOut); + service.enqueueNotificationWithTag(pkg, tag, id, notification, idOut, + UserHandle.myUserId()); + if (id != idOut[0]) { + Log.w(TAG, "notify: id corrupted: sent " + id + ", got back " + idOut[0]); + } + } catch (RemoteException e) { + } + } + + /** + * @hide + */ + public void notifyAsUser(String tag, int id, Notification notification, UserHandle user) + { + int[] idOut = new int[1]; + INotificationManager service = getService(); + String pkg = mContext.getPackageName(); + if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")"); + try { + service.enqueueNotificationWithTag(pkg, tag, id, notification, idOut, + user.getIdentifier()); if (id != idOut[0]) { Log.w(TAG, "notify: id corrupted: sent " + id + ", got back " + idOut[0]); } @@ -154,7 +175,21 @@ public class NotificationManager String pkg = mContext.getPackageName(); if (localLOGV) Log.v(TAG, pkg + ": cancel(" + id + ")"); try { - service.cancelNotificationWithTag(pkg, tag, id); + service.cancelNotificationWithTag(pkg, tag, id, UserHandle.myUserId()); + } catch (RemoteException e) { + } + } + + /** + * @hide + */ + public void cancelAsUser(String tag, int id, UserHandle user) + { + INotificationManager service = getService(); + String pkg = mContext.getPackageName(); + if (localLOGV) Log.v(TAG, pkg + ": cancel(" + id + ")"); + try { + service.cancelNotificationWithTag(pkg, tag, id, user.getIdentifier()); } catch (RemoteException e) { } } @@ -169,7 +204,7 @@ public class NotificationManager String pkg = mContext.getPackageName(); if (localLOGV) Log.v(TAG, pkg + ": cancelAll()"); try { - service.cancelAllNotifications(pkg); + service.cancelAllNotifications(pkg, UserHandle.myUserId()); } catch (RemoteException e) { } } diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java index a57c516..bcd42ea 100644 --- a/core/java/android/app/PendingIntent.java +++ b/core/java/android/app/PendingIntent.java @@ -228,7 +228,29 @@ public final class PendingIntent implements Parcelable { ActivityManager.INTENT_SENDER_ACTIVITY, packageName, null, null, requestCode, new Intent[] { intent }, resolvedType != null ? new String[] { resolvedType } : null, - flags, options); + flags, options, UserHandle.myUserId()); + return target != null ? new PendingIntent(target) : null; + } catch (RemoteException e) { + } + return null; + } + + /** + * @hide + */ + public static PendingIntent getActivityAsUser(Context context, int requestCode, + Intent intent, int flags, Bundle options, UserHandle user) { + String packageName = context.getPackageName(); + String resolvedType = intent != null ? intent.resolveTypeIfNeeded( + context.getContentResolver()) : null; + try { + intent.setAllowFds(false); + IIntentSender target = + ActivityManagerNative.getDefault().getIntentSender( + ActivityManager.INTENT_SENDER_ACTIVITY, packageName, + null, null, requestCode, new Intent[] { intent }, + resolvedType != null ? new String[] { resolvedType } : null, + flags, options, user.getIdentifier()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } @@ -334,7 +356,8 @@ public final class PendingIntent implements Parcelable { IIntentSender target = ActivityManagerNative.getDefault().getIntentSender( ActivityManager.INTENT_SENDER_ACTIVITY, packageName, - null, null, requestCode, intents, resolvedTypes, flags, options); + null, null, requestCode, intents, resolvedTypes, flags, options, + UserHandle.myUserId()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } @@ -372,7 +395,7 @@ public final class PendingIntent implements Parcelable { ActivityManager.INTENT_SENDER_BROADCAST, packageName, null, null, requestCode, new Intent[] { intent }, resolvedType != null ? new String[] { resolvedType } : null, - flags, null); + flags, null, UserHandle.myUserId()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } @@ -411,7 +434,7 @@ public final class PendingIntent implements Parcelable { ActivityManager.INTENT_SENDER_SERVICE, packageName, null, null, requestCode, new Intent[] { intent }, resolvedType != null ? new String[] { resolvedType } : null, - flags, null); + flags, null, UserHandle.myUserId()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } diff --git a/core/java/android/content/SyncManager.java b/core/java/android/content/SyncManager.java index ee075b4..6b5e6e2 100644 --- a/core/java/android/content/SyncManager.java +++ b/core/java/android/content/SyncManager.java @@ -980,7 +980,7 @@ public class SyncManager implements OnAccountsUpdateListener { mSyncHandler.sendMessage(msg); } - boolean bindToSyncAdapter(RegisteredServicesCache.ServiceInfo info) { + boolean bindToSyncAdapter(RegisteredServicesCache.ServiceInfo info, int userId) { if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.d(TAG, "bindToSyncAdapter: " + info.componentName + ", connection " + this); } @@ -989,8 +989,9 @@ public class SyncManager implements OnAccountsUpdateListener { intent.setComponent(info.componentName); intent.putExtra(Intent.EXTRA_CLIENT_LABEL, com.android.internal.R.string.sync_binding_label); - intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( - mContext, 0, new Intent(Settings.ACTION_SYNC_SETTINGS), 0)); + intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser( + mContext, 0, new Intent(Settings.ACTION_SYNC_SETTINGS), 0, + null, new UserHandle(userId))); mBound = true; final boolean bindResult = mContext.bindService(intent, this, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND @@ -2132,7 +2133,7 @@ public class SyncManager implements OnAccountsUpdateListener { if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "dispatchSyncOperation: starting " + activeSyncContext); } - if (!activeSyncContext.bindToSyncAdapter(syncAdapterInfo)) { + if (!activeSyncContext.bindToSyncAdapter(syncAdapterInfo, op.userId)) { Log.e(TAG, "Bind attempt failed to " + syncAdapterInfo); closeActiveSyncContext(activeSyncContext); return false; @@ -2255,10 +2256,12 @@ public class SyncManager implements OnAccountsUpdateListener { if (syncResult != null && syncResult.tooManyDeletions) { installHandleTooManyDeletesNotification(syncOperation.account, - syncOperation.authority, syncResult.stats.numDeletes); + syncOperation.authority, syncResult.stats.numDeletes, + syncOperation.userId); } else { - mNotificationMgr.cancel( - syncOperation.account.hashCode() ^ syncOperation.authority.hashCode()); + mNotificationMgr.cancelAsUser(null, + syncOperation.account.hashCode() ^ syncOperation.authority.hashCode(), + new UserHandle(syncOperation.userId)); } if (syncResult != null && syncResult.fullSyncRequested) { @@ -2471,7 +2474,7 @@ public class SyncManager implements OnAccountsUpdateListener { } private void installHandleTooManyDeletesNotification(Account account, String authority, - long numDeletes) { + long numDeletes, int userId) { if (mNotificationMgr == null) return; final ProviderInfo providerInfo = mContext.getPackageManager().resolveContentProvider( @@ -2493,7 +2496,8 @@ public class SyncManager implements OnAccountsUpdateListener { } final PendingIntent pendingIntent = PendingIntent - .getActivity(mContext, 0, clickIntent, PendingIntent.FLAG_CANCEL_CURRENT); + .getActivityAsUser(mContext, 0, clickIntent, + PendingIntent.FLAG_CANCEL_CURRENT, null, new UserHandle(userId)); CharSequence tooManyDeletesDescFormat = mContext.getResources().getText( R.string.contentServiceTooManyDeletesNotificationDesc); @@ -2507,7 +2511,8 @@ public class SyncManager implements OnAccountsUpdateListener { String.format(tooManyDeletesDescFormat.toString(), authorityName), pendingIntent); notification.flags |= Notification.FLAG_ONGOING_EVENT; - mNotificationMgr.notify(account.hashCode() ^ authority.hashCode(), notification); + mNotificationMgr.notifyAsUser(null, account.hashCode() ^ authority.hashCode(), + notification, new UserHandle(userId)); } /** diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java index 5d40456..ea14098 100644 --- a/core/java/android/os/Binder.java +++ b/core/java/android/os/Binder.java @@ -73,34 +73,6 @@ public class Binder implements IBinder { public static final native int getCallingUid(); /** - * Return the original ID of the user assigned to the process that sent you the current - * transaction that is being processed. This uid can be used with higher-level system services - * to determine its identity and check permissions. If the current thread is not currently - * executing an incoming transaction, then its own uid is returned. - * <p/> - * This value cannot be reset by calls to {@link #clearCallingIdentity()}. - * @hide - */ - public static final int getOrigCallingUid() { - if (UserHandle.MU_ENABLED) { - return getOrigCallingUidNative(); - } else { - return getCallingUid(); - } - } - - private static final native int getOrigCallingUidNative(); - - /** - * Utility function to return the user id of the calling process. - * @return userId of the calling process, extracted from the callingUid - * @hide - */ - public static final int getOrigCallingUser() { - return UserHandle.getUserId(getOrigCallingUid()); - } - - /** * Reset the identity of the incoming IPC on the current thread. This can * be useful if, while handling an incoming call, you will be calling * on interfaces of other objects that may be local to your process and diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp index 04dc49f..881d9a0 100644 --- a/core/jni/android_util_Binder.cpp +++ b/core/jni/android_util_Binder.cpp @@ -729,11 +729,6 @@ static jint android_os_Binder_getCallingUid(JNIEnv* env, jobject clazz) return IPCThreadState::self()->getCallingUid(); } -static jint android_os_Binder_getOrigCallingUid(JNIEnv* env, jobject clazz) -{ - return IPCThreadState::self()->getOrigCallingUid(); -} - static jlong android_os_Binder_clearCallingIdentity(JNIEnv* env, jobject clazz) { return IPCThreadState::self()->clearCallingIdentity(); @@ -805,7 +800,6 @@ static const JNINativeMethod gBinderMethods[] = { /* name, signature, funcPtr */ { "getCallingPid", "()I", (void*)android_os_Binder_getCallingPid }, { "getCallingUid", "()I", (void*)android_os_Binder_getCallingUid }, - { "getOrigCallingUidNative", "()I", (void*)android_os_Binder_getOrigCallingUid }, { "clearCallingIdentity", "()J", (void*)android_os_Binder_clearCallingIdentity }, { "restoreCallingIdentity", "(J)V", (void*)android_os_Binder_restoreCallingIdentity }, { "setThreadStrictModePolicy", "(I)V", (void*)android_os_Binder_setThreadStrictModePolicy }, diff --git a/core/tests/coretests/src/android/app/activity/BroadcastTest.java b/core/tests/coretests/src/android/app/activity/BroadcastTest.java index 7f551b0..f28ba7e 100644 --- a/core/tests/coretests/src/android/app/activity/BroadcastTest.java +++ b/core/tests/coretests/src/android/app/activity/BroadcastTest.java @@ -305,7 +305,7 @@ public class BroadcastTest extends ActivityTestsBase { Intent intent = new Intent(LaunchpadActivity.BROADCAST_STICKY1, null); intent.putExtra("test", LaunchpadActivity.DATA_1); ActivityManagerNative.getDefault().unbroadcastIntent(null, intent, - Binder.getOrigCallingUser()); + UserHandle.myUserId()); ActivityManagerNative.broadcastStickyIntent(intent, null, UserHandle.myUserId()); addIntermediate("finished-broadcast"); @@ -323,7 +323,7 @@ public class BroadcastTest extends ActivityTestsBase { ActivityManagerNative.getDefault().unbroadcastIntent( null, new Intent(LaunchpadActivity.BROADCAST_STICKY1, null), - Binder.getOrigCallingUser()); + UserHandle.myUserId()); addIntermediate("finished-unbroadcast"); IntentFilter filter = new IntentFilter(LaunchpadActivity.BROADCAST_STICKY1); |