Java 类android.accounts.AuthenticatorException 实例源码

项目:letv    文件:LogonManager.java   
private void syncLogon4LetvPhone() {
    new Thread() {
        public void run() {
            try {
                String blockingGetAuthToken = LogonManager.this.accountManager.blockingGetAuthToken(LogonManager.this.accounts[0], LogonManager.this.AUTH_TOKEN_TYPE_LETV, true);
                LemallPlatform.getInstance().setSsoToken(blockingGetAuthToken);
                LogonManager.this.syncToken4Logon(blockingGetAuthToken, (IWebviewListener) LogonManager.this.context);
            } catch (OperationCanceledException e) {
                e.printStackTrace();
            } catch (AuthenticatorException e2) {
                e2.printStackTrace();
            } catch (IOException e3) {
                e3.printStackTrace();
            }
        }
    }.start();
}
项目:boohee_v5.6    文件:XiaomiOAuthorize$1.java   
protected Bundle doInBackground(Void... params) {
    try {
        return this.this$0.tryAddXiaomiAccount(this.val$activity);
    } catch (SecurityException e) {
        e.printStackTrace();
        this.retryWebViewWay = true;
        return null;
    } catch (OperationCanceledException e2) {
        e2.printStackTrace();
        return null;
    } catch (AuthenticatorException e3) {
        e3.printStackTrace();
        this.retryWebViewWay = true;
        return null;
    } catch (IOException e4) {
        e4.printStackTrace();
        return null;
    }
}
项目:TPlayer    文件:AmsTask.java   
private Exception convertErrorToException(int code, String message) {
    if (code == ERROR_CODE_NETWORK_ERROR) {
        return new IOException(message);
    }

    if (code == ERROR_CODE_UNSUPPORTED_OPERATION) {
        return new UnsupportedOperationException(message);
    }

    if (code == ERROR_CODE_INVALID_RESPONSE) {
        return new AuthenticatorException(message);
    }

    if (code == ERROR_CODE_BAD_ARGUMENTS) {
        return new IllegalArgumentException(message);
    }

    return new AuthenticatorException(message);
}
项目:android-wg-planer    文件:UserSyncAdapter.java   
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    try {
        String username = mAccountManager.blockingGetAuthToken(account, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, true);

        SyncServerInterface serverInterface = new SyncServerInterface(getContext());
        User user = serverInterface.getUserInfo(username);

        UserContentHelper.clearUsers(getContext());

        if (user != null) {
            UserContentHelper.addUser(getContext(), user);
        }
    } catch (OperationCanceledException | IOException | AuthenticatorException e) {
        e.printStackTrace();
        syncResult.stats.numParseExceptions++;
    }
}
项目:FMTech    文件:fpz.java   
public final void a(Context paramContext, String paramString)
{
  try
  {
    ebf.a(paramContext, paramString);
    return;
  }
  catch (ebg localebg)
  {
    throw new AuthenticatorException("Cannot invalidate token", localebg);
  }
  catch (ebe localebe)
  {
    throw new AuthenticatorException("Cannot invalidate token", localebe);
  }
}
项目:FMTech    文件:kcn.java   
public String a(Context paramContext, String paramString1, String paramString2, boolean paramBoolean)
{
  fpw localfpw = (fpw)mbb.a(paramContext, fpw.class);
  if (paramBoolean) {
    return this.b.a(paramContext, paramString1, paramString2);
  }
  try
  {
    String str = localfpw.a(paramString1, paramString2);
    return str;
  }
  catch (fpv localfpv)
  {
    throw new AuthenticatorException("Recoverable error", localfpv);
  }
}
项目:FMTech    文件:fqa.java   
public Account[] a(String paramString, String[] paramArrayOfString)
{
  try
  {
    Account[] arrayOfAccount = (Account[])AccountManager.get(this.a).getAccountsByTypeAndFeatures(paramString, paramArrayOfString, null, null).getResult(b, TimeUnit.MILLISECONDS);
    return arrayOfAccount;
  }
  catch (AuthenticatorException localAuthenticatorException)
  {
    throw new fpv(localAuthenticatorException);
  }
  catch (OperationCanceledException localOperationCanceledException)
  {
    throw new IOException(localOperationCanceledException);
  }
}
项目:flowzr-android-black    文件:FlowzrBillTask.java   
public void run(AccountManagerFuture<Bundle> result) {
    Bundle bundle;          
    try {
        bundle = result.getResult();
        Intent intent = (Intent)bundle.get(AccountManager.KEY_INTENT);
        if(intent != null) {
            // User input required
            context.startActivity(intent);
        } else {
            AccountManager.get(context).invalidateAuthToken(bundle.getString(AccountManager.KEY_ACCOUNT_TYPE), bundle.getString(AccountManager.KEY_AUTHTOKEN));
            AccountManager.get(context).invalidateAuthToken("ah", bundle.getString(AccountManager.KEY_AUTHTOKEN));
            onGetAuthToken(bundle);
        }
    } catch (OperationCanceledException | AuthenticatorException | IOException e) {
        //notifyUser(context.getString(R.string.flowzr_sync_error_no_network), 100);
        //showErrorPopup(FlowzrSyncActivity.this, R.string.flowzr_sync_error_no_network);
        //context.setReady();
        e.printStackTrace();
    }
}
项目:retroauth    文件:AndroidTokenStorage.java   
@Override
public AndroidToken getToken(Account account, AndroidTokenType type) throws AuthenticationCanceledException {
    try {
        AndroidToken token;
        Activity activity = activityManager.getActivity();
        if (account == null) {
            token = createAccountAndGetToken(activity, type);
        } else {
            token = getToken(activity, account, type);
        }
        if (token == null) {
            throw new AuthenticationCanceledException("user canceled the login!");
        }
        return token;
    } catch (AuthenticatorException | OperationCanceledException | IOException e) {
        throw new AuthenticationCanceledException(e);
    }
}
项目:retroauth    文件:AndroidTokenStorage.java   
private AndroidToken createAccountAndGetToken(@Nullable Activity activity, @NonNull AndroidTokenType type)
        throws AuthenticatorException, OperationCanceledException, IOException {

    AccountManagerFuture<Bundle> future = accountManager
            .addAccount(type.accountType, type.tokenType, null, null, activity, null, null);
    Bundle result = future.getResult();
    String accountName = result.getString(AccountManager.KEY_ACCOUNT_NAME);
    if (accountName != null) {
        Account account = new Account(result.getString(AccountManager.KEY_ACCOUNT_NAME),
                result.getString(AccountManager.KEY_ACCOUNT_TYPE));
        String token = accountManager.peekAuthToken(account, type.tokenType);
        String refreshToken = accountManager.peekAuthToken(account, getRefreshTokenType(type));
        if (token != null) return new AndroidToken(token, refreshToken);
    }
    return null;
}
项目:fantasywear    文件:OAuthApiRequest.java   
@Override
protected Token getToken() throws AuthFailureError {
    String tokenStr;
    try {
        // NOTE: We pass true for notifyAuthFailure for clarity, but our authenticator always
        // assumes it is true, because AccountManager#KEY_NOTIFY_ON_FAILURE is a hidden API.
        tokenStr = mAccountManager.blockingGetAuthToken(
                mAccount, AccountAuthenticator.TOKEN_TYPE_OAUTH, true /* notifyAuthFailure */);
    } catch (AuthenticatorException | OperationCanceledException | IOException e) {
        throw new AuthFailureError("Unable to obtain auth token", e);
    }

    mToken = WireUtil.decodeFromString(tokenStr, Token.class);
    if (mToken == null) {
        throw new AuthFailureError("Error decoding token string");
    }
    return mToken;
}
项目:picframe    文件:SimpleFactoryManager.java   
@Override
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
           throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
           IOException {

    Log_OC.d(TAG, "getClientFor(OwnCloudAccount ... : ");

    OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
            account.getBaseUri(), 
            context.getApplicationContext(),
            true);

    Log_OC.v(TAG, "    new client {" +
            (account.getName() != null ?
                    account.getName() :
                    AccountUtils.buildAccountName(account.getBaseUri(), "")

               ) + ", " + client.hashCode() + "}");

       if (account.getCredentials() == null) {
           account.loadCredentials(context);
       }
       client.setCredentials(account.getCredentials());
    return client;
}
项目:picframe    文件:SingleSessionManager.java   
@Override
public void saveAllClients(Context context, String accountType)
        throws AccountNotFoundException, AuthenticatorException, IOException,
        OperationCanceledException {

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log_OC.d(TAG, "Saving sessions... ");
    }

    Iterator<String> accountNames = mClientsWithKnownUsername.keySet().iterator();
    String accountName = null;
    Account account = null;
    while (accountNames.hasNext()) {
        accountName = accountNames.next();
        account = new Account(accountName, accountType);
        AccountUtils.saveClient(
                mClientsWithKnownUsername.get(accountName),
                account, 
                context);
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log_OC.d(TAG, "All sessions saved");
    }
}
项目:decider-android    文件:ApiUI.java   
public JSONObject getQuestions(QuestionsGetRequest request) throws IOException, JSONException, InvalidAccessTokenException, AuthenticatorException, OperationCanceledException, ServerErrorException {
    UrlParams params = new UrlParams();
    params.add("first_question_id", request.getFirstQuestionId());
    params.add("limit", request.getLimit());
    params.add("offset", request.getOffset());
    params.add("tab", request.getContentSection().toString().toLowerCase());
    for (int category : request.getCategories()) {
        params.add("categories[]", category);
    }

    HttpResponse response = makeProtectedGetCall(resolveApiUrl(request.getPath()), params);
    if (response == null || response.getBody() == null) {
        return null;
    }
    return new JSONObject(response.getBody());
}
项目:decider-android    文件:ApiUI.java   
public JSONObject uploadImage(ImageUploadRequest request) throws JSONException, IOException, InvalidAccessTokenException, AuthenticatorException, OperationCanceledException, ServerErrorException {
    UrlParams params = new UrlParams();
    ImageData image = request.getImage();
    ImageParamFacade imageParamFacade = new ImageParamFacade(image);

    try {
        imageParamFacade.write(params, "image", "preview");

        HttpResponse response = makeProtectedMultipartPostCall(resolveApiUrl(request.getPath()), params);
        if (response == null || response.getBody() == null) {
            return null;
        }
        return new JSONObject(response.getBody());
    } finally {
        imageParamFacade.close();
    }
}
项目:attendee-checkin    文件:BaseActivity.java   
@Override
public void run(AccountManagerFuture<Bundle> bundleAccountManagerFuture) {
    try {
        Bundle result = bundleAccountManagerFuture.getResult();
        Intent intent = (Intent) result.get(AccountManager.KEY_INTENT);
        if (intent == null) {
            String authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
            GutenbergApplication app = GutenbergApplication.from(BaseActivity.this);
            app.setAuthToken(authToken);
            app.requestSync(false);
        } else {
            startActivityForResult(intent, REQUEST_AUTHENTICATE);
        }
    } catch (OperationCanceledException | IOException | AuthenticatorException e) {
        Log.e(TAG, "Error authenticating.", e);
    }
}
项目:android-testdpc    文件:AddAccountActivity.java   
private void addAccount(String accountName) {
    AccountManager accountManager = AccountManager.get(this);
    Bundle bundle = new Bundle();
    if (!TextUtils.isEmpty(accountName)) {
        bundle.putString(AccountManager.KEY_ACCOUNT_NAME, accountName);
    }

    accountManager.addAccount(GOOGLE_ACCOUNT_TYPE, null, null, bundle, this,
            accountManagerFuture -> {
                try {
                    Bundle result = accountManagerFuture.getResult();
                    String accountNameAdded = result.getString(AccountManager.KEY_ACCOUNT_NAME);
                    Log.d(TAG, "addAccount - accountNameAdded: " + accountNameAdded);
                    if (mNextActivityIntent != null) {
                        startActivity(mNextActivityIntent);
                    }
                    finish();
                } catch (OperationCanceledException | AuthenticatorException
                        | IOException e) {
                    Log.e(TAG, "addAccount - failed", e);
                    Toast.makeText(AddAccountActivity.this,
                            R.string.fail_to_add_account, Toast.LENGTH_LONG).show();
                }
            }, null);
}
项目:Paperwork-Android    文件:NoteSync.java   
/**
 * Uploads all new local notes
 */
