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

Commit a6c5defc authored by Danny Baumann's avatar Danny Baumann
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 baf0eefd
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -4144,13 +4144,19 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                    adjustCurrentStreamVolume();
                    // TODO: Cap volume at safe levels

                    boolean launchPlayer = Settings.System.getInt(context.getContentResolver(),
                            Settings.System.HEADSET_CONNECT_PLAYER, 0) != 0;
                    boolean launchPlayer = Settings.System.getIntForUser(
                            context.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);
                        try {
                            context.startActivity(playerIntent);
                        } catch (ActivityNotFoundException e) {
                            Log.w(TAG, "No music player found to start after headset connection");
                        }
                    }
                } else {
                    // Headset disconnected