162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh/* 262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Copyright (C) 2010 The Android Open Source Project 362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Licensed under the Apache License, Version 2.0 (the "License"); 562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * you may not use this file except in compliance with the License. 662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * You may obtain a copy of the License at 762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * http://www.apache.org/licenses/LICENSE-2.0 962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 1062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Unless required by applicable law or agreed to in writing, software 1162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * distributed under the License is distributed on an "AS IS" BASIS, 1262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * See the License for the specific language governing permissions and 1462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * limitations under the License. 1562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 1662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 1762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 1862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganeshpackage android.bluetooth; 1962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 2003cd78cf5e51c3adb78d2e3d314838dcf3e36b26Jaikumar Ganeshimport java.util.List; 2162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 2262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh/** 2362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Public APIs for the Bluetooth Profiles. 2462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 2562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * <p> Clients should call {@link BluetoothAdapter#getProfileProxy}, 2662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * to get the Profile Proxy. Each public profile implements this 2762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * interface. 2862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 2962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganeshpublic interface BluetoothProfile { 3062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 3162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 3262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Extra for the connection state intents of the individual profiles. 3362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 3462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * This extra represents the current connection state of the profile of the 3562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Bluetooth device. 3662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 3762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final String EXTRA_STATE = "android.bluetooth.profile.extra.STATE"; 3862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 3962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 4062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Extra for the connection state intents of the individual profiles. 4162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 4262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * This extra represents the previous connection state of the profile of the 4362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Bluetooth device. 4462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 4562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final String EXTRA_PREVIOUS_STATE = 4662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh "android.bluetooth.profile.extra.PREVIOUS_STATE"; 4762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 4862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** The profile is in disconnected state */ 4962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int STATE_DISCONNECTED = 0; 5062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** The profile is in connecting state */ 5162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int STATE_CONNECTING = 1; 5262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** The profile is in connected state */ 5362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int STATE_CONNECTED = 2; 5462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** The profile is in disconnecting state */ 5562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int STATE_DISCONNECTING = 3; 5662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 5762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 5862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Headset and Handsfree profile 5962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 6062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int HEADSET = 1; 6174ef1199459629c5dd9f272f8cd706d82cdfeeb1Jaikumar Ganesh 6262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 6362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * A2DP profile. 6462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 6562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int A2DP = 2; 6674ef1199459629c5dd9f272f8cd706d82cdfeeb1Jaikumar Ganesh 674ab0e7746fe74a9e4d75d374f73b7af87420b2f6Jaikumar Ganesh /** 682ea1e85dcb57d17f5782dbafa1d25eb51c630e4bJaikumar Ganesh * Health Profile 692ea1e85dcb57d17f5782dbafa1d25eb51c630e4bJaikumar Ganesh */ 702ea1e85dcb57d17f5782dbafa1d25eb51c630e4bJaikumar Ganesh public static final int HEALTH = 3; 712ea1e85dcb57d17f5782dbafa1d25eb51c630e4bJaikumar Ganesh 722ea1e85dcb57d17f5782dbafa1d25eb51c630e4bJaikumar Ganesh /** 734ab0e7746fe74a9e4d75d374f73b7af87420b2f6Jaikumar Ganesh * Input Device Profile 744ab0e7746fe74a9e4d75d374f73b7af87420b2f6Jaikumar Ganesh * @hide 754ab0e7746fe74a9e4d75d374f73b7af87420b2f6Jaikumar Ganesh */ 762ea1e85dcb57d17f5782dbafa1d25eb51c630e4bJaikumar Ganesh public static final int INPUT_DEVICE = 4; 7762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 7862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 7974ef1199459629c5dd9f272f8cd706d82cdfeeb1Jaikumar Ganesh * PAN Profile 8074ef1199459629c5dd9f272f8cd706d82cdfeeb1Jaikumar Ganesh * @hide 8174ef1199459629c5dd9f272f8cd706d82cdfeeb1Jaikumar Ganesh */ 822ea1e85dcb57d17f5782dbafa1d25eb51c630e4bJaikumar Ganesh public static final int PAN = 5; 8374ef1199459629c5dd9f272f8cd706d82cdfeeb1Jaikumar Ganesh 8474ef1199459629c5dd9f272f8cd706d82cdfeeb1Jaikumar Ganesh /** 85cb1d354c1e9b458a0426cd08520d938012e32b34Jaikumar Ganesh * PBAP 86cb1d354c1e9b458a0426cd08520d938012e32b34Jaikumar Ganesh * @hide 87cb1d354c1e9b458a0426cd08520d938012e32b34Jaikumar Ganesh */ 88cb1d354c1e9b458a0426cd08520d938012e32b34Jaikumar Ganesh public static final int PBAP = 6; 89cb1d354c1e9b458a0426cd08520d938012e32b34Jaikumar Ganesh 90cb1d354c1e9b458a0426cd08520d938012e32b34Jaikumar Ganesh /** 9162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Default priority for devices that we try to auto-connect to and 9262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * and allow incoming connections for the profile 9362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * @hide 9462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh **/ 9562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int PRIORITY_AUTO_CONNECT = 1000; 9662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 9762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 9862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Default priority for devices that allow incoming 9962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * and outgoing connections for the profile 10062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * @hide 10162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh **/ 10262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int PRIORITY_ON = 100; 10362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 10462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 10562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Default priority for devices that does not allow incoming 10662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * connections and outgoing connections for the profile. 10762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * @hide 10862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh **/ 10962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int PRIORITY_OFF = 0; 11062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 11162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 11262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Default priority when not set or when the device is unpaired 11362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * @hide 11462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * */ 11562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public static final int PRIORITY_UNDEFINED = -1; 11662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 11762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 11862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Get connected devices for this specific profile. 11962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 12062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * <p> Return the set of devices which are in state {@link #STATE_CONNECTED} 12162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 122c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 12362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 12403cd78cf5e51c3adb78d2e3d314838dcf3e36b26Jaikumar Ganesh * @return List of devices. The list will be empty on error. 12562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 12603cd78cf5e51c3adb78d2e3d314838dcf3e36b26Jaikumar Ganesh public List<BluetoothDevice> getConnectedDevices(); 12762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 12862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 129c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Get a list of devices that match any of the given connection 13062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * states. 13162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 132c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p> If none of the devices match any of the given states, 133c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * an empty list will be returned. 13462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 135c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 13662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 13762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * @param states Array of states. States can be one of 13862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING}, 13962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}, 14003cd78cf5e51c3adb78d2e3d314838dcf3e36b26Jaikumar Ganesh * @return List of devices. The list will be empty on error. 14162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 14203cd78cf5e51c3adb78d2e3d314838dcf3e36b26Jaikumar Ganesh public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states); 14362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 14462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 14562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Get the current connection state of the profile 14662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 147c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 14862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * 14962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * @param device Remote bluetooth device. 15062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * @return State of the profile connection. One of 15162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING}, 15262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING} 15362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 15462c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public int getConnectionState(BluetoothDevice device); 15562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 15662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 15762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * An interface for notifying BluetoothProfile IPC clients when they have 15862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * been connected or disconnected to the service. 15962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 16062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public interface ServiceListener { 16162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 16262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Called to notify the client when the proxy object has been 16362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * connected to the service. 1642d68a6ba3c1354f363e5ee77448f163664bf47d9Scott Main * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or 16562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * {@link #A2DP} 1662d68a6ba3c1354f363e5ee77448f163664bf47d9Scott Main * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or 16762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * {@link BluetoothA2dp} 16862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 16962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public void onServiceConnected(int profile, BluetoothProfile proxy); 17062c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh 17162c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh /** 17262c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * Called to notify the client that this proxy object has been 17362c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * disconnected from the service. 1742d68a6ba3c1354f363e5ee77448f163664bf47d9Scott Main * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or 17562c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh * {@link #A2DP} 17662c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh */ 17762c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh public void onServiceDisconnected(int profile); 17862c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh } 17962c37efc9e894809b29a004c142a8e0a6b374db7Jaikumar Ganesh} 180