Fix Settings getProfileIdsWithDisabled usage

In two places, Settings uses getProfileIdsWithDisabled intending to
restrict itself to *managed* profiles, but actually allows for any type
of profile.

Since the declared intent is to only deal with managed profiles, we
update the code to only consider managed profiles.

On devices that only have managed profiles (currently almost all
devices), this cl is a no-op.

Bug: 230495929
Bug: 230534572
Bug: 170249807
Test: com.android.settings.UtilsTest
Test: make RunSettingsRoboTests -j
Change-Id: Id04d45839ef61080b00ca2f91525718cb3a85120
This commit is contained in:
Adam Bookatz
2022-04-27 12:24:24 -07:00
parent de3a095e2c
commit 8311f68065
7 changed files with 57 additions and 37 deletions

View File

@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -118,6 +119,9 @@ public class LocationInjectedServicesPreferenceControllerTest {
final int fakeWorkProfileId = 123;
ShadowUserManager.getShadow().setProfileIdsWithDisabled(
new int[]{UserHandle.myUserId(), fakeWorkProfileId});
ShadowUserManager.getShadow().addProfile(new UserInfo(UserHandle.myUserId(), "", 0));
ShadowUserManager.getShadow().addProfile(new UserInfo(fakeWorkProfileId, "",
UserInfo.FLAG_MANAGED_PROFILE | UserInfo.FLAG_PROFILE));
// Mock RestrictedLockUtils.checkIfRestrictionEnforced and let it return non-null.
final List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();