org.chromium.chrome.browser.signin.AccountManagementFragment Java Examples

The following examples show how to use org.chromium.chrome.browser.signin.AccountManagementFragment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignInPreference.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void setupSignedIn(String accountName) {
    String title = AccountManagementFragment.getCachedUserName(accountName);
    if (title == null) {
        Profile profile = Profile.getLastUsedProfile();
        String cachedName = ProfileDownloader.getCachedFullName(profile);
        Bitmap cachedBitmap = ProfileDownloader.getCachedAvatar(profile);
        if (TextUtils.isEmpty(cachedName) || cachedBitmap == null) {
            AccountManagementFragment.startFetchingAccountInformation(
                    getContext(), profile, accountName);
        }
        title = TextUtils.isEmpty(cachedName) ? accountName : cachedName;
    }
    setTitle(title);
    setSummary(SyncPreference.getSyncStatusSummary(getContext()));
    setFragment(AccountManagementFragment.class.getName());

    Resources resources = getContext().getResources();
    Bitmap bitmap = AccountManagementFragment.getUserPicture(accountName, resources);
    setIcon(new BitmapDrawable(resources, bitmap));

    setWidgetLayoutResource(
            SyncPreference.showSyncErrorIcon(getContext()) ? R.layout.sync_error_widget : 0);

    setViewEnabled(true);
}
 
Example #2
Source File: ForcedSigninProcessor.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Processes the fully automatic non-FRE-related forced sign-in.
 * This is used to enforce the environment for Android EDU and child accounts.
 */
private static void processForcedSignIn(final Context appContext) {
    final SigninManager signinManager = SigninManager.get(appContext);
    // By definition we have finished all the checks for first run.
    signinManager.onFirstRunCheckDone();
    if (!FeatureUtilities.canAllowSync(appContext) || !signinManager.isSignInAllowed()) {
        Log.d(TAG, "Sign in disallowed");
        return;
    }
    AccountManagerHelper.get(appContext).getGoogleAccounts(new Callback<Account[]>() {
        @Override
        public void onResult(Account[] accounts) {
            if (accounts.length != 1) {
                Log.d(TAG, "Incorrect number of accounts (%d)", accounts.length);
                return;
            }
            signinManager.signIn(accounts[0], null, new SigninManager.SignInCallback() {
                @Override
                public void onSignInComplete() {
                    // Since this is a forced signin, signout is not allowed.
                    AccountManagementFragment.setSignOutAllowedPreferenceValue(
                            appContext, false);
                }

                @Override
                public void onSignInAborted() {}
            });
        }
    });
}
 
Example #3
Source File: ForcedSigninProcessor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Processes the fully automatic non-FRE-related forced sign-in.
 * This is used to enforce the environment for Android EDU and child accounts.
 */
private static void processForcedSignIn(final Context appContext) {
    final SigninManager signinManager = SigninManager.get(appContext);
    // By definition we have finished all the checks for first run.
    signinManager.onFirstRunCheckDone();
    if (!FeatureUtilities.canAllowSync(appContext) || !signinManager.isSignInAllowed()) {
        Log.d(TAG, "Sign in disallowed");
        return;
    }
    AccountManagerHelper.get(appContext).getGoogleAccounts(new Callback<Account[]>() {
        @Override
        public void onResult(Account[] accounts) {
            if (accounts.length != 1) {
                Log.d(TAG, "Incorrect number of accounts (%d)", accounts.length);
                return;
            }
            signinManager.signIn(accounts[0], null, new SigninManager.SignInCallback() {
                @Override
                public void onSignInComplete() {
                    // Since this is a forced signin, signout is not allowed.
                    AccountManagementFragment.setSignOutAllowedPreferenceValue(
                            appContext, false);
                }

                @Override
                public void onSignInAborted() {}
            });
        }
    });
}
 
Example #4
Source File: ForcedSigninProcessor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Processes the fully automatic non-FRE-related forced sign-in.
 * This is used to enforce the environment for Android EDU and child accounts.
 */
