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

Commit 61f7a873 authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Android (Google) Code Review
Browse files

Merge "Fix provide wrong resources when check isOnBackInvokedCallbackEnabled" into main

parents 69821f9a 19c1ef31
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;
@@ -2231,7 +2232,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;
                        });
    }

    /**