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 final LockPatternUtils mLockPatternUtils;
private TrustAgentManager mTrustAgentManager;
public ManageTrustAgentsPreferenceController(Context context, String key) {
super(context, key);
final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context)
.getSecurityFeatureProvider();
mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context);
mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
}
@Override
@@ -66,6 +64,6 @@ public class ManageTrustAgentsPreferenceController extends BasePreferenceControl
}
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.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import androidx.preference.Preference;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.security.trustagent.TrustAgentManager.TrustAgentComponentInfo;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -45,8 +45,6 @@ import java.util.Collections;
@RunWith(RobolectricTestRunner.class)
public class ManageTrustAgentsPreferenceControllerTest {
@Mock
private TrustAgentManager mTrustAgentManager;
@Mock
private LockPatternUtils mLockPatternUtils;
@@ -62,8 +60,6 @@ public class ManageTrustAgentsPreferenceControllerTest {
mFeatureFactory = FakeFeatureFactory.setupForTest();
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(mLockPatternUtils);
when(mFeatureFactory.securityFeatureProvider.getTrustAgentManager())
.thenReturn(mTrustAgentManager);
mController = new ManageTrustAgentsPreferenceController(mContext, "key");
mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
@@ -94,8 +90,7 @@ public class ManageTrustAgentsPreferenceControllerTest {
@Test
public void updateState_isSecure_noTrustAgent_shouldShowGenericSummary() {
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
.thenReturn(new ArrayList<>());
when(mLockPatternUtils.getEnabledTrustAgents(anyInt())).thenReturn(new ArrayList<>());
mController.updateState(mPreference);
@@ -107,8 +102,8 @@ public class ManageTrustAgentsPreferenceControllerTest {
@Test
public void updateState_isSecure_hasTrustAgent_shouldShowDetailedSummary() {
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
.thenReturn(Collections.singletonList(new TrustAgentComponentInfo()));
when(mLockPatternUtils.getEnabledTrustAgents(anyInt())).thenReturn(
Collections.singletonList(new ComponentName("packageName", "className")));
mController.updateState(mPreference);