public static void uploadNotes(Context context, String host, String hash) throws IOException, JSONException, AuthenticatorException
{
    NoteDataSource dataSource = NoteDataSource.getInstance(context);
    List<Note> notSyncedNotes = dataSource.getNotes(DatabaseContract.NoteEntry.NOTE_STATUS.not_synced);

    for (Note note : notSyncedNotes)
    {
        Note newNote = createNote(host, hash, note);
        if (newNote != null)
        {
            dataSource.deleteNote(note);
            dataSource.insertNote(newNote);
        }
        else
        {
            Log.d(LOG_TAG, "Creating note failed");
        }
    }
}
项目:Paperwork-Android    文件:NoteSync.java   
/**
 * Updates notes on the server
 *
 * @param updatedNotes Notes that should be updated on the server
 */
public static void updateNotes(Context context, String host, String hash, List<Note> updatedNotes) throws IOException, JSONException, AuthenticatorException
{
    for (Note localNote : updatedNotes)
    {
        if (updateNote(host, hash, localNote))
        {
            localNote.setSyncStatus(DatabaseContract.NoteEntry.NOTE_STATUS.synced);
            NoteDataSource.getInstance(context).updateNote(localNote);
        }
        else
        {
            Log.d(LOG_TAG, "Updating note failed");
        }
    }
}
项目:chromium-net-for-android    文件:HttpNegotiateAuthenticator.java   
@Override
public void run(AccountManagerFuture<Bundle> future) {
    Bundle result;
    try {
        result = future.getResult();
    } catch (OperationCanceledException | AuthenticatorException | IOException e) {
        Log.w(TAG, "ERR_UNEXPECTED: Error while attempting to obtain a token.", e);
        nativeSetResult(mRequestData.nativeResultObject, NetError.ERR_UNEXPECTED, null);
        return;
    }

    if (result.containsKey(AccountManager.KEY_INTENT)) {
        final Context appContext = ContextUtils.getApplicationContext();

        // We wait for a broadcast that should be sent once the user is done interacting
        // with the notification
        // TODO(dgn) We currently hang around if the notification is swiped away, until
        // a LOGIN_ACCOUNTS_CHANGED_ACTION filter is received. It might be for something
        // unrelated then we would wait again here. Maybe we should limit the number of
        // retries in some way?
        BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                appContext.unregisterReceiver(this);
                mRequestData.accountManager.getAuthToken(mRequestData.account,
                        mRequestData.authTokenType, mRequestData.options,
                        true /* notifyAuthFailure */, new GetTokenCallback(mRequestData),
                        null);
            }

        };
        appContext.registerReceiver(broadcastReceiver,
                new IntentFilter(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION));
    } else {
        processResult(result, mRequestData);
    }
}
项目:chromium-net-for-android    文件:HttpNegotiateAuthenticatorTest.java   
/**
 * Returns a future that successfully returns the provided result.
 * Hides mocking related annoyances: compiler warnings and irrelevant catch clauses.
 */
