1 /*
2  * Copyright (C) 2021 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.media.controls.util
18 
19 import android.app.StatusBarManager
20 import android.os.UserHandle
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.flags.FeatureFlags
23 import com.android.systemui.flags.Flags
24 import javax.inject.Inject
25 
26 @SysUISingleton
27 class MediaFlags @Inject constructor(private val featureFlags: FeatureFlags) {
28     /**
29      * Check whether media control actions should be based on PlaybackState instead of notification
30      */
31     fun areMediaSessionActionsEnabled(packageName: String, user: UserHandle): Boolean {
32         val enabled = StatusBarManager.useMediaSessionActionsForApp(packageName, user)
33         // Allow global override with flag
34         return enabled || featureFlags.isEnabled(Flags.MEDIA_SESSION_ACTIONS)
35     }
36 
37     /**
38      * If true, keep active media controls for the lifetime of the MediaSession, regardless of
39      * whether the underlying notification was dismissed
40      */
41     fun isRetainingPlayersEnabled() = featureFlags.isEnabled(Flags.MEDIA_RETAIN_SESSIONS)
42 
43     /** Check whether to get progress information for resume players */
44     fun isResumeProgressEnabled() = featureFlags.isEnabled(Flags.MEDIA_RESUME_PROGRESS)
45 
46     /** If true, do not automatically dismiss the recommendation card */
47     fun isPersistentSsCardEnabled() = featureFlags.isEnabled(Flags.MEDIA_RETAIN_RECOMMENDATIONS)
48 
49     /** Check whether we allow remote media to generate resume controls */
50     fun isRemoteResumeAllowed() = featureFlags.isEnabled(Flags.MEDIA_REMOTE_RESUME)
51 }
52