The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.server; |
| 18 | |
| 19 | import android.bluetooth.BluetoothA2dp; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 20 | import android.bluetooth.BluetoothAdapter; |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothClass; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.bluetooth.BluetoothDevice; |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 23 | import android.bluetooth.BluetoothInputDevice; |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 24 | import android.bluetooth.BluetoothPan; |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 25 | import android.bluetooth.BluetoothProfile; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 26 | import android.bluetooth.BluetoothUuid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
| 29 | import android.os.Handler; |
| 30 | import android.os.Message; |
Jaikumar Ganesh | 577dd1f | 2009-12-17 14:59:10 -0800 | [diff] [blame] | 31 | import android.os.ParcelUuid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 32 | import android.os.PowerManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.util.Log; |
| 34 | |
| 35 | import java.util.HashMap; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 36 | import java.util.List; |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 37 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | * @hide |
| 41 | */ |
| 42 | class BluetoothEventLoop { |
| 43 | private static final String TAG = "BluetoothEventLoop"; |
| 44 | private static final boolean DBG = false; |
| 45 | |
| 46 | private int mNativeData; |
| 47 | private Thread mThread; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 48 | private boolean mStarted; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | private boolean mInterrupted; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 50 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 51 | private final HashMap<String, Integer> mPasskeyAgentRequestData; |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 52 | private final HashMap<String, Integer> mAuthorizationAgentRequestData; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 53 | private final BluetoothService mBluetoothService; |
| 54 | private final BluetoothAdapter mAdapter; |
Matthew Xie | 7f9ecca | 2011-07-15 13:03:58 -0700 | [diff] [blame] | 55 | private final BluetoothAdapterStateMachine mBluetoothState; |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 56 | private BluetoothA2dp mA2dp; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 57 | private final Context mContext; |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 58 | // The WakeLock is used for bringing up the LCD during a pairing request |
| 59 | // from remote device when Android is in Suspend state. |
| 60 | private PowerManager.WakeLock mWakeLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 62 | private static final int EVENT_RESTART_BLUETOOTH = 1; |
| 63 | private static final int EVENT_PAIRING_CONSENT_DELAYED_ACCEPT = 2; |
| 64 | private static final int EVENT_AGENT_CANCEL = 3; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 66 | private static final int CREATE_DEVICE_ALREADY_EXISTS = 1; |
| 67 | private static final int CREATE_DEVICE_SUCCESS = 0; |
| 68 | private static final int CREATE_DEVICE_FAILED = -1; |
| 69 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; |
| 71 | private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH; |
| 72 | |
| 73 | private final Handler mHandler = new Handler() { |
| 74 | @Override |
| 75 | public void handleMessage(Message msg) { |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 76 | String address = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | switch (msg.what) { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 78 | case EVENT_RESTART_BLUETOOTH: |
Nick Pelly | 37b5a10 | 2009-03-24 20:46:18 -0700 | [diff] [blame] | 79 | mBluetoothService.restart(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 80 | break; |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 81 | case EVENT_PAIRING_CONSENT_DELAYED_ACCEPT: |
| 82 | address = (String)msg.obj; |
| 83 | if (address != null) { |
| 84 | mBluetoothService.setPairingConfirmation(address, true); |
| 85 | } |
| 86 | break; |
Jaikumar Ganesh | e5d93b7 | 2009-10-08 02:27:52 -0700 | [diff] [blame] | 87 | case EVENT_AGENT_CANCEL: |
| 88 | // Set the Bond State to BOND_NONE. |
| 89 | // We always have only 1 device in BONDING state. |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 90 | String[] devices = mBluetoothService.listInState(BluetoothDevice.BOND_BONDING); |
Jaikumar Ganesh | e5d93b7 | 2009-10-08 02:27:52 -0700 | [diff] [blame] | 91 | if (devices.length == 0) { |
| 92 | break; |
| 93 | } else if (devices.length > 1) { |
| 94 | Log.e(TAG, " There is more than one device in the Bonding State"); |
| 95 | break; |
| 96 | } |
| 97 | address = devices[0]; |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 98 | mBluetoothService.setBondState(address, |
Jaikumar Ganesh | e5d93b7 | 2009-10-08 02:27:52 -0700 | [diff] [blame] | 99 | BluetoothDevice.BOND_NONE, |
| 100 | BluetoothDevice.UNBOND_REASON_REMOTE_AUTH_CANCELED); |
| 101 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | static { classInitNative(); } |
| 107 | private static native void classInitNative(); |
| 108 | |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 109 | /* package */ BluetoothEventLoop(Context context, BluetoothAdapter adapter, |
Matthew Xie | 7f9ecca | 2011-07-15 13:03:58 -0700 | [diff] [blame] | 110 | BluetoothService bluetoothService, |
| 111 | BluetoothAdapterStateMachine bluetoothState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | mBluetoothService = bluetoothService; |
| 113 | mContext = context; |
Matthew Xie | 7f9ecca | 2011-07-15 13:03:58 -0700 | [diff] [blame] | 114 | mBluetoothState = bluetoothState; |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 115 | mPasskeyAgentRequestData = new HashMap<String, Integer>(); |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 116 | mAuthorizationAgentRequestData = new HashMap<String, Integer>(); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 117 | mAdapter = adapter; |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 118 | //WakeLock instantiation in BluetoothEventLoop class |
| 119 | PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 120 | mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP |
| 121 | | PowerManager.ON_AFTER_RELEASE, TAG); |
| 122 | mWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | initializeNativeDataNative(); |
Jaikumar Ganesh | 7d0548d | 2010-10-18 15:29:09 -0700 | [diff] [blame] | 124 | } |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 125 | |
Jaikumar Ganesh | 7d0548d | 2010-10-18 15:29:09 -0700 | [diff] [blame] | 126 | /*package*/ void getProfileProxy() { |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 127 | mAdapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.A2DP); |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 128 | mAdapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.INPUT_DEVICE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 131 | private BluetoothProfile.ServiceListener mProfileServiceListener = |
| 132 | new BluetoothProfile.ServiceListener() { |
| 133 | public void onServiceConnected(int profile, BluetoothProfile proxy) { |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 134 | if (profile == BluetoothProfile.A2DP) { |
| 135 | mA2dp = (BluetoothA2dp) proxy; |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 136 | } |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 137 | } |
| 138 | public void onServiceDisconnected(int profile) { |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 139 | if (profile == BluetoothProfile.A2DP) { |
| 140 | mA2dp = null; |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 141 | } |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 142 | } |
| 143 | }; |
| 144 | |
| 145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | protected void finalize() throws Throwable { |
| 147 | try { |
| 148 | cleanupNativeDataNative(); |
| 149 | } finally { |
| 150 | super.finalize(); |
| 151 | } |
| 152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 154 | /* package */ HashMap<String, Integer> getPasskeyAgentRequestData() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | return mPasskeyAgentRequestData; |
| 156 | } |
| 157 | |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 158 | /* package */ HashMap<String, Integer> getAuthorizationAgentRequestData() { |
| 159 | return mAuthorizationAgentRequestData; |
| 160 | } |
| 161 | |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 162 | /* package */ void start() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 164 | if (!isEventLoopRunningNative()) { |
| 165 | if (DBG) log("Starting Event Loop thread"); |
| 166 | startEventLoopNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 170 | public void stop() { |
| 171 | if (isEventLoopRunningNative()) { |
| 172 | if (DBG) log("Stopping Event Loop thread"); |
| 173 | stopEventLoopNative(); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | public boolean isEventLoopRunning() { |
| 178 | return isEventLoopRunningNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 181 | private void addDevice(String address, String[] properties) { |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 182 | BluetoothDeviceProperties deviceProperties = |
| 183 | mBluetoothService.getDeviceProperties(); |
| 184 | deviceProperties.addProperties(address, properties); |
| 185 | String rssi = deviceProperties.getProperty(address, "RSSI"); |
| 186 | String classValue = deviceProperties.getProperty(address, "Class"); |
| 187 | String name = deviceProperties.getProperty(address, "Name"); |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 188 | short rssiValue; |
| 189 | // For incoming connections, we don't get the RSSI value. Use a default of MIN_VALUE. |
| 190 | // If we accept the pairing, we will automatically show it at the top of the list. |
| 191 | if (rssi != null) { |
| 192 | rssiValue = (short)Integer.valueOf(rssi).intValue(); |
| 193 | } else { |
| 194 | rssiValue = Short.MIN_VALUE; |
| 195 | } |
| 196 | if (classValue != null) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 197 | Intent intent = new Intent(BluetoothDevice.ACTION_FOUND); |
| 198 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 199 | intent.putExtra(BluetoothDevice.EXTRA_CLASS, |
| 200 | new BluetoothClass(Integer.valueOf(classValue))); |
| 201 | intent.putExtra(BluetoothDevice.EXTRA_RSSI, rssiValue); |
| 202 | intent.putExtra(BluetoothDevice.EXTRA_NAME, name); |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 203 | |
| 204 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 205 | } else { |
| 206 | log ("ClassValue: " + classValue + " for remote device: " + address + " is null"); |
| 207 | } |
| 208 | } |
| 209 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 210 | /** |
| 211 | * Called by native code on a DeviceFound signal from org.bluez.Adapter. |
| 212 | * |
| 213 | * @param address the MAC address of the new device |
| 214 | * @param properties an array of property keys and value strings |
| 215 | * |
| 216 | * @see BluetoothDeviceProperties#addProperties(String, String[]) |
| 217 | */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 218 | private void onDeviceFound(String address, String[] properties) { |
| 219 | if (properties == null) { |
| 220 | Log.e(TAG, "ERROR: Remote device properties are null"); |
| 221 | return; |
| 222 | } |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 223 | addDevice(address, properties); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 226 | /** |
| 227 | * Called by native code on a DeviceDisappeared signal from |
| 228 | * org.bluez.Adapter. |
| 229 | * |
| 230 | * @param address the MAC address of the disappeared device |
| 231 | */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 232 | private void onDeviceDisappeared(String address) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 233 | Intent intent = new Intent(BluetoothDevice.ACTION_DISAPPEARED); |
| 234 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 236 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 238 | /** |
| 239 | * Called by native code on a DisconnectRequested signal from |
| 240 | * org.bluez.Device. |
| 241 | * |
| 242 | * @param deviceObjectPath the object path for the disconnecting device |
| 243 | */ |
Jaikumar Ganesh | 5e59ca8 | 2009-09-11 12:16:19 -0700 | [diff] [blame] | 244 | private void onDeviceDisconnectRequested(String deviceObjectPath) { |
| 245 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 246 | if (address == null) { |
| 247 | Log.e(TAG, "onDeviceDisconnectRequested: Address of the remote device in null"); |
| 248 | return; |
| 249 | } |
| 250 | Intent intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED); |
| 251 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 252 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 253 | } |
| 254 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 255 | /** |
| 256 | * Called by native code for the async response to a CreatePairedDevice |
| 257 | * method call to org.bluez.Adapter. |
| 258 | * |
| 259 | * @param address the MAC address of the device to pair |
| 260 | * @param result success or error result for the pairing operation |
| 261 | */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 262 | private void onCreatePairedDeviceResult(String address, int result) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | address = address.toUpperCase(); |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 264 | mBluetoothService.onCreatePairedDeviceResult(address, result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 267 | /** |
| 268 | * Called by native code on a DeviceCreated signal from org.bluez.Adapter. |
| 269 | * |
| 270 | * @param deviceObjectPath the object path for the created device |
| 271 | */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 272 | private void onDeviceCreated(String deviceObjectPath) { |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 273 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 274 | if (!mBluetoothService.isRemoteDeviceInCache(address)) { |
| 275 | // Incoming connection, we haven't seen this device, add to cache. |
| 276 | String[] properties = mBluetoothService.getRemoteDeviceProperties(address); |
| 277 | if (properties != null) { |
| 278 | addDevice(address, properties); |
| 279 | } |
| 280 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 281 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 284 | /** |
| 285 | * Called by native code on a DeviceRemoved signal from org.bluez.Adapter. |
| 286 | * |
| 287 | * @param deviceObjectPath the object path for the removed device |
| 288 | */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 289 | private void onDeviceRemoved(String deviceObjectPath) { |
| 290 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
Jaikumar Ganesh | 081a9b69a | 2010-03-02 17:19:20 -0800 | [diff] [blame] | 291 | if (address != null) { |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 292 | mBluetoothService.setBondState(address.toUpperCase(), BluetoothDevice.BOND_NONE, |
| 293 | BluetoothDevice.UNBOND_REASON_REMOVED); |
Jaikumar Ganesh | 081a9b69a | 2010-03-02 17:19:20 -0800 | [diff] [blame] | 294 | mBluetoothService.setRemoteDeviceProperty(address, "UUIDs", null); |
| 295 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 298 | /** |
| 299 | * Called by native code on a PropertyChanged signal from |
Matthew Xie | 7f9ecca | 2011-07-15 13:03:58 -0700 | [diff] [blame] | 300 | * org.bluez.Adapter. This method is also called from |
| 301 | * {@link BluetoothAdapterStateMachine} to set the "Pairable" |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 302 | * property when Bluetooth is enabled. |
| 303 | * |
| 304 | * @param propValues a string array containing the key and one or more |
| 305 | * values. |
| 306 | */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 307 | /*package*/ void onPropertyChanged(String[] propValues) { |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 308 | BluetoothAdapterProperties adapterProperties = |
| 309 | mBluetoothService.getAdapterProperties(); |
| 310 | |
| 311 | if (adapterProperties.isEmpty()) { |
Jaikumar Ganesh | 9519ce7 | 2009-09-08 21:37:32 -0700 | [diff] [blame] | 312 | // We have got a property change before |
| 313 | // we filled up our cache. |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 314 | adapterProperties.getAllProperties(); |
Jaikumar Ganesh | 9519ce7 | 2009-09-08 21:37:32 -0700 | [diff] [blame] | 315 | } |
Jaikumar Ganesh | b1ef244 | 2010-10-26 00:14:04 -0700 | [diff] [blame] | 316 | log("Property Changed: " + propValues[0] + " : " + propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 317 | String name = propValues[0]; |
| 318 | if (name.equals("Name")) { |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 319 | adapterProperties.setProperty(name, propValues[1]); |
Jaikumar Ganesh | 6a9d93c | 2009-09-20 11:48:16 -0700 | [diff] [blame] | 320 | Intent intent = new Intent(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED); |
| 321 | intent.putExtra(BluetoothAdapter.EXTRA_LOCAL_NAME, propValues[1]); |
Jaikumar Ganesh | 6a3c473 | 2010-12-15 13:12:57 -0800 | [diff] [blame] | 322 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 323 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 324 | } else if (name.equals("Pairable") || name.equals("Discoverable")) { |
| 325 | String pairable = name.equals("Pairable") ? propValues[1] : |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 326 | adapterProperties.getProperty("Pairable"); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 327 | String discoverable = name.equals("Discoverable") ? propValues[1] : |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 328 | adapterProperties.getProperty("Discoverable"); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 329 | |
| 330 | // This shouldn't happen, unless Adapter Properties are null. |
| 331 | if (pairable == null || discoverable == null) |
| 332 | return; |
| 333 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 334 | adapterProperties.setProperty(name, propValues[1]); |
Matthew Xie | 7f9ecca | 2011-07-15 13:03:58 -0700 | [diff] [blame] | 335 | |
| 336 | if (name.equals("Pairable")) { |
| 337 | if (pairable.equals("true")) { |
Jaikumar Ganesh | ef2cb7c | 2011-07-21 18:13:38 -0700 | [diff] [blame] | 338 | mBluetoothState.sendMessage(BluetoothAdapterStateMachine.BECAME_PAIRABLE); |
Matthew Xie | 7f9ecca | 2011-07-15 13:03:58 -0700 | [diff] [blame] | 339 | } else { |
Jaikumar Ganesh | ef2cb7c | 2011-07-21 18:13:38 -0700 | [diff] [blame] | 340 | mBluetoothState.sendMessage(BluetoothAdapterStateMachine.BECAME_NON_PAIRABLE); |
Matthew Xie | 7f9ecca | 2011-07-15 13:03:58 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 344 | int mode = BluetoothService.bluezStringToScanMode( |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 345 | pairable.equals("true"), |
| 346 | discoverable.equals("true")); |
| 347 | if (mode >= 0) { |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 348 | Intent intent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED); |
| 349 | intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, mode); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 350 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 351 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 352 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 353 | } else if (name.equals("Discovering")) { |
| 354 | Intent intent; |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 355 | adapterProperties.setProperty(name, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 356 | if (propValues[1].equals("true")) { |
| 357 | mBluetoothService.setIsDiscovering(true); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 358 | intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_STARTED); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 359 | } else { |
Jake Hamby | 39657b8 | 2010-11-19 16:45:58 -0800 | [diff] [blame] | 360 | // Stop the discovery. |
| 361 | mBluetoothService.cancelDiscovery(); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 362 | mBluetoothService.setIsDiscovering(false); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 363 | intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 364 | } |
| 365 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 366 | } else if (name.equals("Devices") || name.equals("UUIDs")) { |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 367 | String value = null; |
| 368 | int len = Integer.valueOf(propValues[1]); |
| 369 | if (len > 0) { |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 370 | StringBuilder str = new StringBuilder(); |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 371 | for (int i = 2; i < propValues.length; i++) { |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 372 | str.append(propValues[i]); |
| 373 | str.append(","); |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 374 | } |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 375 | value = str.toString(); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 376 | } |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 377 | adapterProperties.setProperty(name, value); |
Jaikumar Ganesh | 50b40ce | 2011-02-02 14:44:49 -0800 | [diff] [blame] | 378 | if (name.equals("UUIDs")) { |
| 379 | mBluetoothService.updateBluetoothState(value); |
| 380 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 381 | } else if (name.equals("Powered")) { |
| 382 | // bluetoothd has restarted, re-read all our properties. |
| 383 | // Note: bluez only sends this property change when it restarts. |
| 384 | if (propValues[1].equals("true")) |
| 385 | onRestartRequired(); |
Jaikumar Ganesh | ff7db40 | 2010-10-25 16:25:52 -0700 | [diff] [blame] | 386 | } else if (name.equals("DiscoverableTimeout")) { |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 387 | adapterProperties.setProperty(name, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 388 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 391 | /** |
| 392 | * Called by native code on a PropertyChanged signal from |
| 393 | * org.bluez.Device. |
| 394 | * |
| 395 | * @param deviceObjectPath the object path for the changed device |
| 396 | * @param propValues a string array containing the key and one or more |
| 397 | * values. |
| 398 | */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 399 | private void onDevicePropertyChanged(String deviceObjectPath, String[] propValues) { |
| 400 | String name = propValues[0]; |
| 401 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 402 | if (address == null) { |
| 403 | Log.e(TAG, "onDevicePropertyChanged: Address of the remote device in null"); |
| 404 | return; |
| 405 | } |
Jaikumar Ganesh | b1ef244 | 2010-10-26 00:14:04 -0700 | [diff] [blame] | 406 | log("Device property changed: " + address + " property: " |
| 407 | + name + " value: " + propValues[1]); |
| 408 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 409 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 410 | if (name.equals("Name")) { |
Jaikumar Ganesh | 2dfe101 | 2010-09-29 10:31:02 -0700 | [diff] [blame] | 411 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 412 | Intent intent = new Intent(BluetoothDevice.ACTION_NAME_CHANGED); |
| 413 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); |
| 414 | intent.putExtra(BluetoothDevice.EXTRA_NAME, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 415 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
Matthew Xie | 269e81a | 2011-07-26 18:36:49 -0700 | [diff] [blame] | 416 | } else if (name.equals("Alias")) { |
| 417 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 418 | } else if (name.equals("Class")) { |
Jaikumar Ganesh | 2dfe101 | 2010-09-29 10:31:02 -0700 | [diff] [blame] | 419 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 420 | Intent intent = new Intent(BluetoothDevice.ACTION_CLASS_CHANGED); |
| 421 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); |
| 422 | intent.putExtra(BluetoothDevice.EXTRA_CLASS, |
| 423 | new BluetoothClass(Integer.valueOf(propValues[1]))); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 424 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 425 | } else if (name.equals("Connected")) { |
Jaikumar Ganesh | 2dfe101 | 2010-09-29 10:31:02 -0700 | [diff] [blame] | 426 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 427 | Intent intent = null; |
| 428 | if (propValues[1].equals("true")) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 429 | intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); |
Jaikumar Ganesh | b7e029d | 2010-03-09 15:31:24 -0800 | [diff] [blame] | 430 | // Set the link timeout to 8000 slots (5 sec timeout) |
| 431 | // for bluetooth docks. |
| 432 | if (mBluetoothService.isBluetoothDock(address)) { |
| 433 | mBluetoothService.setLinkTimeout(address, 8000); |
| 434 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 435 | } else { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 436 | intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 437 | } |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 438 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 439 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 440 | } else if (name.equals("UUIDs")) { |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 441 | String uuid = null; |
| 442 | int len = Integer.valueOf(propValues[1]); |
| 443 | if (len > 0) { |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 444 | StringBuilder str = new StringBuilder(); |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 445 | for (int i = 2; i < propValues.length; i++) { |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 446 | str.append(propValues[i]); |
| 447 | str.append(","); |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 448 | } |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 449 | uuid = str.toString(); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 450 | } |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 451 | mBluetoothService.setRemoteDeviceProperty(address, name, uuid); |
Jaikumar Ganesh | 10eac97 | 2009-09-21 12:48:51 -0700 | [diff] [blame] | 452 | |
| 453 | // UUIDs have changed, query remote service channel and update cache. |
| 454 | mBluetoothService.updateDeviceServiceChannelCache(address); |
| 455 | |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 456 | mBluetoothService.sendUuidIntent(address); |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 457 | } else if (name.equals("Paired")) { |
| 458 | if (propValues[1].equals("true")) { |
Henrik Backlund | 4226415 | 2010-08-30 11:59:42 +0200 | [diff] [blame] | 459 | // If locally initiated pairing, we will |
| 460 | // not go to BOND_BONDED state until we have received a |
| 461 | // successful return value in onCreatePairedDeviceResult |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 462 | if (null == mBluetoothService.getPendingOutgoingBonding()) { |
| 463 | mBluetoothService.setBondState(address, BluetoothDevice.BOND_BONDED); |
Henrik Backlund | 4226415 | 2010-08-30 11:59:42 +0200 | [diff] [blame] | 464 | } |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 465 | } else { |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 466 | mBluetoothService.setBondState(address, BluetoothDevice.BOND_NONE); |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 467 | mBluetoothService.setRemoteDeviceProperty(address, "Trusted", "false"); |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 468 | } |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 469 | } else if (name.equals("Trusted")) { |
| 470 | if (DBG) |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 471 | log("set trust state succeeded, value is: " + propValues[1]); |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 472 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 473 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 476 | /** |
| 477 | * Called by native code on a PropertyChanged signal from |
| 478 | * org.bluez.Input. |
| 479 | * |
| 480 | * @param path the object path for the changed input device |
| 481 | * @param propValues a string array containing the key and one or more |
| 482 | * values. |
| 483 | */ |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 484 | private void onInputDevicePropertyChanged(String path, String[] propValues) { |
| 485 | String address = mBluetoothService.getAddressFromObjectPath(path); |
| 486 | if (address == null) { |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 487 | Log.e(TAG, "onInputDevicePropertyChanged: Address of the remote device is null"); |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 488 | return; |
| 489 | } |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 490 | log("Input Device : Name of Property is: " + propValues[0]); |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 491 | boolean state = false; |
| 492 | if (propValues[1].equals("true")) { |
| 493 | state = true; |
| 494 | } |
| 495 | mBluetoothService.handleInputDevicePropertyChange(address, state); |
| 496 | } |
| 497 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 498 | /** |
| 499 | * Called by native code on a PropertyChanged signal from |
| 500 | * org.bluez.Network. |
| 501 | * |
| 502 | * @param deviceObjectPath the object path for the changed PAN device |
| 503 | * @param propValues a string array containing the key and one or more |
| 504 | * values. |
| 505 | */ |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 506 | private void onPanDevicePropertyChanged(String deviceObjectPath, String[] propValues) { |
| 507 | String name = propValues[0]; |
| 508 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 509 | if (address == null) { |
| 510 | Log.e(TAG, "onPanDevicePropertyChanged: Address of the remote device in null"); |
| 511 | return; |
| 512 | } |
| 513 | if (DBG) { |
| 514 | log("Pan Device property changed: " + address + " property: " |
| 515 | + name + " value: "+ propValues[1]); |
| 516 | } |
| 517 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
| 518 | if (name.equals("Connected")) { |
Jaikumar Ganesh | 707952e | 2010-09-13 19:04:54 -0700 | [diff] [blame] | 519 | if (propValues[1].equals("false")) { |
| 520 | mBluetoothService.handlePanDeviceStateChange(device, |
Jaikumar Ganesh | 5200c8a | 2010-12-14 14:26:46 -0800 | [diff] [blame] | 521 | BluetoothPan.STATE_DISCONNECTED, |
| 522 | BluetoothPan.LOCAL_PANU_ROLE); |
Jaikumar Ganesh | 707952e | 2010-09-13 19:04:54 -0700 | [diff] [blame] | 523 | } |
| 524 | } else if (name.equals("Interface")) { |
| 525 | String iface = propValues[1]; |
Jaikumar Ganesh | 057898a | 2010-12-21 22:42:04 -0800 | [diff] [blame] | 526 | if (!iface.equals("")) { |
| 527 | mBluetoothService.handlePanDeviceStateChange(device, iface, |
| 528 | BluetoothPan.STATE_CONNECTED, |
| 529 | BluetoothPan.LOCAL_PANU_ROLE); |
| 530 | } |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 534 | private String checkPairingRequestAndGetAddress(String objectPath, int nativeData) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 535 | String address = mBluetoothService.getAddressFromObjectPath(objectPath); |
| 536 | if (address == null) { |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 537 | Log.e(TAG, "Unable to get device address in checkPairingRequestAndGetAddress, " + |
| 538 | "returning null"); |
| 539 | return null; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | address = address.toUpperCase(); |
| 542 | mPasskeyAgentRequestData.put(address, new Integer(nativeData)); |
| 543 | |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 544 | if (mBluetoothService.getBluetoothState() == BluetoothAdapter.STATE_TURNING_OFF) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 545 | // shutdown path |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 546 | mBluetoothService.cancelPairingUserInput(address); |
| 547 | return null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 548 | } |
Jaikumar Ganesh | 3768606 | 2009-09-30 13:57:37 -0700 | [diff] [blame] | 549 | // Set state to BONDING. For incoming connections it will be set here. |
| 550 | // For outgoing connections, it gets set when we call createBond. |
| 551 | // Also set it only when the state is not already Bonded, we can sometimes |
| 552 | // get an authorization request from the remote end if it doesn't have the link key |
| 553 | // while we still have it. |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 554 | if (mBluetoothService.getBondState(address) != BluetoothDevice.BOND_BONDED) |
| 555 | mBluetoothService.setBondState(address, BluetoothDevice.BOND_BONDING); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 556 | return address; |
| 557 | } |
| 558 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 559 | /** |
| 560 | * Called by native code on a RequestPairingConsent method call to |
| 561 | * org.bluez.Agent. |
| 562 | * |
| 563 | * @param objectPath the path of the device to request pairing consent for |
| 564 | * @param nativeData a native pointer to the original D-Bus message |
| 565 | */ |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 566 | private void onRequestPairingConsent(String objectPath, int nativeData) { |
| 567 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 568 | if (address == null) return; |
| 569 | |
| 570 | /* The link key will not be stored if the incoming request has MITM |
| 571 | * protection switched on. Unfortunately, some devices have MITM |
| 572 | * switched on even though their capabilities are NoInputNoOutput, |
| 573 | * so we may get this request many times. Also if we respond immediately, |
| 574 | * the other end is unable to handle it. Delay sending the message. |
| 575 | */ |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 576 | if (mBluetoothService.getBondState(address) == BluetoothDevice.BOND_BONDED) { |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 577 | Message message = mHandler.obtainMessage(EVENT_PAIRING_CONSENT_DELAYED_ACCEPT); |
| 578 | message.obj = address; |
| 579 | mHandler.sendMessageDelayed(message, 1500); |
| 580 | return; |
| 581 | } |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 582 | // Acquire wakelock during PIN code request to bring up LCD display |
| 583 | mWakeLock.acquire(); |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 584 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 585 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 586 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
| 587 | BluetoothDevice.PAIRING_VARIANT_CONSENT); |
| 588 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 589 | // Release wakelock to allow the LCD to go off after the PIN popup notification. |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 590 | mWakeLock.release(); |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 591 | return; |
| 592 | } |
| 593 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 594 | /** |
| 595 | * Called by native code on a RequestConfirmation method call to |
| 596 | * org.bluez.Agent. |
| 597 | * |
| 598 | * @param objectPath the path of the device to confirm the passkey for |
| 599 | * @param passkey an integer containing the 6-digit passkey to confirm |
| 600 | * @param nativeData a native pointer to the original D-Bus message |
| 601 | */ |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 602 | private void onRequestPasskeyConfirmation(String objectPath, int passkey, int nativeData) { |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 603 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 604 | if (address == null) return; |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 605 | // Acquire wakelock during PIN code request to bring up LCD display |
| 606 | mWakeLock.acquire(); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 607 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 608 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 609 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, passkey); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 610 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 611 | BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 612 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 613 | // Release wakelock to allow the LCD to go off after the PIN popup notification. |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 614 | mWakeLock.release(); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 615 | return; |
| 616 | } |
| 617 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 618 | /** |
| 619 | * Called by native code on a RequestPasskey method call to |
| 620 | * org.bluez.Agent. |
| 621 | * |
| 622 | * @param objectPath the path of the device requesting a passkey |
| 623 | * @param nativeData a native pointer to the original D-Bus message |
| 624 | */ |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 625 | private void onRequestPasskey(String objectPath, int nativeData) { |
| 626 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 627 | if (address == null) return; |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 628 | // Acquire wakelock during PIN code request to bring up LCD display |
| 629 | mWakeLock.acquire(); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 630 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 631 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 632 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
| 633 | BluetoothDevice.PAIRING_VARIANT_PASSKEY); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 634 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 635 | // Release wakelock to allow the LCD to go off after the PIN popup notification. |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 636 | mWakeLock.release(); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 637 | return; |
| 638 | } |
| 639 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 640 | /** |
| 641 | * Called by native code on a RequestPinCode method call to |
| 642 | * org.bluez.Agent. |
| 643 | * |
| 644 | * @param objectPath the path of the device requesting a PIN code |
| 645 | * @param nativeData a native pointer to the original D-Bus message |
| 646 | */ |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 647 | private void onRequestPinCode(String objectPath, int nativeData) { |
| 648 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 649 | if (address == null) return; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 650 | |
Jaikumar Ganesh | 2092361 | 2009-09-20 12:56:21 -0700 | [diff] [blame] | 651 | String pendingOutgoingAddress = |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 652 | mBluetoothService.getPendingOutgoingBonding(); |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 653 | BluetoothClass btClass = new BluetoothClass(mBluetoothService.getRemoteClass(address)); |
| 654 | int btDeviceClass = btClass.getDeviceClass(); |
| 655 | |
Jaikumar Ganesh | 2092361 | 2009-09-20 12:56:21 -0700 | [diff] [blame] | 656 | if (address.equals(pendingOutgoingAddress)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | // we initiated the bonding |
Jaikumar Ganesh | 3fbf7b6 | 2009-12-02 17:28:38 -0800 | [diff] [blame] | 658 | |
| 659 | // Check if its a dock |
| 660 | if (mBluetoothService.isBluetoothDock(address)) { |
| 661 | String pin = mBluetoothService.getDockPin(); |
| 662 | mBluetoothService.setPin(address, BluetoothDevice.convertPinToBytes(pin)); |
| 663 | return; |
| 664 | } |
| 665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | // try 0000 once if the device looks dumb |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 667 | switch (btDeviceClass) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET: |
| 669 | case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE: |
| 670 | case BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES: |
| 671 | case BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | case BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO: |
Jaikumar Ganesh | a224f70 | 2010-09-10 15:09:54 -0700 | [diff] [blame] | 673 | if (mBluetoothService.attemptAutoPair(address)) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | } |
| 675 | } |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 676 | |
Jaikumar Ganesh | ac6f13d | 2011-01-12 10:08:57 -0800 | [diff] [blame] | 677 | if (btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD || |
| 678 | btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD_POINTING) { |
| 679 | // Its a keyboard. Follow the HID spec recommendation of creating the |
Jaikumar Ganesh | f487d72 | 2011-01-12 10:12:01 -0800 | [diff] [blame] | 680 | // passkey and displaying it to the user. If the keyboard doesn't follow |
| 681 | // the spec recommendation, check if the keyboard has a fixed PIN zero |
| 682 | // and pair. |
| 683 | if (mBluetoothService.isFixedPinZerosAutoPairKeyboard(address)) { |
| 684 | mBluetoothService.setPin(address, BluetoothDevice.convertPinToBytes("0000")); |
| 685 | return; |
| 686 | } |
| 687 | |
Jaikumar Ganesh | ac6f13d | 2011-01-12 10:08:57 -0800 | [diff] [blame] | 688 | // Generate a variable PIN. This is not truly random but good enough. |
| 689 | int pin = (int) Math.floor(Math.random() * 10000); |
| 690 | sendDisplayPinIntent(address, pin); |
| 691 | return; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 692 | } |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 693 | // Acquire wakelock during PIN code request to bring up LCD display |
| 694 | mWakeLock.acquire(); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 695 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 696 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 697 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PIN); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 699 | // Release wakelock to allow the LCD to go off after the PIN popup notification. |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 700 | mWakeLock.release(); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 701 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | } |
| 703 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 704 | /** |
| 705 | * Called by native code on a DisplayPasskey method call to |
| 706 | * org.bluez.Agent. |
| 707 | * |
| 708 | * @param objectPath the path of the device to display the passkey for |
| 709 | * @param passkey an integer containing the 6-digit passkey |
| 710 | * @param nativeData a native pointer to the original D-Bus message |
| 711 | */ |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 712 | private void onDisplayPasskey(String objectPath, int passkey, int nativeData) { |
| 713 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 714 | if (address == null) return; |
| 715 | |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 716 | // Acquire wakelock during PIN code request to bring up LCD display |
| 717 | mWakeLock.acquire(); |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 718 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 719 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 720 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, passkey); |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 721 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
| 722 | BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY); |
| 723 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 724 | //Release wakelock to allow the LCD to go off after the PIN popup notification. |
Bheemsen Kulkarni | abf9943 | 2010-03-17 14:56:00 +0530 | [diff] [blame] | 725 | mWakeLock.release(); |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 728 | private void sendDisplayPinIntent(String address, int pin) { |
| 729 | // Acquire wakelock during PIN code request to bring up LCD display |
| 730 | mWakeLock.acquire(); |
| 731 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 732 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 733 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pin); |
| 734 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
| 735 | BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN); |
| 736 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
| 737 | //Release wakelock to allow the LCD to go off after the PIN popup notifcation. |
| 738 | mWakeLock.release(); |
| 739 | } |
| 740 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 741 | /** |
| 742 | * Called by native code on a RequestOobData method call to |
| 743 | * org.bluez.Agent. |
| 744 | * |
| 745 | * @param objectPath the path of the device requesting OOB data |
| 746 | * @param nativeData a native pointer to the original D-Bus message |
| 747 | */ |
| 748 | private void onRequestOobData(String objectPath, int nativeData) { |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 749 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 750 | if (address == null) return; |
| 751 | |
| 752 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 753 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 754 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
| 755 | BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT); |
| 756 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
| 757 | } |
| 758 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 759 | /** |
| 760 | * Called by native code on an Authorize method call to org.bluez.Agent. |
| 761 | * |
| 762 | * @param objectPath the path of the device requesting to be authorized |
| 763 | * @param deviceUuid the UUID of the requesting device |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 764 | * @param nativeData reference for native data |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 765 | */ |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 766 | private void onAgentAuthorize(String objectPath, String deviceUuid, int nativeData) { |
| 767 | if (!mBluetoothService.isEnabled()) return; |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 768 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 769 | String address = mBluetoothService.getAddressFromObjectPath(objectPath); |
| 770 | if (address == null) { |
| 771 | Log.e(TAG, "Unable to get device address in onAuthAgentAuthorize"); |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 772 | return; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 773 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | boolean authorized = false; |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 776 | ParcelUuid uuid = ParcelUuid.fromString(deviceUuid); |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 777 | |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 778 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 779 | mAuthorizationAgentRequestData.put(address, new Integer(nativeData)); |
Jaikumar Ganesh | b16c4f7 | 2009-12-04 15:10:54 -0800 | [diff] [blame] | 780 | |
Nick Pelly | b23d445 | 2009-08-26 09:33:40 -0700 | [diff] [blame] | 781 | // Bluez sends the UUID of the local service being accessed, _not_ the |
| 782 | // remote service |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 783 | if (mA2dp != null && |
| 784 | (BluetoothUuid.isAudioSource(uuid) || BluetoothUuid.isAvrcpTarget(uuid) |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 785 | || BluetoothUuid.isAdvAudioDist(uuid)) && |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 786 | !isOtherSinkInNonDisconnectedState(address)) { |
| 787 | authorized = mA2dp.getPriority(device) > BluetoothProfile.PRIORITY_OFF; |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 788 | if (authorized && !BluetoothUuid.isAvrcpTarget(uuid)) { |
| 789 | Log.i(TAG, "First check pass for incoming A2DP / AVRCP connection from " + address); |
Jaikumar Ganesh | 70a053b | 2010-10-13 15:54:30 -0700 | [diff] [blame] | 790 | // Some headsets try to connect AVCTP before AVDTP - against the recommendation |
| 791 | // If AVCTP connection fails, we get stuck in IncomingA2DP state in the state |
| 792 | // machine. We don't handle AVCTP signals currently. We only send |
| 793 | // intents for AVDTP state changes. We need to handle both of them in |
| 794 | // some cases. For now, just don't move to incoming state in this case. |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 795 | mBluetoothService.notifyIncomingA2dpConnection(address); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | } else { |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 797 | Log.i(TAG, "" + authorized + |
| 798 | "Incoming A2DP / AVRCP connection from " + address); |
| 799 | mA2dp.allowIncomingConnect(device, authorized); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | } |
Jaikumar Ganesh | bbd8675 | 2011-08-01 19:11:18 -0700 | [diff] [blame^] | 801 | } else if (BluetoothUuid.isInputDevice(uuid)) { |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 802 | // We can have more than 1 input device connected. |
Jaikumar Ganesh | bbd8675 | 2011-08-01 19:11:18 -0700 | [diff] [blame^] | 803 | authorized = mBluetoothService.getInputDevicePriority(device) > |
| 804 | BluetoothInputDevice.PRIORITY_OFF; |
| 805 | if (authorized) { |
| 806 | Log.i(TAG, "First check pass for incoming HID connection from " + address); |
| 807 | // notify profile state change |
| 808 | mBluetoothService.notifyIncomingHidConnection(address); |
| 809 | } else { |
| 810 | Log.i(TAG, "Rejecting incoming HID connection from " + address); |
| 811 | mBluetoothService.allowIncomingProfileConnect(device, authorized); |
| 812 | } |
| 813 | } else if (BluetoothUuid.isBnep(uuid)) { |
| 814 | // PAN doesn't go to the state machine, accept or reject from here |
| 815 | authorized = mBluetoothService.allowIncomingTethering(); |
| 816 | mBluetoothService.allowIncomingProfileConnect(device, authorized); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | } else { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 818 | Log.i(TAG, "Rejecting incoming " + deviceUuid + " connection from " + address); |
Jaikumar Ganesh | bbd8675 | 2011-08-01 19:11:18 -0700 | [diff] [blame^] | 819 | mBluetoothService.allowIncomingProfileConnect(device, authorized); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | } |
Nick Pelly | b23d445 | 2009-08-26 09:33:40 -0700 | [diff] [blame] | 821 | log("onAgentAuthorize(" + objectPath + ", " + deviceUuid + ") = " + authorized); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | } |
| 823 | |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 824 | private boolean onAgentOutOfBandDataAvailable(String objectPath) { |
| 825 | if (!mBluetoothService.isEnabled()) return false; |
| 826 | |
| 827 | String address = mBluetoothService.getAddressFromObjectPath(objectPath); |
| 828 | if (address == null) return false; |
| 829 | |
| 830 | if (mBluetoothService.getDeviceOutOfBandData( |
| 831 | mAdapter.getRemoteDevice(address)) != null) { |
| 832 | return true; |
| 833 | } |
Jaikumar Ganesh | 1510770 | 2010-09-13 15:24:01 -0700 | [diff] [blame] | 834 | return false; |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 837 | private boolean isOtherSinkInNonDisconnectedState(String address) { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 838 | List<BluetoothDevice> devices = |
Jaikumar Ganesh | 96a7983 | 2010-09-27 17:02:01 -0700 | [diff] [blame] | 839 | mA2dp.getDevicesMatchingConnectionStates(new int[] {BluetoothA2dp.STATE_CONNECTED, |
| 840 | BluetoothA2dp.STATE_CONNECTING, |
| 841 | BluetoothA2dp.STATE_DISCONNECTING}); |
| 842 | |
Jaikumar Ganesh | 577dd1f | 2009-12-17 14:59:10 -0800 | [diff] [blame] | 843 | if (devices.size() == 0) return false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 844 | for (BluetoothDevice dev: devices) { |
Jaikumar Ganesh | 577dd1f | 2009-12-17 14:59:10 -0800 | [diff] [blame] | 845 | if (!dev.getAddress().equals(address)) return true; |
| 846 | } |
| 847 | return false; |
| 848 | } |
| 849 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 850 | /** |
| 851 | * Called by native code on a Cancel method call to org.bluez.Agent. |
| 852 | */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 853 | private void onAgentCancel() { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 854 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_CANCEL); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 855 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
Jaikumar Ganesh | e5d93b7 | 2009-10-08 02:27:52 -0700 | [diff] [blame] | 856 | |
| 857 | mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_AGENT_CANCEL), |
| 858 | 1500); |
| 859 | |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 860 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | } |
| 862 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 863 | /** |
| 864 | * Called by native code for the async response to a DiscoverServices |
| 865 | * method call to org.bluez.Adapter. |
| 866 | * |
| 867 | * @param deviceObjectPath the path for the specified device |
| 868 | * @param result true for success; false on error |
| 869 | */ |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 870 | private void onDiscoverServicesResult(String deviceObjectPath, boolean result) { |
| 871 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
Staffan Lindvall | 81f8e3c | 2010-10-27 10:34:53 +0200 | [diff] [blame] | 872 | if (address == null) return; |
| 873 | |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 874 | // We don't parse the xml here, instead just query Bluez for the properties. |
| 875 | if (result) { |
Jaikumar Ganesh | 10eac97 | 2009-09-21 12:48:51 -0700 | [diff] [blame] | 876 | mBluetoothService.updateRemoteDevicePropertiesCache(address); |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 877 | } |
| 878 | mBluetoothService.sendUuidIntent(address); |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 879 | mBluetoothService.makeServiceChannelCallbacks(address); |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 882 | /** |
| 883 | * Called by native code for the async response to a CreateDevice |
| 884 | * method call to org.bluez.Adapter. |
| 885 | * |
| 886 | * @param address the MAC address of the device to create |
| 887 | * @param result {@link #CREATE_DEVICE_SUCCESS}, |
| 888 | * {@link #CREATE_DEVICE_ALREADY_EXISTS} or {@link #CREATE_DEVICE_FAILED}} |
| 889 | */ |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 890 | private void onCreateDeviceResult(String address, int result) { |
| 891 | if (DBG) log("Result of onCreateDeviceResult:" + result); |
| 892 | |
| 893 | switch (result) { |
| 894 | case CREATE_DEVICE_ALREADY_EXISTS: |
| 895 | String path = mBluetoothService.getObjectPathFromAddress(address); |
| 896 | if (path != null) { |
| 897 | mBluetoothService.discoverServicesNative(path, ""); |
| 898 | break; |
| 899 | } |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 900 | Log.w(TAG, "Device exists, but we don't have the bluez path, failing"); |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 901 | // fall-through |
| 902 | case CREATE_DEVICE_FAILED: |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 903 | mBluetoothService.sendUuidIntent(address); |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 904 | mBluetoothService.makeServiceChannelCallbacks(address); |
| 905 | break; |
| 906 | case CREATE_DEVICE_SUCCESS: |
| 907 | // nothing to do, UUID intent's will be sent via property changed |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 911 | /** |
| 912 | * Called by native code for the async response to a Connect |
| 913 | * method call to org.bluez.Input. |
| 914 | * |
| 915 | * @param path the path of the specified input device |
| 916 | * @param result Result code of the operation. |
| 917 | */ |
Jaikumar Ganesh | fbe807d | 2011-01-19 13:59:32 -0800 | [diff] [blame] | 918 | private void onInputDeviceConnectionResult(String path, int result) { |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 919 | // Success case gets handled by Property Change signal |
Jaikumar Ganesh | fbe807d | 2011-01-19 13:59:32 -0800 | [diff] [blame] | 920 | if (result != BluetoothInputDevice.INPUT_OPERATION_SUCCESS) { |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 921 | String address = mBluetoothService.getAddressFromObjectPath(path); |
| 922 | if (address == null) return; |
| 923 | |
| 924 | boolean connected = false; |
| 925 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 926 | int state = mBluetoothService.getInputDeviceConnectionState(device); |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 927 | if (state == BluetoothInputDevice.STATE_CONNECTING) { |
Jaikumar Ganesh | fbe807d | 2011-01-19 13:59:32 -0800 | [diff] [blame] | 928 | if (result == BluetoothInputDevice.INPUT_CONNECT_FAILED_ALREADY_CONNECTED) { |
| 929 | connected = true; |
| 930 | } else { |
| 931 | connected = false; |
| 932 | } |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 933 | } else if (state == BluetoothInputDevice.STATE_DISCONNECTING) { |
Jaikumar Ganesh | fbe807d | 2011-01-19 13:59:32 -0800 | [diff] [blame] | 934 | if (result == BluetoothInputDevice.INPUT_DISCONNECT_FAILED_NOT_CONNECTED) { |
| 935 | connected = false; |
| 936 | } else { |
| 937 | // There is no better way to handle this, this shouldn't happen |
| 938 | connected = true; |
| 939 | } |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 940 | } else { |
| 941 | Log.e(TAG, "Error onInputDeviceConnectionResult. State is:" + state); |
| 942 | } |
| 943 | mBluetoothService.handleInputDevicePropertyChange(address, connected); |
| 944 | } |
| 945 | } |
| 946 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 947 | /** |
| 948 | * Called by native code for the async response to a Connect |
| 949 | * method call to org.bluez.Network. |
| 950 | * |
| 951 | * @param path the path of the specified PAN device |
| 952 | * @param result Result code of the operation. |
| 953 | */ |
Jaikumar Ganesh | fbe807d | 2011-01-19 13:59:32 -0800 | [diff] [blame] | 954 | private void onPanDeviceConnectionResult(String path, int result) { |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 955 | log ("onPanDeviceConnectionResult " + path + " " + result); |
| 956 | // Success case gets handled by Property Change signal |
Jaikumar Ganesh | fbe807d | 2011-01-19 13:59:32 -0800 | [diff] [blame] | 957 | if (result != BluetoothPan.PAN_OPERATION_SUCCESS) { |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 958 | String address = mBluetoothService.getAddressFromObjectPath(path); |
| 959 | if (address == null) return; |
| 960 | |
| 961 | boolean connected = false; |
| 962 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
Jaikumar Ganesh | 74ef119 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 963 | int state = mBluetoothService.getPanDeviceConnectionState(device); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 964 | if (state == BluetoothPan.STATE_CONNECTING) { |
Jaikumar Ganesh | fbe807d | 2011-01-19 13:59:32 -0800 | [diff] [blame] | 965 | if (result == BluetoothPan.PAN_CONNECT_FAILED_ALREADY_CONNECTED) { |
| 966 | connected = true; |
| 967 | } else { |
| 968 | connected = false; |
| 969 | } |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 970 | } else if (state == BluetoothPan.STATE_DISCONNECTING) { |
Jaikumar Ganesh | fbe807d | 2011-01-19 13:59:32 -0800 | [diff] [blame] | 971 | if (result == BluetoothPan.PAN_DISCONNECT_FAILED_NOT_CONNECTED) { |
| 972 | connected = false; |
| 973 | } else { |
| 974 | // There is no better way to handle this, this shouldn't happen |
| 975 | connected = true; |
| 976 | } |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 977 | } else { |
| 978 | Log.e(TAG, "Error onPanDeviceConnectionResult. State is: " |
| 979 | + state + " result: "+ result); |
| 980 | } |
| 981 | int newState = connected? BluetoothPan.STATE_CONNECTED : |
| 982 | BluetoothPan.STATE_DISCONNECTED; |
Jaikumar Ganesh | 5200c8a | 2010-12-14 14:26:46 -0800 | [diff] [blame] | 983 | mBluetoothService.handlePanDeviceStateChange(device, newState, |
| 984 | BluetoothPan.LOCAL_PANU_ROLE); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 988 | /** |
| 989 | * Called by native code on a DeviceDisconnected signal from |
| 990 | * org.bluez.NetworkServer. |
| 991 | * |
| 992 | * @param address the MAC address of the disconnected device |
| 993 | */ |
Jaikumar Ganesh | c1520ec | 2010-08-31 19:55:10 -0700 | [diff] [blame] | 994 | private void onNetworkDeviceDisconnected(String address) { |
| 995 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
Jaikumar Ganesh | 5200c8a | 2010-12-14 14:26:46 -0800 | [diff] [blame] | 996 | mBluetoothService.handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED, |
| 997 | BluetoothPan.LOCAL_NAP_ROLE); |
Jaikumar Ganesh | c1520ec | 2010-08-31 19:55:10 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Jake Hamby | 9a62c9c | 2010-12-09 14:47:57 -0800 | [diff] [blame] | 1000 | /** |
| 1001 | * Called by native code on a DeviceConnected signal from |
| 1002 | * org.bluez.NetworkServer. |
| 1003 | * |
| 1004 | * @param address the MAC address of the connected device |
| 1005 | * @param iface interface of remote network |
| 1006 | * @param destUuid unused UUID parameter |
| 1007 | */ |
Jaikumar Ganesh | 707952e | 2010-09-13 19:04:54 -0700 | [diff] [blame] | 1008 | private void onNetworkDeviceConnected(String address, String iface, int destUuid) { |
Jaikumar Ganesh | c1520ec | 2010-08-31 19:55:10 -0700 | [diff] [blame] | 1009 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
Jaikumar Ganesh | 5200c8a | 2010-12-14 14:26:46 -0800 | [diff] [blame] | 1010 | mBluetoothService.handlePanDeviceStateChange(device, iface, BluetoothPan.STATE_CONNECTED, |
| 1011 | BluetoothPan.LOCAL_NAP_ROLE); |
Jaikumar Ganesh | c1520ec | 2010-08-31 19:55:10 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 1014 | /** |
| 1015 | * Called by native code on a PropertyChanged signal from |
| 1016 | * org.bluez.HealthDevice. |
| 1017 | * |
| 1018 | * @param devicePath the object path of the remote device |
| 1019 | * @param propValues Properties (Name-Value) of the Health Device. |
| 1020 | */ |
| 1021 | private void onHealthDevicePropertyChanged(String devicePath, String[] propValues) { |
| 1022 | log("Health Device : Name of Property is: " + propValues[0] + " Value:" + propValues[1]); |
| 1023 | mBluetoothService.onHealthDevicePropertyChanged(devicePath, propValues[1]); |
| 1024 | } |
| 1025 | |
| 1026 | /** |
| 1027 | * Called by native code on a ChannelCreated/Deleted signal from |
| 1028 | * org.bluez.HealthDevice. |
| 1029 | * |
| 1030 | * @param devicePath the object path of the remote device |
| 1031 | * @param channelPath the path of the health channel. |
| 1032 | * @param exists Boolean to indicate if the channel was created or deleted. |
| 1033 | */ |
| 1034 | private void onHealthDeviceChannelChanged(String devicePath, String channelPath, |
| 1035 | boolean exists) { |
| 1036 | log("Health Device : devicePath: " + devicePath + ":channelPath:" + channelPath + |
| 1037 | ":exists" + exists); |
| 1038 | mBluetoothService.onHealthDeviceChannelChanged(devicePath, channelPath, exists); |
| 1039 | } |
| 1040 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1041 | private void onRestartRequired() { |
| 1042 | if (mBluetoothService.isEnabled()) { |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 1043 | Log.e(TAG, "*** A serious error occurred (did bluetoothd crash?) - " + |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1044 | "restarting Bluetooth ***"); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1045 | mHandler.sendEmptyMessage(EVENT_RESTART_BLUETOOTH); |
| 1046 | } |
| 1047 | } |
| 1048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | private static void log(String msg) { |
| 1050 | Log.d(TAG, msg); |
| 1051 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1052 | |
| 1053 | private native void initializeNativeDataNative(); |
| 1054 | private native void startEventLoopNative(); |
| 1055 | private native void stopEventLoopNative(); |
| 1056 | private native boolean isEventLoopRunningNative(); |
| 1057 | private native void cleanupNativeDataNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | } |