|
27 | 27 | #include <private/android_filesystem_config.h> |
28 | 28 | #include <private/gui/ComposerServiceAIDL.h> |
29 | 29 | #include <ui/DisplayMode.h> |
| 30 | +#include <ui/DisplayState.h> |
30 | 31 | #include <ui/DynamicDisplayInfo.h> |
31 | 32 | #include <utils/String8.h> |
32 | 33 | #include <functional> |
@@ -439,6 +440,56 @@ TEST_F(CredentialsTest, TransactionPermissionTest) { |
439 | 440 | } |
440 | 441 | } |
441 | 442 |
|
| 443 | +TEST_F(CredentialsTest, DisplayTransactionPermissionTest) { |
| 444 | + const auto display = getFirstDisplayToken(); |
| 445 | + |
| 446 | + ui::DisplayState displayState; |
| 447 | + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayState(display, &displayState)); |
| 448 | + const ui::Rotation initialOrientation = displayState.orientation; |
| 449 | + |
| 450 | + // Set display orientation from an untrusted process. This should fail silently. |
| 451 | + { |
| 452 | + UIDFaker f{AID_BIN}; |
| 453 | + Transaction transaction; |
| 454 | + Rect layerStackRect; |
| 455 | + Rect displayRect; |
| 456 | + transaction.setDisplayProjection(display, initialOrientation + ui::ROTATION_90, |
| 457 | + layerStackRect, displayRect); |
| 458 | + transaction.apply(/*synchronous=*/true); |
| 459 | + } |
| 460 | + |
| 461 | + // Verify that the display orientation did not change. |
| 462 | + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayState(display, &displayState)); |
| 463 | + ASSERT_EQ(initialOrientation, displayState.orientation); |
| 464 | + |
| 465 | + // Set display orientation from a trusted process. |
| 466 | + { |
| 467 | + UIDFaker f{AID_SYSTEM}; |
| 468 | + Transaction transaction; |
| 469 | + Rect layerStackRect; |
| 470 | + Rect displayRect; |
| 471 | + transaction.setDisplayProjection(display, initialOrientation + ui::ROTATION_90, |
| 472 | + layerStackRect, displayRect); |
| 473 | + transaction.apply(/*synchronous=*/true); |
| 474 | + } |
| 475 | + |
| 476 | + // Verify that the display orientation did change. |
| 477 | + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayState(display, &displayState)); |
| 478 | + ASSERT_EQ(initialOrientation + ui::ROTATION_90, displayState.orientation); |
| 479 | + |
| 480 | + // Reset orientation |
| 481 | + { |
| 482 | + UIDFaker f{AID_SYSTEM}; |
| 483 | + Transaction transaction; |
| 484 | + Rect layerStackRect; |
| 485 | + Rect displayRect; |
| 486 | + transaction.setDisplayProjection(display, initialOrientation, layerStackRect, displayRect); |
| 487 | + transaction.apply(/*synchronous=*/true); |
| 488 | + } |
| 489 | + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayState(display, &displayState)); |
| 490 | + ASSERT_EQ(initialOrientation, displayState.orientation); |
| 491 | +} |
| 492 | + |
442 | 493 | } // namespace android |
443 | 494 |
|
444 | 495 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
|
0 commit comments