diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-04-18 09:19:18 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-18 09:19:18 +0000 |
commit | 8dba78fa756e9c96d399113ce8053dc40fea7c24 (patch) | |
tree | 5339e2cb328c8696e97080e60c9ccb3ed45a9ce0 | |
parent | e284f12e6240ac744f7abe88f2331f37851d1f8b (diff) | |
parent | 9ee5679617f3037b16e9cf2dfa481dc20d600b06 (diff) | |
download | cts-8dba78fa756e9c96d399113ce8053dc40fea7c24.tar.gz |
Merge "mediacuj CTS: Add Split screen mode test for E2E CUJ" into main
5 files changed, 121 insertions, 1 deletions
diff --git a/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/CujTestBase.java b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/CujTestBase.java index 3fb53979039..6181f8eef38 100644 --- a/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/CujTestBase.java +++ b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/CujTestBase.java @@ -100,6 +100,13 @@ public class CujTestBase { } /** + * Whether the device is a television. + */ + public static boolean isTelevisionDevice(final Activity activity) { + return activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK); + } + + /** * Prepare the player, input list and add input list to player's playlist. After that, play for * the provided playlist and validate playback time. * diff --git a/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/MainActivity.java b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/MainActivity.java index d36492236a3..1c7dee3f969 100644 --- a/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/MainActivity.java +++ b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/MainActivity.java @@ -26,6 +26,7 @@ import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.WindowManager; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.media3.common.MediaItem; import androidx.media3.exoplayer.ExoPlayer; @@ -44,6 +45,8 @@ public class MainActivity extends AppCompatActivity { protected ScaleGestureDetector mScaleGestureDetector = null; protected boolean mConfiguredPipMode; protected boolean mIsInPipMode; + protected boolean mConfiguredSplitScreenMode; + protected boolean mIsInMultiWindowMode; @Override protected void onCreate(Bundle savedInstanceState) { @@ -145,6 +148,23 @@ public class MainActivity extends AppCompatActivity { } /** + * {@inheritDoc} + */ + @Override + public void onMultiWindowModeChanged(boolean isInMultiWindowMode, + @NonNull Configuration newConfig) { + super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig); + if (mPlayerListener.isSplitScreenTest()) { + mIsInMultiWindowMode = isInMultiWindowMode; + assertEquals(mConfiguredSplitScreenMode, isInMultiWindowMode); + // Verify that the player is playing in Split screen mode + if (isInMultiWindowMode) { + assertTrue(mPlayer.isPlaying()); + } + } + } + + /** * Register a listener to receive events from the player. * * <p>This method can be called from any thread. diff --git a/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/PlayerListener.java b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/PlayerListener.java index 70373e8d89f..b02da44b74a 100644 --- a/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/PlayerListener.java +++ b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/PlayerListener.java @@ -57,7 +57,8 @@ public abstract class PlayerListener implements Player.Listener { MESSAGE_NOTIFICATION_TEST, PINCH_TO_ZOOM_TEST, SPEED_CHANGE_TEST, - PIP_MODE_TEST + PIP_MODE_TEST, + SPLIT_SCREEN_TEST } public static boolean mPlaybackEnded; @@ -120,6 +121,13 @@ public abstract class PlayerListener implements Player.Listener { } /** + * Returns True for Split Screen test. + */ + public final boolean isSplitScreenTest() { + return getTestType().equals(TestType.SPLIT_SCREEN_TEST); + } + + /** * Returns expected playback time for the playlist. */ public final long getExpectedTotalTime() { diff --git a/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/SplitScreenTestPlayerListener.java b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/SplitScreenTestPlayerListener.java new file mode 100644 index 00000000000..da1f9766af2 --- /dev/null +++ b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/SplitScreenTestPlayerListener.java @@ -0,0 +1,76 @@ +/** + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.cujcommon.cts; + +import static org.junit.Assert.assertTrue; + +import android.content.Intent; +import android.os.Looper; +import android.provider.Settings; + +import androidx.annotation.NonNull; +import androidx.media3.common.Player; + +public class SplitScreenTestPlayerListener extends PlayerListener { + + private static final int SPLIT_SCREEN_DURATION_MS = 5000; + + public SplitScreenTestPlayerListener(long sendMessagePosition) { + super(); + this.mSendMessagePosition = sendMessagePosition; + } + + @Override + public TestType getTestType() { + return TestType.SPLIT_SCREEN_TEST; + } + + @Override + public void onEventsPlaybackStateChanged(@NonNull Player player) { + if (player.getPlaybackState() == Player.STATE_READY) { + // At the first media transition player is not ready. So, add duration of + // first clip when player is ready + mExpectedTotalTime += player.getDuration(); + } + } + + @Override + public void onEventsMediaItemTransition(@NonNull Player player) { + mActivity.mPlayer.createMessage((messageType, payload) -> { + // Switch to split screen mode + Intent intent = new Intent(Settings.ACTION_SETTINGS); + intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK); + mActivity.startActivity(intent); + mActivity.mConfiguredSplitScreenMode = true; + }).setLooper(Looper.getMainLooper()).setPosition(mSendMessagePosition) + .setDeleteAfterDelivery(true) + .send(); + mActivity.mPlayer.createMessage((messageType, payload) -> { + // Verify that the activity is in split screen mode before switching back to normal mode + assertTrue(mActivity.mIsInMultiWindowMode); + // Switch to normal playback mode + mActivity.moveTaskToBack(false); + Intent startIntent = new Intent(mActivity, MainActivity.class); + startIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + mActivity.startActivity(startIntent); + mActivity.mConfiguredSplitScreenMode = false; + }).setLooper(Looper.getMainLooper()) + .setPosition(mSendMessagePosition + SPLIT_SCREEN_DURATION_MS) + .setDeleteAfterDelivery(true) + .send(); + } +} diff --git a/tests/tests/mediacujtest/smalltest/src/android/media/cujsmalltest/cts/CtsMediaShortFormPlaybackTest.java b/tests/tests/mediacujtest/smalltest/src/android/media/cujsmalltest/cts/CtsMediaShortFormPlaybackTest.java index 9db236e35c8..bb95b35a1f8 100644 --- a/tests/tests/mediacujtest/smalltest/src/android/media/cujsmalltest/cts/CtsMediaShortFormPlaybackTest.java +++ b/tests/tests/mediacujtest/smalltest/src/android/media/cujsmalltest/cts/CtsMediaShortFormPlaybackTest.java @@ -24,6 +24,7 @@ import android.media.cujcommon.cts.PipModeTestPlayerListener; import android.media.cujcommon.cts.PlaybackTestPlayerListener; import android.media.cujcommon.cts.ScrollTestPlayerListener; import android.media.cujcommon.cts.SeekTestPlayerListener; +import android.media.cujcommon.cts.SplitScreenTestPlayerListener; import android.media.cujcommon.cts.SwitchAudioTrackTestPlayerListener; import android.media.cujcommon.cts.SwitchSubtitleTrackTestPlayerListener; import android.platform.test.annotations.PlatinumTest; @@ -138,6 +139,10 @@ public class CtsMediaShortFormPlaybackTest extends CujTestBase { .setTimeoutMilliSeconds(45000) .setPlayerListener(new PipModeTestPlayerListener(5000)).build(), "Hevc_720p_15sec_PipModeTest"}, + {CujTestParam.builder().setMediaUrls(prepareHevc_720p_15sec_SingleVideoList()) + .setTimeoutMilliSeconds(45000) + .setPlayerListener(new SplitScreenTestPlayerListener(5000)).build(), + "Hevc_720p_15sec_SplitScreenTest"}, })); return exhaustiveArgsList; } @@ -278,6 +283,10 @@ public class CtsMediaShortFormPlaybackTest extends CujTestBase { "Skipping " + mTestType + " as device doesn't support picture-in-picture feature", deviceSupportPipMode(mActivity)); } + if (mCujTestParam.playerListener().isSplitScreenTest()) { + Assume.assumeFalse("Skipping " + mTestType + " on television", isTelevisionDevice(mActivity)); + Assume.assumeFalse("Skipping " + mTestType + " on watch", isWatchDevice(mActivity)); + } play(mCujTestParam.mediaUrls(), mCujTestParam.timeoutMilliSeconds()); } } |