58
58
59
59
public final ImmutableList <CommandButton > customLayout ;
60
60
61
+ public final ImmutableList <CommandButton > mediaButtonPreferences ;
62
+
61
63
@ Nullable public final Token platformToken ;
62
64
63
65
public final ImmutableList <CommandButton > commandButtonsForMediaItems ;
@@ -68,6 +70,7 @@ public ConnectionState(
68
70
IMediaSession sessionBinder ,
69
71
@ Nullable PendingIntent sessionActivity ,
70
72
ImmutableList <CommandButton > customLayout ,
73
+ ImmutableList <CommandButton > mediaButtonPreferences ,
71
74
ImmutableList <CommandButton > commandButtonsForMediaItems ,
72
75
SessionCommands sessionCommands ,
73
76
Player .Commands playerCommandsFromSession ,
@@ -81,6 +84,7 @@ public ConnectionState(
81
84
this .sessionBinder = sessionBinder ;
82
85
this .sessionActivity = sessionActivity ;
83
86
this .customLayout = customLayout ;
87
+ this .mediaButtonPreferences = mediaButtonPreferences ;
84
88
this .commandButtonsForMediaItems = commandButtonsForMediaItems ;
85
89
this .sessionCommands = sessionCommands ;
86
90
this .playerCommandsFromSession = playerCommandsFromSession ;
@@ -95,6 +99,7 @@ public ConnectionState(
95
99
private static final String FIELD_SESSION_BINDER = Util .intToStringMaxRadix (1 );
96
100
private static final String FIELD_SESSION_ACTIVITY = Util .intToStringMaxRadix (2 );
97
101
private static final String FIELD_CUSTOM_LAYOUT = Util .intToStringMaxRadix (9 );
102
+ private static final String FIELD_MEDIA_BUTTON_PREFERENCES = Util .intToStringMaxRadix (14 );
98
103
private static final String FIELD_COMMAND_BUTTONS_FOR_MEDIA_ITEMS = Util .intToStringMaxRadix (13 );
99
104
private static final String FIELD_SESSION_COMMANDS = Util .intToStringMaxRadix (3 );
100
105
private static final String FIELD_PLAYER_COMMANDS_FROM_SESSION = Util .intToStringMaxRadix (4 );
@@ -106,7 +111,7 @@ public ConnectionState(
106
111
private static final String FIELD_IN_PROCESS_BINDER = Util .intToStringMaxRadix (10 );
107
112
private static final String FIELD_PLATFORM_TOKEN = Util .intToStringMaxRadix (12 );
108
113
109
- // Next field key = 14
114
+ // Next field key = 15
110
115
111
116
public Bundle toBundleForRemoteProcess (int controllerInterfaceVersion ) {
112
117
Bundle bundle = new Bundle ();
@@ -118,6 +123,21 @@ public Bundle toBundleForRemoteProcess(int controllerInterfaceVersion) {
118
123
FIELD_CUSTOM_LAYOUT ,
119
124
BundleCollectionUtil .toBundleArrayList (customLayout , CommandButton ::toBundle ));
120
125
}
126
+ if (!mediaButtonPreferences .isEmpty ()) {
127
+ if (controllerInterfaceVersion >= 7 ) {
128
+ bundle .putParcelableArrayList (
129
+ FIELD_MEDIA_BUTTON_PREFERENCES ,
130
+ BundleCollectionUtil .toBundleArrayList (
131
+ mediaButtonPreferences , CommandButton ::toBundle ));
132
+ } else {
133
+ // Controller doesn't support media button preferences, send the list as a custom layout.
134
+ // TODO: b/332877990 - More accurately reflect media button preferences as custom layout.
135
+ bundle .putParcelableArrayList (
136
+ FIELD_CUSTOM_LAYOUT ,
137
+ BundleCollectionUtil .toBundleArrayList (
138
+ mediaButtonPreferences , CommandButton ::toBundle ));
139
+ }
140
+ }
121
141
if (!commandButtonsForMediaItems .isEmpty ()) {
122
142
bundle .putParcelableArrayList (
123
143
FIELD_COMMAND_BUTTONS_FOR_MEDIA_ITEMS ,
@@ -166,11 +186,20 @@ public static ConnectionState fromBundle(Bundle bundle) {
166
186
IBinder sessionBinder = checkNotNull (BundleCompat .getBinder (bundle , FIELD_SESSION_BINDER ));
167
187
@ Nullable PendingIntent sessionActivity = bundle .getParcelable (FIELD_SESSION_ACTIVITY );
168
188
@ Nullable
169
- List <Bundle > commandButtonArrayList = bundle .getParcelableArrayList (FIELD_CUSTOM_LAYOUT );
189
+ List <Bundle > customLayoutArrayList = bundle .getParcelableArrayList (FIELD_CUSTOM_LAYOUT );
170
190
ImmutableList <CommandButton > customLayout =
171
- commandButtonArrayList != null
191
+ customLayoutArrayList != null
192
+ ? BundleCollectionUtil .fromBundleList (
193
+ b -> CommandButton .fromBundle (b , sessionInterfaceVersion ), customLayoutArrayList )
194
+ : ImmutableList .of ();
195
+ @ Nullable
196
+ List <Bundle > mediaButtonPreferencesArrayList =
197
+ bundle .getParcelableArrayList (FIELD_MEDIA_BUTTON_PREFERENCES );
198
+ ImmutableList <CommandButton > mediaButtonPreferences =
199
+ mediaButtonPreferencesArrayList != null
172
200
? BundleCollectionUtil .fromBundleList (
173
- b -> CommandButton .fromBundle (b , sessionInterfaceVersion ), commandButtonArrayList )
201
+ b -> CommandButton .fromBundle (b , sessionInterfaceVersion ),
202
+ mediaButtonPreferencesArrayList )
174
203
: ImmutableList .of ();
175
204
@ Nullable
176
205
List <Bundle > commandButtonsForMediaItemsArrayList =
@@ -212,6 +241,7 @@ public static ConnectionState fromBundle(Bundle bundle) {
212
241
IMediaSession .Stub .asInterface (sessionBinder ),
213
242
sessionActivity ,
214
243
customLayout ,
244
+ mediaButtonPreferences ,
215
245
commandButtonsForMediaItems ,
216
246
sessionCommands ,
217
247
playerCommandsFromSession ,
0 commit comments