private <T> AccountManagerFuture<T> makeFuture(T result) {
    // Avoid warning when creating mock accountManagerFuture, can't take .class of an
    // instantiated generic type, yet compiler complains if I leave it uninstantiated.
    @SuppressWarnings("unchecked")
    AccountManagerFuture<T> accountManagerFuture = mock(AccountManagerFuture.class);
    try {
        when(accountManagerFuture.getResult()).thenReturn(result);
    } catch (OperationCanceledException | AuthenticatorException | IOException e) {
        // Can never happen - artifact of Mockito.
        fail();
    }
    return accountManagerFuture;
}
项目:chromium-net-for-android    文件:HttpNegotiateAuthenticatorTest.java   
/**
 * Returns a future that fails with the provided exception when trying to get its result.
 * Hides mocking related annoyances: compiler warnings and irrelevant catch clauses.
 */
private <T> AccountManagerFuture<T> makeFuture(Exception ex) {
    // Avoid warning when creating mock accountManagerFuture, can't take .class of an
    // instantiated generic type, yet compiler complains if I leave it uninstantiated.
    @SuppressWarnings("unchecked")
    AccountManagerFuture<T> accountManagerFuture = mock(AccountManagerFuture.class);
    try {
        when(accountManagerFuture.getResult()).thenThrow(ex);
    } catch (OperationCanceledException | AuthenticatorException | IOException e) {
        // Can never happen - artifact of Mockito.
        fail();
    }
    return accountManagerFuture;
}
项目:letv    文件:LogonManager.java   
public void run(AccountManagerFuture<Bundle> arg0) {
    try {
        Bundle result = (Bundle) arg0.getResult();
        if (result != null) {
            LemallPlatform.getInstance().setSsoToken(result.getString("authtoken"));
        }
    } catch (OperationCanceledException e) {
        e.printStackTrace();
    } catch (AuthenticatorException e2) {
        e2.printStackTrace();
    } catch (IOException e3) {
        e3.printStackTrace();
    }
}
项目:XPrivacy    文件:XAccountManager.java   
@Override
public Bundle getResult() throws OperationCanceledException, IOException, AuthenticatorException {
    Bundle bundle = mFuture.getResult();
    String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
    String accountType = bundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
    if (isAccountAllowed(accountName, accountType, mUid))
        return bundle;
    else
        throw new OperationCanceledException("XPrivacy");
}
项目:smarper    文件:XAccountManager.java   
@Override
public Bundle getResult() throws OperationCanceledException, IOException, AuthenticatorException {
    Bundle bundle = mFuture.getResult();
    String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
    String accountType = bundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
    if (isAccountAllowed(accountName, accountType, mUid))
        return bundle;
    else
        throw new OperationCanceledException("XPrivacy");
}
项目:smarper    文件:XAccountManager.java   
@Override
public Bundle getResult(long timeout, TimeUnit unit) throws OperationCanceledException, IOException,
        AuthenticatorException {
    Bundle bundle = mFuture.getResult(timeout, unit);
    String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
    String accountType = bundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
    if (isAccountAllowed(accountName, accountType, mUid))
        return bundle;
    else
        throw new OperationCanceledException("XPrivacy");
}
项目:defect-party    文件:APIUtility.java   
/**
 * Makes a GET request and parses the received JSON string as a Map.
 */
