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

Commit 77cdcfaf authored by wilsonshih's avatar wilsonshih Committed by Wei Sheng Shih
Browse files

Only let app generate progress when client side using DecorView

Add a private flag in layout parameters to let system server know the
client side view can handle back gesture, and fallback to EBGH
intercepting for any other case.

Bug: 344030264
Bug: 344654222
Bug: 344778234
Test: atest BackAnimationControllerTest
Change-Id: I53edf80b39491ec1f79960b26af8956cd13476e0
parent 7f7d690a
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.os.Trace.TRACE_TAG_VIEW;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.DragEvent.ACTION_DRAG_LOCATION;
import static android.view.DragEvent.ACTION_DRAG_LOCATION;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_APP_PROGRESS_GENERATION_ALLOWED;
import static android.view.flags.Flags.sensitiveContentPrematureProtectionRemovedFix;
import static android.view.flags.Flags.sensitiveContentPrematureProtectionRemovedFix;
import static android.view.InputDevice.SOURCE_CLASS_NONE;
import static android.view.InputDevice.SOURCE_CLASS_NONE;
import static android.view.InsetsSource.ID_IME;
import static android.view.InsetsSource.ID_IME;
@@ -269,6 +270,7 @@ import com.android.internal.inputmethod.ImeTracing;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.os.IResultReceiver;
import com.android.internal.os.IResultReceiver;
import com.android.internal.os.SomeArgs;
import com.android.internal.os.SomeArgs;
import com.android.internal.policy.DecorView;
import com.android.internal.policy.PhoneFallbackEventHandler;
import com.android.internal.policy.PhoneFallbackEventHandler;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.view.BaseSurfaceHolder;
import com.android.internal.view.BaseSurfaceHolder;
@@ -1564,6 +1566,9 @@ public final class ViewRootImpl implements ViewParent,
                        pendingInsetsController.replayAndAttach(mInsetsController);
                        pendingInsetsController.replayAndAttach(mInsetsController);
                    }
                    }
                }
                }
                if (mView instanceof DecorView) {
                    mWindowAttributes.privateFlags |= PRIVATE_FLAG_APP_PROGRESS_GENERATION_ALLOWED;
                }
                try {
                try {
                    mOrigWindowType = mWindowAttributes.type;
                    mOrigWindowType = mWindowAttributes.type;
+6 −0
Original line number Original line Diff line number Diff line
@@ -3312,6 +3312,11 @@ public interface WindowManager extends ViewManager {
        @UnsupportedAppUsage
        @UnsupportedAppUsage
        public static final int PRIVATE_FLAG_NO_MOVE_ANIMATION = 1 << 6;
        public static final int PRIVATE_FLAG_NO_MOVE_ANIMATION = 1 << 6;


        /** Window flag: the client side view can intercept back progress, so system does not
         * need to pilfer pointers.
         * {@hide} */
        public static final int PRIVATE_FLAG_APP_PROGRESS_GENERATION_ALLOWED = 1 << 7;

        /** Window flag: a special option intended for system dialogs.  When
        /** Window flag: a special option intended for system dialogs.  When
         * this flag is set, the window will demand focus unconditionally when
         * this flag is set, the window will demand focus unconditionally when
         * it is created.
         * it is created.
@@ -3505,6 +3510,7 @@ public interface WindowManager extends ViewManager {
                SYSTEM_FLAG_SHOW_FOR_ALL_USERS,
                SYSTEM_FLAG_SHOW_FOR_ALL_USERS,
                PRIVATE_FLAG_UNRESTRICTED_GESTURE_EXCLUSION,
                PRIVATE_FLAG_UNRESTRICTED_GESTURE_EXCLUSION,
                PRIVATE_FLAG_NO_MOVE_ANIMATION,
                PRIVATE_FLAG_NO_MOVE_ANIMATION,
                PRIVATE_FLAG_APP_PROGRESS_GENERATION_ALLOWED,
                PRIVATE_FLAG_SYSTEM_ERROR,
                PRIVATE_FLAG_SYSTEM_ERROR,
                PRIVATE_FLAG_OPTIMIZE_MEASURE,
                PRIVATE_FLAG_OPTIMIZE_MEASURE,
                PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS,
                PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS,
+27 −2
Original line number Original line Diff line number Diff line
@@ -117,6 +117,8 @@ public final class BackNavigationInfo implements Parcelable {
    @NonNull
    @NonNull
    private final Rect mTouchableRegion;
    private final Rect mTouchableRegion;


    private final boolean mAppProgressGenerationAllowed;

    /**
    /**
     * Create a new {@link BackNavigationInfo} instance.
     * Create a new {@link BackNavigationInfo} instance.
     *
     *
@@ -132,7 +134,8 @@ public final class BackNavigationInfo implements Parcelable {
            boolean isAnimationCallback,
            boolean isAnimationCallback,
            @Nullable CustomAnimationInfo customAnimationInfo,
            @Nullable CustomAnimationInfo customAnimationInfo,
            int letterboxColor,
            int letterboxColor,
            @Nullable Rect touchableRegion) {
            @Nullable Rect touchableRegion,
            boolean appProgressGenerationAllowed) {
        mType = type;
        mType = type;
        mOnBackNavigationDone = onBackNavigationDone;
        mOnBackNavigationDone = onBackNavigationDone;
        mOnBackInvokedCallback = onBackInvokedCallback;
        mOnBackInvokedCallback = onBackInvokedCallback;
@@ -141,6 +144,7 @@ public final class BackNavigationInfo implements Parcelable {
        mCustomAnimationInfo = customAnimationInfo;
        mCustomAnimationInfo = customAnimationInfo;
        mLetterboxColor = letterboxColor;
        mLetterboxColor = letterboxColor;
        mTouchableRegion = new Rect(touchableRegion);
        mTouchableRegion = new Rect(touchableRegion);
        mAppProgressGenerationAllowed = appProgressGenerationAllowed;
    }
    }


    private BackNavigationInfo(@NonNull Parcel in) {
    private BackNavigationInfo(@NonNull Parcel in) {
@@ -152,6 +156,7 @@ public final class BackNavigationInfo implements Parcelable {
        mCustomAnimationInfo = in.readTypedObject(CustomAnimationInfo.CREATOR);
        mCustomAnimationInfo = in.readTypedObject(CustomAnimationInfo.CREATOR);
        mLetterboxColor = in.readInt();
        mLetterboxColor = in.readInt();
        mTouchableRegion = in.readTypedObject(Rect.CREATOR);
        mTouchableRegion = in.readTypedObject(Rect.CREATOR);
        mAppProgressGenerationAllowed = in.readBoolean();
    }
    }


    /** @hide */
    /** @hide */
@@ -165,6 +170,7 @@ public final class BackNavigationInfo implements Parcelable {
        dest.writeTypedObject(mCustomAnimationInfo, flags);
        dest.writeTypedObject(mCustomAnimationInfo, flags);
        dest.writeInt(mLetterboxColor);
        dest.writeInt(mLetterboxColor);
        dest.writeTypedObject(mTouchableRegion, flags);
        dest.writeTypedObject(mTouchableRegion, flags);
        dest.writeBoolean(mAppProgressGenerationAllowed);
    }
    }


    /**
    /**
@@ -223,6 +229,14 @@ public final class BackNavigationInfo implements Parcelable {
        return mTouchableRegion;
        return mTouchableRegion;
    }
    }


    /**
     * @return The client side view is able to intercept back progress event.
     * @hide
     */
    public boolean isAppProgressGenerationAllowed() {
        return mAppProgressGenerationAllowed;
    }

    /**
    /**
     * Callback to be called when the back preview is finished in order to notify the server that
     * Callback to be called when the back preview is finished in order to notify the server that
     * it can clean up the resources created for the animation.
     * it can clean up the resources created for the animation.
@@ -420,6 +434,7 @@ public final class BackNavigationInfo implements Parcelable {


        private int mLetterboxColor = Color.TRANSPARENT;
        private int mLetterboxColor = Color.TRANSPARENT;
        private Rect mTouchableRegion;
        private Rect mTouchableRegion;
        private boolean mAppProgressGenerationAllowed;


        /**
        /**
         * @see BackNavigationInfo#getType()
         * @see BackNavigationInfo#getType()
@@ -502,6 +517,15 @@ public final class BackNavigationInfo implements Parcelable {
            mTouchableRegion = new Rect(rect);
            mTouchableRegion = new Rect(rect);
            return this;
            return this;
        }
        }

        /**
         * @param allowed Whether client side view able to intercept back progress event.
         */
        public Builder setAppProgressAllowed(boolean allowed) {
            mAppProgressGenerationAllowed = allowed;
            return this;
        }

        /**
        /**
         * Builds and returns an instance of {@link BackNavigationInfo}
         * Builds and returns an instance of {@link BackNavigationInfo}
         */
         */
@@ -512,7 +536,8 @@ public final class BackNavigationInfo implements Parcelable {
                    mAnimationCallback,
                    mAnimationCallback,
                    mCustomAnimationInfo,
                    mCustomAnimationInfo,
                    mLetterboxColor,
                    mLetterboxColor,
                    mTouchableRegion);
                    mTouchableRegion,
                    mAppProgressGenerationAllowed);
        }
        }
    }
    }
}
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -437,7 +437,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    }
    }


    private boolean isAppProgressGenerationAllowed() {
    private boolean isAppProgressGenerationAllowed() {
        return mBackNavigationInfo.getTouchableRegion().equals(mTouchableArea);
        return mBackNavigationInfo.isAppProgressGenerationAllowed()
                && mBackNavigationInfo.getTouchableRegion().equals(mTouchableArea);
    }
    }


    /**
    /**
+2 −1
Original line number Original line Diff line number Diff line
@@ -550,7 +550,8 @@ public class BackAnimationControllerTest extends ShellTestCase {
                .setType(type)
                .setType(type)
                .setOnBackInvokedCallback(mAppCallback)
                .setOnBackInvokedCallback(mAppCallback)
                .setOnBackNavigationDone(new RemoteCallback(result))
                .setOnBackNavigationDone(new RemoteCallback(result))
                .setTouchableRegion(mTouchableRegion));
                .setTouchableRegion(mTouchableRegion)
                .setAppProgressAllowed(true));
        triggerBackGesture();
        triggerBackGesture();
        mShellExecutor.flushAll();
        mShellExecutor.flushAll();
        releaseBackGesture();
        releaseBackGesture();
Loading