[Settings] enhancing data saver config control
Enhancing the control of R.bool.config_show_data_saver when false, which including: 1. Initial presentation is invisible 2. Leaving UI when triggered 3. Avoid from getting searched 4. Robolectric test case support Bug: 243877672 Test: test cases and local testing Change-Id: I909522c0244ebb012a27d6aff34120a4f90128c6
This commit is contained in:
@@ -99,6 +99,7 @@
|
||||
android:title="@string/data_saver_title"
|
||||
android:icon="@drawable/ic_settings_data_usage"
|
||||
android:order="10"
|
||||
settings:isPreferenceVisible="@bool/config_show_data_saver"
|
||||
android:fragment="com.android.settings.datausage.DataSaverSummary"/>
|
||||
|
||||
<com.android.settings.vpn2.VpnInfoPreference
|
||||
|
@@ -103,6 +103,7 @@
|
||||
android:key="data_saver"
|
||||
android:title="@string/unrestricted_data_saver"
|
||||
android:fragment="com.android.settings.datausage.UnrestrictedDataAccess"
|
||||
settings:isPreferenceVisible="@bool/config_show_data_saver"
|
||||
settings:controller="com.android.settings.applications.specialaccess.DataSaverController" />
|
||||
|
||||
<Preference
|
||||
|
@@ -67,9 +67,18 @@ public class DataSaverSummary extends SettingsPreferenceFragment
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
if (!isDataSaverVisible(getContext())) {
|
||||
finishFragment();
|
||||
return;
|
||||
}
|
||||
|
||||
addPreferencesFromResource(R.xml.data_saver);
|
||||
mUnrestrictedAccess = findPreference(KEY_UNRESTRICTED_ACCESS);
|
||||
mApplicationsState = ApplicationsState.getInstance(
|
||||
(Application) getContext().getApplicationContext());
|
||||
mDataSaverBackend = new DataSaverBackend(getContext());
|
||||
mDataUsageBridge = new AppStateDataUsageBridge(mApplicationsState, this, mDataSaverBackend);
|
||||
mSession = mApplicationsState.newSession(this, getSettingsLifecycle());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -202,12 +211,18 @@ public class DataSaverSummary extends SettingsPreferenceFragment
|
||||
R.plurals.data_saver_unrestricted_summary, count, count));
|
||||
}
|
||||
|
||||
public static boolean isDataSaverVisible(Context context) {
|
||||
return context.getResources()
|
||||
.getBoolean(R.bool.config_show_data_saver);
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.data_saver) {
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return DataUsageUtils.hasMobileData(context)
|
||||
return isDataSaverVisible(context)
|
||||
&& DataUsageUtils.hasMobileData(context)
|
||||
&& DataUsageUtils.getDefaultSubscriptionId(context)
|
||||
!= SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
}
|
||||
|
@@ -18,9 +18,13 @@ package com.android.settings.applications.specialaccess;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -34,23 +38,35 @@ import org.robolectric.annotation.Config;
|
||||
public class DataSaverControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private DataSaverController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
mController = new DataSaverController(mContext, "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataSaver_byDefault_shouldBeShown() {
|
||||
when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(true);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void testDataSaver_ifDisabledByCarrier_shouldNotBeShown() {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataSaver_ifDisabled_shouldNotBeShown() {
|
||||
when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user