• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.systemui.statusbar
2 
3 import android.app.Notification
4 import android.os.RemoteException
5 import com.android.internal.statusbar.IStatusBarService
6 import com.android.internal.statusbar.NotificationVisibility
7 import com.android.systemui.dagger.SysUISingleton
8 import com.android.systemui.dagger.qualifiers.Main
9 import com.android.systemui.util.Assert
10 import java.util.concurrent.Executor
11 import javax.inject.Inject
12 
13 /**
14  * Class to shim calls to IStatusBarManager#onNotificationClick/#onNotificationActionClick that
15  * allow an in-process notification to go out (e.g., for tracking interactions) as well as
16  * sending the messages along to system server.
17  *
18  * NOTE: this class eats exceptions from system server, as no current client of these APIs cares
19  * about errors
20  */
21 @SysUISingleton
22 public class NotificationClickNotifier @Inject constructor(
23     val barService: IStatusBarService,
24     @Main val mainExecutor: Executor
25 ) {
26     val listeners = mutableListOf<NotificationInteractionListener>()
27 
addNotificationInteractionListenernull28     fun addNotificationInteractionListener(listener: NotificationInteractionListener) {
29         Assert.isMainThread()
30         listeners.add(listener)
31     }
32 
removeNotificationInteractionListenernull33     fun removeNotificationInteractionListener(listener: NotificationInteractionListener) {
34         Assert.isMainThread()
35         listeners.remove(listener)
36     }
37 
notifyListenersAboutInteractionnull38     private fun notifyListenersAboutInteraction(key: String) {
39         for (l in listeners) {
40             l.onNotificationInteraction(key)
41         }
42     }
43 
onNotificationActionClicknull44     fun onNotificationActionClick(
45         key: String,
46         actionIndex: Int,
47         action: Notification.Action,
48         visibility: NotificationVisibility,
49         generatedByAssistant: Boolean
50     ) {
51         try {
52             barService.onNotificationActionClick(
53                     key, actionIndex, action, visibility, generatedByAssistant)
54         } catch (e: RemoteException) {
55             // nothing
56         }
57 
58         mainExecutor.execute {
59             notifyListenersAboutInteraction(key)
60         }
61     }
62 
onNotificationClicknull63     fun onNotificationClick(
64         key: String,
65         visibility: NotificationVisibility
66     ) {
67         try {
68             barService.onNotificationClick(key, visibility)
69         } catch (e: RemoteException) {
70             // nothing
71         }
72 
73         mainExecutor.execute {
74             notifyListenersAboutInteraction(key)
75         }
76     }
77 }
78 
79 /**
80  * Interface for listeners to get notified when a notification is interacted with via a click or
81  * interaction with remote input or actions
82  */
83 interface NotificationInteractionListener {
onNotificationInteractionnull84     fun onNotificationInteraction(key: String)
85 }
86 
87 private const val TAG = "NotificationClickNotifier"
88