| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import static android.app.ActivityThread.isSystem; |
| 20 |
import static android.app.WindowConfigurationProto.ACTIVITY_TYPE; |
| 21 |
import static android.app.WindowConfigurationProto.APP_BOUNDS; |
| 22 |
import static android.app.WindowConfigurationProto.BOUNDS; |
| 23 |
import static android.app.WindowConfigurationProto.MAX_BOUNDS; |
| 24 |
import static android.app.WindowConfigurationProto.WINDOWING_MODE; |
| 25 |
import static android.view.Surface.rotationToString; |
| 26 |
|
| 27 |
import android.annotation.IntDef; |
| 28 |
import android.annotation.NonNull; |
| 29 |
import android.annotation.Nullable; |
| 30 |
import android.annotation.TestApi; |
| 31 |
import android.compat.annotation.UnsupportedAppUsage; |
| 32 |
import android.content.res.Configuration; |
| 33 |
import android.graphics.Rect; |
| 34 |
import android.os.Parcel; |
| 35 |
import android.os.Parcelable; |
| 36 |
import android.util.proto.ProtoInputStream; |
| 37 |
import android.util.proto.ProtoOutputStream; |
| 38 |
import android.util.proto.WireTypeMismatchException; |
| 39 |
import android.view.DisplayInfo; |
| 40 |
import android.view.Surface; |
| 41 |
import android.view.WindowManager; |
| 42 |
|
| 43 |
import java.io.IOException; |
| 44 |
import java.util.Objects; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
@TestApi |
| 54 |
public class WindowConfiguration implements Parcelable, Comparable<WindowConfiguration> { |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
private final Rect mBounds = new Rect(); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
private Rect mAppBounds; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
private final Rect mMaxBounds = new Rect(); |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
@Surface.Rotation |
| 82 |
private int mDisplayRotation = ROTATION_UNDEFINED; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
private int mRotation = ROTATION_UNDEFINED; |
| 91 |
|
| 92 |
|
| 93 |
public static final int ROTATION_UNDEFINED = -1; |
| 94 |
|
| 95 |
|
| 96 |
private @WindowingMode int mWindowingMode; |
| 97 |
|
| 98 |
|
| 99 |
private @WindowingMode int mDisplayWindowingMode; |
| 100 |
|
| 101 |
|
| 102 |
public static final int WINDOWING_MODE_UNDEFINED = 0; |
| 103 |
|
| 104 |
public static final int WINDOWING_MODE_FULLSCREEN = 1; |
| 105 |
|
| 106 |
public static final int WINDOWING_MODE_PINNED = 2; |
| 107 |
|
| 108 |
|
| 109 |
public static final int WINDOWING_MODE_FREEFORM = 5; |
| 110 |
|
| 111 |
public static final int WINDOWING_MODE_MULTI_WINDOW = 6; |
| 112 |
|
| 113 |
|
| 114 |
@IntDef(prefix = { "WINDOWING_MODE_" }, value = { |
| 115 |
WINDOWING_MODE_UNDEFINED, |
| 116 |
WINDOWING_MODE_FULLSCREEN, |
| 117 |
WINDOWING_MODE_MULTI_WINDOW, |
| 118 |
WINDOWING_MODE_PINNED, |
| 119 |
WINDOWING_MODE_FREEFORM, |
| 120 |
}) |
| 121 |
public @interface WindowingMode {} |
| 122 |
|
| 123 |
|
| 124 |
private @ActivityType int mActivityType; |
| 125 |
|
| 126 |
|
| 127 |
public static final int ACTIVITY_TYPE_UNDEFINED = 0; |
| 128 |
|
| 129 |
public static final int ACTIVITY_TYPE_STANDARD = 1; |
| 130 |
|
| 131 |
public static final int ACTIVITY_TYPE_HOME = 2; |
| 132 |
|
| 133 |
public static final int ACTIVITY_TYPE_RECENTS = 3; |
| 134 |
|
| 135 |
public static final int ACTIVITY_TYPE_ASSISTANT = 4; |
| 136 |
|
| 137 |
public static final int ACTIVITY_TYPE_DREAM = 5; |
| 138 |
|
| 139 |
|
| 140 |
@IntDef(prefix = { "ACTIVITY_TYPE_" }, value = { |
| 141 |
ACTIVITY_TYPE_UNDEFINED, |
| 142 |
ACTIVITY_TYPE_STANDARD, |
| 143 |
ACTIVITY_TYPE_HOME, |
| 144 |
ACTIVITY_TYPE_RECENTS, |
| 145 |
ACTIVITY_TYPE_ASSISTANT, |
| 146 |
ACTIVITY_TYPE_DREAM, |
| 147 |
}) |
| 148 |
public @interface ActivityType {} |
| 149 |
|
| 150 |
|
| 151 |
private @AlwaysOnTop int mAlwaysOnTop; |
| 152 |
|
| 153 |
|
| 154 |
private static final int ALWAYS_ON_TOP_UNDEFINED = 0; |
| 155 |
|
| 156 |
private static final int ALWAYS_ON_TOP_ON = 1; |
| 157 |
|
| 158 |
private static final int ALWAYS_ON_TOP_OFF = 2; |
| 159 |
|
| 160 |
|
| 161 |
@IntDef(prefix = { "ALWAYS_ON_TOP_" }, value = { |
| 162 |
ALWAYS_ON_TOP_UNDEFINED, |
| 163 |
ALWAYS_ON_TOP_ON, |
| 164 |
ALWAYS_ON_TOP_OFF, |
| 165 |
}) |
| 166 |
private @interface AlwaysOnTop {} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public static final int WINDOW_CONFIG_BOUNDS = 1 << 0; |
| 171 |
|
| 172 |
|
| 173 |
public static final int WINDOW_CONFIG_APP_BOUNDS = 1 << 1; |
| 174 |
|
| 175 |
|
| 176 |
public static final int WINDOW_CONFIG_MAX_BOUNDS = 1 << 2; |
| 177 |
|
| 178 |
|
| 179 |
public static final int WINDOW_CONFIG_WINDOWING_MODE = 1 << 3; |
| 180 |
|
| 181 |
|
| 182 |
public static final int WINDOW_CONFIG_ACTIVITY_TYPE = 1 << 4; |
| 183 |
|
| 184 |
|
| 185 |
public static final int WINDOW_CONFIG_ALWAYS_ON_TOP = 1 << 5; |
| 186 |
|
| 187 |
|
| 188 |
public static final int WINDOW_CONFIG_ROTATION = 1 << 6; |
| 189 |
|
| 190 |
|
| 191 |
public static final int WINDOW_CONFIG_DISPLAY_WINDOWING_MODE = 1 << 7; |
| 192 |
|
| 193 |
|
| 194 |
public static final int WINDOW_CONFIG_DISPLAY_ROTATION = 1 << 8; |
| 195 |
|
| 196 |
|
| 197 |
@IntDef(flag = true, prefix = { "WINDOW_CONFIG_" }, value = { |
| 198 |
WINDOW_CONFIG_BOUNDS, |
| 199 |
WINDOW_CONFIG_APP_BOUNDS, |
| 200 |
WINDOW_CONFIG_MAX_BOUNDS, |
| 201 |
WINDOW_CONFIG_WINDOWING_MODE, |
| 202 |
WINDOW_CONFIG_ACTIVITY_TYPE, |
| 203 |
WINDOW_CONFIG_ALWAYS_ON_TOP, |
| 204 |
WINDOW_CONFIG_ROTATION, |
| 205 |
WINDOW_CONFIG_DISPLAY_WINDOWING_MODE, |
| 206 |
WINDOW_CONFIG_DISPLAY_ROTATION, |
| 207 |
}) |
| 208 |
public @interface WindowConfig {} |
| 209 |
|
| 210 |
@UnsupportedAppUsage |
| 211 |
public WindowConfiguration() { |
| 212 |
unset(); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
public WindowConfiguration(WindowConfiguration configuration) { |
| 217 |
setTo(configuration); |
| 218 |
} |
| 219 |
|
| 220 |
private WindowConfiguration(Parcel in) { |
| 221 |
readFromParcel(in); |
| 222 |
} |
| 223 |
|
| 224 |
@Override |
| 225 |
public void writeToParcel(Parcel dest, int flags) { |
| 226 |
mBounds.writeToParcel(dest, flags); |
| 227 |
dest.writeTypedObject(mAppBounds, flags); |
| 228 |
mMaxBounds.writeToParcel(dest, flags); |
| 229 |
dest.writeInt(mWindowingMode); |
| 230 |
dest.writeInt(mActivityType); |
| 231 |
dest.writeInt(mAlwaysOnTop); |
| 232 |
dest.writeInt(mRotation); |
| 233 |
dest.writeInt(mDisplayWindowingMode); |
| 234 |
dest.writeInt(mDisplayRotation); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
public void readFromParcel(@NonNull Parcel source) { |
| 239 |
mBounds.readFromParcel(source); |
| 240 |
mAppBounds = source.readTypedObject(Rect.CREATOR); |
| 241 |
mMaxBounds.readFromParcel(source); |
| 242 |
mWindowingMode = source.readInt(); |
| 243 |
mActivityType = source.readInt(); |
| 244 |
mAlwaysOnTop = source.readInt(); |
| 245 |
mRotation = source.readInt(); |
| 246 |
mDisplayWindowingMode = source.readInt(); |
| 247 |
mDisplayRotation = source.readInt(); |
| 248 |
} |
| 249 |
|
| 250 |
@Override |
| 251 |
public int describeContents() { |
| 252 |
return 0; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
public static final @android.annotation.NonNull Creator<WindowConfiguration> CREATOR = new Creator<WindowConfiguration>() { |
| 257 |
@Override |
| 258 |
public WindowConfiguration createFromParcel(Parcel in) { |
| 259 |
return new WindowConfiguration(in); |
| 260 |
} |
| 261 |
|
| 262 |
@Override |
| 263 |
public WindowConfiguration[] newArray(int size) { |
| 264 |
return new WindowConfiguration[size]; |
| 265 |
} |
| 266 |
}; |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
public void setBounds(Rect rect) { |
| 273 |
if (rect == null) { |
| 274 |
mBounds.setEmpty(); |
| 275 |
return; |
| 276 |
} |
| 277 |
|
| 278 |
mBounds.set(rect); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
public void setAppBounds(Rect rect) { |
| 287 |
if (rect == null) { |
| 288 |
mAppBounds = null; |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
setAppBounds(rect.left, rect.top, rect.right, rect.bottom); |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
public void setMaxBounds(@Nullable Rect rect) { |
| 301 |
if (rect == null) { |
| 302 |
mMaxBounds.setEmpty(); |
| 303 |
return; |
| 304 |
} |
| 305 |
mMaxBounds.set(rect); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
public void setMaxBounds(int left, int top, int right, int bottom) { |
| 313 |
mMaxBounds.set(left, top, right, bottom); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
public void setDisplayRotation(@Surface.Rotation int rotation) { |
| 321 |
mDisplayRotation = rotation; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public void setAlwaysOnTop(boolean alwaysOnTop) { |
| 330 |
mAlwaysOnTop = alwaysOnTop ? ALWAYS_ON_TOP_ON : ALWAYS_ON_TOP_OFF; |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
public void unsetAlwaysOnTop() { |
| 338 |
mAlwaysOnTop = ALWAYS_ON_TOP_UNDEFINED; |
| 339 |
} |
| 340 |
|
| 341 |
private void setAlwaysOnTop(@AlwaysOnTop int alwaysOnTop) { |
| 342 |
mAlwaysOnTop = alwaysOnTop; |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
public void setAppBounds(int left, int top, int right, int bottom) { |
| 351 |
if (mAppBounds == null) { |
| 352 |
mAppBounds = new Rect(); |
| 353 |
} |
| 354 |
|
| 355 |
mAppBounds.set(left, top, right, bottom); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
public Rect getAppBounds() { |
| 360 |
return mAppBounds; |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
public Rect getBounds() { |
| 365 |
return mBounds; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
@NonNull |
| 370 |
public Rect getMaxBounds() { |
| 371 |
return mMaxBounds; |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
public @Surface.Rotation int getDisplayRotation() { |
| 379 |
return mDisplayRotation; |
| 380 |
} |
| 381 |
|
| 382 |
public int getRotation() { |
| 383 |
return mRotation; |
| 384 |
} |
| 385 |
|
| 386 |
public void setRotation(int rotation) { |
| 387 |
mRotation = rotation; |
| 388 |
} |
| 389 |
|
| 390 |
public void setWindowingMode(@WindowingMode int windowingMode) { |
| 391 |
mWindowingMode = windowingMode; |
| 392 |
} |
| 393 |
|
| 394 |
@WindowingMode |
| 395 |
public int getWindowingMode() { |
| 396 |
return mWindowingMode; |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
public void setDisplayWindowingMode(@WindowingMode int windowingMode) { |
| 401 |
mDisplayWindowingMode = windowingMode; |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
@WindowingMode |
| 406 |
public int getDisplayWindowingMode() { |
| 407 |
return mDisplayWindowingMode; |
| 408 |
} |
| 409 |
|
| 410 |
public void setActivityType(@ActivityType int activityType) { |
| 411 |
if (mActivityType == activityType) { |
| 412 |
return; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
if (isSystem() |
| 419 |
&& mActivityType != ACTIVITY_TYPE_UNDEFINED |
| 420 |
&& activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 421 |
throw new IllegalStateException("Can't change activity type once set: " + this |
| 422 |
+ " activityType=" + activityTypeToString(activityType)); |
| 423 |
} |
| 424 |
mActivityType = activityType; |
| 425 |
} |
| 426 |
|
| 427 |
@ActivityType |
| 428 |
public int getActivityType() { |
| 429 |
return mActivityType; |
| 430 |
} |
| 431 |
|
| 432 |
public void setTo(WindowConfiguration other) { |
| 433 |
setBounds(other.mBounds); |
| 434 |
setAppBounds(other.mAppBounds); |
| 435 |
setMaxBounds(other.mMaxBounds); |
| 436 |
setDisplayRotation(other.mDisplayRotation); |
| 437 |
setWindowingMode(other.mWindowingMode); |
| 438 |
setActivityType(other.mActivityType); |
| 439 |
setAlwaysOnTop(other.mAlwaysOnTop); |
| 440 |
setRotation(other.mRotation); |
| 441 |
setDisplayWindowingMode(other.mDisplayWindowingMode); |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
public void unset() { |
| 447 |
setToDefaults(); |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
public void setToDefaults() { |
| 452 |
setAppBounds(null); |
| 453 |
setBounds(null); |
| 454 |
setMaxBounds(null); |
| 455 |
setDisplayRotation(ROTATION_UNDEFINED); |
| 456 |
setWindowingMode(WINDOWING_MODE_UNDEFINED); |
| 457 |
setActivityType(ACTIVITY_TYPE_UNDEFINED); |
| 458 |
setAlwaysOnTop(ALWAYS_ON_TOP_UNDEFINED); |
| 459 |
setRotation(ROTATION_UNDEFINED); |
| 460 |
setDisplayWindowingMode(WINDOWING_MODE_UNDEFINED); |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
public void scale(float scale) { |
| 465 |
mBounds.scale(scale); |
| 466 |
mMaxBounds.scale(scale); |
| 467 |
if (mAppBounds != null) { |
| 468 |
mAppBounds.scale(scale); |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
public @WindowConfig int updateFrom(@NonNull WindowConfiguration delta) { |
| 481 |
int changed = 0; |
| 482 |
|
| 483 |
if (!delta.mBounds.isEmpty() && !delta.mBounds.equals(mBounds)) { |
| 484 |
changed |= WINDOW_CONFIG_BOUNDS; |
| 485 |
setBounds(delta.mBounds); |
| 486 |
} |
| 487 |
if (delta.mAppBounds != null && !delta.mAppBounds.equals(mAppBounds)) { |
| 488 |
changed |= WINDOW_CONFIG_APP_BOUNDS; |
| 489 |
setAppBounds(delta.mAppBounds); |
| 490 |
} |
| 491 |
if (!delta.mMaxBounds.isEmpty() && !delta.mMaxBounds.equals(mMaxBounds)) { |
| 492 |
changed |= WINDOW_CONFIG_MAX_BOUNDS; |
| 493 |
setMaxBounds(delta.mMaxBounds); |
| 494 |
} |
| 495 |
if (delta.mWindowingMode != WINDOWING_MODE_UNDEFINED |
| 496 |
&& mWindowingMode != delta.mWindowingMode) { |
| 497 |
changed |= WINDOW_CONFIG_WINDOWING_MODE; |
| 498 |
setWindowingMode(delta.mWindowingMode); |
| 499 |
} |
| 500 |
if (delta.mActivityType != ACTIVITY_TYPE_UNDEFINED |
| 501 |
&& mActivityType != delta.mActivityType) { |
| 502 |
changed |= WINDOW_CONFIG_ACTIVITY_TYPE; |
| 503 |
setActivityType(delta.mActivityType); |
| 504 |
} |
| 505 |
if (delta.mAlwaysOnTop != ALWAYS_ON_TOP_UNDEFINED |
| 506 |
&& mAlwaysOnTop != delta.mAlwaysOnTop) { |
| 507 |
changed |= WINDOW_CONFIG_ALWAYS_ON_TOP; |
| 508 |
setAlwaysOnTop(delta.mAlwaysOnTop); |
| 509 |
} |
| 510 |
if (delta.mRotation != ROTATION_UNDEFINED && delta.mRotation != mRotation) { |
| 511 |
changed |= WINDOW_CONFIG_ROTATION; |
| 512 |
setRotation(delta.mRotation); |
| 513 |
} |
| 514 |
if (delta.mDisplayWindowingMode != WINDOWING_MODE_UNDEFINED |
| 515 |
&& mDisplayWindowingMode != delta.mDisplayWindowingMode) { |
| 516 |
changed |= WINDOW_CONFIG_DISPLAY_WINDOWING_MODE; |
| 517 |
setDisplayWindowingMode(delta.mDisplayWindowingMode); |
| 518 |
} |
| 519 |
if (delta.mDisplayRotation != ROTATION_UNDEFINED |
| 520 |
&& delta.mDisplayRotation != mDisplayRotation) { |
| 521 |
changed |= WINDOW_CONFIG_DISPLAY_ROTATION; |
| 522 |
setDisplayRotation(delta.mDisplayRotation); |
| 523 |
} |
| 524 |
return changed; |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
public void setTo(@NonNull WindowConfiguration delta, @WindowConfig int mask) { |
| 532 |
if ((mask & WINDOW_CONFIG_BOUNDS) != 0) { |
| 533 |
setBounds(delta.mBounds); |
| 534 |
} |
| 535 |
if ((mask & WINDOW_CONFIG_APP_BOUNDS) != 0) { |
| 536 |
setAppBounds(delta.mAppBounds); |
| 537 |
} |
| 538 |
if ((mask & WINDOW_CONFIG_MAX_BOUNDS) != 0) { |
| 539 |
setMaxBounds(delta.mMaxBounds); |
| 540 |
} |
| 541 |
if ((mask & WINDOW_CONFIG_WINDOWING_MODE) != 0) { |
| 542 |
setWindowingMode(delta.mWindowingMode); |
| 543 |
} |
| 544 |
if ((mask & WINDOW_CONFIG_ACTIVITY_TYPE) != 0) { |
| 545 |
setActivityType(delta.mActivityType); |
| 546 |
} |
| 547 |
if ((mask & WINDOW_CONFIG_ALWAYS_ON_TOP) != 0) { |
| 548 |
setAlwaysOnTop(delta.mAlwaysOnTop); |
| 549 |
} |
| 550 |
if ((mask & WINDOW_CONFIG_ROTATION) != 0) { |
| 551 |
setRotation(delta.mRotation); |
| 552 |
} |
| 553 |
if ((mask & WINDOW_CONFIG_DISPLAY_WINDOWING_MODE) != 0) { |
| 554 |
setDisplayWindowingMode(delta.mDisplayWindowingMode); |
| 555 |
} |
| 556 |
if ((mask & WINDOW_CONFIG_DISPLAY_ROTATION) != 0) { |
| 557 |
setDisplayRotation(delta.mDisplayRotation); |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
public @WindowConfig long diff(WindowConfiguration other, boolean compareUndefined) { |
| 573 |
long changes = 0; |
| 574 |
|
| 575 |
if (!mBounds.equals(other.mBounds)) { |
| 576 |
changes |= WINDOW_CONFIG_BOUNDS; |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
if ((compareUndefined || other.mAppBounds != null) |
| 581 |
&& mAppBounds != other.mAppBounds |
| 582 |
&& (mAppBounds == null || !mAppBounds.equals(other.mAppBounds))) { |
| 583 |
changes |= WINDOW_CONFIG_APP_BOUNDS; |
| 584 |
} |
| 585 |
|
| 586 |
if (!mMaxBounds.equals(other.mMaxBounds)) { |
| 587 |
changes |= WINDOW_CONFIG_MAX_BOUNDS; |
| 588 |
} |
| 589 |
|
| 590 |
if ((compareUndefined || other.mWindowingMode != WINDOWING_MODE_UNDEFINED) |
| 591 |
&& mWindowingMode != other.mWindowingMode) { |
| 592 |
changes |= WINDOW_CONFIG_WINDOWING_MODE; |
| 593 |
} |
| 594 |
|
| 595 |
if ((compareUndefined || other.mActivityType != ACTIVITY_TYPE_UNDEFINED) |
| 596 |
&& mActivityType != other.mActivityType) { |
| 597 |
changes |= WINDOW_CONFIG_ACTIVITY_TYPE; |
| 598 |
} |
| 599 |
|
| 600 |
if ((compareUndefined || other.mAlwaysOnTop != ALWAYS_ON_TOP_UNDEFINED) |
| 601 |
&& mAlwaysOnTop != other.mAlwaysOnTop) { |
| 602 |
changes |= WINDOW_CONFIG_ALWAYS_ON_TOP; |
| 603 |
} |
| 604 |
|
| 605 |
if ((compareUndefined || other.mRotation != ROTATION_UNDEFINED) |
| 606 |
&& mRotation != other.mRotation) { |
| 607 |
changes |= WINDOW_CONFIG_ROTATION; |
| 608 |
} |
| 609 |
|
| 610 |
if ((compareUndefined || other.mDisplayWindowingMode != WINDOWING_MODE_UNDEFINED) |
| 611 |
&& mDisplayWindowingMode != other.mDisplayWindowingMode) { |
| 612 |
changes |= WINDOW_CONFIG_DISPLAY_WINDOWING_MODE; |
| 613 |
} |
| 614 |
|
| 615 |
if ((compareUndefined || other.mDisplayRotation != ROTATION_UNDEFINED) |
| 616 |
&& mDisplayRotation != other.mDisplayRotation) { |
| 617 |
changes |= WINDOW_CONFIG_DISPLAY_ROTATION; |
| 618 |
} |
| 619 |
|
| 620 |
return changes; |
| 621 |
} |
| 622 |
|
| 623 |
@Override |
| 624 |
public int compareTo(WindowConfiguration that) { |
| 625 |
int n = 0; |
| 626 |
if (mAppBounds == null && that.mAppBounds != null) { |
| 627 |
return 1; |
| 628 |
} else if (mAppBounds != null && that.mAppBounds == null) { |
| 629 |
return -1; |
| 630 |
} else if (mAppBounds != null && that.mAppBounds != null) { |
| 631 |
n = mAppBounds.left - that.mAppBounds.left; |
| 632 |
if (n != 0) return n; |
| 633 |
n = mAppBounds.top - that.mAppBounds.top; |
| 634 |
if (n != 0) return n; |
| 635 |
n = mAppBounds.right - that.mAppBounds.right; |
| 636 |
if (n != 0) return n; |
| 637 |
n = mAppBounds.bottom - that.mAppBounds.bottom; |
| 638 |
if (n != 0) return n; |
| 639 |
} |
| 640 |
|
| 641 |
n = mMaxBounds.left - that.mMaxBounds.left; |
| 642 |
if (n != 0) return n; |
| 643 |
n = mMaxBounds.top - that.mMaxBounds.top; |
| 644 |
if (n != 0) return n; |
| 645 |
n = mMaxBounds.right - that.mMaxBounds.right; |
| 646 |
if (n != 0) return n; |
| 647 |
n = mMaxBounds.bottom - that.mMaxBounds.bottom; |
| 648 |
if (n != 0) return n; |
| 649 |
|
| 650 |
n = mBounds.left - that.mBounds.left; |
| 651 |
if (n != 0) return n; |
| 652 |
n = mBounds.top - that.mBounds.top; |
| 653 |
if (n != 0) return n; |
| 654 |
n = mBounds.right - that.mBounds.right; |
| 655 |
if (n != 0) return n; |
| 656 |
n = mBounds.bottom - that.mBounds.bottom; |
| 657 |
if (n != 0) return n; |
| 658 |
|
| 659 |
n = mWindowingMode - that.mWindowingMode; |
| 660 |
if (n != 0) return n; |
| 661 |
n = mActivityType - that.mActivityType; |
| 662 |
if (n != 0) return n; |
| 663 |
n = mAlwaysOnTop - that.mAlwaysOnTop; |
| 664 |
if (n != 0) return n; |
| 665 |
n = mRotation - that.mRotation; |
| 666 |
if (n != 0) return n; |
| 667 |
|
| 668 |
n = mDisplayWindowingMode - that.mDisplayWindowingMode; |
| 669 |
if (n != 0) return n; |
| 670 |
n = mDisplayRotation - that.mDisplayRotation; |
| 671 |
if (n != 0) return n; |
| 672 |
|
| 673 |
|
| 674 |
return n; |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
@Override |
| 679 |
public boolean equals(@Nullable Object that) { |
| 680 |
if (that == null) return false; |
| 681 |
if (that == this) return true; |
| 682 |
if (!(that instanceof WindowConfiguration)) { |
| 683 |
return false; |
| 684 |
} |
| 685 |
return this.compareTo((WindowConfiguration) that) == 0; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
@Override |
| 690 |
public int hashCode() { |
| 691 |
int result = 0; |
| 692 |
result = 31 * result + Objects.hashCode(mAppBounds); |
| 693 |
result = 31 * result + Objects.hashCode(mBounds); |
| 694 |
result = 31 * result + Objects.hashCode(mMaxBounds); |
| 695 |
result = 31 * result + mWindowingMode; |
| 696 |
result = 31 * result + mActivityType; |
| 697 |
result = 31 * result + mAlwaysOnTop; |
| 698 |
result = 31 * result + mRotation; |
| 699 |
result = 31 * result + mDisplayWindowingMode; |
| 700 |
result = 31 * result + mDisplayRotation; |
| 701 |
return result; |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
@Override |
| 706 |
public String toString() { |
| 707 |
return "{ mBounds=" + mBounds |
| 708 |
+ " mAppBounds=" + mAppBounds |
| 709 |
+ " mMaxBounds=" + mMaxBounds |
| 710 |
+ " mDisplayRotation=" + (mRotation == ROTATION_UNDEFINED |
| 711 |
? "undefined" : rotationToString(mDisplayRotation)) |
| 712 |
+ " mWindowingMode=" + windowingModeToString(mWindowingMode) |
| 713 |
+ " mDisplayWindowingMode=" + windowingModeToString(mDisplayWindowingMode) |
| 714 |
+ " mActivityType=" + activityTypeToString(mActivityType) |
| 715 |
+ " mAlwaysOnTop=" + alwaysOnTopToString(mAlwaysOnTop) |
| 716 |
+ " mRotation=" + (mRotation == ROTATION_UNDEFINED |
| 717 |
? "undefined" : rotationToString(mRotation)) |
| 718 |
+ "}"; |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId) { |
| 730 |
final long token = protoOutputStream.start(fieldId); |
| 731 |
if (mAppBounds != null) { |
| 732 |
mAppBounds.dumpDebug(protoOutputStream, APP_BOUNDS); |
| 733 |
} |
| 734 |
protoOutputStream.write(WINDOWING_MODE, mWindowingMode); |
| 735 |
protoOutputStream.write(ACTIVITY_TYPE, mActivityType); |
| 736 |
mBounds.dumpDebug(protoOutputStream, BOUNDS); |
| 737 |
mMaxBounds.dumpDebug(protoOutputStream, MAX_BOUNDS); |
| 738 |
protoOutputStream.end(token); |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
public void readFromProto(ProtoInputStream proto, long fieldId) |
| 750 |
throws IOException, WireTypeMismatchException { |
| 751 |
final long token = proto.start(fieldId); |
| 752 |
try { |
| 753 |
while (proto.nextField() != ProtoInputStream.NO_MORE_FIELDS) { |
| 754 |
switch (proto.getFieldNumber()) { |
| 755 |
case (int) APP_BOUNDS: |
| 756 |
mAppBounds = new Rect(); |
| 757 |
mAppBounds.readFromProto(proto, APP_BOUNDS); |
| 758 |
break; |
| 759 |
case (int) BOUNDS: |
| 760 |
mBounds.readFromProto(proto, BOUNDS); |
| 761 |
break; |
| 762 |
case (int) MAX_BOUNDS: |
| 763 |
mMaxBounds.readFromProto(proto, MAX_BOUNDS); |
| 764 |
break; |
| 765 |
case (int) WINDOWING_MODE: |
| 766 |
mWindowingMode = proto.readInt(WINDOWING_MODE); |
| 767 |
break; |
| 768 |
case (int) ACTIVITY_TYPE: |
| 769 |
mActivityType = proto.readInt(ACTIVITY_TYPE); |
| 770 |
break; |
| 771 |
} |
| 772 |
} |
| 773 |
} finally { |
| 774 |
|
| 775 |
proto.end(token); |
| 776 |
} |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
public boolean hasWindowShadow() { |
| 785 |
return mWindowingMode != WINDOWING_MODE_MULTI_WINDOW && tasksAreFloating(); |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
public boolean hasWindowDecorCaption() { |
| 794 |
return mActivityType == ACTIVITY_TYPE_STANDARD && (mWindowingMode == WINDOWING_MODE_FREEFORM |
| 795 |
|| mDisplayWindowingMode == WINDOWING_MODE_FREEFORM); |
| 796 |
} |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
public boolean canResizeTask() { |
| 804 |
return mWindowingMode == WINDOWING_MODE_FREEFORM |
| 805 |
|| mWindowingMode == WINDOWING_MODE_MULTI_WINDOW; |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
public boolean persistTaskBounds() { |
| 811 |
return mWindowingMode == WINDOWING_MODE_FREEFORM; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
public boolean tasksAreFloating() { |
| 821 |
return isFloating(mWindowingMode); |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
public static boolean isFloating(@WindowingMode int windowingMode) { |
| 826 |
return windowingMode == WINDOWING_MODE_FREEFORM || windowingMode == WINDOWING_MODE_PINNED; |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
public static boolean inMultiWindowMode(int windowingMode) { |
| 835 |
return windowingMode != WINDOWING_MODE_FULLSCREEN |
| 836 |
&& windowingMode != WINDOWING_MODE_UNDEFINED; |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
public boolean canReceiveKeys() { |
| 844 |
return mWindowingMode != WINDOWING_MODE_PINNED; |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
public boolean isAlwaysOnTop() { |
| 853 |
if (mWindowingMode == WINDOWING_MODE_PINNED) return true; |
| 854 |
if (mActivityType == ACTIVITY_TYPE_DREAM) return true; |
| 855 |
if (mAlwaysOnTop != ALWAYS_ON_TOP_ON) return false; |
| 856 |
return mWindowingMode == WINDOWING_MODE_FREEFORM |
| 857 |
|| mWindowingMode == WINDOWING_MODE_MULTI_WINDOW; |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
public boolean keepVisibleDeadAppWindowOnScreen() { |
| 866 |
return mWindowingMode != WINDOWING_MODE_PINNED; |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
public boolean useWindowFrameForBackdrop() { |
| 875 |
return mWindowingMode == WINDOWING_MODE_FREEFORM || mWindowingMode == WINDOWING_MODE_PINNED; |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
public boolean hasMovementAnimations() { |
| 883 |
return mWindowingMode != WINDOWING_MODE_PINNED; |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
public boolean supportSplitScreenWindowingMode() { |
| 892 |
return supportSplitScreenWindowingMode(mActivityType); |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
public static boolean supportSplitScreenWindowingMode(int activityType) { |
| 897 |
return activityType != ACTIVITY_TYPE_ASSISTANT && activityType != ACTIVITY_TYPE_DREAM; |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
public static String windowingModeToString(@WindowingMode int windowingMode) { |
| 902 |
switch (windowingMode) { |
| 903 |
case WINDOWING_MODE_UNDEFINED: return "undefined"; |
| 904 |
case WINDOWING_MODE_FULLSCREEN: return "fullscreen"; |
| 905 |
case WINDOWING_MODE_MULTI_WINDOW: return "multi-window"; |
| 906 |
case WINDOWING_MODE_PINNED: return "pinned"; |
| 907 |
case WINDOWING_MODE_FREEFORM: return "freeform"; |
| 908 |
} |
| 909 |
return String.valueOf(windowingMode); |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
public static String activityTypeToString(@ActivityType int applicationType) { |
| 914 |
switch (applicationType) { |
| 915 |
case ACTIVITY_TYPE_UNDEFINED: return "undefined"; |
| 916 |
case ACTIVITY_TYPE_STANDARD: return "standard"; |
| 917 |
case ACTIVITY_TYPE_HOME: return "home"; |
| 918 |
case ACTIVITY_TYPE_RECENTS: return "recents"; |
| 919 |
case ACTIVITY_TYPE_ASSISTANT: return "assistant"; |
| 920 |
case ACTIVITY_TYPE_DREAM: return "dream"; |
| 921 |
} |
| 922 |
return String.valueOf(applicationType); |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
public static String alwaysOnTopToString(@AlwaysOnTop int alwaysOnTop) { |
| 927 |
switch (alwaysOnTop) { |
| 928 |
case ALWAYS_ON_TOP_UNDEFINED: return "undefined"; |
| 929 |
case ALWAYS_ON_TOP_ON: return "on"; |
| 930 |
case ALWAYS_ON_TOP_OFF: return "off"; |
| 931 |
} |
| 932 |
return String.valueOf(alwaysOnTop); |
| 933 |
} |
| 934 |
} |