1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.datausage; 18 19 import android.app.Activity; 20 import android.net.NetworkTemplate; 21 import android.telephony.SubscriptionManager; 22 23 import androidx.preference.Preference; 24 import androidx.preference.PreferenceFragmentCompat; 25 26 import com.android.settingslib.core.lifecycle.Lifecycle; 27 import com.android.settingslib.net.DataUsageController; 28 29 /** 30 * The controller displays a data usage chart for the specified Wi-Fi network. 31 */ 32 public class WifiDataUsageSummaryPreferenceController extends DataUsageSummaryPreferenceController { 33 final String mNetworkId; 34 WifiDataUsageSummaryPreferenceController(Activity activity, Lifecycle lifecycle, PreferenceFragmentCompat fragment, CharSequence networkId)35 public WifiDataUsageSummaryPreferenceController(Activity activity, 36 Lifecycle lifecycle, PreferenceFragmentCompat fragment, CharSequence networkId) { 37 super(activity, lifecycle, fragment, SubscriptionManager.INVALID_SUBSCRIPTION_ID); 38 39 if (networkId == null) { 40 mNetworkId = null; 41 } else { 42 mNetworkId = String.valueOf(networkId); 43 } 44 } 45 46 @Override updateState(Preference preference)47 public void updateState(Preference preference) { 48 if (preference == null) { 49 return; 50 } 51 52 final DataUsageSummaryPreference mPreference = (DataUsageSummaryPreference) preference; 53 // TODO(b/126299427): Currently gets data usage of whole Wi-Fi networks, but should get 54 // specified one. 55 final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(mNetworkId); 56 final DataUsageController.DataUsageInfo info = mDataUsageController.getDataUsageInfo( 57 template); 58 mDataInfoController.updateDataLimit(info, mPolicyEditor.getPolicy(template)); 59 60 mPreference.setWifiMode(/* isWifiMode */ true, /* usagePeriod */ 61 info.period, /* isSingleWifi */ true); 62 mPreference.setChartEnabled(true); 63 // Treats Wi-Fi network as unlimited network, which has same usage level and limited level. 64 mPreference.setUsageNumbers(info.usageLevel, info.usageLevel, /* hasMobileData */ false); 65 66 // TODO(b/126142293): Passpoint Wi-Fi should have limit of data usage and time remaining 67 mPreference.setProgress(100); 68 mPreference.setLabels(DataUsageUtils.formatDataUsage(mContext, /* sizeBytes */ 0), 69 DataUsageUtils.formatDataUsage(mContext, info.usageLevel)); 70 } 71 } 72