1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.cts; 18 19 import android.media.MediaItem2; 20 import android.media.MediaMetadata2; 21 import android.media.MediaPlaylistAgent; 22 23 import java.util.List; 24 import java.util.concurrent.CountDownLatch; 25 26 /** 27 * A mock implementation of {@link MediaPlaylistAgent} for testing. 28 * <p> 29 * Do not use mockito for {@link MediaPlaylistAgent}. Instead, use this. 30 * Mocks created from mockito should not be shared across different threads. 31 */ 32 public class MockPlaylistAgent extends MediaPlaylistAgent { 33 public final CountDownLatch mCountDownLatch = new CountDownLatch(1); 34 35 public List<MediaItem2> mPlaylist; 36 public MediaMetadata2 mMetadata; 37 public MediaItem2 mItem; 38 public int mIndex = -1; 39 public @RepeatMode int mRepeatMode = -1; 40 public @ShuffleMode int mShuffleMode = -1; 41 42 public boolean mSetPlaylistCalled; 43 public boolean mUpdatePlaylistMetadataCalled; 44 public boolean mAddPlaylistItemCalled; 45 public boolean mRemovePlaylistItemCalled; 46 public boolean mReplacePlaylistItemCalled; 47 public boolean mSkipToPlaylistItemCalled; 48 public boolean mSkipToPreviousItemCalled; 49 public boolean mSkipToNextItemCalled; 50 public boolean mSetRepeatModeCalled; 51 public boolean mSetShuffleModeCalled; 52 53 @Override getPlaylist()54 public List<MediaItem2> getPlaylist() { 55 return mPlaylist; 56 } 57 58 @Override setPlaylist(List<MediaItem2> list, MediaMetadata2 metadata)59 public void setPlaylist(List<MediaItem2> list, MediaMetadata2 metadata) { 60 mSetPlaylistCalled = true; 61 mPlaylist = list; 62 mMetadata = metadata; 63 mCountDownLatch.countDown(); 64 } 65 66 @Override getPlaylistMetadata()67 public MediaMetadata2 getPlaylistMetadata() { 68 return mMetadata; 69 } 70 71 @Override updatePlaylistMetadata(MediaMetadata2 metadata)72 public void updatePlaylistMetadata(MediaMetadata2 metadata) { 73 mUpdatePlaylistMetadataCalled = true; 74 mMetadata = metadata; 75 mCountDownLatch.countDown(); 76 } 77 78 @Override addPlaylistItem(int index, MediaItem2 item)79 public void addPlaylistItem(int index, MediaItem2 item) { 80 mAddPlaylistItemCalled = true; 81 mIndex = index; 82 mItem = item; 83 mCountDownLatch.countDown(); 84 } 85 86 @Override removePlaylistItem(MediaItem2 item)87 public void removePlaylistItem(MediaItem2 item) { 88 mRemovePlaylistItemCalled = true; 89 mItem = item; 90 mCountDownLatch.countDown(); 91 } 92 93 @Override replacePlaylistItem(int index, MediaItem2 item)94 public void replacePlaylistItem(int index, MediaItem2 item) { 95 mReplacePlaylistItemCalled = true; 96 mIndex = index; 97 mItem = item; 98 mCountDownLatch.countDown(); 99 } 100 101 @Override skipToPlaylistItem(MediaItem2 item)102 public void skipToPlaylistItem(MediaItem2 item) { 103 mSkipToPlaylistItemCalled = true; 104 mItem = item; 105 mCountDownLatch.countDown(); 106 } 107 108 @Override skipToPreviousItem()109 public void skipToPreviousItem() { 110 mSkipToPreviousItemCalled = true; 111 mCountDownLatch.countDown(); 112 } 113 114 @Override skipToNextItem()115 public void skipToNextItem() { 116 mSkipToNextItemCalled = true; 117 mCountDownLatch.countDown(); 118 } 119 120 @Override getRepeatMode()121 public int getRepeatMode() { 122 return mRepeatMode; 123 } 124 125 @Override setRepeatMode(int repeatMode)126 public void setRepeatMode(int repeatMode) { 127 mSetRepeatModeCalled = true; 128 mRepeatMode = repeatMode; 129 mCountDownLatch.countDown(); 130 } 131 132 @Override getShuffleMode()133 public int getShuffleMode() { 134 return mShuffleMode; 135 } 136 137 @Override setShuffleMode(int shuffleMode)138 public void setShuffleMode(int shuffleMode) { 139 mSetShuffleModeCalled = true; 140 mShuffleMode = shuffleMode; 141 mCountDownLatch.countDown(); 142 } 143 }