summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Matt Casey <mrcasey@google.com> 2024-10-04 15:56:18 +0000
committer Matt Casey <mrcasey@google.com> 2024-10-04 16:03:59 +0000
commit85b26324b3a6d35a7ef1c61257879004ffed9bc6 (patch)
tree2c94bd8fb64891d6a58c25d58ca401b0431ba72d
parent08d360374849f3ff6229f69e25cae210a0e321c7 (diff)
Always instantiate sound controller
There is only ever one screenshotcontroller (regardless of flags), so we should always instantiate the sound controller. Bug: 371564464 Flag: EXEMPT minor bugfix Test: Manual build/test Change-Id: Ibca0c83504d24b7e1cd84e7e9db6e3822b478b71
-rw-r--r--packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.kt27
1 files changed, 4 insertions, 23 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.kt
index 0806be8d6bb2..fca29e1122d0 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.kt
@@ -60,7 +60,6 @@ import java.util.concurrent.Executor
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.function.Consumer
-import javax.inject.Provider
import kotlin.math.abs
/** Controls the state and flow for screenshots. */
@@ -73,7 +72,7 @@ internal constructor(
screenshotNotificationsControllerFactory: ScreenshotNotificationsController.Factory,
screenshotActionsControllerFactory: ScreenshotActionsController.Factory,
actionExecutorFactory: ActionExecutor.Factory,
- screenshotSoundControllerProvider: Provider<ScreenshotSoundController?>,
+ private val screenshotSoundController: ScreenshotSoundController,
private val uiEventLogger: UiEventLogger,
private val imageExporter: ImageExporter,
private val imageCapture: ImageCapture,
@@ -98,7 +97,6 @@ internal constructor(
private val actionExecutor: ActionExecutor
private val copyBroadcastReceiver: BroadcastReceiver
- private var screenshotSoundController: ScreenshotSoundController? = null
private var screenBitmap: Bitmap? = null
private var screenshotTakenInPortrait = false
private var screenshotAnimation: Animator? = null
@@ -137,14 +135,6 @@ internal constructor(
actionExecutor = actionExecutorFactory.create(window.window, viewProxy) { finishDismiss() }
actionsController = screenshotActionsControllerFactory.getController(actionExecutor)
- // Sound is only reproduced from the controller of the default display.
- screenshotSoundController =
- if (display.displayId == Display.DEFAULT_DISPLAY) {
- screenshotSoundControllerProvider.get()
- } else {
- null
- }
-
copyBroadcastReceiver =
object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
@@ -302,7 +292,7 @@ internal constructor(
// Any cleanup needed when the service is being destroyed.
override fun onDestroy() {
removeWindow()
- releaseMediaPlayer()
+ screenshotSoundController.releaseScreenshotSoundAsync()
releaseContext()
bgExecutor.shutdown()
}
@@ -313,10 +303,6 @@ internal constructor(
context.release()
}
- private fun releaseMediaPlayer() {
- screenshotSoundController?.releaseScreenshotSoundAsync()
- }
-
/** Update resources on configuration change. Reinflate for theme/color changes. */
private fun reloadAssets() {
if (LogConfig.DEBUG_UI) {
@@ -442,18 +428,13 @@ internal constructor(
viewProxy.stopInputListening()
}
- private fun playCameraSoundIfNeeded() {
- // the controller is not-null only on the default display controller
- screenshotSoundController?.playScreenshotSoundAsync()
- }
-
/**
* Save the bitmap but don't show the normal screenshot UI.. just a toast (or notification on
* failure).
*/
private fun saveScreenshotAndToast(screenshot: ScreenshotData, finisher: Consumer<Uri?>) {
// Play the shutter sound to notify that we've taken a screenshot
- playCameraSoundIfNeeded()
+ screenshotSoundController.playScreenshotSoundAsync()
saveScreenshotInBackground(screenshot, UUID.randomUUID(), finisher) {
result: ImageExporter.Result ->
@@ -482,7 +463,7 @@ internal constructor(
viewProxy.createScreenshotDropInAnimation(screenRect, showFlash).apply {
doOnEnd { onAnimationComplete?.run() }
// Play the shutter sound to notify that we've taken a screenshot
- playCameraSoundIfNeeded()
+ screenshotSoundController.playScreenshotSoundAsync()
if (LogConfig.DEBUG_ANIM) {
Log.d(TAG, "starting post-screenshot animation")
}