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. Manual merge for: ag/2631595 Change-Id: I7bb3cdb0f11772bbaefb6c21c61eb63bd0b17c7e Fixes: 64193449 Test: robotests
This commit is contained in:
@@ -54,13 +54,19 @@ import java.util.List;
|
|||||||
public class DataPlanUsageSummary extends DataUsageBase implements Indexable {
|
public class DataPlanUsageSummary extends DataUsageBase implements Indexable {
|
||||||
|
|
||||||
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";
|
public static final String KEY_DATA_PLAN_USAGE = "data_plan_usage";
|
||||||
private static final String KEY_DATA_PLAN_USAGE = "data_plan_usage";
|
|
||||||
|
|
||||||
private static final String KEY_STATUS_HEADER = "status_header";
|
public static final String KEY_STATUS_HEADER = "status_header";
|
||||||
private static final String KEY_LIMIT_SUMMARY = "plan_summary";
|
public static final String KEY_LIMIT_SUMMARY = "plan_summary";
|
||||||
private static final String KEY_MOBILE_USAGE_TITLE = "data_usage_mobile_category";
|
|
||||||
private static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
|
// Mobile data keys
|
||||||
|
public static final String KEY_MOBILE_USAGE_TITLE = "data_usage_mobile_category";
|
||||||
|
public static final String KEY_MOBILE_DATA_USAGE_TOGGLE = "data_usage_enable";
|
||||||
|
|
||||||
|
// 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;
|
||||||
@@ -364,19 +370,17 @@ public class DataPlanUsageSummary extends DataUsageBase implements Indexable {
|
|||||||
boolean enabled) {
|
boolean enabled) {
|
||||||
List<SearchIndexableResource> resources = new ArrayList<>();
|
List<SearchIndexableResource> resources = new ArrayList<>();
|
||||||
SearchIndexableResource resource = new SearchIndexableResource(context);
|
SearchIndexableResource resource = new SearchIndexableResource(context);
|
||||||
resource.xmlResId = R.xml.data_plan_usage;
|
resource.xmlResId = R.xml.data_usage;
|
||||||
|
resources.add(resource);
|
||||||
|
|
||||||
|
resource = new SearchIndexableResource(context);
|
||||||
|
resource.xmlResId = R.xml.data_plan_usage_cell_data_preference_screen;
|
||||||
|
resources.add(resource);
|
||||||
|
|
||||||
|
resource = new SearchIndexableResource(context);
|
||||||
|
resource.xmlResId = R.xml.data_usage_wifi;
|
||||||
resources.add(resource);
|
resources.add(resource);
|
||||||
|
|
||||||
if (DataUsageUtils.hasMobileData(context)) {
|
|
||||||
resource = new SearchIndexableResource(context);
|
|
||||||
resource.xmlResId = R.xml.data_plan_usage_cell_data_preference_screen;
|
|
||||||
resources.add(resource);
|
|
||||||
}
|
|
||||||
if (DataUsageUtils.hasWifiRadio(context)) {
|
|
||||||
resource = new SearchIndexableResource(context);
|
|
||||||
resource.xmlResId = R.xml.data_usage_wifi;
|
|
||||||
resources.add(resource);
|
|
||||||
}
|
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,12 +388,16 @@ public class DataPlanUsageSummary extends DataUsageBase implements Indexable {
|
|||||||
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 (DataUsageUtils.hasMobileData(context)) {
|
if (!DataUsageUtils.hasMobileData(context)) {
|
||||||
keys.add(KEY_RESTRICT_BACKGROUND);
|
keys.add(KEY_MOBILE_USAGE_TITLE);
|
||||||
|
keys.add(KEY_MOBILE_DATA_USAGE_TOGGLE);
|
||||||
}
|
}
|
||||||
if (DataUsageUtils.hasWifiRadio(context)) {
|
|
||||||
|
if (!DataUsageUtils.hasWifiRadio(context)) {
|
||||||
|
keys.add(KEY_WIFI_DATA_USAGE);
|
||||||
keys.add(KEY_NETWORK_RESTRICTIONS);
|
keys.add(KEY_NETWORK_RESTRICTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
keys.add(KEY_WIFI_USAGE_TITLE);
|
keys.add(KEY_WIFI_USAGE_TITLE);
|
||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
|
@@ -69,12 +69,21 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
|
|||||||
static final boolean LOGD = false;
|
static final boolean LOGD = false;
|
||||||
|
|
||||||
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_MOBILE_USAGE_TITLE = "mobile_category";
|
|
||||||
private static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
|
// Mobile data keys
|
||||||
|
public static final String KEY_MOBILE_USAGE_TITLE = "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;
|
||||||
@@ -381,16 +390,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 (DataUsageUtils.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 (DataUsageUtils.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,12 +405,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 (DataUsageUtils.hasMobileData(context)) {
|
if (!DataUsageUtils.hasMobileData(context)) {
|
||||||
keys.add(KEY_RESTRICT_BACKGROUND);
|
keys.add(KEY_MOBILE_USAGE_TITLE);
|
||||||
|
keys.add(KEY_MOBILE_DATA_USAGE_TOGGLE);
|
||||||
|
keys.add(KEY_MOBILE_DATA_USAGE);
|
||||||
|
keys.add(KEY_MOBILE_BILLING_CYCLE);
|
||||||
}
|
}
|
||||||
if (DataUsageUtils.hasWifiRadio(context)) {
|
|
||||||
|
if (!DataUsageUtils.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;
|
||||||
|
@@ -39,7 +39,7 @@ public final class DataUsageUtils {
|
|||||||
* Returns whether device has mobile data.
|
* Returns whether device has mobile data.
|
||||||
* TODO: This is the opposite to Utils.isWifiOnly(), it should be refactored into 1 method.
|
* TODO: This is the opposite to Utils.isWifiOnly(), it should be refactored into 1 method.
|
||||||
*/
|
*/
|
||||||
static boolean hasMobileData(Context context) {
|
public static boolean hasMobileData(Context context) {
|
||||||
ConnectivityManager connectivityManager = ConnectivityManager.from(context);
|
ConnectivityManager connectivityManager = ConnectivityManager.from(context);
|
||||||
return connectivityManager != null && connectivityManager
|
return connectivityManager != null && connectivityManager
|
||||||
.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
|
.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
|
||||||
|
@@ -35,6 +35,7 @@ import com.android.settings.TestConfig;
|
|||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
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.ShadowDataUsageUtils;
|
||||||
import com.android.settingslib.NetworkPolicyEditor;
|
import com.android.settingslib.NetworkPolicyEditor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -129,28 +130,50 @@ public class DataPlanUsageSummaryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(shadows = ShadowDataUsageUtils.class)
|
||||||
public void testNonIndexableKeys_existInXmlLayout() {
|
public void testNonIndexableKeys_existInXmlLayout() {
|
||||||
Context context = RuntimeEnvironment.application;
|
final Context context = RuntimeEnvironment.application;
|
||||||
List<String> niks = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
||||||
|
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
|
||||||
|
final List<String> niks = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||||
.getNonIndexableKeys(context);
|
.getNonIndexableKeys(context);
|
||||||
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_plan_usage_cell_data_preference_screen));
|
||||||
|
|
||||||
assertThat(keys).containsAllIn(niks);
|
assertThat(keys).containsAllIn(niks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowConnectivityManager.class)
|
@Config(shadows = ShadowDataUsageUtils.class)
|
||||||
public void testNonIndexableKeys_hasMobileData_restrictedAccessesAdded() {
|
public void testNonIndexableKeys_hasMobileData_hasWifi_allNonIndexableKeysAdded() {
|
||||||
ShadowConnectivityManager.setIsNetworkSupported(true);
|
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = false;
|
||||||
|
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = false;
|
||||||
List<String> keys = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
List<String> keys = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||||
.getNonIndexableKeys(mContext);
|
.getNonIndexableKeys(mContext);
|
||||||
|
|
||||||
assertThat(keys).contains(DataPlanUsageSummary.KEY_RESTRICT_BACKGROUND);
|
// Mobile data keys
|
||||||
|
assertThat(keys).contains(DataPlanUsageSummary.KEY_MOBILE_USAGE_TITLE);
|
||||||
|
assertThat(keys).contains(DataPlanUsageSummary.KEY_MOBILE_DATA_USAGE_TOGGLE);
|
||||||
|
|
||||||
|
// Wifi keys
|
||||||
|
assertThat(keys).contains(DataPlanUsageSummary.KEY_WIFI_DATA_USAGE);
|
||||||
assertThat(keys).contains(DataPlanUsageSummary.KEY_NETWORK_RESTRICTIONS);
|
assertThat(keys).contains(DataPlanUsageSummary.KEY_NETWORK_RESTRICTIONS);
|
||||||
ShadowConnectivityManager.setIsNetworkSupported(false);
|
assertThat(keys).contains(DataPlanUsageSummary.KEY_WIFI_USAGE_TITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = ShadowDataUsageUtils.class)
|
||||||
|
public void testNonIndexableKeys_noMobile_noWifi_limitedNonIndexableKeys() {
|
||||||
|
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
||||||
|
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
|
||||||
|
List<String> keys = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
||||||
|
.getNonIndexableKeys(mContext);
|
||||||
|
|
||||||
|
assertThat(keys).containsExactly(DataPlanUsageSummary.KEY_WIFI_USAGE_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTest() {
|
private void initTest() {
|
||||||
|
@@ -82,29 +82,4 @@ public class DataUsageSummaryTest {
|
|||||||
verify(preference).setSummary(mContext.getResources().getQuantityString(
|
verify(preference).setSummary(mContext.getResources().getQuantityString(
|
||||||
R.plurals.network_restrictions_summary, 0, 0));
|
R.plurals.network_restrictions_summary, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNonIndexableKeys_existInXmlLayout() {
|
|
||||||
final Context context = RuntimeEnvironment.application;
|
|
||||||
final List<String> niks = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
|
||||||
.getNonIndexableKeys(context);
|
|
||||||
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));
|
|
||||||
|
|
||||||
assertThat(keys).containsAllIn(niks);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(shadows = ShadowConnectivityManager.class)
|
|
||||||
public void testNonIndexableKeys_hasMobileData_restrictedAccessesAdded() {
|
|
||||||
ShadowConnectivityManager.setIsNetworkSupported(true);
|
|
||||||
List<String> keys = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
|
|
||||||
.getNonIndexableKeys(mContext);
|
|
||||||
|
|
||||||
assertThat(keys).contains(DataUsageSummary.KEY_RESTRICT_BACKGROUND);
|
|
||||||
assertThat(keys).contains(DataUsageSummary.KEY_NETWORK_RESTRICTIONS);
|
|
||||||
ShadowConnectivityManager.setIsNetworkSupported(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
package com.android.settings.testutils.shadow;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.datausage.DataUsageUtils;
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
|
@Implements(DataUsageUtils.class)
|
||||||
|
public class ShadowDataUsageUtils {
|
||||||
|
|
||||||
|
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