move some system services from gservices to secure settings

Change-Id: Ie2dfb99a2b42b2cc9310b858c044d8684e3493fa
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 4b5cff6..9ab14da 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2579,6 +2579,108 @@
         public static final String REBOOT_WINDOW = "reboot_window";
 
         /**
+         * Threshold values for the duration and level of a discharge cycle, under
+         * which we log discharge cycle info.
+         * @hide
+         */
+        public static final String BATTERY_DISCHARGE_DURATION_THRESHOLD =
+                "battery_discharge_duration_threshold";
+        /** @hide */
+        public static final String BATTERY_DISCHARGE_THRESHOLD = "battery_discharge_threshold";
+
+        /**
+         * Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
+         * on application crashes and ANRs. If this is disabled, the crash/ANR dialog
+         * will never display the "Report" button.
+         * Type: int ( 0 = disallow, 1 = allow )
+         * @hide
+         */
+        public static final String SEND_ACTION_APP_ERROR = "send_action_app_error";
+
+        /**
+         * Nonzero causes Log.wtf() to crash.
+         * @hide
+         */
+        public static final String WTF_IS_FATAL = "wtf_is_fatal";
+
+        /**
+         * Maximum age of entries kept by {@link android.os.IDropBox}.
+         * @hide
+         */
+        public static final String DROPBOX_AGE_SECONDS =
+                "dropbox_age_seconds";
+        /**
+         * Maximum amount of disk space used by {@link android.os.IDropBox} no matter what.
+         * @hide
+         */
+        public static final String DROPBOX_QUOTA_KB =
+                "dropbox_quota_kb";
+        /**
+         * Percent of free disk (excluding reserve) which {@link android.os.IDropBox} will use.
+         * @hide
+         */
+        public static final String DROPBOX_QUOTA_PERCENT =
+                "dropbox_quota_percent";
+        /**
+         * Percent of total disk which {@link android.os.IDropBox} will never dip into.
+         * @hide
+         */
+        public static final String DROPBOX_RESERVE_PERCENT =
+                "dropbox_reserve_percent";
+        /**
+         * Prefix for per-tag dropbox disable/enable settings.
+         * @hide
+         */
+        public static final String DROPBOX_TAG_PREFIX =
+                "dropbox:";
+
+
+        /**
+         * Screen timeout in milliseconds corresponding to the
+         * PowerManager's POKE_LOCK_SHORT_TIMEOUT flag (i.e. the fastest
+         * possible screen timeout behavior.)
+         * @hide
+         */
+        public static final String SHORT_KEYLIGHT_DELAY_MS =
+                "short_keylight_delay_ms";
+
+        /**
+         * The interval in minutes after which the amount of free storage left on the
+         * device is logged to the event log
+         * @hide
+         */
+        public static final String SYS_FREE_STORAGE_LOG_INTERVAL =
+                "sys_free_storage_log_interval";
+
+        /**
+         * Threshold for the amount of change in disk free space required to report the amount of
+         * free space. Used to prevent spamming the logs when the disk free space isn't changing
+         * frequently.
+         * @hide
+         */
+        public static final String DISK_FREE_CHANGE_REPORTING_THRESHOLD =
+                "disk_free_change_reporting_threshold";
+
+
+        /**
+         * Minimum percentage of free storage on the device that is used to determine if
+         * the device is running low on storage.
+         * Say this value is set to 10, the device is considered running low on storage
+         * if 90% or more of the device storage is filled up.
+         * @hide
+         */
+        public static final String SYS_STORAGE_THRESHOLD_PERCENTAGE =
+                "sys_storage_threshold_percentage";
+
+        /**
+         * The interval in milliseconds after which Wi-Fi is considered idle.
+         * When idle, it is possible for the device to be switched from Wi-Fi to
+         * the mobile data network.
+         * @hide
+         */
+        public static final String WIFI_IDLE_MS = "wifi_idle_ms";
+
+        /**
          * @hide
          */
         public static final String[] SETTINGS_TO_BACKUP = {
@@ -3431,14 +3533,6 @@
                 "parental_control_redirect_regex";
 
         /**
-         * Threshold for the amount of change in disk free space required to report the amount of
-         * free space. Used to prevent spamming the logs when the disk free space isn't changing
-         * frequently.
-         */
-        public static final String DISK_FREE_CHANGE_REPORTING_THRESHOLD =
-                "disk_free_change_reporting_threshold";
-
-        /**
          * Prefix for new Google services published by the checkin
          * server.
          */
@@ -3453,22 +3547,6 @@
                 "sync_max_retry_delay_in_seconds";
 
         /**
-         * Minimum percentage of free storage on the device that is used to determine if
-         * the device is running low on storage.
-         * Say this value is set to 10, the device is considered running low on storage
-         * if 90% or more of the device storage is filled up.
-         */
-        public static final String SYS_STORAGE_THRESHOLD_PERCENTAGE =
-                "sys_storage_threshold_percentage";
-
-        /**
-         * The interval in minutes after which the amount of free storage left on the
-         * device is logged to the event log
-         */
-        public static final String SYS_FREE_STORAGE_LOG_INTERVAL =
-                "sys_free_storage_log_interval";
-
-        /**
          * The interval in milliseconds at which to check the number of SMS sent
          * out without asking for use permit, to limit the un-authorized SMS
          * usage.
@@ -3552,21 +3630,6 @@
                 "gprs_register_check_period_ms";
 
         /**
-         * The interval in milliseconds after which Wi-Fi is considered idle.
-         * When idle, it is possible for the device to be switched from Wi-Fi to
-         * the mobile data network.
-         */
-        public static final String WIFI_IDLE_MS = "wifi_idle_ms";
-
-        /**
-         * Screen timeout in milliseconds corresponding to the
-         * PowerManager's POKE_LOCK_SHORT_TIMEOUT flag (i.e. the fastest
-         * possible screen timeout behavior.)
-         */
-        public static final String SHORT_KEYLIGHT_DELAY_MS =
-                "short_keylight_delay_ms";
-
-        /**
          * List of test suites (local disk filename) for the automatic instrumentation test runner.
          * The file format is similar to automated_suites.xml, see AutoTesterService.
          * If this setting is missing or empty, the automatic test runner will not start.
@@ -3588,14 +3651,6 @@
 
 
         /**
-         * Threshold values for the duration and level of a discharge cycle, under
-         * which we log discharge cycle info.
-         */
-        public static final String BATTERY_DISCHARGE_DURATION_THRESHOLD =
-                "battery_discharge_duration_threshold";
-        public static final String BATTERY_DISCHARGE_THRESHOLD = "battery_discharge_threshold";
-
-        /**
          * An email address that anr bugreports should be sent to.
          */
         public static final String ANR_BUGREPORT_RECIPIENT = "anr_bugreport_recipient";
@@ -3694,13 +3749,6 @@
          */
         public static final String SEARCH_PER_SOURCE_CONCURRENT_QUERY_LIMIT =
                 "search_per_source_concurrent_query_limit";
-        /**
-         * Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
-         * on application crashes and ANRs. If this is disabled, the crash/ANR dialog
-         * will never display the "Report" button.
-         * Type: int ( 0 = disallow, 1 = allow )
-         */
-        public static final String SEND_ACTION_APP_ERROR = "send_action_app_error";
 
         /**
          * Maximum size of /proc/last_kmsg content to upload after reboot.
@@ -3708,37 +3756,6 @@
         public static final String LAST_KMSG_KB = "last_kmsg_kb";
 
         /**
-         * Maximum age of entries kept by {@link android.os.IDropBox}.
-         */
-        public static final String DROPBOX_AGE_SECONDS =
-                "dropbox_age_seconds";
-        /**
-         * Maximum amount of disk space used by {@link android.os.IDropBox} no matter what.
-         */
-        public static final String DROPBOX_QUOTA_KB =
-                "dropbox_quota_kb";
-        /**
-         * Percent of free disk (excluding reserve) which {@link android.os.IDropBox} will use.
-         */
-        public static final String DROPBOX_QUOTA_PERCENT =
-                "dropbox_quota_percent";
-        /**
-         * Percent of total disk which {@link android.os.IDropBox} will never dip into.
-         */
-        public static final String DROPBOX_RESERVE_PERCENT =
-                "dropbox_reserve_percent";
-        /**
-         * Prefix for per-tag dropbox disable/enable settings.
-         */
-        public static final String DROPBOX_TAG_PREFIX =
-                "dropbox:";
-
-        /**
-         * Nonzero causes Log.wtf() to crash.
-         */
-        public static final String WTF_IS_FATAL = "wtf_is_fatal";
-
-        /**
          * The length of time in milli-seconds that automatic small adjustments to
          * SystemClock are ignored if NITZ_UPDATE_DIFF is not exceeded.
          */
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java
index bdebc8d..f435ebc 100644
--- a/services/java/com/android/server/BatteryService.java
+++ b/services/java/com/android/server/BatteryService.java
@@ -413,10 +413,10 @@
 
     private final void logOutlier(long duration) {
         ContentResolver cr = mContext.getContentResolver();
-        String dischargeThresholdString = Settings.Gservices.getString(cr,
-                Settings.Gservices.BATTERY_DISCHARGE_THRESHOLD);
-        String durationThresholdString = Settings.Gservices.getString(cr,
-                Settings.Gservices.BATTERY_DISCHARGE_DURATION_THRESHOLD);
+        String dischargeThresholdString = Settings.Secure.getString(cr,
+                Settings.Secure.BATTERY_DISCHARGE_THRESHOLD);
+        String durationThresholdString = Settings.Secure.getString(cr,
+                Settings.Secure.BATTERY_DISCHARGE_DURATION_THRESHOLD);
 
         if (dischargeThresholdString != null && durationThresholdString != null) {
             try {
diff --git a/services/java/com/android/server/DeviceStorageMonitorService.java b/services/java/com/android/server/DeviceStorageMonitorService.java
index 8e54c6e..e58d346 100644
--- a/services/java/com/android/server/DeviceStorageMonitorService.java
+++ b/services/java/com/android/server/DeviceStorageMonitorService.java
@@ -34,25 +34,29 @@
 import android.os.StatFs;
 import android.os.SystemClock;
 import android.os.SystemProperties;
-import android.provider.Settings.Gservices;
+import android.provider.Settings;
 import android.util.Config;
 import android.util.EventLog;
 import android.util.Log;
 import android.provider.Settings;
 
 /**
- * This class implements a service to monitor the amount of disk storage space
- * on the device. If the free storage on device is less than a tunable threshold value
- * (default is 10%. this value is a gservices parameter) a low memory notification is
- * displayed to alert the user. If the user clicks on the low memory notification the
- * Application Manager application gets launched to let the user free storage space.
- * Event log events:
- * A low memory event with the free storage on device in bytes  is logged to the event log
- * when the device goes low on storage space.
- * The amount of free storage on the device is periodically logged to the event log. The log
- * interval is a gservices parameter with a default value of 12 hours
- * When the free storage differential goes below a threshold(again a gservices parameter with
- * a default value of 2MB), the free memory is logged to the event log
+ * This class implements a service to monitor the amount of disk
+ * storage space on the device.  If the free storage on device is less
+ * than a tunable threshold value (a secure settings parameter;
+ * default 10%) a low memory notification is displayed to alert the
+ * user. If the user clicks on the low memory notification the
+ * Application Manager application gets launched to let the user free
+ * storage space.
+ *
+ * Event log events: A low memory event with the free storage on
+ * device in bytes is logged to the event log when the device goes low
+ * on storage space.  The amount of free storage on the device is
+ * periodically logged to the event log. The log interval is a secure
+ * settings parameter with a default value of 12 hours.  When the free
+ * storage differential goes below a threshold (again a secure
+ * settings parameter with a default value of 2MB), the free memory is
+ * logged to the event log.
  */
 class DeviceStorageMonitorService extends Binder {
     private static final String TAG = "DeviceStorageMonitorService";
@@ -131,9 +135,9 @@
         if (!"".equals(debugFreeMem)) {
             mFreeMem = Long.parseLong(debugFreeMem);
         }
-        // Read the log interval from Gservices
-        long freeMemLogInterval = Gservices.getLong(mContentResolver,
-                Gservices.SYS_FREE_STORAGE_LOG_INTERVAL,
+        // Read the log interval from secure settings
+        long freeMemLogInterval = Settings.Secure.getLong(mContentResolver,
+                Settings.Secure.SYS_FREE_STORAGE_LOG_INTERVAL,
                 DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000;
         //log the amount of free memory in event log
         long currTime = SystemClock.elapsedRealtime();
@@ -159,9 +163,9 @@
             EventLog.writeEvent(EventLogTags.FREE_STORAGE_LEFT,
                                 mFreeMem, mFreeSystem, mFreeCache);
         }
-        // Read the reporting threshold from Gservices
-        long threshold = Gservices.getLong(mContentResolver,
-                Gservices.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
+        // Read the reporting threshold from secure settings
+        long threshold = Settings.Secure.getLong(mContentResolver,
+                Settings.Secure.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
                 DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD);
         // If mFree changed significantly log the new value
         long delta = mFreeMem - mLastReportedFreeMem;
@@ -247,13 +251,13 @@
 
     /*
      * just query settings to retrieve the memory threshold.
-     * Preferred this over using a ContentObserver since Settings.Gservices caches the value
+     * Preferred this over using a ContentObserver since Settings.Secure caches the value
      * any way
      */
     private long getMemThreshold() {
-        int value = Settings.Gservices.getInt(
+        int value = Settings.Secure.getInt(
                               mContentResolver,
-                              Settings.Gservices.SYS_STORAGE_THRESHOLD_PERCENTAGE,
+                              Settings.Secure.SYS_STORAGE_THRESHOLD_PERCENTAGE,
                               DEFAULT_THRESHOLD_PERCENTAGE);
         if(localLOGV) Log.v(TAG, "Threshold Percentage="+value);
         //evaluate threshold value
diff --git a/services/java/com/android/server/DropBoxManagerService.java b/services/java/com/android/server/DropBoxManagerService.java
index e1db6b6..7a708f9 100644
--- a/services/java/com/android/server/DropBoxManagerService.java
+++ b/services/java/com/android/server/DropBoxManagerService.java
@@ -22,9 +22,11 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.PackageManager;
+import android.database.ContentObserver;
 import android.net.Uri;
 import android.os.Debug;
 import android.os.DropBoxManager;
+import android.os.Handler;
 import android.os.ParcelFileDescriptor;
 import android.os.StatFs;
 import android.os.SystemClock;
@@ -113,14 +115,21 @@
      * @param context to use for receiving free space & gservices intents
      * @param path to store drop box entries in
      */
-    public DropBoxManagerService(Context context, File path) {
+    public DropBoxManagerService(final Context context, File path) {
         mDropBoxDir = path;
 
         // Set up intent receivers
         mContext = context;
         mContentResolver = context.getContentResolver();
         context.registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW));
-        context.registerReceiver(mReceiver, new IntentFilter(Settings.Gservices.CHANGED_ACTION));
+
+        mContentResolver.registerContentObserver(
+            Settings.Secure.CONTENT_URI, true,
+            new ContentObserver(new Handler()) {
+                public void onChange(boolean selfChange) {
+                    mReceiver.onReceive(context, (Intent) null);
+                }
+            });
 
         // The real work gets done lazily in init() -- that way service creation always
         // succeeds, and things like disk problems cause individual method failures.
@@ -205,8 +214,8 @@
     }
 
     public boolean isTagEnabled(String tag) {
-        return !"disabled".equals(Settings.Gservices.getString(
-                mContentResolver, Settings.Gservices.DROPBOX_TAG_PREFIX + tag));
+        return !"disabled".equals(Settings.Secure.getString(
+                mContentResolver, Settings.Secure.DROPBOX_TAG_PREFIX + tag));
     }
 
     public synchronized DropBoxManager.Entry getNextEntry(String tag, long millis) {
@@ -611,8 +620,8 @@
     private synchronized long trimToFit() {
         // Expunge aged items (including tombstones marking deleted data).
 
-        int ageSeconds = Settings.Gservices.getInt(mContentResolver,
-                Settings.Gservices.DROPBOX_AGE_SECONDS, DEFAULT_AGE_SECONDS);
+        int ageSeconds = Settings.Secure.getInt(mContentResolver,
+                Settings.Secure.DROPBOX_AGE_SECONDS, DEFAULT_AGE_SECONDS);
         long cutoffMillis = System.currentTimeMillis() - ageSeconds * 1000;
         while (!mAllFiles.contents.isEmpty()) {
             EntryFile entry = mAllFiles.contents.first();
@@ -631,12 +640,12 @@
 
         long uptimeMillis = SystemClock.uptimeMillis();
         if (uptimeMillis > mCachedQuotaUptimeMillis + QUOTA_RESCAN_MILLIS) {
-            int quotaPercent = Settings.Gservices.getInt(mContentResolver,
-                    Settings.Gservices.DROPBOX_QUOTA_PERCENT, DEFAULT_QUOTA_PERCENT);
-            int reservePercent = Settings.Gservices.getInt(mContentResolver,
-                    Settings.Gservices.DROPBOX_RESERVE_PERCENT, DEFAULT_RESERVE_PERCENT);
-            int quotaKb = Settings.Gservices.getInt(mContentResolver,
-                    Settings.Gservices.DROPBOX_QUOTA_KB, DEFAULT_QUOTA_KB);
+            int quotaPercent = Settings.Secure.getInt(mContentResolver,
+                    Settings.Secure.DROPBOX_QUOTA_PERCENT, DEFAULT_QUOTA_PERCENT);
+            int reservePercent = Settings.Secure.getInt(mContentResolver,
+                    Settings.Secure.DROPBOX_RESERVE_PERCENT, DEFAULT_RESERVE_PERCENT);
+            int quotaKb = Settings.Secure.getInt(mContentResolver,
+                    Settings.Secure.DROPBOX_QUOTA_KB, DEFAULT_QUOTA_KB);
 
             mStatFs.restat(mDropBoxDir.getPath());
             int available = mStatFs.getAvailableBlocks();
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 89261a8..bf6996c 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -29,6 +29,7 @@
 import android.content.IntentFilter;
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
+import android.database.ContentObserver;
 import android.database.Cursor;
 import android.hardware.Sensor;
 import android.hardware.SensorEvent;
@@ -36,9 +37,11 @@
 import android.hardware.SensorManager;
 import android.os.BatteryStats;
 import android.os.Binder;
+import android.os.Environment;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
+import android.os.IMountService;
 import android.os.IPowerManager;
 import android.os.LocalPowerManager;
 import android.os.Power;
@@ -46,8 +49,6 @@
 import android.os.Process;
 import android.os.RemoteException;
 import android.os.ServiceManager;
-import android.os.Environment;
-import android.os.IMountService;
 import android.os.SystemClock;
 import android.provider.Settings.SettingNotFoundException;
 import android.provider.Settings;
@@ -88,7 +89,7 @@
                                         | PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK;
 
     //                       time since last state:               time since last event:
-    // The short keylight delay comes from Gservices; this is the default.
+    // The short keylight delay comes from secure settings; this is the default.
     private static final int SHORT_KEYLIGHT_DELAY_DEFAULT = 6000; // t+6 sec
     private static final int MEDIUM_KEYLIGHT_DELAY = 15000;       // t+15 sec
     private static final int LONG_KEYLIGHT_DELAY = 6000;        // t+6 sec
@@ -103,7 +104,7 @@
     // trigger proximity if distance is less than 5 cm
     private static final float PROXIMITY_THRESHOLD = 5.0f;
 
-    // Cached Gservices settings; see updateGservicesValues()
+    // Cached secure settings; see updateSettingsValues()
     private int mShortKeylightDelay = SHORT_KEYLIGHT_DELAY_DEFAULT;
 
     // flags for setPowerState
@@ -516,12 +517,15 @@
         filter.addAction(Intent.ACTION_BOOT_COMPLETED);
         mContext.registerReceiver(new BootCompletedReceiver(), filter);
 
-        // Listen for Gservices changes
-        IntentFilter gservicesChangedFilter =
-                new IntentFilter(Settings.Gservices.CHANGED_ACTION);
-        mContext.registerReceiver(new GservicesChangedReceiver(), gservicesChangedFilter);
-        // And explicitly do the initial update of our cached settings
-        updateGservicesValues();
+        // Listen for secure settings changes
+        mContext.getContentResolver().registerContentObserver(
+            Settings.Secure.CONTENT_URI, true,
+            new ContentObserver(new Handler()) {
+                public void onChange(boolean selfChange) {
+                    updateSettingsValues();
+                }
+            });
+        updateSettingsValues();
 
         if (mUseSoftwareAutoBrightness) {
             // turn the screen on
@@ -2273,7 +2277,7 @@
      * */
     private void setScreenOffTimeoutsLocked() {
         if ((mPokey & POKE_LOCK_SHORT_TIMEOUT) != 0) {
-            mKeylightDelay = mShortKeylightDelay;  // Configurable via Gservices
+            mKeylightDelay = mShortKeylightDelay;  // Configurable via secure settings
             mDimDelay = -1;
             mScreenOffDelay = 0;
         } else if ((mPokey & POKE_LOCK_MEDIUM_TIMEOUT) != 0) {
@@ -2308,28 +2312,15 @@
     }
 
     /**
-     * Refreshes cached Gservices settings.  Called once on startup, and
-     * on subsequent Settings.Gservices.CHANGED_ACTION broadcasts (see
-     * GservicesChangedReceiver).
+     * Refreshes cached secure settings.  Called once on startup, and
+     * on subsequent changes to secure settings.
      */
-    private void updateGservicesValues() {
-        mShortKeylightDelay = Settings.Gservices.getInt(
+    private void updateSettingsValues() {
+        mShortKeylightDelay = Settings.Secure.getInt(
                 mContext.getContentResolver(),
-                Settings.Gservices.SHORT_KEYLIGHT_DELAY_MS,
+                Settings.Secure.SHORT_KEYLIGHT_DELAY_MS,
                 SHORT_KEYLIGHT_DELAY_DEFAULT);
-        // Log.i(TAG, "updateGservicesValues(): mShortKeylightDelay now " + mShortKeylightDelay);
-    }
-
-    /**
-     * Receiver for the Gservices.CHANGED_ACTION broadcast intent,
-     * which tells us we need to refresh our cached Gservices settings.
-     */
-    private class GservicesChangedReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // Log.i(TAG, "GservicesChangedReceiver.onReceive(): " + intent);
-            updateGservicesValues();
-        }
+        // Log.i(TAG, "updateSettingsValues(): mShortKeylightDelay now " + mShortKeylightDelay);
     }
 
     private class LockList extends ArrayList<WakeLock>
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 987a24e..6fab96b 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -113,8 +113,8 @@
     private final IBatteryStats mBatteryStats;
 
     /**
-     * See {@link Settings.Gservices#WIFI_IDLE_MS}. This is the default value if a
-     * Settings.Gservices value is not present. This timeout value is chosen as
+     * See {@link Settings.Secure#WIFI_IDLE_MS}. This is the default value if a
+     * Settings.Secure value is not present. This timeout value is chosen as
      * the approximate point at which the battery drain caused by Wi-Fi
      * being enabled but not active exceeds the battery drain caused by
      * re-establishing a connection to the mobile data network.
@@ -1317,11 +1317,12 @@
         public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
 
-            long idleMillis = Settings.Gservices.getLong(mContext.getContentResolver(),
-                                                  Settings.Gservices.WIFI_IDLE_MS, DEFAULT_IDLE_MILLIS);
+            long idleMillis =
+                Settings.Secure.getLong(mContext.getContentResolver(),
+                                        Settings.Secure.WIFI_IDLE_MS, DEFAULT_IDLE_MILLIS);
             int stayAwakeConditions =
-                    Settings.System.getInt(mContext.getContentResolver(),
-                                           Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0);
+                Settings.System.getInt(mContext.getContentResolver(),
+                                       Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0);
             if (action.equals(Intent.ACTION_SCREEN_ON)) {
                 Log.d(TAG, "ACTION_SCREEN_ON");
                 mAlarmManager.cancel(mIdleIntent);
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 7f12b6d..172bcdb 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -8579,9 +8579,9 @@
     }
 
     private ComponentName getErrorReportReceiver(ProcessRecord app) {
-        // check if error reporting is enabled in Gservices
-        int enabled = Settings.Gservices.getInt(mContext.getContentResolver(),
-                Settings.Gservices.SEND_ACTION_APP_ERROR, 0);
+        // check if error reporting is enabled in secure settings
+        int enabled = Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.SEND_ACTION_APP_ERROR, 0);
         if (enabled == 0) {
             return null;
         }
@@ -8830,8 +8830,8 @@
 
         addExceptionToDropBox("wtf", r, tag, crashInfo);
 
-        if (Settings.Gservices.getInt(mContext.getContentResolver(),
-                Settings.Gservices.WTF_IS_FATAL, 0) != 0) {
+        if (Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.WTF_IS_FATAL, 0) != 0) {
             crashApplication(r, crashInfo);
             return true;
         } else {
diff --git a/tests/AndroidTests/AndroidManifest.xml b/tests/AndroidTests/AndroidManifest.xml
index 786178c..bdaf6ea 100644
--- a/tests/AndroidTests/AndroidManifest.xml
+++ b/tests/AndroidTests/AndroidManifest.xml
@@ -50,6 +50,7 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.WRITE_GSERVICES" />
     <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
     <uses-permission android:name="android.permission.WRITE_SMS"/>
     <uses-permission android:name="com.android.unit_tests.permission.TEST_GRANTED" />
     <uses-permission android:name="com.google.android.googleapps.permission.ACCESS_GOOGLE_PASSWORD" />
diff --git a/tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java b/tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java
index 305788d..d20abd9 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java
@@ -16,7 +16,7 @@
 
 package com.android.unit_tests;
 
-import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.os.DropBoxManager;
@@ -37,11 +37,10 @@
 /** Test {@link DropBoxManager} functionality. */
 public class DropBoxTest extends AndroidTestCase {
     public void tearDown() throws Exception {
-        Intent override = new Intent(Settings.Gservices.OVERRIDE_ACTION);
-        override.putExtra(Settings.Gservices.DROPBOX_AGE_SECONDS, "");
-        override.putExtra(Settings.Gservices.DROPBOX_QUOTA_KB, "");
-        override.putExtra(Settings.Gservices.DROPBOX_TAG_PREFIX + "DropBoxTest", "");
-        waitForBroadcast(override);
+        ContentResolver cr = getContext().getContentResolver();
+        Settings.Secure.putString(cr, Settings.Secure.DROPBOX_AGE_SECONDS, "");
+        Settings.Secure.putString(cr, Settings.Secure.DROPBOX_QUOTA_KB, "");
+        Settings.Secure.putString(cr, Settings.Secure.DROPBOX_TAG_PREFIX + "DropBoxTest", "");
     }
 
     public void testAddText() throws Exception {
@@ -246,16 +245,15 @@
         dropbox.addText("DropBoxTest", "TEST-ENABLED");
         assertTrue(dropbox.isTagEnabled("DropBoxTest"));
 
-        Intent override = new Intent(Settings.Gservices.OVERRIDE_ACTION);
-        override.putExtra(Settings.Gservices.DROPBOX_TAG_PREFIX + "DropBoxTest", "disabled");
-        waitForBroadcast(override);
+        ContentResolver cr = getContext().getContentResolver();
+        Settings.Secure.putString(cr, Settings.Secure.DROPBOX_TAG_PREFIX + "DropBoxTest",
+                                  "disabled");
 
         dropbox.addText("DropBoxTest", "TEST-DISABLED");
         assertFalse(dropbox.isTagEnabled("DropBoxTest"));
 
-        override = new Intent(Settings.Gservices.OVERRIDE_ACTION);
-        override.putExtra(Settings.Gservices.DROPBOX_TAG_PREFIX + "DropBoxTest", "");
-        waitForBroadcast(override);
+        Settings.Secure.putString(cr, Settings.Secure.DROPBOX_TAG_PREFIX + "DropBoxTest",
+                                  "");
 
         dropbox.addText("DropBoxTest", "TEST-ENABLED-AGAIN");
         assertTrue(dropbox.isTagEnabled("DropBoxTest"));
@@ -323,9 +321,8 @@
 
         // Limit storage to 10 blocks
         int kb = blockSize * 10 / 1024;
-        Intent override = new Intent(Settings.Gservices.OVERRIDE_ACTION);
-        override.putExtra(Settings.Gservices.DROPBOX_QUOTA_KB, Integer.toString(kb));
-        waitForBroadcast(override);
+        ContentResolver cr = getContext().getContentResolver();
+        Settings.Secure.putString(cr, Settings.Secure.DROPBOX_QUOTA_KB, Integer.toString(kb));
 
         // Three tags using a total of 12 blocks:
         // DropBoxTest0 [ ][ ]
@@ -426,10 +423,9 @@
 
         // Limit storage to 10 blocks with an expiration of 1 second
         int kb = blockSize * 10 / 1024;
-        Intent override = new Intent(Settings.Gservices.OVERRIDE_ACTION);
-        override.putExtra(Settings.Gservices.DROPBOX_AGE_SECONDS, "1");
-        override.putExtra(Settings.Gservices.DROPBOX_QUOTA_KB, Integer.toString(kb));
-        waitForBroadcast(override);
+        ContentResolver cr = getContext().getContentResolver();
+        Settings.Secure.putString(cr, Settings.Secure.DROPBOX_AGE_SECONDS, "1");
+        Settings.Secure.putString(cr, Settings.Secure.DROPBOX_QUOTA_KB, Integer.toString(kb));
 
         // Write one normal entry and another so big that it is instantly tombstoned
         long before = System.currentTimeMillis();
@@ -505,15 +501,6 @@
         return length;
     }
 
-    private void waitForBroadcast(Intent intent) throws InterruptedException {
-        BroadcastReceiver receiver = new BroadcastReceiver() {
-            public synchronized void onReceive(Context context, Intent intent) { notify(); }
-        };
-
-        getContext().sendOrderedBroadcast(intent, null, receiver, null, 0, null, null);
-        synchronized (receiver) { receiver.wait(); }
-    }
-
     private void recursiveDelete(File file) {
         if (!file.delete() && file.isDirectory()) {
             for (File f : file.listFiles()) recursiveDelete(f);