1/*
2 * Copyright (C) 2010-2016 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
18package android.bluetooth;
19
20import android.Manifest;
21import android.annotation.RequiresPermission;
22import android.annotation.SystemApi;
23
24import java.util.List;
25
26/**
27 * Public APIs for the Bluetooth Profiles.
28 *
29 * <p> Clients should call {@link BluetoothAdapter#getProfileProxy},
30 * to get the Profile Proxy. Each public profile implements this
31 * interface.
32 */
33public interface BluetoothProfile {
34
35    /**
36     * Extra for the connection state intents of the individual profiles.
37     *
38     * This extra represents the current connection state of the profile of the
39     * Bluetooth device.
40     */
41    String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
42
43    /**
44     * Extra for the connection state intents of the individual profiles.
45     *
46     * This extra represents the previous connection state of the profile of the
47     * Bluetooth device.
48     */
49    String EXTRA_PREVIOUS_STATE =
50            "android.bluetooth.profile.extra.PREVIOUS_STATE";
51
52    /** The profile is in disconnected state */
53    int STATE_DISCONNECTED = 0;
54    /** The profile is in connecting state */
55    int STATE_CONNECTING = 1;
56    /** The profile is in connected state */
57    int STATE_CONNECTED = 2;
58    /** The profile is in disconnecting state */
59    int STATE_DISCONNECTING = 3;
60
61    /**
62     * Headset and Handsfree profile
63     */
64    int HEADSET = 1;
65
66    /**
67     * A2DP profile.
68     */
69    int A2DP = 2;
70
71    /**
72     * Health Profile
73     */
74    int HEALTH = 3;
75
76    /**
77     * HID Host
78     *
79     * @hide
80     */
81    int HID_HOST = 4;
82
83    /**
84     * PAN Profile
85     *
86     * @hide
87     */
88    int PAN = 5;
89
90    /**
91     * PBAP
92     *
93     * @hide
94     */
95    int PBAP = 6;
96
97    /**
98     * GATT
99     */
100    int GATT = 7;
101
102    /**
103     * GATT_SERVER
104     */
105    int GATT_SERVER = 8;
106
107    /**
108     * MAP Profile
109     *
110     * @hide
111     */
112    int MAP = 9;
113
114    /*
115     * SAP Profile
116     * @hide
117     */
118    int SAP = 10;
119
120    /**
121     * A2DP Sink Profile
122     *
123     * @hide
124     */
125    int A2DP_SINK = 11;
126
127    /**
128     * AVRCP Controller Profile
129     *
130     * @hide
131     */
132    int AVRCP_CONTROLLER = 12;
133
134    /**
135     * AVRCP Target Profile
136     *
137     * @hide
138     */
139    int AVRCP = 13;
140
141    /**
142     * Headset Client - HFP HF Role
143     *
144     * @hide
145     */
146    int HEADSET_CLIENT = 16;
147
148    /**
149     * PBAP Client
150     *
151     * @hide
152     */
153    int PBAP_CLIENT = 17;
154
155    /**
156     * MAP Messaging Client Equipment (MCE)
157     *
158     * @hide
159     */
160    int MAP_CLIENT = 18;
161
162    /**
163     * HID Device
164     */
165    int HID_DEVICE = 19;
166
167    /**
168     * Object Push Profile (OPP)
169     *
170     * @hide
171     */
172    int OPP = 20;
173
174    /**
175     * Hearing Aid Device
176     *
177     * @hide
178     */
179    int HEARING_AID = 21;
180
181    /**
182     * Max profile ID. This value should be updated whenever a new profile is added to match
183     * the largest value assigned to a profile.
184     *
185     * @hide
186     */
187    int MAX_PROFILE_ID = 21;
188
189    /**
190     * Default priority for devices that we try to auto-connect to and
191     * and allow incoming connections for the profile
192     *
193     * @hide
194     **/
195    int PRIORITY_AUTO_CONNECT = 1000;
196
197    /**
198     * Default priority for devices that allow incoming
199     * and outgoing connections for the profile
200     *
201     * @hide
202     **/
203    @SystemApi
204    int PRIORITY_ON = 100;
205
206    /**
207     * Default priority for devices that does not allow incoming
208     * connections and outgoing connections for the profile.
209     *
210     * @hide
211     **/
212    @SystemApi
213    int PRIORITY_OFF = 0;
214
215    /**
216     * Default priority when not set or when the device is unpaired
217     *
218     * @hide
219     */
220    int PRIORITY_UNDEFINED = -1;
221
222    /**
223     * Get connected devices for this specific profile.
224     *
225     * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
226     *
227     * @return List of devices. The list will be empty on error.
228     */
229    @RequiresPermission(Manifest.permission.BLUETOOTH)
230    public List<BluetoothDevice> getConnectedDevices();
231
232    /**
233     * Get a list of devices that match any of the given connection
234     * states.
235     *
236     * <p> If none of the devices match any of the given states,
237     * an empty list will be returned.
238     *
239     * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
240     * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
241     * @return List of devices. The list will be empty on error.
242     */
243    @RequiresPermission(Manifest.permission.BLUETOOTH)
244    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
245
246    /**
247     * Get the current connection state of the profile
248     *
249     * @param device Remote bluetooth device.
250     * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
251     * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
252     */
253    @RequiresPermission(Manifest.permission.BLUETOOTH)
254    public int getConnectionState(BluetoothDevice device);
255
256    /**
257     * An interface for notifying BluetoothProfile IPC clients when they have
258     * been connected or disconnected to the service.
259     */
260    public interface ServiceListener {
261        /**
262         * Called to notify the client when the proxy object has been
263         * connected to the service.
264         *
265         * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP}
266         * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or {@link
267         * BluetoothA2dp}
268         */
269        public void onServiceConnected(int profile, BluetoothProfile proxy);
270
271        /**
272         * Called to notify the client that this proxy object has been
273         * disconnected from the service.
274         *
275         * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP}
276         */
277        public void onServiceDisconnected(int profile);
278    }
279
280    /**
281     * Convert an integer value of connection state into human readable string
282     *
283     * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
284     * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED}
285     * @return a string representation of the connection state, STATE_UNKNOWN if the state
286     * is not defined
287     * @hide
288     */
289    static String getConnectionStateName(int connectionState) {
290        switch (connectionState) {
291            case STATE_DISCONNECTED:
292                return "STATE_DISCONNECTED";
293            case STATE_CONNECTING:
294                return "STATE_CONNECTING";
295            case STATE_CONNECTED:
296                return "STATE_CONNECTED";
297            case STATE_DISCONNECTING:
298                return "STATE_DISCONNECTING";
299            default:
300                return "STATE_UNKNOWN";
301        }
302    }
303}
304