Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee5ad729 authored by John Spurlock's avatar John Spurlock
Browse files

Audio: Remove the concept of master volume.

- Remove two config resources (use master volume, and volume ramp).
- Remove master volume adjustments / getters / intents.
- Retain @hidden setMasterMute, needed for device admin
- Remove master volume logic in AudioService.
- Remove master volume logic in VolumePanel.
- Rename "getMasterStreamType" to "getUiSoundsStreamType" to avoid confusion.

Bug: 19582978
Change-Id: Id02c8fa4898cff3b913147f5ac1b4038e2e7cc24
parent 20d58e2a
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -64,26 +64,11 @@
         As of Honeycomb, blurring is not supported anymore. -->
    <bool name="config_sf_slowBlur">true</bool>

    <!-- Flag indicating that the media framework should allow changing
         master volume stream and nothing else . -->
    <bool name="config_useMasterVolume">false</bool>

    <!-- Flag indicating that the media framework should support playing of sounds on volume
         key usage.  This adds noticeable additional overhead to volume key processing, so
         is disableable for products for which it is irrelevant. -->
    <bool name="config_useVolumeKeySounds">true</bool>

    <!-- Array of integer pairs controlling the rate at which the master volume changes
         in response to volume up and down key events.
         The first integer of each pair is compared against the current master volume
         (in range 0 to 100).
         The last pair with first integer <= the current volume is chosen,
         and the second integer of the pair indicates the amount to increase the master volume
         when volume up is pressed. -->
    <integer-array name="config_masterVolumeRamp">
        <item>0</item>  <item>5</item>  <!-- default: always increase volume by 5% -->
    </integer-array>

    <!-- The attenuation in dB applied to the sound effects played
         through AudioManager.playSoundEffect() when no volume is specified. -->
    <integer name="config_soundEffectVolumeDb">-6</integer>
+0 −2
Original line number Diff line number Diff line
@@ -274,7 +274,6 @@
  <java-symbol type="bool" name="preferences_prefer_dual_pane" />
  <java-symbol type="bool" name="skip_restoring_network_selection" />
  <java-symbol type="bool" name="split_action_bar_is_narrow" />
  <java-symbol type="bool" name="config_useMasterVolume" />
  <java-symbol type="bool" name="config_useVolumeKeySounds" />
  <java-symbol type="bool" name="config_enableWallpaperService" />
  <java-symbol type="bool" name="config_sendAudioBecomingNoisy" />
@@ -1087,7 +1086,6 @@
  <java-symbol type="array" name="sim_colors" />
  <java-symbol type="array" name="special_locale_codes" />
  <java-symbol type="array" name="special_locale_names" />
  <java-symbol type="array" name="config_masterVolumeRamp" />
  <java-symbol type="array" name="config_cdma_dun_supported_types" />
  <java-symbol type="array" name="config_disabledUntilUsedPreinstalledImes" />
  <java-symbol type="array" name="config_operatorConsideredNonRoaming" />
