1 /* 2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.policy; 18 19 import static android.content.pm.ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED; 20 import static android.content.pm.ActivityInfo.OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS; 21 22 import android.annotation.NonNull; 23 import android.content.pm.ActivityInfo; 24 import android.window.DesktopModeFlags; 25 26 /** 27 * Utility functions for app compat in desktop windowing used by both window manager and System UI. 28 * @hide 29 */ 30 public final class DesktopModeCompatUtils { 31 32 /** 33 * Whether the caption insets should be excluded from configuration for system to handle. 34 * The caller should ensure the activity is in or entering desktop view. 35 * 36 * <p> The treatment is enabled when all the of the following is true: 37 * <li> Any flags to forcibly consume caption insets are enabled. 38 * <li> Top activity have configuration coupled with insets. 39 * <li> Task is not resizeable or per-app override 40 * {@link ActivityInfo#OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS} is enabled. 41 */ shouldExcludeCaptionFromAppBounds(@onNull ActivityInfo info, boolean isResizeable, boolean optOutEdgeToEdge)42 public static boolean shouldExcludeCaptionFromAppBounds(@NonNull ActivityInfo info, 43 boolean isResizeable, boolean optOutEdgeToEdge) { 44 return DesktopModeFlags.EXCLUDE_CAPTION_FROM_APP_BOUNDS.isTrue() 45 && isAnyForceConsumptionFlagsEnabled() 46 && !isConfigurationDecoupled(info, optOutEdgeToEdge) 47 && (!isResizeable 48 || info.isChangeEnabled(OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS)); 49 } 50 isConfigurationDecoupled(@onNull ActivityInfo info, boolean optOutEdgeToEdge)51 private static boolean isConfigurationDecoupled(@NonNull ActivityInfo info, 52 boolean optOutEdgeToEdge) { 53 return info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED) && !optOutEdgeToEdge; 54 } 55 isAnyForceConsumptionFlagsEnabled()56 private static boolean isAnyForceConsumptionFlagsEnabled() { 57 return DesktopModeFlags.ENABLE_CAPTION_COMPAT_INSET_FORCE_CONSUMPTION_ALWAYS.isTrue() 58 || DesktopModeFlags.ENABLE_CAPTION_COMPAT_INSET_FORCE_CONSUMPTION.isTrue(); 59 } 60 } 61