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;
}
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);
}
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);
}
}
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;
}
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();
}
Aggregations