summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2012-05-09 10:48:40 -0700
committerMartijn Coenen <maco@google.com>2012-05-10 15:35:33 -0700
commit78705adb33530d58f6b25bd3976ef36df196af55 (patch)
treed76f02ef122b888269a951b4110eaf9b9c85ed81 /src/com
parentd82d9db81f30ccecd29a0531e6db9b49c9c2cd95 (diff)
downloadpackages_apps_nfc-78705adb33530d58f6b25bd3976ef36df196af55.zip
packages_apps_nfc-78705adb33530d58f6b25bd3976ef36df196af55.tar.gz
packages_apps_nfc-78705adb33530d58f6b25bd3976ef36df196af55.tar.bz2
UI confirmation for pairing a BT device through NFC.
If we find a BT device to pair through NFC and we haven't seen it device before, request confirmation before pairing it. Bug: 6092058 Change-Id: I34fc638fbdb152a48e90644f9a34cc1a0b942de2
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/nfc/handover/BluetoothHeadsetHandover.java37
-rw-r--r--src/com/android/nfc/handover/ConfirmConnectActivity.java48
2 files changed, 80 insertions, 5 deletions
diff --git a/src/com/android/nfc/handover/BluetoothHeadsetHandover.java b/src/com/android/nfc/handover/BluetoothHeadsetHandover.java
index 7cb0424..7974dfa 100644
--- a/src/com/android/nfc/handover/BluetoothHeadsetHandover.java
+++ b/src/com/android/nfc/handover/BluetoothHeadsetHandover.java
@@ -50,14 +50,18 @@ public class BluetoothHeadsetHandover {
static final String TAG = HandoverManager.TAG;
static final boolean DBG = HandoverManager.DBG;
+ static final String ACTION_ALLOW_CONNECT = "com.android.nfc.handover.action.ALLOW_CONNECT";
+ static final String ACTION_DENY_CONNECT = "com.android.nfc.handover.action.DENY_CONNECT";
+
static final int TIMEOUT_MS = 20000;
static final int STATE_INIT = 0;
static final int STATE_TURNING_ON = 1;
- static final int STATE_BONDING = 2;
- static final int STATE_CONNECTING = 3;
- static final int STATE_DISCONNECTING = 4;
- static final int STATE_COMPLETE = 5;
+ static final int STATE_WAITING_FOR_BOND_CONFIRMATION = 2;
+ static final int STATE_BONDING = 3;
+ static final int STATE_CONNECTING = 4;
+ static final int STATE_DISCONNECTING = 5;
+ static final int STATE_COMPLETE = 6;
static final int RESULT_PENDING = 0;
static final int RESULT_CONNECTED = 1;
@@ -113,6 +117,9 @@ public class BluetoothHeadsetHandover {
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
+ filter.addAction(ACTION_ALLOW_CONNECT);
+ filter.addAction(ACTION_DENY_CONNECT);
+
mContext.registerReceiver(mReceiver, filter);
if (mA2dp.getConnectedDevices().contains(mDevice) ||
@@ -189,6 +196,13 @@ public class BluetoothHeadsetHandover {
// fall-through
case STATE_TURNING_ON:
if (mDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
+ requestPairConfirmation();
+ mState = STATE_WAITING_FOR_BOND_CONFIRMATION;
+ break;
+ }
+ // fall-through
+ case STATE_WAITING_FOR_BOND_CONFIRMATION:
+ if (mDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
startBonding();
break;
}
@@ -258,7 +272,11 @@ public class BluetoothHeadsetHandover {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (!mDevice.equals(device)) return;
- if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action) && mState == STATE_BONDING) {
+ if (ACTION_ALLOW_CONNECT.equals(action)) {
+ nextStepConnect();
+ } else if (ACTION_DENY_CONNECT.equals(action)) {
+ complete(false);
+ } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action) && mState == STATE_BONDING) {
int bond = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
BluetoothAdapter.ERROR);
if (bond == BluetoothDevice.BOND_BONDED) {
@@ -312,6 +330,15 @@ public class BluetoothHeadsetHandover {
mContext.sendOrderedBroadcast(intent, null);
}
+ void requestPairConfirmation() {
+ Intent dialogIntent = new Intent(mContext, ConfirmConnectActivity.class);
+ dialogIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ dialogIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
+
+ mContext.startActivity(dialogIntent);
+ }
+
final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
diff --git a/src/com/android/nfc/handover/ConfirmConnectActivity.java b/src/com/android/nfc/handover/ConfirmConnectActivity.java
new file mode 100644
index 0000000..22d518f
--- /dev/null
+++ b/src/com/android/nfc/handover/ConfirmConnectActivity.java
@@ -0,0 +1,48 @@
+package com.android.nfc.handover;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.bluetooth.BluetoothDevice;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.os.Bundle;
+
+import com.android.nfc.R;
+
+public class ConfirmConnectActivity extends Activity {
+ BluetoothDevice mDevice;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_DARK);
+ Intent launchIntent = getIntent();
+ mDevice = launchIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ if (mDevice == null) finish();
+ Resources res = getResources();
+ String deviceName = mDevice.getName() != null ? mDevice.getName() : "";
+ String confirmString = String.format(res.getString(R.string.confirm_pairing), deviceName);
+ builder.setMessage(confirmString)
+ .setCancelable(false)
+ .setPositiveButton(res.getString(R.string.pair_yes),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ Intent allowIntent = new Intent(BluetoothHeadsetHandover.ACTION_ALLOW_CONNECT);
+ allowIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
+ sendBroadcast(allowIntent);
+ ConfirmConnectActivity.this.finish();
+ }
+ })
+ .setNegativeButton(res.getString(R.string.pair_no),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ Intent denyIntent = new Intent(BluetoothHeadsetHandover.ACTION_DENY_CONNECT);
+ denyIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
+ sendBroadcast(denyIntent);
+ ConfirmConnectActivity.this.finish();
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.show();
+ }
+}