Merge "Update summary text for Trust agent." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b9a54bae08
@@ -64,7 +64,6 @@
|
|||||||
|
|
||||||
<Preference android:key="manage_trust_agents"
|
<Preference android:key="manage_trust_agents"
|
||||||
android:title="@string/manage_trust_agents"
|
android:title="@string/manage_trust_agents"
|
||||||
android:summary="@string/manage_trust_agents_summary"
|
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:fragment="com.android.settings.TrustAgentSettings"/>
|
android:fragment="com.android.settings.TrustAgentSettings"/>
|
||||||
|
|
||||||
|
@@ -40,7 +40,6 @@ import android.support.annotation.VisibleForTesting;
|
|||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
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.PreferenceGroup;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
@@ -65,7 +64,6 @@ import com.android.settings.overlay.FeatureFactory;
|
|||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
import com.android.settings.search2.SearchFeatureProvider;
|
|
||||||
import com.android.settings.security.OwnerInfoPreferenceController;
|
import com.android.settings.security.OwnerInfoPreferenceController;
|
||||||
import com.android.settings.security.SecurityFeatureProvider;
|
import com.android.settings.security.SecurityFeatureProvider;
|
||||||
import com.android.settings.trustagent.TrustAgentManager;
|
import com.android.settings.trustagent.TrustAgentManager;
|
||||||
@@ -102,7 +100,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
|
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_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
|
||||||
private static final String KEY_SECURITY_CATEGORY = "security_category";
|
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 String KEY_UNIFICATION = "unification";
|
||||||
|
|
||||||
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
|
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
|
||||||
@@ -312,11 +311,12 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
mIsAdmin = mUm.isAdminUser();
|
mIsAdmin = mUm.isAdminUser();
|
||||||
|
|
||||||
// Fingerprint and trust agents
|
// Fingerprint and trust agents
|
||||||
|
int numberOfTrustAgent = 0;
|
||||||
PreferenceGroup securityCategory = (PreferenceGroup)
|
PreferenceGroup securityCategory = (PreferenceGroup)
|
||||||
root.findPreference(KEY_SECURITY_CATEGORY);
|
root.findPreference(KEY_SECURITY_CATEGORY);
|
||||||
if (securityCategory != null) {
|
if (securityCategory != null) {
|
||||||
maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
|
maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
|
||||||
addTrustAgentSettings(securityCategory);
|
numberOfTrustAgent = addTrustAgentSettings(securityCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
mVisiblePatternProfile =
|
mVisiblePatternProfile =
|
||||||
@@ -351,11 +351,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
|
|
||||||
// Advanced Security features
|
// Advanced Security features
|
||||||
Preference manageAgents = root.findPreference(KEY_MANAGE_TRUST_AGENTS);
|
initTrustAgentPreference(root, numberOfTrustAgent);
|
||||||
if (manageAgents != null && !mLockPatternUtils.isSecure(MY_USER_ID)) {
|
|
||||||
manageAgents.setEnabled(false);
|
|
||||||
manageAgents.setSummary(R.string.disabled_because_no_backup_security);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The above preferences come and go based on security state, so we need to update
|
// 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
|
// the index. This call is expected to be fairly cheap, but we may want to do something
|
||||||
@@ -410,6 +406,23 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
return root;
|
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.
|
* Sets the preference as disabled by admin if PASSWORD_QUALITY_MANAGED is set.
|
||||||
* The preference must be a RestrictedPreference.
|
* The preference must be a RestrictedPreference.
|
||||||
@@ -434,7 +447,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
|
||||||
ArrayList<TrustAgentComponentInfo> agents = getActiveTrustAgents(
|
ArrayList<TrustAgentComponentInfo> agents = getActiveTrustAgents(
|
||||||
getActivity(), mTrustAgentManager, mLockPatternUtils, mDPM);
|
getActivity(), mTrustAgentManager, mLockPatternUtils, mDPM);
|
||||||
@@ -459,6 +473,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
|
trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return agents.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return true if a there is a Slot that has Icc.
|
/* Return true if a there is a Slot that has Icc.
|
||||||
|
@@ -16,13 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.IContentProvider;
|
import android.content.IContentProvider;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.hardware.fingerprint.FingerprintManager;
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
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.dashboard.SummaryLoader;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||||
@@ -39,13 +43,17 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.annotation.Implementation;
|
import org.robolectric.annotation.Implementation;
|
||||||
import org.robolectric.annotation.Implements;
|
import org.robolectric.annotation.Implements;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.isNull;
|
import static org.mockito.Matchers.isNull;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
@@ -121,7 +129,6 @@ public class SecuritySettingsTest {
|
|||||||
verify(mContext).getString(R.string.security_dashboard_summary);
|
verify(mContext).getString(R.string.security_dashboard_summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPackageVerifierSummary_nullInput() {
|
public void testGetPackageVerifierSummary_nullInput() {
|
||||||
assertThat(mSummaryProvider.getPackageVerifierSummary(null)).isNull();
|
assertThat(mSummaryProvider.getPackageVerifierSummary(null)).isNull();
|
||||||
@@ -155,4 +162,28 @@ public class SecuritySettingsTest {
|
|||||||
assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory))
|
assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory))
|
||||||
.isEqualTo(MOCK_SUMMARY);
|
.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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user