From b779b11f9757815f97a8ff77f961ca0d3475b777 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Fri, 19 Nov 2021 15:47:16 -0500 Subject: [PATCH] Make screenshot sound respect system mute In some regions (e.g. Japan) we force the camera to make a sound regardless of the user settings. The screenshot used the same sound so inherited this behavior. This change forks the sound used for screenshots, so that it respects the system volume instead of being forced audible. Bug: 200767953 Fix: 200767953 Test: manual (made AudioService.readCameraSoundForced return true, then test before and after change to verify behavior fixed) Change-Id: I3c9cf2826b5c3f86e47b570f75189405845a7186 --- core/res/res/values/config.xml | 3 ++ core/res/res/values/symbols.xml | 1 + .../screenshot/ScreenshotController.java | 28 ++++++++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 842065a7d987c..7e3ae3d592ee3 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -4238,6 +4238,9 @@ /product/media/audio/ui/InCallNotification.ogg + + /product/media/audio/ui/camera_click.ogg + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 85eed85a9e70f..a7d898997ee93 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3727,6 +3727,7 @@ + diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index 83d8d19a6d4dd..849c4807c11d4 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -51,7 +51,9 @@ import android.graphics.Bitmap; import android.graphics.Insets; import android.graphics.Rect; import android.hardware.display.DisplayManager; -import android.media.MediaActionSound; +import android.media.AudioAttributes; +import android.media.AudioSystem; +import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; @@ -93,6 +95,7 @@ import com.android.systemui.screenshot.TakeScreenshotService.RequestCallback; import com.google.common.util.concurrent.ListenableFuture; +import java.io.File; import java.util.List; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -248,7 +251,7 @@ public class ScreenshotController { private final WindowManager mWindowManager; private final WindowManager.LayoutParams mWindowLayoutParams; private final AccessibilityManager mAccessibilityManager; - private final MediaActionSound mCameraSound; + private final MediaPlayer mCameraSound; private final ScrollCaptureClient mScrollCaptureClient; private final PhoneWindow mWindow; private final DisplayManager mDisplayManager; @@ -331,8 +334,13 @@ public class ScreenshotController { reloadAssets(); // Setup the Camera shutter sound - mCameraSound = new MediaActionSound(); - mCameraSound.load(MediaActionSound.SHUTTER_CLICK); + mCameraSound = MediaPlayer.create(mContext, + Uri.fromFile(new File(mContext.getResources().getString( + com.android.internal.R.string.config_cameraShutterSound))), null, + new AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .build(), AudioSystem.newAudioSessionId()); mCopyBroadcastReceiver = new BroadcastReceiver() { @Override @@ -430,7 +438,9 @@ public class ScreenshotController { void releaseContext() { mContext.unregisterReceiver(mCopyBroadcastReceiver); mContext.release(); - mCameraSound.release(); + if (mCameraSound != null) { + mCameraSound.release(); + } mBgExecutor.shutdownNow(); } @@ -806,7 +816,9 @@ public class ScreenshotController { */ private void saveScreenshotAndToast(Consumer finisher) { // Play the shutter sound to notify that we've taken a screenshot - mCameraSound.play(MediaActionSound.SHUTTER_CLICK); + if (mCameraSound != null) { + mCameraSound.start(); + } saveScreenshotInWorkerThread( /* onComplete */ finisher, @@ -840,7 +852,9 @@ public class ScreenshotController { mScreenshotView.createScreenshotDropInAnimation(screenRect, showFlash); // Play the shutter sound to notify that we've taken a screenshot - mCameraSound.play(MediaActionSound.SHUTTER_CLICK); + if (mCameraSound != null) { + mCameraSound.start(); + } if (DEBUG_ANIM) { Log.d(TAG, "starting post-screenshot animation");