Skip to content

Commit f140bb2

Browse files
committed
Sync with risin42/NagramX@ec956e3: align Android Auto with androidx.car.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
1 parent ee899ef commit f140bb2

6 files changed

Lines changed: 25 additions & 11 deletions

File tree

TMessagesProj/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ dependencies {
209209
implementation 'androidx.sharetarget:sharetarget:1.2.0'
210210
implementation 'androidx.interpolator:interpolator:1.0.0'
211211
implementation 'androidx.biometric:biometric:1.1.0'
212+
implementation "androidx.media:media:1.7.0"
213+
implementation "androidx.lifecycle:lifecycle-runtime:2.7.0"
212214
implementation 'androidx.car.app:app:1.7.0'
213215
implementation 'androidx.car.app:app-projected:1.7.0'
214216
implementation 'org.nanohttpd:nanohttpd:2.3.1'

TMessagesProj/src/main/AndroidManifest.xml

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

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

882-
<!--
883882
<meta-data android:name="com.google.android.gms.car.notification.SmallIcon" android:resource="@drawable/ic_player" />
884883
<meta-data android:name="com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc" />
885884

@@ -895,8 +894,7 @@
895894

896895
<meta-data
897896
android:name="androidx.car.app.minCarApiLevel"
898-
android:value="5" />
899-
-->
897+
android:value="7" />
900898

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

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ private void createNotification(MessageObject messageObject, boolean forBitmap)
527527
}
528528
}
529529

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

543545
mediaSession.setMetadata(meta.build());
546+
TelegramMediaSession.getInstance(this).publishMetadata(messageObject, audioInfo, fullAlbumArt);
544547

545548
bldr.setVisibility(Notification.VISIBILITY_PUBLIC);
546549

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

756761
private void updateRepeatMode() {
@@ -823,6 +828,12 @@ public void onDestroy() {
823828
if (mediaSession != null) {
824829
mediaSession.release();
825830
}
831+
TelegramMediaSession sessionHolder = TelegramMediaSession.peekInstance();
832+
if (sessionHolder != null && MediaController.getInstance().getPlayingMessageObject() == null) {
833+
sessionHolder.publishPlaybackState(new PlaybackStateCompat.Builder()
834+
.setState(PlaybackStateCompat.STATE_STOPPED, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 0)
835+
.build());
836+
}
826837
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
827838
NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingDidSeek);
828839
NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
@@ -873,4 +884,4 @@ public void didReceivedNotification(int id, int account, Object... args) {
873884
}
874885
}
875886

876-
}
887+
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private void applyQueueFor(long did) {
402402
ArrayList<MessageObject> arrayList = musicObjects.get(did);
403403
ArrayList<MediaSessionCompat.QueueItem> queueList = musicQueues.get(did);
404404
if (arrayList == null || arrayList.isEmpty() || queueList == null) return;
405-
session.setQueue(queueList);
405+
session.setQueue(new ArrayList<>(queueList));
406406
if (DialogObject.isUserDialog(did)) {
407407
TLRPC.User user = users.get(did);
408408
session.setQueueTitle(user != null
@@ -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() {
@@ -618,12 +620,12 @@ public void onPlayFromMediaId(String mediaId, Bundle extras) {
618620
int id = Integer.parseInt(args[1]);
619621
ArrayList<MessageObject> arrayList = musicObjects.get(did);
620622
ArrayList<MediaSessionCompat.QueueItem> queueList = musicQueues.get(did);
621-
if (arrayList == null || id < 0 || id >= arrayList.size()) return;
623+
if (arrayList == null || queueList == null || id < 0 || id >= arrayList.size()) return;
622624
lastSelectedDialog = did;
623625
MessagesController.getNotificationsSettings(currentAccount).edit()
624626
.putLong("auto_lastSelectedDialog", did).apply();
625627
MediaController.getInstance().setPlaylist(arrayList, arrayList.get(id), 0, false, null);
626-
session.setQueue(queueList);
628+
session.setQueue(new ArrayList<>(queueList));
627629
if (DialogObject.isUserDialog(did)) {
628630
TLRPC.User user = users.get(did);
629631
session.setQueueTitle(user != null

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<automotiveApp>
33
<uses name="notification"/>
44
<uses name="template"/>
5+
<uses name="media"/>
56
</automotiveApp>

0 commit comments

Comments
 (0)