Config.java revision cd4accc7899fa7b756e1c430d6b196525abd5c3c
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;
213e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.os.Process;
223e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.util.Log;
233e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport java.util.HashSet;
253e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
263e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/**
273e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Provides values for configurable parameters in all of QSB.
283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
293e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * All the methods in this class return fixed default values. Subclasses may
303e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * make these values server-side settable.
313e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
323e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */
333e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertpublic class Config {
343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
353e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final String TAG = "QSB.Config";
3609552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood    private static final boolean DBG = false;
373e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
38f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    protected static final long SECOND_MILLIS = 1000L;
39f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    protected static final long MINUTE_MILLIS = 60L * SECOND_MILLIS;
40f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    protected static final long DAY_MILLIS = 86400000L;
413e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
42fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    private static final int NUM_PROMOTED_SOURCES = 3;
433e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final int MAX_RESULTS_PER_SOURCE = 50;
443e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final long SOURCE_TIMEOUT_MILLIS = 10000;
453e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
463e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final int QUERY_THREAD_PRIORITY =
473e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE;
483e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
4987331ef11a1ac6c907c008354e3aab5eb6f87404Bjorn Bringert    private static final long MAX_STAT_AGE_MILLIS = 30 * DAY_MILLIS;
503e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final int MIN_CLICKS_FOR_SOURCE_RANKING = 3;
513e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
5272f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert    private static final int NUM_WEB_CORPUS_THREADS = 2;
5372f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert
54f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert    private static final int LATENCY_LOG_FREQUENCY = 1000;
55f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert
564ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert    private static final long TYPING_SUGGESTIONS_UPDATE_DELAY_MILLIS = 100;
57ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert    private static final long PUBLISH_RESULT_DELAY_MILLIS = 200;
584ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert
59f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_ACTIVE_PERIOD = 7L * DAY_MILLIS;
60f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
61f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_UPDATE_INTERVAL
62f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood            = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
63f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
64f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_SHOW_PERIOD_MILLIS
65f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood            = AlarmManager.INTERVAL_HOUR * 2;
66f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
67f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_CHANGE_PERIOD = 2L * MINUTE_MILLIS;
68f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
69f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    private static final long VOICE_SEARCH_HINT_VISIBLE_PERIOD = 6L * MINUTE_MILLIS;
70f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
71cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    private static final int HTTP_CONNECT_TIMEOUT_MILLIS = 4000;
72cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    private static final int HTTP_READ_TIMEOUT_MILLIS = 4000;
73cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood
74af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    private final Context mContext;
75fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    private HashSet<String> mDefaultCorpora;
7696c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    private HashSet<String> mHiddenCorpora;
7709552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood    private HashSet<String> mDefaultCorporaSuggestUris;
783e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
793e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
803e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * Creates a new config that uses hard-coded default values.
813e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
823e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public Config(Context context) {
833e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        mContext = context;
843e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
853e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
86af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    protected Context getContext() {
87af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert        return mContext;
88af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    }
89af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert
90af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    /**
91af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * Releases any resources used by the configuration object.
92af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     *
93af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * Default implementation does nothing.
94af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     */
95af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    public void close() {
96af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    }
97af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert
9896c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    private HashSet<String> loadResourceStringSet(int res) {
99fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert        HashSet<String> defaultCorpora = new HashSet<String>();
1001fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        String[] corpora = mContext.getResources().getStringArray(res);
1011fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        for (String corpus : corpora) {
1021fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood            if (DBG) Log.d(TAG, "Default corpus: " + corpus);
1031fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood            defaultCorpora.add(corpus);
1043e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1051fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return defaultCorpora;
1063e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1073e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1083e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
1093e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * Checks if we trust the given source not to be spammy.
1103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
11109552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood    public synchronized boolean isCorpusEnabledByDefault(Corpus corpus) {
11209552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        if (DBG) Log.d(TAG, "isCorpusEnabledByDefault(" + corpus.getName() + ")");
113fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert        if (mDefaultCorpora == null) {
11496c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert            mDefaultCorpora = loadResourceStringSet(R.array.default_corpora);
1153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
11609552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        if (mDefaultCorpora.contains(corpus.getName())) {
11709552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            if (DBG) Log.d(TAG, "Corpus " + corpus.getName() + " IS default");
11809552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            return true;
11909552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        }
12009552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood
12109552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        if (mDefaultCorporaSuggestUris == null) {
12209552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            mDefaultCorporaSuggestUris = loadResourceStringSet(
12309552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood                    R.array.default_corpora_suggest_uris);
12409552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        }
12509552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood
12609552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        for (Source s : corpus.getSources()) {
12709552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            String uri = s.getSuggestUri();
12809552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            if (DBG) Log.d(TAG, "Suggest URI for " + corpus.getName() + ": " + uri);
12909552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            if (mDefaultCorporaSuggestUris.contains(uri)) {
13009552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood                if (DBG) Log.d(TAG, "Corpus " + corpus.getName() + " IS default");
13109552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood                return true;
13209552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood            }
13309552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        }
13409552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        if (DBG) Log.d(TAG, "Corpus " + corpus.getName() + " is NOT default");
13509552c760ad82eb90795e98de96c65005d6ebafcMathew Inwood        return false;
1363e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1373e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1383e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
13996c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert     * Checks if the given corpus should be hidden from the corpus selection dialog.
14096c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert     */
14196c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    public synchronized boolean isCorpusHidden(String corpusName) {
14296c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert        if (mHiddenCorpora == null) {
14396c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert            mHiddenCorpora = loadResourceStringSet(R.array.hidden_corpora);
14496c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert        }
14596c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert        return mHiddenCorpora.contains(corpusName);
14696c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    }
14796c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert
14896c7058210699c82445169048b7c0fdfb16f59eeBjorn Bringert    /**
149af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * The number of promoted sources.
150af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     */
151af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    public int getNumPromotedSources() {
152af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert        return NUM_PROMOTED_SOURCES;
153af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    }
154af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert
155af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    /**
15639bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney     * The number of suggestions visible above the onscreen keyboard.
15739bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney     */
15839bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney    public int getNumSuggestionsAboveKeyboard() {
1591fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        // Get the list of default corpora from a resource, which allows vendor overlays.
1601fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getInteger(R.integer.num_suggestions_above_keyboard);
16139bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney    }
16239bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney
16339bbcdc1a485ded93059de4a3f70bfda85e9f304Bryan Mawhinney    /**
1643e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * The maximum number of suggestions to promote.
1653e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
1663e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getMaxPromotedSuggestions() {
1671fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getInteger(R.integer.max_promoted_suggestions);
1683e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1693e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1707a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    public int getMaxPromotedResults() {
1717a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood        return mContext.getResources().getInteger(R.integer.max_promoted_results);
1727a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    }
1737a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood
1743e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
1753e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * The number of results to ask each source for.
1763e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
1773e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getMaxResultsPerSource() {
1783e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return MAX_RESULTS_PER_SOURCE;
1793e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1803e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1813e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
18208ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert     * The maximum number of shortcuts to show for the web source in All mode.
18308ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert     */
18408ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    public int getMaxShortcutsPerWebSource() {
185af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood        return mContext.getResources().getInteger(R.integer.max_shortcuts_per_web_source);
18608ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    }
18708ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert
18808ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    /**
18908ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert     * The maximum number of shortcuts to show for each non-web source in All mode.
19008ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert     */
19108ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    public int getMaxShortcutsPerNonWebSource() {
192af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood        return mContext.getResources().getInteger(R.integer.max_shortcuts_per_non_web_source);
19308ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    }
19408ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert
19508ff0a7cb6b99db79508fa3124730eb81411bc56Bjorn Bringert    /**
19653aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert     * Gets the maximum number of shortcuts that will be shown from the given source.
19753aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert     */
19853aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert    public int getMaxShortcuts(String sourceName) {
19953aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert        return getMaxShortcutsPerNonWebSource();
20053aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert    }
20153aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert
20253aab8c4459f45664d04ec882d67094c52b78695Bjorn Bringert    /**
2033e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * The timeout for querying each source, in milliseconds.
2043e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
2053e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public long getSourceTimeoutMillis() {
2063e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return SOURCE_TIMEOUT_MILLIS;
2073e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2083e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
2093e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
2103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * The priority of query threads.
2113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     *
2123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * @return A thread priority, as defined in {@link Process}.
2133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
2143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getQueryThreadPriority() {
2153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return QUERY_THREAD_PRIORITY;
2163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
218af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    /**
219af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * The maximum age of log data used for shortcuts.
220af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     */
2213e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public long getMaxStatAgeMillis(){
2223e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return MAX_STAT_AGE_MILLIS;
2233e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
225af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert    /**
226af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     * The minimum number of clicks needed to rank a source.
227af736c70f989ebd716e0e389a28c6604b218e14fBjorn Bringert     */
2283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getMinClicksForSourceRanking(){
2293e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return MIN_CLICKS_FOR_SOURCE_RANKING;
2303e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2313e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
23272f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert    public int getNumWebCorpusThreads() {
23372f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert        return NUM_WEB_CORPUS_THREADS;
23472f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert    }
23572f9b08ce84d0e13daf2d1c112d4e6d1d3ada045Bjorn Bringert
236f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert    /**
237f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     * How often query latency should be logged.
238f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     *
239f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     * @return An integer in the range 0-1000. 0 means that no latency events
240f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     *         should be logged. 1000 means that all latency events should be logged.
241f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert     */
242f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert    public int getLatencyLogFrequency() {
243f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert        return LATENCY_LOG_FREQUENCY;
244f95ce100dcbc77794b79b0187c566bb58b5978d3Bjorn Bringert    }
2454ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert
2464ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert    /**
2474ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert     * The delay in milliseconds before suggestions are updated while typing.
2484ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert     * If a new character is typed before this timeout expires, the timeout is reset.
2494ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert     */
2504ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert    public long getTypingUpdateSuggestionsDelayMillis() {
2514ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert        return TYPING_SUGGESTIONS_UPDATE_DELAY_MILLIS;
2524ef1338a23b040df2ef180c48ff85e14a9d70906Bjorn Bringert    }
253ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert
254ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert    /**
255ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert     * The delay in milliseconds before corpus results are published.
256ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert     * If a new result arrives before this timeout expires, the timeout is reset.
257ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert     */
258ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert    public long getPublishResultDelayMillis() {
259ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert        return PUBLISH_RESULT_DELAY_MILLIS;
260ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert    }
261ced9f76b761536341d739e9a243c98a4bf90638cBjorn Bringert
26249fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    public boolean allowVoiceSearchHints() {
263e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert        return true;
26449fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    }
265f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
266f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
267f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The period of time for which after installing voice search we should consider showing voice
268f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * search hints.
2695d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
270f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * @return The period in milliseconds.
271f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
272f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintActivePeriod() {
273f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_ACTIVE_PERIOD;
274f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
275f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
276f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
277f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The time interval at which we should consider whether or not to show some voice search hints.
2785d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
279f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * @return The period in milliseconds.
280f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
281f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintUpdatePeriod() {
282f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_UPDATE_INTERVAL;
283f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
284f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
285f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
286f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The time interval at which, on average, voice search hints are displayed.
2875d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
2885d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     * @return The period in milliseconds.
289f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
290f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintShowPeriod() {
291f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_SHOW_PERIOD_MILLIS;
292f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
293f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
294f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
295f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The amount of time for which voice search hints are displayed in one go.
2965d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
297f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * @return The period in milliseconds.
298f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
299f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintVisibleTime() {
300f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_VISIBLE_PERIOD;
301f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
302f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood
303f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    /**
304f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * The period that we change voice search hints at while they're being displayed.
3055d8047bba2e05cc0cc1ca6684a53f26656a60584Mathew Inwood     *
306f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     * @return The period in milliseconds.
307f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood     */
308f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    public long getVoiceSearchHintChangePeriod() {
309f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood        return VOICE_SEARCH_HINT_CHANGE_PERIOD;
310f695d6bf59f2a3b2d58ab2480f2178825e712effMathew Inwood    }
311848fa7a19abedc372452073abaf52780c7b6d78dAmith Yamasani
312e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood    public boolean showSuggestionsForZeroQuery() {
3131fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        // Get the list of default corpora from a resource, which allows vendor overlays.
3141fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getBoolean(R.bool.show_zero_query_suggestions);
315e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood    }
316e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood
317e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood    public boolean showShortcutsForZeroQuery() {
3181fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        // Get the list of default corpora from a resource, which allows vendor overlays.
3191fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getBoolean(R.bool.show_zero_query_shortcuts);
320e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood    }
321e15fe38f0142174d223bfda0cd87d1a749a85facMathew Inwood
322fdb80c2962c88ac62dcd7ee7f2fab1857b61506bMathew Inwood    public boolean showScrollingSuggestions() {
3231fe2cb3896fa2a051bc8b716fa97b2c8398b71f1Mathew Inwood        return mContext.getResources().getBoolean(R.bool.show_scrolling_suggestions);
324fdb80c2962c88ac62dcd7ee7f2fab1857b61506bMathew Inwood    }
325fdb80c2962c88ac62dcd7ee7f2fab1857b61506bMathew Inwood
326f5a8912d5da80378d38b667eba4aaa0555aea7bdMathew Inwood    public boolean showScrollingResults() {
327f5a8912d5da80378d38b667eba4aaa0555aea7bdMathew Inwood        return mContext.getResources().getBoolean(R.bool.show_scrolling_results);
328f5a8912d5da80378d38b667eba4aaa0555aea7bdMathew Inwood    }
329f5a8912d5da80378d38b667eba4aaa0555aea7bdMathew Inwood
3305eee22a4ec6fc45deb9706ba535039ccae51b90aBjorn Bringert    public String getHelpUrl() {
3315eee22a4ec6fc45deb9706ba535039ccae51b90aBjorn Bringert        return getContext().getString(R.string.help_url);
3325eee22a4ec6fc45deb9706ba535039ccae51b90aBjorn Bringert    }
3335eee22a4ec6fc45deb9706ba535039ccae51b90aBjorn Bringert
334cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    public int getHttpConnectTimeout() {
335cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood        return HTTP_CONNECT_TIMEOUT_MILLIS;
336cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    }
337cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood
338cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    public int getHttpReadTimeout() {
339cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood        return HTTP_READ_TIMEOUT_MILLIS;
340cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood    }
341cd4accc7899fa7b756e1c430d6b196525abd5c3cMathew Inwood
3423e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert}
343