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.NonNull; 33 import androidx.annotation.Nullable; 34 import androidx.annotation.VisibleForTesting; 35 36 import com.android.settings.R; 37 import com.android.settings.dashboard.DashboardFragment; 38 import com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController; 39 import com.android.settings.display.AmbientDisplayNotificationsPreferenceController; 40 import com.android.settings.gestures.DoubleTapScreenPreferenceController; 41 import com.android.settings.gestures.PickupGesturePreferenceController; 42 import com.android.settings.notification.LockScreenNotificationPreferenceController; 43 import com.android.settings.search.BaseSearchIndexProvider; 44 import com.android.settings.security.screenlock.LockScreenPreferenceController; 45 import com.android.settingslib.core.AbstractPreferenceController; 46 import com.android.settingslib.core.lifecycle.Lifecycle; 47 import com.android.settingslib.search.SearchIndexable; 48 49 import java.util.ArrayList; 50 import java.util.List; 51 52 /** 53 * Settings screen for lock screen preference 54 */ 55 @SearchIndexable 56 public class LockscreenDashboardFragment extends DashboardFragment 57 implements OwnerInfoPreferenceController.OwnerInfoCallback { 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 if (!isCatalystEnabled()) { 113 use(AmbientDisplayAlwaysOnPreferenceController.class).setConfig(getConfig(context)); 114 } 115 use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context)); 116 use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context)); 117 use(PickupGesturePreferenceController.class).setConfig(getConfig(context)); 118 119 mControlsContentObserver = new ContentObserver( 120 new Handler(Looper.getMainLooper())) { 121 @Override 122 public void onChange(boolean selfChange, Uri uri) { 123 super.onChange(selfChange, uri); 124 updatePreferenceStates(); 125 } 126 }; 127 context.getContentResolver().registerContentObserver( 128 Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS), 129 false /* notifyForDescendants */, mControlsContentObserver); 130 } 131 132 @Override onDetach()133 public void onDetach() { 134 if (mControlsContentObserver != null) { 135 getContext().getContentResolver().unregisterContentObserver(mControlsContentObserver); 136 mControlsContentObserver = null; 137 } 138 super.onDetach(); 139 } 140 141 @Override createPreferenceControllers(Context context)142 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 143 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 144 final Lifecycle lifecycle = getSettingsLifecycle(); 145 final LockScreenNotificationPreferenceController notificationController = 146 new LockScreenNotificationPreferenceController(context, 147 KEY_LOCK_SCREEN_NOTIFICATON, 148 KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER, 149 KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE); 150 lifecycle.addObserver(notificationController); 151 controllers.add(notificationController); 152 mOwnerInfoPreferenceController = new OwnerInfoPreferenceController(context, this); 153 controllers.add(mOwnerInfoPreferenceController); 154 155 return controllers; 156 } 157 158 @Override onOwnerInfoUpdated()159 public void onOwnerInfoUpdated() { 160 if (mOwnerInfoPreferenceController != null) { 161 mOwnerInfoPreferenceController.updateSummary(); 162 } 163 } 164 165 @Override getPreferenceScreenBindingKey(@onNull Context context)166 public @Nullable String getPreferenceScreenBindingKey(@NonNull Context context) { 167 return LockScreenPreferenceScreen.KEY; 168 } 169 getConfig(Context context)170 private AmbientDisplayConfiguration getConfig(Context context) { 171 if (mConfig == null) { 172 mConfig = new AmbientDisplayConfiguration(context); 173 } 174 return mConfig; 175 } 176 177 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 178 new BaseSearchIndexProvider(R.xml.security_lockscreen_settings) { 179 180 @Override 181 public List<AbstractPreferenceController> createPreferenceControllers( 182 Context context) { 183 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 184 controllers.add(new LockScreenNotificationPreferenceController(context)); 185 controllers.add(new OwnerInfoPreferenceController( 186 context, null /* fragment */)); 187 return controllers; 188 } 189 190 @Override 191 public List<String> getNonIndexableKeys(Context context) { 192 final List<String> niks = super.getNonIndexableKeys(context); 193 niks.add(KEY_ADD_USER_FROM_LOCK_SCREEN); 194 return niks; 195 } 196 197 @Override 198 protected boolean isPageSearchEnabled(Context context) { 199 return new LockScreenPreferenceController(context, "anykey") 200 .isAvailable(); 201 } 202 }; 203 } 204