1 /*
2  * Copyright (C) 2024 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.systemui.statusbar.disableflags.shared.model
18 
19 import android.app.StatusBarManager.DISABLE2_NONE
20 import android.app.StatusBarManager.DISABLE2_NOTIFICATION_SHADE
21 import android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS
22 import android.app.StatusBarManager.DISABLE2_SYSTEM_ICONS
23 import android.app.StatusBarManager.DISABLE_CLOCK
24 import android.app.StatusBarManager.DISABLE_NONE
25 import android.app.StatusBarManager.DISABLE_NOTIFICATION_ALERTS
26 import android.app.StatusBarManager.DISABLE_NOTIFICATION_ICONS
27 import android.app.StatusBarManager.DISABLE_SYSTEM_INFO
28 import com.android.systemui.log.LogBuffer
29 import com.android.systemui.log.core.LogLevel
30 import com.android.systemui.statusbar.disableflags.DisableFlagsLogger
31 
32 /**
33  * Model for the disable flags that come from [IStatusBar].
34  *
35  * For clients of the disable flags: do *not* refer to the disable integers directly. Instead,
36  * re-use or define a helper method or property that internally processes the flags. (We want to
37  * hide the bitwise logic here so no one else has to worry about it.)
38  */
39 data class DisableFlagsModel(
40     private val disable1: Int = DISABLE_NONE,
41     private val disable2: Int = DISABLE2_NONE,
42     /** True if we should animate any view visibility changes and false otherwise. */
43     val animate: Boolean = false,
44 ) {
45     /** Returns true if notification alerts are allowed based on the flags. */
areNotificationAlertsEnablednull46     fun areNotificationAlertsEnabled(): Boolean {
47         return (disable1 and DISABLE_NOTIFICATION_ALERTS) == 0
48     }
49 
50     /** Returns true if the shade is allowed based on the flags. */
isShadeEnablednull51     fun isShadeEnabled(): Boolean {
52         return (disable2 and DISABLE2_NOTIFICATION_SHADE) == 0
53     }
54 
55     /** Returns true if full quick settings are allowed based on the flags. */
isQuickSettingsEnablednull56     fun isQuickSettingsEnabled(): Boolean {
57         return (disable2 and DISABLE2_QUICK_SETTINGS) == 0
58     }
59 
60     val isClockEnabled = (disable1 and DISABLE_CLOCK) == 0
61 
62     val areNotificationIconsEnabled = (disable1 and DISABLE_NOTIFICATION_ICONS) == 0
63 
64     val isSystemInfoEnabled =
65         (disable1 and DISABLE_SYSTEM_INFO) == 0 && (disable2 and DISABLE2_SYSTEM_ICONS) == 0
66 
67     /** Logs the change to the provided buffer. */
logChangenull68     fun logChange(buffer: LogBuffer, disableFlagsLogger: DisableFlagsLogger) {
69         buffer.log(
70             TAG,
71             LogLevel.INFO,
72             {
73                 int1 = disable1
74                 int2 = disable2
75             },
76             {
77                 disableFlagsLogger.getDisableFlagsString(
78                     new = DisableFlagsLogger.DisableState(int1, int2)
79                 )
80             },
81         )
82     }
83 
84     private companion object {
85         const val TAG = "DisableFlagsModel"
86     }
87 }
88