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