private static void processForcedSignIn(
        final Context appContext, @Nullable final Runnable onComplete) {
    final SigninManager signinManager = SigninManager.get(appContext);
    // By definition we have finished all the checks for first run.
    signinManager.onFirstRunCheckDone();
    if (!FeatureUtilities.canAllowSync(appContext) || !signinManager.isSignInAllowed()) {
        Log.d(TAG, "Sign in disallowed");
        return;
    }
    AccountManagerHelper.get().getGoogleAccounts(new Callback<Account[]>() {
        @Override
        public void onResult(Account[] accounts) {
            if (accounts.length != 1) {
                Log.d(TAG, "Incorrect number of accounts (%d)", accounts.length);
                return;
            }
            signinManager.signIn(accounts[0], null, new SigninManager.SignInCallback() {
                @Override
                public void onSignInComplete() {
                    // Since this is a forced signin, signout is not allowed.
                    AccountManagementFragment.setSignOutAllowedPreferenceValue(false);
                    if (onComplete != null) {
                        onComplete.run();
                    }
                }

                @Override
                public void onSignInAborted() {
                    if (onComplete != null) {
                        onComplete.run();
                    }
                }
            });
        }
    });
}
 
Example #5
Source File: SignInPreference.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the title, summary, and image based on the current sign-in state.
 */
private void update() {
    String title;
    String summary;
    String fragment;

    Account account = ChromeSigninController.get(getContext()).getSignedInUser();
    if (account == null) {
        title = getContext().getString(R.string.sign_in_to_chrome);
        summary = getContext().getString(R.string.sign_in_to_chrome_summary);
        fragment = null;
    } else {
        summary = SyncPreference.getSyncStatusSummary(getContext());
        fragment = AccountManagementFragment.class.getName();
        title = AccountManagementFragment.getCachedUserName(account.name);
        if (title == null) {
            final Profile profile = Profile.getLastUsedProfile();
            String cachedName = ProfileDownloader.getCachedFullName(profile);
            Bitmap cachedBitmap = ProfileDownloader.getCachedAvatar(profile);
            if (TextUtils.isEmpty(cachedName) || cachedBitmap == null) {
                AccountManagementFragment.startFetchingAccountInformation(
                        getContext(), profile, account.name);
            }
            title = TextUtils.isEmpty(cachedName) ? account.name : cachedName;
        }
    }

    setTitle(title);
    setSummary(summary);
    setFragment(fragment);
    updateSyncStatusIcon();

    ChromeSigninController signinController = ChromeSigninController.get(getContext());
    boolean enabled = signinController.isSignedIn()
            || SigninManager.get(getContext()).isSignInAllowed();
    if (mViewEnabled != enabled) {
        mViewEnabled = enabled;
        notifyChanged();
    }
    if (!enabled) setFragment(null);

    if (SigninManager.get(getContext()).isSigninDisabledByPolicy()) {
        setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
    } else {
        Resources resources = getContext().getResources();
        Bitmap bitmap = AccountManagementFragment.getUserPicture(
                signinController.getSignedInAccountName(), resources);
        setIcon(new BitmapDrawable(resources, bitmap));
    }

    setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (!AccountSigninActivity.startIfAllowed(
                        getContext(), SigninAccessPoint.SETTINGS)) {
                return false;
            }

            setEnabled(false);
            return true;
        }
    });
}
 
Example #6
Source File: SignInPreference.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void onProfileDownloaded(String accountId, String fullName, String givenName,
        Bitmap bitmap) {
    AccountManagementFragment.updateUserNamePictureCache(accountId, fullName, bitmap);
    update();
}
 
