Fetch active trustagents from LockPatternUtils
LockPatternUtils is what drives the TrustAgentsPreferenceController, and therefore should be used to determine how many active trust agents there are. TrustAgentManager filters on whether preferences are displayable in the advanced settings app, which does not represent if the agent is actually active. Test: make RunSettingsRoboTests Bug: 217217034 Change-Id: I8cae74d322b8e0658aabfe7d4646e9a299af4934
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user