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

Commit 15361326 authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Prevent system crash when adjusting volume with illegal direction

The system process crashes when any of below methods is called with
illegal direction argument:
 - MediaController.adjustVolume()
 - AudioManager.adjustVolume()
 - AudioManager.adjustSuggestedStreamVolume()

This CL fixes the crash.

Bug: 65755677
Test: Added test methods to CTS. Passed the tests.
Change-Id: I2fbf0459465c75e515110e1300630bda15e4a19e
parent 99f37420
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -462,10 +462,11 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                try {
                    if (useSuggested) {
                        if (AudioSystem.isStreamActive(stream, 0)) {
                        mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream, direction,
                                flags, packageName, uid);
                            mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream,
                                    direction, flags, packageName, uid);
                        } else {
                            mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(
                                    AudioManager.USE_DEFAULT_STREAM_TYPE, direction,
@@ -475,6 +476,12 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
                        mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags,
                                packageName, uid);
                    }
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "Cannot adjust volume: direction=" + direction + ", stream="
                            + stream + ", flags=" + flags + ", packageName=" + packageName
                            + ", uid=" + uid + ", useSuggested=" + useSuggested
                            + ", previousFlagPlaySound=" + previousFlagPlaySound, e);
                }
            }
        });
    }
+4 −0
Original line number Diff line number Diff line
@@ -1363,6 +1363,10 @@ public class MediaSessionService extends SystemService implements Monitor {
                                    flags, packageName, TAG);
                        } catch (RemoteException e) {
                            Log.e(TAG, "Error adjusting default volume.", e);
                        } catch (IllegalArgumentException e) {
                            Log.e(TAG, "Cannot adjust volume: direction=" + direction
                                    + ", suggestedStream=" + suggestedStream + ", flags=" + flags,
                                    e);
                        }
                    }
                });