1 /* 2 * Copyright (C) 2017 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 com.android.tv.testing.shadows; 18 19 import android.app.PendingIntent; 20 import android.content.Context; 21 import android.media.MediaMetadata; 22 import android.media.session.MediaSession; 23 import android.media.session.PlaybackState; 24 import org.robolectric.annotation.Implementation; 25 import org.robolectric.annotation.Implements; 26 27 /** Shadow {@link MediaSession}. */ 28 @Implements(MediaSession.class) 29 public class ShadowMediaSession { 30 31 public MediaSession.Callback mCallback; 32 public PendingIntent mMediaButtonReceiver; 33 public PendingIntent mSessionActivity; 34 public PlaybackState mPlaybackState; 35 public MediaMetadata mMediaMetadata; 36 public int mFlags; 37 public boolean mActive; 38 public boolean mReleased; 39 40 /** Stand-in for the MediaSession constructor with the same parameters. */ __constructor__(Context context, String tag, int userID)41 public void __constructor__(Context context, String tag, int userID) { 42 // This empty method prevents the real MediaSession constructor from being called. 43 } 44 45 @Implementation setCallback(MediaSession.Callback callback)46 public void setCallback(MediaSession.Callback callback) { 47 mCallback = callback; 48 } 49 50 @Implementation setMediaButtonReceiver(PendingIntent mbr)51 public void setMediaButtonReceiver(PendingIntent mbr) { 52 mMediaButtonReceiver = mbr; 53 } 54 55 @Implementation setSessionActivity(PendingIntent activity)56 public void setSessionActivity(PendingIntent activity) { 57 mSessionActivity = activity; 58 } 59 60 @Implementation setPlaybackState(PlaybackState state)61 public void setPlaybackState(PlaybackState state) { 62 mPlaybackState = state; 63 } 64 65 @Implementation setMetadata(MediaMetadata metadata)66 public void setMetadata(MediaMetadata metadata) { 67 mMediaMetadata = metadata; 68 } 69 70 @Implementation setFlags(int flags)71 public void setFlags(int flags) { 72 mFlags = flags; 73 } 74 75 @Implementation isActive()76 public boolean isActive() { 77 return mActive; 78 } 79 80 @Implementation setActive(boolean active)81 public void setActive(boolean active) { 82 mActive = active; 83 } 84 85 @Implementation release()86 public void release() { 87 mReleased = true; 88 } 89 } 90