Fix DataUsageSummary non-indexable keys
Indexing in DataUsage was not conventional, since it blocked adding XML based on current sim status rather than indexing everything and changing non-indexabe keys. Change-Id: I2097a3ac4ffd714b60299c07b29c81f246e414eb Merged-In: I7bb3cdb0f11772bbaefb6c21c61eb63bd0b17c7e Fixes: 64193449 Test: robotests
This commit is contained in:
@@ -72,11 +72,21 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
public static final String TEST_RADIOS_PROP = "test.radios";
|
public static final String TEST_RADIOS_PROP = "test.radios";
|
||||||
|
|
||||||
public static final String KEY_RESTRICT_BACKGROUND = "restrict_background";
|
public static final String KEY_RESTRICT_BACKGROUND = "restrict_background";
|
||||||
public static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
|
|
||||||
|
|
||||||
private static final String KEY_STATUS_HEADER = "status_header";
|
private static final String KEY_STATUS_HEADER = "status_header";
|
||||||
private static final String KEY_LIMIT_SUMMARY = "limit_summary";
|
private static final String KEY_LIMIT_SUMMARY = "limit_summary";
|
||||||
private static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
|
|
||||||
|
// Mobile data keys
|
||||||
|
public static final String KEY_MOBILE_CATEGORY = "mobile_category";
|
||||||
|
public static final String KEY_MOBILE_DATA_USAGE_TOGGLE = "data_usage_enable";
|
||||||
|
public static final String KEY_MOBILE_DATA_USAGE = "cellular_data_usage";
|
||||||
|
public static final String KEY_MOBILE_BILLING_CYCLE = "billing_preference";
|
||||||
|
|
||||||
|
// Wifi keys
|
||||||
|
public static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
|
||||||
|
public static final String KEY_WIFI_DATA_USAGE = "wifi_data_usage";
|
||||||
|
public static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
|
||||||
|
|
||||||
|
|
||||||
private DataUsageController mDataUsageController;
|
private DataUsageController mDataUsageController;
|
||||||
private DataUsageInfoController mDataInfoController;
|
private DataUsageInfoController mDataInfoController;
|
||||||
@@ -471,16 +481,14 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
resource.xmlResId = R.xml.data_usage;
|
resource.xmlResId = R.xml.data_usage;
|
||||||
resources.add(resource);
|
resources.add(resource);
|
||||||
|
|
||||||
if (hasMobileData(context)) {
|
resource = new SearchIndexableResource(context);
|
||||||
resource = new SearchIndexableResource(context);
|
resource.xmlResId = R.xml.data_usage_cellular;
|
||||||
resource.xmlResId = R.xml.data_usage_cellular;
|
resources.add(resource);
|
||||||
resources.add(resource);
|
|
||||||
}
|
resource = new SearchIndexableResource(context);
|
||||||
if (hasWifiRadio(context)) {
|
resource.xmlResId = R.xml.data_usage_wifi;
|
||||||
resource = new SearchIndexableResource(context);
|
resources.add(resource);
|
||||||
resource.xmlResId = R.xml.data_usage_wifi;
|
|
||||||
resources.add(resource);
|
|
||||||
}
|
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,12 +496,19 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
List<String> keys = super.getNonIndexableKeys(context);
|
List<String> keys = super.getNonIndexableKeys(context);
|
||||||
|
|
||||||
if (hasMobileData(context)) {
|
if (!hasMobileData(context)) {
|
||||||
keys.add(KEY_RESTRICT_BACKGROUND);
|
keys.add(KEY_MOBILE_CATEGORY);
|
||||||
|
keys.add(KEY_MOBILE_DATA_USAGE_TOGGLE);
|
||||||
|
keys.add(KEY_MOBILE_DATA_USAGE);
|
||||||
|
keys.add(KEY_MOBILE_BILLING_CYCLE);
|
||||||
}
|
}
|
||||||
if (hasWifiRadio(context)) {
|
|
||||||
|
if (!hasWifiRadio(context)) {
|
||||||
|
keys.add(KEY_WIFI_DATA_USAGE);
|
||||||
keys.add(KEY_NETWORK_RESTRICTIONS);
|
keys.add(KEY_NETWORK_RESTRICTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This title is named Wifi, and will confuse users.
|
||||||
keys.add(KEY_WIFI_USAGE_TITLE);
|
keys.add(KEY_WIFI_USAGE_TITLE);
|
||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
|
@@ -27,6 +27,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.XmlTestUtils;
|
import com.android.settings.testutils.XmlTestUtils;
|
||||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowDataUsageSummary;
|
||||||
import com.android.settingslib.NetworkPolicyEditor;
|
import com.android.settingslib.NetworkPolicyEditor;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -149,27 +150,50 @@ public class DataUsageSummaryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(shadows = ShadowDataUsageSummary.class)
|
||||||
public void testNonIndexableKeys_existInXmlLayout() {
|
public void testNonIndexableKeys_existInXmlLayout() {
|
||||||
final Context context = RuntimeEnvironment.application;
|
final Context context = RuntimeEnvironment.application;
|
||||||
|
ShadowDataUsageSummary.IS_WIFI_SUPPORTED = true;
|
||||||
|
ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = true;
|
||||||
final List<String> niks = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
final List<String> niks = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||||
.getNonIndexableKeys(context);
|
.getNonIndexableKeys(context);
|
||||||
final List<String> keys = new ArrayList<>();
|
final List<String> keys = new ArrayList<>();
|
||||||
|
|
||||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_wifi));
|
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_wifi));
|
||||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage));
|
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage));
|
||||||
|
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_cellular));
|
||||||
|
|
||||||
assertThat(keys).containsAllIn(niks);
|
assertThat(keys).containsAllIn(niks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowConnectivityManager.class)
|
@Config(shadows = ShadowDataUsageSummary.class)
|
||||||
public void testNonIndexableKeys_hasMobileData_restrictedAccessesAdded() {
|
public void testNonIndexableKeys_hasMobileData_hasWifi_allNonIndexableKeysAdded() {
|
||||||
ShadowConnectivityManager.setIsNetworkSupported(true);
|
ShadowDataUsageSummary.IS_WIFI_SUPPORTED = false;
|
||||||
|
ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = false;
|
||||||
List<String> keys = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
List<String> keys = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||||
.getNonIndexableKeys(mContext);
|
.getNonIndexableKeys(mContext);
|
||||||
|
|
||||||
assertThat(keys).contains(DataUsageSummary.KEY_RESTRICT_BACKGROUND);
|
// Mobile data keys
|
||||||
|
assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_CATEGORY);
|
||||||
|
assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_DATA_USAGE_TOGGLE);
|
||||||
|
assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_DATA_USAGE);
|
||||||
|
assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_BILLING_CYCLE);
|
||||||
|
|
||||||
|
// Wifi keys
|
||||||
|
assertThat(keys).contains(DataUsageSummary.KEY_WIFI_DATA_USAGE);
|
||||||
assertThat(keys).contains(DataUsageSummary.KEY_NETWORK_RESTRICTIONS);
|
assertThat(keys).contains(DataUsageSummary.KEY_NETWORK_RESTRICTIONS);
|
||||||
ShadowConnectivityManager.setIsNetworkSupported(false);
|
assertThat(keys).contains(DataUsageSummary.KEY_WIFI_USAGE_TITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = ShadowDataUsageSummary.class)
|
||||||
|
public void testNonIndexableKeys_noMobile_noWifi_limitedNonIndexableKeys() {
|
||||||
|
ShadowDataUsageSummary.IS_WIFI_SUPPORTED = true;
|
||||||
|
ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = true;
|
||||||
|
List<String> keys = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||||
|
.getNonIndexableKeys(mContext);
|
||||||
|
|
||||||
|
assertThat(keys).containsExactly(DataUsageSummary.KEY_WIFI_USAGE_TITLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
package com.android.settings.testutils.shadow;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.datausage.DataUsageSummary;
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
|
@Implements(DataUsageSummary.class)
|
||||||
|
public class ShadowDataUsageSummary {
|
||||||
|
|
||||||
|
public static boolean IS_MOBILE_DATA_SUPPORTED = true;
|
||||||
|
public static boolean IS_WIFI_SUPPORTED = true;
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public static boolean hasMobileData(Context context) {
|
||||||
|
return IS_MOBILE_DATA_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public static boolean hasWifiRadio(Context context) {
|
||||||
|
return IS_WIFI_SUPPORTED;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user