Create MoreSecurtiyPrivacyFragment

Created a new MoreSecurityPrivacyFragment, a new
more_security_privacy_settings xml.
This more_security_privacy_settings xml is a created by merging
privacy_advanced_settings.xml and security_advanced_settings.xml and the
MoreSecurityPrivacyFragment is created by merging
PrivacyDashboardFragment and SecurityAdvancedSettings fragments.

Test: adb shell am start -a com.android.settings.security.MORE_SECURITY_PRIVACY_SETTINGS
Bug: b/261557620
Change-Id: I8729f4eaf25a31f91354383e7b6cb5e0fc7df976
This commit is contained in:
Prabal Singh
2022-12-06 14:28:10 +00:00
parent 43eb9f8fc9
commit 52ba133285
15 changed files with 889 additions and 121 deletions

View File

@@ -15,6 +15,21 @@
*/
package com.android.settings;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
import static com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag.FLAG_INCLUDE_PREF_SCREEN;
import static com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag.FLAG_NEED_KEY;
import android.annotation.XmlRes;
import android.content.Context;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import com.android.settings.core.PreferenceXmlParserUtils;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
import java.util.List;
/**
* Convenience methods and constants for testing.
*/
@@ -22,4 +37,30 @@ public class TestUtils {
public static final long KILOBYTE = 1024L; // TODO: Change to 1000 in O Robolectric.
public static final long MEGABYTE = KILOBYTE * KILOBYTE;
public static final long GIGABYTE = KILOBYTE * MEGABYTE;
public static List<String> getAllXmlKeys(
Context context, BaseSearchIndexProvider indexProvider)
throws Exception {
final List<SearchIndexableResource> resources = indexProvider.getXmlResourcesToIndex(
context, true /* not used*/);
if (resources == null || resources.isEmpty()) {
return new ArrayList<>();
}
final List<String> keys = new ArrayList<>();
for (SearchIndexableResource res : resources) {
keys.addAll(getKeysFromXml(res.xmlResId, context));
}
return keys;
}
private static List<String> getKeysFromXml(@XmlRes int xmlResId, Context context)
throws Exception {
final List<String> keys = new ArrayList<>();
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(context, xmlResId,
FLAG_NEED_KEY | FLAG_INCLUDE_PREF_SCREEN);
for (Bundle bundle : metadata) {
keys.add(bundle.getString(METADATA_KEY));
}
return keys;
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.privacy;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.TestUtils;
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
import com.android.settings.search.BaseSearchIndexProvider;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.List;
public class PrivacyDashboardFragmentTest {
private Context mContext;
private PrivacyDashboardFragment mPrivacyDashboardFragment;
@Mock
private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
@Before
@UiThreadTest
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.initMocks(this);
if (Looper.myLooper() == null) {
Looper.prepare();
}
mContext = ApplicationProvider.getApplicationContext();
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
mPrivacyDashboardFragment = spy(new PrivacyDashboardFragment());
when(mPrivacyDashboardFragment.getContext()).thenReturn(mContext);
}
@Test
public void whenSafetyCenterIsEnabled_pageIndexExcluded() throws Exception {
when(mSafetyCenterManagerWrapper.isEnabled(any())).thenReturn(true);
BaseSearchIndexProvider indexProvider = PrivacyDashboardFragment.SEARCH_INDEX_DATA_PROVIDER;
List<String> allXmlKeys = TestUtils.getAllXmlKeys(mContext, indexProvider);
List<String> nonIndexableKeys = indexProvider.getNonIndexableKeys(mContext);
allXmlKeys.removeAll(nonIndexableKeys);
assertThat(allXmlKeys).isEmpty();
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.safetycenter;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.TestUtils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.List;
@RunWith(AndroidJUnit4.class)
public class MoreSecurityPrivacyFragmentSettingsTest {
private static final String SCREEN_XML_RESOURCE_NAME = "more_security_privacy_settings";
private MoreSecurityPrivacyFragment mMoreSecurityPrivacyFragment;
private Context mContext;
@Mock
private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
@Before
@UiThreadTest
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.initMocks(this);
if (Looper.myLooper() == null) {
Looper.prepare();
}
mContext = ApplicationProvider.getApplicationContext();
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
mMoreSecurityPrivacyFragment = spy(new MoreSecurityPrivacyFragment());
when(mMoreSecurityPrivacyFragment.getContext()).thenReturn(mContext);
}
@Test
public void getPreferenceXml_returnsMoreSecurityPrivacy() {
assertThat(mMoreSecurityPrivacyFragment.getPreferenceScreenResId())
.isEqualTo(getXmlResId(SCREEN_XML_RESOURCE_NAME));
}
@Test
public void whenSafetyCenterIsEnabled_pageIndexIncluded() throws Exception {
when(mSafetyCenterManagerWrapper.isEnabled(any())).thenReturn(true);
BaseSearchIndexProvider indexProvider =
MoreSecurityPrivacyFragment.SEARCH_INDEX_DATA_PROVIDER;
List<String> allXmlKeys = TestUtils.getAllXmlKeys(mContext, indexProvider);
List<String> nonIndexableKeys = indexProvider.getNonIndexableKeys(mContext);
allXmlKeys.removeAll(nonIndexableKeys);
assertThat(allXmlKeys).isNotEmpty();
}
@Test
public void whenSafetyCenterIsDisabled_pageIndexExcluded() throws Exception {
when(mSafetyCenterManagerWrapper.isEnabled(any())).thenReturn(false);
BaseSearchIndexProvider indexProvider =
MoreSecurityPrivacyFragment.SEARCH_INDEX_DATA_PROVIDER;
List<String> allXmlKeys = TestUtils.getAllXmlKeys(mContext, indexProvider);
List<String> nonIndexableKeys = indexProvider.getNonIndexableKeys(mContext);
allXmlKeys.removeAll(nonIndexableKeys);
assertThat(allXmlKeys).isEmpty();
}
private int getXmlResId(String resName) {
return ResourcesUtils.getResourcesId(mContext, "xml", resName);
}
}

View File

@@ -16,6 +16,7 @@
package com.android.settings.security;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -29,7 +30,9 @@ import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.TestUtils;
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.drawer.CategoryKey;
@@ -40,6 +43,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.List;
@RunWith(AndroidJUnit4.class)
public class SecurityAdvancedSettingsTest {
private static final String SCREEN_XML_RESOURCE_NAME = "security_advanced_settings";
@@ -100,6 +105,18 @@ public class SecurityAdvancedSettingsTest {
.isEqualTo(LEGACY_CATEGORY_KEY);
}
@Test
public void whenSafetyCenterIsEnabled_pageIndexExcluded() throws Exception {
when(mSafetyCenterManagerWrapper.isEnabled(any())).thenReturn(false);
BaseSearchIndexProvider indexProvider = SecurityAdvancedSettings.SEARCH_INDEX_DATA_PROVIDER;
List<String> allXmlKeys = TestUtils.getAllXmlKeys(mContext, indexProvider);
List<String> nonIndexableKeys = indexProvider.getNonIndexableKeys(mContext);
allXmlKeys.removeAll(nonIndexableKeys);
assertThat(allXmlKeys).isEmpty();
}
private int getXmlResId(String resName) {
return ResourcesUtils.getResourcesId(mContext, "xml", resName);
}

View File

@@ -21,24 +21,18 @@ import static android.content.Context.FINGERPRINT_SERVICE;
import static android.content.pm.PackageManager.FEATURE_FACE;
import static android.content.pm.PackageManager.FEATURE_FINGERPRINT;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
import static com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag.FLAG_INCLUDE_PREF_SCREEN;
import static com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag.FLAG_NEED_KEY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.annotation.XmlRes;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
import android.os.Looper;
import android.provider.SearchIndexableResource;
import androidx.lifecycle.Lifecycle;
import androidx.preference.Preference;
@@ -48,10 +42,11 @@ import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.TestUtils;
import com.android.settings.biometrics.combination.CombinedBiometricStatusPreferenceController;
import com.android.settings.biometrics.face.FaceStatusPreferenceController;
import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
import com.android.settings.core.PreferenceXmlParserUtils;
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.security.trustagent.TrustAgentManager;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -64,7 +59,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
@RunWith(AndroidJUnit4.class)
@@ -85,6 +79,8 @@ public class SecuritySettingsTest {
private FingerprintManager mFingerprintManager;
@Mock
private PackageManager mPackageManager;
@Mock
private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
private PreferenceScreen mScreen;
@@ -96,6 +92,7 @@ public class SecuritySettingsTest {
}
MockitoAnnotations.initMocks(this);
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.hasSystemFeature(FEATURE_FACE)).thenReturn(true);
@@ -132,12 +129,14 @@ public class SecuritySettingsTest {
}
@Test
public void noAlternativeFragmentAvailable_pageIndexIncluded() throws Exception {
public void noAlternativeFragmentAvailableAndSafetyCenterIsDisabled_pageIndexIncluded()
throws Exception {
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()).thenReturn(
false);
when(mSafetyCenterManagerWrapper.isEnabled(any())).thenReturn(false);
BaseSearchIndexProvider indexProvider = SecuritySettings.SEARCH_INDEX_DATA_PROVIDER;
List<String> allXmlKeys = getAllXmlKeys(indexProvider);
List<String> allXmlKeys = TestUtils.getAllXmlKeys(mContext, indexProvider);
List<String> nonIndexableKeys = indexProvider.getNonIndexableKeys(mContext);
allXmlKeys.removeAll(nonIndexableKeys);
@@ -150,7 +149,7 @@ public class SecuritySettingsTest {
true);
BaseSearchIndexProvider indexProvider = SecuritySettings.SEARCH_INDEX_DATA_PROVIDER;
List<String> allXmlKeys = getAllXmlKeys(indexProvider);
List<String> allXmlKeys = TestUtils.getAllXmlKeys(mContext, indexProvider);
List<String> nonIndexableKeys = indexProvider.getNonIndexableKeys(mContext);
allXmlKeys.removeAll(nonIndexableKeys);
@@ -340,29 +339,6 @@ public class SecuritySettingsTest {
assertThat(mPreferenceCombined.isVisible()).isFalse();
}
private List<String> getAllXmlKeys(BaseSearchIndexProvider indexProvider) throws Exception {
final List<SearchIndexableResource> resources = indexProvider.getXmlResourcesToIndex(
mContext, true /* not used*/);
if (resources == null || resources.isEmpty()) {
return new ArrayList<>();
}
final List<String> keys = new ArrayList<>();
for (SearchIndexableResource res : resources) {
keys.addAll(getKeysFromXml(res.xmlResId));
}
return keys;
}
private List<String> getKeysFromXml(@XmlRes int xmlResId) throws Exception {
final List<String> keys = new ArrayList<>();
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext, xmlResId,
FLAG_NEED_KEY | FLAG_INCLUDE_PREF_SCREEN);
for (Bundle bundle : metadata) {
keys.add(bundle.getString(METADATA_KEY));
}
return keys;
}
boolean isFacePrefAvailable(List<AbstractPreferenceController> controllers) {
return controllers.stream().filter(
controller -> controller instanceof FaceStatusPreferenceController