Skip to content

Add legacy service preservation and feature flag toggle infrastructure#5145

Merged
sztomek merged 5 commits intomainfrom
media3/05-legacy-service
Apr 8, 2026
Merged

Add legacy service preservation and feature flag toggle infrastructure#5145
sztomek merged 5 commits intomainfrom
media3/05-legacy-service

Conversation

@sztomek
Copy link
Copy Markdown
Contributor

@sztomek sztomek commented Mar 18, 2026

Description

This is the 5th step of the media3 migration. This PR preserves the existing PlaybackService logic by extracting it into LegacyPlaybackService (a MediaBrowserServiceCompat) and its thin LegacyAutoPlaybackService subclass, so the old service can continue to run alongside the new Media3 implementation. A PlaybackServiceToggle utility was added to resolve the correct service class based on the MEDIA3_SESSION feature flag, enabling a safe runtime switch between legacy and Media3 paths.
A ProGuard keep rule was also added to ensure the legacy service class isn't stripped during minification.

Testing Instructions

Just review the code since the new components are not wired up yet

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

@sztomek sztomek added this to the 8.10 milestone Mar 18, 2026
@sztomek sztomek requested a review from a team as a code owner March 18, 2026 10:35
@sztomek sztomek removed the request for review from a team March 18, 2026 10:35
@sztomek sztomek requested a review from MiSikora March 18, 2026 10:35
@sztomek sztomek added the [Type] Enhancement Improve an existing feature. label Mar 18, 2026
Copilot AI review requested due to automatic review settings March 18, 2026 10:35
@sztomek sztomek added the [Area] Playback Episode playback issue label Mar 18, 2026
@dangermattic
Copy link
Copy Markdown
Collaborator

dangermattic commented Mar 18, 2026

4 Warnings
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ Class LegacyPlaybackService is missing tests, but unit-tests-exemption label was set to ignore this.
⚠️ Class MediaControllerCallback is missing tests, but unit-tests-exemption label was set to ignore this.
⚠️ Class SleepTimerHandler is missing tests, but unit-tests-exemption label was set to ignore this.

Generated by 🚫 Danger

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR is part of the Media3 migration, preserving the existing MediaBrowserServiceCompat playback service implementation under new “legacy” service classes and adding a feature-flag-based toggle to switch between legacy and Media3 service components at runtime.

Changes:

  • Extracted legacy playback service logic into LegacyPlaybackService and added an automotive-specific LegacyAutoPlaybackService subclass.
  • Added PlaybackServiceToggle to enable/disable the appropriate service components based on the MEDIA3_SESSION feature flag.
  • Added a ProGuard keep rule intended to retain the legacy service during minification.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
proguard-rules.pro Adds a keep rule for the new legacy playback service class.
modules/services/repositories/.../PlaybackServiceToggle.kt Introduces runtime component enable/disable logic based on a feature flag.
modules/services/repositories/.../LegacyPlaybackService.kt New legacy MediaBrowserServiceCompat implementation extracted from existing playback service logic.
automotive/.../LegacyAutoPlaybackService.kt Automotive-specific legacy service subclass with refresh/pause behavior.

You can also share your feedback on Copilot code review. Take the survey.

@sztomek sztomek modified the milestones: 8.10, 8.9 Mar 20, 2026
@sztomek sztomek force-pushed the media3/04-session-callbacks branch from d85dfab to 4841ed3 Compare March 27, 2026 16:03
@sztomek sztomek force-pushed the media3/05-legacy-service branch from 7992866 to 08ef9b3 Compare March 27, 2026 16:04
@wpmobilebot wpmobilebot modified the milestones: 8.9, 8.10 Mar 30, 2026
@wpmobilebot
Copy link
Copy Markdown
Collaborator

Version 8.9 has now entered code-freeze, so the milestone of this PR has been updated to 8.10.

@sztomek sztomek force-pushed the media3/04-session-callbacks branch from 4841ed3 to 497b54c Compare March 31, 2026 17:21
Copilot AI review requested due to automatic review settings April 1, 2026 06:51
@sztomek sztomek force-pushed the media3/05-legacy-service branch from 08ef9b3 to da8949c Compare April 1, 2026 06:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR is part of the Media3 migration stack, extracting the existing PlaybackService (MediaBrowserServiceCompat) behavior into a preserved LegacyPlaybackService and adding a small utility to toggle which service component is enabled at runtime via the MEDIA3_SESSION feature flag.

Changes:

  • Add LegacyPlaybackService (legacy MediaBrowserServiceCompat implementation) and an automotive-specific LegacyAutoPlaybackService subclass.
  • Introduce PlaybackServiceToggle to enable/disable service components based on Feature.MEDIA3_SESSION.
  • Add an R8/ProGuard keep rule for LegacyPlaybackService.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
proguard-rules.pro Adds a keep rule for the legacy playback service class.
modules/services/repositories/.../PlaybackServiceToggle.kt Adds feature-flag-driven component enable/disable utility for swapping service implementations.
modules/services/repositories/.../LegacyPlaybackService.kt Introduces preserved legacy playback service logic (notifications, browsing, sleep timer).
automotive/.../LegacyAutoPlaybackService.kt Adds an automotive-specific legacy service subclass mirroring the existing automotive service behavior.

