Settings.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
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.Intent;
29import android.content.res.Configuration;
30import android.content.res.Resources;
31import android.database.Cursor;
32import android.database.SQLException;
33import android.net.Uri;
34import android.os.*;
35import android.telephony.TelephonyManager;
36import android.text.TextUtils;
37import android.util.AndroidException;
38import android.util.Log;
39
40import java.security.MessageDigest;
41import java.security.NoSuchAlgorithmException;
42import java.util.HashMap;
43
44
45/**
46 * The Settings provider contains global system-level device preferences.
47 */
48public final class Settings {
49
50    // Intent actions for Settings
51
52    /**
53     * Activity Action: Show system settings.
54     * <p>
55     * Input: Nothing.
56     * <p>
57     * Output: nothing.
58     */
59    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
60    public static final String ACTION_SETTINGS = "android.settings.SETTINGS";
61
62    /**
63     * Activity Action: Show settings to allow configuration of APNs.
64     * <p>
65     * Input: Nothing.
66     * <p>
67     * Output: nothing.
68     */
69    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
70    public static final String ACTION_APN_SETTINGS = "android.settings.APN_SETTINGS";
71
72    /**
73     * Activity Action: Show settings to allow configuration of current location
74     * sources.
75     * <p>
76     * In some cases, a matching Activity may not exist, so ensure you
77     * safeguard against this.
78     * <p>
79     * Input: Nothing.
80     * <p>
81     * Output: Nothing.
82     */
83    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
84    public static final String ACTION_LOCATION_SOURCE_SETTINGS =
85            "android.settings.LOCATION_SOURCE_SETTINGS";
86
87    /**
88     * Activity Action: Show settings to allow configuration of wireless controls
89     * such as Wi-Fi, Bluetooth and Mobile networks.
90     * <p>
91     * In some cases, a matching Activity may not exist, so ensure you
92     * safeguard against this.
93     * <p>
94     * Input: Nothing.
95     * <p>
96     * Output: Nothing.
97     */
98    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
99    public static final String ACTION_WIRELESS_SETTINGS =
100            "android.settings.WIRELESS_SETTINGS";
101
102    /**
103     * Activity Action: Show settings to allow configuration of security and
104     * location privacy.
105     * <p>
106     * In some cases, a matching Activity may not exist, so ensure you
107     * safeguard against this.
108     * <p>
109     * Input: Nothing.
110     * <p>
111     * Output: Nothing.
112     */
113    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
114    public static final String ACTION_SECURITY_SETTINGS =
115            "android.settings.SECURITY_SETTINGS";
116
117    /**
118     * Activity Action: Show settings to allow configuration of Wi-Fi.
119     * <p>
120     * In some cases, a matching Activity may not exist, so ensure you
121     * safeguard against this.
122     * <p>
123     * Input: Nothing.
124     * <p>
125     * Output: Nothing.
126     */
127    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
128    public static final String ACTION_WIFI_SETTINGS =
129            "android.settings.WIFI_SETTINGS";
130
131    /**
132     * Activity Action: Show settings to allow configuration of Bluetooth.
133     * <p>
134     * In some cases, a matching Activity may not exist, so ensure you
135     * safeguard against this.
136     * <p>
137     * Input: Nothing.
138     * <p>
139     * Output: Nothing.
140     */
141    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
142    public static final String ACTION_BLUETOOTH_SETTINGS =
143            "android.settings.BLUETOOTH_SETTINGS";
144
145    /**
146     * Activity Action: Show settings to allow configuration of date and time.
147     * <p>
148     * In some cases, a matching Activity may not exist, so ensure you
149     * safeguard against this.
150     * <p>
151     * Input: Nothing.
152     * <p>
153     * Output: Nothing.
154     */
155    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
156    public static final String ACTION_DATE_SETTINGS =
157            "android.settings.DATE_SETTINGS";
158
159    /**
160     * Activity Action: Show settings to allow configuration of sound and volume.
161     * <p>
162     * In some cases, a matching Activity may not exist, so ensure you
163     * safeguard against this.
164     * <p>
165     * Input: Nothing.
166     * <p>
167     * Output: Nothing.
168     */
169    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
170    public static final String ACTION_SOUND_SETTINGS =
171            "android.settings.SOUND_SETTINGS";
172
173    /**
174     * Activity Action: Show settings to allow configuration of display.
175     * <p>
176     * In some cases, a matching Activity may not exist, so ensure you
177     * safeguard against this.
178     * <p>
179     * Input: Nothing.
180     * <p>
181     * Output: Nothing.
182     */
183    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
184    public static final String ACTION_DISPLAY_SETTINGS =
185            "android.settings.DISPLAY_SETTINGS";
186
187    /**
188     * Activity Action: Show settings to allow configuration of locale.
189     * <p>
190     * In some cases, a matching Activity may not exist, so ensure you
191     * safeguard against this.
192     * <p>
193     * Input: Nothing.
194     * <p>
195     * Output: Nothing.
196     */
197    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
198    public static final String ACTION_LOCALE_SETTINGS =
199            "android.settings.LOCALE_SETTINGS";
200
201    /**
202     * Activity Action: Show settings to allow configuration of application-related settings.
203     * <p>
204     * In some cases, a matching Activity may not exist, so ensure you
205     * safeguard against this.
206     * <p>
207     * Input: Nothing.
208     * <p>
209     * Output: Nothing.
210     */
211    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
212    public static final String ACTION_APPLICATION_SETTINGS =
213            "android.settings.APPLICATION_SETTINGS";
214
215    /**
216     * Activity Action: Show settings to allow configuration of sync settings.
217     * <p>
218     * In some cases, a matching Activity may not exist, so ensure you
219     * safeguard against this.
220     * <p>
221     * Input: Nothing.
222     * <p>
223     * Output: Nothing.
224     *
225     * @hide
226     */
227    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
228    public static final String ACTION_SYNC_SETTINGS =
229            "android.settings.SYNC_SETTINGS";
230
231    // End of Intent actions for Settings
232
233    private static final String JID_RESOURCE_PREFIX = "android";
234
235    public static final String AUTHORITY = "settings";
236
237    private static final String TAG = "Settings";
238
239    private static String sJidResource = null;
240
241    public static class SettingNotFoundException extends AndroidException {
242        public SettingNotFoundException(String msg) {
243            super(msg);
244        }
245    }
246
247    /**
248     * Common base for tables of name/value settings.
249     *
250     *
251     */
252    public static class NameValueTable implements BaseColumns {
253        public static final String NAME = "name";
254        public static final String VALUE = "value";
255
256        protected static boolean putString(ContentResolver resolver, Uri uri,
257                String name, String value) {
258            // The database will take care of replacing duplicates.
259            try {
260                ContentValues values = new ContentValues();
261                values.put(NAME, name);
262                values.put(VALUE, value);
263                resolver.insert(uri, values);
264                return true;
265            } catch (SQLException e) {
266                Log.e(TAG, "Can't set key " + name + " in " + uri, e);
267                return false;
268            }
269        }
270
271        public static Uri getUriFor(Uri uri, String name) {
272            return Uri.withAppendedPath(uri, name);
273        }
274    }
275
276    private static class NameValueCache {
277        private final String mVersionSystemProperty;
278        private final HashMap<String, String> mValues = Maps.newHashMap();
279        private long mValuesVersion = 0;
280        private final Uri mUri;
281
282        NameValueCache(String versionSystemProperty, Uri uri) {
283            mVersionSystemProperty = versionSystemProperty;
284            mUri = uri;
285        }
286
287        String getString(ContentResolver cr, String name) {
288            long newValuesVersion = SystemProperties.getLong(mVersionSystemProperty, 0);
289            if (mValuesVersion != newValuesVersion) {
290                mValues.clear();
291                mValuesVersion = newValuesVersion;
292            }
293            if (!mValues.containsKey(name)) {
294                String value = null;
295                Cursor c = null;
296                try {
297                    c = cr.query(mUri, new String[] { Settings.NameValueTable.VALUE },
298                            Settings.NameValueTable.NAME + "=?", new String[]{name}, null);
299                    if (c.moveToNext()) value = c.getString(0);
300                    mValues.put(name, value);
301                } catch (SQLException e) {
302                    // SQL error: return null, but don't cache it.
303                    Log.e(TAG, "Can't get key " + name + " from " + mUri, e);
304                } finally {
305                    if (c != null) c.close();
306                }
307                return value;
308            } else {
309                return mValues.get(name);
310            }
311        }
312    }
313
314    /**
315     * System settings, containing miscellaneous system preferences.  This
316     * table holds simple name/value pairs.  There are convenience
317     * functions for accessing individual settings entries.
318     */
319    public static final class System extends NameValueTable {
320        public static final String SYS_PROP_SETTING_VERSION = "sys.settings_system_version";
321
322        private static volatile NameValueCache mNameValueCache = null;
323
324        /**
325         * Look up a name in the database.
326         * @param resolver to access the database with
327         * @param name to look up in the table
328         * @return the corresponding value, or null if not present
329         */
330        public synchronized static String getString(ContentResolver resolver, String name) {
331            if (mNameValueCache == null) {
332                mNameValueCache = new NameValueCache(SYS_PROP_SETTING_VERSION, CONTENT_URI);
333            }
334            return mNameValueCache.getString(resolver, name);
335        }
336
337        /**
338         * Store a name/value pair into the database.
339         * @param resolver to access the database with
340         * @param name to store
341         * @param value to associate with the name
342         * @return true if the value was set, false on database errors
343         */
344        public static boolean putString(ContentResolver resolver,
345                String name, String value) {
346            return putString(resolver, CONTENT_URI, name, value);
347        }
348
349        /**
350         * Construct the content URI for a particular name/value pair,
351         * useful for monitoring changes with a ContentObserver.
352         * @param name to look up in the table
353         * @return the corresponding content URI, or null if not present
354         */
355        public static Uri getUriFor(String name) {
356            return getUriFor(CONTENT_URI, name);
357        }
358
359        /**
360         * Convenience function for retrieving a single system settings value
361         * as an integer.  Note that internally setting values are always
362         * stored as strings; this function converts the string to an integer
363         * for you.  The default value will be returned if the setting is
364         * not defined or not an integer.
365         *
366         * @param cr The ContentResolver to access.
367         * @param name The name of the setting to retrieve.
368         * @param def Value to return if the setting is not defined.
369         *
370         * @return The setting's current value, or 'def' if it is not defined
371         * or not a valid integer.
372         */
373        public static int getInt(ContentResolver cr, String name, int def) {
374            String v = getString(cr, name);
375            try {
376                return v != null ? Integer.parseInt(v) : def;
377            } catch (NumberFormatException e) {
378                return def;
379            }
380        }
381
382        /**
383         * Convenience function for retrieving a single system settings value
384         * as an integer.  Note that internally setting values are always
385         * stored as strings; this function converts the string to an integer
386         * for you.
387         * <p>
388         * This version does not take a default value.  If the setting has not
389         * been set, or the string value is not a number,
390         * it throws {@link SettingNotFoundException}.
391         *
392         * @param cr The ContentResolver to access.
393         * @param name The name of the setting to retrieve.
394         *
395         * @throws SettingNotFoundException Thrown if a setting by the given
396         * name can't be found or the setting value is not an integer.
397         *
398         * @return The setting's current value.
399         */
400        public static int getInt(ContentResolver cr, String name)
401                throws SettingNotFoundException {
402            String v = getString(cr, name);
403            try {
404                return Integer.parseInt(v);
405            } catch (NumberFormatException e) {
406                throw new SettingNotFoundException(name);
407            }
408        }
409
410        /**
411         * Convenience function for updating a single settings value as an
412         * integer. This will either create a new entry in the table if the
413         * given name does not exist, or modify the value of the existing row
414         * with that name.  Note that internally setting values are always
415         * stored as strings, so this function converts the given value to a
416         * string before storing it.
417         *
418         * @param cr The ContentResolver to access.
419         * @param name The name of the setting to modify.
420         * @param value The new value for the setting.
421         * @return true if the value was set, false on database errors
422         */
423        public static boolean putInt(ContentResolver cr, String name, int value) {
424            return putString(cr, name, Integer.toString(value));
425        }
426
427        /**
428         * Convenience function for retrieving a single system settings value
429         * as a floating point number.  Note that internally setting values are
430         * always stored as strings; this function converts the string to an
431         * float for you. The default value will be returned if the setting
432         * is not defined or not a valid float.
433         *
434         * @param cr The ContentResolver to access.
435         * @param name The name of the setting to retrieve.
436         * @param def Value to return if the setting is not defined.
437         *
438         * @return The setting's current value, or 'def' if it is not defined
439         * or not a valid float.
440         */
441        public static float getFloat(ContentResolver cr, String name, float def) {
442            String v = getString(cr, name);
443            try {
444                return v != null ? Float.parseFloat(v) : def;
445            } catch (NumberFormatException e) {
446                return def;
447            }
448        }
449
450        /**
451         * Convenience function for retrieving a single system settings value
452         * as a float.  Note that internally setting values are always
453         * stored as strings; this function converts the string to a float
454         * for you.
455         * <p>
456         * This version does not take a default value.  If the setting has not
457         * been set, or the string value is not a number,
458         * it throws {@link SettingNotFoundException}.
459         *
460         * @param cr The ContentResolver to access.
461         * @param name The name of the setting to retrieve.
462         *
463         * @throws SettingNotFoundException Thrown if a setting by the given
464         * name can't be found or the setting value is not a float.
465         *
466         * @return The setting's current value.
467         */
468        public static float getFloat(ContentResolver cr, String name)
469                throws SettingNotFoundException {
470            String v = getString(cr, name);
471            try {
472                return Float.parseFloat(v);
473            } catch (NumberFormatException e) {
474                throw new SettingNotFoundException(name);
475            }
476        }
477
478        /**
479         * Convenience function for updating a single settings value as a
480         * floating point number. This will either create a new entry in the
481         * table if the given name does not exist, or modify the value of the
482         * existing row with that name.  Note that internally setting values
483         * are always stored as strings, so this function converts the given
484         * value to a string before storing it.
485         *
486         * @param cr The ContentResolver to access.
487         * @param name The name of the setting to modify.
488         * @param value The new value for the setting.
489         * @return true if the value was set, false on database errors
490         */
491        public static boolean putFloat(ContentResolver cr, String name, float value) {
492            return putString(cr, name, Float.toString(value));
493        }
494
495        /**
496         * Convenience function to read all of the current
497         * configuration-related settings into a
498         * {@link Configuration} object.
499         *
500         * @param cr The ContentResolver to access.
501         * @param outConfig Where to place the configuration settings.
502         */
503        public static void getConfiguration(ContentResolver cr, Configuration outConfig) {
504            outConfig.fontScale = Settings.System.getFloat(
505                cr, FONT_SCALE, outConfig.fontScale);
506            if (outConfig.fontScale < 0) {
507                outConfig.fontScale = 1;
508            }
509        }
510
511        /**
512         * Convenience function to write a batch of configuration-related
513         * settings from a {@link Configuration} object.
514         *
515         * @param cr The ContentResolver to access.
516         * @param config The settings to write.
517         * @return true if the values were set, false on database errors
518         */
519        public static boolean putConfiguration(ContentResolver cr, Configuration config) {
520            return Settings.System.putFloat(cr, FONT_SCALE, config.fontScale);
521        }
522
523        public static boolean getShowGTalkServiceStatus(ContentResolver cr) {
524            return getInt(cr, SHOW_GTALK_SERVICE_STATUS, 0) != 0;
525        }
526
527        public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
528            putInt(cr, SHOW_GTALK_SERVICE_STATUS, flag ? 1 : 0);
529        }
530
531        /**
532         * The content:// style URL for this table
533         */
534        public static final Uri CONTENT_URI =
535            Uri.parse("content://" + AUTHORITY + "/system");
536
537        /**
538         * Whether we keep the device on while the device is plugged in.
539         * 0=no  1=yes
540         */
541        public static final String STAY_ON_WHILE_PLUGGED_IN = "stay_on_while_plugged_in";
542
543        /**
544         * What happens when the user presses the end call button if they're not
545         * on a call.<br/>
546         * <b>Values:</b><br/>
547         * 0 - The end button does nothing.<br/>
548         * 1 - The end button goes to the home screen.<br/>
549         * 2 - The end button puts the device to sleep and locks the keyguard.<br/>
550         * 3 - The end button goes to the home screen.  If the user is already on the
551         * home screen, it puts the device to sleep.
552         */
553        public static final String END_BUTTON_BEHAVIOR = "end_button_behavior";
554
555        /**
556         * Whether Airplane Mode is on.
557         */
558        public static final String AIRPLANE_MODE_ON = "airplane_mode_on";
559
560        /**
561         * Constant for use in AIRPLANE_MODE_RADIOS to specify Bluetooth radio.
562         */
563        public static final String RADIO_BLUETOOTH = "bluetooth";
564
565        /**
566         * Constant for use in AIRPLANE_MODE_RADIOS to specify Wi-Fi radio.
567         */
568        public static final String RADIO_WIFI = "wifi";
569
570        /**
571         * Constant for use in AIRPLANE_MODE_RADIOS to specify Cellular radio.
572         */
573        public static final String RADIO_CELL = "cell";
574
575        /**
576         * A comma separated list of radios that need to be disabled when airplane mode
577         * is on. This overrides WIFI_ON and BLUETOOTH_ON, if Wi-Fi and bluetooth are
578         * included in the comma separated list.
579         */
580        public static final String AIRPLANE_MODE_RADIOS = "airplane_mode_radios";
581
582        /**
583         * Whether the Wi-Fi should be on.  Only the Wi-Fi service should touch this.
584         */
585        public static final String WIFI_ON = "wifi_on";
586
587        /**
588         * Whether to notify the user of open networks.
589         * <p>
590         * If not connected and the scan results have an open network, we will
591         * put this notification up. If we attempt to connect to a network or
592         * the open network(s) disappear, we remove the notification. When we
593         * show the notification, we will not show it again for
594         * {@link #WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY} time.
595         */
596        public static final String WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON =
597                "wifi_networks_available_notification_on";
598
599        /**
600         * Delay (in seconds) before repeating the Wi-Fi networks available notification.
601         * Connecting to a network will reset the timer.
602         */
603        public static final String WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY =
604                "wifi_networks_available_repeat_delay";
605
606        /**
607         * When the number of open networks exceeds this number, the
608         * least-recently-used excess networks will be removed.
609         */
610        public static final String WIFI_NUM_OPEN_NETWORKS_KEPT = "wifi_num_open_networks_kept";
611
612        /**
613         * Whether the Wi-Fi watchdog is enabled.
614         */
615        public static final String WIFI_WATCHDOG_ON = "wifi_watchdog_on";
616
617        /**
618         * The number of access points required for a network in order for the
619         * watchdog to monitor it.
620         */
621        public static final String WIFI_WATCHDOG_AP_COUNT = "wifi_watchdog_ap_count";
622
623        /**
624         * The number of initial pings to perform that *may* be ignored if they
625         * fail. Again, if these fail, they will *not* be used in packet loss
626         * calculation. For example, one network always seemed to time out for
627         * the first couple pings, so this is set to 3 by default.
628         */
629        public static final String WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT = "wifi_watchdog_initial_ignored_ping_count";
630
631        /**
632         * The number of pings to test if an access point is a good connection.
633         */
634        public static final String WIFI_WATCHDOG_PING_COUNT = "wifi_watchdog_ping_count";
635
636        /**
637         * The timeout per ping.
638         */
639        public static final String WIFI_WATCHDOG_PING_TIMEOUT_MS = "wifi_watchdog_ping_timeout_ms";
640
641        /**
642         * The delay between pings.
643         */
644        public static final String WIFI_WATCHDOG_PING_DELAY_MS = "wifi_watchdog_ping_delay_ms";
645
646        /**
647         * The acceptable packet loss percentage (range 0 - 100) before trying
648         * another AP on the same network.
649         */
650        public static final String WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE =
651                "wifi_watchdog_acceptable_packet_loss_percentage";
652
653        /**
654         * The maximum number of access points (per network) to attempt to test.
655         * If this number is reached, the watchdog will no longer monitor the
656         * initial connection state for the network. This is a safeguard for
657         * networks containing multiple APs whose DNS does not respond to pings.
658         */
659        public static final String WIFI_WATCHDOG_MAX_AP_CHECKS = "wifi_watchdog_max_ap_checks";
660
661        /**
662         * Whether the Wi-Fi watchdog is enabled for background checking even
663         * after it thinks the user has connected to a good access point.
664         */
665        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED =
666                "wifi_watchdog_background_check_enabled";
667
668        /**
669         * The timeout for a background ping
670         */
671        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS =
672                "wifi_watchdog_background_check_timeout_ms";
673
674        /**
675         * The delay between background checks.
676         */
677        public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS =
678                "wifi_watchdog_background_check_delay_ms";
679
680        /**
681         * Whether to use static IP and other static network attributes.
682         * <p>
683         * Set to 1 for true and 0 for false.
684         */
685        public static final String WIFI_USE_STATIC_IP = "wifi_use_static_ip";
686
687        /**
688         * The static IP address.
689         * <p>
690         * Example: "192.168.1.51"
691         */
692        public static final String WIFI_STATIC_IP = "wifi_static_ip";
693
694        /**
695         * If using static IP, the gateway's IP address.
696         * <p>
697         * Example: "192.168.1.1"
698         */
699        public static final String WIFI_STATIC_GATEWAY = "wifi_static_gateway";
700
701        /**
702         * If using static IP, the net mask.
703         * <p>
704         * Example: "255.255.255.0"
705         */
706        public static final String WIFI_STATIC_NETMASK = "wifi_static_netmask";
707
708        /**
709         * If using static IP, the primary DNS's IP address.
710         * <p>
711         * Example: "192.168.1.1"
712         */
713        public static final String WIFI_STATIC_DNS1 = "wifi_static_dns1";
714
715        /**
716         * If using static IP, the secondary DNS's IP address.
717         * <p>
718         * Example: "192.168.1.2"
719         */
720        public static final String WIFI_STATIC_DNS2 = "wifi_static_dns2";
721
722        /**
723         * User preference for which network(s) should be used. Only the
724         * connectivity service should touch this.
725         */
726        public static final String NETWORK_PREFERENCE = "network_preference";
727
728        /**
729         * Whether bluetooth is enabled/disabled
730         * 0=disabled. 1=enabled.
731         */
732        public static final String BLUETOOTH_ON = "bluetooth_on";
733
734        /**
735         * Determines whether remote devices may discover and/or connect to
736         * this device.
737         * <P>Type: INT</P>
738         * 2 -- discoverable and connectable
739         * 1 -- connectable but not discoverable
740         * 0 -- neither connectable nor discoverable
741         */
742        public static final String BLUETOOTH_DISCOVERABILITY =
743            "bluetooth_discoverability";
744
745        /**
746         * Bluetooth discoverability timeout.  If this value is nonzero, then
747         * Bluetooth becomes discoverable for a certain number of seconds,
748         * after which is becomes simply connectable.  The value is in seconds.
749         */
750        public static final String BLUETOOTH_DISCOVERABILITY_TIMEOUT =
751            "bluetooth_discoverability_timeout";
752
753        /**
754         * Whether autolock is enabled (0 = false, 1 = true)
755         */
756        public static final String LOCK_PATTERN_ENABLED = "lock_pattern_autolock";
757
758        /**
759         * Whether the device has been provisioned (0 = false, 1 = true)
760         */
761        public static final String DEVICE_PROVISIONED = "device_provisioned";
762
763        /**
764         * Whether lock pattern is visible as user enters (0 = false, 1 = true)
765         */
766        public static final String LOCK_PATTERN_VISIBLE = "lock_pattern_visible_pattern";
767
768
769        /**
770         * A formatted string of the next alarm that is set, or the empty string
771         * if there is no alarm set.
772         */
773        public static final String NEXT_ALARM_FORMATTED = "next_alarm_formatted";
774
775        /**
776         * Comma-separated list of location providers that activities may access.
777         */
778        public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
779
780        /**
781         * Whether or not data roaming is enabled. (0 = false, 1 = true)
782         */
783        public static final String DATA_ROAMING = "data_roaming";
784
785        /**
786         * Scaling factor for fonts, float.
787         */
788        public static final String FONT_SCALE = "font_scale";
789
790        /**
791         * Name of an application package to be debugged.
792         */
793        public static final String DEBUG_APP = "debug_app";
794
795        /**
796         * If 1, when launching DEBUG_APP it will wait for the debugger before
797         * starting user code.  If 0, it will run normally.
798         */
799        public static final String WAIT_FOR_DEBUGGER = "wait_for_debugger";
800
801        /**
802         * Whether or not to dim the screen. 0=no  1=yes
803         */
804        public static final String DIM_SCREEN = "dim_screen";
805
806        /**
807         * The timeout before the screen turns off.
808         */
809        public static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout";
810
811        /**
812         * The screen backlight brightness between 0 and 255.
813         */
814        public static final String SCREEN_BRIGHTNESS = "screen_brightness";
815
816        /**
817         * Control whether the process CPU usage meter should be shown.
818         */
819        public static final String SHOW_PROCESSES = "show_processes";
820
821        /**
822         * If 1, the activity manager will aggressively finish activities and
823         * processes as soon as they are no longer needed.  If 0, the normal
824         * extended lifetime is used.
825         */
826        public static final String ALWAYS_FINISH_ACTIVITIES =
827                "always_finish_activities";
828
829
830        /**
831         * Ringer mode. This is used internally, changing this value will not
832         * change the ringer mode. See AudioManager.
833         */
834        public static final String MODE_RINGER = "mode_ringer";
835
836        /**
837         * Determines which streams are affected by ringer mode changes. The
838         * stream type's bit should be set to 1 if it should be muted when going
839         * into an inaudible ringer mode.
840         */
841        public static final String MODE_RINGER_STREAMS_AFFECTED = "mode_ringer_streams_affected";
842
843         /**
844          * Determines which streams are affected by mute. The
845          * stream type's bit should be set to 1 if it should be muted when a mute request
846          * is received.
847          */
848         public static final String MUTE_STREAMS_AFFECTED = "mute_streams_affected";
849
850        /**
851         * Whether vibrate is on for different events. This is used internally,
852         * changing this value will not change the vibrate. See AudioManager.
853         */
854        public static final String VIBRATE_ON = "vibrate_on";
855
856        /**
857         * Ringer volume. This is used internally, changing this value will not
858         * change the volume. See AudioManager.
859         */
860        public static final String VOLUME_RING = "volume_ring";
861
862        /**
863         * System/notifications volume. This is used internally, changing this
864         * value will not change the volume. See AudioManager.
865         */
866        public static final String VOLUME_SYSTEM = "volume_system";
867
868        /**
869         * Voice call volume. This is used internally, changing this value will
870         * not change the volume. See AudioManager.
871         */
872        public static final String VOLUME_VOICE = "volume_voice";
873
874        /**
875         * Music/media/gaming volume. This is used internally, changing this
876         * value will not change the volume. See AudioManager.
877         */
878        public static final String VOLUME_MUSIC = "volume_music";
879
880        /**
881         * Alarm volume. This is used internally, changing this
882         * value will not change the volume. See AudioManager.
883         */
884        public static final String VOLUME_ALARM = "volume_alarm";
885
886        /**
887         * The mapping of stream type (integer) to its setting.
888         */
889        public static final String[] VOLUME_SETTINGS = {
890            VOLUME_VOICE, VOLUME_SYSTEM, VOLUME_RING, VOLUME_MUSIC, VOLUME_ALARM
891        };
892
893        /**
894         * Appended to various volume related settings to record the previous
895         * values before they the settings were affected by a silent/vibrate
896         * ringer mode change.
897         */
898        public static final String APPEND_FOR_LAST_AUDIBLE = "_last_audible";
899
900        /**
901         * Persistent store for the system-wide default ringtone URI.
902         * <p>
903         * If you need to play the default ringtone at any given time, it is recommended
904         * you give {@link #DEFAULT_RINGTONE_URI} to the media player.  It will resolve
905         * to the set default ringtone at the time of playing.
906         *
907         * @see #DEFAULT_RINGTONE_URI
908         */
909        public static final String RINGTONE = "ringtone";
910
911        /**
912         * A {@link Uri} that will point to the current default ringtone at any
913         * given time.
914         * <p>
915         * If the current default ringtone is in the DRM provider and the caller
916         * does not have permission, the exception will be a
917         * FileNotFoundException.
918         */
919        public static final Uri DEFAULT_RINGTONE_URI = getUriFor(RINGTONE);
920
921        /**
922         * Persistent store for the system-wide default notification sound.
923         *
924         * @see #RINGTONE
925         * @see #DEFAULT_NOTIFICATION_URI
926         */
927        public static final String NOTIFICATION_SOUND = "notification_sound";
928
929        /**
930         * A {@link Uri} that will point to the current default notification
931         * sound at any given time.
932         *
933         * @see #DEFAULT_RINGTONE_URI
934         */
935        public static final Uri DEFAULT_NOTIFICATION_URI = getUriFor(NOTIFICATION_SOUND);
936
937        /**
938         * Setting to enable Auto Replace (AutoText) in text editors. 1 = On, 0 = Off
939         */
940        public static final String TEXT_AUTO_REPLACE = "auto_replace";
941
942        /**
943         * Setting to enable Auto Caps in text editors. 1 = On, 0 = Off
944         */
945        public static final String TEXT_AUTO_CAPS = "auto_caps";
946
947        /**
948         * Setting to enable Auto Punctuate in text editors. 1 = On, 0 = Off. This
949         * feature converts two spaces to a "." and space.
950         */
951        public static final String TEXT_AUTO_PUNCTUATE = "auto_punctuate";
952
953        /**
954         * Setting to showing password characters in text editors. 1 = On, 0 = Off
955         */
956        public static final String TEXT_SHOW_PASSWORD = "show_password";
957        /**
958         * USB Mass Storage Enabled
959         */
960        public static final String USB_MASS_STORAGE_ENABLED =
961                "usb_mass_storage_enabled";
962
963        public static final String SHOW_GTALK_SERVICE_STATUS =
964                "SHOW_GTALK_SERVICE_STATUS";
965
966        /**
967         * Name of activity to use for wallpaper on the home screen.
968         */
969        public static final String WALLPAPER_ACTIVITY = "wallpaper_activity";
970
971        /**
972         * Host name and port for a user-selected proxy.
973         */
974        public static final String HTTP_PROXY = "http_proxy";
975
976        /**
977         * Value to specify if the user prefers the date, time and time zone
978         * to be automatically fetched from the network (NITZ). 1=yes, 0=no
979         */
980        public static final String AUTO_TIME = "auto_time";
981
982        /**
983         * Display times as 12 or 24 hours
984         *   12
985         *   24
986         */
987        public static final String TIME_12_24 = "time_12_24";
988
989        /**
990         * Date format string
991         *   mm/dd/yyyy
992         *   dd/mm/yyyy
993         *   yyyy/mm/dd
994         */
995        public static final String DATE_FORMAT = "date_format";
996
997        /**
998         * Settings classname to launch when Settings is clicked from All
999         * Applications.  Needed because of user testing between the old
1000         * and new Settings apps. TODO: 881807
1001         */
1002        public static final String SETTINGS_CLASSNAME = "settings_classname";
1003
1004        /**
1005         * Whether the setup wizard has been run before (on first boot), or if
1006         * it still needs to be run.
1007         *
1008         * nonzero = it has been run in the past
1009         * 0 = it has not been run in the past
1010         */
1011        public static final String SETUP_WIZARD_HAS_RUN = "setup_wizard_has_run";
1012
1013        /**
1014         * The Android ID (a unique 64-bit value) as a hex string.
1015         * Identical to that obtained by calling
1016         * GoogleLoginService.getAndroidId(); it is also placed here
1017         * so you can get it without binding to a service.
1018         */
1019        public static final String ANDROID_ID = "android_id";
1020
1021        /**
1022         * The Logging ID (a unique 64-bit value) as a hex string.
1023         * Used as a pseudonymous identifier for logging.
1024         */
1025        public static final String LOGGING_ID = "logging_id";
1026
1027        /**
1028         * If this setting is set (to anything), then all references
1029         * to Gmail on the device must change to Google Mail.
1030         */
1031        public static final String USE_GOOGLE_MAIL = "use_google_mail";
1032
1033        /**
1034         * Whether the package installer should allow installation of apps downloaded from
1035         * sources other than the Android Market (vending machine).
1036         *
1037         * 1 = allow installing from other sources
1038         * 0 = only allow installing from the Android Market
1039         */
1040        public static final String INSTALL_NON_MARKET_APPS = "install_non_market_apps";
1041
1042        /**
1043         * Scaling factor for normal window animations. Setting to 0 will disable window
1044         * animations.
1045         */
1046        public static final String WINDOW_ANIMATION_SCALE = "window_animation_scale";
1047
1048        /**
1049         * Scaling factor for activity transition animations. Setting to 0 will disable window
1050         * animations.
1051         */
1052        public static final String TRANSITION_ANIMATION_SCALE = "transition_animation_scale";
1053
1054        public static final String PARENTAL_CONTROL_ENABLED =
1055            "parental_control_enabled";
1056
1057        public static final String PARENTAL_CONTROL_REDIRECT_URL =
1058            "parental_control_redirect_url";
1059
1060        public static final String PARENTAL_CONTROL_LAST_UPDATE =
1061          "parental_control_last_update";
1062
1063        /**
1064         * Whether ADB is enabled.
1065         */
1066        public static final String ADB_ENABLED = "adb_enabled";
1067
1068        /**
1069         * Whether the audible DTMF tones are played by the dialer when dialing. The value is
1070         * boolean (1 or 0).
1071         */
1072        public static final String DTMF_TONE_WHEN_DIALING = "dtmf_tone";
1073
1074        /**
1075         * Whether the sounds effects (key clicks, lid open ...) are enabled. The value is
1076         * boolean (1 or 0).
1077         */
1078        public static final String SOUND_EFFECTS_ENABLED = "sound_effects_enabled";
1079    }
1080
1081
1082    /**
1083     * Gservices settings, containing the network names for Google's
1084     * various services. This table holds simple name/addr pairs.
1085     * Addresses can be accessed through the getString() method.
1086     * @hide
1087     */
1088    public static final class Gservices extends NameValueTable {
1089        public static final String SYS_PROP_SETTING_VERSION = "sys.settings_gservices_version";
1090
1091        private static volatile NameValueCache mNameValueCache = null;
1092        private static final Object mNameValueCacheLock = new Object();
1093
1094        /**
1095         * Look up a name in the database.
1096         * @param resolver to access the database with
1097         * @param name to look up in the table
1098         * @return the corresponding value, or null if not present
1099         */
1100        public static String getString(ContentResolver resolver, String name) {
1101            synchronized (mNameValueCacheLock) {
1102                if (mNameValueCache == null) {
1103                    mNameValueCache = new NameValueCache(SYS_PROP_SETTING_VERSION, CONTENT_URI);
1104                }
1105                return mNameValueCache.getString(resolver, name);
1106            }
1107        }
1108
1109        /**
1110         * Store a name/value pair into the database.
1111         * @param resolver to access the database with
1112         * @param name to store
1113         * @param value to associate with the name
1114         * @return true if the value was set, false on database errors
1115         */
1116        public static boolean putString(ContentResolver resolver,
1117                String name, String value) {
1118            return putString(resolver, CONTENT_URI, name, value);
1119        }
1120
1121        /**
1122         * Look up the value for name in the database, convert it to an int using Integer.parseInt
1123         * and return it. If it is null or if a NumberFormatException is caught during the
1124         * conversion then return defValue.
1125         */
1126        public static int getInt(ContentResolver resolver, String name, int defValue) {
1127            String valString = getString(resolver, name);
1128            int value;
1129            try {
1130                value = valString != null ? Integer.parseInt(valString) : defValue;
1131            } catch (NumberFormatException e) {
1132                value = defValue;
1133            }
1134            return value;
1135        }
1136
1137        /**
1138         * Look up the value for name in the database, convert it to a long using Long.parseLong
1139         * and return it. If it is null or if a NumberFormatException is caught during the
1140         * conversion then return defValue.
1141         */
1142        public static long getLong(ContentResolver resolver, String name, long defValue) {
1143            String valString = getString(resolver, name);
1144            long value;
1145            try {
1146                value = valString != null ? Long.parseLong(valString) : defValue;
1147            } catch (NumberFormatException e) {
1148                value = defValue;
1149            }
1150            return value;
1151        }
1152
1153        /**
1154         * Construct the content URI for a particular name/value pair,
1155         * useful for monitoring changes with a ContentObserver.
1156         * @param name to look up in the table
1157         * @return the corresponding content URI, or null if not present
1158         */
1159        public static Uri getUriFor(String name) {
1160            return getUriFor(CONTENT_URI, name);
1161        }
1162
1163        /**
1164         * The content:// style URL for this table
1165         */
1166        public static final Uri CONTENT_URI =
1167                Uri.parse("content://" + AUTHORITY + "/gservices");
1168
1169        /**
1170         * MMS - URL to use for HTTP "x-wap-profile" header
1171         */
1172        public static final String MMS_X_WAP_PROFILE_URL
1173                = "mms_x_wap_profile_url";
1174
1175        /**
1176         * YouTube - "most viewed" url
1177         */
1178        public static final String YOUTUBE_MOST_VIEWED_URL
1179                = "youtube_most_viewed_url";
1180
1181        /**
1182         * YouTube - "most recent" url
1183         */
1184        public static final String YOUTUBE_MOST_RECENT_URL
1185                = "youtube_most_recent_url";
1186
1187        /**
1188         * YouTube - "top favorites" url
1189         */
1190        public static final String YOUTUBE_TOP_FAVORITES_URL
1191                = "youtube_top_favorites_url";
1192
1193        /**
1194         * YouTube - "most discussed" url
1195         */
1196        public static final String YOUTUBE_MOST_DISCUSSED_URL
1197                = "youtube_most_discussed_url";
1198
1199        /**
1200         * YouTube - "most responded" url
1201         */
1202        public static final String YOUTUBE_MOST_RESPONDED_URL
1203                = "youtube_most_responded_url";
1204
1205        /**
1206         * YouTube - "most linked" url
1207         */
1208        public static final String YOUTUBE_MOST_LINKED_URL
1209                = "youtube_most_linked_url";
1210
1211        /**
1212         * YouTube - "top rated" url
1213         */
1214        public static final String YOUTUBE_TOP_RATED_URL
1215                = "youtube_top_rated_url";
1216
1217        /**
1218         * YouTube - "recently featured" url
1219         */
1220        public static final String YOUTUBE_RECENTLY_FEATURED_URL
1221                = "youtube_recently_featured_url";
1222
1223        /**
1224         * YouTube - my uploaded videos
1225         */
1226        public static final String YOUTUBE_MY_VIDEOS_URL
1227                = "youtube_my_videos_url";
1228
1229        /**
1230         * YouTube - "my favorite" videos url
1231         */
1232        public static final String YOUTUBE_MY_FAVORITES_URL
1233                = "youtube_my_favorites_url";
1234
1235        /**
1236         * YouTube - "by author" videos url -- used for My videos
1237         */
1238        public static final String YOUTUBE_BY_AUTHOR_URL
1239                = "youtube_by_author_url";
1240
1241        /**
1242         * YouTube - save a video to favorite videos url
1243         */
1244        public static final String YOUTUBE_SAVE_TO_FAVORITES_URL
1245                = "youtube_save_to_favorites_url";
1246
1247        /**
1248         * YouTube - "mobile" videos url
1249         */
1250        public static final String YOUTUBE_MOBILE_VIDEOS_URL
1251                = "youtube_mobile_videos_url";
1252
1253        /**
1254         * YouTube - search videos url
1255         */
1256        public static final String YOUTUBE_SEARCH_URL
1257                = "youtube_search_url";
1258
1259        /**
1260         * YouTube - category search videos url
1261         */
1262        public static final String YOUTUBE_CATEGORY_SEARCH_URL
1263                = "youtube_category_search_url";
1264
1265        /**
1266         * YouTube - url to get the list of categories
1267         */
1268        public static final String YOUTUBE_CATEGORY_LIST_URL
1269                = "youtube_category_list_url";
1270
1271        /**
1272         * YouTube - related videos url
1273         */
1274        public static final String YOUTUBE_RELATED_VIDEOS_URL
1275                = "youtube_related_videos_url";
1276
1277        /**
1278         * YouTube - individual video url
1279         */
1280        public static final String YOUTUBE_INDIVIDUAL_VIDEO_URL
1281                = "youtube_individual_video_url";
1282
1283        /**
1284         * YouTube - user's playlist url
1285         */
1286        public static final String YOUTUBE_MY_PLAYLISTS_URL
1287                = "youtube_my_playlists_url";
1288
1289        /**
1290         * YouTube - user's subscriptions url
1291         */
1292        public static final String YOUTUBE_MY_SUBSCRIPTIONS_URL
1293                = "youtube_my_subscriptions_url";
1294
1295        /**
1296         * YouTube - the url we use to contact YouTube to get a device id
1297         */
1298        public static final String YOUTUBE_REGISTER_DEVICE_URL
1299                = "youtube_register_device_url";
1300
1301        /**
1302         * YouTube - the flag to indicate whether to use proxy
1303         */
1304        public static final String YOUTUBE_USE_PROXY
1305                = "youtube_use_proxy";
1306
1307        /**
1308         * Event tags from the kernel event log to upload during checkin.
1309         */
1310        public static final String CHECKIN_EVENTS = "checkin_events";
1311
1312        /**
1313         * The interval (in seconds) between periodic checkin attempts.
1314         */
1315        public static final String CHECKIN_INTERVAL = "checkin_interval";
1316
1317        /**
1318         * How frequently (in seconds) to check the memory status of the
1319         * device.
1320         */
1321        public static final String MEMCHECK_INTERVAL = "memcheck_interval";
1322
1323        /**
1324         * Max frequency (in seconds) to log memory check stats, in realtime
1325         * seconds.  This allows for throttling of logs when the device is
1326         * running for large amounts of time.
1327         */
1328        public static final String MEMCHECK_LOG_REALTIME_INTERVAL = "memcheck_log_realtime_interval";
1329
1330        /**
1331         * Boolean indicating whether rebooting due to system memory checks
1332         * is enabled.
1333         */
1334        public static final String MEMCHECK_SYSTEM_ENABLED = "memcheck_system_enabled";
1335
1336        /**
1337         * How many bytes the system process must be below to avoid scheduling
1338         * a soft reboot.  This reboot will happen when it is next determined
1339         * to be a good time.
1340         */
1341        public static final String MEMCHECK_SYSTEM_SOFT_THRESHOLD = "memcheck_system_soft";
1342
1343        /**
1344         * How many bytes the system process must be below to avoid scheduling
1345         * a hard reboot.  This reboot will happen immediately.
1346         */
1347        public static final String MEMCHECK_SYSTEM_HARD_THRESHOLD = "memcheck_system_hard";
1348
1349        /**
1350         * How many bytes the phone process must be below to avoid scheduling
1351         * a soft restart.  This restart will happen when it is next determined
1352         * to be a good time.
1353         */
1354        public static final String MEMCHECK_PHONE_SOFT_THRESHOLD = "memcheck_phone_soft";
1355
1356        /**
1357         * How many bytes the phone process must be below to avoid scheduling
1358         * a hard restart.  This restart will happen immediately.
1359         */
1360        public static final String MEMCHECK_PHONE_HARD_THRESHOLD = "memcheck_phone_hard";
1361
1362        /**
1363         * Boolean indicating whether restarting the phone process due to
1364         * memory checks is enabled.
1365         */
1366        public static final String MEMCHECK_PHONE_ENABLED = "memcheck_phone_enabled";
1367
1368        /**
1369         * First time during the day it is okay to kill processes
1370         * or reboot the device due to low memory situations.  This number is
1371         * in seconds since midnight.
1372         */
1373        public static final String MEMCHECK_EXEC_START_TIME = "memcheck_exec_start_time";
1374
1375        /**
1376         * Last time during the day it is okay to kill processes
1377         * or reboot the device due to low memory situations.  This number is
1378         * in seconds since midnight.
1379         */
1380        public static final String MEMCHECK_EXEC_END_TIME = "memcheck_exec_end_time";
1381
1382        /**
1383         * How long the screen must have been off in order to kill processes
1384         * or reboot.  This number is in seconds.  A value of -1 means to
1385         * entirely disregard whether the screen is on.
1386         */
1387        public static final String MEMCHECK_MIN_SCREEN_OFF = "memcheck_min_screen_off";
1388
1389        /**
1390         * How much time there must be until the next alarm in order to kill processes
1391         * or reboot.  This number is in seconds.  Note: this value must be
1392         * smaller than {@link #MEMCHECK_RECHECK_INTERVAL} or else it will
1393         * always see an alarm scheduled within its time.
1394         */
1395        public static final String MEMCHECK_MIN_ALARM = "memcheck_min_alarm";
1396
1397        /**
1398         * How frequently to check whether it is a good time to restart things,
1399         * if the device is in a bad state.  This number is in seconds.  Note:
1400         * this value must be larger than {@link #MEMCHECK_MIN_ALARM} or else
1401         * the alarm to schedule the recheck will always appear within the
1402         * minimum "do not execute now" time.
1403         */
1404        public static final String MEMCHECK_RECHECK_INTERVAL = "memcheck_recheck_interval";
1405
1406        /**
1407         * How frequently (in DAYS) to reboot the device.  If 0, no reboots
1408         * will occur.
1409         */
1410        public static final String REBOOT_INTERVAL = "reboot_interval";
1411
1412        /**
1413         * First time during the day it is okay to force a reboot of the
1414         * device (if REBOOT_INTERVAL is set).  This number is
1415         * in seconds since midnight.
1416         */
1417        public static final String REBOOT_START_TIME = "reboot_start_time";
1418
1419        /**
1420         * The window of time (in seconds) after each REBOOT_INTERVAL in which
1421         * a reboot can be executed.  If 0, a reboot will always be executed at
1422         * exactly the given time.  Otherwise, it will only be executed if
1423         * the device is idle within the window.
1424         */
1425        public static final String REBOOT_WINDOW = "reboot_window";
1426
1427        /**
1428         * The minimum version of the server that is required in order for the device to accept
1429         * the server's recommendations about the initial sync settings to use. When this is unset,
1430         * blank or can't be interpreted as an integer then we will not ask the server for a
1431         * recommendation.
1432         */
1433        public static final String GMAIL_CONFIG_INFO_MIN_SERVER_VERSION =
1434                "gmail_config_info_min_server_version";
1435
1436        /**
1437         * Controls whether Gmail offers a preview button for images.
1438         */
1439        public static final String GMAIL_DISALLOW_IMAGE_PREVIEWS = "gmail_disallow_image_previews";
1440
1441        /**
1442         * The timeout in milliseconds that Gmail uses when opening a connection and reading
1443         * from it. A missing value or a value of -1 instructs Gmail to use the defaults provided
1444         * by GoogleHttpClient.
1445         */
1446        public static final String GMAIL_TIMEOUT_MS = "gmail_timeout_ms";
1447
1448        /**
1449         * Hostname of the GTalk server.
1450         */
1451        public static final String GTALK_SERVICE_HOSTNAME = "gtalk_hostname";
1452
1453        /**
1454         * Secure port of the GTalk server.
1455         */
1456        public static final String GTALK_SERVICE_SECURE_PORT = "gtalk_secure_port";
1457
1458        /**
1459         * The server configurable RMQ acking interval
1460         */
1461        public static final String GTALK_SERVICE_RMQ_ACK_INTERVAL = "gtalk_rmq_ack_interval";
1462
1463        /**
1464         * The minimum reconnect delay for short network outages or when the network is suspended
1465         * due to phone use.
1466         */
1467        public static final String GTALK_SERVICE_MIN_RECONNECT_DELAY_SHORT =
1468                "gtalk_min_reconnect_delay_short";
1469
1470        /**
1471         * The reconnect variant range for short network outages or when the network is suspended
1472         * due to phone use. A random number between 0 and this constant is computed and
1473         * added to {@link #GTALK_SERVICE_MIN_RECONNECT_DELAY_SHORT} to form the initial reconnect
1474         * delay.
1475         */
1476        public static final String GTALK_SERVICE_RECONNECT_VARIANT_SHORT =
1477                "gtalk_reconnect_variant_short";
1478
1479        /**
1480         * The minimum reconnect delay for long network outages
1481         */
1482        public static final String GTALK_SERVICE_MIN_RECONNECT_DELAY_LONG =
1483                "gtalk_min_reconnect_delay_long";
1484
1485        /**
1486         * The reconnect variant range for long network outages.  A random number between 0 and this
1487         * constant is computed and added to {@link #GTALK_SERVICE_MIN_RECONNECT_DELAY_LONG} to
1488         * form the initial reconnect delay.
1489         */
1490        public static final String GTALK_SERVICE_RECONNECT_VARIANT_LONG =
1491                "gtalk_reconnect_variant_long";
1492
1493        /**
1494         * The maximum reconnect delay time, in milliseconds.
1495         */
1496        public static final String GTALK_SERVICE_MAX_RECONNECT_DELAY =
1497                "gtalk_max_reconnect_delay";
1498
1499        /**
1500         * The network downtime that is considered "short" for the above calculations,
1501         * in milliseconds.
1502         */
1503        public static final String GTALK_SERVICE_SHORT_NETWORK_DOWNTIME =
1504                "gtalk_short_network_downtime";
1505
1506        /**
1507         * How frequently we send heartbeat pings to the GTalk server. Receiving a server packet
1508         * will reset the heartbeat timer. The away heartbeat should be used when the user is
1509         * logged into the GTalk app, but not actively using it.
1510         */
1511        public static final String GTALK_SERVICE_AWAY_HEARTBEAT_INTERVAL_MS =
1512                "gtalk_heartbeat_ping_interval_ms";  // keep the string backward compatible
1513
1514        /**
1515         * How frequently we send heartbeat pings to the GTalk server. Receiving a server packet
1516         * will reset the heartbeat timer. The active heartbeat should be used when the user is
1517         * actively using the GTalk app.
1518         */
1519        public static final String GTALK_SERVICE_ACTIVE_HEARTBEAT_INTERVAL_MS =
1520                "gtalk_active_heartbeat_ping_interval_ms";
1521
1522        /**
1523         * How frequently we send heartbeat pings to the GTalk server. Receiving a server packet
1524         * will reset the heartbeat timer. The sync heartbeat should be used when the user isn't
1525         * logged into the GTalk app, but auto-sync is enabled.
1526         */
1527        public static final String GTALK_SERVICE_SYNC_HEARTBEAT_INTERVAL_MS =
1528                "gtalk_sync_heartbeat_ping_interval_ms";
1529
1530        /**
1531         * How frequently we send heartbeat pings to the GTalk server. Receiving a server packet
1532         * will reset the heartbeat timer. The no sync heartbeat should be used when the user isn't
1533         * logged into the GTalk app, and auto-sync is not enabled.
1534         */
1535        public static final String GTALK_SERVICE_NOSYNC_HEARTBEAT_INTERVAL_MS =
1536                "gtalk_nosync_heartbeat_ping_interval_ms";
1537
1538        /**
1539         * How long we wait to receive a heartbeat ping acknowledgement (or another packet)
1540         * from the GTalk server, before deeming the connection dead.
1541         */
1542        public static final String GTALK_SERVICE_HEARTBEAT_ACK_TIMEOUT_MS =
1543                "gtalk_heartbeat_ack_timeout_ms";
1544
1545        /**
1546         * How long after screen is turned off before we consider the user to be idle.
1547         */
1548        public static final String GTALK_SERVICE_IDLE_TIMEOUT_MS =
1549                "gtalk_idle_timeout_ms";
1550
1551        /**
1552         * By default, GTalkService will always connect to the server regardless of the auto-sync
1553         * setting. However, if this parameter is true, then GTalkService will only connect
1554         * if auto-sync is enabled. Using the GTalk app will trigger the connection too.
1555         */
1556        public static final String GTALK_SERVICE_CONNECT_ON_AUTO_SYNC =
1557                "gtalk_connect_on_auto_sync";
1558
1559        /**
1560         * GTalkService holds a wakelock while broadcasting the intent for data message received.
1561         * It then automatically release the wakelock after a timeout. This setting controls what
1562         * the timeout should be.
1563         */
1564        public static final String GTALK_DATA_MESSAGE_WAKELOCK_MS =
1565                "gtalk_data_message_wakelock_ms";
1566
1567        /**
1568         * The socket read timeout used to control how long ssl handshake wait for reads before
1569         * timing out. This is needed so the ssl handshake doesn't hang for a long time in some
1570         * circumstances.
1571         */
1572        public static final String GTALK_SSL_HANDSHAKE_TIMEOUT_MS =
1573                "gtalk_ssl_handshake_timeout_ms";
1574
1575        /**
1576         * How many bytes long a message has to be, in order to be gzipped.
1577         */
1578        public static final String SYNC_MIN_GZIP_BYTES =
1579                "sync_min_gzip_bytes";
1580
1581        /**
1582         * The hash value of the current provisioning settings
1583         */
1584        public static final String PROVISIONING_DIGEST = "digest";
1585
1586        /**
1587         * Provisioning keys to block from server update
1588         */
1589        public static final String PROVISIONING_OVERRIDE = "override";
1590
1591        /**
1592         * "Generic" service name for  authentication requests.
1593         */
1594        public static final String GOOGLE_LOGIN_GENERIC_AUTH_SERVICE
1595                = "google_login_generic_auth_service";
1596
1597        /**
1598         * Frequency in milliseconds at which we should sync the locally installed Vending Machine
1599         * content with the server.
1600         */
1601        public static final String VENDING_SYNC_FREQUENCY_MS = "vending_sync_frequency_ms";
1602
1603        /**
1604         * Support URL that is opened in a browser when user clicks on 'Help and Info' in Vending
1605         * Machine.
1606         */
1607        public static final String VENDING_SUPPORT_URL = "vending_support_url";
1608
1609        /**
1610         * Indicates if Vending Machine requires a SIM to be in the phone to allow a purchase.
1611         *
1612         * true = SIM is required
1613         * false = SIM is not required
1614         */
1615        public static final String VENDING_REQUIRE_SIM_FOR_PURCHASE =
1616                "vending_require_sim_for_purchase";
1617
1618        /**
1619         * The current version id of the Vending Machine terms of service.
1620         */
1621        public static final String VENDING_TOS_VERSION = "vending_tos_version";
1622
1623        /**
1624         * URL that points to the terms of service for Vending Machine.
1625         */
1626        public static final String VENDING_TOS_URL = "vending_tos_url";
1627
1628        /**
1629         * Whether to use sierraqa instead of sierra tokens for the purchase flow in
1630         * Vending Machine.
1631         *
1632         * true = use sierraqa
1633         * false = use sierra (default)
1634         */
1635        public static final String VENDING_USE_CHECKOUT_QA_SERVICE =
1636                "vending_use_checkout_qa_service";
1637
1638        /**
1639         * URL that points to the legal terms of service to display in Settings.
1640         * <p>
1641         * This should be a https URL. For a pretty user-friendly URL, use
1642         * {@link #SETTINGS_TOS_PRETTY_URL}.
1643         */
1644        public static final String SETTINGS_TOS_URL = "settings_tos_url";
1645
1646        /**
1647         * URL that points to the legal terms of service to display in Settings.
1648         * <p>
1649         * This should be a pretty http URL. For the URL the device will access
1650         * via Settings, use {@link #SETTINGS_TOS_URL}.
1651         */
1652        public static final String SETTINGS_TOS_PRETTY_URL = "settings_tos_pretty_url";
1653
1654        /**
1655         * URL that points to the contributors to display in Settings.
1656         * <p>
1657         * This should be a https URL. For a pretty user-friendly URL, use
1658         * {@link #SETTINGS_CONTRIBUTORS_PRETTY_URL}.
1659         */
1660        public static final String SETTINGS_CONTRIBUTORS_URL = "settings_contributors_url";
1661
1662        /**
1663         * URL that points to the contributors to display in Settings.
1664         * <p>
1665         * This should be a pretty http URL. For the URL the device will access
1666         * via Settings, use {@link #SETTINGS_CONTRIBUTORS_URL}.
1667         */
1668        public static final String SETTINGS_CONTRIBUTORS_PRETTY_URL =
1669                "settings_contributors_pretty_url";
1670
1671        /**
1672         * Request an MSISDN token for various Google services.
1673         */
1674        public static final String USE_MSISDN_TOKEN = "use_msisdn_token";
1675
1676        /**
1677         * RSA public key used to encrypt passwords stored in the database.
1678         */
1679        public static final String GLS_PUBLIC_KEY = "google_login_public_key";
1680
1681        /**
1682         * Only check parental control status if this is set to "true".
1683         */
1684        public static final String PARENTAL_CONTROL_CHECK_ENABLED =
1685                "parental_control_check_enabled";
1686
1687
1688        /**
1689         * Duration in which parental control status is valid.
1690         */
1691        public static final String PARENTAL_CONTROL_TIMEOUT_IN_MS =
1692                "parental_control_timeout_in_ms";
1693
1694        /**
1695         * When parental control is off, we expect to get this string from the
1696         * litmus url.
1697         */
1698        public static final String PARENTAL_CONTROL_EXPECTED_RESPONSE =
1699                "parental_control_expected_response";
1700
1701        /**
1702         * When the litmus url returns a 302, declare parental control to be on
1703         * only if the redirect url matches this regular expression.
1704         */
1705        public static final String PARENTAL_CONTROL_REDIRECT_REGEX =
1706                "parental_control_redirect_regex";
1707
1708        /**
1709         * Threshold for the amount of change in disk free space required to report the amount of
1710         * free space. Used to prevent spamming the logs when the disk free space isn't changing
1711         * frequently.
1712         */
1713        public static final String DISK_FREE_CHANGE_REPORTING_THRESHOLD =
1714                "disk_free_change_reporting_threshold";
1715
1716        /**
1717         * Prefix for new Google services published by the checkin
1718         * server.
1719         */
1720        public static final String GOOGLE_SERVICES_PREFIX
1721                = "google_services:";
1722
1723        /**
1724         * The maximum reconnect delay for short network outages or when the network is suspended
1725         * due to phone use.
1726         */
1727        public static final String SYNC_MAX_RETRY_DELAY_IN_SECONDS =
1728                "sync_max_retry_delay_in_seconds";
1729
1730        /**
1731         * Minimum percentage of free storage on the device that is used to determine if
1732         * the device is running low on storage.
1733         * Say this value is set to 10, the device is considered running low on storage
1734         * if 90% or more of the device storage is filled up.
1735         */
1736        public static final String SYS_STORAGE_THRESHOLD_PERCENTAGE =
1737                "sys_storage_threshold_percentage";
1738
1739        /**
1740         * The interval in minutes after which the amount of free storage left on the
1741         * device is logged to the event log
1742         */
1743        public static final String SYS_FREE_STORAGE_LOG_INTERVAL =
1744                "sys_free_storage_log_interval";
1745
1746        /**
1747         * The interval in milliseconds at which to check packet counts on the
1748         * mobile data interface when screen is on, to detect possible data
1749         * connection problems.
1750         */
1751        public static final String PDP_WATCHDOG_POLL_INTERVAL_MS =
1752                "pdp_watchdog_poll_interval_ms";
1753
1754        /**
1755         * The interval in milliseconds at which to check packet counts on the
1756         * mobile data interface when screen is off, to detect possible data
1757         * connection problems.
1758         */
1759        public static final String PDP_WATCHDOG_LONG_POLL_INTERVAL_MS =
1760            "pdp_watchdog_long_poll_interval_ms";
1761
1762        /**
1763         * The interval in milliseconds at which to check packet counts on the
1764         * mobile data interface after {@link #PDP_WATCHDOG_TRIGGER_PACKET_COUNT}
1765         * outgoing packets has been reached without incoming packets.
1766         */
1767        public static final String PDP_WATCHDOG_ERROR_POLL_INTERVAL_MS =
1768                "pdp_watchdog_error_poll_interval_ms";
1769
1770        /**
1771         * The number of outgoing packets sent without seeing an incoming packet
1772         * that triggers a countdown (of {@link #PDP_WATCHDOG_ERROR_POLL_COUNT}
1773         * device is logged to the event log
1774         */
1775        public static final String PDP_WATCHDOG_TRIGGER_PACKET_COUNT =
1776                "pdp_watchdog_trigger_packet_count";
1777
1778        /**
1779         * The number of polls to perform (at {@link #PDP_WATCHDOG_ERROR_POLL_INTERVAL_MS})
1780         * after hitting {@link #PDP_WATCHDOG_TRIGGER_PACKET_COUNT} before
1781         * attempting data connection recovery.
1782         */
1783        public static final String PDP_WATCHDOG_ERROR_POLL_COUNT =
1784                "pdp_watchdog_error_poll_count";
1785
1786        /**
1787         * The number of failed PDP reset attempts before moving to something more
1788         * drastic: re-registering to the network.
1789         */
1790        public static final String PDP_WATCHDOG_MAX_PDP_RESET_FAIL_COUNT =
1791                "pdp_watchdog_max_pdp_reset_fail_count";
1792
1793        /**
1794         * Address to ping as a last sanity check before attempting any recovery.
1795         * Unset or set to "0.0.0.0" to skip this check.
1796         */
1797        public static final String PDP_WATCHDOG_PING_ADDRESS =
1798                "pdp_watchdog_ping_address";
1799
1800        /**
1801         * The "-w deadline" parameter for the ping, ie, the max time in
1802         * seconds to spend pinging.
1803         */
1804        public static final String PDP_WATCHDOG_PING_DEADLINE =
1805                "pdp_watchdog_ping_deadline";
1806
1807        /**
1808         * The interval in milliseconds after which Wi-Fi is considered idle.
1809         * When idle, it is possible for the device to be switched from Wi-Fi to
1810         * the mobile data network.
1811         */
1812        public static final String WIFI_IDLE_MS = "wifi_idle_ms";
1813
1814        /**
1815         * The interval in milliseconds at which we forcefully release the
1816         * transition-to-mobile-data wake lock.
1817         */
1818        public static final String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS =
1819                "wifi_mobile_data_transition_wakelock_timeout_ms";
1820
1821        /**
1822         * The maximum number of times we will retry a connection to an access
1823         * point for which we have failed in acquiring an IP address from DHCP.
1824         * A value of N means that we will make N+1 connection attempts in all.
1825         */
1826        public static final String WIFI_MAX_DHCP_RETRY_COUNT = "wifi_max_dhcp_retry_count";
1827
1828        /**
1829         * @deprecated
1830         * @hide
1831         */
1832        @Deprecated  // Obviated by NameValueCache: just fetch the value directly.
1833        public static class QueryMap extends ContentQueryMap {
1834
1835            public QueryMap(ContentResolver contentResolver, Cursor cursor, boolean keepUpdated,
1836                    Handler handlerForUpdateNotifications) {
1837                super(cursor, NAME, keepUpdated, handlerForUpdateNotifications);
1838            }
1839
1840            public QueryMap(ContentResolver contentResolver, boolean keepUpdated,
1841                    Handler handlerForUpdateNotifications) {
1842                this(contentResolver,
1843                        contentResolver.query(CONTENT_URI, null, null, null, null),
1844                        keepUpdated, handlerForUpdateNotifications);
1845            }
1846
1847            public String getString(String name) {
1848                ContentValues cv = getValues(name);
1849                if (cv == null) return null;
1850                return cv.getAsString(VALUE);
1851            }
1852        }
1853
1854    }
1855
1856    /**
1857     * User-defined bookmarks and shortcuts.  The target of each bookmark is an
1858     * Intent URL, allowing it to be either a web page or a particular
1859     * application activity.
1860     *
1861     * @hide
1862     */
1863    public static final class Bookmarks implements BaseColumns
1864    {
1865        private static final String TAG = "Bookmarks";
1866
1867        /**
1868         * The content:// style URL for this table
1869         */
1870        public static final Uri CONTENT_URI =
1871            Uri.parse("content://" + AUTHORITY + "/bookmarks");
1872
1873        /**
1874         * The row ID.
1875         * <p>Type: INTEGER</p>
1876         */
1877        public static final String ID = "_id";
1878
1879        /**
1880         * Descriptive name of the bookmark that can be displayed to the user.
1881         * <P>Type: TEXT</P>
1882         */
1883        public static final String TITLE = "title";
1884
1885        /**
1886         * Arbitrary string (displayed to the user) that allows bookmarks to be
1887         * organized into categories.  There are some special names for
1888         * standard folders, which all start with '@'.  The label displayed for
1889         * the folder changes with the locale (via {@link #labelForFolder}) but
1890         * the folder name does not change so you can consistently query for
1891         * the folder regardless of the current locale.
1892         *
1893         * <P>Type: TEXT</P>
1894         *
1895         */
1896        public static final String FOLDER = "folder";
1897
1898        /**
1899         * The Intent URL of the bookmark, describing what it points to.  This
1900         * value is given to {@link android.content.Intent#getIntent} to create
1901         * an Intent that can be launched.
1902         * <P>Type: TEXT</P>
1903         */
1904        public static final String INTENT = "intent";
1905
1906        /**
1907         * Optional shortcut character associated with this bookmark.
1908         * <P>Type: INTEGER</P>
1909         */
1910        public static final String SHORTCUT = "shortcut";
1911
1912        /**
1913         * The order in which the bookmark should be displayed
1914         * <P>Type: INTEGER</P>
1915         */
1916        public static final String ORDERING = "ordering";
1917
1918        private static final String[] sIntentProjection = { INTENT };
1919        private static final String[] sShortcutProjection = { ID, SHORTCUT };
1920        private static final String sShortcutSelection = SHORTCUT + "=?";
1921
1922        /**
1923         * Convenience function to retrieve the bookmarked Intent for a
1924         * particular shortcut key.
1925         *
1926         * @param cr The ContentResolver to query.
1927         * @param shortcut The shortcut key.
1928         *
1929         * @return Intent The bookmarked URL, or null if there is no bookmark
1930         *         matching the given shortcut.
1931         */
1932        public static Intent getIntentForShortcut(ContentResolver cr, char shortcut)
1933        {
1934            Intent intent = null;
1935
1936            Cursor c = cr.query(CONTENT_URI,
1937                    sIntentProjection, sShortcutSelection,
1938                    new String[] { String.valueOf((int) shortcut) }, ORDERING);
1939            // Keep trying until we find a valid shortcut
1940            try {
1941                while (intent == null && c.moveToNext()) {
1942                    try {
1943                        String intentURI = c.getString(c.getColumnIndexOrThrow(INTENT));
1944                        intent = Intent.getIntent(intentURI);
1945                    } catch (java.net.URISyntaxException e) {
1946                        // The stored URL is bad...  ignore it.
1947                    } catch (IllegalArgumentException e) {
1948                        // Column not found
1949                        Log.e(TAG, "Intent column not found", e);
1950                    }
1951                }
1952            } finally {
1953                if (c != null) c.close();
1954            }
1955
1956            return intent;
1957        }
1958
1959        /**
1960         * Add a new bookmark to the system.
1961         *
1962         * @param cr The ContentResolver to query.
1963         * @param intent The desired target of the bookmark.
1964         * @param title Bookmark title that is shown to the user; null if none.
1965         * @param folder Folder in which to place the bookmark; null if none.
1966         * @param shortcut Shortcut that will invoke the bookmark; 0 if none.
1967         *                 If this is non-zero and there is an existing
1968         *                 bookmark entry with this same shortcut, then that
1969         *                 existing shortcut is cleared (the bookmark is not
1970         *                 removed).
1971         *
1972         * @return The unique content URL for the new bookmark entry.
1973         */
1974        public static Uri add(ContentResolver cr,
1975                                           Intent intent,
1976                                           String title,
1977                                           String folder,
1978                                           char shortcut,
1979                                           int ordering)
1980        {
1981            // If a shortcut is supplied, and it is already defined for
1982            // another bookmark, then remove the old definition.
1983            if (shortcut != 0) {
1984                Cursor c = cr.query(CONTENT_URI,
1985                        sShortcutProjection, sShortcutSelection,
1986                        new String[] { String.valueOf((int) shortcut) }, null);
1987                try {
1988                    if (c.moveToFirst()) {
1989                        while (c.getCount() > 0) {
1990                            if (!c.deleteRow()) {
1991                                Log.w(TAG, "Could not delete existing shortcut row");
1992                            }
1993                        }
1994                    }
1995                } finally {
1996                    if (c != null) c.close();
1997                }
1998            }
1999
2000            ContentValues values = new ContentValues();
2001            if (title != null) values.put(TITLE, title);
2002            if (folder != null) values.put(FOLDER, folder);
2003            values.put(INTENT, intent.toURI());
2004            if (shortcut != 0) values.put(SHORTCUT, (int) shortcut);
2005            values.put(ORDERING, ordering);
2006            return cr.insert(CONTENT_URI, values);
2007        }
2008
2009        /**
2010         * Return the folder name as it should be displayed to the user.  This
2011         * takes care of localizing special folders.
2012         *
2013         * @param r Resources object for current locale; only need access to
2014         *          system resources.
2015         * @param folder The value found in the {@link #FOLDER} column.
2016         *
2017         * @return CharSequence The label for this folder that should be shown
2018         *         to the user.
2019         */
2020        public static CharSequence labelForFolder(Resources r, String folder) {
2021            return folder;
2022        }
2023    }
2024
2025    /**
2026     * Returns the GTalk JID resource associated with this device.
2027     *
2028     * @return  String  the JID resource of the device. It uses the device IMEI in the computation
2029     * of the JID resource. If IMEI is not ready (i.e. telephony module not ready), we'll return
2030     * an empty string.
2031     * @hide
2032     */
2033    // TODO: we shouldn't not have a permenant Jid resource, as that's an easy target for
2034    // spams. We should change it once a while, like when we resubscribe to the subscription feeds
2035    // server.
2036    // (also, should this live in GTalkService?)
2037    public static synchronized String getJidResource() {
2038        if (sJidResource != null) {
2039            return sJidResource;
2040        }
2041
2042        MessageDigest digest;
2043        try {
2044            digest = MessageDigest.getInstance("SHA-1");
2045        } catch (NoSuchAlgorithmException e) {
2046            throw new RuntimeException("this should never happen");
2047        }
2048
2049        String imei = TelephonyManager.getDefault().getDeviceId();
2050        if (TextUtils.isEmpty(imei)) {
2051            return "";
2052        }
2053
2054        byte[] hashedImei = digest.digest(imei.getBytes());
2055        String id = new String(Base64.encodeBase64(hashedImei), 0, 12);
2056        id = id.replaceAll("/", "_");
2057        sJidResource = JID_RESOURCE_PREFIX + id;
2058        return sJidResource;
2059    }
2060
2061    /**
2062     * Returns the device ID that we should use when connecting to the mobile gtalk server.
2063     * This is a string like "android-0x1242", where the hex string is the Android ID obtained
2064     * from the GoogleLoginService.
2065     *
2066     * @param androidId The Android ID for this device.
2067     * @return The device ID that should be used when connecting to the mobile gtalk server.
2068     * @hide
2069     */
2070    public static String getGTalkDeviceId(long androidId) {
2071        return "android-" + Long.toHexString(androidId);
2072    }
2073}
2074