List of usage examples for android.accounts AccountManager getUserData
public String getUserData(final Account account, final String key)
From source file:com.nextgis.maplib.map.LayerFactory.java
public Connection getConnectionFromAccount(Context context, String accountName) { final AccountManager accountManager = AccountManager.get(context); for (Account account : accountManager.getAccountsByType(NGW_ACCOUNT_TYPE)) { if (account.name.equals(accountName)) { String url = accountManager.getUserData(account, "url"); String password = accountManager.getPassword(account); String login = accountManager.getUserData(account, "login"); return new Connection(accountName, login, password, url); }/*from ww w . j a va 2 s .c o m*/ } return null; }
From source file:com.ubuntuone.android.files.fragment.ValidateFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTracker = GoogleAnalyticsTracker.getInstance(); mTracker.start(Analytics.U1F_ACCOUNT, getActivity()); callback = (ValidationFragmentCallback) getActivity(); handler = new Handler(); final AccountManager am = AccountManager.get(getActivity()); final Account account = Preferences.getAccount(am); final String hint = am.getUserData(account, Constants.KEY_AUTHTOKEN_HINT); if (hint != null) { oauthData = hint;/*from w ww .j a v a 2 s .c o m*/ handler.post(new Runnable() { @Override public void run() { validate(); } }); } else { Log.e(TAG, "ValidateFragment used with no OAuth hint!"); getActivity().finish(); } }
From source file:com.clearcenter.mobile_demo.mdAuthenticator.java
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) throws NetworkErrorException { Log.v(TAG, "getAuthToken()"); // If the caller requested an authToken type we don't support, then // return an error if (!authTokenType.equals(mdConstants.AUTHTOKEN_TYPE)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; }//from w ww . j av a 2 s . c o m // 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); final String hostname = am.getUserData(account, "hostname"); final String username = am.getUserData(account, "username"); if (password != null) { try { mdSSLUtil.DisableSecurity(); final String authToken = mdRest.Login(hostname, username, null, password); if (!TextUtils.isEmpty(authToken)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, mdConstants.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); return result; } } catch (JSONException e) { Log.e(TAG, "JSONException", e); } catch (GeneralSecurityException e) { Log.e(TAG, "GeneralSecurityException", e); } } Log.v(TAG, "Asking for password again..."); // If we get here, then we couldn't access the user's password - so we // need to re-prompt them for their credentials. We do that by creating // an intent to display our mdAuthenticatorActivity panel. final Intent intent = new Intent(ctx, mdAuthenticatorActivity.class); intent.putExtra(mdAuthenticatorActivity.PARAM_NICKNAME, account.name); intent.putExtra(mdAuthenticatorActivity.PARAM_USERNAME, username); intent.putExtra(mdAuthenticatorActivity.PARAM_HOSTNAME, hostname); intent.putExtra(mdAuthenticatorActivity.PARAM_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(mdAuthenticatorActivity.PARAM_CONFIRM_CREDENTIALS, true); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.xiaomi.account.utils.SysHelper.java
public static XiaomiUserInfo queryXiaomiUserInfo(Context context, Account account) { XiaomiUserInfo xiaomiUserInfo = null; if (account != null) { String userId = account.name; AccountManager am = AccountManager.get(context); int count = 0; while (count < 2) { String authToken = getAuthToken(am, account, Constants.PASSPORT_API_SID); ExtendedAuthToken extendedAuthToken = ExtendedAuthToken.parse(authToken); if (extendedAuthToken == null) { break; }/* www . j a v a 2 s .c o m*/ String serviceToken = extendedAuthToken.authToken; String security = extendedAuthToken.security; if (serviceToken == null || security == null) { break; } try { xiaomiUserInfo = CloudHelper.getXiaomiUserInfo(userId, am.getUserData(account, Constants.KEY_ENCRYPTED_USER_ID), serviceToken, security); break; } catch (InvalidResponseException e) { Log.e(TAG, "invalid response when get user info", e); } catch (CipherException e2) { Log.e(TAG, "CipherException when get user info", e2); } catch (IOException e3) { Log.e(TAG, "IOException when get user info", e3); } catch (AuthenticationFailureException e4) { Log.e(TAG, "auth failure when get user info", e4); am.invalidateAuthToken(account.type, authToken); count++; } catch (AccessDeniedException e5) { Log.e(TAG, "access denied when get user info", e5); } } } else { Log.w(TAG, "no Xiaomi account, skip to query user info"); } return xiaomiUserInfo; }
From source file:com.xiaomi.account.utils.SysHelper.java
public static boolean deleteBindedDevice(Context context, String devId) { boolean z = false; Account account = ExtraAccountManager.getXiaomiAccount(context); if (account != null) { AccountManager am = AccountManager.get(context); int count = 0; while (count < 2) { String authToken = getAuthToken(am, account, com.xiaomi.account.Constants.DEVICE_INFO_SID); ExtendedAuthToken extendedAuthToken = ExtendedAuthToken.parse(authToken); if (extendedAuthToken == null) { break; }// ww w . j a v a 2 s . co m String serviceToken = extendedAuthToken.authToken; String security = extendedAuthToken.security; if (serviceToken == null || security == null) { break; } try { z = CloudHelper.deleteBindedDevice(account.name, am.getUserData(account, Constants.KEY_ENCRYPTED_USER_ID), devId, serviceToken, security); break; } catch (AuthenticationFailureException e) { Log.e(TAG, "auth failure when delete device", e); am.invalidateAuthToken(account.type, authToken); count++; } } } else { Log.w(TAG, "no Xiaomi account"); } return z; }
From source file:com.xiaomi.account.utils.SysHelper.java
public static XiaomiUserProfile queryXiaomiUserProfile(Context context, Account account) { XiaomiUserProfile xiaomiUserProfile = null; if (account != null) { AccountManager am = AccountManager.get(context); int count = 0; while (count < 2) { String authToken = getAuthToken(am, account, Constants.PASSPORT_API_SID); ExtendedAuthToken extendedAuthToken = ExtendedAuthToken.parse(authToken); if (extendedAuthToken == null) { break; }//from w w w . j av a 2s. co m String serviceToken = extendedAuthToken.authToken; String security = extendedAuthToken.security; if (serviceToken == null || security == null) { break; } try { xiaomiUserProfile = CloudHelper.getXiaomiUserProfile(account.name, am.getUserData(account, Constants.KEY_ENCRYPTED_USER_ID), serviceToken, security); break; } catch (InvalidResponseException e) { Log.e(TAG, "invalid response when get user info", e); } catch (CipherException e2) { Log.e(TAG, "CipherException when get user info", e2); } catch (IOException e3) { Log.e(TAG, "IOException when get user info", e3); } catch (AuthenticationFailureException e4) { Log.e(TAG, "auth failure when get user info", e4); am.invalidateAuthToken(account.type, authToken); count++; } catch (AccessDeniedException e5) { Log.e(TAG, "access denied when get user info", e5); } } } else { Log.w(TAG, "no Xiaomi account, skip to query user profile"); } return xiaomiUserProfile; }
From source file:com.digitalarx.android.files.FileOperationsHelper.java
/** * @return 'True' if the server supports the Share API */// w w w .j a va 2s.c om public boolean isSharedSupported() { if (mFileActivity.getAccount() != null) { AccountManager accountManager = AccountManager.get(mFileActivity); String version = accountManager.getUserData(mFileActivity.getAccount(), Constants.KEY_OC_VERSION); return (new OwnCloudVersion(version)).isSharedSupported(); } return false; }
From source file:de.kollode.redminebrowser.sync.SyncHelper.java
void performSync(SyncResult syncResult, Account account) throws IOException { NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setContentTitle("Projects").setContentText("Syncing in progress") .setSmallIcon(R.drawable.ic_launcher); final ContentResolver resolver = mContext.getContentResolver(); ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); AccountManager accMgr = AccountManager.get(this.mContext); String serverUrl = accMgr.getUserData(account, "serverUrl"); if (isOnline()) { final long startRemote = System.currentTimeMillis(); int syncedProjects = 0; Log.i(sTag, "Remote syncing speakers"); Log.i(sTag, serverUrl);// www . j a va2 s . c om try { int offset = 0; int numberOfProjects; int limit = 100; boolean loadMore = true; do { String restQuery = "sort=updated_on:desc&limit=" + limit + "&offset=" + offset + "&key=" + accMgr.getPassword(account); Log.d(sTag, "REST URL: " + serverUrl + "/projects.json?" + restQuery); JSONObject projectsJson = getJsonFromUrl(serverUrl + "/projects.json?" + restQuery); numberOfProjects = projectsJson.getInt("total_count"); mBuilder.setProgress(numberOfProjects, syncedProjects, false); mNotificationManager.notify(0, mBuilder.build()); if (numberOfProjects < limit + offset) { Log.d(sTag, "Enough Projects"); loadMore = false; } else { Log.d(sTag, "More Projects"); offset += limit; } JSONArray projects = projectsJson.getJSONArray("projects"); for (int i = 0; i < projects.length(); i++) { JSONObject project = projects.getJSONObject(i); Builder projectBuilder = ContentProviderOperation .newInsert(Project.buildProjectsUri(account.name)); Log.d(sTag, project.toString()); try { projectBuilder.withValue(Project.PARENT, project.getJSONObject("parent").getInt("id")); } catch (Exception e) { } batch.add(projectBuilder.withValue(BaseColumns._ID, project.getInt("id")) .withValue(Project.NAME, project.getString("name")) .withValue(Project.IDENTIFIER, project.getString("identifier")) .withValue(Project.UPDATED, System.currentTimeMillis()) .withValue(Project.CREATED, System.currentTimeMillis()) .withValue(Project.CREATED_ON, project.getString("created_on")) .withValue(Project.UPDATED_ON, project.getString("updated_on")).build()); mBuilder.setProgress(numberOfProjects, syncedProjects++, false); mNotificationManager.notify(0, mBuilder.build()); } } while (loadMore && !this.isCanceled()); try { // Apply all queued up batch operations for local data. resolver.applyBatch(RedmineTables.CONTENT_AUTHORITY, batch); } catch (RemoteException e) { throw new RuntimeException("Problem applying batch operation", e); } catch (OperationApplicationException e) { throw new RuntimeException("Problem applying batch operation", e); } } catch (Exception e) { e.printStackTrace(); } if (this.isCanceled()) { mBuilder.setContentText("Sync was canceled").setProgress(0, 0, false); } else { mBuilder.setContentText("Sync complete").setProgress(0, 0, false); } mNotificationManager.notify(0, mBuilder.build()); syncResult.delayUntil = ((long) 60 * 60); Log.d(sTag, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); Log.d(sTag, "Number of projects: " + syncedProjects); } }
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public boolean isUserAnonymous(Context ctx) { AccountManager am = AccountManager.get(ctx); Account account = new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)); String authority = am.getUserData(account, Constants.KEY_AUTHORITY); return Constants.TOKEN_TYPE_ANONYMOUS.equals(authority); }
From source file:com.nextgis.maplibui.SelectNGWResourceDialog.java
protected Connections fillConnections() { Connections connections = new Connections(getString(R.string.accounts)); final AccountManager accountManager = AccountManager.get(getActivity()); for (Account account : accountManager.getAccountsByType(NGW_ACCOUNT_TYPE)) { String url = accountManager.getUserData(account, "url"); String password = accountManager.getPassword(account); String login = accountManager.getUserData(account, "login"); connections.add(new Connection(account.name, login, password, url)); }//from w ww.ja va 2s .co m return connections; }