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!ia0vp^9w5xY3?!3`olAj~WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!h8bpbvhu0Wd6uZuB!w&u2PAxD2eNXD>P5D~Wn-+_Wa#27Xc zC?Zj|6r#X(-D3u$NCt}(Ms06KgJ4FxJVv{GM)!I~&n8Bnc94O7-Hd)cjDZswgC;Qs zO=b+9!WcT8F?0rF7!Uys2bs@gozCP?z~o%U|N3vA*22NaGQG zlg@K`O_XuxvZ&Ks^m&R!`&1=spLvfx7oGDKDwpwW`#iqdw@AL`7MR}m`rwr|mZgU`8P7SBkL78fFf!WnuYWm$5Z0 zNXhDbCv&49sM544K|?c)WrFfiZvCi9h0O)B3Pgg&ebxsLQ05GG~ AQ2+n{ literal 0 HcmV?d00001 diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..17987b79bb8a35cc66c3c1fd44f5a5526c1b78be GIT binary patch literal 442 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA3?vioaBc-sk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5Xx&nMcT!A!W`0S9QKQy;}1Cl^CgaH=;G9cpY;r$Q>i*pfB zP2drbID<_#qf;rPZx^FqH)F_D#*k@@q03KywUtLX8Ua?`H+NMzkczFPK3lFz@i_kW%1NOn0|D2I9n9wzH8m|-tHjsw|9>@K=iMBhxvkv6m8Y-l zytQ?X=U+MF$@3 zt`~i=@j|6y)RWMK--}M|=T`o&^Ni>IoWKHEbBXz7?A@mgWoL>!*SXo`SZH-*HSdS+ yn*9;$7;m`l>wYBC5bq;=U}IMqLzqbYCidGC!)_gkIk_C@Uy!y&wkt5C($~2D>~)O*cj@FGjOCM)M>_ixfudOh)?xMu#Fs z#}Y=@YDTwOM)x{K_j*Q;dPdJ?Mz0n|pLRx{4n|)f>SXlmV)XB04CrSJn#dS5nK2lM zrZ9#~WelCp7&e13Y$jvaEXHskn$2V!!DN-nWS__6T*l;H&Fopn?A6HZ-6WRLFP=R` zqG+CE#d4|IbyAI+rJJ`&x9*T`+a=p|0O(+s{UBcyZdkhj=yS1>AirP+0R;mf2uMgM zC}@~JfByORAh4SyRgi&!(cja>F(l*O+nd+@4m$|6K6KDn_&uvCpV23&>G9HJp{xgg zoq1^2_p9@|WEo z*X_Uko@K)qYYv~>43eQGMdbiGbo>E~Q& zrYBH{QP^@Sti!`2)uG{irBBq@y*$B zi#&(U-*=fp74j)RyIw49+0MRPMRU)+a2r*PJ$L5roHt2$UjExCTZSbq%V!HeS7J$N zdG@vOZB4v_lF7Plrx+hxo7(fCV&}fHq)$ 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!ia0vp^6F``Q8Ax83A=Cw=BuiW)N`mv#O3D+9QW+dm@{>{( zJaZG%Q-e|yQz{EjrrIztFa`(sgt!6~Yi|1%a`XoT0ojZ}lNrNjb9xjc(B0U1_% zz5^97Xt*%oq$rQy4?0GKNfJ44uvxI)gC`h-NZ|&0-7(qS@?b!5r36oQ}zyZrNO3 zMO=Or+<~>+A&uN&E!^Sl+>xE!QC-|oJv`ApDhqC^EWD|@=#J`=d#Xzxs4ah}w&Jnc z$|q_opQ^2TrnVZ0o~wh<3t%W&flvYGe#$xqda2bR_R zvPYgMcHgjZ5nSA^lJr%;<&0do;O^tDDh~=pIxA#coaCY>&N%M2^tq^U%3DB@ynvKo}b?yu-bFc-u0JHzced$sg7S3zqI(2 z#Km{dPr7I=pQ5>FuK#)QwK?Y`E`B?nP+}U)I#c1+FM*1kNvWG|a(TpksZQ3B@sD~b zpQ2)*V*TdwjFOtHvV|;OsiDqHi=6%)o4b!)x$)%9pGTsE z-JL={-Ffv+T87W(Xpooq<`r*VzWQcgBN$$`u}f>-ZQI1BB8ykN*=e4rIsJx9>z}*o zo~|9I;xof 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 zcmb`G{WsKk6vsdJTdFg%tJav9_E4vzrOaqkWF|A724Nly!y+?N9`YV6wZ}5(X(D_N(?!*n3`|_r0Hc?=PQw&*vnU?QTFY zB_MsH|!j$PP;I}?dppoE_gA(4uc!jV&0!l7_;&p2^pxNo>PEcNJv za5_RT$o2Mf!<+r?&EbHH6nMoTsDOa;mN(wv8RNsHpG)`^ymG-S5By8=l9iVXzN_eG%Xg2@Xeq76tTZ*dGh~Lo9vl;Zfs+W#BydUw zCkZ$o1LqWQO$FC9aKlLl*7x9^0q%0}$OMlp@Kk_jHXOjofdePND+j!A{q!8~Jn+s3 z?~~w@4?egS02}8NuulUA=L~QQfm;MzCGd)XhiftT;+zFO&JVyp2mBww?;QByS_1w! zrQlx%{^cMj0|Bo1FjwY@Q8?Hx0cIPF*@-ZRFpPc#bBw{5@tD(5%sClzIfl8WU~V#u zm5Q;_F!wa$BSpqhN>W@2De?TKWR*!ujY;Yylk_X5#~V!L*Gw~;$%4Q8~Mad z@`-kG?yb$a9cHIApZDVZ^U6Xkp<*4rU82O7%}0jjHlK{id@?-wpN*fCHXyXh(bLt* zPc}H-x0e4E&nQ>y%B-(EL=9}RyC%MyX=upHuFhAk&MLbsF0LP-q`XnH78@fT+pKPW zu72MW`|?8ht^tz$iC}ZwLp4tB;Q49K!QCF3@!iB1qOI=?w z7In!}F~ij(18UYUjnbmC!qKhPo%24?8U1x{7o(+?^Zu0Hx81|FuS?bJ0jgBhEMzf< zCgUq7r2OCB(`XkKcN-TL>u5y#dD6D!)5W?`O5)V^>jb)P)GBdy%t$uUMpf$SNV31$ zb||OojAbvMP?T@$h_ZiFLFVHDmbyMhJF|-_)HX3%m=CDI+ID$0^C>kzxprBW)hw(v zr!Gmda);ICoQyhV_oP5+C%?jcG8v+D@9f?Dk*!BxY}dazmrT@64UrP3hlslANK)bq z$67n83eh}OeW&SV@HG95P|bjfqJ7gw$e+`Hxo!4cx`jdK1bJ>YDSpGKLPZ^1cv$ek zIB?0S<#tX?SJCLWdMd{-ME?$hc7A$zBOdIJ)4!KcAwb=VMov)nK;9z>x~rfT1>dS+ zZ6#`2v@`jgbqq)P22H)Tx2CpmM^o1$B+xT6`(v%5xJ(?j#>Q$+rx_R|7TzDZe{J6q zG1*EcU%tE?!kO%^M;3aM6JN*LAKUVb^xz8-Pxo#jR5(-KBeLJvA@-gxNHx0M-ZJLl z;#JwQoh~9V?`UVo#}{6ka@II>++D@%KqGpMdlQ}?9E*wFcf5(#XQnP$Dk5~%iX^>f z%$y;?M0BLp{O3a(-4A?ewryHrrD%cx#Q^%KY1H zNre$ve+vceSLZcNY4U(RBX&)oZn*Py()h)XkE?PL$!bNb{N5FVI2Y%LKEm%yvpyTP z(1P?z~7YxD~Rf<(a@_y` literal 0 HcmV?d00001 diff --git a/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/values-night/styles.xml b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 0000000000..f3ab3e83cd --- /dev/null +++ b/dev/integration_tests/display_cutout_rotation/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,22 @@ + + + + + + + + + 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; +}