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 42 @Implementation getProfileProxy(Context context, BluetoothProfile.ServiceListener listener, int profile)43 protected boolean getProfileProxy(Context context, BluetoothProfile.ServiceListener listener, 44 int profile) { 45 mServiceListener = listener; 46 return true; 47 } 48 getServiceListener()49 public BluetoothProfile.ServiceListener getServiceListener() { 50 return mServiceListener; 51 } 52 53 @Implementation getSupportedProfiles()54 protected List<Integer> getSupportedProfiles() { 55 return mSupportedProfiles; 56 } 57 setSupportedProfiles(List<Integer> supportedProfiles)58 public void setSupportedProfiles(List<Integer> supportedProfiles) { 59 mSupportedProfiles = supportedProfiles; 60 } 61 62 @Implementation getMostRecentlyConnectedDevices()63 protected List<BluetoothDevice> getMostRecentlyConnectedDevices() { 64 return mMostRecentlyConnectedDevices; 65 } 66 setMostRecentlyConnectedDevices(List<BluetoothDevice> list)67 public void setMostRecentlyConnectedDevices(List<BluetoothDevice> list) { 68 mMostRecentlyConnectedDevices = list; 69 } 70 71 @Implementation removeActiveDevice(int profiles)72 protected boolean removeActiveDevice(int profiles) { 73 if (profiles != ACTIVE_DEVICE_AUDIO && profiles != ACTIVE_DEVICE_PHONE_CALL 74 && profiles != ACTIVE_DEVICE_ALL) { 75 return false; 76 } 77 return true; 78 } 79 80 @Implementation setActiveDevice(BluetoothDevice device, int profiles)81 protected boolean setActiveDevice(BluetoothDevice device, int profiles) { 82 if (device == null) { 83 return false; 84 } 85 if (profiles != ACTIVE_DEVICE_AUDIO && profiles != ACTIVE_DEVICE_PHONE_CALL 86 && profiles != ACTIVE_DEVICE_ALL) { 87 return false; 88 } 89 return true; 90 } 91 92 @Implementation getUuids()93 protected ParcelUuid[] getUuids() { 94 return mParcelUuids; 95 } 96 setUuids(ParcelUuid[] uuids)97 public void setUuids(ParcelUuid[] uuids) { 98 mParcelUuids = uuids; 99 } 100 } 101