private void searchEngineSelected(int position) { // First clean up any automatically added permissions (if any) for the previously selected // search engine. SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED, false)) { if (locationEnabled(mSelectedSearchEnginePosition, false)) { String url = TemplateUrlService.getInstance() .getSearchEngineUrlFromTemplateUrl(toIndex(mSelectedSearchEnginePosition)); WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( url, url, ContentSetting.DEFAULT.toInt(), false); } sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLOWED).apply(); } // Record the change in search engine. mSelectedSearchEnginePosition = position; TemplateUrlService.getInstance().setSearchEngine(toIndex(mSelectedSearchEnginePosition)); // Report the change back. TemplateUrl templateUrl = mSearchEngines.get(mSelectedSearchEnginePosition); mCallback.currentSearchEngineDetermined(templateUrl.getShortName()); notifyDataSetChanged(); }
/** * Deletes the snapshot database which is no longer used because the feature has been removed in * Chrome M41. */ @WorkerThread private void removeSnapshotDatabase() { synchronized (SNAPSHOT_DATABASE_LOCK) { SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); if (!prefs.getBoolean(SNAPSHOT_DATABASE_REMOVED, false)) { mAppContext.deleteDatabase(SNAPSHOT_DATABASE_NAME); prefs.edit().putBoolean(SNAPSHOT_DATABASE_REMOVED, true).apply(); } } }
/** * Determine whether the sync promo needs to be displayed. * * @return Whether sync promo should be displayed. */ public boolean shouldDisplaySyncPromo() { if (SigninManager.get(mContext).isSigninDisabledByPolicy()) { return false; } if (ContextUtils.getAppSharedPreferences().getBoolean(PREF_SIGNIN_PROMO_DECLINED, false)) { return false; } return !AndroidSyncSettings.isSyncEnabled(mContext) || mForeignSessions.isEmpty(); }
/** Tests that the WebappActivity gets the next available Tab ID instead of 0. */ @MediumTest @Feature({"Webapps"}) public void testWebappTabIdsProperlyAssigned() throws Exception { SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(TabIdManager.PREF_NEXT_ID, 11684); editor.apply(); final WebappActivity webappActivity = startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON); assertEquals("Wrong Tab ID was used", 11684, webappActivity.getActivityTab().getId()); }
private void setUpUserPreferences(Context context, UserUploadPreference userPreference) { SharedPreferences pref = ContextUtils.getAppSharedPreferences(); SharedPreferences.Editor ed = pref.edit() .putString( PrivacyPreferencesManager.PREF_CRASH_DUMP_UPLOAD, userPreference.toStringValue(context)) .putBoolean( PrivacyPreferencesManager.PREF_CRASH_DUMP_UPLOAD_NO_CELLULAR, userPreference.toBooleanValue()); ed.apply(); }
/** Save that user tapped "No" button on the signin promo. */ public void setSigninPromoDeclined() { SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit(); sharedPreferencesEditor.putBoolean(PREF_SIGNIN_PROMO_DECLINED, true); sharedPreferencesEditor.apply(); }
/** * Caches the native flag that enables the Download Home in SharedPreferences. This is necessary * because the DownloadActivity can be opened before native has been loaded. */ public static void cacheIsDownloadHomeEnabled() { boolean isEnabled = ChromeFeatureList.isEnabled("DownloadsUi"); SharedPreferences preferences = ContextUtils.getAppSharedPreferences(); preferences.edit().putBoolean(PREF_IS_DOWNLOAD_HOME_ENABLED, isEnabled).apply(); }
/** @return Whether or not the Download Home is enabled. */ public static boolean isDownloadHomeEnabled() { SharedPreferences preferences = ContextUtils.getAppSharedPreferences(); return preferences.getBoolean(PREF_IS_DOWNLOAD_HOME_ENABLED, false); }