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

Commit dc911a04 authored by Yorke Lee's avatar Yorke Lee
Browse files

DO NOT MERGE Fix crash when rotating video fragment

Due to a recent framework change,
https://googleplex-android-review.git.corp.google.com/#/c/659363/

TextureView will now crash if setSurfaceTexture is called before
the TextureView is attached to the window. Use an
OnAttachStateListener to call setSurfaceTexture only after the view
is attached to the window.

Cherry-pick from
https://us2-mirror-googleplex-android-review.googlesource.com/#/c/666312/1

Bug: 20071288

Change-Id: I8c443542db6f4a432a097326fdb49607baa55889
parent 18c0feda
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter,
     * changes.
     */
    private static class VideoCallSurface implements TextureView.SurfaceTextureListener,
            View.OnClickListener {
            View.OnClickListener, View.OnAttachStateChangeListener {
        private int mSurfaceId;
        private VideoCallPresenter mPresenter;
        private TextureView mTextureView;
@@ -159,17 +159,7 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter,
            mTextureView = view;
            mTextureView.setSurfaceTextureListener(this);
            mTextureView.setOnClickListener(this);

            final boolean areSameSurfaces =
                    Objects.equal(mSavedSurfaceTexture, mTextureView.getSurfaceTexture());
            Log.d(this, "recreateView: SavedSurfaceTexture=" + mSavedSurfaceTexture
                    + " areSameSurfaces=" + areSameSurfaces);
            if (mSavedSurfaceTexture != null && !areSameSurfaces) {
                mTextureView.setSurfaceTexture(mSavedSurfaceTexture);
                if (createSurface(mWidth, mHeight)) {
                    onSurfaceCreated();
                }
            }
            mTextureView.addOnAttachStateChangeListener(this);
            mIsDoneWithSurface = false;
        }

@@ -281,6 +271,23 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter,
            // Not Handled
        }

        @Override
        public void onViewAttachedToWindow(View v) {
            final boolean areSameSurfaces =
                    Objects.equal(mSavedSurfaceTexture, mTextureView.getSurfaceTexture());
            Log.d(this, "onViewAttachedToWindow: SavedSurfaceTexture=" + mSavedSurfaceTexture
                    + " areSameSurfaces=" + areSameSurfaces);
            if (mSavedSurfaceTexture != null && !areSameSurfaces) {
                mTextureView.setSurfaceTexture(mSavedSurfaceTexture);
                if (createSurface(mWidth, mHeight)) {
                    onSurfaceCreated();
                }
            }
        }

        @Override
        public void onViewDetachedFromWindow(View v) {}

        /**
         * Retrieves the current {@link TextureView}.
         *