diff --git a/src/com/android/settings/biometrics/face/FaceProfileStatusPreferenceController.java b/src/com/android/settings/biometrics/face/FaceProfileStatusPreferenceController.java index 56b325bdf89..c46ddcf2eea 100644 --- a/src/com/android/settings/biometrics/face/FaceProfileStatusPreferenceController.java +++ b/src/com/android/settings/biometrics/face/FaceProfileStatusPreferenceController.java @@ -19,16 +19,20 @@ package com.android.settings.biometrics.face; import android.content.Context; import android.os.UserHandle; -import com.android.settings.R; - import androidx.preference.Preference; +import com.android.settings.R; + public class FaceProfileStatusPreferenceController extends FaceStatusPreferenceController { private static final String KEY_FACE_SETTINGS = "face_settings_profile"; public FaceProfileStatusPreferenceController(Context context) { - super(context, KEY_FACE_SETTINGS); + this(context, KEY_FACE_SETTINGS); + } + + public FaceProfileStatusPreferenceController(Context context, String key) { + super(context, key); } @Override diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintProfileStatusPreferenceController.java b/src/com/android/settings/biometrics/fingerprint/FingerprintProfileStatusPreferenceController.java index 23873f9cb2b..0d9893d68da 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintProfileStatusPreferenceController.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintProfileStatusPreferenceController.java @@ -25,7 +25,11 @@ public class FingerprintProfileStatusPreferenceController public static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings_profile"; public FingerprintProfileStatusPreferenceController(Context context) { - super(context, KEY_FINGERPRINT_SETTINGS); + this(context, KEY_FINGERPRINT_SETTINGS); + } + + public FingerprintProfileStatusPreferenceController(Context context, String key) { + super(context, key); } @Override diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceController.java b/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceController.java index ca8a98266c7..7575066f4e8 100644 --- a/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceController.java +++ b/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceController.java @@ -28,17 +28,23 @@ public class EnterprisePrivacyPreferenceController extends AbstractPreferenceCon private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy"; private final PrivacyPreferenceControllerHelper mPrivacyPreferenceControllerHelper; + private final String mPreferenceKey; public EnterprisePrivacyPreferenceController(Context context) { - this(Objects.requireNonNull(context), new PrivacyPreferenceControllerHelper(context)); + this(Objects.requireNonNull(context), KEY_ENTERPRISE_PRIVACY); + } + + public EnterprisePrivacyPreferenceController(Context context, String key) { + this(Objects.requireNonNull(context), new PrivacyPreferenceControllerHelper(context), key); } @VisibleForTesting - EnterprisePrivacyPreferenceController( - Context context, PrivacyPreferenceControllerHelper privacyPreferenceControllerHelper) { + EnterprisePrivacyPreferenceController(Context context, + PrivacyPreferenceControllerHelper privacyPreferenceControllerHelper, String key) { super(Objects.requireNonNull(context)); mPrivacyPreferenceControllerHelper = Objects.requireNonNull( privacyPreferenceControllerHelper); + this.mPreferenceKey = key; } @Override @@ -54,6 +60,6 @@ public class EnterprisePrivacyPreferenceController extends AbstractPreferenceCon @Override public String getPreferenceKey() { - return KEY_ENTERPRISE_PRIVACY; + return mPreferenceKey; } } diff --git a/src/com/android/settings/enterprise/FinancedPrivacyPreferenceController.java b/src/com/android/settings/enterprise/FinancedPrivacyPreferenceController.java index aca21b6fcef..dd7b2e7c08b 100644 --- a/src/com/android/settings/enterprise/FinancedPrivacyPreferenceController.java +++ b/src/com/android/settings/enterprise/FinancedPrivacyPreferenceController.java @@ -32,17 +32,23 @@ public class FinancedPrivacyPreferenceController extends AbstractPreferenceContr private static final String PREF_KEY_FINANCED_PRIVACY = "financed_privacy"; private final PrivacyPreferenceControllerHelper mPrivacyPreferenceControllerHelper; + private final String mPreferenceKey; public FinancedPrivacyPreferenceController(Context context) { - this(Objects.requireNonNull(context), new PrivacyPreferenceControllerHelper(context)); + this(Objects.requireNonNull(context), PREF_KEY_FINANCED_PRIVACY); + } + + public FinancedPrivacyPreferenceController(Context context, String key) { + this(Objects.requireNonNull(context), new PrivacyPreferenceControllerHelper(context), key); } @VisibleForTesting - FinancedPrivacyPreferenceController( - Context context, PrivacyPreferenceControllerHelper privacyPreferenceControllerHelper) { + FinancedPrivacyPreferenceController(Context context, + PrivacyPreferenceControllerHelper privacyPreferenceControllerHelper, String key) { super(Objects.requireNonNull(context)); mPrivacyPreferenceControllerHelper = Objects.requireNonNull( privacyPreferenceControllerHelper); + this.mPreferenceKey = key; } @Override @@ -57,6 +63,6 @@ public class FinancedPrivacyPreferenceController extends AbstractPreferenceContr @Override public String getPreferenceKey() { - return PREF_KEY_FINANCED_PRIVACY; + return mPreferenceKey; } } diff --git a/src/com/android/settings/security/ChangeProfileScreenLockPreferenceController.java b/src/com/android/settings/security/ChangeProfileScreenLockPreferenceController.java index 8e1a4f8dd8f..d44c100eaa1 100644 --- a/src/com/android/settings/security/ChangeProfileScreenLockPreferenceController.java +++ b/src/com/android/settings/security/ChangeProfileScreenLockPreferenceController.java @@ -37,9 +37,17 @@ public class ChangeProfileScreenLockPreferenceController extends private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile"; + private final String mPreferenceKey; + public ChangeProfileScreenLockPreferenceController(Context context, SettingsPreferenceFragment host) { + this(context, host, KEY_UNLOCK_SET_OR_CHANGE_PROFILE); + } + + public ChangeProfileScreenLockPreferenceController(Context context, + SettingsPreferenceFragment host, String key) { super(context, host); + this.mPreferenceKey = key; } public boolean isAvailable() { @@ -65,7 +73,7 @@ public class ChangeProfileScreenLockPreferenceController extends @Override public String getPreferenceKey() { - return KEY_UNLOCK_SET_OR_CHANGE_PROFILE; + return mPreferenceKey; } @Override diff --git a/src/com/android/settings/security/LockUnificationPreferenceController.java b/src/com/android/settings/security/LockUnificationPreferenceController.java index b6e215c8bf7..2a9fced9973 100644 --- a/src/com/android/settings/security/LockUnificationPreferenceController.java +++ b/src/com/android/settings/security/LockUnificationPreferenceController.java @@ -26,7 +26,6 @@ import android.content.Intent; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; -import android.util.Log; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; @@ -74,6 +73,7 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr private RestrictedSwitchPreference mUnifyProfile; + private final String mPreferenceKey; private LockscreenCredential mCurrentDevicePassword; private LockscreenCredential mCurrentProfilePassword; @@ -82,10 +82,15 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); - mUnifyProfile = screen.findPreference(KEY_UNIFICATION); + mUnifyProfile = screen.findPreference(mPreferenceKey); } public LockUnificationPreferenceController(Context context, SettingsPreferenceFragment host) { + this(context, host, KEY_UNIFICATION); + } + + public LockUnificationPreferenceController( + Context context, SettingsPreferenceFragment host, String key) { super(context); mHost = host; mUm = context.getSystemService(UserManager.class); @@ -96,6 +101,7 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr mProfileUserId = Utils.getManagedProfileId(mUm, MY_USER_ID); mCurrentDevicePassword = LockscreenCredential.createNone(); mCurrentProfilePassword = LockscreenCredential.createNone(); + this.mPreferenceKey = key; } @Override @@ -106,7 +112,7 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr @Override public String getPreferenceKey() { - return KEY_UNIFICATION; + return mPreferenceKey; } @Override diff --git a/src/com/android/settings/security/ScreenPinningPreferenceController.java b/src/com/android/settings/security/ScreenPinningPreferenceController.java index 442380d4925..a5fdf8b29d2 100644 --- a/src/com/android/settings/security/ScreenPinningPreferenceController.java +++ b/src/com/android/settings/security/ScreenPinningPreferenceController.java @@ -27,7 +27,11 @@ public class ScreenPinningPreferenceController extends BasePreferenceController private static final String KEY_SCREEN_PINNING = "screen_pinning_settings"; public ScreenPinningPreferenceController(Context context) { - super(context, KEY_SCREEN_PINNING); + this(context, KEY_SCREEN_PINNING); + } + + public ScreenPinningPreferenceController(Context context, String key) { + super(context, key); } @Override diff --git a/src/com/android/settings/security/SimLockPreferenceController.java b/src/com/android/settings/security/SimLockPreferenceController.java index 03983b532e4..3b8588852e8 100644 --- a/src/com/android/settings/security/SimLockPreferenceController.java +++ b/src/com/android/settings/security/SimLockPreferenceController.java @@ -41,7 +41,11 @@ public class SimLockPreferenceController extends BasePreferenceController { private TelephonyManager mTelephonyManager; public SimLockPreferenceController(Context context) { - super(context, KEY_SIM_LOCK); + this(context, KEY_SIM_LOCK); + } + + public SimLockPreferenceController(Context context, String key) { + super(context, key); mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mCarrierConfigManager = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); diff --git a/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java b/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java index 2db8c241197..64ca8537b56 100644 --- a/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java +++ b/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java @@ -55,9 +55,15 @@ public class VisiblePatternProfilePreferenceController extends TogglePreferenceC this(context, null /* lifecycle */); } - // TODO (b/73074893) Replace this constructor without Lifecycle using setter method instead. public VisiblePatternProfilePreferenceController(Context context, Lifecycle lifecycle) { - super(context, KEY_VISIBLE_PATTERN_PROFILE); + this(context, lifecycle, KEY_VISIBLE_PATTERN_PROFILE); + } + + + // TODO (b/73074893) Replace this constructor without Lifecycle using setter method instead. + public VisiblePatternProfilePreferenceController( + Context context, Lifecycle lifecycle, String key) { + super(context, key); mUm = (UserManager) context.getSystemService(Context.USER_SERVICE); mLockPatternUtils = FeatureFactory.getFactory(context) .getSecurityFeatureProvider() diff --git a/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java b/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java index 056c1f293c2..b0f991efb8c 100644 --- a/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java +++ b/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java @@ -38,7 +38,11 @@ public class ManageTrustAgentsPreferenceController extends BasePreferenceControl private TrustAgentManager mTrustAgentManager; public ManageTrustAgentsPreferenceController(Context context) { - super(context, KEY_MANAGE_TRUST_AGENTS); + this(context, KEY_MANAGE_TRUST_AGENTS); + } + + public ManageTrustAgentsPreferenceController(Context context, String key) { + super(context, key); final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context) .getSecurityFeatureProvider(); mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context); diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintProfileStatusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintProfileStatusPreferenceControllerTest.java index f4410a36bf2..0fa4a9c70ef 100644 --- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintProfileStatusPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintProfileStatusPreferenceControllerTest.java @@ -101,4 +101,16 @@ public class FingerprintProfileStatusPreferenceControllerTest { assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER); } + + @Test + public void getPreferenceKey_byDefault_returnsDefaultValue() { + assertThat(mController.getPreferenceKey()).isEqualTo("fingerprint_settings_profile"); + } + + @Test + public void getPreferenceKey_whenGivenValue_returnsGivenValue() { + mController = new FingerprintProfileStatusPreferenceController(mContext, "key"); + + assertThat(mController.getPreferenceKey()).isEqualTo("key"); + } } diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java index 2bac8f1cebb..afb1971fa8a 100644 --- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java @@ -48,7 +48,7 @@ public class EnterprisePrivacyPreferenceControllerTest { public void setUp() { MockitoAnnotations.initMocks(this); mController = new EnterprisePrivacyPreferenceController( - mContext, mPrivacyPreferenceControllerHelper); + mContext, mPrivacyPreferenceControllerHelper, KEY_ENTERPRISE_PRIVACY); } @Test @@ -90,7 +90,15 @@ public class EnterprisePrivacyPreferenceControllerTest { } @Test - public void testGetPreferenceKey() { + public void getPreferenceKey_byDefault_returnsDefaultValue() { assertThat(mController.getPreferenceKey()).isEqualTo(KEY_ENTERPRISE_PRIVACY); } + + @Test + public void getPreferenceKey_whenGivenValue_returnsGivenValue() { + mController = new EnterprisePrivacyPreferenceController( + mContext, mPrivacyPreferenceControllerHelper, "key"); + + assertThat(mController.getPreferenceKey()).isEqualTo("key"); + } } diff --git a/tests/robotests/src/com/android/settings/enterprise/FinancedPrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/FinancedPrivacyPreferenceControllerTest.java index f8adf6fb6e2..61da68eb036 100644 --- a/tests/robotests/src/com/android/settings/enterprise/FinancedPrivacyPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/FinancedPrivacyPreferenceControllerTest.java @@ -48,7 +48,7 @@ public class FinancedPrivacyPreferenceControllerTest { public void setUp() { MockitoAnnotations.initMocks(this); mController = new FinancedPrivacyPreferenceController( - mContext, mPrivacyPreferenceControllerHelper); + mContext, mPrivacyPreferenceControllerHelper, PREF_KEY_FINANCED_PRIVACY); } @Test @@ -81,7 +81,15 @@ public class FinancedPrivacyPreferenceControllerTest { } @Test - public void testGetPreferenceKey() { + public void getPreferenceKey_byDefault_returnsDefaultValue() { assertThat(mController.getPreferenceKey()).isEqualTo(PREF_KEY_FINANCED_PRIVACY); } + + @Test + public void getPreferenceKey_whenGivenValue_returnsGivenValue() { + mController = new FinancedPrivacyPreferenceController( + mContext, mPrivacyPreferenceControllerHelper, "key"); + + assertThat(mController.getPreferenceKey()).isEqualTo("key"); + } } diff --git a/tests/robotests/src/com/android/settings/security/LockUnificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/LockUnificationPreferenceControllerTest.java index be5593ff97f..8a65e140467 100644 --- a/tests/robotests/src/com/android/settings/security/LockUnificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/security/LockUnificationPreferenceControllerTest.java @@ -98,4 +98,18 @@ public class LockUnificationPreferenceControllerTest { assertThat(mController.isAvailable()).isTrue(); } + + @Test + public void getPreferenceKey_byDefault_returnsDefaultValue() { + init(); + + assertThat(mController.getPreferenceKey()).isEqualTo("unification"); + } + + @Test + public void getPreferenceKey_whenGivenValue_returnsGivenValue() { + mController = new LockUnificationPreferenceController(mContext, mHost, "key"); + + assertThat(mController.getPreferenceKey()).isEqualTo("key"); + } } diff --git a/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java index 9b041d4cc48..f63f4c16a76 100644 --- a/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java @@ -89,4 +89,16 @@ public class ScreenPinningPreferenceControllerTest { assertThat(mPreference.getSummary()) .isEqualTo(mContext.getString(R.string.switch_on_text)); } + + @Test + public void getPreferenceKey_byDefault_returnsDefaultValue() { + assertThat(mController.getPreferenceKey()).isEqualTo("screen_pinning_settings"); + } + + @Test + public void getPreferenceKey_whenGivenValue_returnsGivenValue() { + mController = new ScreenPinningPreferenceController(mContext, "key"); + + assertThat(mController.getPreferenceKey()).isEqualTo("key"); + } } diff --git a/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java index 0ab4256a198..6f9c1baf83f 100644 --- a/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java @@ -65,6 +65,7 @@ public class SimLockPreferenceControllerTest { private SimLockPreferenceController mController; private Preference mPreference; + private Context mContext; @Before public void setUp() { @@ -75,8 +76,9 @@ public class SimLockPreferenceControllerTest { shadowApplication.setSystemService(Context.CARRIER_CONFIG_SERVICE, mCarrierManager); shadowApplication.setSystemService(Context.USER_SERVICE, mUserManager); shadowApplication.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager); - mController = new SimLockPreferenceController(RuntimeEnvironment.application); - mPreference = new Preference(RuntimeEnvironment.application); + mContext = RuntimeEnvironment.application; + mController = new SimLockPreferenceController(mContext); + mPreference = new Preference(mContext); mPreference.setKey(mController.getPreferenceKey()); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); } @@ -136,6 +138,18 @@ public class SimLockPreferenceControllerTest { assertThat(mPreference.isEnabled()).isTrue(); } + @Test + public void getPreferenceKey_byDefault_returnsDefaultValue() { + assertThat(mController.getPreferenceKey()).isEqualTo("sim_lock_settings"); + } + + @Test + public void getPreferenceKey_whenGivenValue_returnsGivenValue() { + mController = new SimLockPreferenceController(mContext, "key"); + + assertThat(mController.getPreferenceKey()).isEqualTo("key"); + } + private void setupMockIcc() { final List subscriptionInfoList = new ArrayList<>(); SubscriptionInfo info = mock(SubscriptionInfo.class); diff --git a/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java index e474b2bf6aa..11d70165794 100644 --- a/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java @@ -115,4 +115,16 @@ public class VisiblePatternProfilePreferenceControllerTest { assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } + + @Test + public void getPreferenceKey_byDefault_returnsDefaultValue() { + assertThat(mController.getPreferenceKey()).isEqualTo("visiblepattern_profile"); + } + + @Test + public void getPreferenceKey_whenGivenValue_returnsGivenValue() { + mController = new VisiblePatternProfilePreferenceController(mContext, mLifecycle, "key"); + + assertThat(mController.getPreferenceKey()).isEqualTo("key"); + } } diff --git a/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java index 9be374c066b..a7a3b643acd 100644 --- a/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java @@ -117,4 +117,16 @@ public class ManageTrustAgentsPreferenceControllerTest { .isEqualTo(mContext.getResources().getQuantityString( R.plurals.manage_trust_agents_summary_on, 1, 1)); } + + @Test + public void getPreferenceKey_byDefault_returnsDefaultValue() { + assertThat(mController.getPreferenceKey()).isEqualTo("manage_trust_agents"); + } + + @Test + public void getPreferenceKey_whenGivenValue_returnsGivenValue() { + mController = new ManageTrustAgentsPreferenceController(mContext, "key"); + + assertThat(mController.getPreferenceKey()).isEqualTo("key"); + } }