Fix trust agent summary not being updated.
- move the handling for enabling the trust agent preference and its summary from displayPreference() into updateState(), so that when user navigates to change screen lock or update trust agent and returns to the security settings page, the trust agent preference enabled state and summary will be refreshed correctly. Change-Id: I60bccfdff755a046a9f5453d39a7ac9d3ce0277c Fixes: 72420147 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -20,7 +20,6 @@ import android.content.Context;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -52,21 +51,18 @@ public class ManageTrustAgentsPreferenceController extends BasePreferenceControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
public void updateState(Preference preference) {
|
||||||
super.displayPreference(screen);
|
|
||||||
final Preference preference = screen.findPreference(getPreferenceKey());
|
|
||||||
if (preference == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int numberOfTrustAgent = getTrustAgentCount();
|
final int numberOfTrustAgent = getTrustAgentCount();
|
||||||
if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
|
if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
|
||||||
preference.setEnabled(false);
|
preference.setEnabled(false);
|
||||||
preference.setSummary(R.string.disabled_because_no_backup_security);
|
preference.setSummary(R.string.disabled_because_no_backup_security);
|
||||||
} else if (numberOfTrustAgent > 0) {
|
} else if (numberOfTrustAgent > 0) {
|
||||||
|
preference.setEnabled(true);
|
||||||
preference.setSummary(mContext.getResources().getQuantityString(
|
preference.setSummary(mContext.getResources().getQuantityString(
|
||||||
R.plurals.manage_trust_agents_summary_on,
|
R.plurals.manage_trust_agents_summary_on,
|
||||||
numberOfTrustAgent, numberOfTrustAgent));
|
numberOfTrustAgent, numberOfTrustAgent));
|
||||||
} else {
|
} else {
|
||||||
|
preference.setEnabled(true);
|
||||||
preference.setSummary(R.string.manage_trust_agents_summary);
|
preference.setSummary(R.string.manage_trust_agents_summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,14 +16,12 @@
|
|||||||
|
|
||||||
package com.android.settings.security.trustagent;
|
package com.android.settings.security.trustagent;
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.Context;
|
import android.content.Context;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -50,8 +48,6 @@ public class ManageTrustAgentsPreferenceControllerTest {
|
|||||||
private TrustAgentManager mTrustAgentManager;
|
private TrustAgentManager mTrustAgentManager;
|
||||||
@Mock
|
@Mock
|
||||||
private LockPatternUtils mLockPatternUtils;
|
private LockPatternUtils mLockPatternUtils;
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
|
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -70,8 +66,6 @@ public class ManageTrustAgentsPreferenceControllerTest {
|
|||||||
mController = new ManageTrustAgentsPreferenceController(mContext);
|
mController = new ManageTrustAgentsPreferenceController(mContext);
|
||||||
mPreference = new Preference(mContext);
|
mPreference = new Preference(mContext);
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
|
||||||
.thenReturn(mPreference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -86,10 +80,10 @@ public class ManageTrustAgentsPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_isNotSecure_shouldDisablePreference() {
|
public void updateState_isNotSecure_shouldDisablePreference() {
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
assertThat(mPreference.getSummary())
|
assertThat(mPreference.getSummary())
|
||||||
@@ -97,12 +91,12 @@ public class ManageTrustAgentsPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_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(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
|
||||||
.thenReturn(new ArrayList<>());
|
.thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isTrue();
|
assertThat(mPreference.isEnabled()).isTrue();
|
||||||
assertThat(mPreference.getSummary())
|
assertThat(mPreference.getSummary())
|
||||||
@@ -110,12 +104,12 @@ public class ManageTrustAgentsPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_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(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
|
||||||
.thenReturn(Arrays.asList(new TrustAgentManager.TrustAgentComponentInfo()));
|
.thenReturn(Arrays.asList(new TrustAgentManager.TrustAgentComponentInfo()));
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isTrue();
|
assertThat(mPreference.isEnabled()).isTrue();
|
||||||
assertThat(mPreference.getSummary())
|
assertThat(mPreference.getSummary())
|
||||||
|
Reference in New Issue
Block a user