android.accounts.NetworkErrorException Java Examples

The following examples show how to use android.accounts.NetworkErrorException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Authenticator.java    From account-transfer-api with Apache License 2.0 6 votes vote down vote up
@Override
public Bundle addAccount(
        AccountAuthenticatorResponse response,
        String accountType,
        String authTokenType,
        String[] requiredFeatures,
        Bundle options)
        throws NetworkErrorException {
    Log.d(TAG, "addAccount");

    final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}
 
Example #2
Source File: Authenticator.java    From identity-samples with Apache License 2.0 6 votes vote down vote up
@Override
public Bundle addAccount(
        AccountAuthenticatorResponse response,
        String accountType,
        String authTokenType,
        String[] requiredFeatures,
        Bundle options)
        throws NetworkErrorException {
    Log.d(TAG, "addAccount");

    final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}
 
Example #3
Source File: Authenticator.java    From octoandroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account) throws NetworkErrorException {
        Bundle result = new Bundle();

        // Code below works, but now can't delete from within app...
//        // Check if app process is running before deleting account
//        if (LifecycleHandler.isApplicationInBackground()) {
//            result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
//            mHandler.post(toastRunnable);
//        } else {
//            String name = account.name;
//            mPrinterDetailsByName.execute(new GetPrinterDetailsSubscriber(), name);
//            result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
//        }

        String name = account.name;
        mSyncWithDb.execute(new DefaultSubscriber() {}, name);
        result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
        return result;
    }
 
Example #4
Source File: PredatorAuthenticator.java    From Capstone-Project with MIT License 6 votes vote down vote up
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
    // Check if the context was null or not.
    if (mContextWeakReference.get() == null) {
        return null;
    }

    Intent intent = new Intent(mContextWeakReference.get(), AuthenticatorActivity.class);
    intent.putExtra(Constants.Authenticator.ACCOUNT_TYPE, accountType);
    intent.putExtra(Constants.Authenticator.AUTH_TOKEN_TYPE, authTokenType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

    Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);

    return bundle;
}
 
Example #5
Source File: AppAccountAuthenticator.java    From account-authenticator with Apache License 2.0 6 votes vote down vote up
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
    AuthenticatorManager authenticatorManager = AuthenticatorManager.authenticatorManager;
    Bundle result;
    AccountManager accountManager = AccountManager.get(context);
    // case 1: access token is available
    result = authenticatorManager.getAccessTokenFromCache(account, authTokenType, accountManager);
    if (result != null) {
        return result;
    }
    final String refreshToken = accountManager.getPassword(account);
    // case 2: access token is not available but refresh token is
    if (refreshToken != null) {
        result = authenticatorManager.makeResultBundle(account, refreshToken, null);
        return result;
    }
    // case 3: neither tokens is available but the account exists
    if (isAccountAvailable(account, accountManager)) {
        result = authenticatorManager.makeResultBundle(account, null, null);
        return result;
    }
    // case 4: account does not exist
    return new Bundle();
}
 
Example #6
Source File: OAuthAuthenticator.java    From auth with MIT License 6 votes vote down vote up
@Override
public Bundle addAccount(
        @NonNull AccountAuthenticatorResponse response,
        @NonNull String accountType,
        @Nullable String authTokenType,
        @Nullable String[] requiredFeatures,
        @Nullable Bundle options)
        throws NetworkErrorException {
    log(
            "addAccount for %s as %s with features %s and options %s",
            accountType,
            authTokenType,
            Arrays.toString(requiredFeatures),
            BundleUtil.toString(options));

    final Bundle bundle = new Bundle();
    final Intent intent = service.getLoginIntent();
    if (intent != null) {
        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
        bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    }

    return bundle;
}
 
Example #7
Source File: DummyAccountService.java    From ChannelSurfer with MIT License 6 votes vote down vote up
@Override
public Bundle addAccount(AccountAuthenticatorResponse accountAuthenticatorResponse,
                         String s, String s2, String[] strings, Bundle options) throws NetworkErrorException {
    Log.d(TAG, "Trying to add an account");
    final AccountManager accountManager = AccountManager.get(getApplicationContext());
    String ACCOUNT_NAME = getApplicationContext().getString(R.string.app_name);
    Account[] accounts = accountManager.getAccountsByType(ACCOUNT_NAME);
    Log.d(TAG, accounts.length+"accounts");
    Log.d(TAG, accounts[0].toString());
    if(accounts.length > 0) {
        final Intent intent = new Intent(getApplicationContext(), DummyAccountIgnoreActivity.class);
        intent.putExtra(DummyAccountIgnoreActivity.INTENT_ACTION, DummyAccountIgnoreActivity.ACTION_ADD);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(AccountManager.KEY_INTENT, intent);
        return bundle;
    } else {
        return null;
    }
}
 
Example #8
Source File: BaseRepository.java    From FastLib with Apache License 2.0 6 votes vote down vote up
/**
 * @param observable 用于解析 统一返回实体统一做相应的错误码--如登录失效
 * @param <T>
 * @return
 */
