Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5348b91d authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Make MediaPlaylistAgent updatable

Bug: 74366050
Test: Pass MediaComponents test
Change-Id: Id4d213e84b4c6081e177d2f297cbf6444f9f50b2
parent fee84b36
Loading
Loading
Loading
Loading
+154 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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 com.android.media;

import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.media.MediaItem2;
import android.media.MediaMetadata2;
import android.media.MediaPlaylistAgent;
import android.media.MediaPlaylistAgent.PlaylistEventCallback;
import android.media.update.MediaPlaylistAgentProvider;

import java.util.List;
import java.util.concurrent.Executor;

public class MediaPlaylistAgentImpl implements MediaPlaylistAgentProvider {
    private final Context mContext;
    private final MediaPlaylistAgent mInstance;

    public MediaPlaylistAgentImpl(Context context, MediaPlaylistAgent instance) {
        mContext = context;
        mInstance = instance;
    }

    final public void registerPlaylistEventCallback_impl(
            @NonNull @CallbackExecutor Executor executor, @NonNull PlaylistEventCallback callback) {
        if (executor == null) {
            throw new IllegalArgumentException("executor shouldn't be null");
        }
        if (callback == null) {
            throw new IllegalArgumentException("callback shouldn't be null");
        }
        // TODO(jaewan): implement this (b/74090741)
    }

    final public void unregisterPlaylistEventCallback_impl(
            @NonNull PlaylistEventCallback callback) {
        if (callback == null) {
            throw new IllegalArgumentException("callback shouldn't be null");
        }
        // TODO(jaewan): implement this (b/74090741)
    }

    final public void notifyPlaylistChanged_impl() {
        // TODO(jaewan): implement this (b/74090741)
    }

    final public void notifyPlaylistMetadataChanged_impl() {
        // TODO(jaewan): implement this (b/74090741)
    }

    final public void notifyShuffleModeChanged_impl() {
        // TODO(jaewan): implement this (b/74090741)
    }

    final public void notifyRepeatModeChanged_impl() {
        // TODO(jaewan): implement this (b/74090741)
    }

    public @Nullable List<MediaItem2> getPlaylist_impl() {
        // TODO(jaewan): implement this (b/74090741)
        return null;
    }

    public void setPlaylist_impl(@NonNull List<MediaItem2> list,
            @Nullable MediaMetadata2 metadata) {
        if (list == null) {
            throw new IllegalArgumentException("list shouldn't be null");
        }
        // TODO(jaewan): implement this (b/74090741)
    }

    public @Nullable MediaMetadata2 getPlaylistMetadata_impl() {
        // TODO(jaewan): implement this (b/74090741)
        return null;
    }

    public void updatePlaylistMetadata_impl(@Nullable MediaMetadata2 metadata) {
        // TODO(jaewan): implement this (b/74090741)
    }

    public void addPlaylistItem_impl(int index, @NonNull MediaItem2 item) {
        if (item == null) {
            throw new IllegalArgumentException("item shouldn't be null");
        }
        // TODO(jaewan): implement this (b/74090741)
    }

    public void removePlaylistItem_impl(@NonNull MediaItem2 item) {
        if (item == null) {
            throw new IllegalArgumentException("item shouldn't be null");
        }
        // TODO(jaewan): implement this (b/74090741)
    }

    public void replacePlaylistItem_impl(int index, @NonNull MediaItem2 item) {
        if (index < 0) {
            throw new IllegalArgumentException("index can not have a negative value");
        }
        if (item == null) {
            throw new IllegalArgumentException("item shouldn't be null");
        }
        // TODO(jaewan): implement this (b/74090741)
    }

    public void skipToPlaylistItem_impl(@NonNull MediaItem2 item) {
        if (item == null) {
            throw new IllegalArgumentException("item shouldn't be null");
        }
        // TODO(jaewan): implement this (b/74090741)
    }

    public void skipToPreviousItem_impl() {
        // TODO(jaewan): implement this (b/74090741)
    }

    public void skipToNextItem_impl() {
        // TODO(jaewan): implement this (b/74090741)
    }

