1 /* 2 * Copyright (C) 2023 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 android.app; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * Stores App Compat information about a particular Task. 26 * @hide 27 */ 28 public class AppCompatTaskInfo implements Parcelable { 29 /** 30 * Whether the direct top activity is eligible for letterbox education. 31 */ 32 public boolean topActivityEligibleForLetterboxEducation; 33 34 /** 35 * Whether the letterbox education is enabled 36 */ 37 public boolean isLetterboxEducationEnabled; 38 39 /** 40 * Whether the direct top activity is in size compat mode on foreground. 41 */ 42 public boolean topActivityInSizeCompat; 43 44 /** 45 * Whether the double tap is enabled. 46 */ 47 public boolean isLetterboxDoubleTapEnabled; 48 49 /** 50 * Whether the user aspect ratio settings button is enabled. 51 */ 52 public boolean topActivityEligibleForUserAspectRatioButton; 53 54 /** 55 * Whether the user has forced the activity to be fullscreen through the user aspect ratio 56 * settings. 57 */ 58 public boolean isUserFullscreenOverrideEnabled; 59 60 /** 61 * Whether the system has forced the activity to be fullscreen 62 */ 63 public boolean isSystemFullscreenOverrideEnabled; 64 65 /** 66 * Hint about the letterbox state of the top activity. 67 */ 68 public boolean topActivityBoundsLetterboxed; 69 70 /** 71 * Whether the update comes from a letterbox double-tap action from the user or not. 72 */ 73 public boolean isFromLetterboxDoubleTap; 74 75 /** 76 * If {@link isLetterboxDoubleTapEnabled} it contains the current letterbox vertical position or 77 * {@link TaskInfo.PROPERTY_VALUE_UNSET} otherwise. 78 */ 79 public int topActivityLetterboxVerticalPosition; 80 81 /** 82 * If {@link isLetterboxDoubleTapEnabled} it contains the current letterbox vertical position or 83 * {@link TaskInfo.PROPERTY_VALUE_UNSET} otherwise. 84 */ 85 public int topActivityLetterboxHorizontalPosition; 86 87 /** 88 * If {@link isLetterboxDoubleTapEnabled} it contains the current width of the letterboxed 89 * activity or {@link TaskInfo.PROPERTY_VALUE_UNSET} otherwise. 90 */ 91 public int topActivityLetterboxWidth; 92 93 /** 94 * If {@link isLetterboxDoubleTapEnabled} it contains the current height of the letterboxed 95 * activity or {@link TaskInfo.PROPERTY_VALUE_UNSET} otherwise. 96 */ 97 public int topActivityLetterboxHeight; 98 99 /** 100 * Stores camera-related app compat information about a particular Task. 101 */ 102 public CameraCompatTaskInfo cameraCompatTaskInfo = CameraCompatTaskInfo.create(); 103 AppCompatTaskInfo()104 private AppCompatTaskInfo() { 105 // Do nothing 106 } 107 108 @NonNull create()109 static AppCompatTaskInfo create() { 110 return new AppCompatTaskInfo(); 111 } 112 AppCompatTaskInfo(Parcel source)113 private AppCompatTaskInfo(Parcel source) { 114 readFromParcel(source); 115 } 116 117 @Override describeContents()118 public int describeContents() { 119 return 0; 120 } 121 122 public static final Creator<AppCompatTaskInfo> CREATOR = 123 new Creator<>() { 124 @Override 125 public AppCompatTaskInfo createFromParcel(Parcel in) { 126 return new AppCompatTaskInfo(in); 127 } 128 129 @Override 130 public AppCompatTaskInfo[] newArray(int size) { 131 return new AppCompatTaskInfo[size]; 132 } 133 }; 134 135 /** 136 * @return {@value true} if the task has some compat ui. 137 */ hasCompatUI()138 public boolean hasCompatUI() { 139 return cameraCompatTaskInfo.hasCameraCompatUI() || topActivityInSizeCompat 140 || topActivityEligibleForLetterboxEducation 141 || isLetterboxDoubleTapEnabled 142 || topActivityEligibleForUserAspectRatioButton; 143 } 144 145 /** 146 * @return {@value true} if top activity is pillarboxed. 147 */ isTopActivityPillarboxed()148 public boolean isTopActivityPillarboxed() { 149 return topActivityLetterboxWidth < topActivityLetterboxHeight; 150 } 151 152 /** 153 * @return {@code true} if the app compat parameters that are important for task organizers 154 * are equal. 155 */ equalsForTaskOrganizer(@ullable AppCompatTaskInfo that)156 public boolean equalsForTaskOrganizer(@Nullable AppCompatTaskInfo that) { 157 if (that == null) { 158 return false; 159 } 160 return isFromLetterboxDoubleTap == that.isFromLetterboxDoubleTap 161 && topActivityEligibleForUserAspectRatioButton 162 == that.topActivityEligibleForUserAspectRatioButton 163 && topActivityLetterboxVerticalPosition == that.topActivityLetterboxVerticalPosition 164 && topActivityLetterboxWidth == that.topActivityLetterboxWidth 165 && topActivityLetterboxHeight == that.topActivityLetterboxHeight 166 && topActivityLetterboxHorizontalPosition 167 == that.topActivityLetterboxHorizontalPosition 168 && isUserFullscreenOverrideEnabled == that.isUserFullscreenOverrideEnabled 169 && isSystemFullscreenOverrideEnabled == that.isSystemFullscreenOverrideEnabled 170 && cameraCompatTaskInfo.equalsForTaskOrganizer(that.cameraCompatTaskInfo); 171 } 172 173 /** 174 * @return {@code true} if parameters that are important for size compat have changed. 175 */ equalsForCompatUi(@ullable AppCompatTaskInfo that)176 public boolean equalsForCompatUi(@Nullable AppCompatTaskInfo that) { 177 if (that == null) { 178 return false; 179 } 180 return topActivityInSizeCompat == that.topActivityInSizeCompat 181 && isFromLetterboxDoubleTap == that.isFromLetterboxDoubleTap 182 && topActivityEligibleForUserAspectRatioButton 183 == that.topActivityEligibleForUserAspectRatioButton 184 && topActivityEligibleForLetterboxEducation 185 == that.topActivityEligibleForLetterboxEducation 186 && isLetterboxEducationEnabled == that.isLetterboxEducationEnabled 187 && topActivityLetterboxVerticalPosition == that.topActivityLetterboxVerticalPosition 188 && topActivityLetterboxHorizontalPosition 189 == that.topActivityLetterboxHorizontalPosition 190 && topActivityLetterboxWidth == that.topActivityLetterboxWidth 191 && topActivityLetterboxHeight == that.topActivityLetterboxHeight 192 && isUserFullscreenOverrideEnabled == that.isUserFullscreenOverrideEnabled 193 && isSystemFullscreenOverrideEnabled == that.isSystemFullscreenOverrideEnabled 194 && cameraCompatTaskInfo.equalsForCompatUi(that.cameraCompatTaskInfo); 195 } 196 197 /** 198 * Reads the AppCompatTaskInfo from a parcel. 199 */ readFromParcel(Parcel source)200 void readFromParcel(Parcel source) { 201 isLetterboxEducationEnabled = source.readBoolean(); 202 topActivityInSizeCompat = source.readBoolean(); 203 topActivityEligibleForLetterboxEducation = source.readBoolean(); 204 isLetterboxDoubleTapEnabled = source.readBoolean(); 205 topActivityEligibleForUserAspectRatioButton = source.readBoolean(); 206 topActivityBoundsLetterboxed = source.readBoolean(); 207 isFromLetterboxDoubleTap = source.readBoolean(); 208 topActivityLetterboxVerticalPosition = source.readInt(); 209 topActivityLetterboxHorizontalPosition = source.readInt(); 210 topActivityLetterboxWidth = source.readInt(); 211 topActivityLetterboxHeight = source.readInt(); 212 isUserFullscreenOverrideEnabled = source.readBoolean(); 213 isSystemFullscreenOverrideEnabled = source.readBoolean(); 214 cameraCompatTaskInfo = source.readTypedObject(CameraCompatTaskInfo.CREATOR); 215 } 216 217 /** 218 * Writes the AppCompatTaskInfo to a parcel. 219 */ 220 @Override writeToParcel(Parcel dest, int flags)221 public void writeToParcel(Parcel dest, int flags) { 222 dest.writeBoolean(isLetterboxEducationEnabled); 223 dest.writeBoolean(topActivityInSizeCompat); 224 dest.writeBoolean(topActivityEligibleForLetterboxEducation); 225 dest.writeBoolean(isLetterboxDoubleTapEnabled); 226 dest.writeBoolean(topActivityEligibleForUserAspectRatioButton); 227 dest.writeBoolean(topActivityBoundsLetterboxed); 228 dest.writeBoolean(isFromLetterboxDoubleTap); 229 dest.writeInt(topActivityLetterboxVerticalPosition); 230 dest.writeInt(topActivityLetterboxHorizontalPosition); 231 dest.writeInt(topActivityLetterboxWidth); 232 dest.writeInt(topActivityLetterboxHeight); 233 dest.writeBoolean(isUserFullscreenOverrideEnabled); 234 dest.writeBoolean(isSystemFullscreenOverrideEnabled); 235 dest.writeTypedObject(cameraCompatTaskInfo, flags); 236 } 237 238 @Override toString()239 public String toString() { 240 return "AppCompatTaskInfo { topActivityInSizeCompat=" + topActivityInSizeCompat 241 + " topActivityEligibleForLetterboxEducation= " 242 + topActivityEligibleForLetterboxEducation 243 + "isLetterboxEducationEnabled= " + isLetterboxEducationEnabled 244 + " isLetterboxDoubleTapEnabled= " + isLetterboxDoubleTapEnabled 245 + " topActivityEligibleForUserAspectRatioButton= " 246 + topActivityEligibleForUserAspectRatioButton 247 + " topActivityBoundsLetterboxed= " + topActivityBoundsLetterboxed 248 + " isFromLetterboxDoubleTap= " + isFromLetterboxDoubleTap 249 + " topActivityLetterboxVerticalPosition= " + topActivityLetterboxVerticalPosition 250 + " topActivityLetterboxHorizontalPosition= " 251 + topActivityLetterboxHorizontalPosition 252 + " topActivityLetterboxWidth=" + topActivityLetterboxWidth 253 + " topActivityLetterboxHeight=" + topActivityLetterboxHeight 254 + " isUserFullscreenOverrideEnabled=" + isUserFullscreenOverrideEnabled 255 + " isSystemFullscreenOverrideEnabled=" + isSystemFullscreenOverrideEnabled 256 + " cameraCompatTaskInfo=" + cameraCompatTaskInfo.toString() 257 + "}"; 258 } 259 } 260