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

Commit cf6d8410 authored by Ben Lin's avatar Ben Lin
Browse files

Don't add any trust agents if the controller is not available.

TrustAgentListPreferenceController gets a list of trust agents and add
them to the security_category preference category at runtime. However,
this update process is always ran - even if the controller is explicitly
disabled/not available. This fixes this.

Bug: None
Test: Updated TrustAgentListPreferenceControllerTest.
Change-Id: Ic95d219bc1d0c7cfa0c4eed0d3dd12dec0e14df6
parent dd1e1e1d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -146,6 +146,10 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
                mSecurityCategory.removePreference(oldAgent);
            }
        }
        // If for some reason the preference is no longer available, don't proceed to add.
        if (!isAvailable()) {
            return;
        }
        // Then add new ones.
        final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
        final List<TrustAgentManager.TrustAgentComponentInfo> agents =
+21 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -141,4 +142,24 @@ public class TrustAgentListPreferenceControllerTest {

        verify(mCategory, atLeastOnce()).addPreference(any(Preference.class));
    }

    @Test
    @Config(qualifiers = "mcc999")
    public void onResume_ifNotAvailable_shouldNotAddNewAgents() {
        final List<TrustAgentManager.TrustAgentComponentInfo> agents = new ArrayList<>();
        final TrustAgentManager.TrustAgentComponentInfo agent = mock(
                TrustAgentManager.TrustAgentComponentInfo.class);
        agent.title = "Test_title";
        agent.summary = "test summary";
        agent.componentName = new ComponentName("pkg", "agent");
        agent.admin = null;
        agents.add(agent);
        when(mTrustAgentManager.getActiveTrustAgents(mActivity, mLockPatternUtils))
                .thenReturn(agents);

        mController.displayPreference(mScreen);
        mController.onResume();

        verify(mCategory, never()).addPreference(any(Preference.class));
    }
}