Skip to content

Migrate Android Auto implementation to androidx.car.app:app:1.7.0 - #2008

Open
rainman74 wants to merge 1 commit into
DrKLO:masterfrom
rainman74:fix/android-auto-1.7
Open

Migrate Android Auto implementation to androidx.car.app:app:1.7.0#2008
rainman74 wants to merge 1 commit into
DrKLO:masterfrom
rainman74:fix/android-auto-1.7

Conversation

@rainman74

@rainman74 rainman74 commented Aug 3, 2026

Copy link
Copy Markdown

What

Aligns the Android Auto code path in DrKLO/Telegram with the androidx.car.app:app:1.7.0 contract, and adds the MusicPlayerService -> TelegramMediaSession publish hooks so that the CarApp / MediaBrowserService surface is in sync with the phone player.

Why

The 1.7.x line of androidx.car.app tightened the contract that CarAppService implementations have to satisfy:

  • ConversationItem.validateSender() now requires every Person passed in to have a non-null key. A missing key throws at runtime.
  • The new contract needs androidx.media:1.7.0 (for the android.support.v4.media.* compat shims) and androidx.lifecycle:lifecycle-runtime:2.7.0 (for DefaultLifecycleObserver used by HomeScreen).
  • minCarApiLevel has to be bumped from 5 to 7.

The phone player's MusicPlayerService keeps its own MediaSessionCompat, but the CarApp / MediaBrowserService surface that Android Auto uses is backed by TelegramMediaSession. Without explicitly publishing playback state and metadata to TelegramMediaSession, the Android Auto side has no view of what the phone player is doing. The same goes for STATE_STOPPED on service teardown.

How

6 files changed (+23/-10 vs master):

Build

  • TMessagesProj/build.gradle - bump androidx.car.app:app:1.4.0 -> 1.7.0; drop app-projected:1.4.0; add androidx.media:1.7.0 and androidx.lifecycle:lifecycle-runtime:2.7.0

Manifest / config

  • TMessagesProj/src/main/AndroidManifest.xml - uncomment the CarApp <meta-data> + <service> block, bump minCarApiLevel 5 -> 7
  • TMessagesProj/src/main/res/xml/automotive_app_desc.xml - add <uses name="media"/>

Code

  • TMessagesProj/src/main/java/org/telegram/messenger/car/HomeScreen.java - the senderBuilder.setName("") empty-fallback branch in buildCarMessage now also calls setKey("d" + dialogId), so every Person handed to a ConversationItem has a key.
  • TMessagesProj/src/main/java/org/telegram/messenger/MusicPlayerService.java - after every mediaSession.setPlaybackState() and mediaSession.setMetadata(), also publishPlaybackState() / publishMetadata() on TelegramMediaSession; on onDestroy publish STATE_STOPPED when nothing is playing.
  • TMessagesProj/src/main/java/org/telegram/messenger/TelegramMediaSession.java - publishPlaybackState now merges getAvailableActions() into the state so Android Auto renders the full action set.

Notes

  • The androidx.media:1.7.0 artifact keeps its classes under the legacy android.support.v4.media.* package for binary compatibility - no import migration needed.
  • The MusicPlayerService / TelegramMediaSession changes are applied as targeted hunks on top of upstream master, not as a verbatim file copy, because upstream master carries additional MIUI-specific lock-screen logic in supportLockScreenControls and an accountLogin handler in didReceivedNotification that the NagramX-derived forks do not have. Only the contract-alignment hunks are taken; the rest of the upstream file is preserved as-is.
  • This PR is intentionally limited in scope: it does not touch the upstream accountLogin handler in MusicPlayerService (which is the NagramX-specific quirk that is being removed there). If upstream later wants to follow the same removal, that should be a separate change with its own discussion.
  • Final diff against master: 6 files, 23 insertions(+), 10 deletions(-).

rainman74 added a commit to rainman74/NagramX that referenced this pull request Aug 13, 2026
Ports the missing pieces from DrKLO/Telegram#2008 into risin42/NagramX:
align the Android Auto code path with the androidx.car.app:app:1.7.0
contract that the rest of the codebase already assumes.

This repo already pins androidx.car.app:app:1.7.0 (and app-projected:1.7.0),
so the dependency bump itself is in place. What's missing is the rest
of the 1.7.x contract that the upstream PR bundled: the two transitive
deps (androidx.media, androidx.lifecycle), the manifest side, the
automotive_app_desc.xml template category, and the Person setKey
guarantee in HomeScreen that the 1.7.x ConversationItem.validateSender()
requires.

