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

Commit 8e466465 authored by Danesh M's avatar Danesh M Committed by Steve Kondik
Browse files

AudioService: launch default music player on headset connect [2/2]

Change-Id: Ibbb0607a56ab4d9246c14632eb4199558866854a
parent a4b7dc7c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3770,6 +3770,12 @@ public final class Settings {
         */
        public static final String NAVIGATION_BAR_MENU_ARROW_KEYS = "navigation_bar_menu_arrow_keys";

        /**
         * Whether or not to launch default music player when headset is connected
         * @hide
         */
        public static final String HEADSET_CONNECT_PLAYER = "headset_connect_player";

    }

    /**
+14 −0
Original line number Diff line number Diff line
@@ -4706,12 +4706,14 @@ public class AudioService extends IAudioService.Stub {
            connType = AudioRoutesInfo.MAIN_HEADSET;
            intent.setAction(Intent.ACTION_HEADSET_PLUG);
            intent.putExtra("microphone", 1);
            startMusicPlayer();
        } else if (device == AudioSystem.DEVICE_OUT_WIRED_HEADPHONE ||
                   device == AudioSystem.DEVICE_OUT_LINE) {
            /*do apps care about line-out vs headphones?*/
            connType = AudioRoutesInfo.MAIN_HEADPHONES;
            intent.setAction(Intent.ACTION_HEADSET_PLUG);
            intent.putExtra("microphone", 0);
            startMusicPlayer();
        } else if (device == AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET) {
            connType = AudioRoutesInfo.MAIN_DOCK_SPEAKERS;
            intent.setAction(AudioManager.ACTION_ANALOG_AUDIO_DOCK_PLUG);
@@ -4747,6 +4749,18 @@ public class AudioService extends IAudioService.Stub {
        }
    }

    private void startMusicPlayer()
    {
        boolean launchPlayer = Settings.System.getIntForUser(mContext.getContentResolver(),
                Settings.System.HEADSET_CONNECT_PLAYER, 0, UserHandle.USER_CURRENT) != 0;
        if (launchPlayer) {
            Intent playerIntent = new Intent(Intent.ACTION_MAIN);
            playerIntent.addCategory(Intent.CATEGORY_APP_MUSIC);
            playerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(playerIntent);
        }
    }

    private void onSetWiredDeviceConnectionState(int device, int state, String name)
    {
        synchronized (mConnectedDevices) {