public static Map getJson(OIDCAccountManager accountManager, String url, Account account,
                          AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {

    String jsonString = makeRequest(accountManager, HttpRequest.METHOD_GET, url, account, callback);
    Log.i("APIUtility", jsonString);
    return new Gson().fromJson(jsonString, Map.class);
}
项目:defect-party    文件:APIUtility.java   
public static List<JSONObject> getJsonList(OIDCAccountManager accountManager, String url, Account account,
                               AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {

    String jsonString = makeRequest(accountManager, HttpRequest.METHOD_GET, url, account, callback);
    Log.i("APIUtility", jsonString);
    return new Gson().fromJson(jsonString, List.class);
}
项目:defect-party    文件:APIUtility.java   
/**
 * Makes an arbitrary HTTP request using the provided account.
 *
 * If the request doesn't execute successfully on the first try, the tokens will be refreshed
 * and the request will be retried. If the second try fails, an exception will be raised.
 */
public static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account,
                                 AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {

    return makeRequest(accountManager, method, url, "", account, true, callback);
}
项目:defect-party    文件:APIUtility.java   
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, String body, Account account,
                                  boolean doRetry, AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {


    String accessToken = accountManager.getAccessToken(account, callback);
    String cookies = accountManager.getCookies(account, callback);

    // Prepare an API request using the accessToken
    HttpRequest request = new HttpRequest(url, method);
    request = prepareApiRequest(request, accessToken, cookies);
    if (body != "") {
        request.send(body);
    }

    if (request.ok()) {
        return request.body();
    } else {
        int code = request.code();

        String requestContent = "empty body";
        try {
            requestContent = request.body();
        } catch (HttpRequest.HttpRequestException e) {
            //Nothing to do, the response has no body or couldn't fetch it
            e.printStackTrace();
        }

        if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN ||
                (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) {
            // We're being denied access on the first try, let's renew the token and retry
            accountManager.invalidateAuthTokens(account);

            return makeRequest(accountManager, method, url, body, account, false, callback);
        } else {
            // An unrecoverable error or the renewed token didn't work either
            throw new IOException(request.code() + " " + request.message() + " " + requestContent);
        }
    }
}
项目:jogging-app    文件:Util.java   
public static String getAuthToken(Context ctx) {
    String token = null;
    try {
        token = getAccountManager(ctx).blockingGetAuthToken(getAccount(ctx), "Bearer", false);
    } catch (OperationCanceledException | IOException | AuthenticatorException e) {
        e.printStackTrace();
    }

    return "Bearer " + token;
}
项目:octoandroid    文件:AccountHelper.java   
private boolean removeAccount(Account account) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        return mAccountManager.removeAccountExplicitly(account);
    } else {
        //noinspection deprecation
        AccountManagerFuture<Boolean> feature = mAccountManager.removeAccount(account, null, null);
        try {
            return feature.getResult();
        } catch (OperationCanceledException | IOException | AuthenticatorException e) {
            e.printStackTrace();
            return false;
        }
    }
}
项目:Cirrus    文件:AbstractOwnCloudSyncAdapter.java   
protected void initClientForCurrentAccount() throws OperationCanceledException,
        AuthenticatorException, IOException, AccountNotFoundException {
    AccountUtils.constructFullURLForAccount(getContext(), account);
    OwnCloudAccount ocAccount = new OwnCloudAccount(account, getContext());
    mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
            getClientFor(ocAccount, getContext());
}
项目:xprivacy-mod    文件:XAccountManager.java   
@Override
public Bundle getResult() throws OperationCanceledException, IOException, AuthenticatorException {
    Bundle bundle = mFuture.getResult();
    String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
    String accountType = bundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
    if (isAccountAllowed(accountName, accountType, mUid))
        return bundle;
    else
        throw new OperationCanceledException("XPrivacy");
}
项目:xprivacy-mod    文件:XAccountManager.java   
@Override
public Bundle getResult(long timeout, TimeUnit unit) throws OperationCanceledException, IOException,
        AuthenticatorException {
    Bundle bundle = mFuture.getResult(timeout, unit);
    String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
    String accountType = bundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
    if (isAccountAllowed(accountName, accountType, mUid))
        return bundle;
    else
        throw new OperationCanceledException("XPrivacy");
}
项目:foursquared.eclair    文件:AuthenticationService.java   
public static Bundle createSystemAccount(Context context, String name, String password)
        throws OperationCanceledException, AuthenticatorException, IOException {
    Log.d(TAG, "createSystemAccount: " + name);
    Bundle options = new Bundle();
    options.putString(OPTION_USERNAME, name);
    options.putString(OPTION_PASSWORD, password);
    AccountManagerFuture<Bundle> future = AccountManager.get(context).addAccount(ACCOUNT_TYPE,
            null, null, options, null, null, null);
    return future.getResult(); // Blocks
}
项目:foursquared.eclair    文件:AuthenticationService.java   
public static Boolean removeSystemAccount(Context context, String name)
        throws OperationCanceledException, AuthenticatorException, IOException {
    Account account = new Account(name, ACCOUNT_TYPE);
    AccountManagerFuture<Boolean> future = AccountManager.get(context).removeAccount(account,
            null, null);
    return future.getResult();
}
项目:OIDCAndroidLib    文件:APIUtility.java   
/**
 * Makes a GET request and parses the received JSON string as a Map.
 */
