Use opPackageName to filter accounts in getAccountsAsUserForPakage
method.
Allow authenticators use getAccountsByTypeForPackage with null account
type.
Test: manual.
Change-Id: I47679f522a6c03c3d27f814b80b6f10530c31014
diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java
index ea9b651..dade0ed 100644
--- a/services/core/java/com/android/server/accounts/AccountManagerService.java
+++ b/services/core/java/com/android/server/accounts/AccountManagerService.java
@@ -4003,12 +4003,12 @@
public Account[] getAccountsAsUser(String type, int userId, String opPackageName) {
int callingUid = Binder.getCallingUid();
mAppOpsManager.checkPackage(callingUid, opPackageName);
- return getAccountsAsUser(type, userId, opPackageName /* callingPackage */, -1,
+ return getAccountsAsUserForPackage(type, userId, opPackageName /* callingPackage */, -1,
opPackageName, false /* includeUserManagedNotVisible */);
}
@NonNull
- private Account[] getAccountsAsUser(
+ private Account[] getAccountsAsUserForPackage(
String type,
int userId,
String callingPackage,
@@ -4061,7 +4061,7 @@
return getAccountsInternal(
accounts,
callingUid,
- callingPackage,
+ opPackageName,
visibleAccountTypes,
includeUserManagedNotVisible);
} finally {
@@ -4178,7 +4178,7 @@
throw new SecurityException("getAccountsForPackage() called from unauthorized uid "
+ callingUid + " with uid=" + uid);
}
- return getAccountsAsUser(null, UserHandle.getCallingUserId(), packageName, uid,
+ return getAccountsAsUserForPackage(null, UserHandle.getCallingUserId(), packageName, uid,
opPackageName, true /* includeUserManagedNotVisible */);
}
@@ -4197,11 +4197,10 @@
return EMPTY_ACCOUNT_ARRAY;
}
if (!UserHandle.isSameApp(callingUid, Process.SYSTEM_UID)
- && !isAccountManagedByCaller(type, callingUid, userId)) {
- return EMPTY_ACCOUNT_ARRAY;
+ && (type != null && !isAccountManagedByCaller(type, callingUid, userId))) {
+ return EMPTY_ACCOUNT_ARRAY;
}
-
- return getAccountsAsUser(type, userId,
+ return getAccountsAsUserForPackage(type, userId,
packageName, packageUid, opPackageName, true /* includeUserManagedNotVisible */);
}
@@ -5371,10 +5370,13 @@
@NonNull
private Account[] filterAccounts(UserAccounts accounts, Account[] unfiltered, int callingUid,
String callingPackage, boolean includeManagedNotVisible) {
- // filter based on visibility.
+ String visibilityFilterPackage = callingPackage;
+ if (visibilityFilterPackage == null) {
+ visibilityFilterPackage = getPackageNameForUid(callingUid);
+ }
Map<Account, Integer> firstPass = new LinkedHashMap<>();
for (Account account : unfiltered) {
- int visibility = resolveAccountVisibility(account, callingPackage, accounts);
+ int visibility = resolveAccountVisibility(account, visibilityFilterPackage, accounts);
if ((visibility == AccountManager.VISIBILITY_VISIBLE
|| visibility == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE)
|| (includeManagedNotVisible
@@ -5394,7 +5396,7 @@
@NonNull
private Map<Account, Integer> filterSharedAccounts(UserAccounts userAccounts,
@NonNull Map<Account, Integer> unfiltered, int callingUid,
- String callingPackage) {
+ @Nullable String callingPackage) {
// first part is to filter shared accounts.
// unfiltered type check is not necessary.
if (getUserManager() == null || userAccounts == null || userAccounts.userId < 0
@@ -5474,7 +5476,7 @@
*/
@NonNull
protected Account[] getAccountsFromCacheLocked(UserAccounts userAccounts, String accountType,
- int callingUid, String callingPackage, boolean includeManagedNotVisible) {
+ int callingUid, @Nullable String callingPackage, boolean includeManagedNotVisible) {
if (callingPackage == null) {
callingPackage = getPackageNameForUid(callingUid);
}