private void doSignIn() { Log.d(TAG, "Committing the sign-in process now"); assert mSignInAccount != null; // Cache the signed-in account name. ChromeSigninController.get(mContext).setSignedInAccountName(mSignInAccount.name); // Tell the native side that sign-in has completed. // This will trigger NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL. nativeOnSignInCompleted(mNativeSigninManagerAndroid, mSignInAccount.name); // Register for invalidations. InvalidationController invalidationController = InvalidationController.get(mContext); invalidationController.setRegisteredTypes(mSignInAccount, true, new HashSet<ModelType>()); // Sign-in to sync. ProfileSyncService profileSyncService = ProfileSyncService.get(mContext); if (SyncStatusHelper.get(mContext).isSyncEnabled(mSignInAccount) && !profileSyncService.hasSyncSetupCompleted()) { profileSyncService.setSetupInProgress(true); profileSyncService.syncSignIn(); } if (mSignInObserver != null) mSignInObserver.onSigninComplete(); // All done, cleanup. Log.d(TAG, "Signin done"); mSignInActivity = null; mSignInAccount = null; mSignInObserver = null; }
@Override protected void setUp() throws Exception { super.setUp(); clearAppData(); // Mock out the account manager on the device. mContext = new SyncTestUtil.SyncTestContext(getInstrumentation().getTargetContext()); mAccountManager = new MockAccountManager(mContext, getInstrumentation().getContext()); AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAccountManager); MockSyncContentResolverDelegate syncContentResolverDelegate = new MockSyncContentResolverDelegate(); syncContentResolverDelegate.setMasterSyncAutomatically(true); SyncStatusHelper.overrideSyncStatusHelperForTests(mContext, syncContentResolverDelegate); // This call initializes the ChromeSigninController to use our test context. ChromeSigninController.get(mContext); startChromeBrowserProcessSync(getInstrumentation().getTargetContext()); ThreadUtils.runOnUiThreadBlocking( new Runnable() { @Override public void run() { mSyncController = SyncController.get(mContext); } }); SyncTestUtil.verifySyncServerIsRunning(); }
/** * Signs out of Chrome. * * <p>This method clears the signed-in username, stops sync and sends out a sign-out notification * on the native side. * * @param activity If not null then a progress dialog is shown over the activity until signout * completes, in case the account had management enabled. The activity must be valid until the * callback is invoked. * @param callback Will be invoked after signout completes, if not null. */ public void signOut(Activity activity, Runnable callback) { mSignOutCallback = callback; boolean wipeData = getManagementDomain() != null; Log.d(TAG, "Signing out, wipe data? " + wipeData); ChromeSigninController.get(mContext).clearSignedInUser(); ProfileSyncService.get(mContext).signOut(); nativeSignOut(mNativeSigninManagerAndroid); if (wipeData) { wipeProfileData(activity); } else { onSignOutDone(); } }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mCanDeleteBrowsingHistory = PrefServiceBridge.getInstance().canDeleteBrowsingHistory(); DialogOption[] options = getDialogOptions(); String[] optionNames = new String[options.length]; Resources resources = getResources(); for (int i = 0; i < options.length; i++) { optionNames[i] = resources.getString(options[i].getResourceId()); } mSelectedOptions = getDefaultDialogOptionsSelections(); mAdapter = new ClearBrowsingDataAdapter(options, optionNames, getDisabledDialogOptions()); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme) .setTitle(R.string.clear_browsing_data_title) .setPositiveButton(R.string.clear_data_delete, this) .setNegativeButton(R.string.cancel, this) .setAdapter(mAdapter, null); // OnClickListener is registered manually. if (ChromeSigninController.get(getActivity()).isSignedIn()) { final String message = getString(R.string.clear_cookies_no_sign_out_summary); final SpannableString messageWithLink = SpanApplier.applySpans( message, new SpanApplier.SpanInfo( "<link>", "</link>", new ClickableSpan() { @Override public void onClick(View widget) { dismiss(); Preferences prefActivity = (Preferences) getActivity(); prefActivity.startFragment(AccountManagementFragment.class.getName(), null); } // Change link formatting to use no underline @Override public void updateDrawState(TextPaint textPaint) { textPaint.setColor(textPaint.linkColor); textPaint.setUnderlineText(false); } })); View view = getActivity().getLayoutInflater().inflate(R.layout.single_line_bottom_text_dialog, null); TextView summaryView = (TextView) view.findViewById(R.id.summary); summaryView.setText(messageWithLink); summaryView.setMovementMethod(LinkMovementMethod.getInstance()); builder.setView(view); } mDialog = builder.create(); mDialog .getListView() .setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // The present behaviour of AlertDialog is to dismiss after the onClick event. // Hence we are manually overriding this outside the builder. mAdapter.onClick(position); } }); return mDialog; }
public boolean isSignedIn() { return ChromeSigninController.get(mContext).isSignedIn(); }