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
17package com.android.settings.security;
18
19import android.content.Context;
20import android.provider.SearchIndexableResource;
21import android.support.annotation.VisibleForTesting;
22
23import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
24import com.android.settings.R;
25import com.android.settings.dashboard.DashboardFragment;
26import com.android.settings.notification.LockScreenNotificationPreferenceController;
27import com.android.settings.search.BaseSearchIndexProvider;
28import com.android.settings.users.AddUserWhenLockedPreferenceController;
29import com.android.settingslib.core.AbstractPreferenceController;
30import com.android.settingslib.core.lifecycle.Lifecycle;
31
32import java.util.ArrayList;
33import java.util.Arrays;
34import java.util.List;
35
36/**
37 * Settings screen for lock screen preference
38 */
39public 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    @VisibleForTesting
53    static final String KEY_ADD_USER_FROM_LOCK_SCREEN =
54            "security_lockscreen_add_users_when_locked";
55
56    private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
57
58    @Override
59    public int getMetricsCategory() {
60        return MetricsEvent.SETTINGS_LOCK_SCREEN_PREFERENCES;
61    }
62
63    @Override
64    protected String getLogTag() {
65        return TAG;
66    }
67
68    @Override
69    protected int getPreferenceScreenResId() {
70        return R.xml.security_lockscreen_settings;
71    }
72
73    @Override
74    public int getHelpResource() {
75        return R.string.help_url_lockscreen;
76    }
77
78    @Override
79    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
80        final List<AbstractPreferenceController> controllers = new ArrayList<>();
81        final Lifecycle lifecycle = getLifecycle();
82        final LockScreenNotificationPreferenceController notificationController =
83                new LockScreenNotificationPreferenceController(context,
84                        KEY_LOCK_SCREEN_NOTIFICATON,
85                        KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER,
86                        KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE);
87        lifecycle.addObserver(notificationController);
88        controllers.add(notificationController);
89        controllers.add(new AddUserWhenLockedPreferenceController(
90                context, KEY_ADD_USER_FROM_LOCK_SCREEN, lifecycle));
91        mOwnerInfoPreferenceController =
92                new OwnerInfoPreferenceController(context, this, lifecycle);
93        controllers.add(mOwnerInfoPreferenceController);
94        controllers.add(new LockdownButtonPreferenceController(context));
95
96        return controllers;
97    }
98
99    @Override
100    public void onOwnerInfoUpdated() {
101        if (mOwnerInfoPreferenceController != null) {
102            mOwnerInfoPreferenceController.updateSummary();
103        }
104    }
105
106    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
107            new BaseSearchIndexProvider() {
108                @Override
109                public List<SearchIndexableResource> getXmlResourcesToIndex(
110                        Context context, boolean enabled) {
111                    final SearchIndexableResource sir = new SearchIndexableResource(context);
112                    sir.xmlResId = R.xml.security_lockscreen_settings;
113                    return Arrays.asList(sir);
114                }
115
116                @Override
117                public List<AbstractPreferenceController> createPreferenceControllers(
118                        Context context) {
119                    final List<AbstractPreferenceController> controllers = new ArrayList<>();
120                    controllers.add(new LockScreenNotificationPreferenceController(context));
121                    controllers.add(new AddUserWhenLockedPreferenceController(context,
122                            KEY_ADD_USER_FROM_LOCK_SCREEN, null /* lifecycle */));
123                    controllers.add(new OwnerInfoPreferenceController(
124                            context, null /* fragment */, null /* lifecycle */));
125                    controllers.add(new LockdownButtonPreferenceController(context));
126                    return controllers;
127                }
128
129                @Override
130                public List<String> getNonIndexableKeys(Context context) {
131                    final List<String> niks = super.getNonIndexableKeys(context);
132                    niks.add(KEY_ADD_USER_FROM_LOCK_SCREEN);
133                    niks.add(KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE);
134                    return niks;
135                }
136            };
137}
138