use of android.accounts.Account in project platform_frameworks_base by android.
the class DevicePolicyManagerService method hasIncompatibleAccountsLocked.
/**
* 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.
*/
private boolean hasIncompatibleAccountsLocked(int userId, @Nullable ComponentName owner) {
final long token = mInjector.binderClearCallingIdentity();
try {
final AccountManager am = AccountManager.get(mContext);
final Account[] accounts = am.getAccountsAsUser(userId);
if (accounts.length == 0) {
return false;
}
final String[] feature_allow = { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED };
final String[] feature_disallow = { DevicePolicyManager.ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED };
// Even if we find incompatible accounts along the way, we still check all accounts
// for logging.
boolean compatible = true;
for (Account account : accounts) {
if (hasAccountFeatures(am, account, feature_disallow)) {
Log.e(LOG_TAG, account + " has " + feature_disallow[0]);
compatible = false;
}
if (!hasAccountFeatures(am, account, feature_allow)) {
Log.e(LOG_TAG, account + " doesn't have " + feature_allow[0]);
compatible = false;
}
}
if (compatible) {
Log.w(LOG_TAG, "All accounts are compatible");
} else {
Log.e(LOG_TAG, "Found incompatible accounts");
}
// Then check if the owner is test-only.
String log;
if (owner == null) {
// Owner is unknown. Suppose it's not test-only
compatible = false;
log = "Only test-only device/profile owner can be installed with accounts";
} else if (isAdminTestOnlyLocked(owner, userId)) {
if (compatible) {
log = "Installing test-only owner " + owner;
} else {
log = "Can't install test-only owner " + owner + " with incompatible accounts";
}
} else {
compatible = false;
log = "Can't install non test-only owner " + owner + " with accounts";
}
if (compatible) {
Log.w(LOG_TAG, log);
} else {
Log.e(LOG_TAG, log);
}
return !compatible;
} finally {
mInjector.binderRestoreCallingIdentity(token);
}
}
use of android.accounts.Account in project platform_frameworks_base by android.
the class AppLaunch method checkAccountSignIn.
private void checkAccountSignIn() {
// for Gmail
if (mRequiredAccounts == null || mRequiredAccounts.isEmpty()) {
return;
}
final AccountManager am = (AccountManager) getInstrumentation().getTargetContext().getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = am.getAccounts();
// use set here in case device has multiple accounts of the same type
Set<String> foundAccounts = new HashSet<String>();
for (Account account : accounts) {
if (mRequiredAccounts.contains(account.type)) {
foundAccounts.add(account.type);
}
}
// are missing
if (mRequiredAccounts.size() != foundAccounts.size()) {
mRequiredAccounts.removeAll(foundAccounts);
StringBuilder sb = new StringBuilder("Device missing these accounts:");
for (String account : mRequiredAccounts) {
sb.append(' ');
sb.append(account);
}
fail(sb.toString());
}
}
use of android.accounts.Account in project iosched by google.
the class ScheduleWidgetProvider method onReceive.
@Override
public void onReceive(final Context context, Intent widgetIntent) {
final String action = widgetIntent.getAction();
if (REFRESH_ACTION.equals(action)) {
LOGD(TAG, "received REFRESH_ACTION from widget");
final boolean shouldSync = widgetIntent.getBooleanExtra(EXTRA_PERFORM_SYNC, false);
// Trigger sync
Account chosenAccount = AccountUtils.getActiveAccount(context);
if (shouldSync && chosenAccount != null) {
SyncHelper.requestManualSync();
}
// Notify the widget that the list view needs to be updated.
final AppWidgetManager mgr = AppWidgetManager.getInstance(context);
final ComponentName cn = new ComponentName(context, ScheduleWidgetProvider.class);
mgr.notifyAppWidgetViewDataChanged(mgr.getAppWidgetIds(cn), R.id.widget_schedule_list);
}
super.onReceive(context, widgetIntent);
}
use of android.accounts.Account in project iosched by google.
the class ForceSyncNowAction method run.
@Override
public void run(final Context context, final Callback callback) {
ConferenceDataHandler.resetDataTimestamp(context);
final Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
new AsyncTask<Context, Void, Void>() {
@Override
protected Void doInBackground(Context... contexts) {
Account account = AccountUtils.getActiveAccount(context);
if (account == null) {
callback.done(false, "Cannot sync if there is no active account.");
} else {
new SyncHelper(contexts[0]).performSync(new SyncResult(), bundle);
}
return null;
}
}.execute(context);
}
use of android.accounts.Account in project iosched by google.
the class AppNavigationViewAsDrawerImpl method setupAccountBox.
/**
* Sets up the account box. The account box is the area at the top of the nav drawer that shows
* which account the user is logged in as, and lets them switch accounts. It also shows the
* user's Google+ cover photo as background.
*/
private void setupAccountBox() {
final View chosenAccountView = mActivity.findViewById(R.id.chosen_account_view);
if (chosenAccountView == null) {
//This activity does not have an account box
return;
}
Account chosenAccount = AccountUtils.getActiveAccount(mActivity);
if (chosenAccount == null) {
// No account logged in; hide account box
chosenAccountView.setVisibility(View.GONE);
return;
} else {
chosenAccountView.setVisibility(View.VISIBLE);
}
ImageView coverImageView = (ImageView) chosenAccountView.findViewById(R.id.profile_cover_image);
ImageView profileImageView = (ImageView) chosenAccountView.findViewById(R.id.profile_image);
String imageUrl = AccountUtils.getPlusImageUrl(mActivity);
if (imageUrl != null) {
mImageLoader.loadImage(imageUrl, profileImageView);
}
String coverImageUrl = AccountUtils.getPlusCoverUrl(mActivity);
if (coverImageUrl != null) {
mActivity.findViewById(R.id.profile_cover_image_placeholder).setVisibility(View.GONE);
coverImageView.setVisibility(View.VISIBLE);
coverImageView.setContentDescription(mActivity.getResources().getString(R.string.navview_header_user_image_content_description));
mImageLoader.loadImage(coverImageUrl, coverImageView);
coverImageView.setColorFilter(mActivity.getResources().getColor(R.color.light_content_scrim));
} else {
mActivity.findViewById(R.id.profile_cover_image_placeholder).setVisibility(View.VISIBLE);
coverImageView.setVisibility(View.GONE);
}
List<Account> accounts = Arrays.asList(AccountUtils.getActiveAccount(getContext()));
populateAccountList(accounts);
}
Aggregations