Home | History | Annotate | Download | only in settings
      1 /*
      2  * Copyright (C) 2008 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;
     18 
     19 import android.app.Activity;
     20 import android.app.Fragment;
     21 import android.content.Context;
     22 import android.content.Intent;
     23 import android.provider.SearchIndexableResource;
     24 
     25 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     26 import com.android.settings.dashboard.DashboardFragment;
     27 import com.android.settings.dashboard.SummaryLoader;
     28 import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
     29 import com.android.settings.deviceinfo.BasebandVersionPreferenceController;
     30 import com.android.settings.deviceinfo.BuildNumberPreferenceController;
     31 import com.android.settings.deviceinfo.DeviceModelPreferenceController;
     32 import com.android.settings.deviceinfo.FccEquipmentIdPreferenceController;
     33 import com.android.settings.deviceinfo.FeedbackPreferenceController;
     34 import com.android.settings.deviceinfo.FirmwareVersionPreferenceController;
     35 import com.android.settings.deviceinfo.KernelVersionPreferenceController;
     36 import com.android.settings.deviceinfo.ManualPreferenceController;
     37 import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
     38 import com.android.settings.deviceinfo.SELinuxStatusPreferenceController;
     39 import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
     40 import com.android.settings.deviceinfo.SecurityPatchPreferenceController;
     41 import com.android.settings.search.BaseSearchIndexProvider;
     42 import com.android.settings.search.Indexable;
     43 import com.android.settingslib.core.AbstractPreferenceController;
     44 import com.android.settingslib.core.lifecycle.Lifecycle;
     45 
     46 import java.util.ArrayList;
     47 import java.util.Arrays;
     48 import java.util.List;
     49 
     50 public class DeviceInfoSettings extends DashboardFragment implements Indexable {
     51 
     52     private static final String LOG_TAG = "DeviceInfoSettings";
     53 
     54     private static final String KEY_LEGAL_CONTAINER = "legal_container";
     55 
     56     @Override
     57     public int getMetricsCategory() {
     58         return MetricsEvent.DEVICEINFO;
     59     }
     60 
     61     @Override
     62     protected int getHelpResource() {
     63         return R.string.help_uri_about;
     64     }
     65 
     66     @Override
     67     public void onActivityResult(int requestCode, int resultCode, Intent data) {
     68         final BuildNumberPreferenceController buildNumberPreferenceController =
     69                 getPreferenceController(BuildNumberPreferenceController.class);
     70         if (buildNumberPreferenceController.onActivityResult(requestCode, resultCode, data)) {
     71             return;
     72         }
     73         super.onActivityResult(requestCode, resultCode, data);
     74     }
     75 
     76     @Override
     77     protected String getLogTag() {
     78         return LOG_TAG;
     79     }
     80 
     81     @Override
     82     protected int getPreferenceScreenResId() {
     83         return R.xml.device_info_settings;
     84     }
     85 
     86     @Override
     87     protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
     88         return buildPreferenceControllers(context, getActivity(), this /* fragment */,
     89                 getLifecycle());
     90     }
     91 
     92     private static class SummaryProvider implements SummaryLoader.SummaryProvider {
     93 
     94         private final SummaryLoader mSummaryLoader;
     95 
     96         public SummaryProvider(SummaryLoader summaryLoader) {
     97             mSummaryLoader = summaryLoader;
     98         }
     99 
    100         @Override
    101         public void setListening(boolean listening) {
    102             if (listening) {
    103                 mSummaryLoader.setSummary(this, DeviceModelPreferenceController.getDeviceModel());
    104             }
    105         }
    106     }
    107 
    108     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
    109             = new SummaryLoader.SummaryProviderFactory() {
    110         @Override
    111         public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
    112                 SummaryLoader summaryLoader) {
    113             return new SummaryProvider(summaryLoader);
    114         }
    115     };
    116 
    117     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
    118             Activity activity, Fragment fragment, Lifecycle lifecycle) {
    119         final List<AbstractPreferenceController> controllers = new ArrayList<>();
    120         controllers.add(
    121                 new BuildNumberPreferenceController(context, activity, fragment, lifecycle));
    122         controllers.add(new AdditionalSystemUpdatePreferenceController(context));
    123         controllers.add(new ManualPreferenceController(context));
    124         controllers.add(new FeedbackPreferenceController(fragment, context));
    125         controllers.add(new KernelVersionPreferenceController(context));
    126         controllers.add(new BasebandVersionPreferenceController(context));
    127         controllers.add(new FirmwareVersionPreferenceController(context, lifecycle));
    128         controllers.add(new RegulatoryInfoPreferenceController(context));
    129         controllers.add(new DeviceModelPreferenceController(context, fragment));
    130         controllers.add(new SecurityPatchPreferenceController(context));
    131         controllers.add(new FccEquipmentIdPreferenceController(context));
    132         controllers.add(new SELinuxStatusPreferenceController(context));
    133         controllers.add(new SafetyInfoPreferenceController(context));
    134         return controllers;
    135     }
    136 
    137     /**
    138      * For Search.
    139      */
    140     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
    141             new BaseSearchIndexProvider() {
    142 
    143                 @Override
    144                 public List<SearchIndexableResource> getXmlResourcesToIndex(
    145                         Context context, boolean enabled) {
    146                     final SearchIndexableResource sir = new SearchIndexableResource(context);
    147                     sir.xmlResId = R.xml.device_info_settings;
    148                     return Arrays.asList(sir);
    149                 }
    150 
    151                 @Override
    152                 public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
    153                     return buildPreferenceControllers(context, null /*activity */,
    154                             null /* fragment */, null /* lifecycle */);
    155                 }
    156 
    157                 @Override
    158                 public List<String> getNonIndexableKeys(Context context) {
    159                     List<String> keys = super.getNonIndexableKeys(context);
    160                     keys.add(KEY_LEGAL_CONTAINER);
    161                     return keys;
    162                 }
    163             };
    164 }
    165