@@ -1297,8 +1297,17 @@ protected String toDebugString(long now) {
12971297 }
12981298 }
12991299
1300- public void confirmCredentials (IAccountManagerResponse response ,
1301- final Account account , final Bundle options , final boolean expectActivityLaunch ) {
1300+ @ Override
1301+ public void confirmCredentialsAsUser (IAccountManagerResponse response ,
1302+ final Account account , final Bundle options , final boolean expectActivityLaunch ,
1303+ int userId ) {
1304+ // Only allow the system process to read accounts of other users
1305+ if (userId != UserHandle .getCallingUserId ()
1306+ && Binder .getCallingUid () != android .os .Process .myUid ()) {
1307+ throw new SecurityException ("User " + UserHandle .getCallingUserId ()
1308+ + " trying to confirm account credentials for " + userId );
1309+ }
1310+
13021311 if (Log .isLoggable (TAG , Log .VERBOSE )) {
13031312 Log .v (TAG , "confirmCredentials: " + account
13041313 + ", response " + response
@@ -1309,7 +1318,7 @@ public void confirmCredentials(IAccountManagerResponse response,
13091318 if (response == null ) throw new IllegalArgumentException ("response is null" );
13101319 if (account == null ) throw new IllegalArgumentException ("account is null" );
13111320 checkManageAccountsPermission ();
1312- UserAccounts accounts = getUserAccountsForCaller ( );
1321+ UserAccounts accounts = getUserAccounts ( userId );
13131322 long identityToken = clearCallingIdentity ();
13141323 try {
13151324 new Session (accounts , response , account .type , expectActivityLaunch ,
@@ -1548,14 +1557,22 @@ private AccountAndUser[] getAccounts(int[] userIds) {
15481557 return runningAccounts .toArray (accountsArray );
15491558 }
15501559
1551- public Account [] getAccounts (String type ) {
1560+ @ Override
1561+ public Account [] getAccountsAsUser (String type , int userId ) {
1562+ // Only allow the system process to read accounts of other users
1563+ if (userId != UserHandle .getCallingUserId ()
1564+ && Binder .getCallingUid () != android .os .Process .myUid ()) {
1565+ throw new SecurityException ("User " + UserHandle .getCallingUserId ()
1566+ + " trying to get account for " + userId );
1567+ }
1568+
15521569 if (Log .isLoggable (TAG , Log .VERBOSE )) {
15531570 Log .v (TAG , "getAccounts: accountType " + type
15541571 + ", caller's uid " + Binder .getCallingUid ()
15551572 + ", pid " + Binder .getCallingPid ());
15561573 }
15571574 checkReadAccountsPermission ();
1558- UserAccounts accounts = getUserAccountsForCaller ( );
1575+ UserAccounts accounts = getUserAccounts ( userId );
15591576 long identityToken = clearCallingIdentity ();
15601577 try {
15611578 synchronized (accounts .cacheLock ) {
@@ -1566,6 +1583,11 @@ public Account[] getAccounts(String type) {
15661583 }
15671584 }
15681585
1586+ @ Override
1587+ public Account [] getAccounts (String type ) {
1588+ return getAccountsAsUser (type , UserHandle .getCallingUserId ());
1589+ }
1590+
15691591 public void getAccountsByFeatures (IAccountManagerResponse response ,
15701592 String type , String [] features ) {
15711593 if (Log .isLoggable (TAG , Log .VERBOSE )) {
0 commit comments