Example #7
Source File: SyncController.java    From delion with Apache License 2.0 4 votes vote down vote up
private SyncController(Context context) {
    mContext = context;
    mChromeSigninController = ChromeSigninController.get(mContext);
    AndroidSyncSettings.registerObserver(context, this);
    mProfileSyncService = ProfileSyncService.get();
    mProfileSyncService.addSyncStateChangedListener(this);
    mProfileSyncService.setMasterSyncEnabledProvider(
            new ProfileSyncService.MasterSyncEnabledProvider() {
                public boolean isMasterSyncEnabled() {
                    return AndroidSyncSettings.isMasterSyncEnabled(mContext);
                }
            });

    setSessionsId();

    // Create the SyncNotificationController.
    mSyncNotificationController = new SyncNotificationController(
            mContext, PassphraseActivity.class, AccountManagementFragment.class);
    mProfileSyncService.addSyncStateChangedListener(mSyncNotificationController);

    updateSyncStateFromAndroid();

    // When the application gets paused, tell sync to flush the directory to disk.
    ApplicationStatus.registerStateListenerForAllActivities(new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.PAUSED) {
                mProfileSyncService.flushDirectory();
            }
        }
    });

    GmsCoreSyncListener gmsCoreSyncListener =
            ((ChromeApplication) context.getApplicationContext()).createGmsCoreSyncListener();
    if (gmsCoreSyncListener != null) {
        mProfileSyncService.addSyncStateChangedListener(gmsCoreSyncListener);
    }

    SigninManager.get(mContext).addSignInStateObserver(new SigninManager.SignInStateObserver() {
        @Override
        public void onSignedIn() {
            mProfileSyncService.requestStart();
        }

        @Override
        public void onSignedOut() {}
    });
}
 
Example #8
Source File: FirstRunSignInProcessor.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Opens sign in settings as requested in the FRE sign-in dialog.
 */
private static void openSignInSettings(Activity activity) {
    Intent intent = PreferencesLauncher.createIntentForSettingsPage(
            activity, AccountManagementFragment.class.getName());
    activity.startActivity(intent);
}
 
Example #9
Source File: SignInPreference.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the title, summary, and image based on the current sign-in state.
 */
private void update() {
    String title;
    String summary;
    String fragment;

    Account account = ChromeSigninController.get(getContext()).getSignedInUser();
    if (account == null) {
        title = getContext().getString(R.string.sign_in_to_chrome);
        summary = getContext().getString(R.string.sign_in_to_chrome_summary);
        fragment = null;
    } else {
        summary = SyncPreference.getSyncStatusSummary(getContext());
        fragment = AccountManagementFragment.class.getName();
        title = AccountManagementFragment.getCachedUserName(account.name);
        if (title == null) {
            final Profile profile = Profile.getLastUsedProfile();
            String cachedName = ProfileDownloader.getCachedFullName(profile);
            Bitmap cachedBitmap = ProfileDownloader.getCachedAvatar(profile);
            if (TextUtils.isEmpty(cachedName) || cachedBitmap == null) {
                AccountManagementFragment.startFetchingAccountInformation(
                        getContext(), profile, account.name);
            }
            title = TextUtils.isEmpty(cachedName) ? account.name : cachedName;
        }
    }

    setTitle(title);
    setSummary(summary);
    setFragment(fragment);
    updateSyncStatusIcon();

    ChromeSigninController signinController = ChromeSigninController.get(getContext());
    boolean enabled = signinController.isSignedIn()
            || SigninManager.get(getContext()).isSignInAllowed();
    if (mViewEnabled != enabled) {
        mViewEnabled = enabled;
        notifyChanged();
    }
    if (!enabled) setFragment(null);

    if (SigninManager.get(getContext()).isSigninDisabledByPolicy()) {
        setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
    } else {
        Resources resources = getContext().getResources();
        Bitmap bitmap = AccountManagementFragment.getUserPicture(
                signinController.getSignedInAccountName(), resources);
        setIcon(new BitmapDrawable(resources, bitmap));
    }

    setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (!AccountSigninActivity.startIfAllowed(
                        getContext(), SigninAccessPoint.SETTINGS)) {
                return false;
            }

            setEnabled(false);
            return true;
        }
    });

    if (account == null && enabled) {
        RecordUserAction.record("Signin_Impression_FromSettings");
    }
}
 
Example #10
Source File: SignInPreference.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void onProfileDownloaded(String accountId, String fullName, String givenName,
        Bitmap bitmap) {
    AccountManagementFragment.updateUserNamePictureCache(accountId, fullName, bitmap);
    update();
}
 
