Java Code Examples for org.chromium.chrome.browser.ChromeFeatureList#isEnabled()

The following examples show how to use org.chromium.chrome.browser.ChromeFeatureList#isEnabled() . 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: InvalidationController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the instance that will use {@code context} to issue intents.
 *
 * Calling this method will create the instance if it does not yet exist.
 */
public static InvalidationController get(Context context) {
    synchronized (LOCK) {
        if (sInstance == null) {
            // The PageRevisitInstrumentation trial needs sessions invalidations to be on such
            // that local session data is current and can be used to perform checks.
            boolean requireInvalidationsForInstrumentation =
                    FieldTrialList.findFullName("PageRevisitInstrumentation").equals("Enabled");
            // If the NTP is trying to suggest foreign tabs, then recieving invalidations is
            // vital, otherwise data is stale and less useful.
            boolean requireInvalidationsForSuggestions = ChromeFeatureList.isEnabled(
                    ChromeFeatureList.NTP_FOREIGN_SESSIONS_SUGGESTIONS);
            boolean canDisableSessionInvalidations = !requireInvalidationsForInstrumentation
                    && !requireInvalidationsForSuggestions;

            boolean canUseGcmUpstream =
                    FieldTrialList.findFullName("InvalidationsGCMUpstream").equals("Enabled");
            sInstance = new InvalidationController(
                    context, canDisableSessionInvalidations, canUseGcmUpstream);
        }
        return sInstance;
    }
}
 
Example 2
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Cache whether or not Chrome Home is enabled.
 */
public static void cacheChromeHomeEnabled() {
    Context context = ContextUtils.getApplicationContext();

    // Chrome Home doesn't work with tablets.
    if (DeviceFormFactor.isTablet(context)) return;

    boolean isChromeHomeEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME);
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(context);
    boolean valueChanged = isChromeHomeEnabled != manager.isChromeHomeEnabled();
    manager.setChromeHomeEnabled(isChromeHomeEnabled);
    sChromeHomeEnabled = isChromeHomeEnabled;

    // If the cached value changed, restart chrome.
    if (valueChanged) ApplicationLifetime.terminate(true);
}
 
Example 3
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * If no payment methods are supported, disconnect from the client and return true.
 *
 * @return True if no payment methods are supported
 */
private boolean disconnectIfNoPaymentMethodsSupported() {
    boolean waitingForPaymentApps = !isFinishedQueryingPaymentApps();
    boolean foundPaymentMethods =
            mPaymentMethodsSection != null && !mPaymentMethodsSection.isEmpty();
    boolean userCanAddCreditCard = mMerchantSupportsAutofillPaymentInstruments
            && !ChromeFeatureList.isEnabled(ChromeFeatureList.NO_CREDIT_CARD_ABORT);

    if (!mArePaymentMethodsSupported
            || (getIsShowing() && !waitingForPaymentApps && !foundPaymentMethods
                       && !userCanAddCreditCard)) {
        // All payment apps have responded, but none of them have instruments. It's possible to
        // add credit cards, but the merchant does not support them either. The payment request
        // must be rejected.
        disconnectFromClientWithDebugMessage("Requested payment methods have no instruments",
                PaymentErrorReason.NOT_SUPPORTED);
        recordAbortReasonHistogram(mArePaymentMethodsSupported
                        ? PaymentRequestMetrics.ABORT_REASON_NO_MATCHING_PAYMENT_METHOD
                        : PaymentRequestMetrics.ABORT_REASON_NO_SUPPORTED_PAYMENT_METHOD);
        if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
        return true;
    }

    return false;
}
 
Example 4
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Requests a location refresh so that a valid location will be available for constructing
 * an X-Geo header in the near future (i.e. within 5 minutes).
 */
public static void primeLocationForGeoHeader() {
    if (!hasGeolocationPermission()) return;

    if (sFirstLocationTime == Long.MAX_VALUE) {
        sFirstLocationTime = SystemClock.elapsedRealtime();
    }
    GeolocationTracker.refreshLastKnownLocation(
            ContextUtils.getApplicationContext(), REFRESH_LOCATION_AGE);

    // Only refresh visible networks if enabled.
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.XGEO_VISIBLE_NETWORKS)) {
        VisibleNetworksTracker.refreshVisibleNetworks(ContextUtils.getApplicationContext());
    }
}
 
