• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.display;
18 
19 import android.content.Context;
20 import android.os.UserHandle;
21 import android.os.UserManager;
22 
23 import com.android.settings.R;
24 import com.android.settings.core.BasePreferenceController;
25 
26 /** Controls the "widgets on lock screen" preferences (under "Display & touch"). */
27 public class WidgetsOnLockscreenPreferenceController extends BasePreferenceController {
WidgetsOnLockscreenPreferenceController(Context context, String preferenceKey)28     public WidgetsOnLockscreenPreferenceController(Context context, String preferenceKey) {
29         super(context, preferenceKey);
30     }
31 
32     @Override
getAvailabilityStatus()33     public int getAvailabilityStatus() {
34         return isAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
35     }
36 
37     /**
38      * Returns whether "widgets on lock screen" preferences are available.
39      */
isAvailable(Context context)40     public static boolean isAvailable(Context context) {
41         if (!isMainUser(context)) {
42             return false;
43         }
44 
45         return com.android.systemui.Flags.glanceableHubV2()
46                 && (context.getResources().getBoolean(R.bool.config_show_communal_settings)
47                     || context.getResources().getBoolean(
48                             R.bool.config_show_communal_settings_mobile));
49     }
50 
isMainUser(Context context)51     private static boolean isMainUser(Context context) {
52         final UserManager userManager = context.getSystemService(UserManager.class);
53         return userManager.getUserInfo(UserHandle.myUserId()).isMain();
54     }
55 }
56