From a7f1e5c540ff7b94c212facdcd89459cba3e4edc Mon Sep 17 00:00:00 2001 From: Eric Laurent <> Date: Fri, 27 Mar 2009 16:27:16 -0700 Subject: AI 143177: am: CL 142889 Fix issue #1736153 Camera shutter sound can be muted by new AlarmClock setting. Current implementation of Camera service plays the camera shutter sound over the ALARM stream so that it cannot be muted by silent mode in order to comply to some country specific requirement. A recent change made it possible for the user to mute the ALARM stream thus making this stream not suitable any more for the camera shutter sound. The fix consists in creating a new stream type only accessible by native code and that cannot be muted and use it to play camera sounds. Original author: elaurent Merged from: //branches/cupcake/... Automated import of CL 143177 --- camera/libcameraservice/CameraService.cpp | 10 +++++++++- include/media/AudioSystem.h | 1 + libs/audioflinger/AudioFlinger.cpp | 9 ++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index 7e5fdbe..cb8ab58 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -32,6 +32,8 @@ #include #include "CameraService.h" +#include + namespace android { extern "C" { @@ -157,7 +159,13 @@ static sp newMediaPlayer(const char *file) { sp mp = new MediaPlayer(); if (mp->setDataSource(file) == NO_ERROR) { - mp->setAudioStreamType(AudioSystem::ALARM); + char value[PROPERTY_VALUE_MAX]; + property_get("ro.camera.sound.forced", value, "0"); + if (atoi(value)) { + mp->setAudioStreamType(AudioSystem::ENFORCED_AUDIBLE); + } else { + mp->setAudioStreamType(AudioSystem::SYSTEM); + } mp->prepare(); } else { mp.clear(); diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h index 77c90ba..3a3a714 100644 --- a/include/media/AudioSystem.h +++ b/include/media/AudioSystem.h @@ -38,6 +38,7 @@ public: ALARM = 4, NOTIFICATION = 5, BLUETOOTH_SCO = 6, + ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker NUM_STREAM_TYPES }; diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp index 9ba7f90..b9ecdd8 100644 --- a/libs/audioflinger/AudioFlinger.cpp +++ b/libs/audioflinger/AudioFlinger.cpp @@ -243,7 +243,8 @@ bool AudioFlinger::streamForcedToSpeaker(int streamType) // AudioSystem::routedToA2dpOutput(streamType) == false return (streamType == AudioSystem::RING || streamType == AudioSystem::ALARM || - streamType == AudioSystem::NOTIFICATION); + streamType == AudioSystem::NOTIFICATION || + streamType == AudioSystem::ENFORCED_AUDIBLE); } status_t AudioFlinger::dumpClients(int fd, const Vector& args) @@ -645,7 +646,8 @@ status_t AudioFlinger::setStreamVolume(int stream, float value) return PERMISSION_DENIED; } - if (uint32_t(stream) >= AudioSystem::NUM_STREAM_TYPES) { + if (uint32_t(stream) >= AudioSystem::NUM_STREAM_TYPES || + uint32_t(stream) == AudioSystem::ENFORCED_AUDIBLE) { return BAD_VALUE; } @@ -680,7 +682,8 @@ status_t AudioFlinger::setStreamMute(int stream, bool muted) return PERMISSION_DENIED; } - if (uint32_t(stream) >= AudioSystem::NUM_STREAM_TYPES) { + if (uint32_t(stream) >= AudioSystem::NUM_STREAM_TYPES || + uint32_t(stream) == AudioSystem::ENFORCED_AUDIBLE) { return BAD_VALUE; } -- cgit v1.1