diff options
author | Brian Muramatsu <btmura@android.com> | 2011-06-15 12:35:54 -0700 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-06-15 12:35:54 -0700 |
commit | 5e50522aea7f9219467ecf4fd2a7addb7ba6fe29 (patch) | |
tree | 81bcf5152853976c2389694ee99f60dc9a8bb18f | |
parent | 248ec83f3eacb98b3aa06709cbe4e3601ea17f65 (diff) | |
parent | 8b98f7c62976339792181a7993aeb63b8c7e3d7e (diff) | |
download | platform_cts-5e50522aea7f9219467ecf4fd2a7addb7ba6fe29.tar.gz platform_cts-5e50522aea7f9219467ecf4fd2a7addb7ba6fe29.tar.bz2 platform_cts-5e50522aea7f9219467ecf4fd2a7addb7ba6fe29.zip |
Merge "Detect when BT Pairing Dialog is Incorrectly Shown" into gingerbread
3 files changed, 49 insertions, 0 deletions
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml index 93b50787d80..08bd98b7950 100644 --- a/apps/CtsVerifier/res/values/strings.xml +++ b/apps/CtsVerifier/res/values/strings.xml @@ -75,6 +75,8 @@ <string name="bt_sent_messages">Sent Messages</string> <string name="bt_no_messages">No messages</string> <string name="bt_make_discoverable">Make Discoverable</string> + <string name="bt_insecure_pairing_error_title">Pairing dialog shown?</string> + <string name="bt_insecure_pairing_error_message">Insecure connections should not show the pairing dialog!</string> <string name="bt_secure_client">Secure Client</string> <string name="bt_insecure_client">Insecure Client</string> diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BluetoothTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BluetoothTestActivity.java index a6f9919414a..b617fc28dcc 100644 --- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BluetoothTestActivity.java +++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BluetoothTestActivity.java @@ -254,6 +254,7 @@ public class BluetoothTestActivity extends PassFailButtons.ListActivity { if (data != null) { TestResult result = TestResult.fromActivityResult(resultCode, data); TestListItem test = secure ? mSecureClientTest : mInsecureClientTest; + test.setResult(result.getResult()); updateTest(test); } } diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/MessageTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/MessageTestActivity.java index aabe00c43b5..1d6706d9a41 100644 --- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/MessageTestActivity.java +++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/MessageTestActivity.java @@ -18,11 +18,16 @@ package com.android.cts.verifier.bluetooth; import com.android.cts.verifier.PassFailButtons; import com.android.cts.verifier.R; +import com.android.cts.verifier.TestResult; import android.app.AlertDialog; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; +import android.content.IntentFilter; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -43,12 +48,17 @@ public class MessageTestActivity extends PassFailButtons.Activity { static final String EXTRA_DEVICE_ADDRESS = "deviceAddress"; static final String EXTRA_SECURE = "secure"; + /** Broadcast action that should only be fired when pairing for a secure connection. */ + private static final String ACTION_PAIRING_REQUEST = + "android.bluetooth.device.action.PAIRING_REQUEST"; + private static final int ENABLE_BLUETOOTH_REQUEST = 1; private static final String MESSAGE_DELIMITER = "\n"; private static final Pattern MESSAGE_PATTERN = Pattern.compile("Message (\\d+) to .*"); private BluetoothAdapter mBluetoothAdapter; + private PairingActionReceiver mPairingActionReceiver; private BluetoothChatService mChatService; private ArrayAdapter<String> mReceivedMessagesAdapter; @@ -112,6 +122,10 @@ public class MessageTestActivity extends PassFailButtons.Activity { getPassButton().setEnabled(false); + mPairingActionReceiver = new PairingActionReceiver(); + IntentFilter intentFilter = new IntentFilter(ACTION_PAIRING_REQUEST); + registerReceiver(mPairingActionReceiver, intentFilter); + mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { startChatService(); @@ -284,9 +298,41 @@ public class MessageTestActivity extends PassFailButtons.Activity { Toast.makeText(this, toast, Toast.LENGTH_LONG).show(); } + class PairingActionReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (!mSecure && ACTION_PAIRING_REQUEST.equals(intent.getAction())) { + runOnUiThread(new Runnable() { + @Override + public void run() { + showPairingErrorDialog(); + } + }); + } + } + } + + private void showPairingErrorDialog() { + new AlertDialog.Builder(MessageTestActivity.this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(R.string.bt_insecure_pairing_error_title) + .setMessage(R.string.bt_insecure_pairing_error_message) + .setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + TestResult.setFailedResult(MessageTestActivity.this); + finish(); + } + }) + .setCancelable(false) + .show(); + } + @Override protected void onDestroy() { super.onDestroy(); mChatService.stop(); + unregisterReceiver(mPairingActionReceiver); } } |