Camera: Play shutter sound in absence of CAMERA_MSG_SHUTTER

When shutter sound is ON, even if application calls takePicture
without CAMERA_MSG_SHUTTER, the camera service should still play
shutter sound.

Also remove the code using ro.camera.sound.forced since it's
not used any more.

Test: 3rd party app on device with enforced shutter sound
Bug: 111995040
Change-Id: I0d2e888b7f17eff5e5bff8d0f3ec3da7f7ad97b7
gugelfrei
Shuzhen Wang 6 years ago
parent a0e772b26e
commit 06fcfb071c

@ -582,7 +582,7 @@ Status CameraService::filterGetInfoErrorCode(status_t err) {
Status CameraService::makeClient(const sp<CameraService>& cameraService,
const sp<IInterface>& cameraCb, const String16& packageName, const String8& cameraId,
int api1CameraId, int facing, int clientPid, uid_t clientUid, int servicePid,
bool legacyMode, int halVersion, int deviceVersion, apiLevel effectiveApiLevel,
int halVersion, int deviceVersion, apiLevel effectiveApiLevel,
/*out*/sp<BasicClient>* client) {
if (halVersion < 0 || halVersion == deviceVersion) {
@ -594,7 +594,7 @@ Status CameraService::makeClient(const sp<CameraService>& cameraService,
sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
*client = new CameraClient(cameraService, tmp, packageName,
api1CameraId, facing, clientPid, clientUid,
getpid(), legacyMode);
getpid());
} else { // Camera2 API route
ALOGW("Camera using old HAL version: %d", deviceVersion);
return STATUS_ERROR_FMT(ERROR_DEPRECATED_HAL,
@ -612,7 +612,7 @@ Status CameraService::makeClient(const sp<CameraService>& cameraService,
*client = new Camera2Client(cameraService, tmp, packageName,
cameraId, api1CameraId,
facing, clientPid, clientUid,
servicePid, legacyMode);
servicePid);
} else { // Camera2 API route
sp<hardware::camera2::ICameraDeviceCallbacks> tmp =
static_cast<hardware::camera2::ICameraDeviceCallbacks*>(cameraCb.get());
@ -636,7 +636,7 @@ Status CameraService::makeClient(const sp<CameraService>& cameraService,
sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
*client = new CameraClient(cameraService, tmp, packageName,
api1CameraId, facing, clientPid, clientUid,
servicePid, legacyMode);
servicePid);
} else {
// Other combinations (e.g. HAL3.x open as HAL2.x) are not supported yet.
ALOGE("Invalid camera HAL version %x: HAL %x device can only be"
@ -735,8 +735,7 @@ Status CameraService::initializeShimMetadata(int cameraId) {
sp<ICameraClient>{nullptr}, id, cameraId,
static_cast<int>(CAMERA_HAL_API_VERSION_UNSPECIFIED),
internalPackageName, uid, USE_CALLING_PID,
API_1, /*legacyMode*/ false, /*shimUpdateOnly*/ true,
/*out*/ tmp)
API_1, /*shimUpdateOnly*/ true, /*out*/ tmp)
).isOk()) {
ALOGE("%s: Error initializing shim metadata: %s", __FUNCTION__, ret.toString8().string());
}
@ -1200,8 +1199,7 @@ Status CameraService::connect(
sp<Client> client = nullptr;
ret = connectHelper<ICameraClient,Client>(cameraClient, id, api1CameraId,
CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageName, clientUid, clientPid, API_1,
/*legacyMode*/ false, /*shimUpdateOnly*/ false,
/*out*/client);
/*shimUpdateOnly*/ false, /*out*/client);
if(!ret.isOk()) {
logRejected(id, getCallingPid(), String8(clientPackageName),
@ -1227,8 +1225,7 @@ Status CameraService::connectLegacy(
Status ret = Status::ok();
sp<Client> client = nullptr;
ret = connectHelper<ICameraClient,Client>(cameraClient, id, api1CameraId, halVersion,
clientPackageName, clientUid, USE_CALLING_PID, API_1,
/*legacyMode*/ true, /*shimUpdateOnly*/ false,
clientPackageName, clientUid, USE_CALLING_PID, API_1, /*shimUpdateOnly*/ false,
/*out*/client);
if(!ret.isOk()) {
@ -1256,9 +1253,7 @@ Status CameraService::connectDevice(
ret = connectHelper<hardware::camera2::ICameraDeviceCallbacks,CameraDeviceClient>(cameraCb, id,
/*api1CameraId*/-1,
CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageName,
clientUid, USE_CALLING_PID, API_2,
/*legacyMode*/ false, /*shimUpdateOnly*/ false,
/*out*/client);
clientUid, USE_CALLING_PID, API_2, /*shimUpdateOnly*/ false, /*out*/client);
if(!ret.isOk()) {
logRejected(id, getCallingPid(), String8(clientPackageName),
@ -1273,7 +1268,7 @@ Status CameraService::connectDevice(
template<class CALLBACK, class CLIENT>
Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
int api1CameraId, int halVersion, const String16& clientPackageName, int clientUid,
int clientPid, apiLevel effectiveApiLevel, bool legacyMode, bool shimUpdateOnly,
int clientPid, apiLevel effectiveApiLevel, bool shimUpdateOnly,
/*out*/sp<CLIENT>& device) {
binder::Status ret = binder::Status::ok();
@ -1358,7 +1353,7 @@ Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8&
sp<BasicClient> tmp = nullptr;
if(!(ret = makeClient(this, cameraCb, clientPackageName,
cameraId, api1CameraId, facing,
clientPid, clientUid, getpid(), legacyMode,
clientPid, clientUid, getpid(),
halVersion, deviceVersion, effectiveApiLevel,
/*out*/&tmp)).isOk()) {
return ret;

@ -585,8 +585,7 @@ private:
template<class CALLBACK, class CLIENT>
binder::Status connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
int api1CameraId, int halVersion, const String16& clientPackageName,
int clientUid, int clientPid,
apiLevel effectiveApiLevel, bool legacyMode, bool shimUpdateOnly,
int clientUid, int clientPid, apiLevel effectiveApiLevel, bool shimUpdateOnly,
/*out*/sp<CLIENT>& device);
// Lock guarding camera service state
@ -844,7 +843,7 @@ private:
static binder::Status makeClient(const sp<CameraService>& cameraService,
const sp<IInterface>& cameraCb, const String16& packageName, const String8& cameraId,
int api1CameraId, int facing, int clientPid, uid_t clientUid, int servicePid,
bool legacyMode, int halVersion, int deviceVersion, apiLevel effectiveApiLevel,
int halVersion, int deviceVersion, apiLevel effectiveApiLevel,
/*out*/sp<BasicClient>* client);
status_t checkCameraAccess(const String16& opPackageName);

@ -54,8 +54,7 @@ Camera2Client::Camera2Client(const sp<CameraService>& cameraService,
int cameraFacing,
int clientPid,
uid_t clientUid,
int servicePid,
bool legacyMode):
int servicePid):
Camera2ClientBase(cameraService, cameraClient, clientPackageName,
cameraDeviceId, api1CameraId, cameraFacing,
clientPid, clientUid, servicePid),
@ -65,8 +64,6 @@ Camera2Client::Camera2Client(const sp<CameraService>& cameraService,
SharedParameters::Lock l(mParameters);
l.mParameters.state = Parameters::DISCONNECTED;
mLegacyMode = legacyMode;
}
status_t Camera2Client::initialize(sp<CameraProviderManager> manager, const String8& monitorTags) {
@ -1443,7 +1440,7 @@ status_t Camera2Client::cancelAutoFocus() {
return OK;
}
status_t Camera2Client::takePicture(int msgType) {
status_t Camera2Client::takePicture(int /*msgType*/) {
ATRACE_CALL();
Mutex::Autolock icl(mBinderSerializationLock);
status_t res;
@ -1542,7 +1539,7 @@ status_t Camera2Client::takePicture(int msgType) {
// Need HAL to have correct settings before (possibly) triggering precapture
syncWithDevice();
res = mCaptureSequencer->startCapture(msgType);
res = mCaptureSequencer->startCapture();
if (res != OK) {
ALOGE("%s: Camera %d: Unable to start capture: %s (%d)",
__FUNCTION__, mCameraId, strerror(-res), res);
@ -1662,27 +1659,6 @@ status_t Camera2Client::commandEnableShutterSoundL(bool enable) {
return OK;
}
// the camera2 api legacy mode can unconditionally disable the shutter sound
if (mLegacyMode) {
ALOGV("%s: Disable shutter sound in legacy mode", __FUNCTION__);
l.mParameters.playShutterSound = false;
return OK;
}
// Disabling shutter sound may not be allowed. In that case only
// allow the mediaserver process to disable the sound.
char value[PROPERTY_VALUE_MAX];
property_get("ro.camera.sound.forced", value, "0");
if (strncmp(value, "0", 2) != 0) {
// Disabling shutter sound is not allowed. Deny if the current
// process is not mediaserver.
if (getCallingPid() != getpid()) {
ALOGE("Failed to disable shutter sound. Permission denied (pid %d)",
getCallingPid());
return PERMISSION_DENIED;
}
}
l.mParameters.playShutterSound = false;
return OK;
}

@ -96,8 +96,7 @@ public:
int cameraFacing,
int clientPid,
uid_t clientUid,
int servicePid,
bool legacyMode);
int servicePid);
virtual ~Camera2Client();

@ -40,7 +40,7 @@ CameraClient::CameraClient(const sp<CameraService>& cameraService,
const String16& clientPackageName,
int cameraId, int cameraFacing,
int clientPid, int clientUid,
int servicePid, bool legacyMode):
int servicePid):
Client(cameraService, cameraClient, clientPackageName,
String8::format("%d", cameraId), cameraId, cameraFacing, clientPid,
clientUid, servicePid)
@ -57,7 +57,6 @@ CameraClient::CameraClient(const sp<CameraService>& cameraService,
// Callback is disabled by default
mPreviewCallbackFlag = CAMERA_FRAME_CALLBACK_FLAG_NOOP;
mOrientation = getOrientation(0, mCameraFacing == CAMERA_FACING_FRONT);
mLegacyMode = legacyMode;
mPlayShutterSound = true;
LOG1("CameraClient::CameraClient X (pid %d, id %d)", callingPid, cameraId);
}
@ -715,26 +714,6 @@ status_t CameraClient::enableShutterSound(bool enable) {
return OK;
}
// the camera2 api legacy mode can unconditionally disable the shutter sound
if (mLegacyMode) {
ALOGV("%s: Disable shutter sound in legacy mode", __FUNCTION__);
mPlayShutterSound = false;
return OK;
}
// Disabling shutter sound may not be allowed. In that case only
// allow the mediaserver process to disable the sound.
char value[PROPERTY_VALUE_MAX];
property_get("ro.camera.sound.forced", value, "0");
if (strcmp(value, "0") != 0) {
// Disabling shutter sound is not allowed. Deny if the current
// process is not mediaserver.
if (getCallingPid() != getpid()) {
ALOGE("Failed to disable shutter sound. Permission denied (pid %d)", getCallingPid());
return PERMISSION_DENIED;
}
}
mPlayShutterSound = false;
return OK;
}

@ -68,8 +68,7 @@ public:
int cameraFacing,
int clientPid,
int clientUid,
int servicePid,
bool legacyMode = false);
int servicePid);
~CameraClient();
virtual status_t initialize(sp<CameraProviderManager> manager,

@ -50,8 +50,7 @@ CaptureSequencer::CaptureSequencer(wp<Camera2Client> client):
mStateTransitionCount(0),
mTriggerId(0),
mTimeoutCount(0),
mCaptureId(Camera2Client::kCaptureRequestIdStart),
mMsgType(0) {
mCaptureId(Camera2Client::kCaptureRequestIdStart) {
ALOGV("%s", __FUNCTION__);
}
@ -64,7 +63,7 @@ void CaptureSequencer::setZslProcessor(const wp<ZslProcessor>& processor) {
mZslProcessor = processor;
}
status_t CaptureSequencer::startCapture(int msgType) {
status_t CaptureSequencer::startCapture() {
ALOGV("%s", __FUNCTION__);
ATRACE_CALL();
Mutex::Autolock l(mInputMutex);
@ -73,7 +72,6 @@ status_t CaptureSequencer::startCapture(int msgType) {
return INVALID_OPERATION;
}
if (!mStartCapture) {
mMsgType = msgType;
mStartCapture = true;
mStartCaptureSignal.signal();
}
@ -386,7 +384,7 @@ CaptureSequencer::CaptureState CaptureSequencer::manageZslStart(
SharedParameters::Lock l(client->getParameters());
/* warning: this also locks a SharedCameraCallbacks */
shutterNotifyLocked(l.mParameters, client, mMsgType);
shutterNotifyLocked(l.mParameters, client);
mShutterNotified = true;
mTimeoutCount = kMaxTimeoutsForCaptureEnd;
return STANDARD_CAPTURE_WAIT;
@ -610,7 +608,7 @@ CaptureSequencer::CaptureState CaptureSequencer::manageStandardCaptureWait(
if (!mShutterNotified) {
SharedParameters::Lock l(client->getParameters());
/* warning: this also locks a SharedCameraCallbacks */
shutterNotifyLocked(l.mParameters, client, mMsgType);
shutterNotifyLocked(l.mParameters, client);
mShutterNotified = true;
}
} else if (mTimeoutCount <= 0) {
@ -715,12 +713,11 @@ status_t CaptureSequencer::updateCaptureRequest(const Parameters &params,
}
/*static*/ void CaptureSequencer::shutterNotifyLocked(const Parameters &params,
const sp<Camera2Client>& client, int msgType) {
const sp<Camera2Client>& client) {
ATRACE_CALL();
if (params.state == Parameters::STILL_CAPTURE
&& params.playShutterSound
&& (msgType & CAMERA_MSG_SHUTTER)) {
&& params.playShutterSound) {
client->getCameraService()->playSound(CameraService::SOUND_SHUTTER);
}

@ -51,7 +51,7 @@ class CaptureSequencer:
void setZslProcessor(const wp<ZslProcessor>& processor);
// Begin still image capture
status_t startCapture(int msgType);
status_t startCapture();
// Wait until current image capture completes; returns immediately if no
// capture is active. Returns TIMED_OUT if capture does not complete during
@ -145,7 +145,6 @@ class CaptureSequencer:
bool mAeInPrecapture;
int32_t mCaptureId;
int mMsgType;
// Main internal methods
@ -172,7 +171,7 @@ class CaptureSequencer:
// Emit Shutter/Raw callback to java, and maybe play a shutter sound
static void shutterNotifyLocked(const Parameters &params,
const sp<Camera2Client>& client, int msgType);
const sp<Camera2Client>& client);
};
}; // namespace camera2

Loading…
Cancel
Save