Home | History | Annotate | Download | only in aboutphone
      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 static com.android.settings.bluetooth.Utils.getLocalBtManager;
     20 
     21 import android.app.Activity;
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.content.pm.UserInfo;
     25 import android.os.Bundle;
     26 import android.os.UserManager;
     27 import android.provider.SearchIndexableResource;
     28 import android.view.View;
     29 
     30 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     31 import com.android.settings.R;
     32 import com.android.settings.Utils;
     33 import com.android.settings.accounts.EmergencyInfoPreferenceController;
     34 import com.android.settings.applications.LayoutPreference;
     35 import com.android.settings.dashboard.DashboardFragment;
     36 import com.android.settings.dashboard.SummaryLoader;
     37 import com.android.settings.deviceinfo.BluetoothAddressPreferenceController;
     38 import com.android.settings.deviceinfo.BrandedAccountPreferenceController;
     39 import com.android.settings.deviceinfo.BuildNumberPreferenceController;
     40 import com.android.settings.deviceinfo.DeviceModelPreferenceController;
     41 import com.android.settings.deviceinfo.DeviceNamePreferenceController;
     42 import com.android.settings.deviceinfo.FccEquipmentIdPreferenceController;
     43 import com.android.settings.deviceinfo.FeedbackPreferenceController;
     44 import com.android.settings.deviceinfo.IpAddressPreferenceController;
     45 import com.android.settings.deviceinfo.ManualPreferenceController;
     46 import com.android.settings.deviceinfo.PhoneNumberPreferenceController;
     47 import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
     48 import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
     49 import com.android.settings.deviceinfo.WifiMacAddressPreferenceController;
     50 import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController;
     51 import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceController;
     52 import com.android.settings.deviceinfo.simstatus.SimStatusPreferenceController;
     53 import com.android.settings.search.BaseSearchIndexProvider;
     54 import com.android.settings.widget.EntityHeaderController;
     55 import com.android.settingslib.core.AbstractPreferenceController;
     56 import com.android.settingslib.core.lifecycle.Lifecycle;
     57 
     58 import java.util.ArrayList;
     59 import java.util.Arrays;
     60 import java.util.List;
     61 
     62 public class MyDeviceInfoFragment extends DashboardFragment
     63         implements DeviceNamePreferenceController.DeviceNamePreferenceHost {
     64     private static final String LOG_TAG = "MyDeviceInfoFragment";
     65 
     66     private static final String KEY_MY_DEVICE_INFO_HEADER = "my_device_info_header";
     67     private static final String KEY_LEGAL_CONTAINER = "legal_container";
     68 
     69     @Override
     70     public int getMetricsCategory() {
     71         return MetricsEvent.DEVICEINFO;
     72     }
     73 
     74     @Override
     75     public int getHelpResource() {
     76         return R.string.help_uri_about;
     77     }
     78 
     79     @Override
     80     public void onResume() {
     81         super.onResume();
     82         initHeader();
     83     }
     84 
     85     @Override
     86     protected String getLogTag() {
     87         return LOG_TAG;
     88     }
     89 
     90     @Override
     91     protected int getPreferenceScreenResId() {
     92         return R.xml.my_device_info;
     93     }
     94 
     95     @Override
     96     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     97         return buildPreferenceControllers(context, getActivity(), this /* fragment */,
     98                 getLifecycle());
     99     }
    100 
    101     private static List<AbstractPreferenceController> buildPreferenceControllers(
    102             Context context,
    103             Activity activity,
    104             MyDeviceInfoFragment fragment,
    105             Lifecycle lifecycle) {
    106         final List<AbstractPreferenceController> controllers = new ArrayList<>();
    107         controllers.add(new EmergencyInfoPreferenceController(context));
    108         controllers.add(new PhoneNumberPreferenceController(context));
    109         controllers.add(new BrandedAccountPreferenceController(context));
    110         DeviceNamePreferenceController deviceNamePreferenceController =
    111                 new DeviceNamePreferenceController(context);
    112         deviceNamePreferenceController.setLocalBluetoothManager(getLocalBtManager(context));
    113         deviceNamePreferenceController.setHost(fragment);
    114         if (lifecycle != null) {
    115             lifecycle.addObserver(deviceNamePreferenceController);
    116         }
    117         controllers.add(deviceNamePreferenceController);
    118         controllers.add(new SimStatusPreferenceController(context, fragment));
    119         controllers.add(new DeviceModelPreferenceController(context, fragment));
    120         controllers.add(new ImeiInfoPreferenceController(context, fragment));
    121         controllers.add(new FirmwareVersionPreferenceController(context, fragment));
    122         controllers.add(new IpAddressPreferenceController(context, lifecycle));
    123         controllers.add(new WifiMacAddressPreferenceController(context, lifecycle));
    124         controllers.add(new BluetoothAddressPreferenceController(context, lifecycle));
    125         controllers.add(new RegulatoryInfoPreferenceController(context));
    126         controllers.add(new SafetyInfoPreferenceController(context));
    127         controllers.add(new ManualPreferenceController(context));
    128         controllers.add(new FeedbackPreferenceController(fragment, context));
    129         controllers.add(new FccEquipmentIdPreferenceController(context));
    130         controllers.add(
    131                 new BuildNumberPreferenceController(context, activity, fragment, lifecycle));
    132         return controllers;
    133     }
    134 
    135     @Override
    136     public void onActivityResult(int requestCode, int resultCode, Intent data) {
    137         final BuildNumberPreferenceController buildNumberPreferenceController =
    138             use(BuildNumberPreferenceController.class);
    139         if (buildNumberPreferenceController.onActivityResult(requestCode, resultCode, data)) {
    140             return;
    141         }
    142         super.onActivityResult(requestCode, resultCode, data);
    143     }
    144 
    145     private void initHeader() {
    146         // TODO: Migrate into its own controller.
    147         final LayoutPreference headerPreference =
    148                 (LayoutPreference) getPreferenceScreen().findPreference(KEY_MY_DEVICE_INFO_HEADER);
    149         final View appSnippet = headerPreference.findViewById(R.id.entity_header);
    150         final Activity context = getActivity();
    151         final Bundle bundle = getArguments();
    152         EntityHeaderController controller = EntityHeaderController
    153                 .newInstance(context, this, appSnippet)
    154                 .setRecyclerView(getListView(), getLifecycle())
    155                 .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
    156                         EntityHeaderController.ActionType.ACTION_NONE);
    157 
    158         // TODO: There may be an avatar setting action we can use here.
    159         final int iconId = bundle.getInt("icon_id", 0);
    160         if (iconId == 0) {
    161             UserManager userManager = (UserManager) getActivity().getSystemService(
    162                     Context.USER_SERVICE);
    163             UserInfo info = Utils.getExistingUser(userManager, android.os.Process.myUserHandle());
    164             controller.setLabel(info.name);
    165             controller.setIcon(
    166                     com.android.settingslib.Utils.getUserIcon(getActivity(), userManager, info));
    167         }
    168 
    169         controller.done(context, true /* rebindActions */);
    170     }
    171 
    172     @Override
    173     public void showDeviceNameWarningDialog(String deviceName) {
    174         DeviceNameWarningDialog.show(this);
    175     }
    176 
    177     public void onSetDeviceNameConfirm() {
    178         final DeviceNamePreferenceController controller = use(DeviceNamePreferenceController.class);
    179         controller.confirmDeviceName();
    180     }
    181 
    182     private static class SummaryProvider implements SummaryLoader.SummaryProvider {
    183 
    184         private final SummaryLoader mSummaryLoader;
    185 
    186         public SummaryProvider(SummaryLoader summaryLoader) {
    187             mSummaryLoader = summaryLoader;
    188         }
    189 
    190         @Override
    191         public void setListening(boolean listening) {
    192             if (listening) {
    193                 mSummaryLoader.setSummary(this, DeviceModelPreferenceController.getDeviceModel());
    194             }
    195         }
    196     }
    197 
    198     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
    199             = (activity, summaryLoader) -> new SummaryProvider(summaryLoader);
    200 
    201     /**
    202      * For Search.
    203      */
    204     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
    205             new BaseSearchIndexProvider() {
    206 
    207                 @Override
    208                 public List<SearchIndexableResource> getXmlResourcesToIndex(
    209                         Context context, boolean enabled) {
    210                     final SearchIndexableResource sir = new SearchIndexableResource(context);
    211                     sir.xmlResId = R.xml.my_device_info;
    212                     return Arrays.asList(sir);
    213                 }
    214 
    215                 @Override
    216                 public List<AbstractPreferenceController> createPreferenceControllers(
    217                         Context context) {
    218                     return buildPreferenceControllers(context, null /*activity */,
    219                             null /* fragment */, null /* lifecycle */);
    220                 }
    221 
    222                 @Override
    223                 public List<String> getNonIndexableKeys(Context context) {
    224                     List<String> keys = super.getNonIndexableKeys(context);
    225                     // The legal container is duplicated, so we ignore it here.
    226                     keys.add(KEY_LEGAL_CONTAINER);
    227                     return keys;
    228                 }
    229             };
    230 }
    231