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