Skip to content

Commit 145bd31

Browse files
committed
Migrate Android Auto implementation to androidx.car.app:app:1.7.0
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 #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 #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
1 parent 45ab8f4 commit 145bd31

6 files changed

Lines changed: 23 additions & 10 deletions

File tree

TMessagesProj/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ dependencies {
2727

2828
implementation 'com.google.android.gms:play-services-cast-framework:21.4.0'
2929
implementation "androidx.mediarouter:mediarouter:1.7.0"
30+
implementation "androidx.media:media:1.7.0"
31+
implementation "androidx.lifecycle:lifecycle-runtime:2.7.0"
3032

31-
implementation 'androidx.car.app:app:1.4.0'
32-
implementation 'androidx.car.app:app-projected:1.4.0'
33+
implementation 'androidx.car.app:app:1.7.0'
3334
implementation 'org.nanohttpd:nanohttpd:2.3.1'
3435

3536
compileOnly 'org.checkerframework:checker-qual:2.5.2'

TMessagesProj/src/main/AndroidManifest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@
672672

673673
<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" />
674674

675-
<!--
676675
<meta-data android:name="com.google.android.gms.car.notification.SmallIcon" android:resource="@drawable/ic_player" />
677676
<meta-data android:name="com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc" />
678677

@@ -688,8 +687,7 @@
688687

689688
<meta-data
690689
android:name="androidx.car.app.minCarApiLevel"
691-
android:value="5" />
692-
-->
690+
android:value="7" />
693691

694692
<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="face,barcode" />
695693

TMessagesProj/src/main/java/org/telegram/messenger/MusicPlayerService.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,9 @@ private void createNotification(MessageObject messageObject, boolean forBitmap)
526526
}
527527
}
528528

529-
mediaSession.setPlaybackState(playbackState.build());
529+
PlaybackStateCompat currentPlaybackState = playbackState.build();
530+
mediaSession.setPlaybackState(currentPlaybackState);
531+
TelegramMediaSession.getInstance(this).publishPlaybackState(currentPlaybackState);
530532
updateRepeatMode();
531533
updateShuffleMode();
532534
MediaMetadataCompat.Builder meta = new MediaMetadataCompat.Builder()
@@ -540,6 +542,7 @@ private void createNotification(MessageObject messageObject, boolean forBitmap)
540542
}
541543

542544
mediaSession.setMetadata(meta.build());
545+
TelegramMediaSession.getInstance(this).publishMetadata(messageObject, audioInfo, fullAlbumArt);
543546

544547
bldr.setVisibility(Notification.VISIBILITY_PUBLIC);
545548

@@ -749,7 +752,9 @@ private void updatePlaybackState(long seekTo) {
749752
NOTIFY_REPEAT, LocaleController.getString(R.string.RepeatSong), repeatIcon).build());
750753
}
751754
}
752-
mediaSession.setPlaybackState(playbackState.build());
755+
PlaybackStateCompat currentPlaybackState = playbackState.build();
756+
mediaSession.setPlaybackState(currentPlaybackState);
757+
TelegramMediaSession.getInstance(this).publishPlaybackState(currentPlaybackState);
753758
}
754759

755760
private void updateRepeatMode() {
@@ -822,6 +827,12 @@ public void onDestroy() {
822827
if (mediaSession != null) {
823828
mediaSession.release();
824829
}
830+
TelegramMediaSession sessionHolder = TelegramMediaSession.peekInstance();
831+
if (sessionHolder != null && MediaController.getInstance().getPlayingMessageObject() == null) {
832+
sessionHolder.publishPlaybackState(new PlaybackStateCompat.Builder()
833+
.setState(PlaybackStateCompat.STATE_STOPPED, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 0)
834+
.build());
835+
}
825836
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
826837
NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingDidSeek);
827838
NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingPlayStateChanged);

TMessagesProj/src/main/java/org/telegram/messenger/TelegramMediaSession.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@ public void publishMetadata(MessageObject messageObject, @Nullable AudioInfo aud
436436
}
437437

438438
public void publishPlaybackState(PlaybackStateCompat state) {
439-
session.setPlaybackState(state);
439+
session.setPlaybackState(new PlaybackStateCompat.Builder(state)
440+
.setActions(state.getActions() | getAvailableActions())
441+
.build());
440442
}
441443

442444
public long getAvailableActions() {

TMessagesProj/src/main/java/org/telegram/messenger/car/HomeScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private CarMessage buildCarMessage(MessageObject mo, long dialogId, boolean isGr
268268
} else if (chat != null) {
269269
senderBuilder.setName(chat.title != null ? chat.title : "").setKey("c" + chat.id);
270270
} else {
271-
senderBuilder.setName("");
271+
senderBuilder.setName("").setKey("d" + dialogId);
272272
}
273273

274274
return new CarMessage.Builder()

TMessagesProj/src/main/res/xml/automotive_app_desc.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<automotiveApp>
33
<uses name="notification"/>
44
<uses name="template"/>
5-
</automotiveApp>
5+
<uses name="media"/>
6+
</automotiveApp>

0 commit comments

Comments
 (0)