summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/tests/mediacujtest/common/Android.bp1
-rw-r--r--tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/DeviceLockTestPlayerListener.java119
-rw-r--r--tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/MainActivity.java15
-rw-r--r--tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/PlayerListener.java5
-rw-r--r--tests/tests/mediacujtest/smalltest/res/raw/ElephantsDream_2ch_48Khz_15s.mp3bin0 -> 448852 bytes
-rw-r--r--tests/tests/mediacujtest/smalltest/src/android/media/cujsmalltest/cts/CtsMediaShortFormPlaybackTest.java24
6 files changed, 160 insertions, 4 deletions
diff --git a/tests/tests/mediacujtest/common/Android.bp b/tests/tests/mediacujtest/common/Android.bp
index 5f95f923101..67b6f4c0b52 100644
--- a/tests/tests/mediacujtest/common/Android.bp
+++ b/tests/tests/mediacujtest/common/Android.bp
@@ -30,6 +30,7 @@ android_library {
"androidx.media3.media3-exoplayer",
"androidx.media3.media3-ui",
"permission-test-util-lib",
+ "cts-wm-util",
],
libs: [
"auto_value_annotations",
diff --git a/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/DeviceLockTestPlayerListener.java b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/DeviceLockTestPlayerListener.java
new file mode 100644
index 00000000000..ceb7ecd88d2
--- /dev/null
+++ b/tests/tests/mediacujtest/common/src/android/media/cujcommon/cts/DeviceLockTestPlayerListener.java
@@ -0,0 +1,119 @@
+/**
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.os.Looper;
+import android.server.wm.UiDeviceUtils;
+import android.view.Display;
+
+import androidx.annotation.NonNull;
+import androidx.media3.common.Player;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class DeviceLockTestPlayerListener extends PlayerListener {
+
+ private static final int LOCK_DURATION_MS = 5000;
+ private static final int DELAY_MS = 2000;
+
+ private final boolean mIsAudioOnlyClip;
+
+ private Display mDisplay;
+ private boolean mIsPlayerPlaying;
+
+ public DeviceLockTestPlayerListener(long sendMessagePosition, boolean isAudioOnlyClip) {
+ super();
+ this.mSendMessagePosition = sendMessagePosition;
+ this.mIsAudioOnlyClip = isAudioOnlyClip;
+ }
+
+ @Override
+ public void onIsPlayingChanged(boolean isPlaying) {
+ super.onIsPlayingChanged(isPlaying);
+ mIsPlayerPlaying = isPlaying;
+ }
+
+ @Override
+ public TestType getTestType() {
+ return TestType.DEVICE_LOCK_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() + LOCK_DURATION_MS;
+ // Register the screen receiver to listen for screen on and off events
+ mDisplay = mActivity.getDisplay();
+ }
+ }
+
+ @Override
+ public void onEventsMediaItemTransition(@NonNull Player player) {
+ mActivity.mPlayer.createMessage((messageType, payload) -> {
+ // Lock the device
+ UiDeviceUtils.pressSleepButton();
+ // Unlock the device after LOCK_DURATION
+ Timer timer = new Timer();
+ timer.schedule(new Task(), LOCK_DURATION_MS);
+ }).setLooper(Looper.getMainLooper()).setPosition(mSendMessagePosition)
+ .setDeleteAfterDelivery(true)
+ .send();
+ mActivity.mPlayer.createMessage((messageType, payload) -> {
+ // Verify that the screen is on and player is playing while device is in unlocked state
+ assertTrue(isDisplayOn());
+ assertTrue(mIsPlayerPlaying);
+ }).setLooper(Looper.getMainLooper())
+ .setPosition(mIsAudioOnlyClip ? (mSendMessagePosition + LOCK_DURATION_MS + DELAY_MS)
+ : (mSendMessagePosition + DELAY_MS))
+ .setDeleteAfterDelivery(true)
+ .send();
+ }
+
+ private boolean isDisplayOn() {
+ return mDisplay != null && mDisplay.getState() == Display.STATE_ON;
+ }
+
+ class Task extends TimerTask {
+
+ @Override
+ public void run() {
+ unlockPhone();
+ }
+
+ private void unlockPhone() {
+ // Verify that the screen is off when device is in locked state
+ assertFalse(isDisplayOn());
+ if (mIsAudioOnlyClip) {
+ // In case of audio only clip, verify that the player is playing while device is in
+ // locked state
+ assertTrue(mIsPlayerPlaying);
+ } else {
+ // Otherwise verify that the player is not playing while device is in locked state
+ assertFalse(mIsPlayerPlaying);
+ }
+ // Unlock the device
+ UiDeviceUtils.pressWakeupButton();
+ UiDeviceUtils.pressUnlockButton();
+ }
+ }
+}
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 1c7dee3f969..e50bbed8a64 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
@@ -28,10 +28,14 @@ import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
+import androidx.media3.common.Tracks.Group;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.ui.PlayerView;
+import com.google.common.collect.ImmutableList;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -94,8 +98,15 @@ public class MainActivity extends AppCompatActivity {
*/
@Override
protected void onStop() {
- mPlayer.stop();
- super.onStop();
+ // When activity is stopped, don't pause the playback if it is an audio only clip
+ ImmutableList<Group> currentTrackGroups = mPlayer.getCurrentTracks().getGroups();
+ if ((currentTrackGroups.size() == 1) && (currentTrackGroups.get(0).getType()
+ == C.TRACK_TYPE_AUDIO)) {
+ super.onStop();
+ } else {
+ mPlayer.stop();
+ super.onStop();
+ }
}
/**
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 b02da44b74a..2956a56228a 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
@@ -45,7 +45,7 @@ public abstract class PlayerListener implements Player.Listener {
public static int CURRENT_MEDIA_INDEX = 0;
// Enum Declared for Test Type
- protected enum TestType {
+ public enum TestType {
PLAYBACK_TEST,
SEEK_TEST,
ORIENTATION_TEST,
@@ -58,7 +58,8 @@ public abstract class PlayerListener implements Player.Listener {
PINCH_TO_ZOOM_TEST,
SPEED_CHANGE_TEST,
PIP_MODE_TEST,
- SPLIT_SCREEN_TEST
+ SPLIT_SCREEN_TEST,
+ DEVICE_LOCK_TEST
}
public static boolean mPlaybackEnded;
diff --git a/tests/tests/mediacujtest/smalltest/res/raw/ElephantsDream_2ch_48Khz_15s.mp3 b/tests/tests/mediacujtest/smalltest/res/raw/ElephantsDream_2ch_48Khz_15s.mp3
new file mode 100644
index 00000000000..101c302d92f
--- /dev/null
+++ b/tests/tests/mediacujtest/smalltest/res/raw/ElephantsDream_2ch_48Khz_15s.mp3
Binary files differ
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 bb95b35a1f8..717d27c7a35 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
@@ -18,10 +18,12 @@ package android.media.cujsmalltest.cts;
import android.media.cujcommon.cts.CujTestBase;
import android.media.cujcommon.cts.CujTestParam;
+import android.media.cujcommon.cts.DeviceLockTestPlayerListener;
import android.media.cujcommon.cts.OrientationTestPlayerListener;
import android.media.cujcommon.cts.PinchToZoomTestPlayerListener;
import android.media.cujcommon.cts.PipModeTestPlayerListener;
import android.media.cujcommon.cts.PlaybackTestPlayerListener;
+import android.media.cujcommon.cts.PlayerListener.TestType;
import android.media.cujcommon.cts.ScrollTestPlayerListener;
import android.media.cujcommon.cts.SeekTestPlayerListener;
import android.media.cujcommon.cts.SplitScreenTestPlayerListener;
@@ -79,6 +81,8 @@ public class CtsMediaShortFormPlaybackTest extends CujTestBase {
"android.resource://android.media.cujsmalltest.cts/raw/tearsofsteel_srt_subtitles_eng_fre_5sec";
private static final String MKV_TEARS_OF_STEEL_ASSET_SSA_SUBTITLES_ENG_FRENCH_URI_STRING =
"android.resource://android.media.cujsmalltest.cts/raw/tearsofsteel_ssa_subtitles_eng_fre_5sec";
+ private static final String MP3_ELEPHANTSDREAM_2CH_48KHZ_URI_STRING =
+ "android.resource://android.media.cujsmalltest.cts/raw/ElephantsDream_2ch_48Khz_15s";
CujTestParam mCujTestParam;
private final String mTestType;
@@ -143,6 +147,14 @@ public class CtsMediaShortFormPlaybackTest extends CujTestBase {
.setTimeoutMilliSeconds(45000)
.setPlayerListener(new SplitScreenTestPlayerListener(5000)).build(),
"Hevc_720p_15sec_SplitScreenTest"},
+ {CujTestParam.builder().setMediaUrls(prepareHevc_720p_15sec_SingleVideoList())
+ .setTimeoutMilliSeconds(50000)
+ .setPlayerListener(new DeviceLockTestPlayerListener(3000, false)).build(),
+ "Hevc_720p_15sec_DeviceLockTest"},
+ {CujTestParam.builder().setMediaUrls(prepareMp3_15secAudioListForDeviceLockTest())
+ .setTimeoutMilliSeconds(45000)
+ .setPlayerListener(new DeviceLockTestPlayerListener(3000, true)).build(),
+ "Mp3_15sec_DeviceLockTest"},
}));
return exhaustiveArgsList;
}
@@ -256,6 +268,14 @@ public class CtsMediaShortFormPlaybackTest extends CujTestBase {
return videoInput;
}
+ /**
+ * Prepare Mp3 15sec audio list for Device Lock Test.
+ */
+ public static List<String> prepareMp3_15secAudioListForDeviceLockTest() {
+ List<String> audioInput = Arrays.asList(
+ MP3_ELEPHANTSDREAM_2CH_48KHZ_URI_STRING);
+ return audioInput;
+ }
// Test to Verify video playback with and without seek
@ApiTest(apis = {"android.media.MediaCodec#configure",
@@ -287,6 +307,10 @@ public class CtsMediaShortFormPlaybackTest extends CujTestBase {
Assume.assumeFalse("Skipping " + mTestType + " on television", isTelevisionDevice(mActivity));
Assume.assumeFalse("Skipping " + mTestType + " on watch", isWatchDevice(mActivity));
}
+ if (mCujTestParam.playerListener().getTestType().equals(TestType.DEVICE_LOCK_TEST)) {
+ Assume.assumeFalse("Skipping " + mTestType + " on watch", isWatchDevice(mActivity));
+ Assume.assumeFalse("Skipping " + mTestType + " on television", isTelevisionDevice(mActivity));
+ }
play(mCujTestParam.mediaUrls(), mCujTestParam.timeoutMilliSeconds());
}
}