Search in sources :

Example 6 with AccountManager

use of android.accounts.AccountManager in project android by owncloud.

the class GetUserProfileOperation method run.

/**
     * Performs the operation.
     *
     * Target user account is implicit in 'client'.
     *
     * Stored account is implicit in {@link #getStorageManager()}.
     *
     * @return      Result of the operation. If successful, includes an instance of
     *              {@link String} with the display name retrieved from the server.
     *              Call {@link RemoteOperationResult#getData()}.get(0) to get it.
     */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    UserProfile userProfile = null;
    RemoteOperationResult result = null;
    try {
        /// get display name
        GetRemoteUserInfoOperation getDisplayName = new GetRemoteUserInfoOperation();
        RemoteOperationResult remoteResult = getDisplayName.execute(client);
        if (remoteResult.isSuccess()) {
            // store display name with account data
            AccountManager accountManager = AccountManager.get(MainApp.getAppContext());
            UserInfo userInfo = (UserInfo) remoteResult.getData().get(0);
            Account storedAccount = getStorageManager().getAccount();
            accountManager.setUserData(storedAccount, // keep also there, for the moment
            AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.mDisplayName);
            // map user info into UserProfile instance
            userProfile = new UserProfile(storedAccount.name, userInfo.mId, userInfo.mDisplayName, userInfo.mEmail);
            /// get avatar (optional for success)
            int dimension = getAvatarDimension();
            UserProfile.UserAvatar currentUserAvatar = getUserProfilesRepository().getAvatar(storedAccount.name);
            GetRemoteUserAvatarOperation getAvatarOperation = new GetRemoteUserAvatarOperation(dimension, (currentUserAvatar == null) ? "" : currentUserAvatar.getEtag());
            remoteResult = getAvatarOperation.execute(client);
            if (remoteResult.isSuccess()) {
                GetRemoteUserAvatarOperation.ResultData avatar = (GetRemoteUserAvatarOperation.ResultData) remoteResult.getData().get(0);
                //
                byte[] avatarData = avatar.getAvatarData();
                String avatarKey = ThumbnailsCacheManager.addAvatarToCache(storedAccount.name, avatarData, dimension);
                UserProfile.UserAvatar userAvatar = new UserProfile.UserAvatar(avatarKey, avatar.getMimeType(), avatar.getEtag());
                userProfile.setAvatar(userAvatar);
            } else if (remoteResult.getCode().equals(RemoteOperationResult.ResultCode.FILE_NOT_FOUND)) {
                Log_OC.i(TAG, "No avatar available, removing cached copy");
                getUserProfilesRepository().deleteAvatar(storedAccount.name);
                ThumbnailsCacheManager.removeAvatarFromCache(storedAccount.name);
            }
            // others are ignored, including 304 (not modified), so the avatar is only stored
            // if changed in the server :D
            /// store userProfile
            getUserProfilesRepository().update(userProfile);
            result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK);
            ArrayList<Object> data = new ArrayList<>();
            data.add(userProfile);
            result.setData(data);
        } else {
            result = remoteResult;
        }
    } catch (Exception e) {
        Log_OC.e(TAG, "Exception while getting user profile: ", e);
        result = new RemoteOperationResult(e);
    }
    return result;
}
Also used : Account(android.accounts.Account) UserProfile(com.owncloud.android.datamodel.UserProfile) GetRemoteUserInfoOperation(com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) UserInfo(com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation.UserInfo) AccountManager(android.accounts.AccountManager) GetRemoteUserAvatarOperation(com.owncloud.android.lib.resources.users.GetRemoteUserAvatarOperation)

Example 7 with AccountManager

use of android.accounts.AccountManager in project android by owncloud.

the class AccountUtils method hasSearchUsersSupport.

public static boolean hasSearchUsersSupport(Account account) {
    OwnCloudVersion serverVersion = null;
    if (account != null) {
        AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());
        String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);
        if (serverVersionStr != null) {
            serverVersion = new OwnCloudVersion(serverVersionStr);
        }
    }
    return (serverVersion != null ? serverVersion.isSearchUsersSupported() : false);
}
Also used : AccountManager(android.accounts.AccountManager) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Example 8 with AccountManager

use of android.accounts.AccountManager in project android_frameworks_base by ResurrectionRemix.

the class DevicePolicyManagerService method hasIncompatibleAccountsOrNonAdbNoLock.

