1 /*
2  * Copyright (C) 2022 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.notification.collection.provider
18 
19 import android.util.Log
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.statusbar.notification.collection.NotificationEntry
22 import com.android.systemui.util.ListenerSet
23 import javax.inject.Inject
24 
25 /**
26  * A class that enables communication of decisions to launch a notification's full screen intent.
27  */
28 @SysUISingleton
29 class LaunchFullScreenIntentProvider @Inject constructor() {
30     companion object {
31         private const val TAG = "LaunchFullScreenIntentProvider"
32     }
33     private val listeners = ListenerSet<Listener>()
34 
35     /**
36      * Registers a listener with this provider. These listeners will be updated whenever a full
37      * screen intent should be launched for a notification entry.
38      */
registerListenernull39     fun registerListener(listener: Listener) {
40         listeners.addIfAbsent(listener)
41     }
42 
43     /** Removes the specified listener. */
removeListenernull44     fun removeListener(listener: Listener) {
45         listeners.remove(listener)
46     }
47 
48     /**
49      * Sends a request to launch full screen intent for the given notification entry to all
50      * registered listeners.
51      */
launchFullScreenIntentnull52     fun launchFullScreenIntent(entry: NotificationEntry) {
53         if (listeners.isEmpty()) {
54             // This should never happen, but we should definitely know if it does because having
55             // no listeners would indicate that FSIs are getting entirely dropped on the floor.
56             Log.wtf(TAG, "no listeners found when launchFullScreenIntent requested")
57         }
58         for (listener in listeners) {
59             listener.onFullScreenIntentRequested(entry)
60         }
61     }
62 
63     /** Listener interface for passing full screen intent launch decisions. */
interfacenull64     fun interface Listener {
65         /**
66          * Invoked whenever a full screen intent launch is requested for the given notification
67          * entry.
68          */
69         fun onFullScreenIntentRequested(entry: NotificationEntry)
70     }
71 }
72