Example 5
Source File: GeolocationSnackbarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) return;
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = DeviceClassManager.isAccessibilityModeEnabled(view.getContext())
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
 
Example 6
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void startSpeculation(CustomTabsSessionToken session, String url, int speculationMode,
        Bundle extras, int uid) {
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    boolean preconnect = true, createSpareWebContents = true;
    if (speculationMode == SpeculationParams.HIDDEN_TAB
            && !ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_BACKGROUND_TAB)) {
        speculationMode = SpeculationParams.PRERENDER;
    }
    switch (speculationMode) {
        case SpeculationParams.PREFETCH:
            boolean didPrefetch = new LoadingPredictor(profile).prepareForPageLoad(url);
            if (didPrefetch) mSpeculation = SpeculationParams.forPrefetch(session, url);
            preconnect = !didPrefetch;
            break;
        case SpeculationParams.PRERENDER:
            boolean didPrerender = prerenderUrl(session, url, extras, uid);
            createSpareWebContents = !didPrerender;
            break;
        case SpeculationParams.HIDDEN_TAB:
            launchUrlInHiddenTab(session, url, extras);
            break;
        default:
            break;
    }
    if (preconnect) warmupManager.maybePreconnectUrlAndSubResources(profile, url);
    if (createSpareWebContents) warmupManager.createSpareWebContents();
}
 
Example 7
Source File: SectionList.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isResetAllowed() {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME)) return false;

    // TODO(dgn): Also check if the bottom sheet is closed and how long since it has been closed
    // or opened, so that we don't refresh content while the user still cares about it.
    // Note: don't only use visibility, as pending FetchMore requests can still come, we don't
    // want to clear all the current suggestions in that case. See https://crbug.com/711414

    return !mUiDelegate.isVisible();
}
 
Example 8
Source File: VrShellDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static boolean activitySupportsVrBrowsing(Activity activity) {
    if (activity instanceof ChromeTabbedActivity) return true;
    if (activity instanceof CustomTabActivity) {
        return ChromeFeatureList.isEnabled(ChromeFeatureList.VR_CUSTOM_TAB_BROWSING);
    }
    return false;
}
 
Example 9
Source File: NewTabPageView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private boolean shouldShowLogo() {
    boolean condensedLayoutEnabled =
            ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_CONDENSED_LAYOUT);
    boolean showLogoInCondensedLayout = ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
            ChromeFeatureList.NTP_CONDENSED_LAYOUT, PARAM_CONDENSED_LAYOUT_SHOW_LOGO, false);
    return mSearchProviderHasLogo && (!condensedLayoutEnabled || showLogoInCondensedLayout);
}
 
Example 10
Source File: ClearBrowsingDataPreferences.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns if we should show the important sites dialog. We check to see if
 * <ol>
 * <li>We've fetched the important sites,
 * <li>there are important sites,
 * <li>the feature is enabled, and
 * <li>we have cache or cookies selected.
 * </ol>
 */
private boolean shouldShowImportantSitesDialog() {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.IMPORTANT_SITES_IN_CBD)) return false;
    EnumSet<DialogOption> selectedOptions = getSelectedOptions();
    if (!selectedOptions.contains(DialogOption.CLEAR_CACHE)
            && !selectedOptions.contains(DialogOption.CLEAR_COOKIES_AND_SITE_DATA)) {
        return false;
    }
    boolean haveImportantSites =
            mSortedImportantDomains != null && mSortedImportantDomains.length != 0;
    RecordHistogram.recordBooleanHistogram(
            "History.ClearBrowsingData.ImportantDialogShown", haveImportantSites);
    return haveImportantSites;
}
 
Example 11
Source File: TabRedirectHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Updates |mIntentHistory| and |mLastIntentUpdatedTime|. If |intent| comes from chrome and
 * currently |mIsOnEffectiveIntentRedirectChain| is true, that means |intent| was sent from
 * this tab because only the front tab or a new tab can receive an intent from chrome. In that
 * case, |intent| is added to |mIntentHistory|.
 * Otherwise, |mIntentHistory| and |mPreviousResolvers| are cleared, and then |intent| is put
 * into |mIntentHistory|.
 */
