Merge "Implemented the CardContentLoader"
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index a2a2450..0279cfa 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -15,12 +15,15 @@
*/
package com.android.settings.network;
+import static android.provider.Settings.ACTION_DATA_USAGE_SETTINGS;
import static com.android.settings.network.MobilePlanPreferenceController
.MANAGE_MOBILE_PLAN_DIALOG_ID;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.icu.text.ListFormatter;
import android.provider.SearchIndexableResource;
import android.text.BidiFormatter;
@@ -45,6 +48,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.function.BooleanSupplier;
import java.util.List;
@SearchIndexable
@@ -158,24 +162,32 @@
private final WifiMasterSwitchPreferenceController mWifiPreferenceController;
private final MobileNetworkPreferenceController mMobileNetworkPreferenceController;
private final TetherPreferenceController mTetherPreferenceController;
+ private final BooleanSupplier mHasDataUsageActivity;
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
this(context, summaryLoader,
new WifiMasterSwitchPreferenceController(context, null),
new MobileNetworkPreferenceController(context),
- new TetherPreferenceController(context, null /* lifecycle */));
+ new TetherPreferenceController(context, null /* lifecycle */),
+ () -> {
+ final Intent intent = new Intent(ACTION_DATA_USAGE_SETTINGS);
+ final PackageManager pm = context.getPackageManager();
+ return intent.resolveActivity(pm) != null;
+ });
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
SummaryProvider(Context context, SummaryLoader summaryLoader,
WifiMasterSwitchPreferenceController wifiPreferenceController,
MobileNetworkPreferenceController mobileNetworkPreferenceController,
- TetherPreferenceController tetherPreferenceController) {
+ TetherPreferenceController tetherPreferenceController,
+ BooleanSupplier hasDataUsageActivity) {
mContext = context;
mSummaryLoader = summaryLoader;
mWifiPreferenceController = wifiPreferenceController;
mMobileNetworkPreferenceController = mobileNetworkPreferenceController;
mTetherPreferenceController = tetherPreferenceController;
+ mHasDataUsageActivity = hasDataUsageActivity;
}
@@ -198,7 +210,7 @@
if (mMobileNetworkPreferenceController.isAvailable() && !TextUtils.isEmpty(mobileSummary)) {
summaries.add(mobileSummary);
}
- if (!TextUtils.isEmpty(dataUsageSummary)) {
+ if (!TextUtils.isEmpty(dataUsageSummary) && mHasDataUsageActivity.getAsBoolean()) {
summaries.add(dataUsageSummary);
}
if (mTetherPreferenceController.isAvailable() && !TextUtils.isEmpty(hotspotSummary)) {
diff --git a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
index d6f86f9..469a537 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
@@ -79,7 +79,7 @@
final SummaryLoader.SummaryProvider provider =
new NetworkDashboardFragment.SummaryProvider(mContext, summaryLoader,
wifiPreferenceController, mobileNetworkPreferenceController,
- tetherPreferenceController);
+ tetherPreferenceController, () -> true);
provider.setListening(false);
@@ -107,7 +107,7 @@
final SummaryLoader.SummaryProvider provider =
new NetworkDashboardFragment.SummaryProvider(mContext, summaryLoader,
wifiPreferenceController, mobileNetworkPreferenceController,
- tetherPreferenceController);
+ tetherPreferenceController, () -> true);
provider.setListening(false);
@@ -121,4 +121,34 @@
verify(summaryLoader).setSummary(provider, "Wi\u2011Fi and data usage");
}
+
+ @Test
+ public void summaryProviderSetListening_noDataUsageActivity_shouldReturnNoDataUsageSummary() {
+ final WifiMasterSwitchPreferenceController wifiPreferenceController =
+ mock(WifiMasterSwitchPreferenceController.class);
+ final MobileNetworkPreferenceController mobileNetworkPreferenceController =
+ mock(MobileNetworkPreferenceController.class);
+ final TetherPreferenceController tetherPreferenceController =
+ mock(TetherPreferenceController.class);
+
+ final SummaryLoader summaryLoader = mock(SummaryLoader.class);
+ final SummaryLoader.SummaryProvider provider =
+ new NetworkDashboardFragment.SummaryProvider(mContext, summaryLoader,
+ wifiPreferenceController, mobileNetworkPreferenceController,
+ tetherPreferenceController, () -> false);
+
+ provider.setListening(false);
+
+ verifyZeroInteractions(summaryLoader);
+
+ when(wifiPreferenceController.isAvailable()).thenReturn(true);
+ when(mobileNetworkPreferenceController.isAvailable()).thenReturn(true);
+ when(tetherPreferenceController.isAvailable()).thenReturn(true);
+
+ provider.setListening(true);
+
+ verify(summaryLoader).setSummary(provider, "Wi\u2011Fi, mobile, and hotspot");
+ }
+
+
}