• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import java.util.HashSet;
30 import java.util.Set;
31 
32 /**
33  * The controller displays a data usage chart for the specified Wi-Fi network.
34  */
35 public class WifiDataUsageSummaryPreferenceController extends DataUsageSummaryPreferenceController {
36     final Set<String> mAllNetworkKeys;
37 
WifiDataUsageSummaryPreferenceController(Activity activity, Lifecycle lifecycle, PreferenceFragmentCompat fragment, Set<String> allNetworkKeys)38     public WifiDataUsageSummaryPreferenceController(Activity activity, Lifecycle lifecycle,
39             PreferenceFragmentCompat fragment, Set<String> allNetworkKeys) {
40         super(activity, lifecycle, fragment, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
41         mAllNetworkKeys = new HashSet<>(allNetworkKeys);
42     }
43 
44     @Override
updateState(Preference preference)45     public void updateState(Preference preference) {
46         if (preference == null) {
47             return;
48         }
49 
50         final DataUsageSummaryPreference mPreference = (DataUsageSummaryPreference) preference;
51         final NetworkTemplate template = new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI)
52                 .setWifiNetworkKeys(mAllNetworkKeys).build();
53         if (mDataUsageController == null) {
54             updateConfiguration(mContext, mSubId, getSubscriptionInfo(mSubId));
55         }
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