From 02e11f95a18a64c231ad0ef43c1c5eaafd8da2e8 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Fri, 24 Jan 2025 09:50:38 -0500 Subject: [PATCH] Add integration test for cutout rotation evaluation (#160354) Test that the position of a cutout as reported by the Android engine repositions based on screen orientation. Related to https://github.com/flutter/engine/pull/55992 Part of https://github.com/flutter/flutter/issues/155658 to test run flutter drive integration_test/display_cutout_test.dart from dev/integration_tests/display_cutout_rotation Pr also force upgrades pub dependencies because I was getting presubmit failure in version solve. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --- .../display_cutout_rotation/.gitignore | 45 ++++++ .../display_cutout_rotation/.metadata | 30 ++++ .../display_cutout_rotation/README.md | 3 + .../analysis_options.yaml | 5 + .../android/.gitignore | 13 ++ .../android/app/build.gradle.kts | 43 ++++++ .../android/app/src/debug/AndroidManifest.xml | 11 ++ .../android/app/src/main/AndroidManifest.xml | 49 +++++++ .../display_cutout_rotation/MainActivity.kt | 42 ++++++ .../res/drawable-v21/launch_background.xml | 16 +++ .../main/res/drawable/launch_background.xml | 16 +++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 544 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 442 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 721 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 1031 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 1443 bytes .../app/src/main/res/values-night/styles.xml | 22 +++ .../app/src/main/res/values/styles.xml | 22 +++ .../app/src/profile/AndroidManifest.xml | 11 ++ .../android/build.gradle.kts | 24 ++++ .../android/gradle.properties | 3 + .../gradle/wrapper/gradle-wrapper.properties | 5 + .../android/settings.gradle.kts | 26 ++++ .../integration_test/display_cutout_test.dart | 131 ++++++++++++++++++ .../display_cutout_rotation/lib/main.dart | 50 +++++++ .../display_cutout_rotation/pubspec.yaml | 123 ++++++++++++++++ .../test_driver/display_cutout_test_test.dart | 106 ++++++++++++++ 27 files changed, 796 insertions(+) create mode 100644 dev/integration_tests/display_cutout_rotation/.gitignore create mode 100644 dev/integration_tests/display_cutout_rotation/.metadata create mode 100644 dev/integration_tests/display_cutout_rotation/README.md create mode 100644 dev/integration_tests/display_cutout_rotation/analysis_options.yaml create mode 100644 dev/integration_tests/display_cutout_rotation/android/.gitignore create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/build.gradle.kts create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/debug/AndroidManifest.xml create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/AndroidManifest.xml create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/java/com/example/display_cutout_rotation/MainActivity.kt create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/drawable-v21/launch_background.xml create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/drawable/launch_background.xml create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/values-night/styles.xml create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/main/res/values/styles.xml create mode 100644 dev/integration_tests/display_cutout_rotation/android/app/src/profile/AndroidManifest.xml create mode 100644 dev/integration_tests/display_cutout_rotation/android/build.gradle.kts create mode 100644 dev/integration_tests/display_cutout_rotation/android/gradle.properties create mode 100644 dev/integration_tests/display_cutout_rotation/android/gradle/wrapper/gradle-wrapper.properties create mode 100644 dev/integration_tests/display_cutout_rotation/android/settings.gradle.kts create mode 100644 dev/integration_tests/display_cutout_rotation/integration_test/display_cutout_test.dart create mode 100644 dev/integration_tests/display_cutout_rotation/lib/main.dart create mode 100644 dev/integration_tests/display_cutout_rotation/pubspec.yaml create mode 100644 dev/integration_tests/display_cutout_rotation/test_driver/display_cutout_test_test.dart diff --git a/dev/integration_tests/display_cutout_rotation/.gitignore b/dev/integration_tests/display_cutout_rotation/.gitignore new file mode 100644 index 0000000000..79c113f9b5 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/.gitignore @@ -0,0 +1,45 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.build/ +.buildlog/ +.history +.svn/ +.swiftpm/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/dev/integration_tests/display_cutout_rotation/.metadata b/dev/integration_tests/display_cutout_rotation/.metadata new file mode 100644 index 0000000000..ae37682597 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/.metadata @@ -0,0 +1,30 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "0dc4eb31df6fe16c1bac10bef3904eb378056c35" + channel: "[user-branch]" + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 0dc4eb31df6fe16c1bac10bef3904eb378056c35 + base_revision: 0dc4eb31df6fe16c1bac10bef3904eb378056c35 + - platform: android + create_revision: 0dc4eb31df6fe16c1bac10bef3904eb378056c35 + base_revision: 0dc4eb31df6fe16c1bac10bef3904eb378056c35 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/dev/integration_tests/display_cutout_rotation/README.md b/dev/integration_tests/display_cutout_rotation/README.md new file mode 100644 index 0000000000..7f3c5627b5 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/README.md @@ -0,0 +1,3 @@ +# display_cutout_rotation + +To run test locally use `flutter drive integration_test/display_cutout_test.dart` from this folder. diff --git a/dev/integration_tests/display_cutout_rotation/analysis_options.yaml b/dev/integration_tests/display_cutout_rotation/analysis_options.yaml new file mode 100644 index 0000000000..c4a47172d2 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/analysis_options.yaml @@ -0,0 +1,5 @@ +include: ../../analysis_options.yaml + +analyzer: + exclude: + - build/** diff --git a/dev/integration_tests/display_cutout_rotation/android/.gitignore b/dev/integration_tests/display_cutout_rotation/android/.gitignore new file mode 100644 index 0000000000..55afd919c6 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/.gitignore @@ -0,0 +1,13 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/to/reference-keystore +key.properties +**/*.keystore +**/*.jks diff --git a/dev/integration_tests/display_cutout_rotation/android/app/build.gradle.kts b/dev/integration_tests/display_cutout_rotation/android/app/build.gradle.kts new file mode 100644 index 0000000000..f966b60fa9 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + id("com.android.application") + id("kotlin-android") + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id("dev.flutter.flutter-gradle-plugin") +} + +android { + namespace = "com.example.display_cutout_rotation" + compileSdk = flutter.compileSdkVersion + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = "17" + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId = "com.example.display_cutout_rotation" + // You can update the following values to match your application needs. + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig = signingConfigs.getByName("debug") + } + } +} + +flutter { + source = "../.." +} diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/debug/AndroidManifest.xml b/dev/integration_tests/display_cutout_rotation/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000000..e00f903eae --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/AndroidManifest.xml b/dev/integration_tests/display_cutout_rotation/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..1b6f4c2f75 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/java/com/example/display_cutout_rotation/MainActivity.kt b/dev/integration_tests/display_cutout_rotation/android/app/src/main/java/com/example/display_cutout_rotation/MainActivity.kt new file mode 100644 index 0000000000..61e46e72d9 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/src/main/java/com/example/display_cutout_rotation/MainActivity.kt @@ -0,0 +1,42 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +@file:Suppress("PackageName") + +package com.example.display_cutout_rotation + +import android.os.Build +import android.os.Bundle +import android.view.WindowManager +import androidx.core.view.WindowCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat +import io.flutter.embedding.android.FlutterActivity + +class MainActivity : FlutterActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // https://developer.android.com/training/system-ui + // Set app into fullscreen mode without insets from system bars. + // Matches api 35 default behavior and is required by test which assumes no other inset + // except for a cutout. + val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView) + windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) + + // The default behavior on SDK level 34 and below is for display cutouts to be consumed + // before the insets would reach the engine. In order to receive the display cutouts in the + // engine, the test app must request that it be allowed to draw its content behind cutouts. + // See + // https://developer.android.com/reference/android/view/WindowManager.LayoutParams#layoutInDisplayCutoutMode + // LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS was added in api 30 so we need to check api level + // before setting the value. Not setting this value will prevent flutter from drawing in + // cutout areas which our test is explicitly requires. + if (Build.VERSION.SDK_INT >= 30) { + window.attributes.layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS + } + } +} diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/drawable-v21/launch_background.xml b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 0000000000..9f19e2f904 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/drawable/launch_background.xml b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 0000000000..3727f9e00a --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..db77bb4b7b0906d62b1847e87f15cdcacf6a4f29 GIT binary patch literal 544 zcmeAS@N?(olHy`uVBq!ia0y~yVDJE84rT@hh9qO>QU(SF$r9IylHmNblJdl&R0hYC z{G?O`&)mfH)S%SFl*+=BsWuD@4C?}XLR=Xb7#RJ!7{h04Zu=H;^aq4w44VZJaXaum zG@>0o`I5 z6U6gpN>(hBs@ovlyiK}omrVN}&28UY_JdsVcA=Cl0|SF_NswPKgMfg5KtMnO2sE4r zf%}pIPku2lFue41aSVw#{PxUsz9t6&hrp0GdlTMw^~h@f`fs1s!olsWbZ#C0v7PJ9 zExVjNeb(Ol`RU07XFf|X@qSK7qke0_C&kUH>MnD(8u-mi5B zt(&|xZ@%@sBNk%nt_5+E&U1QAlyT>>sMB2Zd5T5*R3&Sld5=98o%0qdm+@@-JjKB8 z(xcUiGOB?O=e)LCdt!o~wXBiQlFwyn4J{(JaZG%Q-e|yQz{EjrrIztFmwg@gt#&=FffMC4mtWmbKAF&qdyqKXG0ipk&vT5 zAmZ%d{SXF=bCKq@Z-GZZ;tV#~j83JDzFmxd-Hahq8AGNqhE8V;o5>h9i!po_WB6=l zU2kT?Kvt(bR^JA;;7+;DUGlvL6sMk6nsrHO&Q;BA-wby`jSBSdXJueu5G@Jv3uX`y zP*5;1FzBB@fBpXR=g+?ff&5MV!VC-yOFdm2Lp+YZy>e2h$w0vMVh8iNMNLhM)++IJ z{QqCg*LgRGXKpKZaOLSMJFo8MNc{figWv3mbJp+w-BoBm(|-hT|4dcbJ2lEyX!??Y`jpZ81*D{;rF6b`?;0>>pbJRKPRw2)?8wK8GH9> zL)n=k&vkA#ITl(SSsBW`??>AG{pM|AK2Jc#t6>y4N#$)H8ZEGkUc!`m{6pbTImMF#2{f z`gJk-_b~?aGX_m$44TXsJQ-wH$W+GA>5O4B7{g{VhRtFOpT!tHo5?tW$tsn}K99+{ zjLE&4*|Uz>tC88eNi3sZJbQ{n(LBkDd1t=Sn-plsE283-d*czTa-zm@iQD#kujt@|Kvt4hp|H z71QJA-@DE-vCc=}m3vdfeqD}l&W>B;IduNM%M_}RPx;yPVrk2E_T?&?d+vqXsA}xF zGk52_Ny78;-$vOoENNLjTll#WOG?YLuZ?eO;uVxk)@?h*_~6>qo(~l}_f@BaD>p=c zm>yaWRpaQm|`^KGX?!;c=*_;KycpYksb1 rdBk${xlomwC<})`ozHbP0l+XkKcl<5t literal 0 HcmV?d00001 diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..d5f1c8d34e7a88e3f88bea192c3a370d44689c3c GIT binary patch literal 1031 zcmeAS@N?(olHy`uVBq!ia0y~yV3+{H9Lx+13>Rhybuln7NS3%plmzFem6RtIr7}3C z$Dctjh(SM?K|h4SAdJB{hQT_6!9JhSFr3jep3y9U z(L9OKDxJ|flhG!d(I$t{HiywRm(ebd(Y}z;v6#`Zgwd&#(Yb=rrHawDn$fL>(XE!z zt&Y*Xj?trm(W8;kvysuWiP5u}(X)lotC`WOh0&*-(Wisaw}a8QlhLo6(XWTmzlYJk zmocD^F|eO8Z~|lCM8?2Lj6o9_gC>F8A3T{ccnV|4RK}2LjG@yRLuW9C&0q|h$rv_^ zF?<$d_-uBwU=HgjPRC?Uw`?x2A}+rQ?!a2^kVfvX7VhwN?#NE=s4niP9-inPl?69d z7T#1{bVqf`J=LWT)RsR~Tk%+JQT9|ZQFKYxDR#LKT37?|`uT^vIyZoR#b9vmDf()v(?iz7_L)oF78 zkJJ<)r8pUt8M$!5-N#*39u$gn zR>-(G$wg0`aolam=a?PG9$oC(GH>-!X0d*^l*gJvuFJp95x7~EvFLL3EEhhxt`pq; z%_lBC*86lUSiR`uj?O)w{s`}^n&Wz}@?RH+ochG+^SU~oY!t72t=ZWjXFc({Ty9i< zoXX3Kohi2Ju9xPeP296QFr{gETuR&Xh?K77YDUL{MQ1+I?2fS6ciP3jaR24wmqlki zKfgU-wdbO}>o1>vX;$n~9ltDoY4ItEi|?MFbkSNqMRUkMU-}~Bs z)+NdNzgg`VE)XKX=tVT|2z5{L4{YJjHWS*rIm-E6Ws`IFvdRnm87H fR&jd1QhDAN-h`R^uRUjAU|{fc^>bP0l+XkKAv&s= literal 0 HcmV?d00001 diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..4d6372eebdb28e45604e46eeda8dd24651419bc0 GIT binary patch literal 1443 zcmeAS@N?(olHy`uVBq!ia0y~yU^oE69Lx+145>_WOc@v$BuiW)N`mv#O3D+9QW+dm z@{>{(JaZG%Q-e|yQz{EjrrIztFy0FA32|j$U7=vLLgJC#>aTJ4T9D`W`gLwjjbtZ#N4x^eAqnb0LmM5cOIHO54qe%>- zNi3sjJfm3xqeU{KMGB*38lzP@qg4i@bta=t7NczrqirsuT`r?t9;018qkTT3eF39G z5u;-~4uK+6lW`UY0|SF-NswPKgMfko7&thbzyBTz-gcI+Wnf^o^K@|x zskrs_3VX0{ph#Pyi^G})N%|2R%{L?-ZV(U%Y+lqcfu(WAio}U)uIrV(+3WUaecD+A zmQ6SJem|Gdo_Kp z-*x@+`J3Y19B#kQTkx(t_`-K<>p6dn#rh_GuokuWC9d+nXX1zFdIcZVw{qEhc&=6O z^|eUFqwV?=KCBk6c(Pr4!l%_@70=G=P581}wBp75D22D-njfy%?{qk*AOB#Z{bq-g z`q2+|)-Q6ns2@Io{eMN{rubzF`u|EA+wSjG@UL6#aQc1N1oQe;4(H#;OmN?SS>~@F ztIeOC+&g|0i+=ccTfE@YZP5>((!~ot`|Cb zb^PFdrt-VXypJEaJ95?T2$v)Ws{O#V4Ednvz`|Pb} zf4VOe!@bWom-}e`tT2YtP3!%mny=z+}-K6mV2ZEt5Icwo(g z%Zr!wX>UAuh9QhqUj7<;)5IBxDQpH>KRz6|eoM6P*rQ_`EdPlXYgN?$U-3W2|NYf9 z3~H?J-^u1!lq%j3KgpL6_~F~TxcJXA&m~w0?N0Rh)m167XXobE9?sqiHmlnth&$|i z@b&H6->;epMCgPeb()B(Tr|RH~O+1PwlVxdT!ROU2OGQ3PvhLeQAwP zO|AMWqpQ}lM;-?Ix_3Z(ZoZK*%HiZ|EUDeVf^rGH<21r@EM zSf|zZ`p5aNP1ut4@|gFs0GYW>Kcl68^QPJ_Y + + + + + + + + diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/values/styles.xml b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000000..9a0ead3c04 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/values/styles.xml @@ -0,0 +1,22 @@ + + + + + + + + + diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/profile/AndroidManifest.xml b/dev/integration_tests/display_cutout_rotation/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 0000000000..e00f903eae --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/dev/integration_tests/display_cutout_rotation/android/build.gradle.kts b/dev/integration_tests/display_cutout_rotation/android/build.gradle.kts new file mode 100644 index 0000000000..dbee657bb5 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/build.gradle.kts @@ -0,0 +1,24 @@ +allprojects { + repositories { + google() + mavenCentral() + } +} + +val newBuildDir: Directory = + rootProject.layout.buildDirectory + .dir("../../build") + .get() +rootProject.layout.buildDirectory.value(newBuildDir) + +subprojects { + val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name) + project.layout.buildDirectory.value(newSubprojectBuildDir) +} +subprojects { + project.evaluationDependsOn(":app") +} + +tasks.register("clean") { + delete(rootProject.layout.buildDirectory) +} diff --git a/dev/integration_tests/display_cutout_rotation/android/gradle.properties b/dev/integration_tests/display_cutout_rotation/android/gradle.properties new file mode 100644 index 0000000000..f018a61817 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError +android.useAndroidX=true +android.enableJetifier=true diff --git a/dev/integration_tests/display_cutout_rotation/android/gradle/wrapper/gradle-wrapper.properties b/dev/integration_tests/display_cutout_rotation/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..afa1e8eb0a --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip diff --git a/dev/integration_tests/display_cutout_rotation/android/settings.gradle.kts b/dev/integration_tests/display_cutout_rotation/android/settings.gradle.kts new file mode 100644 index 0000000000..ead4a0bbc6 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/settings.gradle.kts @@ -0,0 +1,26 @@ +pluginManagement { + val flutterSdkPath = + run { + val properties = java.util.Properties() + file("local.properties").inputStream().use { properties.load(it) } + val flutterSdkPath = properties.getProperty("flutter.sdk") + require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" } + flutterSdkPath + } + + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") + + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +plugins { + id("dev.flutter.flutter-plugin-loader") version "1.0.0" + id("com.android.application") version "8.7.0" apply false + id("org.jetbrains.kotlin.android") version "1.8.22" apply false +} + +include(":app") diff --git a/dev/integration_tests/display_cutout_rotation/integration_test/display_cutout_test.dart b/dev/integration_tests/display_cutout_rotation/integration_test/display_cutout_test.dart new file mode 100644 index 0000000000..cbbc711b6d --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/integration_test/display_cutout_test.dart @@ -0,0 +1,131 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:display_cutout_rotation/main.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + group('end-to-end test', () { + // Test assumes a custom driver that enables + // "com.android.internal.display.cutout.emulation.tall". + testWidgets('cutout should be on top in portrait mode', (WidgetTester tester) async { + // Force rotation + await setOrientationAndWaitUntilRotation(tester, DeviceOrientation.portraitUp); + // Load app widget. + await tester.pumpWidget(const MyApp()); + final BuildContext context = tester.element(find.byType(Text)); + final Iterable displayFeatures = getCutouts(tester, context); + // Test is expecting one cutout setup in the test harness. + expect(displayFeatures.length, 1, reason: 'Single cutout display feature expected'); + // Verify that app code thinks there is a top cutout. + expect( + displayFeatures.first.bounds.top, + 0, + reason: + 'cutout should start at the top, does the test device have a ' + 'camera cutout or window inset?', + ); + }); + + testWidgets('cutout should be on left in landscape left', (WidgetTester tester) async { + await setOrientationAndWaitUntilRotation(tester, DeviceOrientation.landscapeLeft); + // Load app widget. + await tester.pumpWidget(const MyApp()); + final BuildContext context = tester.element(find.byType(Text)); + // Verify that app code thinks there is a left cutout. + final Iterable displayFeatures = getCutouts(tester, context); + + // Test is expecting one cutout setup in the test harness. + expect(displayFeatures.length, 1, reason: 'Single cutout display feature expected'); + expect( + displayFeatures.first.bounds.left, + 0, + reason: + 'cutout should start at the left, does the test device have a ' + 'camera cutout or window inset?', + ); + }); + + testWidgets('cutout handles rotation', (WidgetTester tester) async { + await setOrientationAndWaitUntilRotation(tester, DeviceOrientation.portraitUp); + const MyApp widgetUnderTest = MyApp(); + // Load app widget. + await tester.pumpWidget(widgetUnderTest); + BuildContext context = tester.element(find.byType(Text)); + Iterable displayFeatures = getCutouts(tester, context); + // Test is expecting one cutout setup in the test harness. + expect(displayFeatures.length, 1, reason: 'Single cutout display feature expected'); + // Verify that app code thinks there is a top cutout. + expect( + displayFeatures.first.bounds.top, + 0, + reason: + 'cutout should start at the top, does the test device have a ' + 'camera cutout or window inset?', + ); + await setOrientationAndWaitUntilRotation(tester, DeviceOrientation.landscapeLeft); + await tester.pumpWidget(widgetUnderTest); + + // Requery for display features after rotation. + context = tester.element(find.byType(Text)); + displayFeatures = getCutouts(tester, context); + // Test is expecting one cutout setup in the test harness. + expect(displayFeatures.length, 1, reason: 'Single cutout display feature expected'); + expect( + displayFeatures.first.bounds.left, + 0, + reason: 'cutout should start at the left or handle camera', + ); + }); + + tearDown(() { + // After each test reset to device perfered orientations to avoid + // test pollution. + SystemChrome.setPreferredOrientations([]); + }); + }); +} + +/* + * Force rotation then poll to ensure rotation has happened. + * + * Rotations have an async communication to engine which then has an async + * communication to the android operating system. + */ +Future setOrientationAndWaitUntilRotation( + WidgetTester tester, + DeviceOrientation orientation, +) async { + SystemChrome.setPreferredOrientations([orientation]); + Orientation expectedOrientation; + switch (orientation) { + case DeviceOrientation.portraitUp: + case DeviceOrientation.portraitDown: + expectedOrientation = Orientation.portrait; + case DeviceOrientation.landscapeRight: + case DeviceOrientation.landscapeLeft: + expectedOrientation = Orientation.landscape; + } + while (true) { + final BuildContext context = tester.element(find.byType(Text)); + if (expectedOrientation == MediaQuery.of(context).orientation) { + break; + } + await tester.pumpAndSettle(); + } +} + +Iterable getCutouts(WidgetTester tester, BuildContext context) { + final List displayFeatures = MediaQuery.of(context).displayFeatures; + return displayFeatures.where( + (DisplayFeature feature) => feature.type == DisplayFeatureType.cutout, + ); +} diff --git a/dev/integration_tests/display_cutout_rotation/lib/main.dart b/dev/integration_tests/display_cutout_rotation/lib/main.dart new file mode 100644 index 0000000000..91f3a8ba03 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/lib/main.dart @@ -0,0 +1,50 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/material.dart'; + +void main() { + runApp(const MyApp()); +} + +final class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + @override + Widget build(BuildContext context) { + final List displayFeatures = MediaQuery.of(context).displayFeatures; + displayFeatures.retainWhere( + (DisplayFeature feature) => feature.type == DisplayFeatureType.cutout, + ); + String text; + // None of this complexity is required for the test but it helps when + // visually debugging or watching a video of a remote device. + if (displayFeatures.isEmpty) { + text = 'CutoutNone'; + } else if (displayFeatures.length > 1) { + text = 'CutoutMany'; + } else { + final Rect cutout = displayFeatures[0].bounds; + if (cutout.top == 0) { + text = 'CutoutTop'; + } else if (cutout.left == 0) { + text = 'CutoutLeft'; + } else { + text = 'CutoutNeither'; + } + } + // Tests assume there is some text element displayed. + return MaterialApp( + debugShowCheckedModeBanner: false, + home: Text('Cutout status: $text', key: Key(text)), + ); + } +} diff --git a/dev/integration_tests/display_cutout_rotation/pubspec.yaml b/dev/integration_tests/display_cutout_rotation/pubspec.yaml new file mode 100644 index 0000000000..6dce77262d --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/pubspec.yaml @@ -0,0 +1,123 @@ +name: display_cutout_rotation +description: "A new Flutter project." +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. +version: 1.0.0+1 + +environment: + sdk: ^3.7.0-0 + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: 1.0.8 + + characters: 1.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.19.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.16.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + flutter_driver: + sdk: flutter + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: 5.0.0 + integration_test: + sdk: flutter + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. + + async: 2.12.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + file: 7.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.8 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 3.0.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 3.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + lints: 5.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.17 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.9.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.12.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + sync_http: 0.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.7.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 14.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webdriver: 3.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/to/resolution-aware-images + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/to/asset-from-package + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/to/font-from-package + +# PUBSPEC CHECKSUM: 7b61 diff --git a/dev/integration_tests/display_cutout_rotation/test_driver/display_cutout_test_test.dart b/dev/integration_tests/display_cutout_rotation/test_driver/display_cutout_test_test.dart new file mode 100644 index 0000000000..e8ca40aa99 --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/test_driver/display_cutout_test_test.dart @@ -0,0 +1,106 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// ignore_for_file: avoid_print + +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter_driver/flutter_driver.dart'; + +// display_cutout needs a custom driver becuase cutout manipulations needs to be +// done to a device/emulator in order for the tests to pass. +Future main() async { + if (!(Platform.isLinux || Platform.isMacOS)) { + // Not a fundemental limitation, developer shortcut. + print('This test must be run on a POSIX host. Skipping...'); + return; + } + final bool adbExists = Process.runSync('which', ['adb']).exitCode == 0; + if (!adbExists) { + print(r'This test needs ADB to exist on the $PATH.'); + exitCode = 1; + return; + } + // Test requires developer settings added in 28 and behavior added in 30 + final ProcessResult checkApiLevel = Process.runSync('adb', [ + 'shell', + 'getprop', + 'ro.build.version.sdk', + ]); + final String apiStdout = checkApiLevel.stdout.toString(); + // Api level 30 or higher. + if (apiStdout.startsWith('2') || apiStdout.startsWith('1') || apiStdout.length == 1) { + print('This test must be run on api 30 or higher. Skipping...'); + return; + } + // Developer settings are required on target device for cutout manipulation. + bool shouldResetDevSettings = false; + final ProcessResult checkDevSettingsResult = Process.runSync('adb', [ + 'shell', + 'settings', + 'get', + 'global', + 'development_settings_enabled', + ]); + if (checkDevSettingsResult.stdout.toString().startsWith('0')) { + print('Enabling developer settings...'); + // Developer settings not enabled, enable them and mark that the origional + // state should be restored after. + shouldResetDevSettings = true; + Process.runSync('adb', [ + 'shell', + 'settings', + 'put', + 'global', + 'development_settings_enabled', + '1', + ]); + } + // Assumption of diplay_cutout_test.dart is that there is a "tall" notch. + print('Adding Synthetic notch...'); + Process.runSync('adb', [ + 'shell', + 'cmd', + 'overlay', + 'enable', + 'com.android.internal.display.cutout.emulation.tall', + ]); + print('Starting test.'); + try { + final FlutterDriver driver = await FlutterDriver.connect(); + final String data = await driver.requestData(null, timeout: const Duration(minutes: 1)); + await driver.close(); + final Map result = jsonDecode(data) as Map; + print('Test finished!'); + print(result); + exitCode = result['result'] == 'true' ? 0 : 1; + } catch (e) { + print(e); + exitCode = 1; + } finally { + print('Removing Synthetic notch...'); + Process.runSync('adb', [ + 'shell', + 'cmd', + 'overlay', + 'disable', + 'com.android.internal.display.cutout.emulation.tall', + ]); + print('Reverting Adb changes...'); + if (shouldResetDevSettings) { + print('Disabling developer settings...'); + Process.runSync('adb', [ + 'shell', + 'settings', + 'put', + 'global', + 'development_settings_enabled', + '0', + ]); + } + } + return; +}