Search in sources :

Example 1 with ChromePreferenceManager

use of org.chromium.chrome.browser.preferences.ChromePreferenceManager in project AndroidChromium by JackyAndroid.

the class ChromeTabbedActivity method finishNativeInitialization.

@Override
public void finishNativeInitialization() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.finishNativeInitialization");
        launchFirstRunExperience();
        ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(this);
        // after FRE is complete.
        if (!mIntentWithEffect && FirstRunStatus.getFirstRunFlowComplete(this)) {
            // first oppurtunity, and we don't want to show such content back to back.
            if (preferenceManager.getPromosSkippedOnFirstStart()) {
                // shown to avoid nagging users too much.
                if (!SigninPromoUtil.launchSigninPromoIfNeeded(this)) {
                    DataReductionPromoScreen.launchDataReductionPromo(this);
                }
            } else {
                preferenceManager.setPromosSkippedOnFirstStart(true);
            }
        }
        refreshSignIn();
        initializeUI();
        // The dataset has already been created, we need to initialize our state.
        mTabModelSelectorImpl.notifyChanged();
        getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, Window.PROGRESS_VISIBILITY_OFF);
        // Check for incognito tabs to handle the case where Chrome was swiped away in the
        // background.
        int incognitoCount = TabWindowManager.getInstance().getIncognitoTabCount();
        if (incognitoCount == 0)
            IncognitoNotificationManager.dismissIncognitoNotification();
        // LocaleManager can only function after the native library is loaded.
        mLocaleManager = LocaleManager.getInstance();
        mLocaleManager.showSearchEnginePromoIfNeeded(this);
        super.finishNativeInitialization();
    } finally {
        TraceEvent.end("ChromeTabbedActivity.finishNativeInitialization");
    }
}
Also used : ChromePreferenceManager(org.chromium.chrome.browser.preferences.ChromePreferenceManager) SuppressLint(android.annotation.SuppressLint)

Example 2 with ChromePreferenceManager

use of org.chromium.chrome.browser.preferences.ChromePreferenceManager in project AndroidChromium by JackyAndroid.

the class ContextualSearchSelectionController method handleShowUnhandledTapUIIfNeeded.

/**
     * Handles an unhandled tap gesture.
     */
void handleShowUnhandledTapUIIfNeeded(int x, int y) {
    mWasTapGestureDetected = false;
    // TODO(donnd): refactor to avoid needing a new handler API method as suggested by Pedro.
    if (mSelectionType != SelectionType.LONG_PRESS) {
        mWasTapGestureDetected = true;
        long tapTimeNanoseconds = System.nanoTime();
        // TODO(donnd): add a policy method to get adjusted tap count.
        ChromePreferenceManager prefs = ChromePreferenceManager.getInstance(mActivity);
        int adjustedTapsSinceOpen = prefs.getContextualSearchTapCount() - prefs.getContextualSearchTapQuickAnswerCount();
        // Explicitly destroy the old heuristics so native code can dispose data.
        if (mTapHeuristics != null)
            mTapHeuristics.destroy();
        mTapHeuristics = new TapSuppressionHeuristics(this, mLastTapState, x, y, adjustedTapsSinceOpen);
        // TODO(donnd): Move to be called when the panel closes to work with states that change.
        mTapHeuristics.logConditionState();
        // Tell the manager what it needs in order to log metrics on whether the tap would have
        // been suppressed if each of the heuristics were satisfied.
        mHandler.handleMetricsForWouldSuppressTap(mTapHeuristics);
        mX = x;
        mY = y;
        boolean shouldSuppressTap = mTapHeuristics.shouldSuppressTap();
        if (shouldSuppressTap) {
            mHandler.handleSuppressedTap();
        } else {
            // TODO(donnd): Find a better way to determine that a navigation will be triggered
            // by the tap, or merge with other time-consuming actions like gathering surrounding
            // text or detecting page mutations.
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mHandler.handleValidTap();
                }
            }, TAP_NAVIGATION_DETECTION_DELAY);
        }
        // Remember the tap state for subsequent tap evaluation.
        mLastTapState = new ContextualSearchTapState(x, y, tapTimeNanoseconds, shouldSuppressTap);
    } else {
        // Long press; reset last tap state.
        mLastTapState = null;
        mHandler.handleInvalidTap();
    }
}
Also used : ChromePreferenceManager(org.chromium.chrome.browser.preferences.ChromePreferenceManager) Handler(android.os.Handler)

Example 3 with ChromePreferenceManager

use of org.chromium.chrome.browser.preferences.ChromePreferenceManager in project AndroidChromium by JackyAndroid.

the class SigninHelper method validateAccountSettings.