The AndroidX media-compat artifact androidx.media:media:1.7.0 keeps its
classes under the legacy android.support.v4.media.* package for binary
compatibility reasons — the import migration to androidx.media.* is
NOT applied here (it would reference non-existent classes). Only the
new transitive dependency is added; existing android.support.v4.media.*
imports are left as-is.

Build / manifest
- add androidx.media:media:1.7.0 (AndroidX media session)
- add androidx.lifecycle:lifecycle-runtime:2.7.0 (DefaultLifecycleObserver)
- uncomment the entire CarAppService <meta-data> + <service> block in
  AndroidManifest.xml; bump minCarApiLevel 5 -> 7 (required by
  ConversationItem @RequiresCarApi(7))
- automotive_app_desc.xml: add <uses name="media"/> for the new
  CarAppService messaging category, keep notification and template

Code
- HomeScreen: ensure Person always carries a key, which the 1.7.x
  ConversationItem.validateSender() requires. Applied locally to the
  senderBuilder.setName("") branch in buildCarMessage, matching the
  upstream intent without touching the surrounding code (NagramX has
  a richer DefaultLifecycleObserver + NotificationCenter pipeline
  than the upstream).

NagramX-specific context
- NagramX already ships androidx.car.app:app:1.7.0 and
  app-projected:1.7.0; the dependency swap itself is a no-op in this
  repo — only the two missing transitive dependencies and the
  manifest / xml / setKey changes are added.
- Final diff against dev: 4 files, 5 insertions(+), 4 deletions(-).

Refs: DrKLO/Telegram#2008
rainman74 added a commit to rainman74/NagramXF that referenced this pull request Aug 13, 2026
Ports DrKLO/Telegram PR #2008 (branch fix/android-auto-1.7,
commit 32ca438) into NagramXF.

The car-app code introduced in 12.8.0 already uses the 1.7.x API
(ConversationItem, ConversationCallback, CarMessage), but build.gradle
still pinned androidx.car.app:app:1.4.0, leaving the CarAppService code
path in an unbuildable state. Bump the dependency and align the rest of
the codebase with the 1.7.x contract.

The AndroidX media-compat artifact androidx.media:media:1.7.0 keeps its
classes under the legacy android.support.v4.media.* package for binary
compatibility reasons — the import migration to androidx.media.* is
NOT applied here (it would reference non-existent classes). Only the
new transitive dependency is added; existing android.support.v4.media.*
imports are left as-is.

Build / manifest
- androidx.car.app:app 1.4.0 -> 1.7.0
- drop androidx.car.app:app-projected (1.4-era AAR, unused in 1.7+)
- add androidx.media:media:1.7.0 (AndroidX media session)
- add androidx.lifecycle:lifecycle-runtime:2.7.0 (DefaultLifecycleObserver)
- minCarApiLevel 5 -> 7 (required by ConversationItem @RequiresCarApi(7))
- automotive_app_desc.xml: add 'media' for the new CarAppService
  messaging category, keep 'template' for the new category, keep
  'notification' for the regular notification path

Code
- HomeScreen: ensure Person always carries a key, which the 1.7.x
  ConversationItem.validateSender() requires.

NagramXF-specific context
- NagramXF already ships androidx.mediarouter:mediarouter:1.8.0 (upstream
  PR also bumps it to 1.7.0; 1.8.0 is the patch above and is left as-is).
- The car-app metadata block in AndroidManifest.xml was entirely
  commented out in NagramXF; this commit uncomments it and bumps
  minCarApiLevel from 5 to 7 alongside the dependency bump.
- Final diff against dev: 4 files, 7 insertions(+), 7 deletions(-).

Refs: DrKLO/Telegram#2008
@rainman74
rainman74 force-pushed the fix/android-auto-1.7 branch from 32ca438 to 43c3a52 Compare August 13, 2026 10:04
@rainman74

Copy link
Copy Markdown
Author

Update: corrected the import migration in commit 43c3a52e.

The original commit 32ca438 bumped androidx.media:media:1.7.0 and migrated the imports to androidx.media.*, but that artifact does not publish its MediaSessionCompat / MediaDescriptionCompat / MediaMetadataCompat / RatingCompat / MediaControllerCompat / PlaybackStateCompat classes under androidx.media.* — they stay under the legacy android.support.v4.media.* package for binary-compatibility reasons. Only the newer AudioAttributesCompat / AudioFocusRequestCompat / VolumeProviderCompat family is in the androidx.media.* package.

Verified by downloading the actual androidx.media:media:1.7.0 AAR from dl.google.com and listing the classes.jar entries:

  • android.support.v4.media.*226 classes (including MediaSessionCompat, MediaDescriptionCompat, MediaMetadataCompat, RatingCompat, MediaBrowserCompat, PlaybackStateCompat, MediaControllerCompat)
  • androidx.media.*94 classes (only AudioAttributesCompat, AudioAttributesImpl*, AudioFocusRequestCompat, VolumeProviderCompat family)

