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

Commit fc97e533 authored by Saumya Prakash's avatar Saumya Prakash Committed by Android (Google) Code Review
Browse files

Merge "Check that onAttach() is called before onResume() to prevent NPE." into main

parents 8fa129e9 ec514d05
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.quickstep.interaction.GestureSandboxActivity.KEY_USE_T
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Insets;
@@ -86,6 +87,8 @@ abstract class TutorialFragment extends GestureSandboxFragment implements OnTouc
    private boolean mIsFoldable;
    private boolean mOnAttachedToWindowPendingCreate;

    @Nullable private Runnable mOnAttachedOnGlobalLayoutCallback = null;

    public static TutorialFragment newInstance(
            TutorialType tutorialType, boolean gestureComplete, boolean fromTutorialMenu) {
        TutorialFragment fragment = getFragmentForTutorialType(tutorialType, fromTutorialMenu);
@@ -349,13 +352,27 @@ abstract class TutorialFragment extends GestureSandboxFragment implements OnTouc
                    new ViewTreeObserver.OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            changeController(mTutorialType);
                            runOnAttached(() -> changeController(mTutorialType));
                            mRootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    });
        }
    }

    private void runOnAttached(Runnable callback) {
        mOnAttachedOnGlobalLayoutCallback = callback;
        if (getContext() != null) {
            onAttached();
        }
    }

    private void onAttached() {
        if (mOnAttachedOnGlobalLayoutCallback != null) {
            mOnAttachedOnGlobalLayoutCallback.run();
            mOnAttachedOnGlobalLayoutCallback = null;
        }
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (mTutorialController != null && !isGestureComplete()) {
@@ -377,6 +394,12 @@ abstract class TutorialFragment extends GestureSandboxFragment implements OnTouc
                | mNavBarGestureHandler.onInterceptTouch(motionEvent);
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        onAttached();
    }

    @Override
    void onAttachedToWindow() {
        if (mEdgeBackGestureHandler == null) {