Home | History | Annotate | Download | only in security
      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 package com.android.settings.security;
     17 
     18 import static com.android.settings.security.EncryptionStatusPreferenceController
     19         .PREF_KEY_ENCRYPTION_SECURITY_PAGE;
     20 
     21 import android.app.Activity;
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.hardware.fingerprint.FingerprintManager;
     25 import android.provider.SearchIndexableResource;
     26 
     27 import com.android.internal.logging.nano.MetricsProto;
     28 import com.android.settings.R;
     29 import com.android.settings.Utils;
     30 import com.android.settings.dashboard.DashboardFragment;
     31 import com.android.settings.dashboard.SummaryLoader;
     32 import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
     33 import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
     34 import com.android.settings.fingerprint.FingerprintProfileStatusPreferenceController;
     35 import com.android.settings.fingerprint.FingerprintStatusPreferenceController;
     36 import com.android.settings.location.LocationPreferenceController;
     37 import com.android.settings.search.BaseSearchIndexProvider;
     38 import com.android.settings.security.screenlock.LockScreenPreferenceController;
     39 import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
     40 import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
     41 import com.android.settings.widget.PreferenceCategoryController;
     42 import com.android.settingslib.core.AbstractPreferenceController;
     43 import com.android.settingslib.core.lifecycle.Lifecycle;
     44 
     45 import java.util.ArrayList;
     46 import java.util.List;
     47 
     48 public class SecuritySettings extends DashboardFragment {
     49 
     50     private static final String TAG = "SecuritySettings";
     51     private static final String SECURITY_CATEGORY = "security_category";
     52     private static final String WORK_PROFILE_SECURITY_CATEGORY = "security_category_profile";
     53 
     54     public static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
     55     public static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 128;
     56     public static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129;
     57     public static final int UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 130;
     58 
     59     @Override
     60     public int getMetricsCategory() {
     61         return MetricsProto.MetricsEvent.SECURITY;
     62     }
     63 
     64     @Override
     65     protected int getPreferenceScreenResId() {
     66         return R.xml.security_dashboard_settings;
     67     }
     68 
     69     @Override
     70     protected String getLogTag() {
     71         return TAG;
     72     }
     73 
     74     @Override
     75     public int getHelpResource() {
     76         return R.string.help_url_security;
     77     }
     78 
     79     @Override
     80     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     81         return buildPreferenceControllers(context, getLifecycle(), this /* host*/);
     82     }
     83 
     84     /**
     85      * see confirmPatternThenDisableAndClear
     86      */
     87     @Override
     88     public void onActivityResult(int requestCode, int resultCode, Intent data) {
     89         if (use(TrustAgentListPreferenceController.class)
     90                 .handleActivityResult(requestCode, resultCode)) {
     91             return;
     92         }
     93         if (use(LockUnificationPreferenceController.class)
     94                 .handleActivityResult(requestCode, resultCode, data)) {
     95             return;
     96         }
     97         super.onActivityResult(requestCode, resultCode, data);
     98     }
     99 
    100     void launchConfirmDeviceLockForUnification() {
    101         use(LockUnificationPreferenceController.class)
    102                 .launchConfirmDeviceLockForUnification();
    103     }
    104 
    105     void unifyUncompliantLocks() {
    106         use(LockUnificationPreferenceController.class).unifyUncompliantLocks();
    107     }
    108 
    109     void updateUnificationPreference() {
    110         use(LockUnificationPreferenceController.class).updateState(null);
    111     }
    112 
    113     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
    114             Lifecycle lifecycle, SecuritySettings host) {
    115         final List<AbstractPreferenceController> controllers = new ArrayList<>();
    116         controllers.add(new LocationPreferenceController(context, lifecycle));
    117         controllers.add(new ManageDeviceAdminPreferenceController(context));
    118         controllers.add(new EnterprisePrivacyPreferenceController(context));
    119         controllers.add(new ManageTrustAgentsPreferenceController(context));
    120         controllers.add(new ScreenPinningPreferenceController(context));
    121         controllers.add(new SimLockPreferenceController(context));
    122         controllers.add(new ShowPasswordPreferenceController(context));
    123         controllers.add(new EncryptionStatusPreferenceController(context,
    124                 PREF_KEY_ENCRYPTION_SECURITY_PAGE));
    125         controllers.add(new TrustAgentListPreferenceController(context, host, lifecycle));
    126 
    127         final List<AbstractPreferenceController> securityPreferenceControllers = new ArrayList<>();
    128         securityPreferenceControllers.add(new FingerprintStatusPreferenceController(context));
    129         securityPreferenceControllers.add(new LockScreenPreferenceController(context, lifecycle));
    130         securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host));
    131         controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
    132                 .setChildren(securityPreferenceControllers));
    133         controllers.addAll(securityPreferenceControllers);
    134 
    135         final List<AbstractPreferenceController> profileSecurityControllers = new ArrayList<>();
    136         profileSecurityControllers.add(new ChangeProfileScreenLockPreferenceController(
    137                 context, host));
    138         profileSecurityControllers.add(new LockUnificationPreferenceController(context, host));
    139         profileSecurityControllers.add(new VisiblePatternProfilePreferenceController(
    140                 context, lifecycle));
    141         profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(context));
    142         controllers.add(new PreferenceCategoryController(context, WORK_PROFILE_SECURITY_CATEGORY)
    143                 .setChildren(profileSecurityControllers));
    144         controllers.addAll(profileSecurityControllers);
    145 
    146         return controllers;
    147     }
    148 
    149     /**
    150      * For Search. Please keep it in sync when updating "createPreferenceHierarchy()"
    151      */
    152     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
    153             new BaseSearchIndexProvider() {
    154 
    155                 @Override
    156                 public List<SearchIndexableResource> getXmlResourcesToIndex(
    157                         Context context, boolean enabled) {
    158                     final List<SearchIndexableResource> index = new ArrayList<>();
    159                     // Append the rest of the settings
    160                     final SearchIndexableResource sir = new SearchIndexableResource(context);
    161                     sir.xmlResId = R.xml.security_dashboard_settings;
    162                     index.add(sir);
    163                     return index;
    164                 }
    165 
    166                 @Override
    167                 public List<AbstractPreferenceController> createPreferenceControllers(Context
    168                         context) {
    169                     return buildPreferenceControllers(context, null /* lifecycle */,
    170                             null /* host*/);
    171                 }
    172             };
    173 
    174     static class SummaryProvider implements SummaryLoader.SummaryProvider {
    175 
    176         private final Context mContext;
    177         private final SummaryLoader mSummaryLoader;
    178 
    179         public SummaryProvider(Context context, SummaryLoader summaryLoader) {
    180             mContext = context;
    181             mSummaryLoader = summaryLoader;
    182         }
    183 
    184         @Override
    185         public void setListening(boolean listening) {
    186             if (listening) {
    187                 final FingerprintManager fpm =
    188                         Utils.getFingerprintManagerOrNull(mContext);
    189                 if (fpm != null && fpm.isHardwareDetected()) {
    190                     mSummaryLoader.setSummary(this,
    191                             mContext.getString(R.string.security_dashboard_summary));
    192                 } else {
    193                     mSummaryLoader.setSummary(this, mContext.getString(
    194                             R.string.security_dashboard_summary_no_fingerprint));
    195                 }
    196             }
    197         }
    198     }
    199 
    200     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
    201             new SummaryLoader.SummaryProviderFactory() {
    202                 @Override
    203                 public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
    204                         SummaryLoader summaryLoader) {
    205                     return new SummaryProvider(activity, summaryLoader);
    206                 }
    207             };
    208 }
    209