Settings.java revision a3d5e0c5e3d12b3f8d7f43acb0c170b5e5899876
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.provider;
18
19import com.google.android.collect.Maps;
20
21import org.apache.commons.codec.binary.Base64;
22
23import android.annotation.SdkConstant;
24import android.annotation.SdkConstant.SdkConstantType;
25import android.content.ContentQueryMap;
26import android.content.ContentResolver;
27import android.content.ContentValues;
28import android.content.Context;
29import android.content.Intent;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
32import android.content.res.Configuration;
33import android.content.res.Resources;
34import android.database.Cursor;
35import android.database.SQLException;
36import android.net.Uri;
37import android.os.*;
38import android.telephony.TelephonyManager;
39import android.text.TextUtils;
40import android.util.AndroidException;
41import android.util.Config;
42import android.util.Log;
43
44import java.net.URISyntaxException;
45import java.security.MessageDigest;
46import java.security.NoSuchAlgorithmException;
47import java.util.Collections;
48import java.util.HashMap;
49import java.util.HashSet;
50import java.util.Map;
51
52
53/**
54 * The Settings provider contains global system-level device preferences.
55 */
56public final class Settings {
57
58    // Intent actions for Settings
59
60    /**
61     * Activity Action: Show system settings.
62     * <p>
63     * Input: Nothing.
64     * <p>
65     * Output: nothing.
66     */
67    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
68    public static final String ACTION_SETTINGS = "android.settings.SETTINGS";
69
70    /**
71     * Activity Action: Show settings to allow configuration of APNs.
72     * <p>
73     * Input: Nothing.
74     * <p>
75     * Output: nothing.
76     */
77    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
78    public static final String ACTION_APN_SETTINGS = "android.settings.APN_SETTINGS";
79
80    /**
81     * Activity Action: Show settings to allow configuration of current location
82     * sources.
83     * <p>
84     * In some cases, a matching Activity may not exist, so ensure you
85     * safeguard against this.
86     * <p>
87     * Input: Nothing.
88     * <p>
89     * Output: Nothing.
90     */
91    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
92    public static final String ACTION_LOCATION_SOURCE_SETTINGS =
93            "android.settings.LOCATION_SOURCE_SETTINGS";
94
95    /**
96     * Activity Action: Show settings to allow configuration of wireless controls
97     * such as Wi-Fi, Bluetooth and Mobile networks.
98     * <p>
99     * In some cases, a matching Activity may not exist, so ensure you
100     * safeguard against this.
101     * <p>
102     * Input: Nothing.
103     * <p>
104     * Output: Nothing.
105     */
106    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
107    public static final String ACTION_WIRELESS_SETTINGS =
108            "android.settings.WIRELESS_SETTINGS";
109
110    /**
111     * Activity Action: Show settings to allow entering/exiting airplane mode.
112     * <p>
113     * In some cases, a matching Activity may not exist, so ensure you
114     * safeguard against this.
115     * <p>
116     * Input: Nothing.
117     * <p>
118     * Output: Nothing.
119     */
120    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
121    public static final String ACTION_AIRPLANE_MODE_SETTINGS =
122            "android.settings.AIRPLANE_MODE_SETTINGS";
123
124    /**
125     * Activity Action: Show settings for accessibility modules.
126     * <p>
127     * In some cases, a matching Activity may not exist, so ensure you
128     * safeguard against this.
129     * <p>
130     * Input: Nothing.
131     * <p>
132     * Output: Nothing.
133     */
134    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
135    public static final String ACTION_ACCESSIBILITY_SETTINGS =
136            "android.settings.ACCESSIBILITY_SETTINGS";
137
138    /**
139     * Activity Action: Show settings to allow configuration of security and
140     * location privacy.
141     * <p>
142     * In some cases, a matching Activity may not exist, so ensure you
143     * safeguard against this.
144     * <p>
145     * Input: Nothing.
146     * <p>
147     * Output: Nothing.
148     */
149    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
150    public static final String ACTION_SECURITY_SETTINGS =
151            "android.settings.SECURITY_SETTINGS";
152
153    /**
154     * Activity Action: Show settings to allow configuration of privacy options.
155     * <p>
156     * In some cases, a matching Activity may not exist, so ensure you
157     * safeguard against this.
158     * <p>
159     * Input: Nothing.
160     * <p>
161     * Output: Nothing.
162     */
163    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
164    public static final String ACTION_PRIVACY_SETTINGS =
165            "android.settings.PRIVACY_SETTINGS";
166
167    /**
168     * Activity Action: Show settings to allow configuration of Wi-Fi.
169
170     * <p>
171     * In some cases, a matching Activity may not exist, so ensure you
172     * safeguard against this.
173     * <p>
174     * Input: Nothing.
175     * <p>
176     * Output: Nothing.
177
178     */
179    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
180    public static final String ACTION_WIFI_SETTINGS =
181            "android.settings.WIFI_SETTINGS";
182
183    /**
184     * Activity Action: Show settings to allow configuration of a static IP
185     * address for Wi-Fi.
186     * <p>
187     * In some cases, a matching Activity may not exist, so ensure you safeguard
188     * against this.
189     * <p>
190     * Input: Nothing.
191     * <p>
192     * Output: Nothing.
193     */
194    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
195    public static final String ACTION_WIFI_IP_SETTINGS =
196            "android.settings.WIFI_IP_SETTINGS";
197
198    /**
199     * Activity Action: Show settings to allow configuration of Bluetooth.
200     * <p>
201     * In some cases, a matching Activity may not exist, so ensure you
202     * safeguard against this.
203     * <p>
204     * Input: Nothing.
205     * <p>
206     * Output: Nothing.
207     */
208    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
209    public static final String ACTION_BLUETOOTH_SETTINGS =
210            "android.settings.BLUETOOTH_SETTINGS";
211
212    /**
213     * Activity Action: Show settings to allow configuration of date and time.
214     * <p>
215     * In some cases, a matching Activity may not exist, so ensure you
216     * safeguard against this.
217     * <p>
218     * Input: Nothing.
219     * <p>
220     * Output: Nothing.
221     */
222    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
223    public static final String ACTION_DATE_SETTINGS =
224            "android.settings.DATE_SETTINGS";
225
226    /**
227     * Activity Action: Show settings to allow configuration of sound and volume.
228     * <p>
229     * In some cases, a matching Activity may not exist, so ensure you
230     * safeguard against this.
231     * <p>
232     * Input: Nothing.
233     * <p>
234     * Output: Nothing.
235     */
236    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
237    public static final String ACTION_SOUND_SETTINGS =
238            "android.settings.SOUND_SETTINGS";
239
240    /**
241     * Activity Action: Show settings to allow configuration of display.
242     * <p>
243     * In some cases, a matching Activity may not exist, so ensure you
244     * safeguard against this.
245     * <p>
246     * Input: Nothing.
247     * <p>
248     * Output: Nothing.
249     */
250    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
251    public static final String ACTION_DISPLAY_SETTINGS =
252            "android.settings.DISPLAY_SETTINGS";
253
254    /**
255     * Activity Action: Show settings to allow configuration of locale.
256     * <p>
257     * In some cases, a matching Activity may not exist, so ensure you
258     * safeguard against this.
259     * <p>
260     * Input: Nothing.
261     * <p>
262     * Output: Nothing.
263     */
264    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
265    public static final String ACTION_LOCALE_SETTINGS =
266            "android.settings.LOCALE_SETTINGS";
267
268    /**
269     * Activity Action: Show settings to configure input methods, in particular
270     * allowing the user to enable input methods.
271     * <p>
272     * In some cases, a matching Activity may not exist, so ensure you
273     * safeguard against this.
274     * <p>
275     * Input: Nothing.
276     * <p>
277     * Output: Nothing.
278     */
279    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
280    public static final String ACTION_INPUT_METHOD_SETTINGS =
281            "android.settings.INPUT_METHOD_SETTINGS";
282
283    /**
284     * Activity Action: Show settings to manage the user input dictionary.
285     * <p>
286     * In some cases, a matching Activity may not exist, so ensure you
287     * safeguard against this.
288     * <p>
289     * Input: Nothing.
290     * <p>
291     * Output: Nothing.
292     */
293    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
294    public static final String ACTION_USER_DICTIONARY_SETTINGS =
295            "android.settings.USER_DICTIONARY_SETTINGS";
296
297    /**
298     * Activity Action: Show settings to allow configuration of application-related settings.
299     * <p>
300     * In some cases, a matching Activity may not exist, so ensure you
301     * safeguard against this.
302     * <p>
303     * Input: Nothing.
304     * <p>
305     * Output: Nothing.
306     */
307    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
308    public static final String ACTION_APPLICATION_SETTINGS =
309            "android.settings.APPLICATION_SETTINGS";
310
311    /**
312     * Activity Action: Show settings to allow configuration of application
313     * development-related settings.
314     * <p>
315     * In some cases, a matching Activity may not exist, so ensure you safeguard
316     * against this.
317     * <p>
318     * Input: Nothing.
319     * <p>
320     * Output: Nothing.
321     */
322    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
323    public static final String ACTION_APPLICATION_DEVELOPMENT_SETTINGS =
324            "android.settings.APPLICATION_DEVELOPMENT_SETTINGS";
325
326    /**
327     * Activity Action: Show settings to allow configuration of quick launch shortcuts.
328     * <p>
329     * In some cases, a matching Activity may not exist, so ensure you
330     * safeguard against this.
331     * <p>
332     * Input: Nothing.
333     * <p>
334     * Output: Nothing.
335     */
336    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
337    public static final String ACTION_QUICK_LAUNCH_SETTINGS =
338            "android.settings.QUICK_LAUNCH_SETTINGS";
339
340    /**
341     * Activity Action: Show settings to manage installed applications.
342     * <p>
343     * In some cases, a matching Activity may not exist, so ensure you
344     * safeguard against this.
345     * <p>
346     * Input: Nothing.
347     * <p>
348     * Output: Nothing.
349     */
350    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
351    public static final String ACTION_MANAGE_APPLICATIONS_SETTINGS =
352            "android.settings.MANAGE_APPLICATIONS_SETTINGS";
353
354    /**
355     * Activity Action: Show settings for system update functionality.
356     * <p>
357     * In some cases, a matching Activity may not exist, so ensure you
358     * safeguard against this.
359     * <p>
360     * Input: Nothing.
361     * <p>
362     * Output: Nothing.
363     *
364     * @hide
365     */
366    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
367    public static final String ACTION_SYSTEM_UPDATE_SETTINGS =
368            "android.settings.SYSTEM_UPDATE_SETTINGS";
369
370    /**
371     * Activity Action: Show settings to allow configuration of sync settings.
372     * <p>
373     * In some cases, a matching Activity may not exist, so ensure you
374     * safeguard against this.
375     * <p>
376     * Input: Nothing.
377     * <p>
378     * Output: Nothing.
379     */
380    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
381    public static final String ACTION_SYNC_SETTINGS =
382            "android.settings.SYNC_SETTINGS";
383
384    /**
385     * Activity Action: Show settings for selecting the network operator.
386     * <p>
387     * In some cases, a matching Activity may not exist, so ensure you
388     * safeguard against this.
389     * <p>
390     * Input: Nothing.
391     * <p>
392     * Output: Nothing.
393     */
394    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
395    public static final String ACTION_NETWORK_OPERATOR_SETTINGS =
396            "android.settings.NETWORK_OPERATOR_SETTINGS";
397
398    /**
399     * Activity Action: Show settings for selection of 2G/3G.
400     * <p>
401     * In some cases, a matching Activity may not exist, so ensure you
402     * safeguard against this.
403     * <p>
404     * Input: Nothing.
405     * <p>
406     * Output: Nothing.
407     */
408    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
409    public static final String ACTION_DATA_ROAMING_SETTINGS =
410            "android.settings.DATA_ROAMING_SETTINGS";
411
412    /**
413     * Activity Action: Show settings for internal storage.
414     * <p>
415     * In some cases, a matching Activity may not exist, so ensure you
416     * safeguard against this.
417     * <p>
418     * Input: Nothing.
419     * <p>
420     * Output: Nothing.
421     */
422    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
423    public static final String ACTION_INTERNAL_STORAGE_SETTINGS =
424            "android.settings.INTERNAL_STORAGE_SETTINGS";
425    /**
426     * Activity Action: Show settings for memory card storage.
427     * <p>
428     * In some cases, a matching Activity may not exist, so ensure you
429     * safeguard against this.
430     * <p>
431     * Input: Nothing.
432     * <p>
433     * Output: Nothing.
434     */
435    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
436    public static final String ACTION_MEMORY_CARD_SETTINGS =
437            "android.settings.MEMORY_CARD_SETTINGS";
438
439    /**
440     * Activity Action: Show settings for global search.
441     * <p>
442     * In some cases, a matching Activity may not exist, so ensure you
443     * safeguard against this.
444     * <p>
445     * Input: Nothing.
446     * <p>
447     * Output: Nothing
448     */
449    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
450    public static final String ACTION_SEARCH_SETTINGS =
451        "android.search.action.SEARCH_SETTINGS";
452
453    /**
454     * Activity Action: Show general device information settings (serial
455     * number, software version, phone number, etc.).
456     * <p>
457     * In some cases, a matching Activity may not exist, so ensure you
458     * safeguard against this.
459     * <p>
460     * Input: Nothing.
461     * <p>
462     * Output: Nothing
463     */
464    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
465    public static final String ACTION_DEVICE_INFO_SETTINGS =
466        "android.settings.DEVICE_INFO_SETTINGS";
467
468    // End of Intent actions for Settings
469
470    private static final String JID_RESOURCE_PREFIX = "android";
471
472    public static final String AUTHORITY = "settings";
473
474    private static final String TAG = "Settings";
475    private static final boolean LOCAL_LOGV = Config.LOGV || false;
476
477    public static class SettingNotFoundException extends AndroidException {
478        public SettingNotFoundException(String msg) {
479            super(msg);
480        }
481    }
482
483    /**
484     * Common base for tables of name/value settings.
485     */
486    public static class NameValueTable implements BaseColumns {
487        public static final String NAME = "name";
488        public static final String VALUE = "value";
489
490        protected static boolean putString(ContentResolver resolver, Uri uri,
491                String name, String value) {
492            // The database will take care of replacing duplicates.
493            try {
494                ContentValues values = new ContentValues();
495                values.put(NAME, name);
496                values.put(VALUE, value);
497                resolver.insert(uri, values);
498                return true;
499            } catch (SQLException e) {
500                Log.w(TAG, "Can't set key " + name + " in " + uri, e);
501                return false;
502            }
503        }
504
505        public static Uri getUriFor(Uri uri, String name) {
506            return Uri.withAppendedPath(uri, name);
507        }
508    }
509
510    private static class NameValueCache {
511        private final String mVersionSystemProperty;
512        private final Uri mUri;
513
514        // Must synchronize(mValues) to access mValues and mValuesVersion.
515        private final HashMap<String, String> mValues = new HashMap<String, String>();
516        private long mValuesVersion = 0;
517
518        public NameValueCache(String versionSystemProperty, Uri uri) {
519            mVersionSystemProperty = versionSystemProperty;
520            mUri = uri;
521        }
522
523        public String getString(ContentResolver cr, String name) {
524            long newValuesVersion = SystemProperties.getLong(mVersionSystemProperty, 0);
525
526            synchronized (mValues) {
527                if (mValuesVersion != newValuesVersion) {
528                    if (LOCAL_LOGV) {
529                        Log.v(TAG, "invalidate [" + mUri.getLastPathSegment() + "]: current " +
530                                newValuesVersion + " != cached " + mValuesVersion);
531                    }
532
533                    mValues.clear();
534                    mValuesVersion = newValuesVersion;
535                }
536
537                if (mValues.containsKey(name)) {
538                    return mValues.get(name);  // Could be null, that's OK -- negative caching
539                }
540            }
541
542            Cursor c = null;
543            try {
544                c = cr.query(mUri, new String[] { Settings.NameValueTable.VALUE },
545                        Settings.NameValueTable.NAME + "=?", new String[]{name}, null);
546                if (c == null) {
547                    Log.w(TAG, "Can't get key " + name + " from " + mUri);
548                    return null;
549                }
550
551                String value = c.moveToNext() ? c.getString(0) : null;
552                synchronized (mValues) {
553                    mValues.put(name, value);
554                }
555                if (LOCAL_LOGV) {
556                    Log.v(TAG, "cache miss [" + mUri.getLastPathSegment() + "]: " +
557                            name + " = " + (value == null ? "(null)" : value));
558                }
559                return value;
560            } catch (SQLException e) {
561                Log.w(TAG, "Can't get key " + name + " from " + mUri, e);
562                return null;  // Return null, but don't cache it.
563            } finally {
564                if (c != null) c.close();
565            }
566        }
567    }
568
569    /**
570     * System settings, containing miscellaneous system preferences.  This
571     * table holds simple name/value pairs.  There are convenience
572     * functions for accessing individual settings entries.
573     */
574    public static final class System extends NameValueTable {
575        public static final String SYS_PROP_SETTING_VERSION = "sys.settings_system_version";
576
577        private static volatile NameValueCache mNameValueCache = null;
578
579        private static final HashSet<String> MOVED_TO_SECURE;
580        static {
581            MOVED_TO_SECURE = new HashSet<String>(30);
582            MOVED_TO_SECURE.add(Secure.ADB_ENABLED);
583            MOVED_TO_SECURE.add(Secure.ANDROID_ID);
584            MOVED_TO_SECURE.add(Secure.BLUETOOTH_ON);
585            MOVED_TO_SECURE.add(Secure.DATA_ROAMING);
586            MOVED_TO_SECURE.add(Secure.DEVICE_PROVISIONED);
587            MOVED_TO_SECURE.add(Secure.HTTP_PROXY);
588            MOVED_TO_SECURE.add(Secure.INSTALL_NON_MARKET_APPS);
589            MOVED_TO_SECURE.add(Secure.LOCATION_PROVIDERS_ALLOWED);
590            MOVED_TO_SECURE.add(Secure.LOGGING_ID);
591            MOVED_TO_SECURE.add(Secure.PARENTAL_CONTROL_ENABLED);
592            MOVED_TO_SECURE.add(Secure.PARENTAL_CONTROL_LAST_UPDATE);
593            MOVED_TO_SECURE.add(Secure.PARENTAL_CONTROL_REDIRECT_URL);
594            MOVED_TO_SECURE.add(Secure.SETTINGS_CLASSNAME);
595            MOVED_TO_SECURE.add(Secure.USB_MASS_STORAGE_ENABLED);
596            MOVED_TO_SECURE.add(Secure.USE_GOOGLE_MAIL);
597            MOVED_TO_SECURE.add(Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON);
598            MOVED_TO_SECURE.add(Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY);
599            MOVED_TO_SECURE.add(Secure.WIFI_NUM_OPEN_NETWORKS_KEPT);
600            MOVED_TO_SECURE.add(Secure.WIFI_ON);
601            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE);
602            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_AP_COUNT);
603            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS);
604            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED);
605            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS);
606            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT);
607            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_MAX_AP_CHECKS);
608            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_ON);
609            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_PING_COUNT);
610            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_PING_DELAY_MS);
611            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS);
612        }
613
614        /**
615         * Look up a name in the database.
616         * @param resolver to access the database with
617         * @param name to look up in the table
618         * @return the corresponding value, or null if not present
619         */
620        public synchronized static String getString(ContentResolver resolver, String name) {
621            if (MOVED_TO_SECURE.contains(name)) {
622                Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.System"
623                        + " to android.provider.Settings.Secure, returning read-only value.");
624                return Secure.getString(resolver, name);
625            }
626            if (mNameValueCache == null) {
627                mNameValueCache = new NameValueCache(SYS_PROP_SETTING_VERSION, CONTENT_URI);
628            }
629            return mNameValueCache.getString(resolver, name);
630        }
631
632        /**
633         * Store a name/value pair into the database.
634         * @param resolver to access the database with
635         * @param name to store
636         * @param value to associate with the name
637         * @return true if the value was set, false on database errors
638         */
639        public static boolean putString(ContentResolver resolver, String name, String value) {
640            if (MOVED_TO_SECURE.contains(name)) {
641                Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.System"
642                        + " to android.provider.Settings.Secure, value is unchanged.");
643                return false;
644            }
645            return putString(resolver, CONTENT_URI, name, value);
646        }
647
648        /**
649         * Construct the content URI for a particular name/value pair,
650         * useful for monitoring changes with a ContentObserver.
651         * @param name to look up in the table
652         * @return the corresponding content URI, or null if not present
653         */
654        public static Uri getUriFor(String name) {
655            if (MOVED_TO_SECURE.contains(name)) {
656                Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.System"
657                    + " to android.provider.Settings.Secure, returning Secure URI.");
658                return Secure.getUriFor(Secure.CONTENT_URI, name);
659            }
660            return getUriFor(CONTENT_URI, name);
661        }
662
663        /**
664         * Convenience function for retrieving a single system settings value
665         * as an integer.  Note that internally setting values are always
666         * stored as strings; this function converts the string to an integer
667         * for you.  The default value will be returned if the setting is
668         * not defined or not an integer.
669         *
670         * @param cr The ContentResolver to access.
671         * @param name The name of the setting to retrieve.
672         * @param def Value to return if the setting is not defined.
673         *
674         * @return The setting's current value, or 'def' if it is not defined
675         * or not a valid integer.
676         */
677        public static int getInt(ContentResolver cr, String name, int def) {
678            String v = getString(cr, name);
679            try {
680                return v != null ? Integer.parseInt(v) : def;
681            } catch (NumberFormatException e) {
682                return def;
683            }
684        }
685
686        /**
687         * Convenience function for retrieving a single system settings value
688         * as an integer.  Note that internally setting values are always
689         * stored as strings; this function converts the string to an integer
690         * for you.
691         * <p>
692         * This version does not take a default value.  If the setting has not
693         * been set, or the string value is not a number,
694         * it throws {@link SettingNotFoundException}.
695         *
696         * @param cr The ContentResolver to access.
697         * @param name The name of the setting to retrieve.
698         *
699         * @throws SettingNotFoundException Thrown if a setting by the given
700         * name can't be found or the setting value is not an integer.
701         *
702         * @return The setting's current value.
703         */
704        public static int getInt(ContentResolver cr, String name)
705                throws SettingNotFoundException {
706            String v = getString(cr, name);
707            try {
708                return Integer.parseInt(v);
709            } catch (NumberFormatException e) {
710                throw new SettingNotFoundException(name);
711            }
712        }
713
714        /**
715         * Convenience function for updating a single settings value as an
716         * integer. This will either create a new entry in the table if the
717         * given name does not exist, or modify the value of the existing row
718         * with that name.  Note that internally setting values are always
719         * stored as strings, so this function converts the given value to a
720         * string before storing it.
721         *
722         * @param cr The ContentResolver to access.
723         * @param name The name of the setting to modify.
724         * @param value The new value for the setting.
725         * @return true if the value was set, false on database errors
726         */
727        public static boolean putInt(ContentResolver cr, String name, int value) {
728            return putString(cr, name, Integer.toString(value));
729        }
730
731        /**
732         * Convenience function for retrieving a single system settings value
733         * as a {@code long}.  Note that internally setting values are always
734         * stored as strings; this function converts the string to a {@code long}
735         * for you.  The default value will be returned if the setting is
736         * not defined or not a {@code long}.
737         *
738         * @param cr The ContentResolver to access.
739         * @param name The name of the setting to retrieve.
740         * @param def Value to return if the setting is not defined.
741         *
742         * @return The setting's current value, or 'def' if it is not defined
743         * or not a valid {@code long}.
744         */
745        public static long getLong(ContentResolver cr, String name, long def) {
746            String valString = getString(cr, name);
747            long value;
748            try {
749                value = valString != null ? Long.parseLong(valString) : def;
750            } catch (NumberFormatException e) {
751                value = def;
752            }
753            return value;
754        }
755
756        /**
757         * Convenience function for retrieving a single system settings value
758         * as a {@code long}.  Note that internally setting values are always
759         * stored as strings; this function converts the string to a {@code long}
760         * for you.
761         * <p>
762         * This version does not take a default value.  If the setting has not
763         * been set, or the string value is not a number,
764         * it throws {@link SettingNotFoundException}.
765         *
766         * @param cr The ContentResolver to access.
767         * @param name The name of the setting to retrieve.
768         *
769         * @return The setting's current value.
770         * @throws SettingNotFoundException Thrown if a setting by the given
771         * name can't be found or the setting value is not an integer.
772         */
773        public static long getLong(ContentResolver cr, String name)
774                throws SettingNotFoundException {
775            String valString = getString(cr, name);
776            try {
777                return Long.parseLong(valString);
778            } catch (NumberFormatException e) {
779                throw new SettingNotFoundException(name);
780            }
781        }
782
783        /**
784         * Convenience function for updating a single settings value as a long
785         * integer. This will either create a new entry in the table if the
786         * given name does not exist, or modify the value of the existing row
787         * with that name.  Note that internally setting values are always
788         * stored as strings, so this function converts the given value to a
789         * string before storing it.
790         *
791         * @param cr The ContentResolver to access.
792         * @param name The name of the setting to modify.
793         * @param value The new value for the setting.
794         * @return true if the value was set, false on database errors
795         */
796        public static boolean putLong(ContentResolver cr, String name, long value) {
797            return putString(cr, name, Long.toString(value));
798        }
799
800        /**
801         * Convenience function for retrieving a single system settings value
802         * as a floating point number.  Note that internally setting values are
803         * always stored as strings; this function converts the string to an
804         * float for you. The default value will be returned if the setting
805         * is not defined or not a valid float.
806         *
807         * @param cr The ContentResolver to access.
808         * @param name The name of the setting to retrieve.
809         * @param def Value to return if the setting is not defined.
810         *
811         * @return The setting's current value, or 'def' if it is not defined
812         * or not a valid float.
813         */
814        public static float getFloat(ContentResolver cr, String name, float def) {
815            String v = getString(cr, name);
816            try {
817                return v != null ? Float.parseFloat(v) : def;
818            } catch (NumberFormatException e) {
819                return def;
820            }
821        }
822
823        /**
824         * Convenience function for retrieving a single system settings value
825         * as a float.  Note that internally setting values are always
826         * stored as strings; this function converts the string to a float
827         * for you.
828         * <p>
829         * This version does not take a default value.  If the setting has not
830         * been set, or the string value is not a number,
831         * it throws {@link SettingNotFoundException}.
832         *
833         * @param cr The ContentResolver to access.
834         * @param name The name of the setting to retrieve.
835         *
836         * @throws SettingNotFoundException Thrown if a setting by the given
837         * name can't be found or the setting value is not a float.
838         *
839         * @return The setting's current value.
840         */
841        public static float getFloat(ContentResolver cr, String name)
842                throws SettingNotFoundException {
843            String v = getString(cr, name);
844            try {
845                return Float.parseFloat(v);
846            } catch (NumberFormatException e) {
847                throw new SettingNotFoundException(name);
848            }
849        }
850
851        /**
852         * Convenience function for updating a single settings value as a
853         * floating point number. This will either create a new entry in the
854         * table if the given name does not exist, or modify the value of the
855         * existing row with that name.  Note that internally setting values
856         * are always stored as strings, so this function converts the given
857         * value to a string before storing it.
858         *
859         * @param cr The ContentResolver to access.
860         * @param name The name of the setting to modify.
861         * @param value The new value for the setting.
862         * @return true if the value was set, false on database errors
863         */
864        public static boolean putFloat(ContentResolver cr, String name, float value) {
865            return putString(cr, name, Float.toString(value));
866        }
867
868        /**
869         * Convenience function to read all of the current
870         * configuration-related settings into a
871         * {@link Configuration} object.
872         *
873         * @param cr The ContentResolver to access.
874         * @param outConfig Where to place the configuration settings.
875         */
876        public static void getConfiguration(ContentResolver cr, Configuration outConfig) {
877            outConfig.fontScale = Settings.System.getFloat(
878                cr, FONT_SCALE, outConfig.fontScale);
879            if (outConfig.fontScale < 0) {
880                outConfig.fontScale = 1;
881            }
882        }
883
884        /**
885         * Convenience function to write a batch of configuration-related
886         * settings from a {@link Configuration} object.
887         *
888         * @param cr The ContentResolver to access.
889         * @param config The settings to write.
890         * @return true if the values were set, false on database errors
891         */
892        public static boolean putConfiguration(ContentResolver cr, Configuration config) {
893            return Settings.System.putFloat(cr, FONT_SCALE, config.fontScale);
894        }
895
896        public static boolean getShowGTalkServiceStatus(ContentResolver cr) {
897            return getInt(cr, SHOW_GTALK_SERVICE_STATUS, 0) != 0;
898        }
899
900        public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
901            putInt(cr, SHOW_GTALK_SERVICE_STATUS, flag ? 1 : 0);
902        }
903
904        /**
905         * The content:// style URL for this table
906         */
907        public static final Uri CONTENT_URI =
908            Uri.parse("content://" + AUTHORITY + "/system");
909
910        /**
911         * Whether we keep the device on while the device is plugged in.
912         * Supported values are:
913         * <ul>
914         * <li>{@code 0} to never stay on while plugged in</li>
915         * <li>{@link BatteryManager#BATTERY_PLUGGED_AC} to stay on for AC charger</li>
916         * <li>{@link BatteryManager#BATTERY_PLUGGED_USB} to stay on for USB charger</li>
917         * </ul>
918         * These values can be OR-ed together.
919         */
920        public static final String STAY_ON_WHILE_PLUGGED_IN = "stay_on_while_plugged_in";
921
922        /**
923         * What happens when the user presses the end call button if they're not
924         * on a call.<br/>
925         * <b>Values:</b><br/>
926         * 0 - The end button does nothing.<br/>
927         * 1 - The end button goes to the home screen.<br/>
928         * 2 - The end button puts the device to sleep and locks the keyguard.<br/>
929         * 3 - The end button goes to the home screen.  If the user is already on the
930         * home screen, it puts the device to sleep.
931         */
932        public static final String END_BUTTON_BEHAVIOR = "end_button_behavior";
933
934        /**
935         * Whether Airplane Mode is on.
936         */
937        public static final String AIRPLANE_MODE_ON = "airplane_mode_on";
938
939        /**
940         * Constant for use in AIRPLANE_MODE_RADIOS to specify Bluetooth radio.
941         */
942        public static final String RADIO_BLUETOOTH = "bluetooth";
943
944        /**
945         * Constant for use in AIRPLANE_MODE_RADIOS to specify Wi-Fi radio.
946         */
947        public static final String RADIO_WIFI = "wifi";
948
949        /**
950         * Constant for use in AIRPLANE_MODE_RADIOS to specify Cellular radio.
951         */
952        public static final String RADIO_CELL = "cell";
953
954        /**
955         * A comma separated list of radios that need to be disabled when airplane mode
956         * is on. This overrides WIFI_ON and BLUETOOTH_ON, if Wi-Fi and bluetooth are
957         * included in the comma separated list.
958         */
959        public static final String AIRPLANE_MODE_RADIOS = "airplane_mode_radios";
960
961        /**
962         * A comma separated list of radios that should to be disabled when airplane mode
963         * is on, but can be manually reenabled by the user.  For example, if RADIO_WIFI is
964         * added to both AIRPLANE_MODE_RADIOS and AIRPLANE_MODE_TOGGLEABLE_RADIOS, then Wifi
965         * will be turned off when entering airplane mode, but the user will be able to reenable
966         * Wifi in the Settings app.
967         *
968         * {@hide}
969         */
970        public static final String AIRPLANE_MODE_TOGGLEABLE_RADIOS = "airplane_mode_toggleable_radios";
971
972        /**
973         * The policy for deciding when Wi-Fi should go to sleep (which will in
974         * turn switch to using the mobile data as an Internet connection).
975         * <p>
976         * Set to one of {@link #WIFI_SLEEP_POLICY_DEFAULT},
977         * {@link #WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED}, or
978         * {@link #WIFI_SLEEP_POLICY_NEVER}.
979         */
980        public static final String WIFI_SLEEP_POLICY = "wifi_sleep_policy";
981
982        /**
983         * Value for {@link #WIFI_SLEEP_POLICY} to use the default Wi-Fi sleep
984         * policy, which is to sleep shortly after the turning off
985         * according to the {@link #STAY_ON_WHILE_PLUGGED_IN} setting.
986         */
987        public static final int WIFI_SLEEP_POLICY_DEFAULT = 0;
988
989        /**
990         * Value for {@link #WIFI_SLEEP_POLICY} to use the default policy when
991         * the device is on battery, and never go to sleep when the device is
992         * plugged in.
993         */
994        public static final int WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED = 1;
995
996        /**
997         * Value for {@link #WIFI_SLEEP_POLICY} to never go to sleep.
998         */
999        public static final int WIFI_SLEEP_POLICY_NEVER = 2;
1000
1001        /**
1002         * Whether to use static IP and other static network attributes.
1003         * <p>
1004         * Set to 1 for true and 0 for false.
1005         */
1006        public static final String WIFI_USE_STATIC_IP = "wifi_use_static_ip";
1007
1008        /**
1009         * The static IP address.
1010         * <p>
1011         * Example: "192.168.1.51"
1012         */
1013        public static final String WIFI_STATIC_IP = "wifi_static_ip";
1014
1015        /**
1016         * If using static IP, the gateway's IP address.
1017         * <p>
1018         * Example: "192.168.1.1"
1019         */
1020        public static final String WIFI_STATIC_GATEWAY = "wifi_static_gateway";
1021
1022        /**
1023         * If using static IP, the net mask.
1024         * <p>
1025         * Example: "255.255.255.0"
1026         */
1027        public static final String WIFI_STATIC_NETMASK = "wifi_static_netmask";
1028
1029        /**
1030         * If using static IP, the primary DNS's IP address.
1031         * <p>
1032         * Example: "192.168.1.1"
1033         */
1034        public static final String WIFI_STATIC_DNS1 = "wifi_static_dns1";
1035
1036        /**
1037         * If using static IP, the secondary DNS's IP address.
1038         * <p>
1039         * Example: "192.168.1.2"
1040         */
1041        public static final String WIFI_STATIC_DNS2 = "wifi_static_dns2";
1042
1043        /**
1044         * The number of radio channels that are allowed in the local
1045         * 802.11 regulatory domain.
1046         * @hide
1047         */
1048        public static final String WIFI_NUM_ALLOWED_CHANNELS = "wifi_num_allowed_channels";
1049
1050        /**
1051         * Determines whether remote devices may discover and/or connect to
1052         * this device.
1053         * <P>Type: INT</P>
1054         * 2 -- discoverable and connectable
1055         * 1 -- connectable but not discoverable
1056         * 0 -- neither connectable nor discoverable
1057         */
1058        public static final String BLUETOOTH_DISCOVERABILITY =
1059            "bluetooth_discoverability";
1060
1061        /**
1062         * Bluetooth discoverability timeout.  If this value is nonzero, then
1063         * Bluetooth becomes discoverable for a certain number of seconds,
1064         * after which is becomes simply connectable.  The value is in seconds.
1065         */
1066        public static final String BLUETOOTH_DISCOVERABILITY_TIMEOUT =
1067            "bluetooth_discoverability_timeout";
1068
1069        /**
1070         * Whether autolock is enabled (0 = false, 1 = true)
1071         */
1072        public static final String LOCK_PATTERN_ENABLED = "lock_pattern_autolock";
1073
1074        /**
1075         * Whether lock pattern is visible as user enters (0 = false, 1 = true)
1076         */
1077        public static final String LOCK_PATTERN_VISIBLE = "lock_pattern_visible_pattern";
1078
1079        /**
1080         * Whether lock pattern will vibrate as user enters (0 = false, 1 = true)
1081         */
1082        public static final String LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED =
1083            "lock_pattern_tactile_feedback_enabled";
1084
1085
1086        /**
1087         * A formatted string of the next alarm that is set, or the empty string
1088         * if there is no alarm set.
1089         */
1090        public static final String NEXT_ALARM_FORMATTED = "next_alarm_formatted";
1091
1092        /**
1093         * Scaling factor for fonts, float.
1094         */
1095        public static final String FONT_SCALE = "font_scale";
1096
1097        /**
1098         * Name of an application package to be debugged.
1099         */
1100        public static final String DEBUG_APP = "debug_app";
1101
1102        /**
1103         * If 1, when launching DEBUG_APP it will wait for the debugger before
1104         * starting user code.  If 0, it will run normally.
1105         */
1106        public static final String WAIT_FOR_DEBUGGER = "wait_for_debugger";
1107
1108        /**
1109         * Whether or not to dim the screen. 0=no  1=yes
1110         */
1111        public static final String DIM_SCREEN = "dim_screen";
1112
1113        /**
1114         * The timeout before the screen turns off.
1115         */
1116        public static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout";
1117
1118        /**
1119         * If 0, the compatibility mode is off for all applications.
1120         * If 1, older applications run under compatibility mode.
1121         * TODO: remove this settings before code freeze (bug/1907571)
1122         * @hide
1123         */
1124        public static final String COMPATIBILITY_MODE = "compatibility_mode";
1125
1126        /**
1127         * The screen backlight brightness between 0 and 255.
1128         */
1129        public static final String SCREEN_BRIGHTNESS = "screen_brightness";
1130
1131        /**
1132         * Control whether to enable automatic brightness mode.
1133         * @hide
1134         */
1135        public static final String SCREEN_BRIGHTNESS_MODE = "screen_brightness_mode";
1136
1137        /**
1138         * SCREEN_BRIGHTNESS_MODE value for manual mode.
1139         * @hide
1140         */
1141        public static final int SCREEN_BRIGHTNESS_MODE_MANUAL = 0;
1142
1143        /**
1144         * SCREEN_BRIGHTNESS_MODE value for manual mode.
1145         * @hide
1146         */
1147        public static final int SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1;
1148
1149        /**
1150         * Control whether the process CPU usage meter should be shown.
1151         */
1152        public static final String SHOW_PROCESSES = "show_processes";
1153
1154        /**
1155         * If 1, the activity manager will aggressively finish activities and
1156         * processes as soon as they are no longer needed.  If 0, the normal
1157         * extended lifetime is used.
1158         */
1159        public static final String ALWAYS_FINISH_ACTIVITIES =
1160                "always_finish_activities";
1161
1162
1163        /**
1164         * Ringer mode. This is used internally, changing this value will not
1165         * change the ringer mode. See AudioManager.
1166         */
1167        public static final String MODE_RINGER = "mode_ringer";
1168
1169        /**
1170         * Determines which streams are affected by ringer mode changes. The
1171         * stream type's bit should be set to 1 if it should be muted when going
1172         * into an inaudible ringer mode.
1173         */
1174        public static final String MODE_RINGER_STREAMS_AFFECTED = "mode_ringer_streams_affected";
1175
1176         /**
1177          * Determines which streams are affected by mute. The
1178          * stream type's bit should be set to 1 if it should be muted when a mute request
1179          * is received.
1180          */
1181         public static final String MUTE_STREAMS_AFFECTED = "mute_streams_affected";
1182
1183        /**
1184         * Whether vibrate is on for different events. This is used internally,
1185         * changing this value will not change the vibrate. See AudioManager.
1186         */
1187        public static final String VIBRATE_ON = "vibrate_on";
1188
1189        /**
1190         * Ringer volume. This is used internally, changing this value will not
1191         * change the volume. See AudioManager.
1192         */
1193        public static final String VOLUME_RING = "volume_ring";
1194
1195        /**
1196         * System/notifications volume. This is used internally, changing this
1197         * value will not change the volume. See AudioManager.
1198         */
1199        public static final String VOLUME_SYSTEM = "volume_system";
1200
1201        /**
1202         * Voice call volume. This is used internally, changing this value will
1203         * not change the volume. See AudioManager.
1204         */
1205        public static final String VOLUME_VOICE = "volume_voice";
1206
1207        /**
1208         * Music/media/gaming volume. This is used internally, changing this
1209         * value will not change the volume. See AudioManager.
1210         */
1211        public static final String VOLUME_MUSIC = "volume_music";
1212
1213        /**
1214         * Alarm volume. This is used internally, changing this
1215         * value will not change the volume. See AudioManager.
1216         */
1217        public static final String VOLUME_ALARM = "volume_alarm";
1218
1219        /**
1220         * Notification volume. This is used internally, changing this
1221         * value will not change the volume. See AudioManager.
1222         */
1223        public static final String VOLUME_NOTIFICATION = "volume_notification";
1224
1225        /**
1226         * Bluetooth Headset volume. This is used internally, changing this value will
1227         * not change the volume. See AudioManager.
1228         */
1229        public static final String VOLUME_BLUETOOTH_SCO = "volume_bluetooth_sco";
1230
1231        /**
1232         * Whether the notifications should use the ring volume (value of 1) or
1233         * a separate notification volume (value of 0). In most cases, users
1234         * will have this enabled so the notification and ringer volumes will be
1235         * the same. However, power users can disable this and use the separate
1236         * notification volume control.
1237         * <p>
1238         * Note: This is a one-off setting that will be removed in the future
1239         * when there is profile support. For this reason, it is kept hidden
1240         * from the public APIs.
1241         *
1242         * @hide
1243         */
1244        public static final String NOTIFICATIONS_USE_RING_VOLUME =
1245            "notifications_use_ring_volume";
1246
1247        /**
1248         * The mapping of stream type (integer) to its setting.
1249         */
1250        public static final String[] VOLUME_SETTINGS = {
1251            VOLUME_VOICE, VOLUME_SYSTEM, VOLUME_RING, VOLUME_MUSIC,
1252            VOLUME_ALARM, VOLUME_NOTIFICATION, VOLUME_BLUETOOTH_SCO
1253        };
1254
1255        /**
1256         * Appended to various volume related settings to record the previous
1257         * values before they the settings were affected by a silent/vibrate
1258         * ringer mode change.
1259         */
1260        public static final String APPEND_FOR_LAST_AUDIBLE = "_last_audible";
1261
1262        /**
1263         * Persistent store for the system-wide default ringtone URI.
1264         * <p>
1265         * If you need to play the default ringtone at any given time, it is recommended
1266         * you give {@link #DEFAULT_RINGTONE_URI} to the media player.  It will resolve
1267         * to the set default ringtone at the time of playing.
1268         *
1269         * @see #DEFAULT_RINGTONE_URI
1270         */
1271        public static final String RINGTONE = "ringtone";
1272
1273        /**
1274         * A {@link Uri} that will point to the current default ringtone at any
1275         * given time.
1276         * <p>
1277         * If the current default ringtone is in the DRM provider and the caller
1278         * does not have permission, the exception will be a
1279         * FileNotFoundException.
1280         */
1281        public static final Uri DEFAULT_RINGTONE_URI = getUriFor(RINGTONE);
1282
1283        /**
1284         * Persistent store for the system-wide default notification sound.
1285         *
1286         * @see #RINGTONE
1287         * @see #DEFAULT_NOTIFICATION_URI
1288         */
1289        public static final String NOTIFICATION_SOUND = "notification_sound";
1290
1291        /**
1292         * A {@link Uri} that will point to the current default notification
1293         * sound at any given time.
1294         *
1295         * @see #DEFAULT_RINGTONE_URI
1296         */
1297        public static final Uri DEFAULT_NOTIFICATION_URI = getUriFor(NOTIFICATION_SOUND);
1298
1299        /**
1300         * Persistent store for the system-wide default alarm alert.
1301         *
1302         * @see #RINGTONE
1303         * @see #DEFAULT_ALARM_ALERT_URI
1304         */
1305        public static final String ALARM_ALERT = "alarm_alert";
1306
1307        /**
1308         * A {@link Uri} that will point to the current default alarm alert at
1309         * any given time.
1310         *
1311         * @see #DEFAULT_ALARM_ALERT_URI
1312         */
1313        public static final Uri DEFAULT_ALARM_ALERT_URI = getUriFor(ALARM_ALERT);
1314
1315        /**
1316         * Setting to enable Auto Replace (AutoText) in text editors. 1 = On, 0 = Off
1317         */
1318        public static final String TEXT_AUTO_REPLACE = "auto_replace";
1319
1320        /**
1321         * Setting to enable Auto Caps in text editors. 1 = On, 0 = Off
1322         */
1323        public static final String TEXT_AUTO_CAPS = "auto_caps";
1324
1325        /**
1326         * Setting to enable Auto Punctuate in text editors. 1 = On, 0 = Off. This
1327         * feature converts two spaces to a "." and space.
1328         */
1329        public static final String TEXT_AUTO_PUNCTUATE = "auto_punctuate";
1330
1331        /**
1332         * Setting to showing password characters in text editors. 1 = On, 0 = Off
1333         */
1334        public static final String TEXT_SHOW_PASSWORD = "show_password";
1335
1336        public static final String SHOW_GTALK_SERVICE_STATUS =
1337                "SHOW_GTALK_SERVICE_STATUS";
1338
1339        /**
1340         * Name of activity to use for wallpaper on the home screen.
1341         */
1342        public static final String WALLPAPER_ACTIVITY = "wallpaper_activity";
1343
1344        /**
1345         * Value to specify if the user prefers the date, time and time zone
1346         * to be automatically fetched from the network (NITZ). 1=yes, 0=no
1347         */
1348        public static final String AUTO_TIME = "auto_time";
1349
1350        /**
1351         * Display times as 12 or 24 hours
1352         *   12
1353         *   24
1354         */
1355        public static final String TIME_12_24 = "time_12_24";
1356
1357        /**
1358         * Date format string
1359         *   mm/dd/yyyy
1360         *   dd/mm/yyyy
1361         *   yyyy/mm/dd
1362         */
1363        public static final String DATE_FORMAT = "date_format";
1364
1365        /**
1366         * Whether the setup wizard has been run before (on first boot), or if
1367         * it still needs to be run.
1368         *
1369         * nonzero = it has been run in the past
1370         * 0 = it has not been run in the past
1371         */
1372        public static final String SETUP_WIZARD_HAS_RUN = "setup_wizard_has_run";
1373
1374        /**
1375         * Scaling factor for normal window animations. Setting to 0 will disable window
1376         * animations.
1377         */
1378        public static final String WINDOW_ANIMATION_SCALE = "window_animation_scale";
1379
1380        /**
1381         * Scaling factor for activity transition animations. Setting to 0 will disable window
1382         * animations.
1383         */
1384        public static final String TRANSITION_ANIMATION_SCALE = "transition_animation_scale";
1385
1386        /**
1387         * Scaling factor for normal window animations. Setting to 0 will disable window
1388         * animations.
1389         * @hide
1390         */
1391        public static final String FANCY_IME_ANIMATIONS = "fancy_ime_animations";
1392
1393        /**
1394         * Control whether the accelerometer will be used to change screen
1395         * orientation.  If 0, it will not be used unless explicitly requested
1396         * by the application; if 1, it will be used by default unless explicitly
1397         * disabled by the application.
1398         */
1399        public static final String ACCELEROMETER_ROTATION = "accelerometer_rotation";
1400
1401        /**
1402         * Whether the audible DTMF tones are played by the dialer when dialing. The value is
1403         * boolean (1 or 0).
1404         */
1405        public static final String DTMF_TONE_WHEN_DIALING = "dtmf_tone";
1406
1407        /**
1408         * CDMA only settings
1409         * DTMF tone type played by the dialer when dialing.
1410         *                 0 = Normal
1411         *                 1 = Long
1412         * @hide
1413         */
1414        public static final String DTMF_TONE_TYPE_WHEN_DIALING = "dtmf_tone_type";
1415
1416        /**
1417         * CDMA only settings
1418         * Emergency Tone  0 = Off
1419         *                 1 = Alert
1420         *                 2 = Vibrate
1421         * @hide
1422         */
1423        public static final String EMERGENCY_TONE = "emergency_tone";
1424
1425        /**
1426         * CDMA only settings
1427         * Whether the auto retry is enabled. The value is
1428         * boolean (1 or 0).
1429         * @hide
1430         */
1431        public static final String CALL_AUTO_RETRY = "call_auto_retry";
1432
1433        /**
1434         * Whether the hearing aid is enabled. The value is
1435         * boolean (1 or 0).
1436         * @hide
1437         */
1438        public static final String HEARING_AID = "hearing_aid";
1439
1440        /**
1441         * CDMA only settings
1442         * TTY Mode
1443         * 0 = OFF
1444         * 1 = FULL
1445         * 2 = VCO
1446         * 3 = HCO
1447         * @hide
1448         */
1449        public static final String TTY_MODE = "tty_mode";
1450
1451        /**
1452         * Whether the sounds effects (key clicks, lid open ...) are enabled. The value is
1453         * boolean (1 or 0).
1454         */
1455        public static final String SOUND_EFFECTS_ENABLED = "sound_effects_enabled";
1456
1457        /**
1458         * Whether the haptic feedback (long presses, ...) are enabled. The value is
1459         * boolean (1 or 0).
1460         */
1461        public static final String HAPTIC_FEEDBACK_ENABLED = "haptic_feedback_enabled";
1462
1463        /**
1464         * Whether live web suggestions while the user types into search dialogs are
1465         * enabled. Browsers and other search UIs should respect this, as it allows
1466         * a user to avoid sending partial queries to a search engine, if it poses
1467         * any privacy concern. The value is boolean (1 or 0).
1468         */
1469        public static final String SHOW_WEB_SUGGESTIONS = "show_web_suggestions";
1470
1471        /**
1472         * Whether the notification LED should repeatedly flash when a notification is
1473         * pending. The value is boolean (1 or 0).
1474         * @hide
1475         */
1476        public static final String NOTIFICATION_LIGHT_PULSE = "notification_light_pulse";
1477
1478        /**
1479         * Settings to backup. This is here so that it's in the same place as the settings
1480         * keys and easy to update.
1481         * @hide
1482         */
1483        public static final String[] SETTINGS_TO_BACKUP = {
1484            STAY_ON_WHILE_PLUGGED_IN,
1485            WIFI_SLEEP_POLICY,
1486            WIFI_USE_STATIC_IP,
1487            WIFI_STATIC_IP,
1488            WIFI_STATIC_GATEWAY,
1489            WIFI_STATIC_NETMASK,
1490            WIFI_STATIC_DNS1,
1491            WIFI_STATIC_DNS2,
1492            BLUETOOTH_DISCOVERABILITY,
1493            BLUETOOTH_DISCOVERABILITY_TIMEOUT,
1494            DIM_SCREEN,
1495            SCREEN_OFF_TIMEOUT,
1496            SCREEN_BRIGHTNESS,
1497            SCREEN_BRIGHTNESS_MODE,
1498            VIBRATE_ON,
1499            NOTIFICATIONS_USE_RING_VOLUME,
1500            MODE_RINGER,
1501            MODE_RINGER_STREAMS_AFFECTED,
1502            MUTE_STREAMS_AFFECTED,
1503            VOLUME_VOICE,
1504            VOLUME_SYSTEM,
1505            VOLUME_RING,
1506            VOLUME_MUSIC,
1507            VOLUME_ALARM,
1508            VOLUME_NOTIFICATION,
1509            VOLUME_BLUETOOTH_SCO,
1510            VOLUME_VOICE + APPEND_FOR_LAST_AUDIBLE,
1511            VOLUME_SYSTEM + APPEND_FOR_LAST_AUDIBLE,
1512            VOLUME_RING + APPEND_FOR_LAST_AUDIBLE,
1513            VOLUME_MUSIC + APPEND_FOR_LAST_AUDIBLE,
1514            VOLUME_ALARM + APPEND_FOR_LAST_AUDIBLE,
1515            VOLUME_NOTIFICATION + APPEND_FOR_LAST_AUDIBLE,
1516            VOLUME_BLUETOOTH_SCO + APPEND_FOR_LAST_AUDIBLE,
1517            TEXT_AUTO_REPLACE,
1518            TEXT_AUTO_CAPS,
1519            TEXT_AUTO_PUNCTUATE,
1520            TEXT_SHOW_PASSWORD,
1521            AUTO_TIME,
1522            TIME_12_24,
1523            DATE_FORMAT,
1524            ACCELEROMETER_ROTATION,
1525            DTMF_TONE_WHEN_DIALING,
1526            DTMF_TONE_TYPE_WHEN_DIALING,
1527            EMERGENCY_TONE,
1528            CALL_AUTO_RETRY,
1529            HEARING_AID,
1530            TTY_MODE,
1531            SOUND_EFFECTS_ENABLED,
1532            HAPTIC_FEEDBACK_ENABLED,
1533            SHOW_WEB_SUGGESTIONS,
1534            NOTIFICATION_LIGHT_PULSE
1535        };
1536
1537        // Settings moved to Settings.Secure
1538
1539        /**
1540         * @deprecated Use {@link android.provider.Settings.Secure#ADB_ENABLED}
1541         * instead
1542         */
1543        @Deprecated
1544        public static final String ADB_ENABLED = Secure.ADB_ENABLED;
1545
1546        /**
1547         * @deprecated Use {@link android.provider.Settings.Secure#ANDROID_ID} instead
1548         */
1549        @Deprecated
1550        public static final String ANDROID_ID = Secure.ANDROID_ID;
1551
1552        /**
1553         * @deprecated Use {@link android.provider.Settings.Secure#BLUETOOTH_ON} instead
1554         */
1555        @Deprecated
1556        public static final String BLUETOOTH_ON = Secure.BLUETOOTH_ON;
1557
1558        /**
1559         * @deprecated Use {@link android.provider.Settings.Secure#DATA_ROAMING} instead
1560         */
1561        @Deprecated
1562        public static final String DATA_ROAMING = Secure.DATA_ROAMING;
1563
1564        /**
1565         * @deprecated Use {@link android.provider.Settings.Secure#DEVICE_PROVISIONED} instead
1566         */
1567        @Deprecated
1568        public static final String DEVICE_PROVISIONED = Secure.DEVICE_PROVISIONED;
1569
1570        /**
1571         * @deprecated Use {@link android.provider.Settings.Secure#HTTP_PROXY} instead
1572         */
1573        @Deprecated
1574        public static final String HTTP_PROXY = Secure.HTTP_PROXY;
1575
1576        /**
1577         * @deprecated Use {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS} instead
1578         */
1579        @Deprecated
1580        public static final String INSTALL_NON_MARKET_APPS = Secure.INSTALL_NON_MARKET_APPS;
1581
1582        /**
1583         * @deprecated Use {@link android.provider.Settings.Secure#LOCATION_PROVIDERS_ALLOWED}
1584         * instead
1585         */
1586        @Deprecated
1587        public static final String LOCATION_PROVIDERS_ALLOWED = Secure.LOCATION_PROVIDERS_ALLOWED;
1588
1589        /**
1590         * @deprecated Use {@link android.provider.Settings.Secure#LOGGING_ID} instead
1591         */
1592        @Deprecated
1593        public static final String LOGGING_ID = Secure.LOGGING_ID;
1594
1595        /**
1596         * @deprecated Use {@link android.provider.Settings.Secure#NETWORK_PREFERENCE} instead
1597         */
1598        @Deprecated
1599        public static final String NETWORK_PREFERENCE = Secure.NETWORK_PREFERENCE;
1600
1601        /**
1602         * @deprecated Use {@link android.provider.Settings.Secure#PARENTAL_CONTROL_ENABLED}
1603         * instead
1604         */
1605        @Deprecated
1606        public static final String PARENTAL_CONTROL_ENABLED = Secure.PARENTAL_CONTROL_ENABLED;
1607
1608        /**
1609         * @deprecated Use {@link android.provider.Settings.Secure#PARENTAL_CONTROL_LAST_UPDATE}
1610         * instead
1611         */
1612        @Deprecated
1613        public static final String PARENTAL_CONTROL_LAST_UPDATE = Secure.PARENTAL_CONTROL_LAST_UPDATE;
1614
1615        /**
1616         * @deprecated Use {@link android.provider.Settings.Secure#PARENTAL_CONTROL_REDIRECT_URL}
1617         * instead
1618         */
1619        @Deprecated
1620        public static final String PARENTAL_CONTROL_REDIRECT_URL =
1621            Secure.PARENTAL_CONTROL_REDIRECT_URL;
1622
1623        /**
1624         * @deprecated Use {@link android.provider.Settings.Secure#SETTINGS_CLASSNAME} instead
1625         */
1626        @Deprecated
1627        public static final String SETTINGS_CLASSNAME = Secure.SETTINGS_CLASSNAME;
1628
1629        /**
1630         * @deprecated Use {@link android.provider.Settings.Secure#USB_MASS_STORAGE_ENABLED} instead
1631         */
1632        @Deprecated
1633        public static final String USB_MASS_STORAGE_ENABLED = Secure.USB_MASS_STORAGE_ENABLED;
1634
1635        /**
1636         * @deprecated Use {@link android.provider.Settings.Secure#USE_GOOGLE_MAIL} instead
1637         */
1638        @Deprecated
1639        public static final String USE_GOOGLE_MAIL = Secure.USE_GOOGLE_MAIL;
1640
1641       /**
1642         * @deprecated Use
1643         * {@link android.provider.Settings.Secure#WIFI_MAX_DHCP_RETRY_COUNT} instead
1644         */
1645        @Deprecated
1646        public static final String WIFI_MAX_DHCP_RETRY_COUNT = Secure.WIFI_MAX_DHCP_RETRY_COUNT;
1647
1648        /**
1649         * @deprecated Use
1650         * {@link android.provider.Settings.Secure#WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS} instead
1651         */
1652        @Deprecated
1653        public static final String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS =
1654                Secure.WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS;
1655
1656        /**
1657         * @deprecated Use
1658         * {@link android.provider.Settings.Secure#WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON} instead
1659         */
1660        @Deprecated
1661        public static final String WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON =
1662            Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON;
1663
1664        /**
1665         * @deprecated Use
1666         * {@link android.provider.Settings.Secure#WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY} instead
1667         */
1668        @Deprecated
1669        public static final String WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY =
1670            Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY;
1671
1672        /**
1673         * @deprecated Use {@link android.provider.Settings.Secure#WIFI_NUM_OPEN_NETWORKS_KEPT}
1674         * instead
1675         */
1676        @Deprecated
1677        public static final String WIFI_NUM_OPEN_NETWORKS_KEPT = Secure.WIFI_NUM_OPEN_NETWORKS_KEPT;
1678
1679        /**
1680         * @deprecated Use {@link android.provider.Settings.Secure#WIFI_ON} instead
1681         */
1682        @Deprecated
1683        public static final String WIFI_ON = Secure.WIFI_ON;
1684
1685        /**
1686         * @deprecated Use
1687         * {@link android.provider.Settings.Secure#WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE}
1688         * instead
1689         */
1690        @Deprecated
1691        public static final String WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE =
1692                Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE;
1693
1694        /**
1695         * @deprecated Use {@link android.provider.Settings.Secure#WIFI_WATCHDOG_AP_COUNT} instead
1696         */
1697        @Deprecated
1698        public static final String WIFI_WATCHDOG_AP_COUNT = Secure.WIFI_WATCHDOG_AP_COUNT;
1699
1700        /**
1701         * @deprecated Use
1702         * {@link android.provider.Settings.Secure#WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS} instead
1703         */
1704        @Deprecated
1705        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS =
1706                Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS;
1707
1708        /**
1709         * @deprecated Use
1710         * {@link android.provider.Settings.Secure#WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED} instead
1711         */
1712        @Deprecated
1713        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED =
1714                Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED;
1715
1716        /**
1717         * @deprecated Use
1718         * {@link android.provider.Settings.Secure#WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS}
1719         * instead
1720         */
1721        @Deprecated
1722        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS =
1723                Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS;
1724
1725        /**
1726         * @deprecated Use
1727         * {@link android.provider.Settings.Secure#WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT} instead
1728         */
1729        @Deprecated
1730        public static final String WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT =
1731            Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT;
1732
1733        /**
1734         * @deprecated Use {@link android.provider.Settings.Secure#WIFI_WATCHDOG_MAX_AP_CHECKS}
1735         * instead
1736         */
1737        @Deprecated
1738        public static final String WIFI_WATCHDOG_MAX_AP_CHECKS = Secure.WIFI_WATCHDOG_MAX_AP_CHECKS;
1739
1740        /**
1741         * @deprecated Use {@link android.provider.Settings.Secure#WIFI_WATCHDOG_ON} instead
1742         */
1743        @Deprecated
1744        public static final String WIFI_WATCHDOG_ON = Secure.WIFI_WATCHDOG_ON;
1745
1746        /**
1747         * @deprecated Use {@link android.provider.Settings.Secure#WIFI_WATCHDOG_PING_COUNT} instead
1748         */
1749        @Deprecated
1750        public static final String WIFI_WATCHDOG_PING_COUNT = Secure.WIFI_WATCHDOG_PING_COUNT;
1751
1752        /**
1753         * @deprecated Use {@link android.provider.Settings.Secure#WIFI_WATCHDOG_PING_DELAY_MS}
1754         * instead
1755         */
1756        @Deprecated
1757        public static final String WIFI_WATCHDOG_PING_DELAY_MS = Secure.WIFI_WATCHDOG_PING_DELAY_MS;
1758
1759        /**
1760         * @deprecated Use {@link android.provider.Settings.Secure#WIFI_WATCHDOG_PING_TIMEOUT_MS}
1761         * instead
1762         */
1763        @Deprecated
1764        public static final String WIFI_WATCHDOG_PING_TIMEOUT_MS =
1765            Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS;
1766    }
1767
1768    /**
1769     * Secure system settings, containing system preferences that applications
1770     * can read but are not allowed to write.  These are for preferences that
1771     * the user must explicitly modify through the system UI or specialized
1772     * APIs for those values, not modified directly by applications.
1773     */
1774    public static final class Secure extends NameValueTable {
1775        public static final String SYS_PROP_SETTING_VERSION = "sys.settings_secure_version";
1776
1777        private static volatile NameValueCache mNameValueCache = null;
1778
1779        /**
1780         * Look up a name in the database.
1781         * @param resolver to access the database with
1782         * @param name to look up in the table
1783         * @return the corresponding value, or null if not present
1784         */
1785        public synchronized static String getString(ContentResolver resolver, String name) {
1786            if (mNameValueCache == null) {
1787                mNameValueCache = new NameValueCache(SYS_PROP_SETTING_VERSION, CONTENT_URI);
1788            }
1789            return mNameValueCache.getString(resolver, name);
1790        }
1791
1792        /**
1793         * Store a name/value pair into the database.
1794         * @param resolver to access the database with
1795         * @param name to store
1796         * @param value to associate with the name
1797         * @return true if the value was set, false on database errors
1798         */
1799        public static boolean putString(ContentResolver resolver,
1800                String name, String value) {
1801            return putString(resolver, CONTENT_URI, name, value);
1802        }
1803
1804        /**
1805         * Construct the content URI for a particular name/value pair,
1806         * useful for monitoring changes with a ContentObserver.
1807         * @param name to look up in the table
1808         * @return the corresponding content URI, or null if not present
1809         */
1810        public static Uri getUriFor(String name) {
1811            return getUriFor(CONTENT_URI, name);
1812        }
1813
1814        /**
1815         * Convenience function for retrieving a single secure settings value
1816         * as an integer.  Note that internally setting values are always
1817         * stored as strings; this function converts the string to an integer
1818         * for you.  The default value will be returned if the setting is
1819         * not defined or not an integer.
1820         *
1821         * @param cr The ContentResolver to access.
1822         * @param name The name of the setting to retrieve.
1823         * @param def Value to return if the setting is not defined.
1824         *
1825         * @return The setting's current value, or 'def' if it is not defined
1826         * or not a valid integer.
1827         */
1828        public static int getInt(ContentResolver cr, String name, int def) {
1829            String v = getString(cr, name);
1830            try {
1831                return v != null ? Integer.parseInt(v) : def;
1832            } catch (NumberFormatException e) {
1833                return def;
1834            }
1835        }
1836
1837        /**
1838         * Convenience function for retrieving a single secure settings value
1839         * as an integer.  Note that internally setting values are always
1840         * stored as strings; this function converts the string to an integer
1841         * for you.
1842         * <p>
1843         * This version does not take a default value.  If the setting has not
1844         * been set, or the string value is not a number,
1845         * it throws {@link SettingNotFoundException}.
1846         *
1847         * @param cr The ContentResolver to access.
1848         * @param name The name of the setting to retrieve.
1849         *
1850         * @throws SettingNotFoundException Thrown if a setting by the given
1851         * name can't be found or the setting value is not an integer.
1852         *
1853         * @return The setting's current value.
1854         */
1855        public static int getInt(ContentResolver cr, String name)
1856                throws SettingNotFoundException {
1857            String v = getString(cr, name);
1858            try {
1859                return Integer.parseInt(v);
1860            } catch (NumberFormatException e) {
1861                throw new SettingNotFoundException(name);
1862            }
1863        }
1864
1865        /**
1866         * Convenience function for updating a single settings value as an
1867         * integer. This will either create a new entry in the table if the
1868         * given name does not exist, or modify the value of the existing row
1869         * with that name.  Note that internally setting values are always
1870         * stored as strings, so this function converts the given value to a
1871         * string before storing it.
1872         *
1873         * @param cr The ContentResolver to access.
1874         * @param name The name of the setting to modify.
1875         * @param value The new value for the setting.
1876         * @return true if the value was set, false on database errors
1877         */
1878        public static boolean putInt(ContentResolver cr, String name, int value) {
1879            return putString(cr, name, Integer.toString(value));
1880        }
1881
1882        /**
1883         * Convenience function for retrieving a single secure settings value
1884         * as a {@code long}.  Note that internally setting values are always
1885         * stored as strings; this function converts the string to a {@code long}
1886         * for you.  The default value will be returned if the setting is
1887         * not defined or not a {@code long}.
1888         *
1889         * @param cr The ContentResolver to access.
1890         * @param name The name of the setting to retrieve.
1891         * @param def Value to return if the setting is not defined.
1892         *
1893         * @return The setting's current value, or 'def' if it is not defined
1894         * or not a valid {@code long}.
1895         */
1896        public static long getLong(ContentResolver cr, String name, long def) {
1897            String valString = getString(cr, name);
1898            long value;
1899            try {
1900                value = valString != null ? Long.parseLong(valString) : def;
1901            } catch (NumberFormatException e) {
1902                value = def;
1903            }
1904            return value;
1905        }
1906
1907        /**
1908         * Convenience function for retrieving a single secure settings value
1909         * as a {@code long}.  Note that internally setting values are always
1910         * stored as strings; this function converts the string to a {@code long}
1911         * for you.
1912         * <p>
1913         * This version does not take a default value.  If the setting has not
1914         * been set, or the string value is not a number,
1915         * it throws {@link SettingNotFoundException}.
1916         *
1917         * @param cr The ContentResolver to access.
1918         * @param name The name of the setting to retrieve.
1919         *
1920         * @return The setting's current value.
1921         * @throws SettingNotFoundException Thrown if a setting by the given
1922         * name can't be found or the setting value is not an integer.
1923         */
1924        public static long getLong(ContentResolver cr, String name)
1925                throws SettingNotFoundException {
1926            String valString = getString(cr, name);
1927            try {
1928                return Long.parseLong(valString);
1929            } catch (NumberFormatException e) {
1930                throw new SettingNotFoundException(name);
1931            }
1932        }
1933
1934        /**
1935         * Convenience function for updating a secure settings value as a long
1936         * integer. This will either create a new entry in the table if the
1937         * given name does not exist, or modify the value of the existing row
1938         * with that name.  Note that internally setting values are always
1939         * stored as strings, so this function converts the given value to a
1940         * string before storing it.
1941         *
1942         * @param cr The ContentResolver to access.
1943         * @param name The name of the setting to modify.
1944         * @param value The new value for the setting.
1945         * @return true if the value was set, false on database errors
1946         */
1947        public static boolean putLong(ContentResolver cr, String name, long value) {
1948            return putString(cr, name, Long.toString(value));
1949        }
1950
1951        /**
1952         * Convenience function for retrieving a single secure settings value
1953         * as a floating point number.  Note that internally setting values are
1954         * always stored as strings; this function converts the string to an
1955         * float for you. The default value will be returned if the setting
1956         * is not defined or not a valid float.
1957         *
1958         * @param cr The ContentResolver to access.
1959         * @param name The name of the setting to retrieve.
1960         * @param def Value to return if the setting is not defined.
1961         *
1962         * @return The setting's current value, or 'def' if it is not defined
1963         * or not a valid float.
1964         */
1965        public static float getFloat(ContentResolver cr, String name, float def) {
1966            String v = getString(cr, name);
1967            try {
1968                return v != null ? Float.parseFloat(v) : def;
1969            } catch (NumberFormatException e) {
1970                return def;
1971            }
1972        }
1973
1974        /**
1975         * Convenience function for retrieving a single secure settings value
1976         * as a float.  Note that internally setting values are always
1977         * stored as strings; this function converts the string to a float
1978         * for you.
1979         * <p>
1980         * This version does not take a default value.  If the setting has not
1981         * been set, or the string value is not a number,
1982         * it throws {@link SettingNotFoundException}.
1983         *
1984         * @param cr The ContentResolver to access.
1985         * @param name The name of the setting to retrieve.
1986         *
1987         * @throws SettingNotFoundException Thrown if a setting by the given
1988         * name can't be found or the setting value is not a float.
1989         *
1990         * @return The setting's current value.
1991         */
1992        public static float getFloat(ContentResolver cr, String name)
1993                throws SettingNotFoundException {
1994            String v = getString(cr, name);
1995            try {
1996                return Float.parseFloat(v);
1997            } catch (NumberFormatException e) {
1998                throw new SettingNotFoundException(name);
1999            }
2000        }
2001
2002        /**
2003         * Convenience function for updating a single settings value as a
2004         * floating point number. This will either create a new entry in the
2005         * table if the given name does not exist, or modify the value of the
2006         * existing row with that name.  Note that internally setting values
2007         * are always stored as strings, so this function converts the given
2008         * value to a string before storing it.
2009         *
2010         * @param cr The ContentResolver to access.
2011         * @param name The name of the setting to modify.
2012         * @param value The new value for the setting.
2013         * @return true if the value was set, false on database errors
2014         */
2015        public static boolean putFloat(ContentResolver cr, String name, float value) {
2016            return putString(cr, name, Float.toString(value));
2017        }
2018
2019        /**
2020         * The content:// style URL for this table
2021         */
2022        public static final Uri CONTENT_URI =
2023            Uri.parse("content://" + AUTHORITY + "/secure");
2024
2025        /**
2026         * Whether ADB is enabled.
2027         */
2028        public static final String ADB_ENABLED = "adb_enabled";
2029
2030        /**
2031         * Setting to allow mock locations and location provider status to be injected into the
2032         * LocationManager service for testing purposes during application development.  These
2033         * locations and status values  override actual location and status information generated
2034         * by network, gps, or other location providers.
2035         */
2036        public static final String ALLOW_MOCK_LOCATION = "mock_location";
2037
2038        /**
2039         * The Android ID (a unique 64-bit value) as a hex string.
2040         * Identical to that obtained by calling
2041         * GoogleLoginService.getAndroidId(); it is also placed here
2042         * so you can get it without binding to a service.
2043         */
2044        public static final String ANDROID_ID = "android_id";
2045
2046        /**
2047         * Whether bluetooth is enabled/disabled
2048         * 0=disabled. 1=enabled.
2049         */
2050        public static final String BLUETOOTH_ON = "bluetooth_on";
2051
2052        /**
2053         * Get the key that retrieves a bluetooth headset's priority.
2054         * @hide
2055         */
2056        public static final String getBluetoothHeadsetPriorityKey(String address) {
2057            return ("bluetooth_headset_priority_" + address.toUpperCase());
2058        }
2059
2060        /**
2061         * Get the key that retrieves a bluetooth a2dp sink's priority.
2062         * @hide
2063         */
2064        public static final String getBluetoothA2dpSinkPriorityKey(String address) {
2065            return ("bluetooth_a2dp_sink_priority_" + address.toUpperCase());
2066        }
2067
2068        /**
2069         * Whether or not data roaming is enabled. (0 = false, 1 = true)
2070         */
2071        public static final String DATA_ROAMING = "data_roaming";
2072
2073        /**
2074         * Setting to record the input method used by default, holding the ID
2075         * of the desired method.
2076         */
2077        public static final String DEFAULT_INPUT_METHOD = "default_input_method";
2078
2079        /**
2080         * Whether the device has been provisioned (0 = false, 1 = true)
2081         */
2082        public static final String DEVICE_PROVISIONED = "device_provisioned";
2083
2084        /**
2085         * List of input methods that are currently enabled.  This is a string
2086         * containing the IDs of all enabled input methods, each ID separated
2087         * by ':'.
2088         */
2089        public static final String ENABLED_INPUT_METHODS = "enabled_input_methods";
2090
2091        /**
2092         * Host name and port for a user-selected proxy.
2093         */
2094        public static final String HTTP_PROXY = "http_proxy";
2095
2096        /**
2097         * Whether the package installer should allow installation of apps downloaded from
2098         * sources other than the Android Market (vending machine).
2099         *
2100         * 1 = allow installing from other sources
2101         * 0 = only allow installing from the Android Market
2102         */
2103        public static final String INSTALL_NON_MARKET_APPS = "install_non_market_apps";
2104
2105        /**
2106         * Comma-separated list of location providers that activities may access.
2107         */
2108        public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
2109
2110        /**
2111         * Whether assisted GPS should be enabled or not.
2112         * @hide
2113         */
2114        public static final String ASSISTED_GPS_ENABLED = "assisted_gps_enabled";
2115
2116        /**
2117         * The Logging ID (a unique 64-bit value) as a hex string.
2118         * Used as a pseudonymous identifier for logging.
2119         * @deprecated This identifier is poorly initialized and has
2120         * many collisions.  It should not be used.
2121         */
2122        @Deprecated
2123        public static final String LOGGING_ID = "logging_id";
2124
2125        /**
2126         * User preference for which network(s) should be used. Only the
2127         * connectivity service should touch this.
2128         */
2129        public static final String NETWORK_PREFERENCE = "network_preference";
2130
2131        /**
2132         */
2133        public static final String PARENTAL_CONTROL_ENABLED = "parental_control_enabled";
2134
2135        /**
2136         */
2137        public static final String PARENTAL_CONTROL_LAST_UPDATE = "parental_control_last_update";
2138
2139        /**
2140         */
2141        public static final String PARENTAL_CONTROL_REDIRECT_URL = "parental_control_redirect_url";
2142
2143        /**
2144         * Settings classname to launch when Settings is clicked from All
2145         * Applications.  Needed because of user testing between the old
2146         * and new Settings apps.
2147         */
2148        // TODO: 881807
2149        public static final String SETTINGS_CLASSNAME = "settings_classname";
2150
2151        /**
2152         * USB Mass Storage Enabled
2153         */
2154        public static final String USB_MASS_STORAGE_ENABLED = "usb_mass_storage_enabled";
2155
2156        /**
2157         * If this setting is set (to anything), then all references
2158         * to Gmail on the device must change to Google Mail.
2159         */
2160        public static final String USE_GOOGLE_MAIL = "use_google_mail";
2161
2162        /**
2163         * If accessibility is enabled.
2164         */
2165        public static final String ACCESSIBILITY_ENABLED = "accessibility_enabled";
2166
2167        /**
2168         * List of the enabled accessibility providers.
2169         */
2170        public static final String ENABLED_ACCESSIBILITY_SERVICES =
2171            "enabled_accessibility_services";
2172
2173        /**
2174         * Setting to always use the default text-to-speech settings regardless
2175         * of the application settings.
2176         * 1 = override application settings,
2177         * 0 = use application settings (if specified).
2178         */
2179        public static final String TTS_USE_DEFAULTS = "tts_use_defaults";
2180
2181        /**
2182         * Default text-to-speech engine speech rate. 100 = 1x
2183         */
2184        public static final String TTS_DEFAULT_RATE = "tts_default_rate";
2185
2186        /**
2187         * Default text-to-speech engine pitch. 100 = 1x
2188         */
2189        public static final String TTS_DEFAULT_PITCH = "tts_default_pitch";
2190
2191        /**
2192         * Default text-to-speech engine.
2193         */
2194        public static final String TTS_DEFAULT_SYNTH = "tts_default_synth";
2195
2196        /**
2197         * Default text-to-speech language.
2198         */
2199        public static final String TTS_DEFAULT_LANG = "tts_default_lang";
2200
2201        /**
2202         * Default text-to-speech country.
2203         */
2204        public static final String TTS_DEFAULT_COUNTRY = "tts_default_country";
2205
2206        /**
2207         * Default text-to-speech locale variant.
2208         */
2209        public static final String TTS_DEFAULT_VARIANT = "tts_default_variant";
2210
2211        /**
2212         * Whether to notify the user of open networks.
2213         * <p>
2214         * If not connected and the scan results have an open network, we will
2215         * put this notification up. If we attempt to connect to a network or
2216         * the open network(s) disappear, we remove the notification. When we
2217         * show the notification, we will not show it again for
2218         * {@link android.provider.Settings.Secure#WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY} time.
2219         */
2220        public static final String WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON =
2221                "wifi_networks_available_notification_on";
2222
2223        /**
2224         * Delay (in seconds) before repeating the Wi-Fi networks available notification.
2225         * Connecting to a network will reset the timer.
2226         */
2227        public static final String WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY =
2228                "wifi_networks_available_repeat_delay";
2229
2230        /**
2231         * The number of radio channels that are allowed in the local
2232         * 802.11 regulatory domain.
2233         * @hide
2234         */
2235        public static final String WIFI_NUM_ALLOWED_CHANNELS = "wifi_num_allowed_channels";
2236
2237        /**
2238         * When the number of open networks exceeds this number, the
2239         * least-recently-used excess networks will be removed.
2240         */
2241        public static final String WIFI_NUM_OPEN_NETWORKS_KEPT = "wifi_num_open_networks_kept";
2242
2243        /**
2244         * Whether the Wi-Fi should be on.  Only the Wi-Fi service should touch this.
2245         */
2246        public static final String WIFI_ON = "wifi_on";
2247
2248        /**
2249         * The acceptable packet loss percentage (range 0 - 100) before trying
2250         * another AP on the same network.
2251         */
2252        public static final String WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE =
2253                "wifi_watchdog_acceptable_packet_loss_percentage";
2254
2255        /**
2256         * The number of access points required for a network in order for the
2257         * watchdog to monitor it.
2258         */
2259        public static final String WIFI_WATCHDOG_AP_COUNT = "wifi_watchdog_ap_count";
2260
2261        /**
2262         * The delay between background checks.
2263         */
2264        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS =
2265                "wifi_watchdog_background_check_delay_ms";
2266
2267        /**
2268         * Whether the Wi-Fi watchdog is enabled for background checking even
2269         * after it thinks the user has connected to a good access point.
2270         */
2271        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED =
2272                "wifi_watchdog_background_check_enabled";
2273
2274        /**
2275         * The timeout for a background ping
2276         */
2277        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS =
2278                "wifi_watchdog_background_check_timeout_ms";
2279
2280        /**
2281         * The number of initial pings to perform that *may* be ignored if they
2282         * fail. Again, if these fail, they will *not* be used in packet loss
2283         * calculation. For example, one network always seemed to time out for
2284         * the first couple pings, so this is set to 3 by default.
2285         */
2286        public static final String WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT =
2287            "wifi_watchdog_initial_ignored_ping_count";
2288
2289        /**
2290         * The maximum number of access points (per network) to attempt to test.
2291         * If this number is reached, the watchdog will no longer monitor the
2292         * initial connection state for the network. This is a safeguard for
2293         * networks containing multiple APs whose DNS does not respond to pings.
2294         */
2295        public static final String WIFI_WATCHDOG_MAX_AP_CHECKS = "wifi_watchdog_max_ap_checks";
2296
2297        /**
2298         * Whether the Wi-Fi watchdog is enabled.
2299         */
2300        public static final String WIFI_WATCHDOG_ON = "wifi_watchdog_on";
2301
2302        /**
2303         * A comma-separated list of SSIDs for which the Wi-Fi watchdog should be enabled.
2304         */
2305        public static final String WIFI_WATCHDOG_WATCH_LIST = "wifi_watchdog_watch_list";
2306
2307        /**
2308         * The number of pings to test if an access point is a good connection.
2309         */
2310        public static final String WIFI_WATCHDOG_PING_COUNT = "wifi_watchdog_ping_count";
2311
2312        /**
2313         * The delay between pings.
2314         */
2315        public static final String WIFI_WATCHDOG_PING_DELAY_MS = "wifi_watchdog_ping_delay_ms";
2316
2317        /**
2318         * The timeout per ping.
2319         */
2320        public static final String WIFI_WATCHDOG_PING_TIMEOUT_MS = "wifi_watchdog_ping_timeout_ms";
2321
2322        /**
2323         * The maximum number of times we will retry a connection to an access
2324         * point for which we have failed in acquiring an IP address from DHCP.
2325         * A value of N means that we will make N+1 connection attempts in all.
2326         */
2327        public static final String WIFI_MAX_DHCP_RETRY_COUNT = "wifi_max_dhcp_retry_count";
2328
2329        /**
2330         * Maximum amount of time in milliseconds to hold a wakelock while waiting for mobile
2331         * data connectivity to be established after a disconnect from Wi-Fi.
2332         */
2333        public static final String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS =
2334            "wifi_mobile_data_transition_wakelock_timeout_ms";
2335
2336        /**
2337         * Whether background data usage is allowed by the user. See
2338         * ConnectivityManager for more info.
2339         */
2340        public static final String BACKGROUND_DATA = "background_data";
2341
2342        /**
2343         * The CDMA roaming mode 0 = Home Networks, CDMA default
2344         *                       1 = Roaming on Affiliated networks
2345         *                       2 = Roaming on any networks
2346         * @hide
2347         */
2348        public static final String CDMA_ROAMING_MODE = "roaming_settings";
2349
2350        /**
2351         * The CDMA subscription mode 0 = RUIM/SIM (default)
2352         *                                1 = NV
2353         * @hide
2354         */
2355        public static final String CDMA_SUBSCRIPTION_MODE = "subscription_mode";
2356
2357        /**
2358         * The preferred network mode   7 = Global
2359         *                              6 = EvDo only
2360         *                              5 = CDMA w/o EvDo
2361         *                              4 = CDMA / EvDo auto
2362         *                              3 = GSM / WCDMA auto
2363         *                              2 = WCDMA only
2364         *                              1 = GSM only
2365         *                              0 = GSM / WCDMA preferred
2366         * @hide
2367         */
2368        public static final String PREFERRED_NETWORK_MODE =
2369                "preferred_network_mode";
2370
2371        /**
2372         * The preferred TTY mode     0 = TTy Off, CDMA default
2373         *                            1 = TTY Full
2374         *                            2 = TTY HCO
2375         *                            3 = TTY VCO
2376         * @hide
2377         */
2378        public static final String PREFERRED_TTY_MODE =
2379                "preferred_tty_mode";
2380
2381
2382        /**
2383         * CDMA Cell Broadcast SMS
2384         *                            0 = CDMA Cell Broadcast SMS disabled
2385         *                            1 = CDMA Cell Broadcast SMS enabled
2386         * @hide
2387         */
2388        public static final String CDMA_CELL_BROADCAST_SMS =
2389                "cdma_cell_broadcast_sms";
2390
2391        /**
2392         * The cdma subscription 0 = Subscription from RUIM, when available
2393         *                       1 = Subscription from NV
2394         * @hide
2395         */
2396        public static final String PREFERRED_CDMA_SUBSCRIPTION =
2397                "preferred_cdma_subscription";
2398
2399        /**
2400         * Whether the enhanced voice privacy mode is enabled.
2401         * 0 = normal voice privacy
2402         * 1 = enhanced voice privacy
2403         * @hide
2404         */
2405        public static final String ENHANCED_VOICE_PRIVACY_ENABLED = "enhanced_voice_privacy_enabled";
2406
2407        /**
2408         * Whether the TTY mode mode is enabled.
2409         * 0 = disabled
2410         * 1 = enabled
2411         * @hide
2412         */
2413        public static final String TTY_MODE_ENABLED = "tty_mode_enabled";
2414
2415        /**
2416         * Flag for allowing service provider to use location information to improve products and
2417         * services.
2418         * Type: int ( 0 = disallow, 1 = allow )
2419         * @hide
2420         */
2421        public static final String USE_LOCATION_FOR_SERVICES = "use_location";
2422
2423        /**
2424         * Controls whether settings backup is enabled.
2425         * Type: int ( 0 = disabled, 1 = enabled )
2426         * @hide
2427         */
2428        public static final String BACKUP_ENABLED = "backup_enabled";
2429
2430        /**
2431         * Indicates whether settings backup has been fully provisioned.
2432         * Type: int ( 0 = unprovisioned, 1 = fully provisioned )
2433         * @hide
2434         */
2435        public static final String BACKUP_PROVISIONED = "backup_provisioned";
2436
2437        /**
2438         * Component of the transport to use for backup/restore.
2439         * @hide
2440         */
2441        public static final String BACKUP_TRANSPORT = "backup_transport";
2442
2443        /**
2444         * Version for which the setup wizard was last shown.  Bumped for
2445         * each release when there is new setup information to show.
2446         * @hide
2447         */
2448        public static final String LAST_SETUP_SHOWN = "last_setup_shown";
2449
2450        /**
2451         * How frequently (in seconds) to check the memory status of the
2452         * device.
2453         * @hide
2454         */
2455        public static final String MEMCHECK_INTERVAL = "memcheck_interval";
2456
2457        /**
2458         * Max frequency (in seconds) to log memory check stats, in realtime
2459         * seconds.  This allows for throttling of logs when the device is
2460         * running for large amounts of time.
2461         * @hide
2462         */
2463        public static final String MEMCHECK_LOG_REALTIME_INTERVAL =
2464                "memcheck_log_realtime_interval";
2465
2466        /**
2467         * Boolean indicating whether rebooting due to system memory checks
2468         * is enabled.
2469         * @hide
2470         */
2471        public static final String MEMCHECK_SYSTEM_ENABLED = "memcheck_system_enabled";
2472
2473        /**
2474         * How many bytes the system process must be below to avoid scheduling
2475         * a soft reboot.  This reboot will happen when it is next determined
2476         * to be a good time.
2477         * @hide
2478         */
2479        public static final String MEMCHECK_SYSTEM_SOFT_THRESHOLD = "memcheck_system_soft";
2480
2481        /**
2482         * How many bytes the system process must be below to avoid scheduling
2483         * a hard reboot.  This reboot will happen immediately.
2484         * @hide
2485         */
2486        public static final String MEMCHECK_SYSTEM_HARD_THRESHOLD = "memcheck_system_hard";
2487
2488        /**
2489         * How many bytes the phone process must be below to avoid scheduling
2490         * a soft restart.  This restart will happen when it is next determined
2491         * to be a good time.
2492         * @hide
2493         */
2494        public static final String MEMCHECK_PHONE_SOFT_THRESHOLD = "memcheck_phone_soft";
2495
2496        /**
2497         * How many bytes the phone process must be below to avoid scheduling
2498         * a hard restart.  This restart will happen immediately.
2499         * @hide
2500         */
2501        public static final String MEMCHECK_PHONE_HARD_THRESHOLD = "memcheck_phone_hard";
2502
2503        /**
2504         * Boolean indicating whether restarting the phone process due to
2505         * memory checks is enabled.
2506         * @hide
2507         */
2508        public static final String MEMCHECK_PHONE_ENABLED = "memcheck_phone_enabled";
2509
2510        /**
2511         * First time during the day it is okay to kill processes
2512         * or reboot the device due to low memory situations.  This number is
2513         * in seconds since midnight.
2514         * @hide
2515         */
2516        public static final String MEMCHECK_EXEC_START_TIME = "memcheck_exec_start_time";
2517
2518        /**
2519         * Last time during the day it is okay to kill processes
2520         * or reboot the device due to low memory situations.  This number is
2521         * in seconds since midnight.
2522         * @hide
2523         */
2524        public static final String MEMCHECK_EXEC_END_TIME = "memcheck_exec_end_time";
2525
2526        /**
2527         * How long the screen must have been off in order to kill processes
2528         * or reboot.  This number is in seconds.  A value of -1 means to
2529         * entirely disregard whether the screen is on.
2530         * @hide
2531         */
2532        public static final String MEMCHECK_MIN_SCREEN_OFF = "memcheck_min_screen_off";
2533
2534        /**
2535         * How much time there must be until the next alarm in order to kill processes
2536         * or reboot.  This number is in seconds.  Note: this value must be
2537         * smaller than {@link #MEMCHECK_RECHECK_INTERVAL} or else it will
2538         * always see an alarm scheduled within its time.
2539         * @hide
2540         */
2541        public static final String MEMCHECK_MIN_ALARM = "memcheck_min_alarm";
2542
2543        /**
2544         * How frequently to check whether it is a good time to restart things,
2545         * if the device is in a bad state.  This number is in seconds.  Note:
2546         * this value must be larger than {@link #MEMCHECK_MIN_ALARM} or else
2547         * the alarm to schedule the recheck will always appear within the
2548         * minimum "do not execute now" time.
2549         * @hide
2550         */
2551        public static final String MEMCHECK_RECHECK_INTERVAL = "memcheck_recheck_interval";
2552
2553        /**
2554         * How frequently (in DAYS) to reboot the device.  If 0, no reboots
2555         * will occur.
2556         * @hide
2557         */
2558        public static final String REBOOT_INTERVAL = "reboot_interval";
2559
2560        /**
2561         * First time during the day it is okay to force a reboot of the
2562         * device (if REBOOT_INTERVAL is set).  This number is
2563         * in seconds since midnight.
2564         * @hide
2565         */
2566        public static final String REBOOT_START_TIME = "reboot_start_time";
2567
2568        /**
2569         * The window of time (in seconds) after each REBOOT_INTERVAL in which
2570         * a reboot can be executed.  If 0, a reboot will always be executed at
2571         * exactly the given time.  Otherwise, it will only be executed if
2572         * the device is idle within the window.
2573         * @hide
2574         */
2575        public static final String REBOOT_WINDOW = "reboot_window";
2576
2577        /**
2578         * Threshold values for the duration and level of a discharge cycle, under
2579         * which we log discharge cycle info.
2580         * @hide
2581         */
2582        public static final String BATTERY_DISCHARGE_DURATION_THRESHOLD =
2583                "battery_discharge_duration_threshold";
2584        /** @hide */
2585        public static final String BATTERY_DISCHARGE_THRESHOLD = "battery_discharge_threshold";
2586
2587        /**
2588         * Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
2589         * on application crashes and ANRs. If this is disabled, the crash/ANR dialog
2590         * will never display the "Report" button.
2591         * Type: int ( 0 = disallow, 1 = allow )
2592         * @hide
2593         */
2594        public static final String SEND_ACTION_APP_ERROR = "send_action_app_error";
2595
2596        /**
2597         * Nonzero causes Log.wtf() to crash.
2598         * @hide
2599         */
2600        public static final String WTF_IS_FATAL = "wtf_is_fatal";
2601
2602        /**
2603         * Maximum age of entries kept by {@link android.os.IDropBox}.
2604         * @hide
2605         */
2606        public static final String DROPBOX_AGE_SECONDS =
2607                "dropbox_age_seconds";
2608        /**
2609         * Maximum amount of disk space used by {@link android.os.IDropBox} no matter what.
2610         * @hide
2611         */
2612        public static final String DROPBOX_QUOTA_KB =
2613                "dropbox_quota_kb";
2614        /**
2615         * Percent of free disk (excluding reserve) which {@link android.os.IDropBox} will use.
2616         * @hide
2617         */
2618        public static final String DROPBOX_QUOTA_PERCENT =
2619                "dropbox_quota_percent";
2620        /**
2621         * Percent of total disk which {@link android.os.IDropBox} will never dip into.
2622         * @hide
2623         */
2624        public static final String DROPBOX_RESERVE_PERCENT =
2625                "dropbox_reserve_percent";
2626        /**
2627         * Prefix for per-tag dropbox disable/enable settings.
2628         * @hide
2629         */
2630        public static final String DROPBOX_TAG_PREFIX =
2631                "dropbox:";
2632
2633
2634        /**
2635         * Screen timeout in milliseconds corresponding to the
2636         * PowerManager's POKE_LOCK_SHORT_TIMEOUT flag (i.e. the fastest
2637         * possible screen timeout behavior.)
2638         * @hide
2639         */
2640        public static final String SHORT_KEYLIGHT_DELAY_MS =
2641                "short_keylight_delay_ms";
2642
2643        /**
2644         * The interval in minutes after which the amount of free storage left on the
2645         * device is logged to the event log
2646         * @hide
2647         */
2648        public static final String SYS_FREE_STORAGE_LOG_INTERVAL =
2649                "sys_free_storage_log_interval";
2650
2651        /**
2652         * Threshold for the amount of change in disk free space required to report the amount of
2653         * free space. Used to prevent spamming the logs when the disk free space isn't changing
2654         * frequently.
2655         * @hide
2656         */
2657        public static final String DISK_FREE_CHANGE_REPORTING_THRESHOLD =
2658                "disk_free_change_reporting_threshold";
2659
2660
2661        /**
2662         * Minimum percentage of free storage on the device that is used to determine if
2663         * the device is running low on storage.
2664         * Say this value is set to 10, the device is considered running low on storage
2665         * if 90% or more of the device storage is filled up.
2666         * @hide
2667         */
2668        public static final String SYS_STORAGE_THRESHOLD_PERCENTAGE =
2669                "sys_storage_threshold_percentage";
2670
2671        /**
2672         * The interval in milliseconds after which Wi-Fi is considered idle.
2673         * When idle, it is possible for the device to be switched from Wi-Fi to
2674         * the mobile data network.
2675         * @hide
2676         */
2677        public static final String WIFI_IDLE_MS = "wifi_idle_ms";
2678
2679        /**
2680         * The interval in milliseconds at which to check packet counts on the
2681         * mobile data interface when screen is on, to detect possible data
2682         * connection problems.
2683         * @hide
2684         */
2685        public static final String PDP_WATCHDOG_POLL_INTERVAL_MS =
2686                "pdp_watchdog_poll_interval_ms";
2687
2688        /**
2689         * The interval in milliseconds at which to check packet counts on the
2690         * mobile data interface when screen is off, to detect possible data
2691         * connection problems.
2692         * @hide
2693         */
2694        public static final String PDP_WATCHDOG_LONG_POLL_INTERVAL_MS =
2695                "pdp_watchdog_long_poll_interval_ms";
2696
2697        /**
2698         * The interval in milliseconds at which to check packet counts on the
2699         * mobile data interface after {@link #PDP_WATCHDOG_TRIGGER_PACKET_COUNT}
2700         * outgoing packets has been reached without incoming packets.
2701         * @hide
2702         */
2703        public static final String PDP_WATCHDOG_ERROR_POLL_INTERVAL_MS =
2704                "pdp_watchdog_error_poll_interval_ms";
2705
2706        /**
2707         * The number of outgoing packets sent without seeing an incoming packet
2708         * that triggers a countdown (of {@link #PDP_WATCHDOG_ERROR_POLL_COUNT}
2709         * device is logged to the event log
2710         * @hide
2711         */
2712        public static final String PDP_WATCHDOG_TRIGGER_PACKET_COUNT =
2713                "pdp_watchdog_trigger_packet_count";
2714
2715        /**
2716         * The number of polls to perform (at {@link #PDP_WATCHDOG_ERROR_POLL_INTERVAL_MS})
2717         * after hitting {@link #PDP_WATCHDOG_TRIGGER_PACKET_COUNT} before
2718         * attempting data connection recovery.
2719         * @hide
2720         */
2721        public static final String PDP_WATCHDOG_ERROR_POLL_COUNT =
2722                "pdp_watchdog_error_poll_count";
2723
2724        /**
2725         * The number of failed PDP reset attempts before moving to something more
2726         * drastic: re-registering to the network.
2727         * @hide
2728         */
2729        public static final String PDP_WATCHDOG_MAX_PDP_RESET_FAIL_COUNT =
2730                "pdp_watchdog_max_pdp_reset_fail_count";
2731
2732        /**
2733         * Address to ping as a last sanity check before attempting any recovery.
2734         * Unset or set to "0.0.0.0" to skip this check.
2735         * @hide
2736         */
2737        public static final String PDP_WATCHDOG_PING_ADDRESS = "pdp_watchdog_ping_address";
2738
2739        /**
2740         * The "-w deadline" parameter for the ping, ie, the max time in
2741         * seconds to spend pinging.
2742         * @hide
2743         */
2744        public static final String PDP_WATCHDOG_PING_DEADLINE = "pdp_watchdog_ping_deadline";
2745
2746        /**
2747         * The interval in milliseconds at which to check gprs registration
2748         * after the first registration mismatch of gprs and voice service,
2749         * to detect possible data network registration problems.
2750         *
2751         * @hide
2752         */
2753        public static final String GPRS_REGISTER_CHECK_PERIOD_MS =
2754                "gprs_register_check_period_ms";
2755
2756        /**
2757         * The length of time in milli-seconds that automatic small adjustments to
2758         * SystemClock are ignored if NITZ_UPDATE_DIFF is not exceeded.
2759         * @hide
2760         */
2761        public static final String NITZ_UPDATE_SPACING = "nitz_update_spacing";
2762
2763        /**
2764         * If the NITZ_UPDATE_DIFF time is exceeded then an automatic adjustment
2765         * to SystemClock will be allowed even if NITZ_UPDATE_SPACING has not been
2766         * exceeded.
2767         * @hide
2768         */
2769        public static final String NITZ_UPDATE_DIFF = "nitz_update_diff";
2770
2771        /**
2772         * The maximum reconnect delay for short network outages or when the network is suspended
2773         * due to phone use.
2774         * @hide
2775         */
2776        public static final String SYNC_MAX_RETRY_DELAY_IN_SECONDS =
2777                "sync_max_retry_delay_in_seconds";
2778
2779        /**
2780         * The interval in milliseconds at which to check the number of SMS sent
2781         * out without asking for use permit, to limit the un-authorized SMS
2782         * usage.
2783         * @hide
2784         */
2785        public static final String SMS_OUTGOING_CHECK_INTERVAL_MS =
2786                "sms_outgoing_check_interval_ms";
2787
2788        /**
2789         * The number of outgoing SMS sent without asking for user permit
2790         * (of {@link #SMS_OUTGOING_CHECK_INTERVAL_MS}
2791         * @hide
2792         */
2793        public static final String SMS_OUTGOING_CHECK_MAX_COUNT =
2794                "sms_outgoing_check_max_count";
2795
2796        /**
2797         * Enable use of ssl session caching.
2798         * 'db' - save each session in a (per process) database
2799         * 'file' - save each session in a (per process) file
2800         * not set or any other value - normal java in-memory caching
2801         * @hide
2802         */
2803        public static final String SSL_SESSION_CACHE = "ssl_session_cache";
2804
2805        /**
2806         * How many bytes long a message has to be, in order to be gzipped.
2807         * @hide
2808         */
2809        public static final String SYNC_MIN_GZIP_BYTES =
2810                "sync_min_gzip_bytes";
2811
2812        /**
2813         * The number of promoted sources in GlobalSearch.
2814         * @hide
2815         */
2816        public static final String SEARCH_NUM_PROMOTED_SOURCES = "search_num_promoted_sources";
2817        /**
2818         * The maximum number of suggestions returned by GlobalSearch.
2819         * @hide
2820         */
2821        public static final String SEARCH_MAX_RESULTS_TO_DISPLAY = "search_max_results_to_display";
2822        /**
2823         * The number of suggestions GlobalSearch will ask each non-web search source for.
2824         * @hide
2825         */
2826        public static final String SEARCH_MAX_RESULTS_PER_SOURCE = "search_max_results_per_source";
2827        /**
2828         * The number of suggestions the GlobalSearch will ask the web search source for.
2829         * @hide
2830         */
2831        public static final String SEARCH_WEB_RESULTS_OVERRIDE_LIMIT =
2832                "search_web_results_override_limit";
2833        /**
2834         * The number of milliseconds that GlobalSearch will wait for suggestions from
2835         * promoted sources before continuing with all other sources.
2836         * @hide
2837         */
2838        public static final String SEARCH_PROMOTED_SOURCE_DEADLINE_MILLIS =
2839                "search_promoted_source_deadline_millis";
2840        /**
2841         * The number of milliseconds before GlobalSearch aborts search suggesiton queries.
2842         * @hide
2843         */
2844        public static final String SEARCH_SOURCE_TIMEOUT_MILLIS = "search_source_timeout_millis";
2845        /**
2846         * The maximum number of milliseconds that GlobalSearch shows the previous results
2847         * after receiving a new query.
2848         * @hide
2849         */
2850        public static final String SEARCH_PREFILL_MILLIS = "search_prefill_millis";
2851        /**
2852         * The maximum age of log data used for shortcuts in GlobalSearch.
2853         * @hide
2854         */
2855        public static final String SEARCH_MAX_STAT_AGE_MILLIS = "search_max_stat_age_millis";
2856        /**
2857         * The maximum age of log data used for source ranking in GlobalSearch.
2858         * @hide
2859         */
2860        public static final String SEARCH_MAX_SOURCE_EVENT_AGE_MILLIS =
2861                "search_max_source_event_age_millis";
2862        /**
2863         * The minimum number of impressions needed to rank a source in GlobalSearch.
2864         * @hide
2865         */
2866        public static final String SEARCH_MIN_IMPRESSIONS_FOR_SOURCE_RANKING =
2867                "search_min_impressions_for_source_ranking";
2868        /**
2869         * The minimum number of clicks needed to rank a source in GlobalSearch.
2870         * @hide
2871         */
2872        public static final String SEARCH_MIN_CLICKS_FOR_SOURCE_RANKING =
2873                "search_min_clicks_for_source_ranking";
2874        /**
2875         * The maximum number of shortcuts shown by GlobalSearch.
2876         * @hide
2877         */
2878        public static final String SEARCH_MAX_SHORTCUTS_RETURNED = "search_max_shortcuts_returned";
2879        /**
2880         * The size of the core thread pool for suggestion queries in GlobalSearch.
2881         * @hide
2882         */
2883        public static final String SEARCH_QUERY_THREAD_CORE_POOL_SIZE =
2884                "search_query_thread_core_pool_size";
2885        /**
2886         * The maximum size of the thread pool for suggestion queries in GlobalSearch.
2887         * @hide
2888         */
2889        public static final String SEARCH_QUERY_THREAD_MAX_POOL_SIZE =
2890                "search_query_thread_max_pool_size";
2891        /**
2892         * The size of the core thread pool for shortcut refreshing in GlobalSearch.
2893         * @hide
2894         */
2895        public static final String SEARCH_SHORTCUT_REFRESH_CORE_POOL_SIZE =
2896                "search_shortcut_refresh_core_pool_size";
2897        /**
2898         * The maximum size of the thread pool for shortcut refreshing in GlobalSearch.
2899         * @hide
2900         */
2901        public static final String SEARCH_SHORTCUT_REFRESH_MAX_POOL_SIZE =
2902                "search_shortcut_refresh_max_pool_size";
2903        /**
2904         * The maximun time that excess threads in the GlobalSeach thread pools will
2905         * wait before terminating.
2906         * @hide
2907         */
2908        public static final String SEARCH_THREAD_KEEPALIVE_SECONDS =
2909                "search_thread_keepalive_seconds";
2910        /**
2911         * The maximum number of concurrent suggestion queries to each source.
2912         * @hide
2913         */
2914        public static final String SEARCH_PER_SOURCE_CONCURRENT_QUERY_LIMIT =
2915                "search_per_source_concurrent_query_limit";
2916
2917        /**
2918         * Whether or not alert sounds are played on MountService events. (0 = false, 1 = true)
2919         * @hide
2920         */
2921        public static final String MOUNT_PLAY_NOTIFICATION_SND = "mount_play_not_snd";
2922
2923        /**
2924         * Whether or not UMS auto-starts on UMS host detection. (0 = false, 1 = true)
2925         * @hide
2926         */
2927        public static final String MOUNT_UMS_AUTOSTART = "mount_ums_autostart";
2928
2929        /**
2930         * Whether or not a notification is displayed on UMS host detection. (0 = false, 1 = true)
2931         * @hide
2932         */
2933        public static final String MOUNT_UMS_PROMPT = "mount_ums_prompt";
2934
2935        /**
2936         * Whether or not a notification is displayed while UMS is enabled. (0 = false, 1 = true)
2937         * @hide
2938         */
2939        public static final String MOUNT_UMS_NOTIFY_ENABLED = "mount_ums_notify_enabled";
2940
2941        /**
2942         * If nonzero, ANRs in invisible background processes bring up a dialog.
2943         * Otherwise, the process will be silently killed.
2944         * @hide
2945         */
2946        public static final String ANR_SHOW_BACKGROUND = "anr_show_background";
2947
2948        /**
2949         * @hide
2950         */
2951        public static final String[] SETTINGS_TO_BACKUP = {
2952            ADB_ENABLED,
2953            ALLOW_MOCK_LOCATION,
2954            PARENTAL_CONTROL_ENABLED,
2955            PARENTAL_CONTROL_REDIRECT_URL,
2956            USB_MASS_STORAGE_ENABLED,
2957            ACCESSIBILITY_ENABLED,
2958            ENABLED_ACCESSIBILITY_SERVICES,
2959            TTS_USE_DEFAULTS,
2960            TTS_DEFAULT_RATE,
2961            TTS_DEFAULT_PITCH,
2962            TTS_DEFAULT_SYNTH,
2963            TTS_DEFAULT_LANG,
2964            TTS_DEFAULT_COUNTRY,
2965            WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
2966            WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
2967            WIFI_NUM_ALLOWED_CHANNELS,
2968            WIFI_NUM_OPEN_NETWORKS_KEPT,
2969            MOUNT_PLAY_NOTIFICATION_SND,
2970            MOUNT_UMS_AUTOSTART,
2971            MOUNT_UMS_PROMPT,
2972            MOUNT_UMS_NOTIFY_ENABLED
2973        };
2974
2975        /**
2976         * Helper method for determining if a location provider is enabled.
2977         * @param cr the content resolver to use
2978         * @param provider the location provider to query
2979         * @return true if the provider is enabled
2980         */
2981        public static final boolean isLocationProviderEnabled(ContentResolver cr, String provider) {
2982            String allowedProviders = Settings.Secure.getString(cr, LOCATION_PROVIDERS_ALLOWED);
2983            if (allowedProviders != null) {
2984                return (allowedProviders.equals(provider) ||
2985                        allowedProviders.contains("," + provider + ",") ||
2986                        allowedProviders.startsWith(provider + ",") ||
2987                        allowedProviders.endsWith("," + provider));
2988            }
2989            return false;
2990        }
2991
2992        /**
2993         * Thread-safe method for enabling or disabling a single location provider.
2994         * @param cr the content resolver to use
2995         * @param provider the location provider to enable or disable
2996         * @param enabled true if the provider should be enabled
2997         */
2998        public static final void setLocationProviderEnabled(ContentResolver cr,
2999                String provider, boolean enabled) {
3000            // to ensure thread safety, we write the provider name with a '+' or '-'
3001            // and let the SettingsProvider handle it rather than reading and modifying
3002            // the list of enabled providers.
3003            if (enabled) {
3004                provider = "+" + provider;
3005            } else {
3006                provider = "-" + provider;
3007            }
3008            putString(cr, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, provider);
3009        }
3010    }
3011
3012    /**
3013     * User-defined bookmarks and shortcuts.  The target of each bookmark is an
3014     * Intent URL, allowing it to be either a web page or a particular
3015     * application activity.
3016     *
3017     * @hide
3018     */
3019    public static final class Bookmarks implements BaseColumns
3020    {
3021        private static final String TAG = "Bookmarks";
3022
3023        /**
3024         * The content:// style URL for this table
3025         */
3026        public static final Uri CONTENT_URI =
3027            Uri.parse("content://" + AUTHORITY + "/bookmarks");
3028
3029        /**
3030         * The row ID.
3031         * <p>Type: INTEGER</p>
3032         */
3033        public static final String ID = "_id";
3034
3035        /**
3036         * Descriptive name of the bookmark that can be displayed to the user.
3037         * If this is empty, the title should be resolved at display time (use
3038         * {@link #getTitle(Context, Cursor)} any time you want to display the
3039         * title of a bookmark.)
3040         * <P>
3041         * Type: TEXT
3042         * </P>
3043         */
3044        public static final String TITLE = "title";
3045
3046        /**
3047         * Arbitrary string (displayed to the user) that allows bookmarks to be
3048         * organized into categories.  There are some special names for
3049         * standard folders, which all start with '@'.  The label displayed for
3050         * the folder changes with the locale (via {@link #getLabelForFolder}) but
3051         * the folder name does not change so you can consistently query for
3052         * the folder regardless of the current locale.
3053         *
3054         * <P>Type: TEXT</P>
3055         *
3056         */
3057        public static final String FOLDER = "folder";
3058
3059        /**
3060         * The Intent URL of the bookmark, describing what it points to.  This
3061         * value is given to {@link android.content.Intent#getIntent} to create
3062         * an Intent that can be launched.
3063         * <P>Type: TEXT</P>
3064         */
3065        public static final String INTENT = "intent";
3066
3067        /**
3068         * Optional shortcut character associated with this bookmark.
3069         * <P>Type: INTEGER</P>
3070         */
3071        public static final String SHORTCUT = "shortcut";
3072
3073        /**
3074         * The order in which the bookmark should be displayed
3075         * <P>Type: INTEGER</P>
3076         */
3077        public static final String ORDERING = "ordering";
3078
3079        private static final String[] sIntentProjection = { INTENT };
3080        private static final String[] sShortcutProjection = { ID, SHORTCUT };
3081        private static final String sShortcutSelection = SHORTCUT + "=?";
3082
3083        /**
3084         * Convenience function to retrieve the bookmarked Intent for a
3085         * particular shortcut key.
3086         *
3087         * @param cr The ContentResolver to query.
3088         * @param shortcut The shortcut key.
3089         *
3090         * @return Intent The bookmarked URL, or null if there is no bookmark
3091         *         matching the given shortcut.
3092         */
3093        public static Intent getIntentForShortcut(ContentResolver cr, char shortcut)
3094        {
3095            Intent intent = null;
3096
3097            Cursor c = cr.query(CONTENT_URI,
3098                    sIntentProjection, sShortcutSelection,
3099                    new String[] { String.valueOf((int) shortcut) }, ORDERING);
3100            // Keep trying until we find a valid shortcut
3101            try {
3102                while (intent == null && c.moveToNext()) {
3103                    try {
3104                        String intentURI = c.getString(c.getColumnIndexOrThrow(INTENT));
3105                        intent = Intent.getIntent(intentURI);
3106                    } catch (java.net.URISyntaxException e) {
3107                        // The stored URL is bad...  ignore it.
3108                    } catch (IllegalArgumentException e) {
3109                        // Column not found
3110                        Log.w(TAG, "Intent column not found", e);
3111                    }
3112                }
3113            } finally {
3114                if (c != null) c.close();
3115            }
3116
3117            return intent;
3118        }
3119
3120        /**
3121         * Add a new bookmark to the system.
3122         *
3123         * @param cr The ContentResolver to query.
3124         * @param intent The desired target of the bookmark.
3125         * @param title Bookmark title that is shown to the user; null if none
3126         *            or it should be resolved to the intent's title.
3127         * @param folder Folder in which to place the bookmark; null if none.
3128         * @param shortcut Shortcut that will invoke the bookmark; 0 if none. If
3129         *            this is non-zero and there is an existing bookmark entry
3130         *            with this same shortcut, then that existing shortcut is
3131         *            cleared (the bookmark is not removed).
3132         * @return The unique content URL for the new bookmark entry.
3133         */
3134        public static Uri add(ContentResolver cr,
3135                                           Intent intent,
3136                                           String title,
3137                                           String folder,
3138                                           char shortcut,
3139                                           int ordering)
3140        {
3141            // If a shortcut is supplied, and it is already defined for
3142            // another bookmark, then remove the old definition.
3143            if (shortcut != 0) {
3144                Cursor c = cr.query(CONTENT_URI,
3145                        sShortcutProjection, sShortcutSelection,
3146                        new String[] { String.valueOf((int) shortcut) }, null);
3147                try {
3148                    if (c.moveToFirst()) {
3149                        while (c.getCount() > 0) {
3150                            if (!c.deleteRow()) {
3151                                Log.w(TAG, "Could not delete existing shortcut row");
3152                            }
3153                        }
3154                    }
3155                } finally {
3156                    if (c != null) c.close();
3157                }
3158            }
3159
3160            ContentValues values = new ContentValues();
3161            if (title != null) values.put(TITLE, title);
3162            if (folder != null) values.put(FOLDER, folder);
3163            values.put(INTENT, intent.toURI());
3164            if (shortcut != 0) values.put(SHORTCUT, (int) shortcut);
3165            values.put(ORDERING, ordering);
3166            return cr.insert(CONTENT_URI, values);
3167        }
3168
3169        /**
3170         * Return the folder name as it should be displayed to the user.  This
3171         * takes care of localizing special folders.
3172         *
3173         * @param r Resources object for current locale; only need access to
3174         *          system resources.
3175         * @param folder The value found in the {@link #FOLDER} column.
3176         *
3177         * @return CharSequence The label for this folder that should be shown
3178         *         to the user.
3179         */
3180        public static CharSequence getLabelForFolder(Resources r, String folder) {
3181            return folder;
3182        }
3183
3184        /**
3185         * Return the title as it should be displayed to the user. This takes
3186         * care of localizing bookmarks that point to activities.
3187         *
3188         * @param context A context.
3189         * @param cursor A cursor pointing to the row whose title should be
3190         *        returned. The cursor must contain at least the {@link #TITLE}
3191         *        and {@link #INTENT} columns.
3192         * @return A title that is localized and can be displayed to the user,
3193         *         or the empty string if one could not be found.
3194         */
3195        public static CharSequence getTitle(Context context, Cursor cursor) {
3196            int titleColumn = cursor.getColumnIndex(TITLE);
3197            int intentColumn = cursor.getColumnIndex(INTENT);
3198            if (titleColumn == -1 || intentColumn == -1) {
3199                throw new IllegalArgumentException(
3200                        "The cursor must contain the TITLE and INTENT columns.");
3201            }
3202
3203            String title = cursor.getString(titleColumn);
3204            if (!TextUtils.isEmpty(title)) {
3205                return title;
3206            }
3207
3208            String intentUri = cursor.getString(intentColumn);
3209            if (TextUtils.isEmpty(intentUri)) {
3210                return "";
3211            }
3212
3213            Intent intent;
3214            try {
3215                intent = Intent.getIntent(intentUri);
3216            } catch (URISyntaxException e) {
3217                return "";
3218            }
3219
3220            PackageManager packageManager = context.getPackageManager();
3221            ResolveInfo info = packageManager.resolveActivity(intent, 0);
3222            return info != null ? info.loadLabel(packageManager) : "";
3223        }
3224    }
3225
3226    /**
3227     * Returns the device ID that we should use when connecting to the mobile gtalk server.
3228     * This is a string like "android-0x1242", where the hex string is the Android ID obtained
3229     * from the GoogleLoginService.
3230     *
3231     * @param androidId The Android ID for this device.
3232     * @return The device ID that should be used when connecting to the mobile gtalk server.
3233     * @hide
3234     */
3235    public static String getGTalkDeviceId(long androidId) {
3236        return "android-" + Long.toHexString(androidId);
3237    }
3238}
3239