public void updateIntent(Intent intent) {
    clear();

    if (mContext == null || intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) {
        return;
    }

    mIsCustomTabIntent = ChromeLauncherActivity.isCustomTabIntent(intent);
    boolean checkIsToChrome = true;
    // All custom tabs VIEW intents are by design explicit intents, so the presence of package
    // name doesn't imply they have to be handled by Chrome explicitly. Check if external apps
    // should be checked for handling the initial redirect chain.
    if (mIsCustomTabIntent) {
        boolean sendToExternalApps = IntentUtils.safeGetBooleanExtra(intent,
                CustomTabIntentDataProvider.EXTRA_SEND_TO_EXTERNAL_DEFAULT_HANDLER, false);
        checkIsToChrome = !(sendToExternalApps
                && ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_EXTERNAL_LINK_HANDLING));
    }

    if (checkIsToChrome) mIsInitialIntentHeadingToChrome = isIntentToChrome(mContext, intent);

    // A copy of the intent with component cleared to find resolvers.
    mInitialIntent = new Intent(intent).setComponent(null);
    Intent selector = mInitialIntent.getSelector();
    if (selector != null) selector.setComponent(null);
}
 
Example 12
Source File: ContentSuggestionsPreferences.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private boolean canShowNotificationsSwitch() {
    if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CONTENT_SUGGESTIONS_NOTIFICATIONS)) {
        return false;
    }
    return mIsEnabled;
}
 
Example 13
Source File: MainPreferences.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void updatePreferences() {
    if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();

    PreferenceUtils.addPreferencesFromResource(this, R.xml.main_preferences);

    if (TemplateUrlService.getInstance().isLoaded()) {
        updateSummary();
    } else {
        TemplateUrlService.getInstance().registerLoadListener(this);
        TemplateUrlService.getInstance().load();
        ChromeBasePreference searchEnginePref =
                (ChromeBasePreference) findPreference(PREF_SEARCH_ENGINE);
        searchEnginePref.setEnabled(false);
    }

    ChromeBasePreference autofillPref =
            (ChromeBasePreference) findPreference(PREF_AUTOFILL_SETTINGS);
    autofillPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);

    ChromeBasePreference passwordsPref =
            (ChromeBasePreference) findPreference(PREF_SAVED_PASSWORDS);

    ProfileSyncService syncService = ProfileSyncService.get();

    if (AndroidSyncSettings.isSyncEnabled(getActivity().getApplicationContext())
            && syncService.isEngineInitialized() && !syncService.isUsingSecondaryPassphrase()
            && ChromeFeatureList.isEnabled(VIEW_PASSWORDS)) {
        passwordsPref.setKey(PREF_MANAGE_ACCOUNT_LINK);
        passwordsPref.setTitle(R.string.redirect_to_passwords_text);
        passwordsPref.setSummary(R.string.redirect_to_passwords_link);
        passwordsPref.setOnPreferenceClickListener(this);
        passwordsPref.setManagedPreferenceDelegate(null);
    } else {
        passwordsPref.setTitle(getResources().getString(R.string.prefs_saved_passwords));
        passwordsPref.setFragment(SavePasswordsPreferences.class.getCanonicalName());
        setOnOffSummary(passwordsPref,
                PrefServiceBridge.getInstance().isRememberPasswordsEnabled());
        passwordsPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
    }

    Preference homepagePref = findPreference(PREF_HOMEPAGE);
    if (HomepageManager.shouldShowHomepageSetting()) {
        setOnOffSummary(homepagePref,
                HomepageManager.getInstance(getActivity()).getPrefHomepageEnabled());
    } else {
        getPreferenceScreen().removePreference(homepagePref);
    }

    ChromeBasePreference dataReduction =
            (ChromeBasePreference) findPreference(PREF_DATA_REDUCTION);
    dataReduction.setSummary(DataReductionPreferences.generateSummary(getResources()));
    dataReduction.setManagedPreferenceDelegate(mManagedPreferenceDelegate);

    if (!SigninManager.get(getActivity()).isSigninSupported()) {
        getPreferenceScreen().removePreference(findPreference(PREF_SIGN_IN));
    }
}
 
Example 14
Source File: SnippetsConfig.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public static boolean isEnabled() {
    return ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SNIPPETS);
}
 
