diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2011-07-21 11:53:44 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-21 11:53:44 -0700 |
commit | ac4159549c10dbe428d42980278c0e43ecc8d93f (patch) | |
tree | 9bb9052b3ae9f5f7e2f576fc41c85f9f49e09fbd /core/java | |
parent | d578be2784ba452e7f4e3ef9723509ed115bcc5c (diff) | |
parent | d3728cb32fbd0a85bc77f4bcbdfea386ede2c75f (diff) | |
download | frameworks_base-ac4159549c10dbe428d42980278c0e43ecc8d93f.zip frameworks_base-ac4159549c10dbe428d42980278c0e43ecc8d93f.tar.gz frameworks_base-ac4159549c10dbe428d42980278c0e43ecc8d93f.tar.bz2 |
Merge "Incoming connection dialog tweaks."
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/bluetooth/BluetoothDeviceProfileState.java | 46 | ||||
-rw-r--r-- | core/java/android/server/BluetoothBondState.java | 33 | ||||
-rwxr-xr-x | core/java/android/server/BluetoothService.java | 6 |
3 files changed, 67 insertions, 18 deletions
diff --git a/core/java/android/bluetooth/BluetoothDeviceProfileState.java b/core/java/android/bluetooth/BluetoothDeviceProfileState.java index ab3a426..095cd11 100644 --- a/core/java/android/bluetooth/BluetoothDeviceProfileState.java +++ b/core/java/android/bluetooth/BluetoothDeviceProfileState.java @@ -120,6 +120,7 @@ public final class BluetoothDeviceProfileState extends StateMachine { private Pair<Integer, String> mIncomingConnections; private PowerManager.WakeLock mWakeLock; private PowerManager mPowerManager; + private boolean mPairingRequestRcvd = false; private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override @@ -187,27 +188,38 @@ public final class BluetoothDeviceProfileState extends StateMachine { Message msg = obtainMessage(CONNECTION_ACCESS_REQUEST_REPLY); msg.arg1 = val; sendMessage(msg); + } else if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) { + mPairingRequestRcvd = true; + } else if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) { + int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, + BluetoothDevice.ERROR); + if (state == BluetoothDevice.BOND_BONDED && mPairingRequestRcvd) { + setTrust(BluetoothDevice.CONNECTION_ACCESS_YES); + mPairingRequestRcvd = false; + } else if (state == BluetoothDevice.BOND_NONE) { + mPairingRequestRcvd = false; + } } } }; private boolean isPhoneDocked(BluetoothDevice autoConnectDevice) { - // This works only because these broadcast intents are "sticky" - Intent i = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT)); - if (i != null) { - int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED); - if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) { - BluetoothDevice device = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - if (device != null && autoConnectDevice.equals(device)) { - return true; - } - } - } - return false; - } + // This works only because these broadcast intents are "sticky" + Intent i = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT)); + if (i != null) { + int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED); + if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) { + BluetoothDevice device = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + if (device != null && autoConnectDevice.equals(device)) { + return true; + } + } + } + return false; + } public BluetoothDeviceProfileState(Context context, String address, - BluetoothService service, BluetoothA2dpService a2dpService) { + BluetoothService service, BluetoothA2dpService a2dpService, boolean setTrust) { super(address); mContext = context; mDevice = new BluetoothDevice(address); @@ -231,6 +243,8 @@ public final class BluetoothDeviceProfileState extends StateMachine { filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); + filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST); + filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mContext.registerReceiver(mBroadcastReceiver, filter); @@ -247,6 +261,10 @@ public final class BluetoothDeviceProfileState extends StateMachine { PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG); mWakeLock.setReferenceCounted(false); + + if (setTrust) { + setTrust(BluetoothDevice.CONNECTION_ACCESS_YES); + } } private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener = diff --git a/core/java/android/server/BluetoothBondState.java b/core/java/android/server/BluetoothBondState.java index 75f38f9..30a8b2a 100644 --- a/core/java/android/server/BluetoothBondState.java +++ b/core/java/android/server/BluetoothBondState.java @@ -21,8 +21,13 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothHeadset; +import android.content.BroadcastReceiver; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.provider.Settings; import android.util.Log; import java.io.BufferedReader; @@ -74,11 +79,17 @@ class BluetoothBondState { private BluetoothA2dp mA2dpProxy; private BluetoothHeadset mHeadsetProxy; + private ArrayList<String> mPairingRequestRcvd = new ArrayList<String>(); + BluetoothBondState(Context context, BluetoothService service) { mContext = context; mService = service; mBluetoothInputProfileHandler = BluetoothInputProfileHandler.getInstance(mContext, mService); + + IntentFilter filter = new IntentFilter(); + filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST); + mContext.registerReceiver(mReceiver, filter); } synchronized void setPendingOutgoingBonding(String address) { @@ -137,11 +148,18 @@ class BluetoothBondState { } if (state == BluetoothDevice.BOND_BONDED) { - mService.addProfileState(address); + boolean setTrust = false; + if (mPairingRequestRcvd.contains(address)) setTrust = true; + + mService.addProfileState(address, setTrust); + mPairingRequestRcvd.remove(address); + } else if (state == BluetoothDevice.BOND_BONDING) { if (mA2dpProxy == null || mHeadsetProxy == null) { getProfileProxy(); } + } else if (state == BluetoothDevice.BOND_NONE) { + mPairingRequestRcvd.remove(address); } setProfilePriorities(address, state); @@ -452,4 +470,17 @@ class BluetoothBondState { } } + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent == null) return; + + String action = intent.getAction(); + if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) { + BluetoothDevice dev = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + String address = dev.getAddress(); + mPairingRequestRcvd.add(address); + } + } + }; } diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index ff16c18..ab569a1 100755 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -2277,11 +2277,11 @@ public class BluetoothService extends IBluetooth.Stub { return false; } - BluetoothDeviceProfileState addProfileState(String address) { + BluetoothDeviceProfileState addProfileState(String address, boolean setTrust) { BluetoothDeviceProfileState state = mDeviceProfileState.get(address); if (state != null) return state; - state = new BluetoothDeviceProfileState(mContext, address, this, mA2dpService); + state = new BluetoothDeviceProfileState(mContext, address, this, mA2dpService, setTrust); mDeviceProfileState.put(address, state); state.start(); return state; @@ -2311,7 +2311,7 @@ public class BluetoothService extends IBluetooth.Stub { } for (String path : bonds) { String address = getAddressFromObjectPath(path); - BluetoothDeviceProfileState state = addProfileState(address); + BluetoothDeviceProfileState state = addProfileState(address, false); } } |