import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
-import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.CarrierConfigManager;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
-import com.android.settings.search2.SearchFeatureProvider;
import com.android.settings.security.OwnerInfoPreferenceController;
import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.trustagent.TrustAgentManager;
private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
private static final String KEY_SECURITY_CATEGORY = "security_category";
- private static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents";
+ @VisibleForTesting
+ static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents";
private static final String KEY_UNIFICATION = "unification";
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
mIsAdmin = mUm.isAdminUser();
// Fingerprint and trust agents
+ int numberOfTrustAgent = 0;
PreferenceGroup securityCategory = (PreferenceGroup)
root.findPreference(KEY_SECURITY_CATEGORY);
if (securityCategory != null) {
maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
- addTrustAgentSettings(securityCategory);
+ numberOfTrustAgent = addTrustAgentSettings(securityCategory);
}
mVisiblePatternProfile =
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
// Advanced Security features
- Preference manageAgents = root.findPreference(KEY_MANAGE_TRUST_AGENTS);
- if (manageAgents != null && !mLockPatternUtils.isSecure(MY_USER_ID)) {
- manageAgents.setEnabled(false);
- manageAgents.setSummary(R.string.disabled_because_no_backup_security);
- }
+ initTrustAgentPreference(root, numberOfTrustAgent);
// The above preferences come and go based on security state, so we need to update
// the index. This call is expected to be fairly cheap, but we may want to do something
return root;
}
+ @VisibleForTesting
+ void initTrustAgentPreference(PreferenceScreen root, int numberOfTrustAgent) {
+ Preference manageAgents = root.findPreference(KEY_MANAGE_TRUST_AGENTS);
+ if (manageAgents != null) {
+ if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
+ manageAgents.setEnabled(false);
+ manageAgents.setSummary(R.string.disabled_because_no_backup_security);
+ } else if (numberOfTrustAgent > 0) {
+ manageAgents.setSummary(getActivity().getResources().getQuantityString(
+ R.plurals.manage_trust_agents_summary_on,
+ numberOfTrustAgent, numberOfTrustAgent));
+ } else {
+ manageAgents.setSummary(R.string.manage_trust_agents_summary);
+ }
+ }
+ }
+
/*
* Sets the preference as disabled by admin if PASSWORD_QUALITY_MANAGED is set.
* The preference must be a RestrictedPreference.
}
}
- private void addTrustAgentSettings(PreferenceGroup securityCategory) {
+ // Return the number of trust agents being added
+ private int addTrustAgentSettings(PreferenceGroup securityCategory) {
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
ArrayList<TrustAgentComponentInfo> agents = getActiveTrustAgents(
getActivity(), mTrustAgentManager, mLockPatternUtils, mDPM);
trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
}
}
+ return agents.size();
}
/* Return true if a there is a Slot that has Icc.
package com.android.settings;
+import android.app.Activity;
import android.content.Context;
import android.content.IContentProvider;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import com.android.internal.widget.LockPatternUtils;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
import java.util.Map;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
verify(mContext).getString(R.string.security_dashboard_summary);
}
-
@Test
public void testGetPackageVerifierSummary_nullInput() {
assertThat(mSummaryProvider.getPackageVerifierSummary(null)).isNull();
assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory))
.isEqualTo(MOCK_SUMMARY);
}
+
+ @Test
+ public void testInitTrustAgentPreference_secure_shouldSetSummaryToNumberOfTrustAgent() {
+ final Preference preference = mock(Preference.class);
+ final PreferenceScreen screen = mock(PreferenceScreen.class);
+ when(screen.findPreference(SecuritySettings.KEY_MANAGE_TRUST_AGENTS))
+ .thenReturn(preference);
+ final LockPatternUtils utils = mock(LockPatternUtils.class);
+ when(utils.isSecure(anyInt())).thenReturn(true);
+ final Context context = ShadowApplication.getInstance().getApplicationContext();
+ final Activity activity = mock(Activity.class);
+ when(activity.getResources()).thenReturn(context.getResources());
+ final SecuritySettings securitySettings = spy(new SecuritySettings());
+ when(securitySettings.getActivity()).thenReturn(activity);
+
+ ReflectionHelpers.setField(securitySettings, "mLockPatternUtils", utils);
+
+ securitySettings.initTrustAgentPreference(screen, 0);
+ verify(preference).setSummary(R.string.manage_trust_agents_summary);
+
+ securitySettings.initTrustAgentPreference(screen, 2);
+ verify(preference).setSummary(context.getResources().getQuantityString(
+ R.plurals.manage_trust_agents_summary_on, 2, 2));
+ }
}