From 8adcacbf83697d1299812f5365380b097898567a Mon Sep 17 00:00:00 2001 From: Jaikumar Ganesh Date: Thu, 21 Jul 2011 13:49:54 -0700 Subject: [PATCH] Auto Pairing tweaks. When the stack returns an incorrect error code, we were going on in a loop trying auto pairing. Ideally, the stack shouldn't be returning this incorrect code, but add a fail safe in the userspace code. Also cap attempts at 2. There is no point trying more than that. Change-Id: I5bf3ea871b9c2241ae5ac88e9818c9eb847fac92 --- core/java/android/server/BluetoothService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index ff16c18839843..45ee014fa954a 100755 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -527,10 +527,19 @@ public class BluetoothService extends IBluetooth.Stub { break; case MESSAGE_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY: address = (String)msg.obj; - if (address != null) { + if (address == null) return; + int attempt = mBondState.getAttempt(address); + + // Try only if attemps are in progress and cap it 2 attempts + // The 2 attempts cap is a fail safe if the stack returns + // an incorrect error code for bonding failures and if the pin + // is entered wrongly twice we should abort. + if (attempt > 0 && attempt <= 2) { + mBondState.attempt(address); createBond(address); return; } + if (attempt > 0) mBondState.clearPinAttempts(address); break; } } @@ -741,7 +750,6 @@ public class BluetoothService extends IBluetooth.Stub { BluetoothDevice.BOND_NONE, result); return; } - mBondState.attempt(address); } /*package*/ BluetoothDevice getRemoteDevice(String address) {