• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 package com.android.systemui.statusbar.notification.fsi
2 
3 import android.app.PendingIntent
4 import android.content.Context
5 import android.content.pm.PackageManager
6 import android.graphics.drawable.Drawable
7 import android.os.RemoteException
8 import android.service.dreams.IDreamManager
9 import com.android.systemui.CoreStartable
10 import com.android.systemui.dagger.SysUISingleton
11 import com.android.systemui.flags.FeatureFlags
12 import com.android.systemui.flags.Flags
13 import com.android.systemui.keyguard.data.repository.KeyguardRepository
14 import com.android.systemui.statusbar.notification.collection.NotificationEntry
15 import com.android.systemui.statusbar.notification.collection.provider.LaunchFullScreenIntentProvider
16 import com.android.systemui.statusbar.notification.fsi.FsiDebug.Companion.log
17 import com.android.systemui.statusbar.phone.CentralSurfaces
18 import java.util.concurrent.Executor
19 import javax.inject.Inject
20 import kotlinx.coroutines.flow.MutableStateFlow
21 import kotlinx.coroutines.flow.StateFlow
22 
23 /**
24  * Class that bridges the gap between clean app architecture and existing code. Provides new
25  * implementation of StatusBarNotificationActivityStarter launchFullscreenIntent that pipes
26  * one-directional data => FsiChromeViewModel => FsiChromeView.
27  */
28 @SysUISingleton
29 class FsiChromeRepo
30 @Inject
31 constructor(
32     private val context: Context,
33     private val pm: PackageManager,
34     private val keyguardRepo: KeyguardRepository,
35     private val launchFullScreenIntentProvider: LaunchFullScreenIntentProvider,
36     private val featureFlags: FeatureFlags,
37     private val uiBgExecutor: Executor,
38     private val dreamManager: IDreamManager,
39     private val centralSurfaces: CentralSurfaces
40 ) : CoreStartable {
41 
42     companion object {
43         private const val classTag = "FsiChromeRepo"
44     }
45 
46     data class FSIInfo(
47         val appName: String,
48         val appIcon: Drawable,
49         val fullscreenIntent: PendingIntent
50     )
51 
52     private val _infoFlow = MutableStateFlow<FSIInfo?>(null)
53     val infoFlow: StateFlow<FSIInfo?> = _infoFlow
54 
55     override fun start() {
56         log("$classTag start listening for FSI notifications")
57 
58         // Listen for FSI launch events for the lifetime of SystemUI.
59         launchFullScreenIntentProvider.registerListener { entry -> launchFullscreenIntent(entry) }
60     }
61 
62     fun dismiss() {
63         _infoFlow.value = null
64     }
65 
66     fun onFullscreen() {
67         // TODO(b/243421660) implement transition from container to fullscreen
68     }
69 
70     fun stopScreenSaver() {
71         uiBgExecutor.execute {
72             try {
73                 dreamManager.awaken()
74             } catch (e: RemoteException) {
75                 e.printStackTrace()
76             }
77         }
78     }
79 
80     fun launchFullscreenIntent(entry: NotificationEntry) {
81         if (!featureFlags.isEnabled(Flags.FSI_CHROME)) {
82             return
83         }
84         if (!keyguardRepo.isKeyguardShowing()) {
85             return
86         }
87         stopScreenSaver()
88 
89         var appName = pm.getApplicationLabel(context.applicationInfo) as String
90         val appIcon = pm.getApplicationIcon(context.packageName)
91         val fullscreenIntent = entry.sbn.notification.fullScreenIntent
92 
93         log("FsiChromeRepo launchFullscreenIntent appName=$appName appIcon $appIcon")
94         _infoFlow.value = FSIInfo(appName, appIcon, fullscreenIntent)
95 
96         // If screen is off or we're showing AOD, show lockscreen.
97         centralSurfaces.wakeUpForFullScreenIntent()
98 
99         // Don't show HUN since we're already showing FSI.
100         entry.notifyFullScreenIntentLaunched()
101     }
102 }
103