/**
     * Return true if a given user has any accounts that'll prevent installing a device or profile
     * owner {@code owner}.
     * - If the user has no accounts, then return false.
     * - Otherwise, if the owner is unknown (== null), or is not test-only, then return true.
     * - Otherwise, if there's any account that does not have ..._ALLOWED, or does have
     *   ..._DISALLOWED, return true.
     * - Otherwise return false.
     *
     * If the caller is *not* ADB, it also returns true.  The returned value shouldn't be used
     * when the caller is not ADB.
     *
     * DO NOT CALL IT WITH THE DPMS LOCK HELD.
     */
private boolean hasIncompatibleAccountsOrNonAdbNoLock(int userId, @Nullable ComponentName owner) {
    final boolean isAdb = (mInjector.binderGetCallingUid() == Process.SHELL_UID) || (mInjector.binderGetCallingUid() == Process.ROOT_UID);
    if (!isAdb) {
        return true;
    }
    if (Thread.holdsLock(this)) {
        Slog.wtf(LOG_TAG, "hasIncompatibleAccountsNoLock() called with the DPMS lock held.");
        return true;
    }
    final long token = mInjector.binderClearCallingIdentity();
    try {
        final AccountManager am = AccountManager.get(mContext);
        final Account[] accounts = am.getAccountsAsUser(userId);
        if (accounts.length == 0) {
            return false;
        }
        synchronized (this) {
            if (owner == null || !isAdminTestOnlyLocked(owner, userId)) {
                Log.w(LOG_TAG, "Non test-only owner can't be installed with existing accounts.");
                return true;
            }
        }
        final String[] feature_allow = { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED };
        final String[] feature_disallow = { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED };
        boolean compatible = true;
        for (Account account : accounts) {
            if (hasAccountFeatures(am, account, feature_disallow)) {
                Log.e(LOG_TAG, account + " has " + feature_disallow[0]);
                compatible = false;
                break;
            }
            if (!hasAccountFeatures(am, account, feature_allow)) {
                Log.e(LOG_TAG, account + " doesn't have " + feature_allow[0]);
                compatible = false;
                break;
            }
        }
        if (compatible) {
            Log.w(LOG_TAG, "All accounts are compatible");
        } else {
            Log.e(LOG_TAG, "Found incompatible accounts");
        }
        return !compatible;
    } finally {
        mInjector.binderRestoreCallingIdentity(token);
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) ParcelableString(com.android.internal.util.ParcelableString)

Example 9 with AccountManager

use of android.accounts.AccountManager in project android_packages_apps_Launcher2 by CyanogenMod.

the class LauncherTransitionable method skipCustomClingIfNoAccounts.

private boolean skipCustomClingIfNoAccounts() {
    Cling cling = (Cling) findViewById(R.id.workspace_cling);
    boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
    if (customCling) {
        AccountManager am = AccountManager.get(this);
        Account[] accounts = am.getAccountsByType("com.google");
        return accounts.length == 0;
    }
    return false;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 10 with AccountManager

use of android.accounts.AccountManager in project AndroidChromium by JackyAndroid.

the class ChromeBackupAgent method getAccounts.

// May be overriden by downstream products that access account information in a different way.
protected Account[] getAccounts() {
    Log.d(TAG, "Getting accounts from AccountManager");
    AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
    return manager.getAccounts();
}
Also used : AccountManager(android.accounts.AccountManager)

Aggregations

AccountManager (android.accounts.AccountManager)180 Account (android.accounts.Account)121 Bundle (android.os.Bundle)28 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)16 View (android.view.View)16 TextView (android.widget.TextView)16 Context (android.content.Context)15 IOException (java.io.IOException)14 UserAccountManager (com.nextcloud.client.account.UserAccountManager)13 OperationCanceledException (android.accounts.OperationCanceledException)11 ImageView (android.widget.ImageView)9 AuthenticatorDescription (android.accounts.AuthenticatorDescription)8 UserHandle (android.os.UserHandle)8 LayoutInflater (android.view.LayoutInflater)8 AuthenticatorException (android.accounts.AuthenticatorException)7 UserInfo (android.content.pm.UserInfo)7 Resources (android.content.res.Resources)7 Drawable (android.graphics.drawable.Drawable)7 LinearLayout (android.widget.LinearLayout)7