diff options
| author | 2018-05-09 20:43:14 +0000 | |
|---|---|---|
| committer | 2018-05-09 20:43:14 +0000 | |
| commit | 065df1d75b8a57c6880dc85571e60e87922075fc (patch) | |
| tree | 2f67e2a9bd1d8de7a75a736cfed36499fbbf7512 | |
| parent | 855694e15b9e6aa075e18c098bb0755ea05f776f (diff) | |
| parent | e059e45b053454deb1044123a5a65ba725fb952c (diff) | |
Merge "Fix shutter sound cannot enable." into pi-dev
| -rw-r--r-- | core/java/android/hardware/Camera.java | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java index 1b80d3d5ee57..9154ce0b1455 100644 --- a/core/java/android/hardware/Camera.java +++ b/core/java/android/hardware/Camera.java @@ -1660,23 +1660,29 @@ public class Camera { * @see ShutterCallback */ public final boolean enableShutterSound(boolean enabled) { - if (!enabled) { - IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); - IAudioService audioService = IAudioService.Stub.asInterface(b); - try { - if (audioService.isCameraSoundForced()) return false; - } catch (RemoteException e) { - Log.e(TAG, "Audio service is unavailable for queries"); + boolean canDisableShutterSound = true; + IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); + IAudioService audioService = IAudioService.Stub.asInterface(b); + try { + if (audioService.isCameraSoundForced()) { + canDisableShutterSound = false; } + } catch (RemoteException e) { + Log.e(TAG, "Audio service is unavailable for queries"); + } + if (!enabled && !canDisableShutterSound) { + return false; } synchronized (mShutterSoundLock) { - if (enabled && mHasAppOpsPlayAudio) { - Log.i(TAG, "Shutter sound is not allowed by AppOpsManager"); - return false; - } + mShutterSoundEnabledFromApp = enabled; + // Return the result of _enableShutterSound(enabled) in all cases. + // If the shutter sound can be disabled, disable it when the device is in DnD mode. boolean ret = _enableShutterSound(enabled); - if (ret) { - mShutterSoundEnabledFromApp = enabled; + if (enabled && !mHasAppOpsPlayAudio) { + Log.i(TAG, "Shutter sound is not allowed by AppOpsManager"); + if (canDisableShutterSound) { + _enableShutterSound(false); + } } return ret; } @@ -1739,9 +1745,18 @@ public class Camera { } if (oldHasAppOpsPlayAudio != mHasAppOpsPlayAudio) { if (!mHasAppOpsPlayAudio) { + IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); + IAudioService audioService = IAudioService.Stub.asInterface(b); + try { + if (audioService.isCameraSoundForced()) { + return; + } + } catch (RemoteException e) { + Log.e(TAG, "Audio service is unavailable for queries"); + } _enableShutterSound(false); } else { - _enableShutterSound(mShutterSoundEnabledFromApp); + enableShutterSound(mShutterSoundEnabledFromApp); } } } |