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