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

Commit 19c1ef31 authored by wilsonshih's avatar wilsonshih
Browse files

Fix provide wrong resources when check isOnBackInvokedCallbackEnabled

Provide app context to read the windowSwipeToDismiss.

Bug: 322138503
Test: enable PREDICTIVE_BACK_FALLBACK_WINDOW_ATTRIBUTE, verify activity
can load windowSwipeToDismiss safely.

Change-Id: I07df7cc3cbc0fc9b1a3fc42bb767d7c7e4e84ef2
parent 456d99d8
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -442,8 +442,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {

        return WindowOnBackInvokedDispatcher
                .isOnBackInvokedCallbackEnabled(activityInfo, applicationInfo,
                        () -> originalContext.obtainStyledAttributes(
                                new int[] {android.R.attr.windowSwipeToDismiss}), true);
                        () -> originalContext);
    }

    @Override
@@ -501,7 +500,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
     */
    public static boolean isOnBackInvokedCallbackEnabled(@Nullable ActivityInfo activityInfo,
            @NonNull ApplicationInfo applicationInfo,
            @NonNull Supplier<TypedArray> windowAttrSupplier, boolean recycleTypedArray) {
            @NonNull Supplier<Context> contextSupplier) {
        // new back is enabled if the feature flag is enabled AND the app does not explicitly
        // request legacy back.
        if (!ENABLE_PREDICTIVE_BACK) {
@@ -547,15 +546,15 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
            //    setTrigger(true)
            // Use the original context to resolve the styled attribute so that they stay
            // true to the window.
            TypedArray windowAttr = windowAttrSupplier.get();
            final Context context = contextSupplier.get();
            boolean windowSwipeToDismiss = true;
            if (windowAttr != null) {
                if (windowAttr.getIndexCount() > 0) {
                    windowSwipeToDismiss = windowAttr.getBoolean(0, true);
                }
                if (recycleTypedArray) {
                    windowAttr.recycle();
            if (context != null) {
                final TypedArray array = context.obtainStyledAttributes(
                            new int[]{android.R.attr.windowSwipeToDismiss});
                if (array.getIndexCount() > 0) {
                    windowSwipeToDismiss = array.getBoolean(0, true);
                }
                array.recycle();
            }

            if (DEBUG) {
+12 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import static android.app.WindowConfiguration.activityTypeToString;
import static android.app.admin.DevicePolicyResources.Drawables.Source.PROFILE_SWITCH_ANIMATION;
import static android.app.admin.DevicePolicyResources.Drawables.Style.OUTLINE;
import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON;
import static android.content.Context.CONTEXT_RESTRICTED;
import static android.content.Intent.ACTION_MAIN;
import static android.content.Intent.CATEGORY_HOME;
import static android.content.Intent.CATEGORY_LAUNCHER;
@@ -2227,7 +2228,17 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

        mOptInOnBackInvoked = WindowOnBackInvokedDispatcher
                .isOnBackInvokedCallbackEnabled(info, info.applicationInfo,
                        () -> ent != null ? ent.array : null, false);
                        () -> {
                            Context appContext = null;
                            try {
                                appContext = mAtmService.mContext.createPackageContextAsUser(
                                        info.packageName, CONTEXT_RESTRICTED,
                                        UserHandle.of(mUserId));
                                appContext.setTheme(theme);
                            } catch (PackageManager.NameNotFoundException ignore) {
                            }
                            return appContext;
                        });
    }

    /**