diff options
author | Marie Janssen <jamuraa@google.com> | 2016-07-12 07:53:54 -0700 |
---|---|---|
committer | Marie Janssen <jamuraa@google.com> | 2016-07-15 10:57:59 -0700 |
commit | 9b04e432dee914b685ea30a310d0626d85689f4a (patch) | |
tree | bccf8c42094c507121a873de0b5203e871d175c2 /src | |
parent | 2be5946285b5956fc752f4e1fbbaf9a3f87e20e5 (diff) | |
download | android_packages_apps_Bluetooth-9b04e432dee914b685ea30a310d0626d85689f4a.tar.gz android_packages_apps_Bluetooth-9b04e432dee914b685ea30a310d0626d85689f4a.tar.bz2 android_packages_apps_Bluetooth-9b04e432dee914b685ea30a310d0626d85689f4a.zip |
Fix AVRCP crash, position and state tracking
When the MediaController goes away (media stops) a NPE would cause a
crash.
Initialize the position so that an initial notification gets sent
when position is requested, send it when the music is paused, and
send play state whenever the app sends us a play state update.
Bug: 30039744
Bug: 29416450
Change-Id: I44397b3dc40d328fa75a2c15875fad298a5090dd
(cherry picked from commit 84d3f084d4d1a65eb7a481e5a7fe4a6ac827be7b)
Diffstat (limited to 'src')
-rwxr-xr-x | src/com/android/bluetooth/avrcp/Avrcp.java | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/com/android/bluetooth/avrcp/Avrcp.java b/src/com/android/bluetooth/avrcp/Avrcp.java index e864c16d6..6ce712321 100755 --- a/src/com/android/bluetooth/avrcp/Avrcp.java +++ b/src/com/android/bluetooth/avrcp/Avrcp.java @@ -163,6 +163,8 @@ public final class Avrcp { mSongLengthMs = 0L; mPlaybackIntervalMs = 0L; mPlayPosChangedNT = NOTIFICATION_TYPE_CHANGED; + mNextPosMs = -1; + mPrevPosMs = -1; mFeatures = 0; mRemoteVolume = -1; mInitialRemoteVolume = -1; @@ -267,12 +269,10 @@ public final class Avrcp { mMediaController = controller; if (mMediaController == null) { updateMetadata(null); - updatePlaybackState(null); return; } mMediaController.registerCallback(mMediaControllerCb, mHandler); updateMetadata(mMediaController.getMetadata()); - updatePlaybackState(mMediaController.getPlaybackState()); } /** Handles Avrcp messages. */ @@ -641,7 +641,6 @@ public final class Avrcp { PlaybackState.PLAYBACK_POSITION_UNKNOWN, 0.0f).build(); } - int oldPlayStatus = convertPlayStateToPlayStatus(mCurrentPlayState); int newPlayStatus = convertPlayStateToPlayStatus(state); mCurrentPlayState = state; @@ -649,7 +648,7 @@ public final class Avrcp { sendPlayPosNotificationRsp(false); - if ((mPlayStatusChangedNT == NOTIFICATION_TYPE_INTERIM) && (oldPlayStatus != newPlayStatus)) { + if (mPlayStatusChangedNT == NOTIFICATION_TYPE_INTERIM) { mPlayStatusChangedNT = NOTIFICATION_TYPE_CHANGED; registerNotificationRspPlayStatusNative(mPlayStatusChangedNT, newPlayStatus); } @@ -779,8 +778,13 @@ public final class Avrcp { Log.v(TAG, "MediaAttributes Changed to " + mMediaAttributes.toString()); mTrackNumber++; - // Update the play state, which sends a notification if needed. - updatePlaybackState(mMediaController.getPlaybackState()); + // Update the play state, which sends play state and play position + // notifications if needed. + if (mMediaController != null) { + updatePlaybackState(mMediaController.getPlaybackState()); + } else { + updatePlaybackState(null); + } if (mTrackChangedNT == NOTIFICATION_TYPE_INTERIM) { mTrackChangedNT = NOTIFICATION_TYPE_CHANGED; @@ -903,7 +907,7 @@ public final class Avrcp { return SystemClock.elapsedRealtime() - mLastStateUpdate + mCurrentPlayState.getPosition(); } - return -1L; + return mCurrentPlayState.getPosition(); } private int convertPlayStateToPlayStatus(PlaybackState state) { |