1 /* 2 * Copyright (C) 2017 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.security; 18 19 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_LOCKED_NOTIFICATION_TITLE; 20 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_NOTIFICATIONS_SECTION_HEADER; 21 22 import android.app.settings.SettingsEnums; 23 import android.content.Context; 24 import android.database.ContentObserver; 25 import android.hardware.display.AmbientDisplayConfiguration; 26 import android.net.Uri; 27 import android.os.Bundle; 28 import android.os.Handler; 29 import android.os.Looper; 30 import android.provider.Settings; 31 32 import androidx.annotation.VisibleForTesting; 33 34 import com.android.settings.R; 35 import com.android.settings.dashboard.DashboardFragment; 36 import com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController; 37 import com.android.settings.display.AmbientDisplayNotificationsPreferenceController; 38 import com.android.settings.gestures.DoubleTapScreenPreferenceController; 39 import com.android.settings.gestures.PickupGesturePreferenceController; 40 import com.android.settings.notification.LockScreenNotificationPreferenceController; 41 import com.android.settings.search.BaseSearchIndexProvider; 42 import com.android.settings.security.screenlock.LockScreenPreferenceController; 43 import com.android.settingslib.core.AbstractPreferenceController; 44 import com.android.settingslib.core.lifecycle.Lifecycle; 45 import com.android.settingslib.search.SearchIndexable; 46 47 import java.util.ArrayList; 48 import java.util.List; 49 50 /** 51 * Settings screen for lock screen preference 52 */ 53 @SearchIndexable 54 public class LockscreenDashboardFragment extends DashboardFragment 55 implements OwnerInfoPreferenceController.OwnerInfoCallback { 56 57 public static final String KEY_AMBIENT_DISPLAY_ALWAYS_ON = "ambient_display_always_on"; 58 59 private static final String TAG = "LockscreenDashboardFragment"; 60 61 @VisibleForTesting 62 static final String KEY_LOCK_SCREEN_NOTIFICATON = "security_setting_lock_screen_notif"; 63 @VisibleForTesting 64 static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER = 65 "security_setting_lock_screen_notif_work_header"; 66 @VisibleForTesting 67 static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE = 68 "security_setting_lock_screen_notif_work"; 69 @VisibleForTesting 70 static final String KEY_ADD_USER_FROM_LOCK_SCREEN = 71 "security_lockscreen_add_users_when_locked"; 72 73 74 private AmbientDisplayConfiguration mConfig; 75 private OwnerInfoPreferenceController mOwnerInfoPreferenceController; 76 @VisibleForTesting 77 ContentObserver mControlsContentObserver; 78 79 @Override getMetricsCategory()80 public int getMetricsCategory() { 81 return SettingsEnums.SETTINGS_LOCK_SCREEN_PREFERENCES; 82 } 83 84 @Override getLogTag()85 protected String getLogTag() { 86 return TAG; 87 } 88 89 @Override onCreate(Bundle icicle)90 public void onCreate(Bundle icicle) { 91 super.onCreate(icicle); 92 replaceEnterpriseStringTitle("security_setting_lock_screen_notif_work", 93 WORK_PROFILE_LOCKED_NOTIFICATION_TITLE, 94 R.string.locked_work_profile_notification_title); 95 replaceEnterpriseStringTitle("security_setting_lock_screen_notif_work_header", 96 WORK_PROFILE_NOTIFICATIONS_SECTION_HEADER, R.string.profile_section_header); 97 } 98 99 @Override getPreferenceScreenResId()100 protected int getPreferenceScreenResId() { 101 return R.xml.security_lockscreen_settings; 102 } 103 104 @Override getHelpResource()105 public int getHelpResource() { 106 return R.string.help_url_lockscreen; 107 } 108 109 @Override onAttach(Context context)110 public void onAttach(Context context) { 111 super.onAttach(context); 112 use(AmbientDisplayAlwaysOnPreferenceController.class).setConfig(getConfig(context)); 113 use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context)); 114 use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context)); 115 use(PickupGesturePreferenceController.class).setConfig(getConfig(context)); 116 117 mControlsContentObserver = new ContentObserver( 118 new Handler(Looper.getMainLooper())) { 119 @Override 120 public void onChange(boolean selfChange, Uri uri) { 121 super.onChange(selfChange, uri); 122 updatePreferenceStates(); 123 } 124 }; 125 context.getContentResolver().registerContentObserver( 126 Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS), 127 false /* notifyForDescendants */, mControlsContentObserver); 128 } 129 130 @Override onDetach()131 public void onDetach() { 132 if (mControlsContentObserver != null) { 133 getContext().getContentResolver().unregisterContentObserver(mControlsContentObserver); 134 mControlsContentObserver = null; 135 } 136 super.onDetach(); 137 } 138 139 @Override createPreferenceControllers(Context context)140 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 141 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 142 final Lifecycle lifecycle = getSettingsLifecycle(); 143 final LockScreenNotificationPreferenceController notificationController = 144 new LockScreenNotificationPreferenceController(context, 145 KEY_LOCK_SCREEN_NOTIFICATON, 146 KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER, 147 KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE); 148 lifecycle.addObserver(notificationController); 149 controllers.add(notificationController); 150 mOwnerInfoPreferenceController = new OwnerInfoPreferenceController(context, this); 151 controllers.add(mOwnerInfoPreferenceController); 152 153 return controllers; 154 } 155 156 @Override onOwnerInfoUpdated()157 public void onOwnerInfoUpdated() { 158 if (mOwnerInfoPreferenceController != null) { 159 mOwnerInfoPreferenceController.updateSummary(); 160 } 161 } 162 getConfig(Context context)163 private AmbientDisplayConfiguration getConfig(Context context) { 164 if (mConfig == null) { 165 mConfig = new AmbientDisplayConfiguration(context); 166 } 167 return mConfig; 168 } 169 170 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 171 new BaseSearchIndexProvider(R.xml.security_lockscreen_settings) { 172 173 @Override 174 public List<AbstractPreferenceController> createPreferenceControllers( 175 Context context) { 176 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 177 controllers.add(new LockScreenNotificationPreferenceController(context)); 178 controllers.add(new OwnerInfoPreferenceController( 179 context, null /* fragment */)); 180 return controllers; 181 } 182 183 @Override 184 public List<String> getNonIndexableKeys(Context context) { 185 final List<String> niks = super.getNonIndexableKeys(context); 186 niks.add(KEY_ADD_USER_FROM_LOCK_SCREEN); 187 return niks; 188 } 189 190 @Override 191 protected boolean isPageSearchEnabled(Context context) { 192 return new LockScreenPreferenceController(context, "anykey") 193 .isAvailable(); 194 } 195 }; 196 } 197