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
(cherry picked from commit 153613263e5afbfa8f73717b5e903b4f2a6f7298)
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index b77ed91..b9a2d18 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -1363,6 +1363,10 @@
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);
}
}
});