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

Commit 58e0ee0d 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
parent 39e7ba0d
Loading
Loading
Loading
Loading
+22 −14
Original line number Diff line number Diff line
@@ -200,21 +200,25 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi

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

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

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

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

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

                    mSeekBarElapsedTime.setText(millisecondsToTimeString(position));
                } 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();
            }
        }