Example 15
Source File: SuggestionsBottomSheetContent.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public SuggestionsBottomSheetContent(final ChromeActivity activity, final BottomSheet sheet,
        TabModelSelector tabModelSelector, SnackbarManager snackbarManager) {
    Profile profile = Profile.getLastUsedProfile();
    SuggestionsNavigationDelegate navigationDelegate =
            new SuggestionsNavigationDelegateImpl(activity, profile, sheet, tabModelSelector);
    mTileGroupDelegate = new TileGroupDelegateImpl(
            activity, profile, tabModelSelector, navigationDelegate, snackbarManager);
    mSuggestionsUiDelegate = createSuggestionsDelegate(
            profile, navigationDelegate, sheet, activity.getReferencePool());

    mView = LayoutInflater.from(activity).inflate(
            R.layout.suggestions_bottom_sheet_content, null);
    mRecyclerView = (SuggestionsRecyclerView) mView.findViewById(R.id.recycler_view);

    TouchEnabledDelegate touchEnabledDelegate = new TouchEnabledDelegate() {
        @Override
        public void setTouchEnabled(boolean enabled) {
            activity.getBottomSheet().setTouchEnabled(enabled);
        }
    };
    mContextMenuManager =
            new ContextMenuManager(activity, navigationDelegate, touchEnabledDelegate);
    activity.getWindowAndroid().addContextMenuCloseListener(mContextMenuManager);
    mSuggestionsUiDelegate.addDestructionObserver(new DestructionObserver() {
        @Override
        public void onDestroy() {
            activity.getWindowAndroid().removeContextMenuCloseListener(mContextMenuManager);
        }
    });

    UiConfig uiConfig = new UiConfig(mRecyclerView);

    final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsUiDelegate,
            /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getForProfile(profile),
            mContextMenuManager, mTileGroupDelegate);
    mRecyclerView.init(uiConfig, mContextMenuManager, adapter);

    mBottomSheetObserver = new SuggestionsSheetVisibilityChangeObserver(this, activity) {
        @Override
        public void onSheetOpened() {
            mRecyclerView.scrollToPosition(0);
            adapter.refreshSuggestions();
            mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened();
            mRecyclerView.getScrollEventReporter().reset();

            if (ChromeFeatureList.isEnabled(
                        ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_CAROUSEL)
                    && sheet.getActiveTab() != null) {
                updateContextualSuggestions(sheet.getActiveTab().getUrl());
            }

            super.onSheetOpened();
        }

        @Override
        public void onContentShown() {
            SuggestionsMetrics.recordSurfaceVisible();
        }

        @Override
        public void onContentHidden() {
            SuggestionsMetrics.recordSurfaceHidden();
        }

        @Override
        public void onContentStateChanged(@BottomSheet.SheetState int contentState) {
            if (contentState == BottomSheet.SHEET_STATE_HALF) {
                SuggestionsMetrics.recordSurfaceHalfVisible();
            } else if (contentState == BottomSheet.SHEET_STATE_FULL) {
                SuggestionsMetrics.recordSurfaceFullyVisible();
            }
        }
    };

    mShadowView = (FadingShadowView) mView.findViewById(R.id.shadow);
    mShadowView.init(
            ApiCompatibilityUtils.getColor(mView.getResources(), R.color.toolbar_shadow_color),
            FadingShadow.POSITION_TOP);

    mRecyclerView.addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            boolean shadowVisible = mRecyclerView.canScrollVertically(-1);
            mShadowView.setVisibility(shadowVisible ? View.VISIBLE : View.GONE);
        }
    });

    final LocationBar locationBar = (LocationBar) sheet.findViewById(R.id.location_bar);
    mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        @SuppressLint("ClickableViewAccessibility")
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (locationBar != null && locationBar.isUrlBarFocused()) {
                locationBar.setUrlBarFocus(false);
            }

            // Never intercept the touch event.
            return false;
        }
    });
}
 
Example 16
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an X-Geo HTTP header string if:
 *  1. The current mode is not incognito.
 *  2. The url is a google search URL (e.g. www.google.co.uk/search?q=cars), and
 *  3. The user has not disabled sharing location with this url, and
 *  4. There is a valid and recent location available.
 *
 * Returns null otherwise.
 *
 * @param url The URL of the request with which this header will be sent.
 * @param tab The Tab currently being accessed.
 * @return The X-Geo header string or null.
 */
