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

Commit 7df2d819 authored by Danny Baumann's avatar Danny Baumann Committed by Ricardo Cerqueira
Browse files

Fix up 'launch player on headset connection' option.

- don't crash system_server if no music player can be found
- use the active user's setting instead of the owner's setting

Change-Id: I38a07fe5c8c3d67ececd0768e1fcc01a6cf7fa5a
parent 0520e68f
Loading
Loading
Loading
Loading
+9 −3
Original line number Original line Diff line number Diff line
@@ -4161,13 +4161,19 @@ public class AudioService extends IAudioService.Stub {
                    adjustCurrentStreamVolume();
                    adjustCurrentStreamVolume();
                    // TODO: Cap volume at safe levels
                    // TODO: Cap volume at safe levels


                    boolean launchPlayer = Settings.System.getInt(context.getContentResolver(),
                    boolean launchPlayer = Settings.System.getIntForUser(
                            Settings.System.HEADSET_CONNECT_PLAYER, 0) != 0;
                            context.getContentResolver(),
                            Settings.System.HEADSET_CONNECT_PLAYER,
                            0, UserHandle.USER_CURRENT) != 0;
                    if (launchPlayer) {
                    if (launchPlayer) {
                        Intent playerIntent = new Intent(Intent.ACTION_MAIN);
                        Intent playerIntent = new Intent(Intent.ACTION_MAIN);
                        playerIntent.addCategory(Intent.CATEGORY_APP_MUSIC);
                        playerIntent.addCategory(Intent.CATEGORY_APP_MUSIC);
                        playerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        playerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        try {
                            context.startActivity(playerIntent);
                            context.startActivity(playerIntent);
                        } catch (ActivityNotFoundException e) {
                            Log.w(TAG, "No music player found to start after headset connection");
                        }
                    }
                    }
                } else {
                } else {
                    // Headset disconnected
                    // Headset disconnected