@Override public void setUserData(int userId, Account account, String key, String value) { if (key == null) throw new IllegalArgumentException("key is null"); if (account == null) throw new IllegalArgumentException("account is null"); VAccount vAccount = getAccount(userId, account); if (vAccount != null) { synchronized (accountsByUserId) { vAccount.userDatas.put(key, value); saveAllAccounts(); } } }
@Override public void setAuthToken(int userId, Account account, String authTokenType, String authToken) { if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, account); if (vAccount != null) { // FIXME: cancelNotification vAccount.authTokens.put(authTokenType, authToken); this.saveAllAccounts(); } } }
@Override public boolean accountAuthenticated(int userId, final Account account) { if (account == null) { throw new IllegalArgumentException("account is null"); } synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, account); if (vAccount != null) { vAccount.lastAuthenticatedTime = System.currentTimeMillis(); saveAllAccounts(); return true; } return false; } }
private boolean removeAccountInternal(int userId, Account account) { List<VAccount> accounts = accountsByUserId.get(userId); if (accounts != null) { Iterator<VAccount> iterator = accounts.iterator(); while (iterator.hasNext()) { VAccount vAccount = iterator.next(); if (userId == vAccount.userId && TextUtils.equals(vAccount.name, account.name) && TextUtils.equals(account.type, vAccount.type)) { iterator.remove(); saveAllAccounts(); sendAccountsChangedBroadcast(userId); return true; } } } return false; }
@Override public void invalidateAuthToken(int userId, String accountType, String authToken) { if (accountType == null) throw new IllegalArgumentException("accountType is null"); if (authToken == null) throw new IllegalArgumentException("authToken is null"); synchronized (accountsByUserId) { List<VAccount> accounts = accountsByUserId.get(userId); if (accounts != null) { boolean changed = false; for (VAccount account : accounts) { if (account.type.equals(accountType)) { account.authTokens.values().remove(authToken); changed = true; } } if (changed) { saveAllAccounts(); } } synchronized (authTokenRecords) { Iterator<AuthTokenRecord> iterator = authTokenRecords.iterator(); while (iterator.hasNext()) { AuthTokenRecord record = iterator.next(); if (record.userId == userId && record.authTokenType.equals(accountType) && record.authToken.equals(authToken)) { iterator.remove(); } } } } }
private void broadcastCheckInNowIfNeed(int userId) { long time = System.currentTimeMillis(); if (Math.abs(time - lastAccountChangeTime) > CHECK_IN_TIME) { lastAccountChangeTime = time; saveAllAccounts(); Intent intent = new Intent("android.server.checkin.CHECKIN_NOW"); VActivityManagerService.get().sendBroadcastAsUser(intent, new VUserHandle(userId)); } }
private void setPasswordInternal(int userId, Account account, String password) { synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, account); if (vAccount != null) { vAccount.password = password; vAccount.authTokens.clear(); saveAllAccounts(); synchronized (authTokenRecords) { Iterator<AuthTokenRecord> iterator = authTokenRecords.iterator(); while (iterator.hasNext()) { AuthTokenRecord record = iterator.next(); if (record.userId == userId && record.account.equals(account)) { iterator.remove(); } } } sendAccountsChangedBroadcast(userId); } } }
private boolean insertAccountIntoDatabase(int userId, Account account, String password, Bundle extras) { if (account == null) { return false; } synchronized (accountsByUserId) { VAccount vAccount = new VAccount(userId, account); vAccount.password = password; // convert the [Bundle] to [Map<String, String>] if (extras != null) { for (String key : extras.keySet()) { Object value = extras.get(key); if (value instanceof String) { vAccount.userDatas.put(key, (String) value); } } } List<VAccount> accounts = accountsByUserId.get(userId); if (accounts == null) { accounts = new ArrayList<>(); accountsByUserId.put(userId, accounts); } accounts.add(vAccount); saveAllAccounts(); sendAccountsChangedBroadcast(vAccount.userId); return true; } }
private Account renameAccountInternal(int userId, Account accountToRename, String newName) { // TODO: Cancel Notification synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, accountToRename); if (vAccount != null) { vAccount.previousName = vAccount.name; vAccount.name = newName; saveAllAccounts(); Account newAccount = new Account(vAccount.name, vAccount.type); synchronized (authTokenRecords) { for (AuthTokenRecord record : authTokenRecords) { if (record.userId == userId && record.account.equals(accountToRename)) { record.account = newAccount; } } } sendAccountsChangedBroadcast(userId); return newAccount; } } return accountToRename; }
@Override public void setUserData(int userId, Account account, String key, String value) { if (key == null) throw new IllegalArgumentException("key is null"); if (account == null) throw new IllegalArgumentException("account is null"); VAccount vAccount = getAccount(userId, account); if (vAccount != null) { synchronized (accountsByUserId) { vAccount.userDatas.put(key, value); saveAllAccounts(); } } }
@Override public void setUserData(int userId, Account account, String key, String value) { if (key == null) throw new IllegalArgumentException("key is null"); if (account == null) throw new IllegalArgumentException("account is null"); VAccount vAccount = getAccount(userId, account); if (vAccount != null) { synchronized (accountsByUserId) { vAccount.userDatas.put(key, value); saveAllAccounts(); } } }
@Override public void setAuthToken(int userId, Account account, String authTokenType, String authToken) { if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, account); if (vAccount != null) { // FIXME: cancelNotification vAccount.authTokens.put(authTokenType, authToken); this.saveAllAccounts(); } } }
@Override public void setAuthToken(int userId, Account account, String authTokenType, String authToken) { if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, account); if (vAccount != null) { // FIXME: cancelNotification vAccount.authTokens.put(authTokenType, authToken); this.saveAllAccounts(); } } }
@Override public boolean accountAuthenticated(int userId, final Account account) { if (account == null) { throw new IllegalArgumentException("account is null"); } synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, account); if (vAccount != null) { vAccount.lastAuthenticatedTime = System.currentTimeMillis(); saveAllAccounts(); return true; } return false; } }
@Override public boolean accountAuthenticated(int userId, final Account account) { if (account == null) { throw new IllegalArgumentException("account is null"); } synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, account); if (vAccount != null) { vAccount.lastAuthenticatedTime = System.currentTimeMillis(); saveAllAccounts(); return true; } return false; } }
private boolean removeAccountInternal(int userId, Account account) { List<VAccount> accounts = accountsByUserId.get(userId); if (accounts != null) { Iterator<VAccount> iterator = accounts.iterator(); while (iterator.hasNext()) { VAccount vAccount = iterator.next(); if (userId == vAccount.userId && TextUtils.equals(vAccount.name, account.name) && TextUtils.equals(account.type, vAccount.type)) { iterator.remove(); saveAllAccounts(); sendAccountsChangedBroadcast(userId); return true; } } } return false; }
private void broadcastCheckInNowIfNeed(int userId) { long time = System.currentTimeMillis(); if (Math.abs(time - lastAccountChangeTime) > CHECK_IN_TIME) { lastAccountChangeTime = time; saveAllAccounts(); Intent intent = new Intent("android.server.checkin.CHECKIN_NOW"); VActivityManagerService.get().sendBroadcastAsUser(intent, new VUserHandle(userId)); } }
private void broadcastCheckInNowIfNeed(int userId) { long time = System.currentTimeMillis(); if (Math.abs(time - lastAccountChangeTime) > CHECK_IN_TIME) { lastAccountChangeTime = time; saveAllAccounts(); Intent intent = new Intent("android.server.checkin.CHECKIN_NOW"); VActivityManagerService.get().sendBroadcastAsUser(intent, new VUserHandle(userId)); } }
private Account renameAccountInternal(int userId, Account accountToRename, String newName) { // TODO: Cancel Notification synchronized (accountsByUserId) { VAccount vAccount = getAccount(userId, accountToRename); if (vAccount != null) { vAccount.previousName = vAccount.name; vAccount.name = newName; saveAllAccounts(); Account newAccount = new Account(vAccount.name, vAccount.type); synchronized (authTokenRecords) { for (AuthTokenRecord record : authTokenRecords) { if (record.userId == userId && record.account.equals(accountToRename)) { record.account = newAccount; } } } sendAccountsChangedBroadcast(userId); return newAccount; } } return accountToRename; }