Merge "Fetch active trustagents from LockPatternUtils"

This commit is contained in:
Derek Jedral
2022-02-10 18:17:44 +00:00
committed by Android (Google) Code Review
2 changed files with 5 additions and 12 deletions

View File

@@ -32,14 +32,12 @@ public class ManageTrustAgentsPreferenceController extends BasePreferenceControl
private static final int MY_USER_ID = UserHandle.myUserId(); private static final int MY_USER_ID = UserHandle.myUserId();
private final LockPatternUtils mLockPatternUtils; private final LockPatternUtils mLockPatternUtils;
private TrustAgentManager mTrustAgentManager;
public ManageTrustAgentsPreferenceController(Context context, String key) { public ManageTrustAgentsPreferenceController(Context context, String key) {
super(context, key); super(context, key);
final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context) final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context)
.getSecurityFeatureProvider(); .getSecurityFeatureProvider();
mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context); mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context);
mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
} }
@Override @Override
@@ -66,6 +64,6 @@ public class ManageTrustAgentsPreferenceController extends BasePreferenceControl
} }
private int getTrustAgentCount() { private int getTrustAgentCount() {
return mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils).size(); return mLockPatternUtils.getEnabledTrustAgents(MY_USER_ID).size();
} }
} }

View File

@@ -21,13 +21,13 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.security.trustagent.TrustAgentManager.TrustAgentComponentInfo;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
@@ -45,8 +45,6 @@ import java.util.Collections;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class ManageTrustAgentsPreferenceControllerTest { public class ManageTrustAgentsPreferenceControllerTest {
@Mock
private TrustAgentManager mTrustAgentManager;
@Mock @Mock
private LockPatternUtils mLockPatternUtils; private LockPatternUtils mLockPatternUtils;
@@ -62,8 +60,6 @@ public class ManageTrustAgentsPreferenceControllerTest {
mFeatureFactory = FakeFeatureFactory.setupForTest(); mFeatureFactory = FakeFeatureFactory.setupForTest();
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(mLockPatternUtils); .thenReturn(mLockPatternUtils);
when(mFeatureFactory.securityFeatureProvider.getTrustAgentManager())
.thenReturn(mTrustAgentManager);
mController = new ManageTrustAgentsPreferenceController(mContext, "key"); mController = new ManageTrustAgentsPreferenceController(mContext, "key");
mPreference = new Preference(mContext); mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey()); mPreference.setKey(mController.getPreferenceKey());
@@ -94,8 +90,7 @@ public class ManageTrustAgentsPreferenceControllerTest {
@Test @Test
public void updateState_isSecure_noTrustAgent_shouldShowGenericSummary() { public void updateState_isSecure_noTrustAgent_shouldShowGenericSummary() {
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true); when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils)) when(mLockPatternUtils.getEnabledTrustAgents(anyInt())).thenReturn(new ArrayList<>());
.thenReturn(new ArrayList<>());
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -107,8 +102,8 @@ public class ManageTrustAgentsPreferenceControllerTest {
@Test @Test
public void updateState_isSecure_hasTrustAgent_shouldShowDetailedSummary() { public void updateState_isSecure_hasTrustAgent_shouldShowDetailedSummary() {
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true); when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils)) when(mLockPatternUtils.getEnabledTrustAgents(anyInt())).thenReturn(
.thenReturn(Collections.singletonList(new TrustAgentComponentInfo())); Collections.singletonList(new ComponentName("packageName", "className")));
mController.updateState(mPreference); mController.updateState(mPreference);