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

Commit 4e937fa7 authored by Beth Thibodeau's avatar Beth Thibodeau
Browse files

Fix null pointer exceptions

Possible NPE issue that was seen in some bug reports where the playback state
or metadata was null after closing an app. Also added useful debug messages

Test: manual
Fixes: 129847573
Fixes: 129973823
Change-Id: I76d9f465072831dfe3457751a39e82bdd9b049b7
(cherry picked from commit 58e0ee0d)
parent f5096afd
Loading
Loading
Loading
Loading
+22 −14
Original line number Original line Diff line number Diff line
@@ -200,21 +200,25 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi


    private boolean canSeekMedia() {
    private boolean canSeekMedia() {
        if (mMediaController == null || mMediaController.getPlaybackState() == null) {
        if (mMediaController == null || mMediaController.getPlaybackState() == null) {
            Log.d(TAG, "Cannot seek media because the controller is invalid");
            return false;
            return false;
        }
        }


        long actions = mMediaController.getPlaybackState().getActions();
        long actions = mMediaController.getPlaybackState().getActions();
        Log.d(TAG, "Playback state actions are " + actions);
        return (actions == 0 || (actions & PlaybackState.ACTION_SEEK_TO) != 0);
        return (actions == 0 || (actions & PlaybackState.ACTION_SEEK_TO) != 0);
    }
    }


    protected final Runnable mUpdatePlaybackUi = new Runnable() {
    protected final Runnable mUpdatePlaybackUi = new Runnable() {
        @Override
        @Override
        public void run() {
        public void run() {
            if (mMediaController != null && mMediaController.getMetadata() != null
            if (mMediaController != null && mSeekBar != null) {
                    && mSeekBar != null) {
                MediaMetadata metadata = mMediaController.getMetadata();
                long position = mMediaController.getPlaybackState().getPosition();
                PlaybackState playbackState = mMediaController.getPlaybackState();
                long duration = mMediaController.getMetadata().getLong(

                        MediaMetadata.METADATA_KEY_DURATION);
                if (metadata != null && playbackState != null) {
                    long position = playbackState.getPosition();
                    long duration = metadata.getLong(MediaMetadata.METADATA_KEY_DURATION);


                    if (mDuration != duration) {
                    if (mDuration != duration) {
                        mDuration = duration;
                        mDuration = duration;
@@ -225,7 +229,11 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi


                    mSeekBarElapsedTime.setText(millisecondsToTimeString(position));
                    mSeekBarElapsedTime.setText(millisecondsToTimeString(position));
                } else {
                } else {
                // We no longer have a media session / notification
                    Log.d(TAG, "Controller missing data " + metadata + " " + playbackState);
                    clearTimer();
                }
            } else {
                Log.d(TAG, "No longer have a valid media controller");
                clearTimer();
                clearTimer();
            }
            }
        }
        }