• 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.deviceinfo.aboutphone;
18 
19 import android.app.Activity;
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.pm.UserInfo;
24 import android.os.Bundle;
25 import android.os.UserManager;
26 import android.provider.SearchIndexableResource;
27 import android.view.View;
28 
29 import com.android.settings.R;
30 import com.android.settings.Utils;
31 import com.android.settings.dashboard.DashboardFragment;
32 import com.android.settings.deviceinfo.BluetoothAddressPreferenceController;
33 import com.android.settings.deviceinfo.BuildNumberPreferenceController;
34 import com.android.settings.deviceinfo.DeviceNamePreferenceController;
35 import com.android.settings.deviceinfo.FccEquipmentIdPreferenceController;
36 import com.android.settings.deviceinfo.FeedbackPreferenceController;
37 import com.android.settings.deviceinfo.IpAddressPreferenceController;
38 import com.android.settings.deviceinfo.ManualPreferenceController;
39 import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
40 import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
41 import com.android.settings.deviceinfo.UptimePreferenceController;
42 import com.android.settings.deviceinfo.WifiMacAddressPreferenceController;
43 import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceController;
44 import com.android.settings.deviceinfo.simstatus.SimStatusPreferenceController;
45 import com.android.settings.search.BaseSearchIndexProvider;
46 import com.android.settings.widget.EntityHeaderController;
47 import com.android.settingslib.core.AbstractPreferenceController;
48 import com.android.settingslib.core.lifecycle.Lifecycle;
49 import com.android.settingslib.search.SearchIndexable;
50 import com.android.settingslib.widget.LayoutPreference;
51 
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.List;
55 
56 @SearchIndexable
57 public class MyDeviceInfoFragment extends DashboardFragment
58         implements DeviceNamePreferenceController.DeviceNamePreferenceHost {
59 
60     private static final String LOG_TAG = "MyDeviceInfoFragment";
61     private static final String KEY_MY_DEVICE_INFO_HEADER = "my_device_info_header";
62 
63     private BuildNumberPreferenceController mBuildNumberPreferenceController;
64 
65     @Override
getMetricsCategory()66     public int getMetricsCategory() {
67         return SettingsEnums.DEVICEINFO;
68     }
69 
70     @Override
getHelpResource()71     public int getHelpResource() {
72         return R.string.help_uri_about;
73     }
74 
75     @Override
onAttach(Context context)76     public void onAttach(Context context) {
77         super.onAttach(context);
78         use(ImeiInfoPreferenceController.class).setHost(this /* parent */);
79         use(DeviceNamePreferenceController.class).setHost(this /* parent */);
80         mBuildNumberPreferenceController = use(BuildNumberPreferenceController.class);
81         mBuildNumberPreferenceController.setHost(this /* parent */);
82     }
83 
84     @Override
onStart()85     public void onStart() {
86         super.onStart();
87         initHeader();
88     }
89 
90     @Override
getLogTag()91     protected String getLogTag() {
92         return LOG_TAG;
93     }
94 
95     @Override
getPreferenceScreenResId()96     protected int getPreferenceScreenResId() {
97         return R.xml.my_device_info;
98     }
99 
100     @Override
createPreferenceControllers(Context context)101     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
102         return buildPreferenceControllers(context, this /* fragment */, getSettingsLifecycle());
103     }
104 
buildPreferenceControllers( Context context, MyDeviceInfoFragment fragment, Lifecycle lifecycle)105     private static List<AbstractPreferenceController> buildPreferenceControllers(
106             Context context, MyDeviceInfoFragment fragment, Lifecycle lifecycle) {
107         final List<AbstractPreferenceController> controllers = new ArrayList<>();
108         controllers.add(new SimStatusPreferenceController(context, fragment));
109         controllers.add(new IpAddressPreferenceController(context, lifecycle));
110         controllers.add(new WifiMacAddressPreferenceController(context, lifecycle));
111         controllers.add(new BluetoothAddressPreferenceController(context, lifecycle));
112         controllers.add(new RegulatoryInfoPreferenceController(context));
113         controllers.add(new SafetyInfoPreferenceController(context));
114         controllers.add(new ManualPreferenceController(context));
115         controllers.add(new FeedbackPreferenceController(fragment, context));
116         controllers.add(new FccEquipmentIdPreferenceController(context));
117         controllers.add(new UptimePreferenceController(context, lifecycle));
118         return controllers;
119     }
120 
121     @Override
onActivityResult(int requestCode, int resultCode, Intent data)122     public void onActivityResult(int requestCode, int resultCode, Intent data) {
123         if (mBuildNumberPreferenceController.onActivityResult(requestCode, resultCode, data)) {
124             return;
125         }
126         super.onActivityResult(requestCode, resultCode, data);
127     }
128 
initHeader()129     private void initHeader() {
130         // TODO: Migrate into its own controller.
131         final LayoutPreference headerPreference =
132                 getPreferenceScreen().findPreference(KEY_MY_DEVICE_INFO_HEADER);
133         final boolean shouldDisplayHeader = getContext().getResources().getBoolean(
134                 R.bool.config_show_device_header_in_device_info);
135         headerPreference.setVisible(shouldDisplayHeader);
136         if (!shouldDisplayHeader) {
137             return;
138         }
139         final View headerView = headerPreference.findViewById(R.id.entity_header);
140         final Activity context = getActivity();
141         final Bundle bundle = getArguments();
142         final EntityHeaderController controller = EntityHeaderController
143                 .newInstance(context, this, headerView)
144                 .setRecyclerView(getListView(), getSettingsLifecycle())
145                 .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
146                         EntityHeaderController.ActionType.ACTION_NONE);
147 
148         // TODO: There may be an avatar setting action we can use here.
149         final int iconId = bundle.getInt("icon_id", 0);
150         if (iconId == 0) {
151             final UserManager userManager = (UserManager) getActivity().getSystemService(
152                     Context.USER_SERVICE);
153             final UserInfo info = Utils.getExistingUser(userManager,
154                     android.os.Process.myUserHandle());
155             controller.setLabel(info.name);
156             controller.setIcon(
157                     com.android.settingslib.Utils.getUserIcon(getActivity(), userManager, info));
158         }
159 
160         controller.done(context, true /* rebindActions */);
161     }
162 
163     @Override
showDeviceNameWarningDialog(String deviceName)164     public void showDeviceNameWarningDialog(String deviceName) {
165         DeviceNameWarningDialog.show(this);
166     }
167 
onSetDeviceNameConfirm(boolean confirm)168     public void onSetDeviceNameConfirm(boolean confirm) {
169         final DeviceNamePreferenceController controller = use(DeviceNamePreferenceController.class);
170         controller.updateDeviceName(confirm);
171     }
172 
173     /**
174      * For Search.
175      */
176     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
177             new BaseSearchIndexProvider() {
178 
179                 @Override
180                 public List<SearchIndexableResource> getXmlResourcesToIndex(
181                         Context context, boolean enabled) {
182                     final SearchIndexableResource sir = new SearchIndexableResource(context);
183                     sir.xmlResId = R.xml.my_device_info;
184                     return Arrays.asList(sir);
185                 }
186 
187                 @Override
188                 public List<AbstractPreferenceController> createPreferenceControllers(
189                         Context context) {
190                     return buildPreferenceControllers(context, null /* fragment */,
191                             null /* lifecycle */);
192                 }
193             };
194 }
195