Search in sources :

Example 31 with Account

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);
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) ParcelableString(com.android.internal.util.ParcelableString)

Example 32 with Account

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());
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) HashSet(java.util.HashSet)

Example 33 with Account

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);
}
Also used : Account(android.accounts.Account) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 34 with Account

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);
}
Also used : Context(android.content.Context) Account(android.accounts.Account) Bundle(android.os.Bundle) SyncHelper(com.google.samples.apps.iosched.sync.SyncHelper) SyncResult(android.content.SyncResult)

Example 35 with Account

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);
}
Also used : Account(android.accounts.Account) ImageView(android.widget.ImageView) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

Account (android.accounts.Account)550 Bundle (android.os.Bundle)108 AccountManager (android.accounts.AccountManager)79 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)49 Intent (android.content.Intent)40 File (java.io.File)37 Cursor (android.database.Cursor)31 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)29 PersistableBundle (android.os.PersistableBundle)27 UserInfo (android.content.pm.UserInfo)22 MockContentResolver (android.test.mock.MockContentResolver)22 HashMap (java.util.HashMap)20 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)20 RemoteException (android.os.RemoteException)19 FileOutputStream (java.io.FileOutputStream)19 IOException (java.io.IOException)19 SmallTest (android.test.suitebuilder.annotation.SmallTest)18 HashSet (java.util.HashSet)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16