• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settingslib.testutils.shadow;
18 
19 import static android.bluetooth.BluetoothAdapter.ACTIVE_DEVICE_ALL;
20 import static android.bluetooth.BluetoothAdapter.ACTIVE_DEVICE_AUDIO;
21 import static android.bluetooth.BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL;
22 
23 import android.bluetooth.BluetoothAdapter;
24 import android.bluetooth.BluetoothDevice;
25 import android.bluetooth.BluetoothProfile;
26 import android.content.Context;
27 import android.os.ParcelUuid;
28 
29 import org.robolectric.annotation.Implementation;
30 import org.robolectric.annotation.Implements;
31 
32 import java.util.List;
33 
34 @Implements(value = BluetoothAdapter.class)
35 public class ShadowBluetoothAdapter extends org.robolectric.shadows.ShadowBluetoothAdapter {
36 
37     private List<Integer> mSupportedProfiles;
38     private List<BluetoothDevice> mMostRecentlyConnectedDevices;
39     private BluetoothProfile.ServiceListener mServiceListener;
40     private ParcelUuid[] mParcelUuids;
41     private int mIsLeAudioBroadcastSourceSupported;
42     private int mIsLeAudioBroadcastAssistantSupported;
43 
44     @Implementation
getProfileProxy(Context context, BluetoothProfile.ServiceListener listener, int profile)45     protected boolean getProfileProxy(Context context, BluetoothProfile.ServiceListener listener,
46             int profile) {
47         mServiceListener = listener;
48         return true;
49     }
50 
getServiceListener()51     public BluetoothProfile.ServiceListener getServiceListener() {
52         return mServiceListener;
53     }
54 
55     @Implementation
getSupportedProfiles()56     protected List<Integer> getSupportedProfiles() {
57         return mSupportedProfiles;
58     }
59 
setSupportedProfiles(List<Integer> supportedProfiles)60     public void setSupportedProfiles(List<Integer> supportedProfiles) {
61         mSupportedProfiles = supportedProfiles;
62     }
63 
64     @Implementation
getMostRecentlyConnectedDevices()65     protected List<BluetoothDevice> getMostRecentlyConnectedDevices() {
66         return mMostRecentlyConnectedDevices;
67     }
68 
setMostRecentlyConnectedDevices(List<BluetoothDevice> list)69     public void setMostRecentlyConnectedDevices(List<BluetoothDevice> list) {
70         mMostRecentlyConnectedDevices = list;
71     }
72 
73     @Implementation
removeActiveDevice(int profiles)74     protected boolean removeActiveDevice(int profiles) {
75         if (profiles != ACTIVE_DEVICE_AUDIO && profiles != ACTIVE_DEVICE_PHONE_CALL
76                 && profiles != ACTIVE_DEVICE_ALL) {
77             return false;
78         }
79         return true;
80     }
81 
82     @Implementation
setActiveDevice(BluetoothDevice device, int profiles)83     protected boolean setActiveDevice(BluetoothDevice device, int profiles) {
84         if (device == null) {
85             return false;
86         }
87         if (profiles != ACTIVE_DEVICE_AUDIO && profiles != ACTIVE_DEVICE_PHONE_CALL
88                 && profiles != ACTIVE_DEVICE_ALL) {
89             return false;
90         }
91         return true;
92     }
93 
94     @Implementation
getUuids()95     protected ParcelUuid[] getUuids() {
96         return mParcelUuids;
97     }
98 
setUuids(ParcelUuid[] uuids)99     public void setUuids(ParcelUuid[] uuids) {
100         mParcelUuids = uuids;
101     }
102 
103     @Implementation
isLeAudioBroadcastSourceSupported()104     protected int isLeAudioBroadcastSourceSupported() {
105         return mIsLeAudioBroadcastSourceSupported;
106     }
107 
setIsLeAudioBroadcastSourceSupported(int isSupported)108     public void setIsLeAudioBroadcastSourceSupported(int isSupported) {
109         mIsLeAudioBroadcastSourceSupported = isSupported;
110     }
111 
112     @Implementation
isLeAudioBroadcastAssistantSupported()113     protected int isLeAudioBroadcastAssistantSupported() {
114         return mIsLeAudioBroadcastAssistantSupported;
115     }
116 
setIsLeAudioBroadcastAssistantSupported(int isSupported)117     public void setIsLeAudioBroadcastAssistantSupported(int isSupported) {
118         mIsLeAudioBroadcastAssistantSupported = isSupported;
119     }
120 }
121