1 /*
2  * Copyright (C) 2024 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.connecteddevice.audiosharing.audiostreams.testshadows;
18 
19 import com.android.settingslib.media.LocalMediaManager;
20 import com.android.settingslib.media.MediaDevice;
21 
22 import org.robolectric.annotation.Implementation;
23 import org.robolectric.annotation.Implements;
24 import org.robolectric.annotation.Resetter;
25 
26 import java.util.Collections;
27 
28 @Implements(value = LocalMediaManager.class, callThroughByDefault = false)
29 public class ShadowLocalMediaManager {
30 
31     private static LocalMediaManager sMockManager;
32     private static LocalMediaManager.DeviceCallback sDeviceCallback;
33 
setUseMock(LocalMediaManager mockLocalMediaManager)34     public static void setUseMock(LocalMediaManager mockLocalMediaManager) {
35         sMockManager = mockLocalMediaManager;
36     }
37 
38     /** Reset static fields */
39     @Resetter
reset()40     public static void reset() {
41         sMockManager = null;
42         sDeviceCallback = null;
43     }
44 
45     /** Triggers onDeviceListUpdate of {@link LocalMediaManager.DeviceCallback} */
onDeviceListUpdate()46     public static void onDeviceListUpdate() {
47         sDeviceCallback.onDeviceListUpdate(Collections.emptyList());
48     }
49 
50     /** Starts scan */
51     @Implementation
startScan()52     public void startScan() {
53         sMockManager.startScan();
54     }
55 
56     /** Registers {@link LocalMediaManager.DeviceCallback} */
57     @Implementation
registerCallback(LocalMediaManager.DeviceCallback deviceCallback)58     public void registerCallback(LocalMediaManager.DeviceCallback deviceCallback) {
59         sMockManager.registerCallback(deviceCallback);
60         sDeviceCallback = deviceCallback;
61     }
62 
63     @Implementation
getCurrentConnectedDevice()64     public MediaDevice getCurrentConnectedDevice() {
65         return sMockManager.getCurrentConnectedDevice();
66     }
67 }
68