public static String getGeoHeader(String url, Tab tab) {
    // TODO(lbargu): Refactor and simplify flow.
    boolean isIncognito = tab.isIncognito();
    Location locationToAttach = null;
    VisibleNetworks visibleNetworksToAttach = null;
    long locationAge = Long.MAX_VALUE;
    @HeaderState int headerState = geoHeaderStateForUrl(url, isIncognito, true);
    // XGEO_VISIBLE_NETWORKS
    // When this feature is enabled, we will send visible WiFi and Cell Access Points as part of
    // the X-GEO HTTP Header so that we can better position the client server side in the case
    // where there is no lat/long or it's too old.
    boolean isXGeoVisibleNetworksEnabled =
            ChromeFeatureList.isEnabled(ChromeFeatureList.XGEO_VISIBLE_NETWORKS);
    if (headerState == HEADER_ENABLED) {
        // Only send X-Geo header if there's a fresh location available.
        // Use flag controlling visible network changes to decide whether GPS location should be
        // included as a fallback.
        // TODO(lbargu): Measure timing here and to get visible networks.
        locationToAttach = GeolocationTracker.getLastKnownLocation(
                ContextUtils.getApplicationContext(), isXGeoVisibleNetworksEnabled);
        if (locationToAttach == null) {
            recordHistogram(UMA_LOCATION_NOT_AVAILABLE);
        } else {
            locationAge = GeolocationTracker.getLocationAge(locationToAttach);
            if (locationAge > MAX_LOCATION_AGE) {
                // Do not attach the location
                recordHistogram(UMA_LOCATION_STALE);
                locationToAttach = null;
            } else {
                recordHistogram(UMA_HEADER_SENT);
            }
        }

        // The header state is enabled, so this means we have app permissions, and the url is
        // allowed to receive location. Before attempting to attach visible networks, check if
        // network-based location is enabled.
        if (isXGeoVisibleNetworksEnabled && isNetworkLocationEnabled()
                && !isLocationFresh(locationToAttach)) {
            visibleNetworksToAttach = VisibleNetworksTracker.getLastKnownVisibleNetworks(
                    ContextUtils.getApplicationContext());
        }
    }

    @LocationSource int locationSource = getLocationSource();
    @Permission int appPermission = getGeolocationPermission(tab);
    @Permission int domainPermission = getDomainPermission(url, isIncognito);

    // Record the permission state with a histogram.
    recordPermissionHistogram(locationSource, appPermission, domainPermission,
            locationToAttach != null, headerState);

    if (locationSource != LOCATION_SOURCE_MASTER_OFF && appPermission != PERMISSION_BLOCKED
            && domainPermission != PERMISSION_BLOCKED && !isIncognito) {
        // Record the Location Age with a histogram.
        recordLocationAgeHistogram(locationSource, locationAge);
        long duration = sFirstLocationTime == Long.MAX_VALUE
                ? 0
                : SystemClock.elapsedRealtime() - sFirstLocationTime;
        // Record the Time Listening with a histogram.
        recordTimeListeningHistogram(locationSource, locationToAttach != null, duration);
    }


    if (!isXGeoVisibleNetworksEnabled) {
        String locationAsciiEncoding = encodeAsciiLocation(locationToAttach);
        if (locationAsciiEncoding == null) return null;
        return XGEO_HEADER_PREFIX + LOCATION_SEPARATOR + LOCATION_ASCII_PREFIX
                + LOCATION_SEPARATOR + locationAsciiEncoding;
    }

    // Proto encoding
    String locationProtoEncoding = encodeProtoLocation(locationToAttach);
    String visibleNetworksProtoEncoding = encodeProtoVisibleNetworks(visibleNetworksToAttach);

    if (locationProtoEncoding == null && visibleNetworksProtoEncoding == null) return null;

    StringBuilder header = new StringBuilder(XGEO_HEADER_PREFIX);
    if (locationProtoEncoding != null) {
        header.append(LOCATION_SEPARATOR).append(LOCATION_PROTO_PREFIX)
                .append(LOCATION_SEPARATOR).append(locationProtoEncoding);
    }
    if (visibleNetworksProtoEncoding != null) {
        header.append(LOCATION_SEPARATOR).append(LOCATION_PROTO_PREFIX)
                .append(LOCATION_SEPARATOR).append(visibleNetworksProtoEncoding);
    }
    return header.toString();
}
 