public static Map getJson(OIDCAccountManager accountManager, String url, Account account,
                          AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {

    String jsonString = makeRequest(accountManager, HttpRequest.METHOD_GET, url, account, callback);
    return new Gson().fromJson(jsonString, Map.class);
}
项目:OIDCAndroidLib    文件:APIUtility.java   
/**
 * Makes an arbitrary HTTP request using the provided account.
 *
 * If the request doesn't execute successfully on the first try, the tokens will be refreshed
 * and the request will be retried. If the second try fails, an exception will be raised.
 */
public static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account,
                                 AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {

    return makeRequest(accountManager, method, url, account, true, callback);
}
项目:OIDCAndroidLib    文件:APIUtility.java   
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account,
                                  boolean doRetry, AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {


    String accessToken = accountManager.getAccessToken(account, callback);

    // Prepare an API request using the accessToken
    HttpRequest request = new HttpRequest(url, method);
    request = prepareApiRequest(request, accessToken);

    if (request.ok()) {
        return request.body();
    } else {
        int code = request.code();

        String requestContent = "empty body";
        try {
            requestContent = request.body();
        } catch (HttpRequest.HttpRequestException e) {
            //Nothing to do, the response has no body or couldn't fetch it
            e.printStackTrace();
        }

        if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN ||
                (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) {
            // We're being denied access on the first try, let's renew the token and retry
            accountManager.invalidateAuthTokens(account);

            return makeRequest(accountManager, method, url, account, false, callback);
        } else {
            // An unrecoverable error or the renewed token didn't work either
            throw new IOException(request.code() + " " + request.message() + " " + requestContent);
        }
    }
}