From 1867db33c9f25af1dcd66e211a2aba6a126c2264 Mon Sep 17 00:00:00 2001 From: Alex Johnston Date: Tue, 21 Jan 2020 12:10:50 +0000 Subject: [PATCH] Prevent location for the work profile from being enabled * Previously the user could still enable location for the work profile even after enabling DISALLOW_CONFIG_LOCATION. This was because the LocationForWorkPreferenceController checked whether the base restriction was set and whether the restriction was enforced by the admin in the same condition. * This was fixed by giving the admin precedence and moving the check for the base restriction to only be checked if the admin has not enforced the DISALLOW_CONFIG_LOCATION or DISALLOW_SHARING_LOCATION restriction. Bug: 147758996 Test: Manual testing with Settings and TestDPC atest com.android.settings.location.LocationForWorkPreferenceControllerTest Change-Id: Ide341f2dab4f59f26ffa0c929ba412d61b6ebf1a --- .../LocationForWorkPreferenceController.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/com/android/settings/location/LocationForWorkPreferenceController.java b/src/com/android/settings/location/LocationForWorkPreferenceController.java index 81639346db4..41d26ef3d49 100644 --- a/src/com/android/settings/location/LocationForWorkPreferenceController.java +++ b/src/com/android/settings/location/LocationForWorkPreferenceController.java @@ -67,21 +67,22 @@ public class LocationForWorkPreferenceController extends LocationBasePreferenceC final RestrictedLockUtils.EnforcedAdmin admin = mLocationEnabler.getShareLocationEnforcedAdmin( Utils.getManagedProfile(mUserManager).getIdentifier()); - final boolean isRestrictedByBase = mLocationEnabler.isManagedProfileRestrictedByBase(); - if (!isRestrictedByBase && admin != null) { + if (admin != null) { mPreference.setDisabledByAdmin(admin); - mPreference.setChecked(false); } else { final boolean enabled = mLocationEnabler.isEnabled(mode); mPreference.setEnabled(enabled); + int summaryResId; - int summaryResId = R.string.switch_off_text; - if (!enabled) { + final boolean isRestrictedByBase = + mLocationEnabler.isManagedProfileRestrictedByBase(); + if (isRestrictedByBase || !enabled) { mPreference.setChecked(false); + summaryResId = enabled ? R.string.switch_off_text + : R.string.location_app_permission_summary_location_off; } else { - mPreference.setChecked(!isRestrictedByBase); - summaryResId = (isRestrictedByBase ? - R.string.switch_off_text : R.string.switch_on_text); + mPreference.setChecked(true); + summaryResId = R.string.switch_on_text; } mPreference.setSummary(summaryResId); }