diff options
| author | 2023-05-22 14:29:27 -0700 | |
|---|---|---|
| committer | 2023-05-22 14:34:55 -0700 | |
| commit | a5ad327f45c741738ecec9cf17c9c71c0ce4bbf5 (patch) | |
| tree | ca06ef03877654c64b8df0ec539de07d803c54f5 | |
| parent | b03c480d4baa2deb47c50aa27e7edc5f0e2e67b6 (diff) | |
Cache the Binder call for PlaybackState
It's rare but possible that the 2nd Binder call returns a different
value than the 1st one, fix the potential NPE by caching the return
value of MediaController#getPlaybackState
Bug: 283583998
Test: N/A
Change-Id: I9e8f456f3817f68dd98f637a1ee4a7d6d109801e
| -rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMediaController.java | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMediaController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMediaController.java index 65a12d629c5a..2590cab9ff2e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMediaController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMediaController.java @@ -252,13 +252,16 @@ public class PipMediaController { // It can be removed when min_sdk of the app is set to 31 or greater. @SuppressLint("NewApi") private List<RemoteAction> getMediaActions() { - if (mMediaController == null || mMediaController.getPlaybackState() == null) { + // Cache the PlaybackState since it's a Binder call. + final PlaybackState playbackState; + if (mMediaController == null + || (playbackState = mMediaController.getPlaybackState()) == null) { return Collections.emptyList(); } ArrayList<RemoteAction> mediaActions = new ArrayList<>(); - boolean isPlaying = mMediaController.getPlaybackState().isActive(); - long actions = mMediaController.getPlaybackState().getActions(); + boolean isPlaying = playbackState.isActive(); + long actions = playbackState.getActions(); // Prev action mPrevAction.setEnabled((actions & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0); |