Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Skip Pull Request Checklist:
swift testCodex generated the code, manually validated from a fuse app on android + ios
Summary
Lock-screen controls during remote playback
This change lets the app attach its Android
MediaSessionto a foreground notification, so Android can show media controls on a locked screen (e.g. A music app playing in the background). The app supplies the media title, playback state, and handlers for controls such as play, pause, and seek. SkipDevice keeps the customized notification visible while ordinary requests start and end. The app can refresh it when playback changes and remove the customization when casting ends.Source files
Sources/SkipDevice/BackgroundActivity.swift,Sources/SkipDevice/Skip/AndroidBackgroundActivityNotifications.kt, andREADME.mdTests
customizedActivityStartsFirstAndEndsFirstandcustomizedActivityStartsLastAndEndsLastinTests/SkipDeviceTests/Skip/AndroidBackgroundActivityNotificationsTest.kt. They check which notification stays visible, refreshed content, default restoration, and that refreshing an inactive ID sends no service intent.Tests/SkipDeviceTests/Skip/AndroidManifest.xmlwith the test service permissions andTests/SkipDeviceTests/Skip/skip.ymlto run the Robolectric tests in the JVM suite.Background work could begin before Android confirmed startup
This PR also improves the existing service for any background activity.
BackgroundActivity.beginused to return as soon as it sent the service intent. It now waits for foreground promotion and any requested partial CPU wake lock, and throws on failure or a ten-second acknowledgement timeout. Concurrent requests share the lock and combine their service types. Callers can checkBackgroundActivity.androidStatus(for: id)after startup to detect a service timeout or destruction.Source files
Sources/SkipDevice/BackgroundActivity.swiftandREADME.mdTests
Tests/SkipDeviceTests/SkipDeviceTests.swift.testBackgroundActivityRequestDefaultsandtestBackgroundActivityRequestCustomValuescheck that the wake lock is opt-in. The newtestAndroidStatusForUnknownActivitychecks the Android and Apple results for an unknown identifier.Tests/SkipDeviceTests/Skip/AndroidBackgroundActivityNotificationsTest.ktcheck running and ended status, combined service types, and lock ownership as requests finish.Usage Example
In transpiled Swift, call this helper on the Android main thread with the app's media-session token. Pass the casting request's
notificationIDas the first argument.API Shape
AndroidBackgroundActivityNotifications.register(id, customize),refresh(id), andremove(id), callable from Kotlin or transpiled Swift. The callback accepts aNotificationCompat.Builderand returns aNotification. A media app can attach a session through this general notification callback.BackgroundActivityRequest.requiresAndroidWakeLock: Bool(defaultfalse) andBackgroundActivity.androidStatus(for identifier: String) -> String. Status isunavailableon Apple platforms.Testing
Ran from a clean checkout. macOS XCTest passed 10 tests, Robolectric passed 13, and a Samsung SM-S721U running Android 17 passed 11. Each suite skipped the existing location test. Both notification scenarios ran under Robolectric on API 35. The README's Swift media-notification example also compiled for Android in a separate consumer module.
Limitations
Hosts that request a wake lock must declare
android.permission.WAKE_LOCK. Media sessions and playback actions belong to the host app. Hardware verification of lock-screen playback controls is outside this test coverage.