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