protected <T> Observable<T> transform(Observable<BaseEntity<T>> observable) {
    return FastTransformer.switchSchedulers(
            observable.retryWhen(new FastRetryWhen())
                    .flatMap((Function<BaseEntity<T>, ObservableSource<T>>) result -> {
                        if (result == null) {
                            return Observable.error(new NetworkErrorException());
                        } else {
                            if (result.success) {
                                return result.data != null ? Observable.just(result.data)
                                        : Observable.error(new FastNullException());
                            } else {
                                return Observable.error(new NetworkErrorException());
                            }
                        }
                    }));
}
 
Example #9
Source File: Authenticator.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle updateCredentials(
        AccountAuthenticatorResponse r,
        Account account,
        String s, Bundle bundle) throws NetworkErrorException {
    return null;
}
 
Example #10
Source File: UserLceeWidget.java    From relight with Apache License 2.0 5 votes vote down vote up
@Override
protected LceeStatus onLoadData() throws NetworkErrorException {
    data = UserDataSource.getInstance().getUsersFromRemote();
    if (data.isEmpty())
        return LceeStatus.Empty;
    return LceeStatus.Content;
}
 
Example #11
Source File: PredatorAuthenticator.java    From Capstone-Project with MIT License 5 votes vote down vote up
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
    // Check if the context was null or not.
    if (mContextWeakReference.get() == null) {
        return null;
    }

    // Check if any authToken is available or not.
    AccountManager accountManager = AccountManager.get(mContextWeakReference.get());
    String authToken = accountManager.peekAuthToken(account, authTokenType);

    // If the authToken is available, return it.
    if (!TextUtils.isEmpty(authToken)) {
        Bundle result = new Bundle();
        result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
        result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
        result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
        return result;
    }

    // If the authToken is unavailable, retry for a new one.
    Intent intent = new Intent(mContextWeakReference.get(), AuthenticatorActivity.class);
    intent.putExtra(Constants.Authenticator.ACCOUNT_TYPE, account.type);
    intent.putExtra(Constants.Authenticator.AUTH_TOKEN_TYPE, authTokenType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

    Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);

    return bundle;
}
 
Example #12
Source File: AccountAuthenticatorService.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
                         String authTokenType, String[] requiredFeatures, Bundle options)
        throws NetworkErrorException {

    Intent intent = new Intent(mContext, AddAccountActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

    Bundle result = new Bundle();
    result.putParcelable(AccountManager.KEY_INTENT, intent);
    return result;
}
 
Example #13
Source File: Authenticator.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle addAccount(
        AccountAuthenticatorResponse r,
        String s,
        String s2,
        String[] strings,
        Bundle bundle) throws NetworkErrorException {
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(mContext, "Unsupported operation", Toast.LENGTH_SHORT).show();
        }
    });
    return null;
}
 
Example #14
Source File: Authenticator.java    From device-database with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle confirmCredentials(AccountAuthenticatorResponse response,
                                 Account account,
                                 Bundle options)
        throws NetworkErrorException {
    throw new UnsupportedOperationException("Not yet implemented");
}
 
Example #15
Source File: Authenticator.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle confirmCredentials(
        AccountAuthenticatorResponse r,
        Account account,
        Bundle bundle) throws NetworkErrorException {
    return null;
}
 
Example #16
Source File: AccountAuthenticator.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@NonNull
@Override
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account) throws NetworkErrorException {


    final Bundle result = new Bundle();
    result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);


    SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext);
    sPref.edit()
            .remove("queueName")
            .remove(Configs.LOGIN_USER_LOGIN)
            .remove("username")
            .remove("useravatar")
            .remove("userRepo")
            .remove(Preferences.REPOS_SYNCED)
            .remove(Preferences.TIMELINE_ACEPTED_BOOL)
            .remove(Preferences.SHARE_TIMELINE_DOWNLOAD_BOOL)
            .remove(Preferences.REPOS_SYNCED)
     .apply();
    SecurePreferences.getInstance().edit().remove("access_token").apply();
    mContext.stopService(new Intent(mContext, RabbitMqService.class));

    return result;

}
 
Example #17
Source File: AccountAuthenticator.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
    Log.d("udinic", TAG + "> addAccount");

    final Intent intent = new Intent(mContext, LoginActivity.class);
    intent.putExtra(LoginActivity.ARG_ACCOUNT_TYPE, accountType);
    intent.putExtra(LoginActivity.ARG_AUTH_TYPE, authTokenType);
    intent.putExtra(LoginActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
    intent.putExtra(LoginActivity.ARG_OPTIONS_BUNDLE, options);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);


    final Bundle bundle = new Bundle();

    if(!ArrayUtils.isEmpty(requiredFeatures) && ArrayUtils.contains(requiredFeatures, "timelineLogin")){

        String username = options.getString(AccountManager.KEY_ACCOUNT_NAME);
        String password = options.getString(AccountManager.KEY_PASSWORD);
        String authToken = options.getString(AccountManager.KEY_AUTHTOKEN);
        Account account = new Account(username, accountType);
        AccountManager.get(mContext).addAccountExplicitly(account, password, null);
        AccountManager.get(mContext).setAuthToken(account, authTokenType, authToken);
        Bundle data = new Bundle();
        data.putString(AccountManager.KEY_ACCOUNT_NAME, username);
        data.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);

        response.onResult(data);

    }else{
        bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    }

    return bundle;
}
 
