1 /* 2 * Copyright (C) 2022 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 android.car.builtin.bluetooth; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.bluetooth.BluetoothDevice; 22 import android.bluetooth.BluetoothHeadsetClient; 23 import android.os.Bundle; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 28 /** 29 * Provides access to {@code android.bluetooth.BluetoothHeadsetClient} calls. 30 * @hide 31 * @deprecated Moving towards a framework solution that better integrates voice recognition. 32 */ 33 @Deprecated 34 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 35 public final class BluetoothHeadsetClientHelper { 36 BluetoothHeadsetClientHelper()37 private BluetoothHeadsetClientHelper() { 38 throw new UnsupportedOperationException("contains only static members"); 39 } 40 41 /** 42 * Gets connected devices that support BVRA (voice recognition). 43 * 44 * @param headsetClient Proxy object for controlling the Bluetooth HFP Client service. 45 * @return a list of connected devices that support BVRA. 46 */ getConnectedBvraDevices( @onNull BluetoothHeadsetClient headsetClient)47 public static List<BluetoothDevice> getConnectedBvraDevices( 48 @NonNull BluetoothHeadsetClient headsetClient) { 49 List<BluetoothDevice> devices = headsetClient.getConnectedDevices(); 50 List<BluetoothDevice> bvraDevices = new ArrayList<BluetoothDevice>(); 51 for (int i = 0; i < devices.size(); i++) { 52 BluetoothDevice device = devices.get(i); 53 Bundle bundle = headsetClient.getCurrentAgFeatures(device); 54 if (bundle != null && bundle.getBoolean( 55 BluetoothHeadsetClient.EXTRA_AG_FEATURE_VOICE_RECOGNITION)) { 56 bvraDevices.add(device); 57 } 58 } 59 return bvraDevices; 60 } 61 62 /** 63 * Starts BVRA. 64 * 65 * @param headsetClient Proxy object for controlling the Bluetooth HFP Client service. 66 * @param device The connected device whose voice recognition will be started. 67 * @return {@code true} if the command has been issued successfully; {@code false} otherwise. 68 */ startVoiceRecognition(@onNull BluetoothHeadsetClient headsetClient, BluetoothDevice device)69 public static boolean startVoiceRecognition(@NonNull BluetoothHeadsetClient headsetClient, 70 BluetoothDevice device) { 71 return headsetClient.startVoiceRecognition(device); 72 } 73 74 /** 75 * Stops BVRA. 76 * 77 * @param headsetClient Proxy object for controlling the Bluetooth HFP Client service. 78 * @param device The connected device whose voice recognition will be stopped. 79 * @return {@code true} if the command has been issued successfully; {@code false} otherwise. 80 */ stopVoiceRecognition(@onNull BluetoothHeadsetClient headsetClient, BluetoothDevice device)81 public static boolean stopVoiceRecognition(@NonNull BluetoothHeadsetClient headsetClient, 82 BluetoothDevice device) { 83 return headsetClient.stopVoiceRecognition(device); 84 } 85 } 86