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,
return getAccountsInternal(
accounts,
callingUid,
- callingPackage,
+ opPackageName,
visibleAccountTypes,
includeUserManagedNotVisible);
} finally {
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 */);
}
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 */);
}
@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
@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
*/
@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);
}