Merge "Fix Settings getProfileIdsWithDisabled usage"

This commit is contained in:
TreeHugger Robot
2022-05-06 03:16:37 +00:00
committed by Android (Google) Code Review
7 changed files with 57 additions and 36 deletions

View File

@@ -34,11 +34,11 @@ import static org.mockito.Mockito.when;
import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.widget.LockPatternUtils;
@@ -57,6 +57,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.Arrays;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowUtils.class,
@@ -95,7 +97,7 @@ public class RedactNotificationPreferenceControllerTest {
when(mMockContext.getSystemService(UserManager.class)).thenReturn(mUm);
when(mMockContext.getSystemService(DevicePolicyManager.class)).thenReturn(mDpm);
when(mMockContext.getSystemService(KeyguardManager.class)).thenReturn(mKm);
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {0});
when(mUm.getProfiles(anyInt())).thenReturn(Arrays.asList(new UserInfo(0, "", 0)));
mController = new RedactNotificationPreferenceController(
mMockContext, RedactNotificationPreferenceController.KEY_LOCKSCREEN_REDACT);
@@ -105,7 +107,9 @@ public class RedactNotificationPreferenceControllerTest {
mController.getPreferenceKey())).thenReturn(mPreference);
assertThat(mController.mProfileUserId).isEqualTo(0);
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {0, 10});
when(mUm.getProfiles(anyInt())).thenReturn(Arrays.asList(
new UserInfo(5, "", 0),
new UserInfo(10, "", UserInfo.FLAG_MANAGED_PROFILE | UserInfo.FLAG_PROFILE)));
mWorkController = new RedactNotificationPreferenceController(mMockContext,
RedactNotificationPreferenceController.KEY_LOCKSCREEN_WORK_PROFILE_REDACT);
mWorkPreference = new RestrictedSwitchPreference(mContext);
@@ -137,7 +141,8 @@ public class RedactNotificationPreferenceControllerTest {
@Test
public void getAvailabilityStatus_noWorkProfile() {
// reset controllers with no work profile
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {UserHandle.myUserId()});
when(mUm.getProfiles(anyInt())).thenReturn(Arrays.asList(
new UserInfo(UserHandle.myUserId(), "", 0)));
mWorkController = new RedactNotificationPreferenceController(mMockContext,
RedactNotificationPreferenceController.KEY_LOCKSCREEN_WORK_PROFILE_REDACT);
mController = new RedactNotificationPreferenceController(mMockContext,