• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.network;
18 
19 import android.content.Context;
20 import android.icu.text.ListFormatter;
21 import android.text.BidiFormatter;
22 import android.text.TextUtils;
23 
24 import com.android.settings.R;
25 import com.android.settings.Utils;
26 import com.android.settings.core.BasePreferenceController;
27 import com.android.settings.wifi.WifiMasterSwitchPreferenceController;
28 
29 import java.util.ArrayList;
30 import java.util.List;
31 
32 public class TopLevelNetworkEntryPreferenceController extends BasePreferenceController {
33 
34     private final WifiMasterSwitchPreferenceController mWifiPreferenceController;
35     private final MobileNetworkPreferenceController mMobileNetworkPreferenceController;
36     private final TetherPreferenceController mTetherPreferenceController;
37 
TopLevelNetworkEntryPreferenceController(Context context, String preferenceKey)38     public TopLevelNetworkEntryPreferenceController(Context context, String preferenceKey) {
39         super(context, preferenceKey);
40         mMobileNetworkPreferenceController = new MobileNetworkPreferenceController(mContext);
41         mTetherPreferenceController = new TetherPreferenceController(
42                 mContext, null /* lifecycle */);
43         mWifiPreferenceController = new WifiMasterSwitchPreferenceController(
44                 mContext, null /* metrics */);
45     }
46 
47     @Override
getAvailabilityStatus()48     public int getAvailabilityStatus() {
49         return Utils.isDemoUser(mContext) ? UNSUPPORTED_ON_DEVICE : AVAILABLE_UNSEARCHABLE;
50     }
51 
52     @Override
getSummary()53     public CharSequence getSummary() {
54         final String wifiSummary = BidiFormatter.getInstance()
55                 .unicodeWrap(mContext.getString(R.string.wifi_settings_title));
56         final String mobileSummary = mContext.getString(
57                 R.string.network_dashboard_summary_mobile);
58         final String dataUsageSummary = mContext.getString(
59                 R.string.network_dashboard_summary_data_usage);
60         final String hotspotSummary = mContext.getString(
61                 R.string.network_dashboard_summary_hotspot);
62 
63         final List<String> summaries = new ArrayList<>();
64         if (mWifiPreferenceController.isAvailable()
65                 && !TextUtils.isEmpty(wifiSummary)) {
66             summaries.add(wifiSummary);
67         }
68         if (mMobileNetworkPreferenceController.isAvailable() && !TextUtils.isEmpty(mobileSummary)) {
69             summaries.add(mobileSummary);
70         }
71         if (!TextUtils.isEmpty(dataUsageSummary)) {
72             summaries.add(dataUsageSummary);
73         }
74         if (mTetherPreferenceController.isAvailable()
75                 && !TextUtils.isEmpty(hotspotSummary)) {
76             summaries.add(hotspotSummary);
77         }
78         return ListFormatter.getInstance().format(summaries);
79     }
80 }
81