Example usage for android.accounts AccountManager getUserData

List of usage examples for android.accounts AccountManager getUserData

Introduction

In this page you can find the example usage for android.accounts AccountManager getUserData.

Prototype

public String getUserData(final Account account, final String key) 

Source Link

Document

Gets the user data named by "key" associated with the account.

Usage

From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java

/**
 * //w  ww .  j a  va  2s  . com
 * @return
 * @throws IOException 
 * @throws AuthenticatorException 
 * @throws OperationCanceledException 
 */
public static OwnCloudCredentials getCredentialsForAccount(Context context, Account account)
        throws OperationCanceledException, AuthenticatorException, IOException {

    OwnCloudCredentials credentials = null;
    AccountManager am = AccountManager.get(context);

    boolean isOauth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null;

    boolean isSamlSso = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;

    String username = account.name.substring(0, account.name.lastIndexOf('@'));

    if (isOauth2) {
        String accessToken = am.blockingGetAuthToken(account,
                AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false);

        credentials = OwnCloudCredentialsFactory.newBearerCredentials(accessToken);

    } else if (isSamlSso) {
        String accessToken = am.blockingGetAuthToken(account,
                AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false);

        credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken);

    } else {
        String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type),
                false);

        credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);
    }

    return credentials;

}

From source file:com.ntsync.android.sync.shared.SyncUtils.java

/**
 * Get the last saved Sync Result for an account.
 * // www  .  j  a v  a 2s.co m
 * @param accountManager
 * @param account
 * @return Sync Result or null if there was not saved Result.
 */
public static AccountSyncResult getSyncResult(AccountManager accountManager, Account account) {
    String syncState = accountManager.getUserData(account, SYNC_STATE);

    AccountSyncResult result = null;
    if (syncState != null) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            result = mapper.readValue(syncState, AccountSyncResult.class);
        } catch (IOException e) {
            LogHelper.logW(TAG,
                    "Could not parse AccountSyncResult for account: " + account + " Value:" + syncState, e);
        }
    }
    return result;
}

From source file:com.ntsync.android.sync.shared.SyncUtils.java

/**
 * Get a stored PaymentConfirmation (has to be verified on the server).
 * // www . j  av  a2  s.  co  m
 * @param account
 * @param accountManager
 * @return null if none is available.
 */
public static PaymentData getPayment(Account account, AccountManager accountManager) {
    PaymentData payment = null;
    String paymentData = accountManager.getUserData(account, LAST_PAYMENT);
    if (paymentData != null) {
        int pos1 = paymentData.indexOf(';');
        int pos2 = paymentData.lastIndexOf(';');
        int startTimePos = pos2 + 1;
        if (pos1 > 0 && pos2 > 0 && pos2 > pos1 && startTimePos < paymentData.length()) {
            try {
                long paymentSaveDate = Long.parseLong(paymentData.substring(startTimePos));
                UUID priceId = UUID.fromString(paymentData.substring(0, pos1));
                JSONObject obj = new JSONObject(paymentData.substring(pos1 + 1, pos2));
                payment = new PaymentData(priceId, paymentSaveDate, obj);
            } catch (JSONException ex) {
                Log.w(TAG, "Invalid PaymentConfirmation data. Data Ignored", ex);
            } catch (IllegalArgumentException ex) {
                Log.w(TAG, "Invalid PaymentConfirmation data. Data Ignored", ex);
            }
        }
        if (payment == null) {
            // Remove invalid PaymentData
            accountManager.setUserData(account, LAST_PAYMENT, null);
        }
    }

    return payment;
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.ChannelService.java

public static String getChannelId(Context context) {
    AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    Account ac = AccountUtils.getAccount(context, false);

    if (ac == null) {
        log.warn("Account is null. Channel id can not be get");
        return null;
    }/*from   w w w . j a v a 2s.  co m*/

    String channelId = am.getUserData(ac, JsonKeys.CHANNEL_ID);
    if ((channelId == null || channelId.length() == 0)) {
        return null;
    } else {
        return channelId;
    }
}

From source file:ir.keloud.android.lib.common.accounts.AccountUtils.java

/**
* Restore the client cookies/*ww w  .  j a  v a 2  s  .co  m*/
* @param account
* @param client 
* @param context
*/
public static void restoreCookies(Account account, KeloudClient client, Context context) {

    Log_OC.d(TAG, "Restoring cookies for " + account.name);

    // Account Manager
    AccountManager am = AccountManager.get(context.getApplicationContext());

    Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri();

    String cookiesString = am.getUserData(account, Constants.KEY_COOKIES);
    if (cookiesString != null) {
        String[] cookies = cookiesString.split(";");
        if (cookies.length > 0) {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = new Cookie();
                int equalPos = cookies[i].indexOf('=');
                cookie.setName(cookies[i].substring(0, equalPos));
                cookie.setValue(cookies[i].substring(equalPos + 1));
                cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT 
                cookie.setPath(serverUri.getPath()); // VERY IMPORTANT

                client.getState().addCookie(cookie);
            }
        }
    }
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static String getDeviceSalt(AccountManager accountManager, Account account) {
    if (account == null) {
        if (CMAccount.DEBUG)
            Log.d(TAG, "No CMAccount configured!");
        return null;
    }//from www .jav  a2  s .  c  o m
    return accountManager.getUserData(account, CMAccount.ACCOUNT_EXTRA_DEVICE_SALT);
}

From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java

/**
* Restore the client cookies//from   w w w.j av a  2 s . c o  m
* @param account
* @param client 
* @param context
*/
public static void restoreCookies(Account account, OwnCloudClient client, Context context) {

    Log_OC.d(TAG, "Restoring cookies for " + account.name);

    // Account Manager
    AccountManager am = AccountManager.get(context.getApplicationContext());

    Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri();

    String cookiesString = am.getUserData(account, Constants.KEY_COOKIES);
    if (cookiesString != null) {
        String[] cookies = cookiesString.split(";");
        if (cookies.length > 0) {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = new Cookie();
                int equalPos = cookies[i].indexOf('=');
                cookie.setName(cookies[i].substring(0, equalPos));
                cookie.setValue(cookies[i].substring(equalPos + 1));
                cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT 
                cookie.setPath(serverUri.getPath()); // VERY IMPORTANT

                client.getState().addCookie(cookie);
            }
        }
    }
}

From source file:com.phonemetra.account.util.AccountUtils.java

public static String getDeviceSalt(AccountManager accountManager, Account account) {
    if (account == null) {
        if (Account.DEBUG)
            Log.d(TAG, "No Account configured!");
        return null;
    }//from w w  w . j av a2  s.  co m
    return accountManager.getUserData(account, Account.ACCOUNT_EXTRA_DEVICE_SALT);
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static byte[] getHmacSecret(AccountManager accountManager, Account account) {
    if (account == null) {
        if (CMAccount.DEBUG)
            Log.d(TAG, "No CMAccount configured!");
        return null;
    }//from w  ww.  j a va 2  s. c o  m
    return Base64.decode(accountManager.getUserData(account, CMAccount.ACCOUNT_EXTRA_HMAC_SECRET),
            Base64.NO_WRAP);
}

From source file:com.phonemetra.account.util.AccountUtils.java

public static byte[] getHmacSecret(AccountManager accountManager, Account account) {
    if (account == null) {
        if (Account.DEBUG)
            Log.d(TAG, "No Account configured!");
        return null;
    }/*from   www . j  av  a2  s .co  m*/
    return Base64.decode(accountManager.getUserData(account, Account.ACCOUNT_EXTRA_HMAC_SECRET),
            Base64.NO_WRAP);
}