*/
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;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.function.BooleanSupplier;
import java.util.List;
@SearchIndexable
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;
}
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)) {
final SummaryLoader.SummaryProvider provider =
new NetworkDashboardFragment.SummaryProvider(mContext, summaryLoader,
wifiPreferenceController, mobileNetworkPreferenceController,
- tetherPreferenceController);
+ tetherPreferenceController, () -> true);
provider.setListening(false);
final SummaryLoader.SummaryProvider provider =
new NetworkDashboardFragment.SummaryProvider(mContext, summaryLoader,
wifiPreferenceController, mobileNetworkPreferenceController,
- tetherPreferenceController);
+ tetherPreferenceController, () -> true);
provider.setListening(false);
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");
+ }
+
+
}