So the original import migration would not have compiled.

Fix: force-pushed commit 43c3a52e reverts the seven import files back to android.support.v4.media.*. The transitive androidx.media:media:1.7.0 dependency stays (it is required for the dependency declaration of the manifest + lifecycle observer); we just don't migrate the imports.

Final diff vs dev: 4 files, +7/-7 (the seven import-migration files cancel out vs. master).

rainman74 added a commit to rainman74/NagramX that referenced this pull request Aug 14, 2026
…ar.app:1.7.0

Aligns the Android Auto code path with the androidx.car.app:app:1.7.0
contract that the rest of the codebase already assumes. Combines the
transitive dependency and manifest pieces from DrKLO/Telegram#2008 with
the MediaPlayerService/MediaSession integration that risin42 added in
ec956e3 ("fix: Android Auto support", co-authored by rainman74).

The AndroidX media-compat artifact androidx.media:media:1.7.0 keeps its
classes under the legacy android.support.v4.media.* package for binary
compatibility reasons - the import migration to androidx.media.* is
NOT applied here (it would reference non-existent classes). Only the
new transitive dependency is added; existing android.support.v4.media.*
imports are left as-is.

Build
- add androidx.media:media:1.7.0 (AndroidX media session)
- add androidx.lifecycle:lifecycle-runtime:2.7.0 (DefaultLifecycleObserver)

Manifest / config
- uncomment the CarAppService <meta-data> + <service> block in
  AndroidManifest.xml; bump minCarApiLevel 5 -> 7 (required by
  ConversationItem @RequiresCarApi(7))
- automotive_app_desc.xml: add <uses name="media"/> for the new
  CarAppService media category; keep notification and template

Code
- HomeScreen: ensure Person always carries a key, which the 1.7.x
  ConversationItem.validateSender() requires. Applied locally to the
  senderBuilder.setName("") branch in buildCarMessage, matching the
  upstream intent without touching the surrounding code (NagramX has
  a richer DefaultLifecycleObserver + NotificationCenter pipeline
  than the upstream).
- MusicPlayerService: after every mediaSession.setPlaybackState() and
  mediaSession.setMetadata(), also publish the same state / metadata
  to TelegramMediaSession so the MediaBrowserService is in sync with
  the phone player. On onDestroy, publish STATE_STOPPED if nothing is
  playing. Without this, the Android Auto media surface had no view of
  what the phone player was doing.
- TelegramMediaSession.publishPlaybackState: merge getAvailableActions()
  (skip next/prev, set shuffle, etc.) into the state before publishing,
  so Android Auto renders the full action set.

NagramX-specific context
- NagramX already ships androidx.car.app:app:1.7.0 and
  app-projected:1.7.0; the dependency swap itself is a no-op in this
  repo - only the two missing transitive dependencies are added.
- Final diff against dev: 6 files, 26 insertions(+), 13 deletions(-).

Refs: DrKLO/Telegram#2008
      risin42@ec956e39
rainman74 added a commit to rainman74/NagramXF that referenced this pull request Aug 14, 2026
…ar.app:1.7.0

Aligns the Android Auto code path with the androidx.car.app:app:1.7.0
contract. Combines the dependency bump and manifest pieces from
DrKLO/Telegram#2008 with the MediaPlayerService/MediaSession integration
that risin42 added in ec956e3 ("fix: Android Auto support",
co-authored by rainman74).

The AndroidX media-compat artifact androidx.media:media:1.7.0 keeps its
classes under the legacy android.support.v4.media.* package for binary
compatibility reasons - the import migration to androidx.media.* is
NOT applied here (it would reference non-existent classes). Only the
new transitive dependency is added; existing android.support.v4.media.*
imports are left as-is.

Build
- bump androidx.car.app:app:1.4.0 -> 1.7.0
- drop androidx.car.app:app-projected:1.4.0 (NagramXF pre-1.7.0 used the
  projected variant; the 1.7.0 line no longer needs it as a separate
  dependency)
- add androidx.media:media:1.7.0 (AndroidX media session)
- add androidx.lifecycle:lifecycle-runtime:2.7.0 (DefaultLifecycleObserver)

Manifest / config
- uncomment the CarAppService <meta-data> + <service> block in
  AndroidManifest.xml; bump minCarApiLevel 5 -> 7 (required by
  ConversationItem @RequiresCarApi(7))
- automotive_app_desc.xml: add <uses name="media"/> for the new
  CarAppService media category; keep notification and template