Example 17
Source File: PrivacyPreferences.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager.getInstance();
    privacyPrefManager.migrateNetworkPredictionPreferences();
    PreferenceUtils.addPreferencesFromResource(this, R.xml.privacy_preferences);
    getActivity().setTitle(R.string.prefs_privacy);
    setHasOptionsMenu(true);
    PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();

    mManagedPreferenceDelegate = createManagedPreferenceDelegate();

    ChromeBaseCheckBoxPreference networkPredictionPref =
            (ChromeBaseCheckBoxPreference) findPreference(PREF_NETWORK_PREDICTIONS);
    networkPredictionPref.setChecked(prefServiceBridge.getNetworkPredictionEnabled());
    networkPredictionPref.setOnPreferenceChangeListener(this);
    networkPredictionPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);

    ChromeBaseCheckBoxPreference navigationErrorPref =
            (ChromeBaseCheckBoxPreference) findPreference(PREF_NAVIGATION_ERROR);
    navigationErrorPref.setOnPreferenceChangeListener(this);
    navigationErrorPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);

    ChromeBaseCheckBoxPreference searchSuggestionsPref =
            (ChromeBaseCheckBoxPreference) findPreference(PREF_SEARCH_SUGGESTIONS);
    searchSuggestionsPref.setOnPreferenceChangeListener(this);
    searchSuggestionsPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONTENT_SUGGESTIONS_SETTINGS)) {
        searchSuggestionsPref.setTitle(R.string.search_site_suggestions_title);
        searchSuggestionsPref.setSummary(R.string.search_site_suggestions_summary);
    }

    PreferenceScreen preferenceScreen = getPreferenceScreen();
    if (!ContextualSearchFieldTrial.isEnabled()) {
        preferenceScreen.removePreference(findPreference(PREF_CONTEXTUAL_SEARCH));
    }

    // Listen to changes to both Extended Reporting prefs.
    ChromeBaseCheckBoxPreference legacyExtendedReportingPref =
            (ChromeBaseCheckBoxPreference) findPreference(
                PREF_SAFE_BROWSING_EXTENDED_REPORTING);
    legacyExtendedReportingPref.setOnPreferenceChangeListener(this);
    legacyExtendedReportingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
    ChromeBaseCheckBoxPreference scoutReportingPref =
            (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING_SCOUT_REPORTING);
    scoutReportingPref.setOnPreferenceChangeListener(this);
    scoutReportingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
    // Remove the extended reporting preference that is NOT active.
    String extended_reporting_pref_to_remove =
            prefServiceBridge.isSafeBrowsingScoutReportingActive()
                ? PREF_SAFE_BROWSING_EXTENDED_REPORTING : PREF_SAFE_BROWSING_SCOUT_REPORTING;
    preferenceScreen.removePreference(findPreference(extended_reporting_pref_to_remove));

    ChromeBaseCheckBoxPreference safeBrowsingPref =
            (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING);
    safeBrowsingPref.setOnPreferenceChangeListener(this);
    safeBrowsingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);

    if (!PhysicalWeb.featureIsEnabled()) {
        preferenceScreen.removePreference(findPreference(PREF_PHYSICAL_WEB));
    }

    if (ClearBrowsingDataTabsFragment.isFeatureEnabled()) {
        findPreference(PREF_CLEAR_BROWSING_DATA)
                .setFragment(ClearBrowsingDataTabsFragment.class.getName());
    }

    updateSummaries();
}
 
Example 18
Source File: IncognitoNewTabPage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private static boolean useMDIncognitoNTP() {
    return ChromeFeatureList.isEnabled(ChromeFeatureList.MATERIAL_DESIGN_INCOGNITO_NTP);
}
 
Example 19
Source File: ChromeWebApkHost.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/** Returns whether we should enable WebAPKs */
private static boolean computeEnabled() {
    return isCommandLineFlagSet() && ChromeFeatureList.isEnabled(ChromeFeatureList.WEBAPKS);
}
 
Example 20
Source File: PhysicalWeb.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Evaluate whether the environment is one in which the Physical Web should
 * be enabled.
 * @return true if the PhysicalWeb should be enabled
 */
public static boolean featureIsEnabled() {
    return ChromeFeatureList.isEnabled(FEATURE_NAME)
            && Build.VERSION.SDK_INT >= MIN_ANDROID_VERSION;
}