Skip to content

Commit f7c6c5a

Browse files
author
Eino-Ville Talvala
committed
NEW_API: Add android.hardware.Camera.CameraInfo#canDisableShutterSound
Allow applications to check if the camera shutter sound can be disabled. Bug: 7172643 Change-Id: I3e9184325d3676b24830cc5418ebca8dcade8697
1 parent 9d7657c commit f7c6c5a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9755,6 +9755,7 @@ package android.hardware {
97559755
ctor public Camera.CameraInfo();
97569756
field public static final int CAMERA_FACING_BACK = 0; // 0x0
97579757
field public static final int CAMERA_FACING_FRONT = 1; // 0x1
9758+
field public boolean canDisableShutterSound;
97589759
field public int facing;
97599760
field public int orientation;
97609761
}

core/java/android/hardware/Camera.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,21 @@ public static class CameraInfo {
233233
* @see Parameters#setJpegThumbnailSize(int, int)
234234
*/
235235
public int orientation;
236+
237+
/**
238+
* <p>Whether the shutter sound can be disabled.</p>
239+
*
240+
* <p>On some devices, the camera shutter sound cannot be turned off
241+
* through {@link #enableShutterSound enableShutterSound}. This field
242+
* can be used to determine whether a call to disable the shutter sound
243+
* will succeed.</p>
244+
*
245+
* <p>If this field is set to true, then a call of
246+
* {@code enableShutterSound(false)} will be successful. If set to
247+
* false, then that call will fail, and the shutter sound will be played
248+
* when {@link Camera#takePicture takePicture} is called.</p>
249+
*/
250+
public boolean canDisableShutterSound;
236251
};
237252

238253
/**

core/jni/android_hardware_Camera.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "JNIHelp.h"
2424
#include "android_runtime/AndroidRuntime.h"
2525

26+
#include <cutils/properties.h>
2627
#include <utils/Vector.h>
2728

2829
#include <gui/SurfaceTexture.h>
@@ -38,6 +39,7 @@ struct fields_t {
3839
jfieldID surfaceTexture;
3940
jfieldID facing;
4041
jfieldID orientation;
42+
jfieldID canDisableShutterSound;
4143
jfieldID face_rect;
4244
jfieldID face_score;
4345
jfieldID rect_left;
@@ -453,6 +455,12 @@ static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
453455
}
454456
env->SetIntField(info_obj, fields.facing, cameraInfo.facing);
455457
env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation);
458+
459+
char value[PROPERTY_VALUE_MAX];
460+
property_get("ro.camera.sound.forced", value, "0");
461+
jboolean canDisableShutterSound = (strncmp(value, "0", 2) == 0);
462+
env->SetBooleanField(info_obj, fields.canDisableShutterSound,
463+
canDisableShutterSound);
456464
}
457465

458466
// connect to camera service
@@ -962,6 +970,8 @@ int register_android_hardware_Camera(JNIEnv *env)
962970
ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I", &fields.surfaceTexture },
963971
{ "android/hardware/Camera$CameraInfo", "facing", "I", &fields.facing },
964972
{ "android/hardware/Camera$CameraInfo", "orientation", "I", &fields.orientation },
973+
{ "android/hardware/Camera$CameraInfo", "canDisableShutterSound", "Z",
974+
&fields.canDisableShutterSound },
965975
{ "android/hardware/Camera$Face", "rect", "Landroid/graphics/Rect;", &fields.face_rect },
966976
{ "android/hardware/Camera$Face", "score", "I", &fields.face_score },
967977
{ "android/graphics/Rect", "left", "I", &fields.rect_left },

0 commit comments

Comments
 (0)