DO NOT MERGE Do not clean up global/system settings on package unintalls.

Legacy apps can write their own entries in the system settings and
when they get uninstalled these are hanging around forever polluting
the settings table. We keep track of which settings an app added and
when the app is uninstalled we drop its custom entries. The trouble
was that we did the same thing for global and secure settings with
no explicit list of platform defined settings. Hence, if say a test
signed by the platform certificate touches platform defined global
or secure settings and is then uninstalled, we would drop the platform
defined entries portentially crippling the system.

bug:20113160

Change-Id: Ia21694f6326ad4a1795c4666027b366e26c05a23
(cherry picked from commit b128540dc741c424d4f652419686882b7a3bfa06)
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index 0d61606..1953e75 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -1500,17 +1500,16 @@
         }
 
         public void onPackageRemovedLocked(String packageName, int userId) {
-            final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_OWNER);
-            SettingsState globalSettings = mSettingsStates.get(globalKey);
-            if (globalSettings != null) globalSettings.onPackageRemovedLocked(packageName);
-
-            final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId);
-            SettingsState secureSettings = mSettingsStates.get(secureKey);
-            if (secureSettings != null) secureSettings.onPackageRemovedLocked(packageName);
+            // Global and secure settings are signature protected. Apps signed
+            // by the platform certificate are generally not uninstalled  and
+            // the main exception is tests. We trust components signed
+            // by the platform certificate and do not do a clean up after them.
 
             final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId);
             SettingsState systemSettings = mSettingsStates.get(systemKey);
-            if (systemSettings != null) systemSettings.onPackageRemovedLocked(packageName);
+            if (systemSettings != null) {
+                systemSettings.onPackageRemovedLocked(packageName);
+            }
         }
 
         private SettingsState peekSettingsStateLocked(int key) {