Skip to content

Commit cbdb213

Browse files
Eino-Ville TalvalaAndroid (Google) Code Review
authored andcommitted
Merge "Camera: Query AudioService for shutter sound enforcement." into jb-mr1-dev
2 parents 74bc9b6 + 4f8e5ce commit cbdb213

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

core/java/android/hardware/Camera.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818

1919
import android.annotation.SdkConstant;
2020
import android.annotation.SdkConstant.SdkConstantType;
21+
import android.content.Context;
2122
import android.graphics.ImageFormat;
2223
import android.graphics.Point;
2324
import android.graphics.Rect;
2425
import android.graphics.SurfaceTexture;
26+
import android.media.IAudioService;
2527
import android.os.Handler;
28+
import android.os.IBinder;
2629
import android.os.Looper;
2730
import android.os.Message;
31+
import android.os.RemoteException;
32+
import android.os.ServiceManager;
2833
import android.util.Log;
2934
import android.text.TextUtils;
3035
import android.view.Surface;
@@ -192,7 +197,21 @@ public class Camera {
192197
* Returns the information about a particular camera.
193198
* If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
194199
*/
195-
public native static void getCameraInfo(int cameraId, CameraInfo cameraInfo);
200+
public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
201+
_getCameraInfo(cameraId, cameraInfo);
202+
IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
203+
IAudioService audioService = IAudioService.Stub.asInterface(b);
204+
try {
205+
if (audioService.isCameraSoundForced()) {
206+
// Only set this when sound is forced; otherwise let native code
207+
// decide.
208+
cameraInfo.canDisableShutterSound = false;
209+
}
210+
} catch (RemoteException e) {
211+
Log.e(TAG, "Audio service is unavailable for queries");
212+
}
213+
}
214+
private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
196215

197216
/**
198217
* Information about a camera
@@ -1185,7 +1204,20 @@ public final void takePicture(ShutterCallback shutter, PictureCallback raw,
11851204
* @see CameraInfo#canDisableShutterSound
11861205
* @see ShutterCallback
11871206
*/
1188-
public native final boolean enableShutterSound(boolean enabled);
1207+
public final boolean enableShutterSound(boolean enabled) {
1208+
if (!enabled) {
1209+
IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
1210+
IAudioService audioService = IAudioService.Stub.asInterface(b);
1211+
try {
1212+
if (audioService.isCameraSoundForced()) return false;
1213+
} catch (RemoteException e) {
1214+
Log.e(TAG, "Audio service is unavailable for queries");
1215+
}
1216+
}
1217+
return _enableShutterSound(enabled);
1218+
}
1219+
1220+
private native final boolean _enableShutterSound(boolean enabled);
11891221

11901222
/**
11911223
* Callback interface for zoom changes during a smooth zoom operation.

core/jni/android_hardware_Camera.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ static JNINativeMethod camMethods[] = {
854854
{ "getNumberOfCameras",
855855
"()I",
856856
(void *)android_hardware_Camera_getNumberOfCameras },
857-
{ "getCameraInfo",
857+
{ "_getCameraInfo",
858858
"(ILandroid/hardware/Camera$CameraInfo;)V",
859859
(void*)android_hardware_Camera_getCameraInfo },
860860
{ "native_setup",
@@ -917,7 +917,7 @@ static JNINativeMethod camMethods[] = {
917917
{ "setDisplayOrientation",
918918
"(I)V",
919919
(void *)android_hardware_Camera_setDisplayOrientation },
920-
{ "enableShutterSound",
920+
{ "_enableShutterSound",
921921
"(Z)Z",
922922
(void *)android_hardware_Camera_enableShutterSound },
923923
{ "_startFaceDetection",

0 commit comments

Comments
 (0)