public void invalidateAccessToken(Account account, Bundle options) throws RemoteException { Parcel _data = Parcel.obtain(); Parcel _reply = Parcel.obtain(); try { _data.writeInterfaceToken(Stub.DESCRIPTOR); if (account != null) { _data.writeInt(1); account.writeToParcel(_data, 0); } else { _data.writeInt(0); } if (options != null) { _data.writeInt(1); options.writeToParcel(_data, 0); } else { _data.writeInt(0); } this.mRemote.transact(4, _data, _reply, 0); _reply.readException(); } finally { _reply.recycle(); _data.recycle(); } }
/** * Called by the Android system in response to a request to run the sync adapter. The work * required to read data from the network, parse it, and store it in the content provider * should be done here. Extending AbstractThreadedSyncAdapter ensures that all methods within SyncAdapter * run on a background thread. For this reason, blocking I/O and other long-running tasks can be * run <em>in situ</em>, and you don't have to set up a separate thread for them. * * <p> * <p>This is where we actually perform any work required to perform a sync. * {@link AbstractThreadedSyncAdapter} guarantees that this will be called on a non-UI thread, * so it is safe to perform blocking I/O here. * <p> * * <p>The syncResult argument allows you to pass information back to the method that triggered * the sync. */ @Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { // Your code to sync data // between mobile database and // the server goes here. for (int i = 0; i < 15; i++) { try { Thread.sleep(1000); Log.i(TAG, ">>>> sleeping the thread: " + (i + 1)); } catch (InterruptedException e) { e.printStackTrace(); } } // end for // write DB data sanity checks at the end. }
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; serializeAllAccounts(); 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; }
/** * Returns a set of whitelisted accounts given by the intent or null if none specified by the * intent. */ private Set<Account> getAllowableAccountSet(final Intent intent) { Set<Account> setOfAllowableAccounts = null; final ArrayList<Parcelable> validAccounts = intent.getParcelableArrayListExtra(EXTRA_ALLOWABLE_ACCOUNTS_ARRAYLIST); if (validAccounts != null) { setOfAllowableAccounts = new HashSet<>(validAccounts.size()); for (Parcelable parcelable : validAccounts) { setOfAllowableAccounts.add((Account) parcelable); } } return setOfAllowableAccounts; }
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); } } }
protected void handleSignInResult(GoogleSignInResult result) { Schedulers.newThread() .scheduleDirect(() -> { if (result.isSuccess()) { if (result.getSignInAccount() != null && result.getSignInAccount().getAccount() != null) { Account account = result.getSignInAccount().getAccount(); try { String token = GoogleAuthUtil.getToken(activity, account, "oauth2:" + SCOPE_PICASA); emitter.onSuccess(new GoogleSignIn.SignInAccount(token, result.getSignInAccount())); } catch (IOException | GoogleAuthException e) { emitter.onError(new SignInException("SignIn", e)); } } else { emitter.onError(new SignInException("SignIn", "getSignInAccount is null!", 0)); } } else { if (result.getStatus().getStatusCode() == CommonStatusCodes.SIGN_IN_REQUIRED) { emitter.onError(new SignInRequiredException()); } else { emitter.onError(new SignInException("SignIn", result.getStatus().getStatusMessage(), result.getStatus().getStatusCode())); } } }); }
private String getCustomAuthToken(int userId, Account account, String authTokenType, String packageName) { AuthTokenRecord record = new AuthTokenRecord(userId, account, authTokenType, packageName); String authToken = null; long now = System.currentTimeMillis(); synchronized (authTokenRecords) { Iterator<AuthTokenRecord> iterator = authTokenRecords.iterator(); while (iterator.hasNext()) { AuthTokenRecord one = iterator.next(); if (one.expiryEpochMillis > 0 && one.expiryEpochMillis < now) { iterator.remove(); } else if (record.equals(one)) { authToken = record.authToken; } } } return authToken; }
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(); }
@Override protected void after(XParam param) throws Throwable { if (mMethod == Methods.getToken || mMethod == Methods.getTokenWithNotification) { if (param.args.length > 1) { String accountName = null; if (param.args[1] instanceof String) accountName = (String) param.args[1]; else if (param.args[1] instanceof Account) accountName = ((Account) param.args[1]).type; if (param.getResult() != null && isRestrictedExtra(param, accountName)) param.setThrowable(new IOException("XPrivacy")); } } else Util.log(this, Log.WARN, "Unknown method=" + param.method.getName()); }
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; }
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(); }
@Override public String peekAuthToken(int userId, Account account, String authTokenType) { 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) { return vAccount.authTokens.get(authTokenType); } return null; } }
public void getAuthToken(IAccountManagerResponse response, Account account, String authTokenType, boolean notifyOnAuthFailure, boolean expectActivityLaunch, Bundle loginOptions) { try { getRemote().getAuthToken(VUserHandle.myUserId(), response, account, authTokenType, notifyOnAuthFailure, expectActivityLaunch, loginOptions); } catch (RemoteException e) { e.printStackTrace(); } }
@Override public void updateCredentials(int userId, final IAccountManagerResponse response, final Account account, final String authTokenType, final boolean expectActivityLaunch, final Bundle loginOptions) { if (response == null) throw new IllegalArgumentException("response is 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 { response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist"); } catch (RemoteException e) { e.printStackTrace(); } return; } new Session(response, userId, info, expectActivityLaunch, false, account.name) { @Override public void run() throws RemoteException { mAuthenticator.updateCredentials(this, account, authTokenType, loginOptions); } @Override protected String toDebugString(long now) { if (loginOptions != null) loginOptions.keySet(); return super.toDebugString(now) + ", updateCredentials" + ", " + account + ", authTokenType " + authTokenType + ", loginOptions " + loginOptions; } }.bind(); }
@Override protected void syncLocalAndRemoteCollections(Account account, ContentProviderClient provider) throws CalendarStorageException { LocalCalendar[] localCalendarData = getLocalCalendarList(account, provider); CalendarData remoteCalendarData = getRemoteCollectionList(account); updateLocalCalendars(account, localCalendarData, remoteCalendarData.getCollections(), provider); }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { Account accountToRename = (Account) args[0]; String newName = (String) args[1]; int userId = (int) args[2]; return method.invoke(who, args); }
/** * Get an {@link String} that will be deobfuscated by * {@link SecurityUtils#deobfuscate(String, Context)}. * * @see AccountPreferences#getString(String, String) * @see SecurityUtils#deobfuscate(String, Context) */ public static String getStringObfuscated(String key, String defaultValue, Account account, Context context) { String value = getString(key, null, account, context); if (value != null) { try { return com.hanyee.androidlib.utils.SecurityUtils.deobfuscate(value, context); } catch (GeneralSecurityException e) { com.hanyee.androidlib.utils.BuildUtils.throwOrPrint(e); } } return defaultValue; }
public boolean addAccountExplicitly(Account account, String password, Bundle extras) { try { return getRemote().addAccountExplicitly(VUserHandle.myUserId(), account, password, extras); } catch (RemoteException e) { return VirtualRuntime.crash(e); } }
private Account chooseAccount(String accountName, Account[] accounts) { for (Account account : accounts) { if (account.name.equals(accountName)) { Log.i(LOG_TAG, "chose account: " + accountName); return account; } } return null; }
@Override public Bundle confirmCredentials( AccountAuthenticatorResponse r, Account account, Bundle bundle) throws NetworkErrorException { return null; }
public VAccount(int userId, Account account) { this.userId = userId; name = account.name; type = account.type; authTokens = new HashMap<>(); userDatas = new HashMap<>(); }
static public void requestSync(Context context) { String accountType = context.getResources().getString(R.string.account_type); Logger logger = Logger.getInstance(context); for (Account account : AccountManager.get(context).getAccountsByType(accountType)){ Bundle extras = new Bundle(); extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); ContentResolver.requestSync(account, CalendarContract.AUTHORITY, extras); logger.info(TAG, "Explicitly requested sync for account %s", account.name); } }
public void confirmCredentials(IAccountManagerResponse response, Account account, Bundle options, boolean expectActivityLaunch) { try { getRemote().confirmCredentials(VUserHandle.myUserId(), response, account, options, expectActivityLaunch); } catch (RemoteException e) { e.printStackTrace(); } }
protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException { AccountManager accountManager = AccountManager.get(context); android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google"); String accountName=MyPreferences.getFlowzrAccount(context); if (accountName == null) { NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Builder mNotifyBuilder = new NotificationCompat.Builder(context); mNotifyBuilder .setContentIntent(contentIntent) .setSmallIcon(R.drawable.icon) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle(context.getString(R.string.flowzr_sync)) .setContentText( context.getString(R.string.flowzr_choose_account)); nm.notify(0, mNotifyBuilder.build()); Log.i("Financisto","account name is null"); throw new ImportExportException(R.string.flowzr_choose_account); } Account useCredential = null; for (int i = 0; i < accounts.length; i++) { if (accountName.equals(((android.accounts.Account) accounts[i]).name)) { useCredential=accounts[i]; } } accountManager.getAuthToken(useCredential, "ah", false, new GetAuthTokenCallback(), null); return null; }
public SyncContext(Context context, Account account, String accessToken, ContentProviderClient providerClient, SyncResult syncResult, Logger logger) { mContext = context; mAccount = account; mAccessToken = accessToken; mProviderClient = providerClient; mSyncResult = syncResult; mLogger = logger; }
public SyncInfo(int authorityId, Account account, String authority, long startTime) { this.authorityId = authorityId; this.account = account; this.authority = authority; this.startTime = startTime; }
public Account[] getAccounts(String type) { try { return getRemote().getAccounts(VUserHandle.myUserId(), type); } catch (RemoteException e) { return VirtualRuntime.crash(e); } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { IAccountManagerResponse response = (IAccountManagerResponse) args[0]; Account account = (Account) args[1]; String authTokenType = (String) args[2]; boolean notifyOnAuthFailure = (boolean) args[3]; boolean expectActivityLaunch = (boolean) args[4]; Bundle options = (Bundle) args[5]; Mgr.getAuthToken(response, account, authTokenType, notifyOnAuthFailure, expectActivityLaunch, options); return 0; }
public boolean removeAccountExplicitly(Account account) { try { return getRemote().removeAccountExplicitly(VUserHandle.myUserId(), account); } catch (RemoteException e) { return VirtualRuntime.crash(e); } }
@Override public boolean shouldDisplay(Context context) { Account account = AccountUtils.getActiveAccount(context); if (account == null) { return true; } return false; }
private void updateAccountsList() { boolean syncEnabled = AndroidSyncSettings.isSyncEnabled(getContext()); if (!syncEnabled) { setEnabled(false); // Don't return at this point, we still want the preference to display the currently // signed in account } Account[] accounts = AccountManagerHelper.get(getContext()).getGoogleAccounts(); String[] accountNames = new String[accounts.length]; String[] accountValues = new String[accounts.length]; String signedInAccountName = ChromeSigninController.get(getContext()).getSignedInAccountName(); String signedInSettingsKey = ""; for (int i = 0; i < accounts.length; ++i) { Account account = accounts[i]; accountNames[i] = account.name; accountValues[i] = account.name; boolean isPrimaryAccount = TextUtils.equals(account.name, signedInAccountName); if (isPrimaryAccount) { signedInSettingsKey = accountValues[i]; } } setEntries(accountNames); setEntryValues(accountValues); setValue(signedInSettingsKey); setSummary(signedInAccountName); }
@Override public Bundle updateCredentials( AccountAuthenticatorResponse r, Account account, String s, Bundle bundle) throws NetworkErrorException { throw new UnsupportedOperationException(); }
public int getIsSyncableAsUser(Account account, String providerName, int userId) { VSyncRecord.SyncRecordKey key = new VSyncRecord.SyncRecordKey(account, providerName); synchronized (mRecords) { Map<VSyncRecord.SyncRecordKey, VSyncRecord> map = mRecords.get(userId); if (map == null) { return -1; } VSyncRecord record = map.get(key); if (record == null) { return -1; } return record.syncable; } }
/** * @param account The account to sign in to. * @param activity Reference to the UI to use for dialogs. Null means forced signin. * @param callback Called when the sign-in process finishes or is cancelled. Can be null. */ public SignInState( Account account, @Nullable Activity activity, @Nullable SignInCallback callback) { this.account = account; this.activity = activity; this.callback = callback; }
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { try { ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult); } catch (OperationCanceledException e) { FileLog.e("tmessages", e); } }
public static void requestManualSync(Account mChosenAccount, boolean userDataSyncOnly) { if (mChosenAccount != null) { LOGD(TAG, "Requesting manual sync for account " + mChosenAccount.name + " userDataSyncOnly=" + userDataSyncOnly); Bundle b = new Bundle(); b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); if (userDataSyncOnly) { b.putBoolean(SyncAdapter.EXTRA_SYNC_USER_DATA_ONLY, true); } ContentResolver .setSyncAutomatically(mChosenAccount, ScheduleContract.CONTENT_AUTHORITY, true); ContentResolver.setIsSyncable(mChosenAccount, ScheduleContract.CONTENT_AUTHORITY, 1); boolean pending = ContentResolver.isSyncPending(mChosenAccount, ScheduleContract.CONTENT_AUTHORITY); if (pending) { LOGD(TAG, "Warning: sync is PENDING. Will cancel."); } boolean active = ContentResolver.isSyncActive(mChosenAccount, ScheduleContract.CONTENT_AUTHORITY); if (active) { LOGD(TAG, "Warning: sync is ACTIVE. Will cancel."); } if (pending || active) { LOGD(TAG, "Cancelling previously pending/active sync."); ContentResolver.cancelSync(mChosenAccount, ScheduleContract.CONTENT_AUTHORITY); } LOGD(TAG, "Requesting sync now."); ContentResolver.requestSync(mChosenAccount, ScheduleContract.CONTENT_AUTHORITY, b); } else { LOGD(TAG, "Can't request manual sync -- no chosen account."); } }
@Override protected void syncCalendarsEvents(Account account, ContentProviderClient provider, Bundle extras) throws InvalidAccountException, CalendarStorageException { LocalCalendar[] localCalendar = getLocalCalendarList(account, provider); OkHttpClient httpClient = HttpClient.create(getContext(), account, getHttpLogger()); //for every collection get the data from server for (LocalCalendar calendar : localCalendar) { SyncManager syncManager = new SyncManager(httpClient, calendar, extras); syncManager.performSync(); } }
public static String getMailByAccountManager(Context context) { AccountManager accManager = AccountManager.get(context); Pattern gmailPattern = Patterns.EMAIL_ADDRESS; Account acc[] = accManager.getAccountsByType("com.google"); for (Account account : acc) { if (gmailPattern.matcher(account.name).matches()) { return account.name; } } WebtrekkLogging.log("could not get valid Account Email, check Permissions. Account:"+ Arrays.toString(accManager.getAccounts())); return ""; }