<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.search

import android.content.Context
import android.util.Log
import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.search.SearchEngineParser
import org.mozilla.focus.shortcut.IconGenerator
import org.xmlpull.v1.XmlPullParserException
import java.io.IOException

object CustomSearchEngineStore {
    fun isSearchEngineNameUnique(context: Context, engineName: String): Boolean {
        val sharedPreferences = context.getSharedPreferences(PREF_FILE_SEARCH_ENGINES,
                Context.MODE_PRIVATE)

        return !sharedPreferences.contains(engineName)
    }

    fun restoreDefaultSearchEngines(context: Context) {
        pref(context)
                .edit()
                .remove(PREF_KEY_HIDDEN_DEFAULT_ENGINES)
                .apply()
    }

    fun hasAllDefaultSearchEngines(context: Context): Boolean {
        return !pref(context)<commit_msg>Fixes #2002: Check search engine name against default engine list<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.search

import android.content.Context
import android.util.Log
import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.search.SearchEngineParser
import org.mozilla.focus.Components
import org.mozilla.focus.shortcut.IconGenerator
import org.xmlpull.v1.XmlPullParserException
import java.io.IOException

object CustomSearchEngineStore {
    fun isSearchEngineNameUnique(context: Context, engineName: String): Boolean {
        val sharedPreferences = context.getSharedPreferences(PREF_FILE_SEARCH_ENGINES,
                Context.MODE_PRIVATE)

        val defaultEngines = Components.searchEngineManager.getSearchEngines(context)

        return !sharedPreferences.contains(engineName) && !defaultEngines.any { it.name == engineName }
    }

    fun restoreDefaultSearchEngines(context: Context) {
        pref(context)
                .edit()
                .remove(PREF_KEY_HIDDEN_DEFAULT_ENGINES)
                .apply()
    }

    fun hasAllDefaultSearchEngines(context: Context): Boolean {
        return !pref(context)
{'fraction_non_alphanumeric': 0.07921974522292993, 'fraction_numerical': 0.005573248407643312, 'mean_word_length': 3.5941499085923216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1373859', 'n_tokens_mistral': 707, 'n_tokens_neox': 666, 'n_words': 172}