1 /* 2 * Copyright (C) 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 com.android.settings.testutils.shadow; 18 19 import android.media.MediaRouter; 20 21 import static org.robolectric.RuntimeEnvironment.application; 22 23 import org.robolectric.annotation.Implements; 24 import org.robolectric.annotation.Resetter; 25 import org.robolectric.shadow.api.Shadow; 26 27 import java.util.concurrent.CopyOnWriteArrayList; 28 29 @Implements(value = MediaRouter.class, inheritImplementationMethods = true) 30 public class ShadowMediaRouter extends org.robolectric.shadows.ShadowMediaRouter { 31 MediaRouter.RouteInfo mSelectedRoute; 32 33 final CopyOnWriteArrayList<MediaRouter.Callback> mCallbacks = 34 new CopyOnWriteArrayList<>(); 35 getSelectedRoute(int type)36 public MediaRouter.RouteInfo getSelectedRoute(int type) { 37 return mSelectedRoute; 38 } 39 addCallback(int types, MediaRouter.Callback cb)40 public void addCallback(int types, MediaRouter.Callback cb) { 41 mCallbacks.add(cb); 42 } 43 removeCallback(MediaRouter.Callback cb)44 public void removeCallback(MediaRouter.Callback cb) { 45 if (mCallbacks.contains(cb)) 46 mCallbacks.remove(cb); 47 } 48 getShadow()49 public static ShadowMediaRouter getShadow() { 50 return Shadow.extract(application.getSystemService(MediaRouter.class)); 51 } 52 53 @Resetter reset()54 public void reset() { 55 mCallbacks.clear(); 56 } 57 } 58