• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.hardware.display.AmbientDisplayConfiguration;
22 import android.provider.SearchIndexableResource;
23 
24 import androidx.annotation.VisibleForTesting;
25 
26 import com.android.settings.R;
27 import com.android.settings.dashboard.DashboardFragment;
28 import com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController;
29 import com.android.settings.display.AmbientDisplayNotificationsPreferenceController;
30 import com.android.settings.gestures.DoubleTapScreenPreferenceController;
31 import com.android.settings.gestures.PickupGesturePreferenceController;
32 import com.android.settings.notification.LockScreenNotificationPreferenceController;
33 import com.android.settings.search.BaseSearchIndexProvider;
34 import com.android.settings.security.screenlock.LockScreenPreferenceController;
35 import com.android.settingslib.core.AbstractPreferenceController;
36 import com.android.settingslib.core.lifecycle.Lifecycle;
37 import com.android.settingslib.search.SearchIndexable;
38 
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.List;
42 
43 /**
44  * Settings screen for lock screen preference
45  */
46 @SearchIndexable
47 public class LockscreenDashboardFragment extends DashboardFragment
48         implements OwnerInfoPreferenceController.OwnerInfoCallback {
49 
50     public static final String KEY_AMBIENT_DISPLAY_ALWAYS_ON = "ambient_display_always_on";
51 
52     private static final String TAG = "LockscreenDashboardFragment";
53 
54     @VisibleForTesting
55     static final String KEY_LOCK_SCREEN_NOTIFICATON = "security_setting_lock_screen_notif";
56     @VisibleForTesting
57     static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER =
58             "security_setting_lock_screen_notif_work_header";
59     @VisibleForTesting
60     static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE =
61             "security_setting_lock_screen_notif_work";
62     @VisibleForTesting
63     static final String KEY_ADD_USER_FROM_LOCK_SCREEN =
64             "security_lockscreen_add_users_when_locked";
65 
66 
67     private AmbientDisplayConfiguration mConfig;
68     private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
69 
70     @Override
getMetricsCategory()71     public int getMetricsCategory() {
72         return SettingsEnums.SETTINGS_LOCK_SCREEN_PREFERENCES;
73     }
74 
75     @Override
getLogTag()76     protected String getLogTag() {
77         return TAG;
78     }
79 
80     @Override
getPreferenceScreenResId()81     protected int getPreferenceScreenResId() {
82         return R.xml.security_lockscreen_settings;
83     }
84 
85     @Override
getHelpResource()86     public int getHelpResource() {
87         return R.string.help_url_lockscreen;
88     }
89 
90     @Override
onAttach(Context context)91     public void onAttach(Context context) {
92         super.onAttach(context);
93         use(AmbientDisplayAlwaysOnPreferenceController.class)
94                 .setConfig(getConfig(context))
95                 .setCallback(this::updatePreferenceStates);
96         use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context));
97         use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
98         use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
99     }
100 
101     @Override
createPreferenceControllers(Context context)102     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
103         final List<AbstractPreferenceController> controllers = new ArrayList<>();
104         final Lifecycle lifecycle = getSettingsLifecycle();
105         final LockScreenNotificationPreferenceController notificationController =
106                 new LockScreenNotificationPreferenceController(context,
107                         KEY_LOCK_SCREEN_NOTIFICATON,
108                         KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER,
109                         KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE);
110         lifecycle.addObserver(notificationController);
111         controllers.add(notificationController);
112         mOwnerInfoPreferenceController =
113                 new OwnerInfoPreferenceController(context, this, lifecycle);
114         controllers.add(mOwnerInfoPreferenceController);
115 
116         return controllers;
117     }
118 
119     @Override
onOwnerInfoUpdated()120     public void onOwnerInfoUpdated() {
121         if (mOwnerInfoPreferenceController != null) {
122             mOwnerInfoPreferenceController.updateSummary();
123         }
124     }
125 
getConfig(Context context)126     private AmbientDisplayConfiguration getConfig(Context context) {
127         if (mConfig == null) {
128             mConfig = new AmbientDisplayConfiguration(context);
129         }
130         return mConfig;
131     }
132 
133     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
134             new BaseSearchIndexProvider() {
135                 @Override
136                 public List<SearchIndexableResource> getXmlResourcesToIndex(
137                         Context context, boolean enabled) {
138                     final SearchIndexableResource sir = new SearchIndexableResource(context);
139                     sir.xmlResId = R.xml.security_lockscreen_settings;
140                     return Arrays.asList(sir);
141                 }
142 
143                 @Override
144                 public List<AbstractPreferenceController> createPreferenceControllers(
145                         Context context) {
146                     final List<AbstractPreferenceController> controllers = new ArrayList<>();
147                     controllers.add(new LockScreenNotificationPreferenceController(context));
148                     controllers.add(new OwnerInfoPreferenceController(
149                             context, null /* fragment */, null /* lifecycle */));
150                     return controllers;
151                 }
152 
153                 @Override
154                 public List<String> getNonIndexableKeys(Context context) {
155                     final List<String> niks = super.getNonIndexableKeys(context);
156                     niks.add(KEY_ADD_USER_FROM_LOCK_SCREEN);
157                     return niks;
158                 }
159 
160                 @Override
161                 protected boolean isPageSearchEnabled(Context context) {
162                     return new LockScreenPreferenceController(context, "anykey")
163                             .isAvailable();
164                 }
165             };
166 }
167