Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/example app android 14 #1919

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .github/workflows/test-android-14-device.yaml
bartekpacia marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: test android device

on:
workflow_dispatch:
schedule:
- cron: '30 21 * * *'

jobs:
run_tests:
name: Flutter ${{ matrix.flutter-version }} on ${{ matrix.os }} ${{ matrix.os_version }}
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
SLACK_MESSAGE_TITLE: Flutter ${{ matrix.flutter-version }} on ${{ matrix.os }} ${{ matrix.os_version }}
TESTS_EXIT_CODE: ${{ steps.tests_step.outputs.TESTS_EXIT_CODE }}
EXCLUDED_TESTS: ${{ steps.set_excluded_tests.outputs.EXCLUDED_TESTS }}
URL_TO_DETAILS: ${{ steps.tests_step.outputs.URL_TO_DETAILS }}

strategy:
fail-fast: false
matrix:
flutter-version: ['3.16.x']
flutter-channel: ['stable']
device_model: ['shiba']
os: ['Android API']
os_version: ['34']

defaults:
run:
working-directory: packages/patrol/example

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY_JSON }}'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Gradle cache
uses: gradle/gradle-build-action@v2
with:
generate-job-summary: false

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ matrix.flutter-version }}
channel: ${{ matrix.flutter-channel }}

- name: Preload Flutter artifacts
run: flutter precache --android

- name: Set up Melos and activate workspace
working-directory: .
run: |
dart pub global activate melos
melos bootstrap

- name: Set up Patrol CLI
working-directory: packages/patrol_cli
run: dart pub global activate --source path . && patrol

- name: Generate Gradle wrapper
run: flutter build apk --config-only

- name: Set tests to exclude
id: set_excluded_tests
run: |
TESTS_TO_EXCLUDE="service_airplane_mode_test,\
service_bluetooth_test"

target_paths=""
for target in $(echo $TESTS_TO_EXCLUDE | tr ',' '\n'); do
target_paths+="integration_test/${target}.dart,"
done
target_paths="${target_paths%,}"

echo "EXCLUDED_TESTS=$TESTS_TO_EXCLUDE" >> "$GITHUB_OUTPUT"
echo "EXCLUDED_TESTS=$target_paths" >> "$GITHUB_ENV"

- name: patrol build android
run: patrol build android --exclude ${{ env.EXCLUDED_TESTS }} --verbose

- name: Upload APKs to Firebase Test Lab and wait for tests to finish
id: tests_step
env:
ANDROID_DEVICE_MODEL: ${{ matrix.device_model }}
ANDROID_DEVICE_VERSION: ${{ matrix.os_version }}
run: |
set +e
output="$(./run_android_testlab 2>&1)"
TESTS_EXIT_CODE=$?
set -e

echo "$output"

# Extract the last link using grep, tail, and sed, and write it to Github Summmary
link="$(echo "$output" | grep -o 'https://[^ ]*' | tail -1 | sed 's/\[//;s/\]//')"
echo "[Test details on Firebase Test Lab]($link) (LeanCode members only)" >> "$GITHUB_STEP_SUMMARY"

echo "URL_TO_DETAILS=$link" >> "$GITHUB_OUTPUT"
echo "TESTS_EXIT_CODE=$TESTS_EXIT_CODE" >> "$GITHUB_OUTPUT"
exit $TESTS_EXIT_CODE

call_send_slack_message:
name: Notify on Slack
uses: ./.github/workflows/send-slack-message.yaml
needs: run_tests
if: always()
with:
TESTS_EXIT_CODE: ${{ needs.run_tests.outputs.TESTS_EXIT_CODE }}
SLACK_MESSAGE_TITLE: ${{ needs.run_tests.outputs.SLACK_MESSAGE_TITLE }}
EXCLUDED_TESTS: ${{ needs.run_tests.outputs.EXCLUDED_TESTS }}
URL_TO_DETAILS: ${{ needs.run_tests.outputs.URL_TO_DETAILS }}
secrets: inherit
39 changes: 26 additions & 13 deletions packages/patrol/example/android/app/src/main/AndroidManifest.xml
piotruela marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="pl.leancode.patrol.example">
xmlns:tools="http://schemas.android.com/tools" package="pl.leancode.patrol.example">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

<application
android:label="example"
Expand All @@ -31,14 +33,25 @@
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:exported="false"
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:exported="false"
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2"/>
android:value="2" />
</application>
</manifest>
</manifest>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I overlooked it. Fixing now

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ void main() {
await $.native.grantPermissionWhenInUse();
}

// Android 14+ requires additional permission to schedule notifications
try {
await $.native.tap(
Selector(text: 'Allow setting alarms and reminders'),
);
bartekpacia marked this conversation as resolved.
Show resolved Hide resolved
await $.native.pressBack();
} on PatrolActionException catch (_) {
// ignore
}

await $('Show in a few seconds').tap();
await $.native.pressHome();
await $.native.openNotifications();
Expand Down
4 changes: 4 additions & 0 deletions packages/patrol/example/lib/notifications_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestNotificationsPermission();
await _notificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestExactAlarmsPermission();
}(),
);
}
Expand Down
Loading