+31 −198
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.media.RemoteController.OnClientUpdateListener;
import android.media.audiopolicy.AudioPolicy;
import android.media.session.MediaController;
import android.media.session.MediaSession;
@@ -59,10 +58,8 @@ public class AudioManager {

    private final Context mContext;
    private long mVolumeKeyUpTime;
    private final boolean mUseMasterVolume;
    private final boolean mUseVolumeKeySounds;
    private final boolean mUseFixedVolume;
    private final Binder mToken = new Binder();
    private static String TAG = "AudioManager";
    private static final AudioPortEventHandler sAudioPortEventHandler = new AudioPortEventHandler();

@@ -147,17 +144,6 @@ public class AudioManager {
    public static final String STREAM_MUTE_CHANGED_ACTION =
        "android.media.STREAM_MUTE_CHANGED_ACTION";

    /**
     * @hide Broadcast intent when the master volume changes.
     * Includes the new volume
     *
     * @see #EXTRA_MASTER_VOLUME_VALUE
     * @see #EXTRA_PREV_MASTER_VOLUME_VALUE
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String MASTER_VOLUME_CHANGED_ACTION =
        "android.media.MASTER_VOLUME_CHANGED_ACTION";

    /**
     * @hide Broadcast intent when the master mute state changes.
     * Includes the the new volume
@@ -209,20 +195,6 @@ public class AudioManager {
    public static final String EXTRA_PREV_VOLUME_STREAM_VALUE =
        "android.media.EXTRA_PREV_VOLUME_STREAM_VALUE";

    /**
     * @hide The new master volume value for the master volume changed intent.
     * Value is integer between 0 and 100 inclusive.
     */
    public static final String EXTRA_MASTER_VOLUME_VALUE =
        "android.media.EXTRA_MASTER_VOLUME_VALUE";

    /**
     * @hide The previous master volume value for the master volume changed intent.
     * Value is integer between 0 and 100 inclusive.
     */
    public static final String EXTRA_PREV_MASTER_VOLUME_VALUE =
        "android.media.EXTRA_PREV_MASTER_VOLUME_VALUE";

    /**
     * @hide The new master volume mute state for the master mute changed intent.
     * Value is boolean
@@ -604,8 +576,6 @@ public class AudioManager {
     */
    public AudioManager(Context context) {
        mContext = context;
        mUseMasterVolume = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_useMasterVolume);
        mUseVolumeKeySounds = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_useVolumeKeySounds);
        mUseFixedVolume = mContext.getResources().getBoolean(
@@ -667,14 +637,10 @@ public class AudioManager {
             * The user has hit another key during the delay (e.g., 300ms)
             * since the last volume key up, so cancel any sounds.
             */
            if (mUseMasterVolume) {
                adjustMasterVolume(ADJUST_SAME, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
            } else {
            adjustSuggestedStreamVolume(ADJUST_SAME,
                    stream, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
        }
    }
    }

    /**
     * @hide
@@ -688,22 +654,12 @@ public class AudioManager {
                 * Adjust the volume in on key down since it is more
                 * responsive to the user.
                 */
                int flags = FLAG_SHOW_UI | FLAG_VIBRATE;

                if (mUseMasterVolume) {
                    adjustMasterVolume(
                            keyCode == KeyEvent.KEYCODE_VOLUME_UP
                                    ? ADJUST_RAISE
                                    : ADJUST_LOWER,
                            flags);
                } else {
                adjustSuggestedStreamVolume(
                        keyCode == KeyEvent.KEYCODE_VOLUME_UP
                                ? ADJUST_RAISE
                                : ADJUST_LOWER,
                        stream,
                            flags);
                }
                        FLAG_SHOW_UI | FLAG_VIBRATE);
                break;
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                if (event.getRepeatCount() == 0) {
@@ -726,15 +682,10 @@ public class AudioManager {
                 * sound to play when a user holds down volume down to mute.
                 */
                if (mUseVolumeKeySounds) {
                    if (mUseMasterVolume) {
                        adjustMasterVolume(ADJUST_SAME, FLAG_PLAY_SOUND);
                    } else {
                        int flags = FLAG_PLAY_SOUND;
                    adjustSuggestedStreamVolume(
                            ADJUST_SAME,
                            stream,
                                flags);
                    }
                            FLAG_PLAY_SOUND);
                }
                mVolumeKeyUpTime = SystemClock.uptimeMillis();
                break;
@@ -783,12 +734,8 @@ public class AudioManager {
    public void adjustStreamVolume(int streamType, int direction, int flags) {
        IAudioService service = getService();
        try {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
            service.adjustStreamVolume(streamType, direction, flags,
                    mContext.getOpPackageName());
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustStreamVolume", e);
        }
@@ -818,18 +765,9 @@ public class AudioManager {
     * @see #isVolumeFixed()
     */
    public void adjustVolume(int direction, int flags) {
        IAudioService service = getService();
        try {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
        helper.sendAdjustVolumeBy(USE_DEFAULT_STREAM_TYPE, direction, flags);
    }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustVolume", e);
        }
    }

    /**
     * Adjusts the volume of the most relevant stream, or the given fallback
@@ -856,34 +794,17 @@ public class AudioManager {
     * @see #isVolumeFixed()
     */
    public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags) {
        IAudioService service = getService();
        try {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
        helper.sendAdjustVolumeBy(suggestedStreamType, direction, flags);
    }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustSuggestedStreamVolume", e);
        }
    }

    /**
     * Adjusts the master volume for the device's audio amplifier.
     * <p>
     *
     * @param steps The number of volume steps to adjust. A positive
     *            value will raise the volume.
     * @param flags One or more flags.
     * @hide
     */
    public void adjustMasterVolume(int steps, int flags) {
    /** @hide */
    public void setMasterMute(boolean mute, int flags) {
        IAudioService service = getService();
        try {
            service.adjustMasterVolume(steps, flags, mContext.getOpPackageName());
            service.setMasterMute(mute, flags, mContext.getOpPackageName());
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustMasterVolume", e);
            Log.e(TAG, "Dead object in setMasterMute", e);
        }
    }

@@ -935,11 +856,7 @@ public class AudioManager {
    public int getStreamMaxVolume(int streamType) {
        IAudioService service = getService();
        try {
            if (mUseMasterVolume) {
                return service.getMasterMaxVolume();
            } else {
            return service.getStreamMaxVolume(streamType);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in getStreamMaxVolume", e);
            return 0;
@@ -957,11 +874,7 @@ public class AudioManager {
    public int getStreamVolume(int streamType) {
        IAudioService service = getService();
        try {
            if (mUseMasterVolume) {
                return service.getMasterVolume();
            } else {
            return service.getStreamVolume(streamType);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in getStreamVolume", e);
            return 0;
@@ -976,11 +889,7 @@ public class AudioManager {
    public int getLastAudibleStreamVolume(int streamType) {
        IAudioService service = getService();
        try {
            if (mUseMasterVolume) {
                return service.getLastAudibleMasterVolume();
            } else {
            return service.getLastAudibleStreamVolume(streamType);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in getLastAudibleStreamVolume", e);
            return 0;
@@ -993,12 +902,12 @@ public class AudioManager {
     * It is assumed that this stream type is also tied to ringer mode changes.
     * @hide
     */
    public int getMasterStreamType() {
    public int getUiSoundsStreamType() {
        IAudioService service = getService();
        try {
            return service.getMasterStreamType();
            return service.getUiSoundsStreamType();
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in getMasterStreamType", e);
            Log.e(TAG, "Dead object in getUiSoundsStreamType", e);
            return STREAM_RING;
        }
    }
@@ -1043,81 +952,12 @@ public class AudioManager {
    public void setStreamVolume(int streamType, int index, int flags) {
        IAudioService service = getService();
        try {
            if (mUseMasterVolume) {
                service.setMasterVolume(index, flags, mContext.getOpPackageName());
            } else {
            service.setStreamVolume(streamType, index, flags, mContext.getOpPackageName());
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in setStreamVolume", e);
        }
    }

    /**
     * Returns the maximum volume index for master volume.
     *
     * @hide
     */
    public int getMasterMaxVolume() {
        IAudioService service = getService();
        try {
            return service.getMasterMaxVolume();
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in getMasterMaxVolume", e);
            return 0;
        }
    }

    /**
     * Returns the current volume index for master volume.
     *
     * @return The current volume index for master volume.
     * @hide
     */
    public int getMasterVolume() {
        IAudioService service = getService();
        try {
            return service.getMasterVolume();
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in getMasterVolume", e);
            return 0;
        }
    }

    /**
     * Get last audible volume before master volume was muted.
     *
     * @hide
     */
    public int getLastAudibleMasterVolume() {
        IAudioService service = getService();
        try {
            return service.getLastAudibleMasterVolume();
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in getLastAudibleMasterVolume", e);
            return 0;
        }
    }

    /**
     * Sets the volume index for master volume.
     *
     * @param index The volume index to set. See
     *            {@link #getMasterMaxVolume()} for the largest valid value.
     * @param flags One or more flags.
     * @see #getMasterMaxVolume()
     * @see #getMasterVolume()
     * @hide
     */
    public void setMasterVolume(int index, int flags) {
        IAudioService service = getService();
        try {
            service.setMasterVolume(index, flags, mContext.getOpPackageName());
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in setMasterVolume", e);
        }
    }

    /**
     * Solo or unsolo a particular stream.
     * <p>
@@ -1189,11 +1029,7 @@ public class AudioManager {
    public boolean isStreamMute(int streamType) {
        IAudioService service = getService();
        try {
            if (mUseMasterVolume) {
                return service.isMasterMute();
            } else {
            return service.isStreamMute(streamType);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in isStreamMute", e);
            return false;
@@ -1223,9 +1059,6 @@ public class AudioManager {
     * @hide
     */
    public void forceVolumeControlStream(int streamType) {
        if (mUseMasterVolume) {
            return;
        }
        IAudioService service = getService();
        try {
            service.forceVolumeControlStream(streamType, mICallBack);
@@ -2694,7 +2527,7 @@ public class AudioManager {
     * metadata updates and playback state information from applications using
     * {@link RemoteControlClient}, and control their playback.
     * <p>
     * Registration requires the {@link OnClientUpdateListener} listener to be
     * Registration requires the {@link RemoteController.OnClientUpdateListener} listener to be
     * one of the enabled notification listeners (see
     * {@link android.service.notification.NotificationListenerService}).
     *
+0 −3
Original line number Diff line number Diff line
@@ -36,9 +36,6 @@ public abstract class AudioManagerInternal {
    public abstract void setStreamVolumeForUid(int streamType, int direction, int flags,
            String callingPackage, int uid);

    public abstract void adjustMasterVolumeForUid(int steps, int flags, String callingPackage,
            int uid);

    public abstract void setRingerModeDelegate(RingerModeDelegate delegate);

    public abstract int getRingerModeInternal();
+3 −11
Original line number Diff line number Diff line
@@ -44,32 +44,24 @@ interface IAudioService {

    void adjustStreamVolume(int streamType, int direction, int flags, String callingPackage);

    void adjustMasterVolume(int direction, int flags, String callingPackage);

    void setStreamVolume(int streamType, int index, int flags, String callingPackage);

    oneway void setRemoteStreamVolume(int index);

    void setMasterVolume(int index, int flags, String callingPackage);

    boolean isStreamMute(int streamType);

    void forceRemoteSubmixFullVolume(boolean startForcing, IBinder cb);

    boolean isMasterMute();

    int getStreamVolume(int streamType);
    void setMasterMute(boolean mute, int flags, String callingPackage);

    int getMasterVolume();
    int getStreamVolume(int streamType);

    int getStreamMaxVolume(int streamType);

    int getMasterMaxVolume();

    int getLastAudibleStreamVolume(int streamType);

    int getLastAudibleMasterVolume();

    void setMicrophoneMute(boolean on, String callingPackage);

    void setRingerModeExternal(int ringerMode, String caller);
@@ -187,7 +179,7 @@ interface IAudioService {

    void setRingtonePlayer(IRingtonePlayer player);
    IRingtonePlayer getRingtonePlayer();
    int getMasterStreamType();
    int getUiSoundsStreamType();

    void setWiredDeviceConnectionState(int type, int state, String address, String name);
    int setBluetoothA2dpDeviceConnectionState(in BluetoothDevice device, int state, int profile);
Loading