Commit ba84c2a0 by christosts Committed by microkatz

MediaController: Add missing event flags (1/2)

This is the first commit out of two. This change adds the missing event
flags for the onEvents() callback when MediaController is connected to a
media3 session (see MediaControllerImplBase). I updated the
MediaControllerListenerTest and MediaControllerStateMaskingTest with
assertions that on onEvents() is called alongside individual
Player.Listener callbacks.

There will be a follow-up change for the case where a MediaController is
connected to a legacy MediaSession (MediaControllerImplLegacy). I've
split this in two separate changes to make the size of the commit
manageable for reviewing.

#minor-release

PiperOrigin-RevId: 481933437
(cherry picked from commit 46d5a0e3)
parent e5897184
...@@ -51,6 +51,7 @@ interface IRemoteMediaSession { ...@@ -51,6 +51,7 @@ interface IRemoteMediaSession {
void setIsPlayingAd(String sessionId, boolean isPlayingAd); void setIsPlayingAd(String sessionId, boolean isPlayingAd);
void setCurrentAdGroupIndex(String sessionId, int currentAdGroupIndex); void setCurrentAdGroupIndex(String sessionId, int currentAdGroupIndex);
void setCurrentAdIndexInAdGroup(String sessionId, int currentAdIndexInAdGroup); void setCurrentAdIndexInAdGroup(String sessionId, int currentAdIndexInAdGroup);
void setVolume(String sessionId, float volume);
void notifyPlayerError(String sessionId, in Bundle playerErrorBundle); void notifyPlayerError(String sessionId, in Bundle playerErrorBundle);
void notifyPlayWhenReadyChanged(String sessionId, boolean playWhenReady, int reason); void notifyPlayWhenReadyChanged(String sessionId, boolean playWhenReady, int reason);
void notifyPlaybackStateChanged(String sessionId, int state); void notifyPlaybackStateChanged(String sessionId, int state);
...@@ -79,6 +80,8 @@ interface IRemoteMediaSession { ...@@ -79,6 +80,8 @@ interface IRemoteMediaSession {
void notifySeekBackIncrementChanged(String sessionId, long seekBackIncrementMs); void notifySeekBackIncrementChanged(String sessionId, long seekBackIncrementMs);
void notifySeekForwardIncrementChanged(String sessionId, long seekForwardIncrementMs); void notifySeekForwardIncrementChanged(String sessionId, long seekForwardIncrementMs);
void notifyDeviceVolumeChanged(String sessionId, int volume, boolean muted); void notifyDeviceVolumeChanged(String sessionId, int volume, boolean muted);
void decreaseDeviceVolume(String sessionId);
void increaseDeviceVolume(String sessionId);
void notifyCuesChanged(String sessionId, in Bundle cueGroup); void notifyCuesChanged(String sessionId, in Bundle cueGroup);
void notifyDeviceInfoChanged(String sessionId, in Bundle deviceInfo); void notifyDeviceInfoChanged(String sessionId, in Bundle deviceInfo);
void notifyMediaMetadataChanged(String sessionId, in Bundle mediaMetadata); void notifyMediaMetadataChanged(String sessionId, in Bundle mediaMetadata);
......
...@@ -24,8 +24,10 @@ import android.text.TextUtils; ...@@ -24,8 +24,10 @@ import android.text.TextUtils;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.UiThread; import androidx.annotation.UiThread;
import androidx.media3.common.Player;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import com.google.common.collect.ImmutableList;
import java.util.Locale; import java.util.Locale;
/** Provides utility methods for testing purpose. */ /** Provides utility methods for testing purpose. */
...@@ -127,5 +129,19 @@ public class TestUtils { ...@@ -127,5 +129,19 @@ public class TestUtils {
} }
} }
/**
* Returns an {@link ImmutableList} with the {@linkplain Player.Event Events} contained in {@code
* events}. The contents of the list are in matching order with the {@linkplain Player.Event
* Events} returned by {@link Player.Events#get(int)}.
*/
// TODO(b/254265256): Move this method off test-session-common.
public static ImmutableList<@Player.Event Integer> getEventsAsList(Player.Events events) {
ImmutableList.Builder<@Player.Event Integer> list = new ImmutableList.Builder<>();
for (int i = 0; i < events.size(); i++) {
list.add(events.get(i));
}
return list.build();
}
private TestUtils() {} private TestUtils() {}
} }
...@@ -35,6 +35,7 @@ import androidx.media3.common.Player; ...@@ -35,6 +35,7 @@ import androidx.media3.common.Player;
import androidx.media3.test.session.common.HandlerThreadTestRule; import androidx.media3.test.session.common.HandlerThreadTestRule;
import androidx.media3.test.session.common.PollingCheck; import androidx.media3.test.session.common.PollingCheck;
import androidx.media3.test.session.common.SurfaceActivity; import androidx.media3.test.session.common.SurfaceActivity;
import androidx.media3.test.session.common.TestUtils;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.LargeTest; import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule; import androidx.test.rule.ActivityTestRule;
...@@ -42,6 +43,7 @@ import java.util.Arrays; ...@@ -42,6 +43,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -140,6 +142,7 @@ public class MediaControllerSurfaceSizeChangeTest { ...@@ -140,6 +142,7 @@ public class MediaControllerSurfaceSizeChangeTest {
private final CountDownLatch countDownLatch; private final CountDownLatch countDownLatch;
private final AtomicInteger newSurfaceWidthRef; private final AtomicInteger newSurfaceWidthRef;
private final AtomicInteger newSurfaceHeightRef; private final AtomicInteger newSurfaceHeightRef;
private final AtomicReference<Player.Events> eventsRef;
@Rule @Rule
public ActivityTestRule<SurfaceActivity> activityRule = public ActivityTestRule<SurfaceActivity> activityRule =
...@@ -178,9 +181,10 @@ public class MediaControllerSurfaceSizeChangeTest { ...@@ -178,9 +181,10 @@ public class MediaControllerSurfaceSizeChangeTest {
this.sizeCondition = sizeCondition; this.sizeCondition = sizeCondition;
this.surfaceSizeChangedShouldBeCalled = surfaceSizeChangedShouldBeCalled; this.surfaceSizeChangedShouldBeCalled = surfaceSizeChangedShouldBeCalled;
countDownLatch = new CountDownLatch(1); countDownLatch = new CountDownLatch(2);
newSurfaceWidthRef = new AtomicInteger(C.LENGTH_UNSET); newSurfaceWidthRef = new AtomicInteger(C.LENGTH_UNSET);
newSurfaceHeightRef = new AtomicInteger(C.LENGTH_UNSET); newSurfaceHeightRef = new AtomicInteger(C.LENGTH_UNSET);
eventsRef = new AtomicReference<>();
} }
@Test @Test
...@@ -252,6 +256,12 @@ public class MediaControllerSurfaceSizeChangeTest { ...@@ -252,6 +256,12 @@ public class MediaControllerSurfaceSizeChangeTest {
newSurfaceHeightRef.set(height); newSurfaceHeightRef.set(height);
countDownLatch.countDown(); countDownLatch.countDown();
} }
@Override
public void onEvents(Player player, Player.Events events) {
eventsRef.set(events);
countDownLatch.countDown();
}
})); }));
} }
...@@ -360,6 +370,8 @@ public class MediaControllerSurfaceSizeChangeTest { ...@@ -360,6 +370,8 @@ public class MediaControllerSurfaceSizeChangeTest {
assertThat(countDownLatch.await(TIMEOUT_MS, MILLISECONDS)).isTrue(); assertThat(countDownLatch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(newSurfaceWidthRef.get()).isEqualTo(expectedWidthFromCallback); assertThat(newSurfaceWidthRef.get()).isEqualTo(expectedWidthFromCallback);
assertThat(newSurfaceHeightRef.get()).isEqualTo(expectedHeightFromCallback); assertThat(newSurfaceHeightRef.get()).isEqualTo(expectedHeightFromCallback);
assertThat(TestUtils.getEventsAsList(eventsRef.get()))
.containsExactly(Player.EVENT_SURFACE_SIZE_CHANGED);
} else { } else {
assertThat(countDownLatch.await(NO_RESPONSE_TIMEOUT_MS, MILLISECONDS)).isFalse(); assertThat(countDownLatch.await(NO_RESPONSE_TIMEOUT_MS, MILLISECONDS)).isFalse();
} }
......
...@@ -858,6 +858,17 @@ public class MediaSessionProviderService extends Service { ...@@ -858,6 +858,17 @@ public class MediaSessionProviderService extends Service {
} }
@Override @Override
public void setVolume(String sessionId, float volume) throws RemoteException {
runOnHandler(
() -> {
MediaSession session = sessionMap.get(sessionId);
MockPlayer player = (MockPlayer) session.getPlayer();
player.setVolume(volume);
player.notifyVolumeChanged();
});
}
@Override
public void notifyAvailableCommandsChanged(String sessionId, Bundle commandsBundle) public void notifyAvailableCommandsChanged(String sessionId, Bundle commandsBundle)
throws RemoteException { throws RemoteException {
runOnHandler( runOnHandler(
...@@ -971,6 +982,28 @@ public class MediaSessionProviderService extends Service { ...@@ -971,6 +982,28 @@ public class MediaSessionProviderService extends Service {
} }
@Override @Override
public void decreaseDeviceVolume(String sessionId) throws RemoteException {
runOnHandler(
() -> {
MediaSession session = sessionMap.get(sessionId);
MockPlayer player = (MockPlayer) session.getPlayer();
player.decreaseDeviceVolume();
player.notifyDeviceVolumeChanged();
});
}
@Override
public void increaseDeviceVolume(String sessionId) throws RemoteException {
runOnHandler(
() -> {
MediaSession session = sessionMap.get(sessionId);
MockPlayer player = (MockPlayer) session.getPlayer();
player.increaseDeviceVolume();
player.notifyDeviceVolumeChanged();
});
}
@Override
public void notifyCuesChanged(String sessionId, Bundle cueGroupBundle) throws RemoteException { public void notifyCuesChanged(String sessionId, Bundle cueGroupBundle) throws RemoteException {
CueGroup cueGroup = CueGroup.CREATOR.fromBundle(cueGroupBundle); CueGroup cueGroup = CueGroup.CREATOR.fromBundle(cueGroupBundle);
runOnHandler( runOnHandler(
......
...@@ -655,11 +655,13 @@ public class MockPlayer implements Player { ...@@ -655,11 +655,13 @@ public class MockPlayer implements Player {
@Override @Override
public void increaseDeviceVolume() { public void increaseDeviceVolume() {
deviceVolume += 1;
checkNotNull(conditionVariables.get(METHOD_INCREASE_DEVICE_VOLUME)).open(); checkNotNull(conditionVariables.get(METHOD_INCREASE_DEVICE_VOLUME)).open();
} }
@Override @Override
public void decreaseDeviceVolume() { public void decreaseDeviceVolume() {
deviceVolume -= 1;
checkNotNull(conditionVariables.get(METHOD_DECREASE_DEVICE_VOLUME)).open(); checkNotNull(conditionVariables.get(METHOD_DECREASE_DEVICE_VOLUME)).open();
} }
...@@ -1204,6 +1206,12 @@ public class MockPlayer implements Player { ...@@ -1204,6 +1206,12 @@ public class MockPlayer implements Player {
} }
} }
public void notifyVolumeChanged() {
for (Listener listener : listeners) {
listener.onVolumeChanged(volume);
}
}
@SuppressWarnings("deprecation") // Implementing and calling deprecated listener method. @SuppressWarnings("deprecation") // Implementing and calling deprecated listener method.
public void notifyCuesChanged() { public void notifyCuesChanged() {
for (Listener listener : listeners) { for (Listener listener : listeners) {
......
...@@ -282,6 +282,10 @@ public class RemoteMediaSession { ...@@ -282,6 +282,10 @@ public class RemoteMediaSession {
binder.setCurrentAdIndexInAdGroup(sessionId, currentAdIndexInAdGroup); binder.setCurrentAdIndexInAdGroup(sessionId, currentAdIndexInAdGroup);
} }
public void setVolume(float volume) throws RemoteException {
binder.setVolume(sessionId, volume);
}
public void notifyPlayWhenReadyChanged( public void notifyPlayWhenReadyChanged(
boolean playWhenReady, @Player.PlaybackSuppressionReason int reason) boolean playWhenReady, @Player.PlaybackSuppressionReason int reason)
throws RemoteException { throws RemoteException {
...@@ -399,6 +403,14 @@ public class RemoteMediaSession { ...@@ -399,6 +403,14 @@ public class RemoteMediaSession {
binder.notifyDeviceVolumeChanged(sessionId, volume, muted); binder.notifyDeviceVolumeChanged(sessionId, volume, muted);
} }
public void decreaseDeviceVolume() throws RemoteException {
binder.decreaseDeviceVolume(sessionId);
}
public void increaseDeviceVolume() throws RemoteException {
binder.increaseDeviceVolume(sessionId);
}
public void notifyCuesChanged(CueGroup cueGroup) throws RemoteException { public void notifyCuesChanged(CueGroup cueGroup) throws RemoteException {
binder.notifyCuesChanged(sessionId, cueGroup.toBundle()); binder.notifyCuesChanged(sessionId, cueGroup.toBundle());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment