• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.tv.settings.about;
18 
19 import android.content.Context;
20 
21 import androidx.annotation.Keep;
22 
23 import com.android.internal.logging.nano.MetricsProto;
24 import com.android.settingslib.core.AbstractPreferenceController;
25 import com.android.settingslib.core.lifecycle.Lifecycle;
26 import com.android.settingslib.deviceinfo.AbstractSimStatusImeiInfoPreferenceController;
27 import com.android.tv.settings.NopePreferenceController;
28 import com.android.tv.settings.PreferenceControllerFragment;
29 import com.android.tv.settings.R;
30 
31 import java.util.ArrayList;
32 import java.util.List;
33 
34 /**
35  * Fragment for showing device hardware info, such as MAC addresses and serial numbers
36  */
37 @Keep
38 public class StatusFragment extends PreferenceControllerFragment {
39 
40     private static final String KEY_BATTERY_STATUS = "battery_status";
41     private static final String KEY_BATTERY_LEVEL = "battery_level";
42     private static final String KEY_SIM_STATUS = "sim_status";
43     private static final String KEY_IMEI_INFO = "imei_info";
44 
newInstance()45     public static StatusFragment newInstance() {
46         return new StatusFragment();
47     }
48 
49     @Override
getMetricsCategory()50     public int getMetricsCategory() {
51         return MetricsProto.MetricsEvent.DEVICEINFO_STATUS;
52     }
53 
54     @Override
getPreferenceScreenResId()55     protected int getPreferenceScreenResId() {
56         return R.xml.device_info_status;
57     }
58 
59     @Override
onCreatePreferenceControllers(Context context)60     protected List<AbstractPreferenceController> onCreatePreferenceControllers(Context context) {
61         final List<AbstractPreferenceController> controllers = new ArrayList<>(10);
62         final Lifecycle lifecycle = getLifecycle();
63 
64         // TODO: detect if we have a battery or not
65         controllers.add(new NopePreferenceController(context, KEY_BATTERY_LEVEL));
66         controllers.add(new NopePreferenceController(context, KEY_BATTERY_STATUS));
67 
68         controllers.add(new SerialNumberPreferenceController(context));
69         controllers.add(new UptimePreferenceController(context, lifecycle));
70         controllers.add(new BluetoothAddressPreferenceController(context, lifecycle));
71         controllers.add(new IpAddressPreferenceController(context, lifecycle));
72         controllers.add(new WifiMacAddressPreferenceController(context, lifecycle));
73         controllers.add(new ImsStatusPreferenceController(context, lifecycle));
74 
75         controllers.add(new AdminUserAndPhoneOnlyPreferenceController(context, KEY_SIM_STATUS));
76         controllers.add(new AdminUserAndPhoneOnlyPreferenceController(context, KEY_IMEI_INFO));
77 
78         return controllers;
79     }
80 
81     private static class AdminUserAndPhoneOnlyPreferenceController
82             extends AbstractSimStatusImeiInfoPreferenceController {
83 
84         private final String mKey;
85 
AdminUserAndPhoneOnlyPreferenceController(Context context, String key)86         private AdminUserAndPhoneOnlyPreferenceController(Context context, String key) {
87             super(context);
88             mKey = key;
89         }
90 
91         @Override
getPreferenceKey()92         public String getPreferenceKey() {
93             return mKey;
94         }
95     }
96 }
97