Example #18
Source File: OAuthAuthenticator.java    From auth with MIT License 5 votes vote down vote up
@Override
public Bundle confirmCredentials(
        @NonNull AccountAuthenticatorResponse response,
        @NonNull Account account,
        @Nullable Bundle options)
        throws NetworkErrorException {
    log("confirmCredentials for %s with options %s", account, BundleUtil.toString(options));
    return null;
}
 
Example #19
Source File: Authenticator.java    From background-geolocation-android with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle confirmCredentials(
        AccountAuthenticatorResponse r,
        Account account,
        Bundle bundle) throws NetworkErrorException {
    return null;
}
 
Example #20
Source File: OAuthAuthenticator.java    From auth with MIT License 5 votes vote down vote up
@Override
public Bundle hasFeatures(
        @NonNull AccountAuthenticatorResponse response,
        @NonNull Account account,
        @NonNull String[] features)
        throws NetworkErrorException {
    log("hasFeatures for %s and %s", account, Arrays.toString(features));
    return null;
}
 
Example #21
Source File: OAuthAuthenticatorTest.java    From auth with MIT License 5 votes vote down vote up
private Bundle getAuthTokenWithResponse(
        Account account, AccountAuthenticatorResponse response) {
    try {
        return authenticator.getAuthToken(response, account, "bearer", null);
    } catch (NetworkErrorException e) {
        fail(e.getMessage());
        return null;
    }
}
 
Example #22
Source File: AuthenticatorService.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle getAuthToken(
        AccountAuthenticatorResponse r,
        Account account,
        String s,
        Bundle bundle) throws NetworkErrorException {
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: AuthenticatorService.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle confirmCredentials(
        AccountAuthenticatorResponse r,
        Account account,
        Bundle bundle) throws NetworkErrorException {
    return null;
}
 
Example #24
Source File: Authenticator.java    From device-database with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response,
                           Account account,
                           String authTokenType,
                           Bundle options)
        throws NetworkErrorException {
    throw new UnsupportedOperationException("Not yet implemented");
}
 
Example #25
Source File: SunshineAuthenticator.java    From Krishi-Seva with MIT License 5 votes vote down vote up
@Override
public Bundle confirmCredentials(
        AccountAuthenticatorResponse r,
        Account account,
        Bundle bundle) throws NetworkErrorException {
    return null;
}
 
Example #26
Source File: Authenticator.java    From react-native-account-manager with MIT License 5 votes vote down vote up
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) throws NetworkErrorException
{
    // If the caller requested an authToken type we don't support, then
    // return an error
    /*if(authTokenType isn't a supported auth token type)
    {
        final Bundle result = new Bundle();
        result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType");
        return result;
    }*/

    // Extract the username and password from the Account Manager, and ask
    // the server for an appropriate AuthToken.
    final AccountManager am = AccountManager.get(ctx);
    final String password = am.getPassword(account);
    if (password != null)
    {
        final String authToken = ""; /* TODO: Login with account.name and passwod */
        if (!TextUtils.isEmpty(authToken))
        {
            final Bundle result = new Bundle();
            result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
            result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
            result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
            return result;
        }
    }

    //final Intent intent = null; // TODO: Login intent
    //final Bundle bundle = new Bundle();
    //bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    //return bundle;
    return null;
}
 
Example #27
Source File: DummyAuthenticator.java    From react-native-sync-adapter with MIT License 5 votes vote down vote up
@Override
public Bundle addAccount(
        AccountAuthenticatorResponse r,
        String s,
        String s2,
        String[] strings,
        Bundle bundle) throws NetworkErrorException {
    return null;
}
 
Example #28
Source File: DummyAuthenticator.java    From react-native-sync-adapter with MIT License 5 votes vote down vote up
@Override
public Bundle confirmCredentials(
        AccountAuthenticatorResponse r,
        Account account,
        Bundle bundle) throws NetworkErrorException {
    return null;
}
 
Example #29
Source File: DummyAuthenticator.java    From react-native-sync-adapter with MIT License 5 votes vote down vote up
@Override
public Bundle updateCredentials(
        AccountAuthenticatorResponse r,
        Account account,
        String s, Bundle bundle) throws NetworkErrorException {
    throw new UnsupportedOperationException();
}
 
Example #30
Source File: AuthenticationService.java    From HouSi with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle addAccount(AccountAuthenticatorResponse response,
                         String accountType, String authTokenType,
                         String[] requiredFeatures, Bundle options) throws NetworkErrorException {
    Bundle bundle = new Bundle();
    Intent intent = new Intent(AuthenticationService.this, MainActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}