1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.systemui.statusbar.disableflags.data.model
16 
17 import android.app.StatusBarManager.DISABLE2_NONE
18 import android.app.StatusBarManager.DISABLE2_NOTIFICATION_SHADE
19 import android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS
20 import android.app.StatusBarManager.DISABLE_NONE
21 import android.app.StatusBarManager.DISABLE_NOTIFICATION_ALERTS
22 import com.android.systemui.log.LogBuffer
23 import com.android.systemui.log.core.LogLevel
24 import com.android.systemui.statusbar.disableflags.DisableFlagsLogger
25 
26 /**
27  * Model for the disable flags that come from [IStatusBar].
28  *
29  * For clients of the disable flags: do *not* refer to the disable integers directly. Instead,
30  * re-use or define a helper method that internally processes the flags. (We want to hide the
31  * bitwise logic here so no one else has to worry about it.)
32  */
33 data class DisableFlagsModel(
34     private val disable1: Int = DISABLE_NONE,
35     private val disable2: Int = DISABLE2_NONE,
36 ) {
37     /** Returns true if notification alerts are allowed based on the flags. */
areNotificationAlertsEnablednull38     fun areNotificationAlertsEnabled(): Boolean {
39         return (disable1 and DISABLE_NOTIFICATION_ALERTS) == 0
40     }
41 
42     /** Returns true if the shade is allowed based on the flags. */
isShadeEnablednull43     fun isShadeEnabled(): Boolean {
44         return (disable2 and DISABLE2_NOTIFICATION_SHADE) == 0
45     }
46 
47     /** Returns true if full quick settings are allowed based on the flags. */
isQuickSettingsEnablednull48     fun isQuickSettingsEnabled(): Boolean {
49         return (disable2 and DISABLE2_QUICK_SETTINGS) == 0
50     }
51 
52     /** Logs the change to the provided buffer. */
logChangenull53     fun logChange(buffer: LogBuffer, disableFlagsLogger: DisableFlagsLogger) {
54         buffer.log(
55             TAG,
56             LogLevel.INFO,
57             {
58                 int1 = disable1
59                 int2 = disable2
60             },
61             {
62                 disableFlagsLogger.getDisableFlagsString(
63                     new = DisableFlagsLogger.DisableState(int1, int2),
64                 )
65             }
66         )
67     }
68 
69     private companion object {
70         const val TAG = "DisableFlagsModel"
71     }
72 }
73