From 0b1356ff1f3cd2fd06d770af1ad466822173cc3a Mon Sep 17 00:00:00 2001 From: Suprabh Shukla Date: Tue, 21 Feb 2017 14:33:50 -0800 Subject: [PATCH] Fix 'Modifying dpm.setSecureSetting call for install_non_market_apps' The previous change was reverted as it broke work profile provisioning. Clearing binder calling identity before calling into settings provider should fix the issue. Test: runtest managed-provisioning Test: runtest -x services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java Test: Manually tested that work profile is inflated with expected values of install_non_market_apps Bug: 33947615 Bug: 35590590 Change-Id: I3c31a73fef0c25c0e682e18f637272adad39b28d --- .../app/admin/DevicePolicyManager.java | 10 ++- core/java/android/provider/Settings.java | 12 ++++ .../android/provider/SettingsBackupTest.java | 1 + .../SettingsProvider/res/values/defaults.xml | 2 +- .../providers/settings/SettingsProvider.java | 10 ++- .../InstallNonMarketAppsDeprecationTest.java | 30 ++++++--- .../DevicePolicyManagerService.java | 66 ++++++++++++++++++- 7 files changed, 117 insertions(+), 14 deletions(-) diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 2ace0a211dd67..9cb3dd6e4c0af 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -6343,7 +6343,6 @@ public class DevicePolicyManager { * The settings that can be updated by a profile or device owner with this method are: * *

@@ -6352,6 +6351,15 @@ public class DevicePolicyManager { *

  • {@link Settings.Secure#LOCATION_MODE}
  • * * + * Note: Starting from Android O, apps should no longer call this method with the + * setting {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, which is + * deprecated. Instead, device owners or profile owners should use the restriction + * {@link UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES}. + * If any app targeting {@link android.os.Build.VERSION_CODES#O} or higher calls this method + * with {@link android.provider.Settings.Secure#INSTALL_NON_MARKET_APPS}, + * an {@link UnsupportedOperationException} is thrown. + * + * * @param admin Which {@link DeviceAdminReceiver} this request is associated with. * @param setting The name of the setting to update. * @param value The value to update the setting to. diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index ebc5b88b57987..8aa2b2c1567d9 100755 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -5216,6 +5216,18 @@ public final class Settings { */ public static final String INSTALL_NON_MARKET_APPS = "install_non_market_apps"; + /** + * A flag to tell {@link com.android.server.devicepolicy.DevicePolicyManagerService} that + * the default for {@link #INSTALL_NON_MARKET_APPS} is reversed for this user on OTA. So it + * can set the restriction {@link android.os.UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES} + * on behalf of the profile owner if needed to make the change transparent for profile + * owners. + * + * @hide + */ + public static final String UNKNOWN_SOURCES_DEFAULT_REVERSED = + "unknown_sources_default_reversed"; + /** * Comma-separated list of location providers that activities may access. Do not rely on * this value being present in settings.db or on ContentObserver notifications on the diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java index 76331a865ba31..3584569e95b9b 100644 --- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java +++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java @@ -460,6 +460,7 @@ public class SettingsBackupTest { Settings.Secure.TV_INPUT_CUSTOM_LABELS, Settings.Secure.TV_INPUT_HIDDEN_INPUTS, Settings.Secure.UI_NIGHT_MODE, // candidate? + Settings.Secure.UNKNOWN_SOURCES_DEFAULT_REVERSED, Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, Settings.Secure.USER_SETUP_COMPLETE, diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml index 136f17e5a77c4..720612726a8f5 100644 --- a/packages/SettingsProvider/res/values/defaults.xml +++ b/packages/SettingsProvider/res/values/defaults.xml @@ -38,7 +38,7 @@ true false - true + false true