Adds SecuritySetting feature for providing an alternative SecuritySettings fragment
Bug: 181764224 Test: New tests added to SettingsUnitTests. Test: Tested manually with and without feature-provided fragment. Test: No new failures in SettingsUnitTests, or robolectric. No failures in security directory of robolectric tests. Change-Id: I21038baf3098c18e1713a332085a5efc376f73da
This commit is contained in:
@@ -43,6 +43,7 @@ import com.android.settings.overlay.SurveyFeatureProvider;
|
||||
import com.android.settings.panel.PanelFeatureProvider;
|
||||
import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.security.SecuritySettingsFeatureProvider;
|
||||
import com.android.settings.slices.SlicesFeatureProvider;
|
||||
import com.android.settings.users.UserFeatureProvider;
|
||||
import com.android.settings.wifi.WifiTrackerLibProvider;
|
||||
@@ -83,6 +84,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
|
||||
public WifiTrackerLibProvider wifiTrackerLibProvider;
|
||||
public ExtraAppInfoFeatureProvider extraAppInfoFeatureProvider;
|
||||
public SecuritySettingsFeatureProvider securitySettingsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||
@@ -130,6 +132,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
mFaceFeatureProvider = mock(FaceFeatureProvider.class);
|
||||
wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class);
|
||||
extraAppInfoFeatureProvider = mock(ExtraAppInfoFeatureProvider.class);
|
||||
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -256,4 +259,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public ExtraAppInfoFeatureProvider getExtraAppInfoFeatureProvider() {
|
||||
return extraAppInfoFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecuritySettingsFeatureProvider getSecuritySettingsFeatureProvider() {
|
||||
return securitySettingsFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.security;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SecuritySettingsFeatureProviderImplTest {
|
||||
|
||||
private SecuritySettingsFeatureProviderImpl mSecuritySettingsFeatureProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mSecuritySettingsFeatureProvider = new SecuritySettingsFeatureProviderImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasAlternativeSecuritySettingsFragment_returnsFalse() {
|
||||
assertThat(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAlternativeSecuritySettingsFragmentClassname_returnsNull() {
|
||||
String alternativeFragmentClassname =
|
||||
mSecuritySettingsFeatureProvider.getAlternativeSecuritySettingsFragmentClassname();
|
||||
assertThat(alternativeFragmentClassname).isNull();
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.security;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TopLevelSecurityEntryPreferenceControllerTest {
|
||||
|
||||
private static final String PREFERENCE_KEY = "top_level_security";
|
||||
private static final String ALTERNATIVE_FRAGMENT_CLASSNAME = "AlternativeFragmentClassname";
|
||||
|
||||
private TopLevelSecurityEntryPreferenceController mTopLevelSecurityEntryPreferenceController;
|
||||
private Preference mPreference;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private SecuritySettingsFeatureProvider mSecuritySettingsFeatureProvider;
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
||||
|
||||
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
||||
mPreference.setKey(PREFERENCE_KEY);
|
||||
|
||||
doNothing().when(mContext).startActivity(any(Intent.class));
|
||||
mTopLevelSecurityEntryPreferenceController =
|
||||
new TopLevelSecurityEntryPreferenceController(mContext, PREFERENCE_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_forDifferentPreferenceKey_isNotHandled() {
|
||||
Preference preference = new Preference(ApplicationProvider.getApplicationContext());
|
||||
preference.setKey("some_other_preference");
|
||||
|
||||
boolean preferenceHandled =
|
||||
mTopLevelSecurityEntryPreferenceController.handlePreferenceTreeClick(preference);
|
||||
|
||||
assertThat(preferenceHandled).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_withAlternativeFragment_launchesAlternativeFragment() {
|
||||
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
||||
.thenReturn(true);
|
||||
when(mSecuritySettingsFeatureProvider.getAlternativeSecuritySettingsFragmentClassname())
|
||||
.thenReturn(ALTERNATIVE_FRAGMENT_CLASSNAME);
|
||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
|
||||
boolean preferenceHandled =
|
||||
mTopLevelSecurityEntryPreferenceController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(preferenceHandled).isTrue();
|
||||
verify(mContext).startActivity(intentCaptor.capture());
|
||||
assertThat(intentCaptor.getValue().getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(ALTERNATIVE_FRAGMENT_CLASSNAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_withDisabledAlternative_isNotHandled() {
|
||||
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
||||
.thenReturn(false);
|
||||
when(mSecuritySettingsFeatureProvider.getAlternativeSecuritySettingsFragmentClassname())
|
||||
.thenReturn(ALTERNATIVE_FRAGMENT_CLASSNAME);
|
||||
|
||||
boolean preferenceHandled =
|
||||
mTopLevelSecurityEntryPreferenceController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(preferenceHandled).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_withoutAlternativeFragmentName_isNotHandled() {
|
||||
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
||||
.thenReturn(true);
|
||||
when(mSecuritySettingsFeatureProvider.getAlternativeSecuritySettingsFragmentClassname())
|
||||
.thenReturn(null);
|
||||
|
||||
boolean preferenceHandled =
|
||||
mTopLevelSecurityEntryPreferenceController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(preferenceHandled).isFalse();
|
||||
}
|
||||
}
|
@@ -41,6 +41,7 @@ import com.android.settings.overlay.SurveyFeatureProvider;
|
||||
import com.android.settings.panel.PanelFeatureProvider;
|
||||
import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.security.SecuritySettingsFeatureProvider;
|
||||
import com.android.settings.slices.SlicesFeatureProvider;
|
||||
import com.android.settings.users.UserFeatureProvider;
|
||||
import com.android.settings.wifi.WifiTrackerLibProvider;
|
||||
@@ -78,6 +79,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
|
||||
public WifiTrackerLibProvider wifiTrackerLibProvider;
|
||||
public ExtraAppInfoFeatureProvider extraAppInfoFeatureProvider;
|
||||
public SecuritySettingsFeatureProvider securitySettingsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||
@@ -116,6 +118,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
mFaceFeatureProvider = mock(FaceFeatureProvider.class);
|
||||
wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class);
|
||||
extraAppInfoFeatureProvider = mock(ExtraAppInfoFeatureProvider.class);
|
||||
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -242,4 +245,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public ExtraAppInfoFeatureProvider getExtraAppInfoFeatureProvider() {
|
||||
return extraAppInfoFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecuritySettingsFeatureProvider getSecuritySettingsFeatureProvider() {
|
||||
return securitySettingsFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user