Merge commit 'korg/cupcake'
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index 63dfc3b..a21a7a4 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -258,13 +258,12 @@
status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType)
{
int output = getOutput(streamType);
+
+ if (output == NUM_AUDIO_OUTPUT_TYPES) return PERMISSION_DENIED;
- if (gOutSamplingRate[output] == 0) {
- const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
- if (af == 0) return PERMISSION_DENIED;
- // gOutSamplingRate is updated by get_audio_flinger()
- }
+ // gOutSamplingRate[] is updated by getOutput() which calls get_audio_flinger()
LOGV("getOutputSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output, gOutSamplingRate[output]);
+
*samplingRate = gOutSamplingRate[output];
return NO_ERROR;
@@ -274,14 +273,13 @@
{
int output = getOutput(streamType);
- if (gOutFrameCount[output] == 0) {
- const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
- if (af == 0) return PERMISSION_DENIED;
- // gOutFrameCount is updated by get_audio_flinger()
- }
+ if (output == NUM_AUDIO_OUTPUT_TYPES) return PERMISSION_DENIED;
+
+ // gOutFrameCount[] is updated by getOutput() which calls get_audio_flinger()
LOGV("getOutputFrameCount() streamType %d, output %d, frame count %d", streamType, output, gOutFrameCount[output]);
*frameCount = gOutFrameCount[output];
+
return NO_ERROR;
}
@@ -289,11 +287,9 @@
{
int output = getOutput(streamType);
- if (gOutLatency[output] == 0) {
- const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
- if (af == 0) return PERMISSION_DENIED;
- // gOutLatency is updated by get_audio_flinger()
- }
+ if (output == NUM_AUDIO_OUTPUT_TYPES) return PERMISSION_DENIED;
+
+ // gOutLatency[] is updated by getOutput() which calls get_audio_flinger()
LOGV("getOutputLatency() streamType %d, output %d, latency %d", streamType, output, gOutLatency[output]);
*latency = gOutLatency[output];
@@ -354,7 +350,12 @@
}
int AudioSystem::getOutput(int streamType)
-{
+{
+ // make sure that gA2dpEnabled is valid by calling get_audio_flinger() which in turn
+ // will call gAudioFlinger->isA2dpEnabled()
+ const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
+ if (af == 0) return NUM_AUDIO_OUTPUT_TYPES;
+
if (streamType == DEFAULT) {
streamType = MUSIC;
}
diff --git a/media/libmediaplayerservice/MediaRecorderClient.cpp b/media/libmediaplayerservice/MediaRecorderClient.cpp
index 5d1887d..e0d2947 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.cpp
+++ b/media/libmediaplayerservice/MediaRecorderClient.cpp
@@ -30,11 +30,24 @@
#include <utils/MemoryHeapBase.h>
#include <utils/MemoryBase.h>
#include <media/PVMediaRecorder.h>
+#include <utils/String16.h>
#include "MediaRecorderClient.h"
namespace android {
+const char* cameraPermission = "android.permission.CAMERA";
+
+static bool checkPermission(const char* permissionString) {
+#ifndef HAVE_ANDROID_OS
+ return true;
+#endif
+ if (getpid() == IPCThreadState::self()->getCallingPid()) return true;
+ bool ok = checkCallingPermission(String16(permissionString));
+ if (!ok) LOGE("Request requires %s", permissionString);
+ return ok;
+}
+
status_t MediaRecorderClient::setCamera(const sp<ICamera>& camera)
{
LOGV("setCamera");
@@ -60,6 +73,9 @@
status_t MediaRecorderClient::setVideoSource(int vs)
{
LOGV("setVideoSource(%d)", vs);
+ if (!checkPermission(cameraPermission)) {
+ return PERMISSION_DENIED;
+ }
Mutex::Autolock lock(mLock);
if (mRecorder == NULL) {
LOGE("recorder is not initialized");