diff options
author | RoboErik <epastern@google.com> | 2015-01-30 18:55:08 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-01-30 18:55:10 +0000 |
commit | ddce02f3b90b5b0c6709200cbc960c892e3ea48b (patch) | |
tree | df8140790cc619e9a48a616f9523db62bbdb65c4 /media/java | |
parent | 447590524ac387f8d1ad7fad5e8c56e6644a3d70 (diff) | |
parent | 4197cb60bc74629fe4c04ab10cb3b1c9a7427d24 (diff) | |
download | frameworks_base-ddce02f3b90b5b0c6709200cbc960c892e3ea48b.zip frameworks_base-ddce02f3b90b5b0c6709200cbc960c892e3ea48b.tar.gz frameworks_base-ddce02f3b90b5b0c6709200cbc960c892e3ea48b.tar.bz2 |
Merge "Move mute/unmute handling to adjust volume paths"
Diffstat (limited to 'media/java')
-rw-r--r-- | media/java/android/media/AudioManager.java | 166 | ||||
-rw-r--r-- | media/java/android/media/AudioManagerInternal.java | 3 | ||||
-rw-r--r-- | media/java/android/media/AudioService.java | 297 | ||||
-rw-r--r-- | media/java/android/media/IAudioService.aidl | 6 | ||||
-rw-r--r-- | media/java/android/media/session/MediaSessionLegacyHelper.java | 6 | ||||
-rw-r--r-- | media/java/android/media/session/MediaSessionManager.java | 8 |
6 files changed, 185 insertions, 301 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 9bcf3c8..f448dc2 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -346,6 +346,31 @@ public class AudioManager { */ public static final int ADJUST_SAME = 0; + /** + * Mute the volume. Has no effect if the stream is already muted. + * + * @see #adjustVolume(int, int) + * @see #adjustStreamVolume(int, int, int) + */ + public static final int ADJUST_MUTE = -100; + + /** + * Unmute the volume. Has no effect if the stream is not muted. + * + * @see #adjustVolume(int, int) + * @see #adjustStreamVolume(int, int, int) + */ + public static final int ADJUST_UNMUTE = 100; + + /** + * Toggle the mute state. If muted the stream will be unmuted. If not muted + * the stream will be muted. + * + * @see #adjustVolume(int, int) + * @see #adjustStreamVolume(int, int, int) + */ + public static final int ADJUST_TOGGLE_MUTE = 101; + // Flags should be powers of 2! /** @@ -777,13 +802,17 @@ public class AudioManager { * screen is showing. Another example, if music is playing in the background * and a call is not active, the music stream will be adjusted. * <p> - * This method should only be used by applications that replace the platform-wide - * management of audio settings or the main telephony application. - * <p>This method has no effect if the device implements a fixed volume policy + * This method should only be used by applications that replace the + * platform-wide management of audio settings or the main telephony + * application. + * <p> + * This method has no effect if the device implements a fixed volume policy * as indicated by {@link #isVolumeFixed()}. + * * @param direction The direction to adjust the volume. One of - * {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, or - * {@link #ADJUST_SAME}. + * {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, + * {@link #ADJUST_SAME}, {@link #ADJUST_MUTE}, + * {@link #ADJUST_UNMUTE}, or {@link #ADJUST_TOGGLE_MUTE}. * @param flags One or more flags. * @see #adjustSuggestedStreamVolume(int, int, int) * @see #adjustStreamVolume(int, int, int) @@ -808,16 +837,20 @@ public class AudioManager { * Adjusts the volume of the most relevant stream, or the given fallback * stream. * <p> - * This method should only be used by applications that replace the platform-wide - * management of audio settings or the main telephony application. - * - * <p>This method has no effect if the device implements a fixed volume policy + * This method should only be used by applications that replace the + * platform-wide management of audio settings or the main telephony + * application. + * <p> + * This method has no effect if the device implements a fixed volume policy * as indicated by {@link #isVolumeFixed()}. + * * @param direction The direction to adjust the volume. One of - * {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, or - * {@link #ADJUST_SAME}. + * {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, + * {@link #ADJUST_SAME}, {@link #ADJUST_MUTE}, + * {@link #ADJUST_UNMUTE}, or {@link #ADJUST_TOGGLE_MUTE}. * @param suggestedStreamType The stream type that will be used if there - * isn't a relevant stream. {@link #USE_DEFAULT_STREAM_TYPE} is valid here. + * isn't a relevant stream. {@link #USE_DEFAULT_STREAM_TYPE} is + * valid here. * @param flags One or more flags. * @see #adjustVolume(int, int) * @see #adjustStreamVolume(int, int, int) @@ -1088,72 +1121,72 @@ public class AudioManager { } /** - * Solo or unsolo a particular stream. All other streams are muted. - * <p> - * The solo command is protected against client process death: if a process - * with an active solo request on a stream dies, all streams that were muted - * because of this request will be unmuted automatically. - * <p> - * The solo requests for a given stream are cumulative: the AudioManager - * can receive several solo requests from one or more clients and the stream - * will be unsoloed only when the same number of unsolo requests are received. + * Solo or unsolo a particular stream. * <p> - * For a better user experience, applications MUST unsolo a soloed stream - * in onPause() and solo is again in onResume() if appropriate. - * <p>This method has no effect if the device implements a fixed volume policy - * as indicated by {@link #isVolumeFixed()}. + * Do not use. This method has been deprecated and is now a no-op. + * {@link #requestAudioFocus} should be used for exclusive audio playback. * * @param streamType The stream to be soloed/unsoloed. - * @param state The required solo state: true for solo ON, false for solo OFF - * + * @param state The required solo state: true for solo ON, false for solo + * OFF * @see #isVolumeFixed() + * @deprecated Do not use. If you need exclusive audio playback use + * {@link #requestAudioFocus}. */ + @Deprecated public void setStreamSolo(int streamType, boolean state) { - IAudioService service = getService(); - try { - service.setStreamSolo(streamType, state, mICallBack); - } catch (RemoteException e) { - Log.e(TAG, "Dead object in setStreamSolo", e); - } + Log.w(TAG, "setStreamSolo has been deprecated. Do not use."); } /** * Mute or unmute an audio stream. * <p> - * The mute command is protected against client process death: if a process - * with an active mute request on a stream dies, this stream will be unmuted - * automatically. - * <p> - * The mute requests for a given stream are cumulative: the AudioManager - * can receive several mute requests from one or more clients and the stream - * will be unmuted only when the same number of unmute requests are received. - * <p> - * For a better user experience, applications MUST unmute a muted stream - * in onPause() and mute is again in onResume() if appropriate. + * This method should only be used by applications that replace the + * platform-wide management of audio settings or the main telephony + * application. * <p> - * This method should only be used by applications that replace the platform-wide - * management of audio settings or the main telephony application. - * <p>This method has no effect if the device implements a fixed volume policy + * This method has no effect if the device implements a fixed volume policy * as indicated by {@link #isVolumeFixed()}. + * <p> + * This method was deprecated in API level 22. Prior to API level 22 this + * method had significantly different behavior and should be used carefully. + * The following applies only to pre-22 platforms: + * <ul> + * <li>The mute command is protected against client process death: if a + * process with an active mute request on a stream dies, this stream will be + * unmuted automatically.</li> + * <li>The mute requests for a given stream are cumulative: the AudioManager + * can receive several mute requests from one or more clients and the stream + * will be unmuted only when the same number of unmute requests are + * received.</li> + * <li>For a better user experience, applications MUST unmute a muted stream + * in onPause() and mute is again in onResume() if appropriate.</li> + * </ul> * * @param streamType The stream to be muted/unmuted. - * @param state The required mute state: true for mute ON, false for mute OFF - * + * @param state The required mute state: true for mute ON, false for mute + * OFF * @see #isVolumeFixed() + * @deprecated Use {@link #adjustStreamVolume(int, int, int)} with + * {@link #ADJUST_MUTE} or {@link #ADJUST_UNMUTE} instead. */ + @Deprecated public void setStreamMute(int streamType, boolean state) { - IAudioService service = getService(); - try { - service.setStreamMute(streamType, state, mICallBack); - } catch (RemoteException e) { - Log.e(TAG, "Dead object in setStreamMute", e); + Log.w(TAG, "setStreamMute is deprecated. adjustStreamVolume should be used instead."); + int direction = state ? ADJUST_MUTE : ADJUST_UNMUTE; + if (streamType == AudioManager.USE_DEFAULT_STREAM_TYPE) { + adjustSuggestedStreamVolume(direction, streamType, 0); + } else { + adjustStreamVolume(streamType, direction, 0); } } /** - * get stream mute state. + * Returns the current mute state for a particular stream. * - * @hide + * @param streamType The stream to get mute state for. + * @return The mute state for the given stream. + * @see #adjustStreamVolume(int, int, int) */ public boolean isStreamMute(int streamType) { IAudioService service = getService(); @@ -1166,29 +1199,6 @@ public class AudioManager { } /** - * set master mute state. - * - * @hide - */ - public void setMasterMute(boolean state) { - setMasterMute(state, FLAG_SHOW_UI); - } - - /** - * set master mute state with optional flags. - * - * @hide - */ - public void setMasterMute(boolean state, int flags) { - IAudioService service = getService(); - try { - service.setMasterMute(state, flags, mContext.getOpPackageName(), mICallBack); - } catch (RemoteException e) { - Log.e(TAG, "Dead object in setMasterMute", e); - } - } - - /** * get master mute state. * * @hide diff --git a/media/java/android/media/AudioManagerInternal.java b/media/java/android/media/AudioManagerInternal.java index 616bdd1..873c142 100644 --- a/media/java/android/media/AudioManagerInternal.java +++ b/media/java/android/media/AudioManagerInternal.java @@ -41,9 +41,6 @@ public abstract class AudioManagerInternal { public abstract void adjustMasterVolumeForUid(int steps, int flags, String callingPackage, int uid); - public abstract void setMasterMuteForUid(boolean state, int flags, String callingPackage, - IBinder cb, int uid); - public abstract void setRingerModeDelegate(RingerModeDelegate delegate); public abstract int getRingerModeInternal(); diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 0ffa5fc..d96fee6 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -748,7 +748,7 @@ public class AudioService extends IAudioService.Stub { setAllIndexes(mStreamStates[mStreamVolumeAlias[streamType]]); } // apply stream volume - if (!mStreamStates[streamType].isMuted_syncVSS()) { + if (!mStreamStates[streamType].mIsMuted) { mStreamStates[streamType].applyAllVolumes(); } } @@ -970,6 +970,7 @@ public class AudioService extends IAudioService.Stub { if (DEBUG_VOL) Log.d(TAG, "adjustSuggestedStreamVolume() stream="+suggestedStreamType + ", flags=" + flags); int streamType; + boolean isMute = isMuteAdjust(direction); if (mVolumeControlStream != -1) { streamType = mVolumeControlStream; } else { @@ -984,7 +985,8 @@ public class AudioService extends IAudioService.Stub { } // For notifications/ring, show the ui before making any adjustments - if (mVolumeController.suppressAdjustment(resolvedStream, flags)) { + // Don't suppress mute/unmute requests + if (mVolumeController.suppressAdjustment(resolvedStream, flags, isMute)) { direction = 0; flags &= ~AudioManager.FLAG_PLAY_SOUND; flags &= ~AudioManager.FLAG_VIBRATE; @@ -1011,10 +1013,17 @@ public class AudioService extends IAudioService.Stub { ensureValidDirection(direction); ensureValidStreamType(streamType); + boolean isMuteAdjust = isMuteAdjust(direction); + // use stream type alias here so that streams with same alias have the same behavior, // including with regard to silent mode control (e.g the use of STREAM_RING below and in // checkForRingerModeChange() in place of STREAM_RING or STREAM_NOTIFICATION) int streamTypeAlias = mStreamVolumeAlias[streamType]; + + if (isMuteAdjust && !isStreamAffectedByMute(streamTypeAlias)) { + return; + } + VolumeStreamState streamState = mStreamStates[streamTypeAlias]; final int device = getDeviceForStream(streamTypeAlias); @@ -1100,13 +1109,37 @@ public class AudioService extends IAudioService.Stub { } } - if ((direction == AudioManager.ADJUST_RAISE) && + if (isMuteAdjust) { + boolean state; + if (direction == AudioManager.ADJUST_TOGGLE_MUTE) { + state = !streamState.mIsMuted; + } else { + state = direction == AudioManager.ADJUST_MUTE; + } + if (streamTypeAlias == AudioSystem.STREAM_MUSIC) { + setSystemAudioMute(state); + } + for (int stream = 0; stream < mStreamStates.length; stream++) { + if (streamTypeAlias == mStreamVolumeAlias[stream]) { + mStreamStates[stream].mute(state); + + Intent intent = new Intent(AudioManager.STREAM_MUTE_CHANGED_ACTION); + intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, stream); + intent.putExtra(AudioManager.EXTRA_STREAM_VOLUME_MUTED, state); + sendBroadcastToAll(intent); + } + } + } else if ((direction == AudioManager.ADJUST_RAISE) && !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) { - Log.e(TAG, "adjustStreamVolume() safe volume index = "+oldIndex); + Log.e(TAG, "adjustStreamVolume() safe volume index = " + oldIndex); mVolumeController.postDisplaySafeVolumeWarning(flags); - } else if (streamState.adjustIndex(direction * step, device)) { - // Post message to set system volume (it in turn will post a message - // to persist). Do not change volume if stream is muted. + } else if (streamState.adjustIndex(direction * step, device) || streamState.mIsMuted) { + // Post message to set system volume (it in turn will post a + // message to persist). + if (streamState.mIsMuted) { + // Unmute the stream if it was previously muted + streamState.mute(false); + } sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE, @@ -1116,7 +1149,7 @@ public class AudioService extends IAudioService.Stub { 0); } - // Check if volume update should be send to Hdmi system audio. + // Check if volume update should be sent to Hdmi system audio. int newIndex = mStreamStates[streamType].getIndex(device); if (streamTypeAlias == AudioSystem.STREAM_MUSIC) { setSystemAudioVolume(oldIndex, newIndex, getStreamMaxVolume(streamType), flags); @@ -1129,7 +1162,7 @@ public class AudioService extends IAudioService.Stub { oldIndex != newIndex) { synchronized (mHdmiPlaybackClient) { int keyCode = (direction == -1) ? KeyEvent.KEYCODE_VOLUME_DOWN : - KeyEvent.KEYCODE_VOLUME_UP; + KeyEvent.KEYCODE_VOLUME_UP; mHdmiPlaybackClient.sendKeyEvent(keyCode, true); mHdmiPlaybackClient.sendKeyEvent(keyCode, false); } @@ -1172,6 +1205,10 @@ public class AudioService extends IAudioService.Stub { if (mUseFixedVolume) { return; } + if (isMuteAdjust(steps)) { + setMasterMuteInternal(steps, flags, callingPackage, uid); + return; + } ensureValidSteps(steps); int volume = Math.round(AudioSystem.getMasterVolume() * MAX_MASTER_VOLUME); int delta = 0; @@ -1500,46 +1537,6 @@ public class AudioService extends IAudioService.Stub { } } - /** @see AudioManager#setStreamSolo(int, boolean) */ - public void setStreamSolo(int streamType, boolean state, IBinder cb) { - if (mUseFixedVolume) { - return; - } - int streamAlias = mStreamVolumeAlias[streamType]; - for (int stream = 0; stream < mStreamStates.length; stream++) { - if (!isStreamAffectedByMute(streamAlias) || streamAlias == mStreamVolumeAlias[stream]) { - continue; - } - mStreamStates[stream].mute(cb, state); - } - } - - /** @see AudioManager#setStreamMute(int, boolean) */ - public void setStreamMute(int streamType, boolean state, IBinder cb) { - if (mUseFixedVolume) { - return; - } - if (streamType == AudioManager.USE_DEFAULT_STREAM_TYPE) { - streamType = getActiveStreamType(streamType); - } - int streamAlias = mStreamVolumeAlias[streamType]; - if (isStreamAffectedByMute(streamAlias)) { - if (streamAlias == AudioSystem.STREAM_MUSIC) { - setSystemAudioMute(state); - } - for (int stream = 0; stream < mStreamStates.length; stream++) { - if (streamAlias == mStreamVolumeAlias[stream]) { - mStreamStates[stream].mute(cb, state); - - Intent intent = new Intent(AudioManager.STREAM_MUTE_CHANGED_ACTION); - intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, stream); - intent.putExtra(AudioManager.EXTRA_STREAM_VOLUME_MUTED, state); - sendBroadcastToAll(intent); - } - } - } - } - private void setSystemAudioMute(boolean state) { if (mHdmiManager == null || mHdmiTvClient == null) return; synchronized (mHdmiManager) { @@ -1561,7 +1558,7 @@ public class AudioService extends IAudioService.Stub { streamType = getActiveStreamType(streamType); } synchronized (VolumeStreamState.class) { - return mStreamStates[streamType].isMuted_syncVSS(); + return mStreamStates[streamType].mIsMuted; } } @@ -1665,20 +1662,17 @@ public class AudioService extends IAudioService.Stub { } } - /** @see AudioManager#setMasterMute(boolean, int) */ - public void setMasterMute(boolean state, int flags, String callingPackage, IBinder cb) { - setMasterMuteInternal(state, flags, callingPackage, cb, Binder.getCallingUid()); - } - - private void setMasterMuteInternal(boolean state, int flags, String callingPackage, IBinder cb, - int uid) { - if (mUseFixedVolume) { - return; - } + private void setMasterMuteInternal(int adjust, int flags, String callingPackage, int uid) { if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, uid, callingPackage) != AppOpsManager.MODE_ALLOWED) { return; } + boolean state; + if (adjust == AudioManager.ADJUST_TOGGLE_MUTE) { + state = !AudioSystem.getMasterMute(); + } else { + state = adjust == AudioManager.ADJUST_MUTE; + } if (state != AudioSystem.getMasterMute()) { setSystemAudioMute(state); AudioSystem.setMasterMute(state); @@ -1714,7 +1708,7 @@ public class AudioService extends IAudioService.Stub { int index = mStreamStates[streamType].getIndex(device); // by convention getStreamVolume() returns 0 when a stream is muted. - if (mStreamStates[streamType].isMuted_syncVSS()) { + if (mStreamStates[streamType].mIsMuted) { index = 0; } if (index != 0 && (mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && @@ -1934,11 +1928,11 @@ public class AudioService extends IAudioService.Stub { } } } - mStreamStates[streamType].mute(null, false); + mStreamStates[streamType].mute(false); mRingerModeMutedStreams &= ~(1 << streamType); } else { // mute - mStreamStates[streamType].mute(null, true); + mStreamStates[streamType].mute(true); mRingerModeMutedStreams |= (1 << streamType); } } @@ -2426,13 +2420,9 @@ public class AudioService extends IAudioService.Stub { streamState.readSettings(); synchronized (VolumeStreamState.class) { // unmute stream that was muted but is not affect by mute anymore - if (streamState.isMuted_syncVSS() && ((!isStreamAffectedByMute(streamType) && + if (streamState.mIsMuted && ((!isStreamAffectedByMute(streamType) && !isStreamMutedByRingerMode(streamType)) || mUseFixedVolume)) { - int size = streamState.mDeathHandlers.size(); - for (int i = 0; i < size; i++) { - streamState.mDeathHandlers.get(i).mMuteCount = 1; - streamState.mDeathHandlers.get(i).mute_syncVSS(false); - } + streamState.mIsMuted = false; } } } @@ -3221,8 +3211,16 @@ public class AudioService extends IAudioService.Stub { } private void ensureValidDirection(int direction) { - if (direction < AudioManager.ADJUST_LOWER || direction > AudioManager.ADJUST_RAISE) { - throw new IllegalArgumentException("Bad direction " + direction); + switch (direction) { + case AudioManager.ADJUST_LOWER: + case AudioManager.ADJUST_RAISE: + case AudioManager.ADJUST_SAME: + case AudioManager.ADJUST_MUTE: + case AudioManager.ADJUST_UNMUTE: + case AudioManager.ADJUST_TOGGLE_MUTE: + break; + default: + throw new IllegalArgumentException("Bad direction " + direction); } } @@ -3238,6 +3236,11 @@ public class AudioService extends IAudioService.Stub { } } + private boolean isMuteAdjust(int adjust) { + return adjust == AudioManager.ADJUST_MUTE || adjust == AudioManager.ADJUST_UNMUTE + || adjust == AudioManager.ADJUST_TOGGLE_MUTE; + } + private boolean isInCommunication() { boolean IsInCall = false; @@ -3467,11 +3470,11 @@ public class AudioService extends IAudioService.Stub { public class VolumeStreamState { private final int mStreamType; + private boolean mIsMuted; private String mVolumeIndexSettingName; private int mIndexMax; private final ConcurrentHashMap<Integer, Integer> mIndex = new ConcurrentHashMap<Integer, Integer>(8, 0.75f, 4); - private ArrayList<VolumeDeathHandler> mDeathHandlers; //handles mute/solo clients death private VolumeStreamState(String settingName, int streamType) { @@ -3482,9 +3485,6 @@ public class AudioService extends IAudioService.Stub { AudioSystem.initStreamVolume(streamType, 0, mIndexMax); mIndexMax *= 10; - // mDeathHandlers must be created before calling readSettings() - mDeathHandlers = new ArrayList<VolumeDeathHandler>(); - readSettings(); } @@ -3549,7 +3549,7 @@ public class AudioService extends IAudioService.Stub { // must be called while synchronized VolumeStreamState.class public void applyDeviceVolume_syncVSS(int device) { int index; - if (isMuted_syncVSS()) { + if (mIsMuted) { index = 0; } else if (((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && mAvrcpAbsVolSupported) || ((device & mFullVolumeDevices) != 0)) { @@ -3565,7 +3565,7 @@ public class AudioService extends IAudioService.Stub { // apply default volume first: by convention this will reset all // devices volumes in audio policy manager to the supplied value int index; - if (isMuted_syncVSS()) { + if (mIsMuted) { index = 0; } else { index = (getIndex(AudioSystem.DEVICE_OUT_DEFAULT) + 5)/10; @@ -3578,7 +3578,7 @@ public class AudioService extends IAudioService.Stub { Map.Entry entry = (Map.Entry)i.next(); int device = ((Integer)entry.getKey()).intValue(); if (device != AudioSystem.DEVICE_OUT_DEFAULT) { - if (isMuted_syncVSS()) { + if (mIsMuted) { index = 0; } else if (((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && mAvrcpAbsVolSupported) @@ -3688,14 +3688,20 @@ public class AudioService extends IAudioService.Stub { } } - public void mute(IBinder cb, boolean state) { + public void mute(boolean state) { synchronized (VolumeStreamState.class) { - VolumeDeathHandler handler = getDeathHandler_syncVSS(cb, state); - if (handler == null) { - Log.e(TAG, "Could not get client death handler for stream: "+mStreamType); - return; + if (state != mIsMuted) { + mIsMuted = state; + // Set the new mute volume. This propagates the values to + // the audio system, otherwise the volume won't be changed + // at the lower level. + sendMsg(mAudioHandler, + MSG_SET_ALL_VOLUMES, + SENDMSG_QUEUE, + 0, + 0, + this, 0); } - handler.mute_syncVSS(state); } } @@ -3733,117 +3739,9 @@ public class AudioService extends IAudioService.Stub { return index; } - private class VolumeDeathHandler implements IBinder.DeathRecipient { - private IBinder mICallback; // To be notified of client's death - private int mMuteCount; // Number of active mutes for this client - - VolumeDeathHandler(IBinder cb) { - mICallback = cb; - } - - // must be called while synchronized VolumeStreamState.class - public void mute_syncVSS(boolean state) { - boolean updateVolume = false; - if (state) { - if (mMuteCount == 0) { - // Register for client death notification - try { - // mICallback can be 0 if muted by AudioService - if (mICallback != null) { - mICallback.linkToDeath(this, 0); - } - VolumeStreamState.this.mDeathHandlers.add(this); - // If the stream is not yet muted by any client, set level to 0 - if (!VolumeStreamState.this.isMuted_syncVSS()) { - updateVolume = true; - } - } catch (RemoteException e) { - // Client has died! - binderDied(); - return; - } - } else { - Log.w(TAG, "stream: "+mStreamType+" was already muted by this client"); - } - mMuteCount++; - } else { - if (mMuteCount == 0) { - Log.e(TAG, "unexpected unmute for stream: "+mStreamType); - } else { - mMuteCount--; - if (mMuteCount == 0) { - // Unregister from client death notification - VolumeStreamState.this.mDeathHandlers.remove(this); - // mICallback can be 0 if muted by AudioService - if (mICallback != null) { - mICallback.unlinkToDeath(this, 0); - } - if (!VolumeStreamState.this.isMuted_syncVSS()) { - updateVolume = true; - } - } - } - } - if (updateVolume) { - sendMsg(mAudioHandler, - MSG_SET_ALL_VOLUMES, - SENDMSG_QUEUE, - 0, - 0, - VolumeStreamState.this, 0); - } - } - - public void binderDied() { - Log.w(TAG, "Volume service client died for stream: "+mStreamType); - synchronized (VolumeStreamState.class) { - if (mMuteCount != 0) { - // Reset all active mute requests from this client. - mMuteCount = 1; - mute_syncVSS(false); - } - } - } - } - - private int muteCount() { - int count = 0; - int size = mDeathHandlers.size(); - for (int i = 0; i < size; i++) { - count += mDeathHandlers.get(i).mMuteCount; - } - return count; - } - - // must be called while synchronized VolumeStreamState.class - private boolean isMuted_syncVSS() { - return muteCount() != 0; - } - - // must be called while synchronized VolumeStreamState.class - private VolumeDeathHandler getDeathHandler_syncVSS(IBinder cb, boolean state) { - VolumeDeathHandler handler; - int size = mDeathHandlers.size(); - for (int i = 0; i < size; i++) { - handler = mDeathHandlers.get(i); - if (cb == handler.mICallback) { - return handler; - } - } - // If this is the first mute request for this client, create a new - // client death handler. Otherwise, it is an out of sequence unmute request. - if (state) { - handler = new VolumeDeathHandler(cb); - } else { - Log.w(TAG, "stream was not muted by this client"); - handler = null; - } - return handler; - } - private void dump(PrintWriter pw) { - pw.print(" Mute count: "); - pw.println(muteCount()); + pw.print(" Muted: "); + pw.println(mIsMuted); pw.print(" Max: "); pw.println((mIndexMax + 5) / 10); pw.print(" Current: "); @@ -5648,7 +5546,10 @@ public class AudioService extends IAudioService.Stub { Settings.Secure.LONG_PRESS_TIMEOUT, 500, UserHandle.USER_CURRENT); } - public boolean suppressAdjustment(int resolvedStream, int flags) { + public boolean suppressAdjustment(int resolvedStream, int flags, boolean isMute) { + if (isMute) { + return false; + } boolean suppress = false; if (resolvedStream == AudioSystem.STREAM_RING && mController != null) { final long now = SystemClock.uptimeMillis(); @@ -5801,12 +5702,6 @@ public class AudioService extends IAudioService.Stub { public void setRingerModeInternal(int ringerMode, String caller) { AudioService.this.setRingerModeInternal(ringerMode, caller); } - - @Override - public void setMasterMuteForUid(boolean state, int flags, String callingPackage, IBinder cb, - int uid) { - setMasterMuteInternal(state, flags, callingPackage, cb, uid); - } } //========================================================================================== diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl index fad3cec..bfb78a1 100644 --- a/media/java/android/media/IAudioService.aidl +++ b/media/java/android/media/IAudioService.aidl @@ -52,16 +52,10 @@ interface IAudioService { void setMasterVolume(int index, int flags, String callingPackage); - void setStreamSolo(int streamType, boolean state, IBinder cb); - - void setStreamMute(int streamType, boolean state, IBinder cb); - boolean isStreamMute(int streamType); void forceRemoteSubmixFullVolume(boolean startForcing, IBinder cb); - void setMasterMute(boolean state, int flags, String callingPackage, IBinder cb); - boolean isMasterMute(); int getStreamVolume(int streamType); diff --git a/media/java/android/media/session/MediaSessionLegacyHelper.java b/media/java/android/media/session/MediaSessionLegacyHelper.java index 7ea269b..9954de5 100644 --- a/media/java/android/media/session/MediaSessionLegacyHelper.java +++ b/media/java/android/media/session/MediaSessionLegacyHelper.java @@ -222,13 +222,9 @@ public class MediaSessionLegacyHelper { direction, flags); } else if (isMute) { if (down) { - // We need to send two volume events on down, one to mute - // and one to show the UI mSessionManager.dispatchAdjustVolume(AudioManager.USE_DEFAULT_STREAM_TYPE, - MediaSessionManager.DIRECTION_MUTE, flags); + AudioManager.ADJUST_TOGGLE_MUTE, flags); } - mSessionManager.dispatchAdjustVolume(AudioManager.USE_DEFAULT_STREAM_TYPE, - 0 /* direction, causes UI to show on down */, flags); } } } diff --git a/media/java/android/media/session/MediaSessionManager.java b/media/java/android/media/session/MediaSessionManager.java index a4ef851..b4fff8f 100644 --- a/media/java/android/media/session/MediaSessionManager.java +++ b/media/java/android/media/session/MediaSessionManager.java @@ -59,14 +59,6 @@ public final class MediaSessionManager { private Context mContext; /** - * Special flag for sending the mute key to dispatchAdjustVolume used by the - * system. - * - * @hide - */ - public static final int DIRECTION_MUTE = -99; - - /** * @hide */ public MediaSessionManager(Context context) { |