13e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/*
23e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Copyright (C) 2009 The Android Open Source Project
33e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
43e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License");
53e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * you may not use this file except in compliance with the License.
63e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * You may obtain a copy of the License at
73e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
83e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *      http://www.apache.org/licenses/LICENSE-2.0
93e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Unless required by applicable law or agreed to in writing, software
113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS,
123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * See the License for the specific language governing permissions and
143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * limitations under the License.
153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */
163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertpackage com.android.quicksearchbox;
183e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
19f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwoodimport android.app.AlarmManager;
203e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.Context;
2171f9f8ccd3c12d7d48e2fee4c55cd57e1970b797Bjorn Bringertimport android.net.Uri;
223e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.os.Process;
233e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.util.Log;
243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
253e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport java.util.HashSet;
263e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
273e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/**
283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Provides values for configurable parameters in all of QSB.
293e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
303e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * All the methods in this class return fixed default values. Subclasses may
313e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * make these values server-side settable.
323e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
333e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */
343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertpublic class Config {
353e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
363e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final String TAG = "QSB.Config";
3709552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood    private static final boolean DBG = false;
383e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
39f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    protected static final long SECOND_MILLIS = 1000L;
40f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    protected static final long MINUTE_MILLIS = 60L * SECOND_MILLIS;
41f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    protected static final long DAY_MILLIS = 86400000L;
423e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
43fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    private static final int NUM_PROMOTED_SOURCES = 3;
443e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final int MAX_RESULTS_PER_SOURCE = 50;
453e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final long SOURCE_TIMEOUT_MILLIS = 10000;
463e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
473e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final int QUERY_THREAD_PRIORITY =
483e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE;
493e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
5087331ef11a1ac6c907c008354e3aab5eb6f87404Bjorn Bringert    private static final long MAX_STAT_AGE_MILLIS = 30 * DAY_MILLIS;
513e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final int MIN_CLICKS_FOR_SOURCE_RANKING = 3;
523e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
5372f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert    private static final int NUM_WEB_CORPUS_THREADS = 2;
5472f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert
55f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert    private static final int LATENCY_LOG_FREQUENCY = 1000;
56f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert
574ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert    private static final long TYPING_SUGGESTIONS_UPDATE_DELAY_MILLIS = 100;
58ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert    private static final long PUBLISH_RESULT_DELAY_MILLIS = 200;
594ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert
60f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_ACTIVE_PERIOD = 7L * DAY_MILLIS;
61f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
62f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_UPDATE_INTERVAL
63f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood            = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
64f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
65f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_SHOW_PERIOD_MILLIS
66f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood            = AlarmManager.INTERVAL_HOUR * 2;
67f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
68f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_CHANGE_PERIOD = 2L * MINUTE_MILLIS;
69f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
70f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_VISIBLE_PERIOD = 6L * MINUTE_MILLIS;
71f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
72cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    private static final int HTTP_CONNECT_TIMEOUT_MILLIS = 4000;
73cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    private static final int HTTP_READ_TIMEOUT_MILLIS = 4000;
74cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood
75ef6dbc776667219ac89bd5f80c181f65260457acNarayan Kamath    private static final String USER_AGENT = "Android/1.0";
76ef6dbc776667219ac89bd5f80c181f65260457acNarayan Kamath
77af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    private final Context mContext;
78fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    private HashSet<String> mDefaultCorpora;
7996c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    private HashSet<String> mHiddenCorpora;
8009552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood    private HashSet<String> mDefaultCorporaSuggestUris;
813e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
823e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
833e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * Creates a new config that uses hard-coded default values.
843e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
853e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public Config(Context context) {
863e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        mContext = context;
873e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
883e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
89af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    protected Context getContext() {
90af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert        return mContext;
91af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    }
92af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert
93af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    /**
94af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * Releases any resources used by the configuration object.
95af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     *
96af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * Default implementation does nothing.
97af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     */
98af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    public void close() {
99af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    }
100af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert
10196c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    private HashSet<String> loadResourceStringSet(int res) {
102fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert        HashSet<String> defaultCorpora = new HashSet<String>();
1031fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        String[] corpora = mContext.getResources().getStringArray(res);
1041fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        for (String corpus : corpora) {
1051fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood            if (DBG) Log.d(TAG, "Default corpus: " + corpus);
1061fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood            defaultCorpora.add(corpus);
1073e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1081fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return defaultCorpora;
1093e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
1123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * Checks if we trust the given source not to be spammy.
1133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
11409552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood    public synchronized boolean isCorpusEnabledByDefault(Corpus corpus) {
11509552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        if (DBG) Log.d(TAG, "isCorpusEnabledByDefault(" + corpus.getName() + ")");
116fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert        if (mDefaultCorpora == null) {
11796c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert            mDefaultCorpora = loadResourceStringSet(R.array.default_corpora);
1183e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
11909552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        if (mDefaultCorpora.contains(corpus.getName())) {
12009552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            if (DBG) Log.d(TAG, "Corpus " + corpus.getName() + " IS default");
12109552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            return true;
12209552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        }
12309552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood
12409552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        if (mDefaultCorporaSuggestUris == null) {
12509552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            mDefaultCorporaSuggestUris = loadResourceStringSet(
12609552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood                    R.array.default_corpora_suggest_uris);
12709552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        }
12809552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood
12909552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        for (Source s : corpus.getSources()) {
13009552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            String uri = s.getSuggestUri();
13109552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            if (DBG) Log.d(TAG, "Suggest URI for " + corpus.getName() + ": " + uri);
13209552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            if (mDefaultCorporaSuggestUris.contains(uri)) {
13309552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood                if (DBG) Log.d(TAG, "Corpus " + corpus.getName() + " IS default");
13409552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood                return true;
13509552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            }
13609552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        }
13709552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        if (DBG) Log.d(TAG, "Corpus " + corpus.getName() + " is NOT default");
13809552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        return false;
1393e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1403e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1413e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
14296c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert     * Checks if the given corpus should be hidden from the corpus selection dialog.
14396c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert     */
14496c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    public synchronized boolean isCorpusHidden(String corpusName) {
14596c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert        if (mHiddenCorpora == null) {
14696c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert            mHiddenCorpora = loadResourceStringSet(R.array.hidden_corpora);
14796c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert        }
14896c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert        return mHiddenCorpora.contains(corpusName);
14996c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    }
15096c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert
15196c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    /**
152af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * The number of promoted sources.
153af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     */
154af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    public int getNumPromotedSources() {
155af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert        return NUM_PROMOTED_SOURCES;
156af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    }
157af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert
158af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    /**
15939bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney     * The number of suggestions visible above the onscreen keyboard.
16039bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney     */
16139bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney    public int getNumSuggestionsAboveKeyboard() {
1621fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        // Get the list of default corpora from a resource, which allows vendor overlays.
1631fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getInteger(R.integer.num_suggestions_above_keyboard);
16439bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney    }
16539bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney
16639bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney    /**
1673e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * The maximum number of suggestions to promote.
1683e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
1693e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getMaxPromotedSuggestions() {
1701fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getInteger(R.integer.max_promoted_suggestions);
1713e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1723e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1737a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    public int getMaxPromotedResults() {
1747a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood        return mContext.getResources().getInteger(R.integer.max_promoted_results);
1757a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    }
1767a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood
1773e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
1783e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * The number of results to ask each source for.
1793e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
1803e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getMaxResultsPerSource() {
1813e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return MAX_RESULTS_PER_SOURCE;
1823e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1833e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1843e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
18508ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert     * The maximum number of shortcuts to show for the web source in All mode.
18608ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert     */
18708ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    public int getMaxShortcutsPerWebSource() {
188af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood        return mContext.getResources().getInteger(R.integer.max_shortcuts_per_web_source);
18908ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    }
19008ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert
19108ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    /**
19208ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert     * The maximum number of shortcuts to show for each non-web source in All mode.
19308ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert     */
19408ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    public int getMaxShortcutsPerNonWebSource() {
195af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood        return mContext.getResources().getInteger(R.integer.max_shortcuts_per_non_web_source);
19608ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    }
19708ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert
19808ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    /**
19953aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert     * Gets the maximum number of shortcuts that will be shown from the given source.
20053aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert     */
20153aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert    public int getMaxShortcuts(String sourceName) {
20253aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert        return getMaxShortcutsPerNonWebSource();
20353aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert    }
20453aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert
20553aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert    /**
2063e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * The timeout for querying each source, in milliseconds.
2073e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
2083e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public long getSourceTimeoutMillis() {
2093e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return SOURCE_TIMEOUT_MILLIS;
2103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
2123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
2133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * The priority of query threads.
2143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     *
2153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * @return A thread priority, as defined in {@link Process}.
2163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
2173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getQueryThreadPriority() {
2183e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return QUERY_THREAD_PRIORITY;
2193e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2203e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
221af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    /**
222af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * The maximum age of log data used for shortcuts.
223af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     */
2243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public long getMaxStatAgeMillis(){
2253e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return MAX_STAT_AGE_MILLIS;
2263e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2273e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
228af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    /**
229af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * The minimum number of clicks needed to rank a source.
230af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     */
2313e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getMinClicksForSourceRanking(){
2323e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return MIN_CLICKS_FOR_SOURCE_RANKING;
2333e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
23572f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert    public int getNumWebCorpusThreads() {
23672f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert        return NUM_WEB_CORPUS_THREADS;
23772f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert    }
23872f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert
239f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert    /**
240f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     * How often query latency should be logged.
241f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     *
242f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     * @return An integer in the range 0-1000. 0 means that no latency events
243f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     *         should be logged. 1000 means that all latency events should be logged.
244f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     */
245f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert    public int getLatencyLogFrequency() {
246f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert        return LATENCY_LOG_FREQUENCY;
247f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert    }
2484ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert
2494ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert    /**
2504ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert     * The delay in milliseconds before suggestions are updated while typing.
2514ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert     * If a new character is typed before this timeout expires, the timeout is reset.
2524ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert     */
2534ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert    public long getTypingUpdateSuggestionsDelayMillis() {
2544ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert        return TYPING_SUGGESTIONS_UPDATE_DELAY_MILLIS;
2554ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert    }
256ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert
257ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert    /**
258ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert     * The delay in milliseconds before corpus results are published.
259ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert     * If a new result arrives before this timeout expires, the timeout is reset.
260ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert     */
261ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert    public long getPublishResultDelayMillis() {
262ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert        return PUBLISH_RESULT_DELAY_MILLIS;
263ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert    }
264ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert
26549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    public boolean allowVoiceSearchHints() {
266e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert        return true;
26749fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    }
268f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
269f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
270f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The period of time for which after installing voice search we should consider showing voice
271f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * search hints.
2725d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
273f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * @return The period in milliseconds.
274f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
275f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintActivePeriod() {
276f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_ACTIVE_PERIOD;
277f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
278f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
279f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
280f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The time interval at which we should consider whether or not to show some voice search hints.
2815d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
282f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * @return The period in milliseconds.
283f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
284f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintUpdatePeriod() {
285f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_UPDATE_INTERVAL;
286f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
287f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
288f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
289f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The time interval at which, on average, voice search hints are displayed.
2905d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
2915d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     * @return The period in milliseconds.
292f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
293f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintShowPeriod() {
294f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_SHOW_PERIOD_MILLIS;
295f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
296f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
297f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
298f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The amount of time for which voice search hints are displayed in one go.
2995d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
300f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * @return The period in milliseconds.
301f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
302f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintVisibleTime() {
303f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_VISIBLE_PERIOD;
304f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
305f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
306f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
307f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The period that we change voice search hints at while they're being displayed.
3085d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
309f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * @return The period in milliseconds.
310f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
311f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintChangePeriod() {
312f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_CHANGE_PERIOD;
313f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
314848fa7a19abedc372452073abaf52780c7b6d78dAmith Yamasani
315e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood    public boolean showSuggestionsForZeroQuery() {
3161fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        // Get the list of default corpora from a resource, which allows vendor overlays.
3171fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getBoolean(R.bool.show_zero_query_suggestions);
318e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood    }
319e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood
320e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood    public boolean showShortcutsForZeroQuery() {
3211fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        // Get the list of default corpora from a resource, which allows vendor overlays.
3221fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getBoolean(R.bool.show_zero_query_shortcuts);
323e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood    }
324e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood
325fdb80c2962c88ac62dcd7ee7f2fab1857b61506bMathew Inwood    public boolean showScrollingSuggestions() {
3261fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getBoolean(R.bool.show_scrolling_suggestions);
327fdb80c2962c88ac62dcd7ee7f2fab1857b61506bMathew Inwood    }
328fdb80c2962c88ac62dcd7ee7f2fab1857b61506bMathew Inwood
329f5a8912d5da80378d38b667eba4aaa0555aea7bdMathew Inwood    public boolean showScrollingResults() {
330f5a8912d5da80378d38b667eba4aaa0555aea7bdMathew Inwood        return mContext.getResources().getBoolean(R.bool.show_scrolling_results);
331f5a8912d5da80378d38b667eba4aaa0555aea7bdMathew Inwood    }
332f5a8912d5da80378d38b667eba4aaa0555aea7bdMathew Inwood
33371f9f8ccd3c12d7d48e2fee4c55cd57e1970b797Bjorn Bringert    public Uri getHelpUrl(String activity) {
33471f9f8ccd3c12d7d48e2fee4c55cd57e1970b797Bjorn Bringert        return null;
3355eee22a4ec6fc45deb9706ba535039ccae51b90aBjorn Bringert    }
3365eee22a4ec6fc45deb9706ba535039ccae51b90aBjorn Bringert
337cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    public int getHttpConnectTimeout() {
338cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood        return HTTP_CONNECT_TIMEOUT_MILLIS;
339cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    }
340cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood
341cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    public int getHttpReadTimeout() {
342cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood        return HTTP_READ_TIMEOUT_MILLIS;
343cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    }
344cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood
345ef6dbc776667219ac89bd5f80c181f65260457acNarayan Kamath    public String getUserAgent() {
346ef6dbc776667219ac89bd5f80c181f65260457acNarayan Kamath        return USER_AGENT;
347ef6dbc776667219ac89bd5f80c181f65260457acNarayan Kamath    }
3483e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert}
349