Code
- HomeScreen: ensure Person always carries a key, which the 1.7.x
  ConversationItem.validateSender() requires. Applied locally to the
  senderBuilder.setName("") branch in buildCarMessage, matching the
  upstream intent without touching the surrounding code (NagramXF has
  a richer DefaultLifecycleObserver + NotificationCenter pipeline
  than the upstream).
- MusicPlayerService: after every mediaSession.setPlaybackState() and
  mediaSession.setMetadata(), also publish the same state / metadata
  to TelegramMediaSession so the MediaBrowserService is in sync with
  the phone player. On onDestroy, publish STATE_STOPPED if nothing is
  playing. Without this, the Android Auto media surface had no view of
  what the phone player was doing.
- TelegramMediaSession.publishPlaybackState: merge getAvailableActions()
  (skip next/prev, set shuffle, etc.) into the state before publishing,
  so Android Auto renders the full action set.

NagramXF-specific context
- NagramXF pre-1.7.0 pinned androidx.car.app:app:1.4.0 +
  app-projected:1.4.0; this PR bumps both lines to 1.7.0 (the
  app-projected artifact is no longer needed in the 1.7.0 line).
- Final diff against dev: 6 files, 25 insertions(+), 11 deletions(-).

Refs: DrKLO/Telegram#2008
      risin42/NagramX@ec956e39
Updates the Android Auto code path to the androidx.car.app:app:1.7.0
contract. The bulk of this PR is the 1.7.0 contract alignment from
DrKLO#2008; the MediaPlayerService / TelegramMediaSession
integration is a follow-up added by risin42 in
risin42/NagramX@ec956e3 ("fix: Android Auto support", co-authored by
rainman74).

The AndroidX media-compat artifact androidx.media:media:1.7.0 keeps its
classes under the legacy android.support.v4.media.* package for binary
compatibility reasons - the import migration to androidx.media.* is
NOT applied here (it would reference non-existent classes). Only the
new transitive dependency is added; existing android.support.v4.media.*
imports are left as-is.

Build
- bump androidx.car.app:app:1.4.0 -> 1.7.0
- drop androidx.car.app:app-projected:1.4.0 (upstream pre-1.7.0 used
  the projected variant; the 1.7.0 line no longer needs it as a
  separate dependency)
- add androidx.media:media:1.7.0 (AndroidX media session)
- add androidx.lifecycle:lifecycle-runtime:2.7.0 (DefaultLifecycleObserver)

Manifest / config
- uncomment the CarAppService <meta-data> + <service> block in
  AndroidManifest.xml; bump minCarApiLevel 5 -> 7 (required by
  ConversationItem @RequiresCarApi(7))
- automotive_app_desc.xml: add <uses name="media"/> for the new
  CarAppService media category; keep notification and template

Code
- HomeScreen: ensure Person always carries a key, which the 1.7.x
  ConversationItem.validateSender() requires. Applied locally to the
  senderBuilder.setName("") branch in buildCarMessage, matching the
  upstream intent without touching the surrounding code.
- MusicPlayerService: after every mediaSession.setPlaybackState() and
  mediaSession.setMetadata(), also publish the same state / metadata
  to TelegramMediaSession so the MediaBrowserService is in sync with
  the phone player. On onDestroy, publish STATE_STOPPED if nothing is
  playing. Without this, the Android Auto media surface had no view of
  what the phone player was doing.
- TelegramMediaSession.publishPlaybackState: merge getAvailableActions()
  (skip next/prev, set shuffle, etc.) into the state before publishing,
  so Android Auto renders the full action set.

Upstream-specific context
- This PR adds the risin42/NagramX@ec956e3 MediaPlayerService /
  TelegramMediaSession integration on top of the original DrKLO#2008
  contract alignment, so all three repos (upstream / NagramXF / NagramX)
  are in sync. The ec956e3 version of MusicPlayerService.java is NOT
  copied verbatim because DrKLO's upstream code has additional
  MIUI-specific lock-screen logic and an accountLogin handler that
  NagramX does not carry; the four targeted hunks (publishPlaybackState
  after each setPlaybackState, publishMetadata after setMetadata, and
  STATE_STOPPED cleanup in onDestroy) are applied on top of DrKLO's
  current file instead.
- Final diff against master: 6 files, 23 insertions(+), 10 deletions(-).

Refs: risin42/NagramX@ec956e3
@rainman74
rainman74 force-pushed the fix/android-auto-1.7 branch 2 times, most recently from 3d36a93 to 145bd31 Compare August 15, 2026 10:39
iamfromreallife added a commit to iamfromreallife/Telegram that referenced this pull request Aug 15, 2026
iamfromreallife added a commit to iamfromreallife/Telegram that referenced this pull request Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant