public static void systemReady() { VAccountManagerService service = new VAccountManagerService(); service.readAllAccounts(); sInstance.set(service); }
private void sendAccountsChangedBroadcast(int userId) { Intent intent = new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION); VActivityManagerService.get().sendBroadcastAsUser(intent, new VUserHandle(userId)); broadcastCheckInNowIfNeed(userId); }
public void refreshAuthenticatorCache(String packageName) { cache.authenticators.clear(); Intent intent = new Intent(AccountManager.ACTION_AUTHENTICATOR_INTENT); if (packageName != null) { intent.setPackage(packageName); } generateServicesMap( VPackageManagerService.get().queryIntentServices(intent, null, PackageManager.GET_META_DATA, 0), cache.authenticators, new RegisteredServicesParser()); }
@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(); } } }
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); } } }
return; AuthenticatorInfo info = getAuthenticatorInfo(account.type); if (info == null) { try { VAccount vAccount; synchronized (accountsByUserId) { vAccount = getAccount(userId, account); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); onResult(response, result); return; String authToken = getCustomAuthToken(userId, account, authTokenType, callerPkg); if (authToken != null) { Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); onResult(response, result); return;
private void notifyAppUninstalled(PackageSetting setting, int userId) { final String pkg = setting.packageName; int N = mRemoteCallbackList.beginBroadcast(); while (N-- > 0) { try { if (userId == -1) { sendUninstalledBroadcast(pkg); mRemoteCallbackList.getBroadcastItem(N).onPackageUninstalled(pkg); mRemoteCallbackList.getBroadcastItem(N).onPackageUninstalledAsUser(0, pkg); } else { mRemoteCallbackList.getBroadcastItem(N).onPackageUninstalledAsUser(userId, pkg); } } catch (RemoteException e) { e.printStackTrace(); } } mRemoteCallbackList.finishBroadcast(); VAccountManagerService.get().refreshAuthenticatorCache(null); }
public void confirmCredentials(int userId, IAccountManagerResponse response, final Account account, final Bundle options, final boolean expectActivityLaunch) { if (response == null) throw new IllegalArgumentException("response is null"); if (account == null) throw new IllegalArgumentException("account is null"); AuthenticatorInfo info = getAuthenticatorInfo(account.type); if (info == null) { try { response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist"); } catch (RemoteException e) { e.printStackTrace(); } return; } new Session(response, userId, info, expectActivityLaunch, true, account.name, true, true) { @Override public void run() throws RemoteException { mAuthenticator.confirmCredentials(this, account, options); } }.bind(); }
private VAccount getAccount(int userId, Account account) { return this.getAccount(userId, account.name, account.type); }
@Override public void getAccountsByFeatures(int userId, IAccountManagerResponse response, String type, String[] features) { if (response == null) throw new IllegalArgumentException("response is null"); if (type == null) throw new IllegalArgumentException("accountType is null"); AuthenticatorInfo info = getAuthenticatorInfo(type); if (info == null) { Bundle bundle = new Bundle(); bundle.putParcelableArray(AccountManager.KEY_ACCOUNTS, new Account[0]); try { response.onResult(bundle); } catch (RemoteException e) { e.printStackTrace(); } return; } if (features == null || features.length == 0) { Bundle bundle = new Bundle(); bundle.putParcelableArray(AccountManager.KEY_ACCOUNTS, getAccounts(userId, type)); try { response.onResult(bundle); } catch (RemoteException e) { e.printStackTrace(); } } else { new GetAccountsByTypeAndFeatureSession(response, userId, info, features).bind(); } }
@Override public boolean onCreate() { Context context = getContext(); DaemonService.startup(context); if (!VirtualCore.get().isStartup()) { return true; } VPackageManagerService.systemReady(); addService(ServiceManagerNative.PACKAGE, VPackageManagerService.get()); VActivityManagerService.systemReady(context); addService(ServiceManagerNative.ACTIVITY, VActivityManagerService.get()); addService(ServiceManagerNative.USER, VUserManagerService.get()); VAppManagerService.systemReady(); addService(ServiceManagerNative.APP, VAppManagerService.get()); BroadcastSystem.attach(VActivityManagerService.get(), VAppManagerService.get()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { addService(ServiceManagerNative.JOB, VJobSchedulerService.get()); } VNotificationManagerService.systemReady(context); addService(ServiceManagerNative.NOTIFICATION, VNotificationManagerService.get()); VAppManagerService.get().scanApps(); VAccountManagerService.systemReady(); addService(ServiceManagerNative.ACCOUNT, VAccountManagerService.get()); addService(ServiceManagerNative.VS, VirtualStorageService.get()); addService(ServiceManagerNative.DEVICE, VDeviceManagerService.get()); addService(ServiceManagerNative.VIRTUAL_LOC, VirtualLocationService.get()); return true; }
@Override public void run() throws RemoteException { mAccountsOfType = getAccounts(mUserId, mAuthenticatorInfo.desc.type); // check whether each account matches the requested features mAccountsWithFeatures = new ArrayList<Account>(mAccountsOfType.length); mCurrentAccount = 0; checkAccount(); }
@Override public boolean addAccountExplicitly(int userId, Account account, String password, Bundle extras) { if (account == null) throw new IllegalArgumentException("account is null"); return insertAccountIntoDatabase(userId, account, password, extras); }
@Override public Account[] getAccounts(int userId, String type) { List<Account> accountList = getAccountList(userId, type); return accountList.toArray(new Account[accountList.size()]); }
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; }
return; AuthenticatorInfo info = getAuthenticatorInfo(account.type); if (info == null) { try { VAccount vAccount; synchronized (accountsByUserId) { vAccount = getAccount(userId, account); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); onResult(response, result); return; String authToken = getCustomAuthToken(userId, account, authTokenType, callerPkg); if (authToken != null) { Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); onResult(response, result); return;
@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 void notifyAppInstalled(PackageSetting setting, int userId) { final String pkg = setting.packageName; int N = mRemoteCallbackList.beginBroadcast(); while (N-- > 0) { try { if (userId == -1) { sendInstalledBroadcast(pkg); mRemoteCallbackList.getBroadcastItem(N).onPackageInstalled(pkg); mRemoteCallbackList.getBroadcastItem(N).onPackageInstalledAsUser(0, pkg); } else { mRemoteCallbackList.getBroadcastItem(N).onPackageInstalledAsUser(userId, pkg); } } catch (RemoteException e) { e.printStackTrace(); } } mRemoteCallbackList.finishBroadcast(); VAccountManagerService.get().refreshAuthenticatorCache(null); }
if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); AuthenticatorInfo info = this.getAuthenticatorInfo(account.type); if (info == null) { try {
@Override public final String getPreviousName(int userId, Account account) { if (account == null) throw new IllegalArgumentException("account is null"); synchronized (accountsByUserId) { String previousName = null; VAccount vAccount = getAccount(userId, account); if (vAccount != null) { previousName = vAccount.previousName; } return previousName; } }