1 /* 2 * Copyright (C) 2019 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.car.dialer.testutils; 18 19 import android.bluetooth.BluetoothAdapter; 20 import android.bluetooth.BluetoothProfile; 21 22 import androidx.annotation.Nullable; 23 24 import org.robolectric.annotation.Implementation; 25 import org.robolectric.annotation.Implements; 26 import org.robolectric.shadows.ShadowApplication; 27 28 import java.util.HashMap; 29 import java.util.Map; 30 31 /** 32 * Derived from {@link org.robolectric.shadows.ShadowBluetoothAdapter} 33 * 34 * Needed for Bluetooth related tests because the default ShadowBluetooth Adapter does not include 35 * an implementation of setProfileConnectionState. 36 */ 37 @Implements(value = BluetoothAdapter.class) 38 public class ShadowBluetoothAdapterForDialer extends 39 org.robolectric.shadows.ShadowBluetoothAdapter { 40 41 private static boolean bluetoothAvailable = true; 42 private Map<Integer, Integer> profileConnectionStateData = new HashMap<>(); 43 44 @Nullable 45 @Implementation getDefaultAdapter()46 public static synchronized BluetoothAdapter getDefaultAdapter() { 47 if (!bluetoothAvailable) { 48 return null; 49 } 50 return (BluetoothAdapter) ShadowApplication.getInstance().getBluetoothAdapter(); 51 } 52 53 /** 54 * Sets if the default Bluetooth Adapter is null 55 */ setBluetoothAvailable(boolean available)56 public static void setBluetoothAvailable(boolean available) { 57 bluetoothAvailable = available; 58 } 59 } 60