    public int getRepeatMode_impl() {
        // TODO(jaewan): implement this (b/74090741)
        return MediaPlaylistAgent.REPEAT_MODE_NONE;
    }

    public void setRepeatMode_impl(int repeatMode) {
        // TODO(jaewan): implement this (b/74090741)
    }

    public int getShuffleMode_impl() {
        // TODO(jaewan): implement this (b/74090741)
        return MediaPlaylistAgent.SHUFFLE_MODE_NONE;
    }

    public void setShuffleMode_impl(int shuffleMode) {
        // TODO(jaewan): implement this (b/74090741)
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.media.MediaLibraryService2.MediaLibrarySession;
import android.media.MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback;
import android.media.MediaMetadata2;
import android.media.MediaPlayerBase;
import android.media.MediaPlaylistAgent;
import android.media.MediaSession2;
import android.media.MediaSession2.Command;
import android.media.MediaSession2.CommandGroup;
@@ -50,6 +51,7 @@ import android.media.update.MediaController2Provider;
import android.media.update.MediaItem2Provider;
import android.media.update.MediaLibraryService2Provider.LibraryRootProvider;
import android.media.update.MediaMetadata2Provider;
import android.media.update.MediaPlaylistAgentProvider;
import android.media.update.MediaSession2Provider;
import android.media.update.MediaSession2Provider.BuilderBaseProvider;
import android.media.update.MediaSession2Provider.CommandButtonProvider.BuilderProvider;
@@ -76,6 +78,7 @@ import com.android.media.MediaItem2Impl;
import com.android.media.MediaLibraryService2Impl;
import com.android.media.MediaLibraryService2Impl.LibraryRootImpl;
import com.android.media.MediaMetadata2Impl;
import com.android.media.MediaPlaylistAgentImpl;
import com.android.media.MediaSession2Impl;
import com.android.media.MediaSession2Impl.PlaylistParamsImpl;
import com.android.media.MediaSessionService2Impl;
@@ -301,4 +304,10 @@ public class ApiFactory implements StaticProvider {
    public PlaybackState2 fromBundle_PlaybackState2(Context context, Bundle bundle) {
        return PlaybackState2Impl.fromBundle(context, bundle);
    }

    @Override
    public MediaPlaylistAgentProvider createMediaPlaylistAgent(Context context,
            MediaPlaylistAgent instance) {
        return new MediaPlaylistAgentImpl(context, instance);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ public class MediaController2Test extends MediaSession2TestBase {
        assertTrue(mPlayer.mSkipToPreviousCalled);
    }

    @Ignore
    @Test
    public void testSkipToNextItem() throws InterruptedException {
        mController.skipToNextItem();
+9 −7
Original line number Diff line number Diff line
@@ -187,6 +187,7 @@ public class MediaSession2Test extends MediaSession2TestBase {
        });
    }

    @Ignore
    @Test
    public void testSkipToNextItem() throws Exception {
        sHandler.postAndSync(() -> {
@@ -355,13 +356,14 @@ public class MediaSession2Test extends MediaSession2TestBase {
        assertEquals(1, callback.commands.size());
        assertEquals(MediaSession2.COMMAND_CODE_PLAYBACK_PAUSE,
                (long) callback.commands.get(0).getCommandCode());
        controller.skipToNextItem();
        assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS));
        assertTrue(mPlayer.mSkipToNextCalled);
        assertFalse(mPlayer.mPauseCalled);
        assertEquals(2, callback.commands.size());
        assertEquals(MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM,
                (long) callback.commands.get(1).getCommandCode());
        // TODO(jaewan): uncomment followings once skipToNextItem is implemented (b/74090741)
//        controller.skipToNextItem();
//        assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS));
//        assertTrue(mPlayer.mSkipToNextCalled);
//        assertFalse(mPlayer.mPauseCalled);
//        assertEquals(2, callback.commands.size());
//        assertEquals(MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM,
//                (long) callback.commands.get(1).getCommandCode());
    }

    @Test