Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a03b6695 authored by Derek Jedral's avatar Derek Jedral Committed by Android (Google) Code Review
Browse files

Merge "Fetch active trustagents from LockPatternUtils"

parents 4ed41905 c1c39b67
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -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();
    }
}
+4 −9
Original line number Diff line number Diff line
@@ -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);