@sztomek sztomek force-pushed the media3/05-legacy-service branch from da8949c to bc1dd94 Compare April 1, 2026 17:55
@sztomek sztomek force-pushed the media3/04-session-callbacks branch from f992988 to 376454a Compare April 1, 2026 20:26
Copilot AI review requested due to automatic review settings April 1, 2026 20:28
@sztomek sztomek force-pushed the media3/05-legacy-service branch from bc1dd94 to 3327e0e Compare April 1, 2026 20:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

@sztomek sztomek force-pushed the media3/04-session-callbacks branch from 376454a to 8eceb80 Compare April 2, 2026 10:56
@sztomek sztomek force-pushed the media3/05-legacy-service branch from 3327e0e to 09906b3 Compare April 2, 2026 10:56
Copilot AI review requested due to automatic review settings April 2, 2026 11:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented Apr 2, 2026

Project manifest changes for automotive

The following changes in the automotive's merged AndroidManifest.xml file were detected (build variant: release):

--- ./build/reports/diff_manifest/automotive/release/base_manifest.txt	2026-04-08 09:38:56.585481713 +0000
+++ ./build/reports/diff_manifest/automotive/release/head_manifest.txt	2026-04-08 09:39:00.335504706 +0000
@@ -105,6 +105,16 @@
                 <action android:name="android.media.browse.MediaBrowserService" />
             </intent-filter>
         </service>
+        <service
+            android:name="au.com.shiftyjelly.pocketcasts.LegacyAutoPlaybackService"
+            android:enabled="false"
+            android:exported="true"
+            android:foregroundServiceType="mediaPlayback"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.media.browse.MediaBrowserService" />
+            </intent-filter>
+        </service>
 
         <!-- services which are periodic or trigerred by the app automatically triggered, eg: can run in the background -->
         <service
@@ -127,10 +137,10 @@
                 android:name="androidx.lifecycle.ProcessLifecycleInitializer"
                 android:value="androidx.startup" />
             <meta-data
-                android:name="okhttp3.internal.platform.PlatformInitializer"
+                android:name="androidx.profileinstaller.ProfileInstallerInitializer"
                 android:value="androidx.startup" />
             <meta-data
-                android:name="androidx.profileinstaller.ProfileInstallerInitializer"
+                android:name="okhttp3.internal.platform.PlatformInitializer"
                 android:value="androidx.startup" />
         </provider>
 
@@ -433,21 +443,6 @@
         <uses-library
             android:name="androidx.window.sidecar"
             android:required="false" />
-        <uses-library
-            android:name="android.ext.adservices"
-            android:required="false" />
-
-        <meta-data
-            android:name="com.google.android.gms.version"
-            android:value="@integer/google_play_services_version" />
-
-        <service
-            android:name="com.google.android.datatransport.runtime.backends.TransportBackendDiscovery"
-            android:exported="false" >
-            <meta-data
-                android:name="backend:com.google.android.datatransport.cct.CctBackendFactory"
-                android:value="cct" />
-        </service>
 
         <receiver
             android:name="androidx.profileinstaller.ProfileInstallReceiver"
@@ -469,6 +464,21 @@
             </intent-filter>
         </receiver>
 
+        <uses-library
+            android:name="android.ext.adservices"
+            android:required="false" />
+
+        <meta-data
+            android:name="com.google.android.gms.version"
+            android:value="@integer/google_play_services_version" />
+
+        <service
+            android:name="com.google.android.datatransport.runtime.backends.TransportBackendDiscovery"
+            android:exported="false" >
+            <meta-data
+                android:name="backend:com.google.android.datatransport.cct.CctBackendFactory"
+                android:value="cct" />
+        </service>
         <service
             android:name="com.google.android.datatransport.runtime.scheduling.jobscheduling.JobInfoSchedulerService"
             android:exported="false"

Go to https://buildkite.com/automattic/pocket-casts-android/builds/16265/canvas?sid=019d6c6e-a5fc-4e9f-a34a-9bc631ed2672, click on the Artifacts tab and audit the files.

@sztomek sztomek force-pushed the media3/04-session-callbacks branch from 8eceb80 to 9c15b07 Compare April 8, 2026 08:25
@sztomek sztomek force-pushed the media3/05-legacy-service branch from a03231c to b3edfd8 Compare April 8, 2026 08:30
Base automatically changed from media3/04-session-callbacks to main April 8, 2026 09:07
Copilot AI review requested due to automatic review settings April 8, 2026 09:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated 7 comments.

sztomek and others added 5 commits April 8, 2026 11:26
Add SupervisorJob to LegacyPlaybackService coroutine context and
cancel it in onDestroy() so coroutines are properly cleaned up.
Fix misleading proguard comment to match the actual rule behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The class was introduced in this branch but the manifest entry was
deferred to 06d, causing lint to fail on branches 05 through 06c.
Register it now with android:enabled="false" — PlaybackServiceToggle
enables the correct service at runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@sztomek sztomek force-pushed the media3/05-legacy-service branch from 97409db to 2182d09 Compare April 8, 2026 09:31
@sztomek
Copy link
Copy Markdown
Contributor Author

sztomek commented Apr 8, 2026

recheck

@sztomek sztomek merged commit 7d7b1dc into main Apr 8, 2026
18 checks passed
@sztomek sztomek deleted the media3/05-legacy-service branch April 8, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Playback Episode playback issue [Type] Enhancement Improve an existing feature. unit-tests-exemption

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants