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