Example #11
Source File: SyncController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private SyncController(Context context) {
    mContext = context;
    mChromeSigninController = ChromeSigninController.get(mContext);
    AndroidSyncSettings.registerObserver(context, this);
    mProfileSyncService = ProfileSyncService.get();
    mProfileSyncService.addSyncStateChangedListener(this);
    mProfileSyncService.setMasterSyncEnabledProvider(
            new ProfileSyncService.MasterSyncEnabledProvider() {
                public boolean isMasterSyncEnabled() {
                    return AndroidSyncSettings.isMasterSyncEnabled(mContext);
                }
            });

    setSessionsId();

    // Create the SyncNotificationController.
    mSyncNotificationController = new SyncNotificationController(
            mContext, PassphraseActivity.class, AccountManagementFragment.class);
    mProfileSyncService.addSyncStateChangedListener(mSyncNotificationController);

    updateSyncStateFromAndroid();

    // When the application gets paused, tell sync to flush the directory to disk.
    ApplicationStatus.registerStateListenerForAllActivities(new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.PAUSED) {
                mProfileSyncService.flushDirectory();
            }
        }
    });

    GmsCoreSyncListener gmsCoreSyncListener =
            ((ChromeApplication) context.getApplicationContext()).createGmsCoreSyncListener();
    if (gmsCoreSyncListener != null) {
        mProfileSyncService.addSyncStateChangedListener(gmsCoreSyncListener);
    }

    SigninManager.get(mContext).addSignInStateObserver(new SigninManager.SignInStateObserver() {
        @Override
        public void onSignedIn() {
            mProfileSyncService.requestStart();
        }

        @Override
        public void onSignedOut() {}
    });
}
 
Example #12
Source File: FirstRunSignInProcessor.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Opens sign in settings as requested in the FRE sign-in dialog.
 */
private static void openSignInSettings(Activity activity) {
    Intent intent = PreferencesLauncher.createIntentForSettingsPage(
            activity, AccountManagementFragment.class.getName());
    activity.startActivity(intent);
}
 
Example #13
Source File: SignInPreference.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onProfileDownloaded(String accountId, String fullName, String givenName,
        Bitmap bitmap) {
    AccountManagementFragment.updateUserNamePictureCache(accountId, fullName, bitmap);
    update();
}
 
Example #14
Source File: SyncController.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private SyncController(Context context) {
    mContext = context;
    mChromeSigninController = ChromeSigninController.get();
    AndroidSyncSettings.registerObserver(context, this);
    mProfileSyncService = ProfileSyncService.get();
    mProfileSyncService.addSyncStateChangedListener(this);
    mProfileSyncService.setMasterSyncEnabledProvider(
            new ProfileSyncService.MasterSyncEnabledProvider() {
                @Override
                public boolean isMasterSyncEnabled() {
                    return AndroidSyncSettings.isMasterSyncEnabled(mContext);
                }
            });

    setSessionsId();

    // Create the SyncNotificationController.
    mSyncNotificationController = new SyncNotificationController(
            mContext, PassphraseActivity.class, AccountManagementFragment.class);
    mProfileSyncService.addSyncStateChangedListener(mSyncNotificationController);

    updateSyncStateFromAndroid();

    // When the application gets paused, tell sync to flush the directory to disk.
    ApplicationStatus.registerStateListenerForAllActivities(new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.PAUSED) {
                mProfileSyncService.flushDirectory();
            }
        }
    });

    GmsCoreSyncListener gmsCoreSyncListener = AppHooks.get().createGmsCoreSyncListener();
    if (gmsCoreSyncListener != null) {
        mProfileSyncService.addSyncStateChangedListener(gmsCoreSyncListener);
    }

    SigninManager.get(mContext).addSignInStateObserver(new SigninManager.SignInStateObserver() {
        @Override
        public void onSignedIn() {
            mProfileSyncService.requestStart();
        }

        @Override
        public void onSignedOut() {}
    });
}
 
Example #15
Source File: FirstRunSignInProcessor.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Opens sign in settings as requested in the FRE sign-in dialog.
 */
private static void openSignInSettings(Activity activity) {
    Intent intent = PreferencesLauncher.createIntentForSettingsPage(
            activity, AccountManagementFragment.class.getName());
    activity.startActivity(intent);
}