diff options
author | Amith Yamasani <yamasani@google.com> | 2013-03-31 17:44:31 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2013-03-31 17:44:31 -0700 |
commit | 5be347bc527ca3eebb448f85245957c810e6b142 (patch) | |
tree | 9053ba243ca44985d704b9c9eb3ff414cfd290da /services/java/com/android/server/accounts | |
parent | 42bc734b302f1fe68c031e013513535bed4c24f1 (diff) | |
download | frameworks_base-5be347bc527ca3eebb448f85245957c810e6b142.zip frameworks_base-5be347bc527ca3eebb448f85245957c810e6b142.tar.gz frameworks_base-5be347bc527ca3eebb448f85245957c810e6b142.tar.bz2 |
Add new primary accounts to secondary limited users
When a new account is added to the primary, those will be marked
as shared accounts for secondary limited users. If the secondary user
is currently running, clone the account right away.
Bug: 8510431
Change-Id: Ie8ad87a7205e7b1a5a1752e75fbbfc416b2a58a7
Diffstat (limited to 'services/java/com/android/server/accounts')
-rw-r--r-- | services/java/com/android/server/accounts/AccountManagerService.java | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/services/java/com/android/server/accounts/AccountManagerService.java b/services/java/com/android/server/accounts/AccountManagerService.java index 5009793..eb144ab 100644 --- a/services/java/com/android/server/accounts/AccountManagerService.java +++ b/services/java/com/android/server/accounts/AccountManagerService.java @@ -116,6 +116,7 @@ public class AccountManagerService // Messages that can be sent on mHandler private static final int MESSAGE_TIMED_OUT = 3; + private static final int MESSAGE_COPY_SHARED_ACCOUNT = 4; private final IAccountAuthenticatorCache mAuthenticatorCache; @@ -619,7 +620,17 @@ public class AccountManagerService } public void run() throws RemoteException { - mAuthenticator.addAccountFromCredentials(this, account, result); + // Confirm that the owner's account still exists before this step. + UserAccounts owner = getUserAccounts(UserHandle.USER_OWNER); + synchronized (owner.cacheLock) { + Account[] ownerAccounts = getAccounts(UserHandle.USER_OWNER); + for (Account acc : ownerAccounts) { + if (acc.equals(account)) { + mAuthenticator.addAccountFromCredentials(this, account, result); + break; + } + } + } } public void onResult(Bundle result) { @@ -692,7 +703,33 @@ public class AccountManagerService db.endTransaction(); } sendAccountsChangedBroadcast(accounts.userId); - return true; + } + if (accounts.userId == UserHandle.USER_OWNER) { + addAccountToLimitedUsers(account); + } + return true; + } + + /** + * Adds the account to all limited users as shared accounts. If the user is currently + * running, then clone the account too. + * @param account the account to share with limited users + */ + private void addAccountToLimitedUsers(Account account) { + List<UserInfo> users = mUserManager.getUsers(); + for (UserInfo user : users) { + if (user.isRestricted()) { + addSharedAccountAsUser(account, user.id); + try { + if (ActivityManagerNative.getDefault().isUserRunning(user.id, false)) { + mMessageHandler.sendMessage(mMessageHandler.obtainMessage( + MESSAGE_COPY_SHARED_ACCOUNT, UserHandle.USER_OWNER, user.id, + account)); + } + } catch (RemoteException re) { + // Shouldn't happen + } + } } } @@ -2161,6 +2198,10 @@ public class AccountManagerService session.onTimedOut(); break; + case MESSAGE_COPY_SHARED_ACCOUNT: + copyAccountToUser((Account) msg.obj, msg.arg1, msg.arg2); + break; + default: throw new IllegalStateException("unhandled message: " + msg.what); } |