Merge "Use correct category key for SecurityAdvancedSettings based on the type of active Security Settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
ac06c38866
@@ -25,6 +25,8 @@ import com.android.settings.biometrics.combination.CombinedBiometricProfileStatu
|
||||
import com.android.settings.biometrics.face.FaceProfileStatusPreferenceController;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
@@ -47,6 +49,10 @@ public class SecurityAdvancedSettings extends DashboardFragment {
|
||||
private static final String TAG = "SecurityAdvancedSettings";
|
||||
private static final String WORK_PROFILE_SECURITY_CATEGORY = "security_category_profile";
|
||||
|
||||
/** Used in case of old Security settings when SafetyCenter is disabled */
|
||||
private static final String CATEGORY_SECURITY_LEGACY_ADVANCED_SETTINGS =
|
||||
"com.android.settings.category.ia.legacy_advanced_security";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SECURITY_ADVANCED;
|
||||
@@ -54,7 +60,19 @@ public class SecurityAdvancedSettings extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
public String getCategoryKey() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
return CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS;
|
||||
} else {
|
||||
final SecuritySettingsFeatureProvider securitySettingsFeatureProvider =
|
||||
FeatureFactory.getFactory(getContext())
|
||||
.getSecuritySettingsFeatureProvider();
|
||||
|
||||
if (securitySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()) {
|
||||
return securitySettingsFeatureProvider.getAlternativeAdvancedSettingsCategoryKey();
|
||||
} else {
|
||||
return CATEGORY_SECURITY_LEGACY_ADVANCED_SETTINGS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -24,4 +24,10 @@ public interface SecuritySettingsFeatureProvider {
|
||||
|
||||
/** Returns the alternative SecuritySettings fragment name if available. */
|
||||
String getAlternativeSecuritySettingsFragmentClassname();
|
||||
|
||||
/**
|
||||
* Returns the category of SecurityAdvancedSettings fragment for the alternative
|
||||
* SecuritySettings if available.
|
||||
*/
|
||||
String getAlternativeAdvancedSettingsCategoryKey();
|
||||
}
|
||||
|
@@ -28,4 +28,9 @@ public class SecuritySettingsFeatureProviderImpl implements SecuritySettingsFeat
|
||||
public String getAlternativeSecuritySettingsFragmentClassname() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlternativeAdvancedSettingsCategoryKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -18,13 +18,18 @@ package com.android.settings.security;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
@@ -35,6 +40,9 @@ import org.junit.runner.RunWith;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SecurityAdvancedSettingsTest {
|
||||
private static final String SCREEN_XML_RESOURCE_NAME = "security_advanced_settings";
|
||||
private static final String ALTERNATIVE_CATEGORY_KEY = "alternative_category_key";
|
||||
private static final String LEGACY_CATEGORY_KEY =
|
||||
"com.android.settings.category.ia.legacy_advanced_security";
|
||||
|
||||
private Context mContext;
|
||||
private SecurityAdvancedSettings mSecurityAdvancedSettings;
|
||||
@@ -58,12 +66,51 @@ public class SecurityAdvancedSettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenCalled_returnsSecurity() {
|
||||
public void getCategoryKey_whenSafetyCenterIsEnabled_returnsSecurity() {
|
||||
setSafetyCenterEnabled(true);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
.isEqualTo(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenAlternativeFragmentPresented_returnsAlternative() {
|
||||
setSafetyCenterEnabled(false);
|
||||
setupAlternativeFragment(true, ALTERNATIVE_CATEGORY_KEY);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
.isEqualTo(ALTERNATIVE_CATEGORY_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenNoAlternativeFragmentPresented_returnsLegacy() {
|
||||
setSafetyCenterEnabled(false);
|
||||
setupAlternativeFragment(false, null);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
.isEqualTo(LEGACY_CATEGORY_KEY);
|
||||
}
|
||||
|
||||
private int getXmlResId(String resName) {
|
||||
return ResourcesUtils.getResourcesId(mContext, "xml", resName);
|
||||
}
|
||||
|
||||
private void setSafetyCenterEnabled(boolean isEnabled) {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(isEnabled),
|
||||
/* makeDefault = */ false);
|
||||
}
|
||||
|
||||
private void setupAlternativeFragment(boolean hasAlternativeFragment,
|
||||
String alternativeCategoryKey) {
|
||||
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(fakeFeatureFactory.securitySettingsFeatureProvider
|
||||
.hasAlternativeSecuritySettingsFragment())
|
||||
.thenReturn(hasAlternativeFragment);
|
||||
when(fakeFeatureFactory.securitySettingsFeatureProvider
|
||||
.getAlternativeAdvancedSettingsCategoryKey())
|
||||
.thenReturn(alternativeCategoryKey);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user