1 /*
2  * Copyright (C) 2010-2014 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 
18 package android.bluetooth;
19 
20 import android.Manifest;
21 import android.annotation.RequiresPermission;
22 
23 import java.util.List;
24 
25 /**
26  * Public APIs for the Bluetooth Profiles.
27  *
28  * <p> Clients should call {@link BluetoothAdapter#getProfileProxy},
29  * to get the Profile Proxy. Each public profile implements this
30  * interface.
31  */
32 public interface BluetoothProfile {
33 
34     /**
35      * Extra for the connection state intents of the individual profiles.
36      *
37      * This extra represents the current connection state of the profile of the
38      * Bluetooth device.
39      */
40     public static final String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
41 
42     /**
43      * Extra for the connection state intents of the individual profiles.
44      *
45      * This extra represents the previous connection state of the profile of the
46      * Bluetooth device.
47      */
48     public static final String EXTRA_PREVIOUS_STATE =
49         "android.bluetooth.profile.extra.PREVIOUS_STATE";
50 
51     /** The profile is in disconnected state */
52     public static final int STATE_DISCONNECTED  = 0;
53     /** The profile is in connecting state */
54     public static final int STATE_CONNECTING    = 1;
55     /** The profile is in connected state */
56     public static final int STATE_CONNECTED     = 2;
57     /** The profile is in disconnecting state */
58     public static final int STATE_DISCONNECTING = 3;
59 
60     /**
61      * Headset and Handsfree profile
62      */
63     public static final int HEADSET = 1;
64 
65     /**
66      * A2DP profile.
67      */
68     public static final int A2DP = 2;
69 
70     /**
71      * Health Profile
72      */
73     public static final int HEALTH = 3;
74 
75     /**
76      * Input Device Profile
77      * @hide
78      */
79     public static final int INPUT_DEVICE = 4;
80 
81     /**
82      * PAN Profile
83      * @hide
84      */
85     public static final int PAN = 5;
86 
87     /**
88      * PBAP
89      * @hide
90      */
91     public static final int PBAP = 6;
92 
93     /**
94      * GATT
95      */
96     static public final int GATT = 7;
97 
98     /**
99      * GATT_SERVER
100      */
101     static public final int GATT_SERVER = 8;
102 
103     /**
104      * MAP Profile
105      * @hide
106      */
107     public static final int MAP = 9;
108 
109     /*
110      * SAP Profile
111      * @hide
112      */
113     public static final int SAP = 10;
114 
115     /**
116      * A2DP Sink Profile
117      * @hide
118      */
119     public static final int A2DP_SINK = 11;
120 
121     /**
122      * AVRCP Controller Profile
123      * @hide
124      */
125     public static final int AVRCP_CONTROLLER = 12;
126 
127     /**
128      * Headset Client - HFP HF Role
129      * @hide
130      */
131     public static final int HEADSET_CLIENT = 16;
132 
133     /**
134      * Default priority for devices that we try to auto-connect to and
135      * and allow incoming connections for the profile
136      * @hide
137      **/
138     public static final int PRIORITY_AUTO_CONNECT = 1000;
139 
140     /**
141      *  Default priority for devices that allow incoming
142      * and outgoing connections for the profile
143      * @hide
144      **/
145     public static final int PRIORITY_ON = 100;
146 
147     /**
148      * Default priority for devices that does not allow incoming
149      * connections and outgoing connections for the profile.
150      * @hide
151      **/
152     public static final int PRIORITY_OFF = 0;
153 
154     /**
155      * Default priority when not set or when the device is unpaired
156      * @hide
157      * */
158     public static final int PRIORITY_UNDEFINED = -1;
159 
160     /**
161      * Get connected devices for this specific profile.
162      *
163      * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
164      *
165      * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
166      *
167      * @return List of devices. The list will be empty on error.
168      */
169     @RequiresPermission(Manifest.permission.BLUETOOTH)
getConnectedDevices()170     public List<BluetoothDevice> getConnectedDevices();
171 
172     /**
173      * Get a list of devices that match any of the given connection
174      * states.
175      *
176      * <p> If none of the devices match any of the given states,
177      * an empty list will be returned.
178      *
179      * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
180      *
181      * @param states Array of states. States can be one of
182      *              {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING},
183      *              {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
184      * @return List of devices. The list will be empty on error.
185      */
186     @RequiresPermission(Manifest.permission.BLUETOOTH)
getDevicesMatchingConnectionStates(int[] states)187     public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
188 
189     /**
190      * Get the current connection state of the profile
191      *
192      * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
193      *
194      * @param device Remote bluetooth device.
195      * @return State of the profile connection. One of
196      *               {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING},
197      *               {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
198      */
199     @RequiresPermission(Manifest.permission.BLUETOOTH)
getConnectionState(BluetoothDevice device)200     public int getConnectionState(BluetoothDevice device);
201 
202     /**
203      * An interface for notifying BluetoothProfile IPC clients when they have
204      * been connected or disconnected to the service.
205      */
206     public interface ServiceListener {
207         /**
208          * Called to notify the client when the proxy object has been
209          * connected to the service.
210          * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or
211          *                  {@link #A2DP}
212          * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or
213          *                {@link BluetoothA2dp}
214          */
onServiceConnected(int profile, BluetoothProfile proxy)215         public void onServiceConnected(int profile, BluetoothProfile proxy);
216 
217         /**
218          * Called to notify the client that this proxy object has been
219          * disconnected from the service.
220          * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or
221          *                  {@link #A2DP}
222          */
onServiceDisconnected(int profile)223         public void onServiceDisconnected(int profile);
224     }
225 }
226