|
18 | 18 |
|
19 | 19 | import android.annotation.SdkConstant; |
20 | 20 | import android.annotation.SdkConstant.SdkConstantType; |
| 21 | +import android.content.Context; |
21 | 22 | import android.graphics.ImageFormat; |
22 | 23 | import android.graphics.Point; |
23 | 24 | import android.graphics.Rect; |
24 | 25 | import android.graphics.SurfaceTexture; |
| 26 | +import android.media.IAudioService; |
25 | 27 | import android.os.Handler; |
| 28 | +import android.os.IBinder; |
26 | 29 | import android.os.Looper; |
27 | 30 | import android.os.Message; |
| 31 | +import android.os.RemoteException; |
| 32 | +import android.os.ServiceManager; |
28 | 33 | import android.util.Log; |
29 | 34 | import android.text.TextUtils; |
30 | 35 | import android.view.Surface; |
@@ -192,7 +197,21 @@ public class Camera { |
192 | 197 | * Returns the information about a particular camera. |
193 | 198 | * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1. |
194 | 199 | */ |
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); |
196 | 215 |
|
197 | 216 | /** |
198 | 217 | * Information about a camera |
@@ -1185,7 +1204,20 @@ public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
1185 | 1204 | * @see CameraInfo#canDisableShutterSound |
1186 | 1205 | * @see ShutterCallback |
1187 | 1206 | */ |
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); |
1189 | 1221 |
|
1190 | 1222 | /** |
1191 | 1223 | * Callback interface for zoom changes during a smooth zoom operation. |
|
0 commit comments