diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java index 12fcdcfc7b57f..806a55bfb8698 100644 --- a/core/java/android/accounts/AccountManager.java +++ b/core/java/android/accounts/AccountManager.java @@ -359,7 +359,29 @@ public class AccountManager { */ public AuthenticatorDescription[] getAuthenticatorTypes() { try { - return mService.getAuthenticatorTypes(); + return mService.getAuthenticatorTypes(UserHandle.getCallingUserId()); + } catch (RemoteException e) { + // will never happen + throw new RuntimeException(e); + } + } + + /** + * @hide + * Lists the currently registered authenticators for a given user id. + * + *
It is safe to call this method from the main thread. + * + *
The caller has to be in the same user or have the permission + * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}. + * + * @return An array of {@link AuthenticatorDescription} for every + * authenticator known to the AccountManager service. Empty (never + * null) if no authenticators are known. + */ + public AuthenticatorDescription[] getAuthenticatorTypesAsUser(int userId) { + try { + return mService.getAuthenticatorTypes(userId); } catch (RemoteException e) { // will never happen throw new RuntimeException(e); @@ -387,6 +409,28 @@ public class AccountManager { } } + /** + * @hide + * Lists all accounts of any type registered on the device for a given + * user id. Equivalent to getAccountsByType(null). + * + *
It is safe to call this method from the main thread. + * + *
This method requires the caller to hold the permission
+ * {@link android.Manifest.permission#GET_ACCOUNTS}.
+ *
+ * @return An array of {@link Account}, one for each account. Empty
+ * (never null) if no accounts have been added.
+ */
+ public Account[] getAccountsAsUser(int userId) {
+ try {
+ return mService.getAccountsAsUser(null, userId);
+ } catch (RemoteException e) {
+ // won't ever happen
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* @hide
* For use by internal activities. Returns the list of accounts that the calling package
diff --git a/core/java/android/accounts/IAccountManager.aidl b/core/java/android/accounts/IAccountManager.aidl
index 86e279f3d005d..1373dc8b1a20d 100644
--- a/core/java/android/accounts/IAccountManager.aidl
+++ b/core/java/android/accounts/IAccountManager.aidl
@@ -29,7 +29,7 @@ import android.os.Bundle;
interface IAccountManager {
String getPassword(in Account account);
String getUserData(in Account account, String key);
- AuthenticatorDescription[] getAuthenticatorTypes();
+ AuthenticatorDescription[] getAuthenticatorTypes(int userId);
Account[] getAccounts(String accountType);
Account[] getAccountsForPackage(String packageName, int uid);
Account[] getAccountsByTypeForPackage(String type, String packageName);
diff --git a/core/java/android/os/UserHandle.java b/core/java/android/os/UserHandle.java
index 914c170881c3e..afbf98372c071 100644
--- a/core/java/android/os/UserHandle.java
+++ b/core/java/android/os/UserHandle.java
@@ -16,7 +16,10 @@
package android.os;
+import android.util.SparseArray;
+
import java.io.PrintWriter;
+import java.util.HashMap;
/**
* Representation of a user on the device.
@@ -66,6 +69,8 @@ public final class UserHandle implements Parcelable {
final int mHandle;
+ private static final SparseArray