Skip to content

Commit 4120375

Browse files
author
Dianne Hackborn
committed
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
1 parent 176d105 commit 4120375

30 files changed

+443
-411
lines changed

cmds/pm/src/com/android/commands/pm/Pm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,8 @@ private void runClear() {
11201120

11211121
ClearDataObserver obs = new ClearDataObserver();
11221122
try {
1123-
if (!ActivityManagerNative.getDefault().clearApplicationUserData(pkg, obs,
1124-
Binder.getOrigCallingUser())) {
1123+
// XXX TO DO: add user arg
1124+
if (!ActivityManagerNative.getDefault().clearApplicationUserData(pkg, obs, 0)) {
11251125
System.err.println("Failed");
11261126
}
11271127

core/java/android/accounts/AccountManagerService.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ public void getAuthToken(IAccountManagerResponse response, final Account account
10521052
if (account == null) throw new IllegalArgumentException("account is null");
10531053
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
10541054
checkBinderPermission(Manifest.permission.USE_CREDENTIALS);
1055-
UserAccounts accounts = getUserAccountsForCaller();
1055+
final UserAccounts accounts = getUserAccountsForCaller();
10561056
AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo =
10571057
mAuthenticatorCache.getServiceInfo(
10581058
AuthenticatorDescription.newKey(account.type));
@@ -1141,7 +1141,7 @@ public void onResult(Bundle result) {
11411141
if (intent != null && notifyOnAuthFailure && !customTokens) {
11421142
doNotification(mAccounts,
11431143
account, result.getString(AccountManager.KEY_AUTH_FAILED_MESSAGE),
1144-
intent);
1144+
intent, accounts.userId);
11451145
}
11461146
}
11471147
super.onResult(result);
@@ -1152,7 +1152,8 @@ public void onResult(Bundle result) {
11521152
}
11531153
}
11541154

1155-
private void createNoCredentialsPermissionNotification(Account account, Intent intent) {
1155+
private void createNoCredentialsPermissionNotification(Account account, Intent intent,
1156+
int userId) {
11561157
int uid = intent.getIntExtra(
11571158
GrantCredentialsPermissionActivity.EXTRAS_REQUESTING_UID, -1);
11581159
String authTokenType = intent.getStringExtra(
@@ -1172,9 +1173,10 @@ private void createNoCredentialsPermissionNotification(Account account, Intent i
11721173
title = titleAndSubtitle.substring(0, index);
11731174
subtitle = titleAndSubtitle.substring(index + 1);
11741175
}
1175-
n.setLatestEventInfo(mContext,
1176-
title, subtitle,
1177-
PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
1176+
n.setLatestEventInfo(mContext, title, subtitle,
1177+
PendingIntent.getActivityAsUser(mContext, 0, intent,
1178+
PendingIntent.FLAG_CANCEL_CURRENT,
1179+
null, new UserHandle(userId)));
11781180
installNotification(getCredentialPermissionNotificationId(account, authTokenType, uid), n);
11791181
}
11801182

@@ -2083,7 +2085,7 @@ private void dumpUser(UserAccounts userAccounts, FileDescriptor fd, PrintWriter
20832085
}
20842086

20852087
private void doNotification(UserAccounts accounts, Account account, CharSequence message,
2086-
Intent intent) {
2088+
Intent intent, int userId) {
20872089
long identityToken = clearCallingIdentity();
20882090
try {
20892091
if (Log.isLoggable(TAG, Log.VERBOSE)) {
@@ -2093,7 +2095,7 @@ private void doNotification(UserAccounts accounts, Account account, CharSequence
20932095
if (intent.getComponent() != null &&
20942096
GrantCredentialsPermissionActivity.class.getName().equals(
20952097
intent.getComponent().getClassName())) {
2096-
createNoCredentialsPermissionNotification(account, intent);
2098+
createNoCredentialsPermissionNotification(account, intent, userId);
20972099
} else {
20982100
final Integer notificationId = getSigninRequiredNotificationId(accounts, account);
20992101
intent.addCategory(String.valueOf(notificationId));
@@ -2103,8 +2105,9 @@ private void doNotification(UserAccounts accounts, Account account, CharSequence
21032105
mContext.getText(R.string.notification_title).toString();
21042106
n.setLatestEventInfo(mContext,
21052107
String.format(notificationTitleFormat, account.name),
2106-
message, PendingIntent.getActivity(
2107-
mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
2108+
message, PendingIntent.getActivityAsUser(
2109+
mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT,
2110+
null, new UserHandle(userId)));
21082111
installNotification(notificationId, n);
21092112
}
21102113
} finally {

core/java/android/app/Activity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4278,7 +4278,8 @@ public PendingIntent createPendingResult(int requestCode, Intent data,
42784278
ActivityManagerNative.getDefault().getIntentSender(
42794279
ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName,
42804280
mParent == null ? mToken : mParent.mToken,
4281-
mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null);
4281+
mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null,
4282+
UserHandle.myUserId());
42824283
return target != null ? new PendingIntent(target) : null;
42834284
} catch (RemoteException e) {
42844285
// Empty

core/java/android/app/ActivityManager.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.content.pm.ConfigurationInfo;
2828
import android.content.pm.IPackageDataObserver;
2929
import android.content.pm.PackageManager;
30+
import android.content.pm.UserInfo;
3031
import android.content.res.Resources;
3132
import android.graphics.Bitmap;
3233
import android.graphics.Point;
@@ -1225,7 +1226,7 @@ public void getMemoryInfo(MemoryInfo outInfo) {
12251226
public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
12261227
try {
12271228
return ActivityManagerNative.getDefault().clearApplicationUserData(packageName,
1228-
observer, Binder.getOrigCallingUser());
1229+
observer, UserHandle.myUserId());
12291230
} catch (RemoteException e) {
12301231
return false;
12311232
}
@@ -1902,6 +1903,31 @@ public static int checkUidPermission(String permission, int uid) {
19021903
return PackageManager.PERMISSION_DENIED;
19031904
}
19041905

1906+
/** @hide */
1907+
public static int handleIncomingUser(int callingPid, int callingUid, int userId,
1908+
boolean allowAll, boolean requireFull, String name, String callerPackage) {
1909+
if (UserHandle.getUserId(callingUid) == userId) {
1910+
return userId;
1911+
}
1912+
try {
1913+
return ActivityManagerNative.getDefault().handleIncomingUser(callingPid,
1914+
callingUid, userId, allowAll, requireFull, name, callerPackage);
1915+
} catch (RemoteException e) {
1916+
throw new SecurityException("Failed calling activity manager", e);
1917+
}
1918+
}
1919+
1920+
/** @hide */
1921+
public static int getCurrentUser() {
1922+
UserInfo ui;
1923+
try {
1924+
ui = ActivityManagerNative.getDefault().getCurrentUser();
1925+
return ui != null ? ui.id : 0;
1926+
} catch (RemoteException e) {
1927+
return 0;
1928+
}
1929+
}
1930+
19051931
/**
19061932
* Returns the usage statistics of each installed package.
19071933
*

core/java/android/app/ActivityManagerNative.java

Lines changed: 43 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
199199
Configuration config = Configuration.CREATOR.createFromParcel(data);
200200
Bundle options = data.readInt() != 0
201201
? Bundle.CREATOR.createFromParcel(data) : null;
202+
int userId = data.readInt();
202203
int result = startActivityWithConfig(app, intent, resolvedType,
203-
resultTo, resultWho, requestCode, startFlags, config, options);
204+
resultTo, resultWho, requestCode, startFlags, config, options, userId);
204205
reply.writeNoException();
205206
reply.writeInt(result);
206207
return true;
@@ -897,9 +898,10 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
897898
int fl = data.readInt();
898899
Bundle options = data.readInt() != 0
899900
? Bundle.CREATOR.createFromParcel(data) : null;
901+
int userId = data.readInt();
900902
IIntentSender res = getIntentSender(type, packageName, token,
901903
resultWho, requestCode, requestIntents,
902-
requestResolvedTypes, fl, options);
904+
requestResolvedTypes, fl, options, userId);
903905
reply.writeNoException();
904906
reply.writeStrongBinder(res != null ? res.asBinder() : null);
905907
return true;
@@ -934,6 +936,22 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
934936
return true;
935937
}
936938

939+
case HANDLE_INCOMING_USER_TRANSACTION: {
940+
data.enforceInterface(IActivityManager.descriptor);
941+
int callingPid = data.readInt();
942+
int callingUid = data.readInt();
943+
int userId = data.readInt();
944+
boolean allowAll = data.readInt() != 0 ;
945+
boolean requireFull = data.readInt() != 0;
946+
String name = data.readString();
947+
String callerPackage = data.readString();
948+
int res = handleIncomingUser(callingPid, callingUid, userId, allowAll,
949+
requireFull, name, callerPackage);
950+
reply.writeNoException();
951+
reply.writeInt(res);
952+
return true;
953+
}
954+
937955
case SET_PROCESS_LIMIT_TRANSACTION: {
938956
data.enforceInterface(IActivityManager.descriptor);
939957
int max = data.readInt();
@@ -1304,25 +1322,6 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
13041322
return true;
13051323
}
13061324

1307-
case START_ACTIVITY_IN_PACKAGE_TRANSACTION:
1308-
{
1309-
data.enforceInterface(IActivityManager.descriptor);
1310-
int uid = data.readInt();
1311-
Intent intent = Intent.CREATOR.createFromParcel(data);
1312-
String resolvedType = data.readString();
1313-
IBinder resultTo = data.readStrongBinder();
1314-
String resultWho = data.readString();
1315-
int requestCode = data.readInt();
1316-
int startFlags = data.readInt();
1317-
Bundle options = data.readInt() != 0
1318-
? Bundle.CREATOR.createFromParcel(data) : null;
1319-
int result = startActivityInPackage(uid, intent, resolvedType,
1320-
resultTo, resultWho, requestCode, startFlags, options);
1321-
reply.writeNoException();
1322-
reply.writeInt(result);
1323-
return true;
1324-
}
1325-
13261325
case KILL_APPLICATION_WITH_UID_TRANSACTION: {
13271326
data.enforceInterface(IActivityManager.descriptor);
13281327
String pkg = data.readString();
@@ -1489,22 +1488,6 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
14891488
return true;
14901489
}
14911490

1492-
case START_ACTIVITIES_IN_PACKAGE_TRANSACTION:
1493-
{
1494-
data.enforceInterface(IActivityManager.descriptor);
1495-
int uid = data.readInt();
1496-
Intent[] intents = data.createTypedArray(Intent.CREATOR);
1497-
String[] resolvedTypes = data.createStringArray();
1498-
IBinder resultTo = data.readStrongBinder();
1499-
Bundle options = data.readInt() != 0
1500-
? Bundle.CREATOR.createFromParcel(data) : null;
1501-
int result = startActivitiesInPackage(uid, intents, resolvedTypes,
1502-
resultTo, options);
1503-
reply.writeNoException();
1504-
reply.writeInt(result);
1505-
return true;
1506-
}
1507-
15081491
case START_ACTIVITIES_TRANSACTION:
15091492
{
15101493
data.enforceInterface(IActivityManager.descriptor);
@@ -1877,7 +1860,7 @@ public WaitResult startActivityAndWait(IApplicationThread caller, Intent intent,
18771860
public int startActivityWithConfig(IApplicationThread caller, Intent intent,
18781861
String resolvedType, IBinder resultTo, String resultWho,
18791862
int requestCode, int startFlags, Configuration config,
1880-
Bundle options) throws RemoteException {
1863+
Bundle options, int userId) throws RemoteException {
18811864
Parcel data = Parcel.obtain();
18821865
Parcel reply = Parcel.obtain();
18831866
data.writeInterfaceToken(IActivityManager.descriptor);
@@ -1895,6 +1878,7 @@ public int startActivityWithConfig(IApplicationThread caller, Intent intent,
18951878
} else {
18961879
data.writeInt(0);
18971880
}
1881+
data.writeInt(userId);
18981882
mRemote.transact(START_ACTIVITY_TRANSACTION, data, reply, 0);
18991883
reply.readException();
19001884
int result = reply.readInt();
@@ -2840,7 +2824,7 @@ public String getPackageForToken(IBinder token) throws RemoteException
28402824
public IIntentSender getIntentSender(int type,
28412825
String packageName, IBinder token, String resultWho,
28422826
int requestCode, Intent[] intents, String[] resolvedTypes, int flags,
2843-
Bundle options) throws RemoteException {
2827+
Bundle options, int userId) throws RemoteException {
28442828
Parcel data = Parcel.obtain();
28452829
Parcel reply = Parcel.obtain();
28462830
data.writeInterfaceToken(IActivityManager.descriptor);
@@ -2863,6 +2847,7 @@ public IIntentSender getIntentSender(int type,
28632847
} else {
28642848
data.writeInt(0);
28652849
}
2850+
data.writeInt(userId);
28662851
mRemote.transact(GET_INTENT_SENDER_TRANSACTION, data, reply, 0);
28672852
reply.readException();
28682853
IIntentSender res = IIntentSender.Stub.asInterface(
@@ -2905,6 +2890,25 @@ public int getUidForIntentSender(IIntentSender sender) throws RemoteException {
29052890
reply.recycle();
29062891
return res;
29072892
}
2893+
public int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll,
2894+
boolean requireFull, String name, String callerPackage) throws RemoteException {
2895+
Parcel data = Parcel.obtain();
2896+
Parcel reply = Parcel.obtain();
2897+
data.writeInterfaceToken(IActivityManager.descriptor);
2898+
data.writeInt(callingPid);
2899+
data.writeInt(callingUid);
2900+
data.writeInt(userId);
2901+
data.writeInt(allowAll ? 1 : 0);
2902+
data.writeInt(requireFull ? 1 : 0);
2903+
data.writeString(name);
2904+
data.writeString(callerPackage);
2905+
mRemote.transact(HANDLE_INCOMING_USER_TRANSACTION, data, reply, 0);
2906+
reply.readException();
2907+
int res = reply.readInt();
2908+
data.recycle();
2909+
reply.recycle();
2910+
return res;
2911+
}
29082912
public void setProcessLimit(int max) throws RemoteException
29092913
{
29102914
Parcel data = Parcel.obtain();
@@ -3360,34 +3364,6 @@ public void resumeAppSwitches() throws RemoteException {
33603364
data.recycle();
33613365
}
33623366

3363-
public int startActivityInPackage(int uid,
3364-
Intent intent, String resolvedType, IBinder resultTo,
3365-
String resultWho, int requestCode, int startFlags, Bundle options)
3366-
throws RemoteException {
3367-
Parcel data = Parcel.obtain();
3368-
Parcel reply = Parcel.obtain();
3369-
data.writeInterfaceToken(IActivityManager.descriptor);
3370-
data.writeInt(uid);
3371-
intent.writeToParcel(data, 0);
3372-
data.writeString(resolvedType);
3373-
data.writeStrongBinder(resultTo);
3374-
data.writeString(resultWho);
3375-
data.writeInt(requestCode);
3376-
data.writeInt(startFlags);
3377-
if (options != null) {
3378-
data.writeInt(1);
3379-
options.writeToParcel(data, 0);
3380-
} else {
3381-
data.writeInt(0);
3382-
}
3383-
mRemote.transact(START_ACTIVITY_IN_PACKAGE_TRANSACTION, data, reply, 0);
3384-
reply.readException();
3385-
int result = reply.readInt();
3386-
reply.recycle();
3387-
data.recycle();
3388-
return result;
3389-
}
3390-
33913367
public void killApplicationWithUid(String pkg, int uid) throws RemoteException {
33923368
Parcel data = Parcel.obtain();
33933369
Parcel reply = Parcel.obtain();
@@ -3655,30 +3631,6 @@ public int startActivities(IApplicationThread caller,
36553631
return result;
36563632
}
36573633

3658-
public int startActivitiesInPackage(int uid,
3659-
Intent[] intents, String[] resolvedTypes, IBinder resultTo,
3660-
Bundle options) throws RemoteException {
3661-
Parcel data = Parcel.obtain();
3662-
Parcel reply = Parcel.obtain();
3663-
data.writeInterfaceToken(IActivityManager.descriptor);
3664-
data.writeInt(uid);
3665-
data.writeTypedArray(intents, 0);
3666-
data.writeStringArray(resolvedTypes);
3667-
data.writeStrongBinder(resultTo);
3668-
if (options != null) {
3669-
data.writeInt(1);
3670-
options.writeToParcel(data, 0);
3671-
} else {
3672-
data.writeInt(0);
3673-
}
3674-
mRemote.transact(START_ACTIVITIES_IN_PACKAGE_TRANSACTION, data, reply, 0);
3675-
reply.readException();
3676-
int result = reply.readInt();
3677-
reply.recycle();
3678-
data.recycle();
3679-
return result;
3680-
}
3681-
36823634
public int getFrontActivityScreenCompatMode() throws RemoteException {
36833635
Parcel data = Parcel.obtain();
36843636
Parcel reply = Parcel.obtain();

0 commit comments

Comments
 (0)