• 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.content.Context;
20 import android.provider.SearchIndexableResource;
21 import android.support.annotation.VisibleForTesting;
22 
23 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
24 import com.android.settings.R;
25 import com.android.settings.accounts.AddUserWhenLockedPreferenceController;
26 import com.android.settings.core.PreferenceController;
27 import com.android.settings.core.lifecycle.Lifecycle;
28 import com.android.settings.dashboard.DashboardFragment;
29 import com.android.settings.notification.LockScreenNotificationPreferenceController;
30 import com.android.settings.search.BaseSearchIndexProvider;
31 
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.List;
35 
36 /**
37  * Settings screen for lock screen preference
38  */
39 public class LockscreenDashboardFragment extends DashboardFragment
40         implements OwnerInfoPreferenceController.OwnerInfoCallback {
41 
42     private static final String TAG = "LockscreenDashboardFragment";
43 
44     @VisibleForTesting
45     static final String KEY_LOCK_SCREEN_NOTIFICATON = "security_setting_lock_screen_notif";
46     @VisibleForTesting
47     static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER =
48             "security_setting_lock_screen_notif_work_header";
49     @VisibleForTesting
50     static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE =
51             "security_setting_lock_screen_notif_work";
52 
53     private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
54 
55     @Override
getMetricsCategory()56     public int getMetricsCategory() {
57         return MetricsEvent.SETTINGS_LOCK_SCREEN_PREFERENCES;
58     }
59 
60     @Override
getLogTag()61     protected String getLogTag() {
62         return TAG;
63     }
64 
65     @Override
getPreferenceScreenResId()66     protected int getPreferenceScreenResId() {
67         return R.xml.security_lockscreen_settings;
68     }
69 
70     @Override
getPreferenceControllers(Context context)71     protected List<PreferenceController> getPreferenceControllers(Context context) {
72         final List<PreferenceController> controllers = new ArrayList<>();
73         final Lifecycle lifecycle = getLifecycle();
74         final LockScreenNotificationPreferenceController notificationController =
75             new LockScreenNotificationPreferenceController(context,
76                     KEY_LOCK_SCREEN_NOTIFICATON,
77                     KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER,
78                     KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE);
79         lifecycle.addObserver(notificationController);
80         controllers.add(notificationController);
81         final AddUserWhenLockedPreferenceController addUserWhenLockedController =
82             new AddUserWhenLockedPreferenceController(context);
83         lifecycle.addObserver(addUserWhenLockedController);
84         controllers.add(addUserWhenLockedController);
85         mOwnerInfoPreferenceController =
86             new OwnerInfoPreferenceController(context, this, lifecycle);
87         controllers.add(mOwnerInfoPreferenceController);
88         return controllers;
89     }
90 
91     @Override
onOwnerInfoUpdated()92     public void onOwnerInfoUpdated() {
93         if (mOwnerInfoPreferenceController != null) {
94             mOwnerInfoPreferenceController.updateSummary();
95         }
96     }
97 
98     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
99         new BaseSearchIndexProvider() {
100             @Override
101             public List<SearchIndexableResource> getXmlResourcesToIndex(
102                 Context context, boolean enabled) {
103                 final SearchIndexableResource sir = new SearchIndexableResource(context);
104                 sir.xmlResId = R.xml.security_lockscreen_settings;
105                 return Arrays.asList(sir);
106             }
107 
108             @Override
109             public List<PreferenceController> getPreferenceControllers(Context context) {
110                 final List<PreferenceController> controllers = new ArrayList<>();
111                 controllers.add(new LockScreenNotificationPreferenceController(context));
112                 controllers.add(new AddUserWhenLockedPreferenceController(context));
113                 controllers.add(new OwnerInfoPreferenceController(
114                     context, null /* fragment */, null /* lifecycle */));
115                 return controllers;
116             }
117         };
118 }
119