public void validateAccountSettings(boolean accountsChanged) {
    // Ensure System accounts have been seeded.
    mAccountTrackerService.checkAndSeedSystemAccounts();
    if (!accountsChanged) {
        mAccountTrackerService.validateSystemAccounts();
    }
    Account syncAccount = mChromeSigninController.getSignedInUser();
    if (syncAccount == null) {
        // Never shows a signin promo if user has manually disconnected.
        String lastSyncAccountName = PrefServiceBridge.getInstance().getSyncLastAccountName();
        if (lastSyncAccountName != null && !lastSyncAccountName.isEmpty())
            return;
        SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
        boolean hasKnownAccountKeys = sharedPrefs.contains(ANDROID_ACCOUNTS_PREFS_KEY);
        // Nothing to do if Android accounts are not changed and already known to Chrome.
        if (hasKnownAccountKeys && !accountsChanged)
            return;
        List<String> currentAccountNames = AccountManagerHelper.get(mContext).getGoogleAccountNames();
        if (hasKnownAccountKeys) {
            ChromePreferenceManager chromePreferenceManager = ChromePreferenceManager.getInstance(mContext);
            if (!chromePreferenceManager.getSigninPromoShown()) {
                Set<String> lastKnownAccountNames = sharedPrefs.getStringSet(ANDROID_ACCOUNTS_PREFS_KEY, new HashSet<String>());
                Set<String> newAccountNames = new HashSet<String>(currentAccountNames);
                newAccountNames.removeAll(lastKnownAccountNames);
                if (!newAccountNames.isEmpty()) {
                    chromePreferenceManager.setShowSigninPromo(true);
                }
            }
        }
        sharedPrefs.edit().putStringSet(ANDROID_ACCOUNTS_PREFS_KEY, new HashSet<String>(currentAccountNames)).apply();
        return;
    }
    String renamedAccount = getNewSignedInAccountName(mContext);
    if (accountsChanged && renamedAccount != null) {
        handleAccountRename(ChromeSigninController.get(mContext).getSignedInAccountName(), renamedAccount);
        return;
    }
    // Always check for account deleted.
    if (!accountExists(mContext, syncAccount)) {
        // It is possible that Chrome got to this point without account
        // rename notification. Let us signout before doing a rename.
        // updateAccountRenameData(mContext, new SystemAccountChangeEventChecker());
        AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                updateAccountRenameData(mContext, new SystemAccountChangeEventChecker());
                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                String renamedAccount = getNewSignedInAccountName(mContext);
                if (renamedAccount == null) {
                    mSigninManager.signOut();
                } else {
                    validateAccountSettings(true);
                }
            }
        };
        task.execute();
        return;
    }
    if (accountsChanged) {
        // Account details have changed so inform the token service that credentials
        // should now be available.
        mOAuth2TokenService.validateAccounts(mContext, false);
    }
    if (mProfileSyncService != null && AndroidSyncSettings.isSyncEnabled(mContext)) {
        if (mProfileSyncService.isFirstSetupComplete()) {
            if (accountsChanged) {
                // Nudge the syncer to ensure it does a full sync.
                InvalidationServiceFactory.getForProfile(Profile.getLastUsedProfile()).requestSyncFromNativeChromeForAllTypes();
            }
        } else {
            // We should have set up sync but for some reason it's not enabled. Tell the sync
            // engine to start.
            mProfileSyncService.requestStart();
        }
    }
}
Also used : Account(android.accounts.Account) SharedPreferences(android.content.SharedPreferences) AsyncTask(android.os.AsyncTask) ChromePreferenceManager(org.chromium.chrome.browser.preferences.ChromePreferenceManager) HashSet(java.util.HashSet)

Example 4 with ChromePreferenceManager

use of org.chromium.chrome.browser.preferences.ChromePreferenceManager in project AndroidChromium by JackyAndroid.

the class SigninPromoUtil method launchSigninPromoIfNeeded.

/**
     * Launches the signin promo if it needs to be displayed.
     * @param activity The parent activity.
     * @return Whether the signin promo is shown.
     */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(activity);
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity))
        return false;
    if (!preferenceManager.getShowSigninPromo())
        return false;
    preferenceManager.setShowSigninPromo(false);
    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get(activity).isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }
    AccountSigninActivity.startAccountSigninActivity(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
Also used : ChromePreferenceManager(org.chromium.chrome.browser.preferences.ChromePreferenceManager)

Aggregations

ChromePreferenceManager (org.chromium.chrome.browser.preferences.ChromePreferenceManager)4 Account (android.accounts.Account)1 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 AsyncTask (android.os.AsyncTask)1 Handler (android.os.Handler)1 HashSet (java.util.HashSet)1