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

Commit ffcfe4c5 authored by Danesh M's avatar Danesh M Committed by Gerrit Code Review
Browse files

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

Change-Id: Ibbb0607a56ab4d9246c14632eb4199558866854a
parent 9fdfca4a
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -5083,12 +5083,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_HDMI ||
                device == AudioSystem.DEVICE_OUT_HDMI_ARC) {
            connType = AudioRoutesInfo.MAIN_HDMI;
@@ -5121,6 +5123,17 @@ public class AudioService extends IAudioService.Stub {
        }
    }

    private void startMusicPlayer() {
        boolean launchPlayer = CMSettings.System.getIntForUser(mContext.getContentResolver(),
                CMSettings.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 address,
            String deviceName, String caller) {
        if (DEBUG_DEVICES) {