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

Commit 6156017c authored by John Spurlock's avatar John Spurlock
Browse files

Move AudioService to services.

...and a few dependencies. Move remaining shared items to AudioSystem.

Change-Id: Ib9623ff867678d34977337856bb0156e8cdaeeb5
parent 7d85bc4c
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -45,8 +45,9 @@ public final class AudioFocusInfo implements Parcelable {
     * @param gainRequest
     * @param lossReceived
     * @param flags
     * @hide
     */
    AudioFocusInfo(AudioAttributes aa, String clientId, String packageName,
    public AudioFocusInfo(AudioAttributes aa, String clientId, String packageName,
            int gainRequest, int lossReceived, int flags) {
        mAttributes = aa == null ? new AudioAttributes.Builder().build() : aa;
        mClientId = clientId == null ? "" : clientId;
@@ -91,7 +92,7 @@ public final class AudioFocusInfo implements Parcelable {
    public int getLossReceived() { return mLossReceived; }

    /** @hide */
    void clearLossReceived() { mLossReceived = 0; }
    public void clearLossReceived() { mLossReceived = 0; }

    /**
     * The flags set in the audio focus request.
+3 −4
Original line number Diff line number Diff line
@@ -663,8 +663,7 @@ public class AudioManager {
        int keyCode = event.getKeyCode();
        if (keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_UP
                && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
                && mVolumeKeyUpTime + AudioService.PLAY_SOUND_DELAY
                        > SystemClock.uptimeMillis()) {
                && mVolumeKeyUpTime + AudioSystem.PLAY_SOUND_DELAY > SystemClock.uptimeMillis()) {
            /*
             * The user has hit another key during the delay (e.g., 300ms)
             * since the last volume key up, so cancel any sounds.
@@ -2501,7 +2500,7 @@ public class AudioManager {
            service.requestAudioFocus(new AudioAttributes.Builder()
                        .setInternalLegacyStreamType(streamType).build(),
                    durationHint, mICallBack, null,
                    MediaFocusControl.IN_VOICE_COMM_FOCUS_ID,
                    AudioSystem.IN_VOICE_COMM_FOCUS_ID,
                    mContext.getOpPackageName(),
                    AUDIOFOCUS_FLAG_LOCK,
                    null /* policy token */);
@@ -2519,7 +2518,7 @@ public class AudioManager {
    public void abandonAudioFocusForCall() {
        IAudioService service = getService();
        try {
            service.abandonAudioFocus(null, MediaFocusControl.IN_VOICE_COMM_FOCUS_ID,
            service.abandonAudioFocus(null, AudioSystem.IN_VOICE_COMM_FOCUS_ID,
                    null /*AudioAttributes, legacy behavior*/);
        } catch (RemoteException e) {
            Log.e(TAG, "Can't call abandonAudioFocusForCall() on AudioService:", e);
+14 −14
Original line number Diff line number Diff line
@@ -25,27 +25,27 @@ import android.text.TextUtils;
 * @hide
 */
public class AudioRoutesInfo implements Parcelable {
    static final int MAIN_SPEAKER = 0;
    static final int MAIN_HEADSET = 1<<0;
    static final int MAIN_HEADPHONES = 1<<1;
    static final int MAIN_DOCK_SPEAKERS = 1<<2;
    static final int MAIN_HDMI = 1<<3;
    static final int MAIN_USB = 1<<4;
    public static final int MAIN_SPEAKER = 0;
    public static final int MAIN_HEADSET = 1<<0;
    public static final int MAIN_HEADPHONES = 1<<1;
    public static final int MAIN_DOCK_SPEAKERS = 1<<2;
    public static final int MAIN_HDMI = 1<<3;
    public static final int MAIN_USB = 1<<4;

    CharSequence mBluetoothName;
    int mMainType = MAIN_SPEAKER;
    public CharSequence bluetoothName;
    public int mainType = MAIN_SPEAKER;

    public AudioRoutesInfo() {
    }

    public AudioRoutesInfo(AudioRoutesInfo o) {
        mBluetoothName = o.mBluetoothName;
        mMainType = o.mMainType;
        bluetoothName = o.bluetoothName;
        mainType = o.mainType;
    }

    AudioRoutesInfo(Parcel src) {
        mBluetoothName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(src);
        mMainType = src.readInt();
        bluetoothName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(src);
        mainType = src.readInt();
    }

    @Override
@@ -55,8 +55,8 @@ public class AudioRoutesInfo implements Parcelable {

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        TextUtils.writeToParcel(mBluetoothName, dest, flags);
        dest.writeInt(mMainType);
        TextUtils.writeToParcel(bluetoothName, dest, flags);
        dest.writeInt(mainType);
    }

    public static final Parcelable.Creator<AudioRoutesInfo> CREATOR
+104 −0
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@

package android.media;

import android.content.Context;
import android.content.pm.PackageManager;
import android.media.audiopolicy.AudioMix;

import java.util.ArrayList;

/* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET
@@ -65,6 +68,19 @@ public class AudioSystem
    private static final int NUM_STREAM_TYPES = 10;
    public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; }

    public static final String[] STREAM_NAMES = new String[] {
        "STREAM_VOICE_CALL",
        "STREAM_SYSTEM",
        "STREAM_RING",
        "STREAM_MUSIC",
        "STREAM_ALARM",
        "STREAM_NOTIFICATION",
        "STREAM_BLUETOOTH_SCO",
        "STREAM_SYSTEM_ENFORCED",
        "STREAM_DTMF",
        "STREAM_TTS"
    };

    /*
     * Sets the microphone mute on or off.
     *
@@ -570,5 +586,93 @@ public class AudioSystem
    public static native int getAudioHwSyncForSession(int sessionId);

    public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register);


    // Items shared with audio service

    /**
     * The delay before playing a sound. This small period exists so the user
     * can press another key (non-volume keys, too) to have it NOT be audible.
     * <p>
     * PhoneWindow will implement this part.
     */
    public static final int PLAY_SOUND_DELAY = 300;

    /**
     * Constant to identify a focus stack entry that is used to hold the focus while the phone
     * is ringing or during a call. Used by com.android.internal.telephony.CallManager when
     * entering and exiting calls.
     */
    public final static String IN_VOICE_COMM_FOCUS_ID = "AudioFocus_For_Phone_Ring_And_Calls";

    /**
     * @see AudioManager#setVibrateSetting(int, int)
     */
    public static int getValueForVibrateSetting(int existingValue, int vibrateType,
            int vibrateSetting) {

        // First clear the existing setting. Each vibrate type has two bits in
        // the value. Note '3' is '11' in binary.
        existingValue &= ~(3 << (vibrateType * 2));

        // Set into the old value
        existingValue |= (vibrateSetting & 3) << (vibrateType * 2);

        return existingValue;
    }

    public static int getDefaultStreamVolume(int streamType) {
        return DEFAULT_STREAM_VOLUME[streamType];
    }

    public static int[] DEFAULT_STREAM_VOLUME = new int[] {
        4,  // STREAM_VOICE_CALL
        7,  // STREAM_SYSTEM
        5,  // STREAM_RING
        11, // STREAM_MUSIC
        6,  // STREAM_ALARM
        5,  // STREAM_NOTIFICATION
        7,  // STREAM_BLUETOOTH_SCO
        7,  // STREAM_SYSTEM_ENFORCED
        11, // STREAM_DTMF
        11  // STREAM_TTS
    };

    public static String streamToString(int stream) {
        if (stream >= 0 && stream < STREAM_NAMES.length) return STREAM_NAMES[stream];
        if (stream == AudioManager.USE_DEFAULT_STREAM_TYPE) return "USE_DEFAULT_STREAM_TYPE";
        return "UNKNOWN_STREAM_" + stream;
    }

    /** The platform has no specific capabilities */
    public static final int PLATFORM_DEFAULT = 0;
    /** The platform is voice call capable (a phone) */
    public static final int PLATFORM_VOICE = 1;
    /** The platform is a television or a set-top box */
    public static final int PLATFORM_TELEVISION = 2;

    /**
     * Return the platform type that this is running on. One of:
     * <ul>
     * <li>{@link #PLATFORM_VOICE}</li>
     * <li>{@link #PLATFORM_TELEVISION}</li>
     * <li>{@link #PLATFORM_DEFAULT}</li>
     * </ul>
     */
    public static int getPlatformType(Context context) {
        if (context.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable)) {
            return PLATFORM_VOICE;
        } else if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
            return PLATFORM_TELEVISION;
        } else {
            return PLATFORM_DEFAULT;
        }
    }

    public static final int DEFAULT_MUTE_STREAMS_AFFECTED =
            (1 << STREAM_MUSIC) |
            (1 << STREAM_RING) |
            (1 << STREAM_NOTIFICATION) |
            (1 << STREAM_SYSTEM);
}
+12 −12
Original line number Diff line number Diff line
@@ -171,15 +171,15 @@ public class MediaRouter {
        }

        void updateAudioRoutes(AudioRoutesInfo newRoutes) {
            if (newRoutes.mMainType != mCurAudioRoutesInfo.mMainType) {
                mCurAudioRoutesInfo.mMainType = newRoutes.mMainType;
            if (newRoutes.mainType != mCurAudioRoutesInfo.mainType) {
                mCurAudioRoutesInfo.mainType = newRoutes.mainType;
                int name;
                if ((newRoutes.mMainType&AudioRoutesInfo.MAIN_HEADPHONES) != 0
                        || (newRoutes.mMainType&AudioRoutesInfo.MAIN_HEADSET) != 0) {
                if ((newRoutes.mainType&AudioRoutesInfo.MAIN_HEADPHONES) != 0
                        || (newRoutes.mainType&AudioRoutesInfo.MAIN_HEADSET) != 0) {
                    name = com.android.internal.R.string.default_audio_route_name_headphones;
                } else if ((newRoutes.mMainType&AudioRoutesInfo.MAIN_DOCK_SPEAKERS) != 0) {
                } else if ((newRoutes.mainType&AudioRoutesInfo.MAIN_DOCK_SPEAKERS) != 0) {
                    name = com.android.internal.R.string.default_audio_route_name_dock_speakers;
                } else if ((newRoutes.mMainType&AudioRoutesInfo.MAIN_HDMI) != 0) {
                } else if ((newRoutes.mainType&AudioRoutesInfo.MAIN_HDMI) != 0) {
                    name = com.android.internal.R.string.default_media_route_name_hdmi;
                } else {
                    name = com.android.internal.R.string.default_audio_route_name;
@@ -188,21 +188,21 @@ public class MediaRouter {
                dispatchRouteChanged(sStatic.mDefaultAudioVideo);
            }

            final int mainType = mCurAudioRoutesInfo.mMainType;
            final int mainType = mCurAudioRoutesInfo.mainType;

            if (!TextUtils.equals(newRoutes.mBluetoothName, mCurAudioRoutesInfo.mBluetoothName)) {
                mCurAudioRoutesInfo.mBluetoothName = newRoutes.mBluetoothName;
                if (mCurAudioRoutesInfo.mBluetoothName != null) {
            if (!TextUtils.equals(newRoutes.bluetoothName, mCurAudioRoutesInfo.bluetoothName)) {
                mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName;
                if (mCurAudioRoutesInfo.bluetoothName != null) {
                    if (sStatic.mBluetoothA2dpRoute == null) {
                        final RouteInfo info = new RouteInfo(sStatic.mSystemCategory);
                        info.mName = mCurAudioRoutesInfo.mBluetoothName;
                        info.mName = mCurAudioRoutesInfo.bluetoothName;
                        info.mDescription = sStatic.mResources.getText(
                                com.android.internal.R.string.bluetooth_a2dp_audio_route_name);
                        info.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO;
                        sStatic.mBluetoothA2dpRoute = info;
                        addRouteStatic(sStatic.mBluetoothA2dpRoute);
                    } else {
                        sStatic.mBluetoothA2dpRoute.mName = mCurAudioRoutesInfo.mBluetoothName;
                        sStatic.mBluetoothA2dpRoute.mName = mCurAudioRoutesInfo.bluetoothName;
                        dispatchRouteChanged(sStatic.mBluetoothA2dpRoute);
                    }
                } else if (sStatic.mBluetoothA2dpRoute != null) {
Loading