Skip to content

Commit 26ae600

Browse files
Carlos ValdiviaAndroid (Google) Code Review
authored andcommitted
Merge "Permissions: GET_ACCOUNTS permission cleanup" into mnc-dev
2 parents 7676e40 + e7ed827 commit 26ae600

3 files changed

Lines changed: 199 additions & 127 deletions

File tree

core/java/android/accounts/AbstractAccountAuthenticator.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ public void addAccount(IAccountAuthenticatorResponse response, String accountTyp
138138
new AccountAuthenticatorResponse(response),
139139
accountType, authTokenType, features, options);
140140
if (Log.isLoggable(TAG, Log.VERBOSE)) {
141-
result.keySet(); // force it to be unparcelled
141+
if (result != null) {
142+
result.keySet(); // force it to be unparcelled
143+
}
142144
Log.v(TAG, "addAccount: result " + AccountManager.sanitizeResult(result));
143145
}
144146
if (result != null) {
@@ -160,7 +162,9 @@ public void confirmCredentials(IAccountAuthenticatorResponse response,
160162
final Bundle result = AbstractAccountAuthenticator.this.confirmCredentials(
161163
new AccountAuthenticatorResponse(response), account, options);
162164
if (Log.isLoggable(TAG, Log.VERBOSE)) {
163-
result.keySet(); // force it to be unparcelled
165+
if (result != null) {
166+
result.keySet(); // force it to be unparcelled
167+
}
164168
Log.v(TAG, "confirmCredentials: result "
165169
+ AccountManager.sanitizeResult(result));
166170
}
@@ -185,7 +189,9 @@ public void getAuthTokenLabel(IAccountAuthenticatorResponse response,
185189
result.putString(AccountManager.KEY_AUTH_TOKEN_LABEL,
186190
AbstractAccountAuthenticator.this.getAuthTokenLabel(authTokenType));
187191
if (Log.isLoggable(TAG, Log.VERBOSE)) {
188-
result.keySet(); // force it to be unparcelled
192+
if (result != null) {
193+
result.keySet(); // force it to be unparcelled
194+
}
189195
Log.v(TAG, "getAuthTokenLabel: result "
190196
+ AccountManager.sanitizeResult(result));
191197
}
@@ -209,7 +215,9 @@ public void getAuthToken(IAccountAuthenticatorResponse response,
209215
new AccountAuthenticatorResponse(response), account,
210216
authTokenType, loginOptions);
211217
if (Log.isLoggable(TAG, Log.VERBOSE)) {
212-
result.keySet(); // force it to be unparcelled
218+
if (result != null) {
219+
result.keySet(); // force it to be unparcelled
220+
}
213221
Log.v(TAG, "getAuthToken: result " + AccountManager.sanitizeResult(result));
214222
}
215223
if (result != null) {
@@ -234,7 +242,10 @@ public void updateCredentials(IAccountAuthenticatorResponse response, Account ac
234242
new AccountAuthenticatorResponse(response), account,
235243
authTokenType, loginOptions);
236244
if (Log.isLoggable(TAG, Log.VERBOSE)) {
237-
result.keySet(); // force it to be unparcelled
245+
// Result may be null.
246+
if (result != null) {
247+
result.keySet(); // force it to be unparcelled
248+
}
238249
Log.v(TAG, "updateCredentials: result "
239250
+ AccountManager.sanitizeResult(result));
240251
}
@@ -490,7 +501,7 @@ public abstract Bundle getAuthToken(AccountAuthenticatorResponse response,
490501
* <ul>
491502
* <li> {@link AccountManager#KEY_INTENT}, or
492503
* <li> {@link AccountManager#KEY_ACCOUNT_NAME} and {@link AccountManager#KEY_ACCOUNT_TYPE} of
493-
* the account that was added, or
504+
* the account whose credentials were updated, or
494505
* <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
495506
* indicate an error
496507
* </ul>

core/java/android/accounts/AccountManager.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public String getPassword(final Account account) {
333333
try {
334334
return mService.getPassword(account);
335335
} catch (RemoteException e) {
336-
// will never happen
336+
// won't ever happen
337337
throw new RuntimeException(e);
338338
}
339339
}
@@ -362,7 +362,7 @@ public String getUserData(final Account account, final String key) {
362362
try {
363363
return mService.getUserData(account, key);
364364
} catch (RemoteException e) {
365-
// will never happen
365+
// won't ever happen
366366
throw new RuntimeException(e);
367367
}
368368
}
@@ -415,8 +415,10 @@ public AuthenticatorDescription[] getAuthenticatorTypesAsUser(int userId) {
415415
*
416416
* <p>It is safe to call this method from the main thread.
417417
*
418-
* <p>This method requires the caller to hold the permission
419-
* {@link android.Manifest.permission#GET_ACCOUNTS}.
418+
* <p>Clients of this method that have not been granted the
419+
* {@link android.Manifest.permission#GET_ACCOUNTS} permission,
420+
* will only see those accounts managed by AbstractAccountAuthenticators whose
421+
* signature matches the client.
420422
*
421423
* @return An array of {@link Account}, one for each account. Empty
422424
* (never null) if no accounts have been added.
@@ -438,8 +440,10 @@ public Account[] getAccounts() {
438440
*
439441
* <p>It is safe to call this method from the main thread.
440442
*
441-
* <p>This method requires the caller to hold the permission
442-
* {@link android.Manifest.permission#GET_ACCOUNTS}.
443+
* <p>Clients of this method that have not been granted the
444+
* {@link android.Manifest.permission#GET_ACCOUNTS} permission,
445+
* will only see those accounts managed by AbstractAccountAuthenticators whose
446+
* signature matches the client.
443447
*
444448
* @return An array of {@link Account}, one for each account. Empty
445449
* (never null) if no accounts have been added.
@@ -466,7 +470,7 @@ public Account[] getAccountsForPackage(String packageName, int uid) {
466470
try {
467471
return mService.getAccountsForPackage(packageName, uid);
468472
} catch (RemoteException re) {
469-
// possible security exception
473+
// won't ever happen
470474
throw new RuntimeException(re);
471475
}
472476
}
@@ -483,7 +487,7 @@ public Account[] getAccountsByTypeForPackage(String type, String packageName) {
483487
try {
484488
return mService.getAccountsByTypeForPackage(type, packageName);
485489
} catch (RemoteException re) {
486-
// possible security exception
490+
// won't ever happen
487491
throw new RuntimeException(re);
488492
}
489493
}
@@ -497,9 +501,10 @@ public Account[] getAccountsByTypeForPackage(String type, String packageName) {
497501
*
498502
* <p>It is safe to call this method from the main thread.
499503
*
500-
* <p>This method requires the caller to hold the permission
501-
* {@link android.Manifest.permission#GET_ACCOUNTS} or share a uid with the
502-
* authenticator that owns the account type.
504+
* <p>Clients of this method that have not been granted the
505+
* {@link android.Manifest.permission#GET_ACCOUNTS} permission,
506+
* will only see those accounts managed by AbstractAccountAuthenticators whose
507+
* signature matches the client.
503508
*
504509
* <p><b>NOTE:</b> If targeting your app to work on API level 22 and before,
505510
* GET_ACCOUNTS permission is needed for those platforms, irrespective of uid
@@ -585,7 +590,8 @@ public String bundleToResult(Bundle bundle) throws AuthenticatorException {
585590
* {@link AccountManagerFuture} must not be used on the main thread.
586591
*
587592
* <p>This method requires the caller to hold the permission
588-
* {@link android.Manifest.permission#GET_ACCOUNTS}.
593+
* {@link android.Manifest.permission#GET_ACCOUNTS} or be a signature
594+
* match with the AbstractAccountAuthenticator that manages the account.
589595
*
590596
* @param account The {@link Account} to test
591597
* @param features An array of the account features to check
@@ -628,9 +634,10 @@ public Boolean bundleToResult(Bundle bundle) throws AuthenticatorException {
628634
* <p>This method may be called from any thread, but the returned
629635
* {@link AccountManagerFuture} must not be used on the main thread.
630636
*
631-
* <p>This method requires the caller to hold the permission
632-
* {@link android.Manifest.permission#GET_ACCOUNTS} or share a uid with the
633-
* authenticator that owns the account type.
637+
* <p>Clients of this method that have not been granted the
638+
* {@link android.Manifest.permission#GET_ACCOUNTS} permission,
639+
* will only see those accounts managed by AbstractAccountAuthenticators whose
640+
* signature matches the client.
634641
*
635642
* @param type The type of accounts to return, must not be null
636643
* @param features An array of the account features to require,
@@ -701,7 +708,7 @@ public boolean addAccountExplicitly(Account account, String password, Bundle use
701708
try {
702709
return mService.addAccountExplicitly(account, password, userdata);
703710
} catch (RemoteException e) {
704-
// won't ever happen
711+
// Can happen if there was a SecurityException was thrown.
705712
throw new RuntimeException(e);
706713
}
707714
}
@@ -966,7 +973,7 @@ public boolean removeAccountExplicitly(Account account) {
966973
try {
967974
return mService.removeAccountExplicitly(account);
968975
} catch (RemoteException e) {
969-
// won't ever happen
976+
// May happen if the caller doesn't match the signature of the authenticator.
970977
throw new RuntimeException(e);
971978
}
972979
}
@@ -1114,7 +1121,7 @@ public void setUserData(final Account account, final String key, final String va
11141121
try {
11151122
mService.setUserData(account, key, value);
11161123
} catch (RemoteException e) {
1117-
// won't ever happen
1124+
// Will happen if there is not signature match.
11181125
throw new RuntimeException(e);
11191126
}
11201127
}
@@ -1733,7 +1740,7 @@ public void doWork() throws RemoteException {
17331740
* with these fields if an activity was supplied and the account
17341741
* credentials were successfully updated:
17351742
* <ul>
1736-
* <li> {@link #KEY_ACCOUNT_NAME} - the name of the account created
1743+
* <li> {@link #KEY_ACCOUNT_NAME} - the name of the account
17371744
* <li> {@link #KEY_ACCOUNT_TYPE} - the type of the account
17381745
* </ul>
17391746
*
@@ -2501,10 +2508,12 @@ public void onReceive(final Context context, final Intent intent) {
25012508
* listeners are added in an Activity or Service's {@link Activity#onCreate}
25022509
* and removed in {@link Activity#onDestroy}.
25032510
*
2504-
* <p>It is safe to call this method from the main thread.
2511+
* <p>The listener will only be informed of accounts that would be returned
2512+
* to the caller via {@link #getAccounts()}. Typically this means that to
2513+
* get any accounts, the caller will need to be grated the GET_ACCOUNTS
2514+
* permission.
25052515
*
2506-
* <p>This method requires the caller to hold the permission
2507-
* {@link android.Manifest.permission#GET_ACCOUNTS}.
2516+
* <p>It is safe to call this method from the main thread.
25082517
*
25092518
* @param listener The listener to send notifications to
25102519
* @param handler {@link Handler} identifying the thread to use

0 commit comments

Comments
 (0)