summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2010-03-02 15:04:27 -0800
committerMichael Chan <mchan@android.com>2010-03-03 12:35:49 -0800
commit76098b7f7ac4f19af776fcad8413b582904bfdc2 (patch)
tree4379d6408fd391a6877109407b8af976298a4712 /tests
parent385a9e52be6f3a6014d6aaca06a800289e90b528 (diff)
downloadpackages_apps_Settings-76098b7f7ac4f19af776fcad8413b582904bfdc2.zip
packages_apps_Settings-76098b7f7ac4f19af776fcad8413b582904bfdc2.tar.gz
packages_apps_Settings-76098b7f7ac4f19af776fcad8413b582904bfdc2.tar.bz2
b/2310373 Show pairing dialogs if the device has been scanning for bt devices recently.
Change-Id: Iec9eb37a5e79b63cc3cf226e2ead6d9ed06d56a6
Diffstat (limited to 'tests')
-rw-r--r--tests/AndroidManifest.xml1
-rw-r--r--tests/res/layout/bluetooth_request_permission_test.xml8
-rw-r--r--tests/res/values/strings.xml2
-rw-r--r--tests/src/com/android/settings/tests/BluetoothRequestPermissionTest.java45
4 files changed, 50 insertions, 6 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 8a0ce21..6b9e050 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -18,6 +18,7 @@
package="com.android.settings.tests">
<uses-permission android:name="android.permission.BLUETOOTH" />
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application>
<uses-library android:name="android.test.runner" />
diff --git a/tests/res/layout/bluetooth_request_permission_test.xml b/tests/res/layout/bluetooth_request_permission_test.xml
index 4d54544..0a5aec0 100644
--- a/tests/res/layout/bluetooth_request_permission_test.xml
+++ b/tests/res/layout/bluetooth_request_permission_test.xml
@@ -37,10 +37,16 @@
android:layout_weight="1"
android:text="@string/enable" />
- <Button android:id="@+id/discover"
+ <Button android:id="@+id/discoverable"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/discoverable" />
+
+ <Button android:id="@+id/scan"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/start_scan" />
</LinearLayout>
</LinearLayout>
diff --git a/tests/res/values/strings.xml b/tests/res/values/strings.xml
index b06782f..f8a0481 100644
--- a/tests/res/values/strings.xml
+++ b/tests/res/values/strings.xml
@@ -20,4 +20,6 @@
<!-- Test only. Do not translate. -->
<string name="enable">Enable</string>
<string name="discoverable">Discoverable</string>
+ <string name="start_scan">Start Scan</string>
+ <string name="stop_scan">Stop Scan</string>
</resources>
diff --git a/tests/src/com/android/settings/tests/BluetoothRequestPermissionTest.java b/tests/src/com/android/settings/tests/BluetoothRequestPermissionTest.java
index 105c98e..8064e3a 100644
--- a/tests/src/com/android/settings/tests/BluetoothRequestPermissionTest.java
+++ b/tests/src/com/android/settings/tests/BluetoothRequestPermissionTest.java
@@ -33,7 +33,7 @@ import android.widget.ListView;
public class BluetoothRequestPermissionTest extends Activity {
private static final String TAG = "BluetoothRequestPermissionTest";
-
+ BluetoothAdapter mAdapter;
private ArrayAdapter<String> mMsgAdapter;
private class BtOnClickListener implements OnClickListener {
@@ -48,23 +48,50 @@ public class BluetoothRequestPermissionTest extends Activity {
}
}
+ private class BtScanOnClickListener implements OnClickListener {
+ public void onClick(View v) {
+ Button scanButton = (Button) v;
+ if (mAdapter.isDiscovering()) {
+ mAdapter.cancelDiscovery();
+ scanButton.setText(R.string.start_scan);
+ } else {
+ mAdapter.startDiscovery();
+ scanButton.setText(R.string.stop_scan);
+ }
+ }
+ }
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.bluetooth_request_permission_test);
+ mAdapter = BluetoothAdapter.getDefaultAdapter();
Button enable = (Button) findViewById(R.id.enable);
enable.setOnClickListener(new BtOnClickListener(true /* enable */));
- Button discover = (Button) findViewById(R.id.discover);
- discover.setOnClickListener(new BtOnClickListener(false /* enable & discoverable */));
+ Button discoverable = (Button) findViewById(R.id.discoverable);
+ discoverable.setOnClickListener(new BtOnClickListener(false /* enable & discoverable */));
+
+ Button scanButton = (Button) findViewById(R.id.scan);
+ scanButton.setOnClickListener(new BtScanOnClickListener());
+ if (mAdapter.isDiscovering()) {
+ scanButton.setText(R.string.stop_scan);
+ } else {
+ scanButton.setText(R.string.start_scan);
+ }
mMsgAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
ListView listView = (ListView) findViewById(R.id.msg_container);
listView.setAdapter(mMsgAdapter);
- registerReceiver(mReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
+ filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
+ filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
+ filter.addAction(BluetoothDevice.ACTION_FOUND);
+ registerReceiver(mReceiver, filter);
addMsg("Initialized");
}
@@ -113,7 +140,8 @@ public class BluetoothRequestPermissionTest extends Activity {
public void onReceive(Context context, Intent intent) {
if (intent == null)
return;
- if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
+ String action = intent.getAction();
+ if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
String stateStr = "???";
switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothDevice.ERROR)) {
case BluetoothAdapter.STATE_OFF:
@@ -130,6 +158,13 @@ public class BluetoothRequestPermissionTest extends Activity {
break;
}
addMsg("Bluetooth status = " + stateStr);
+ } else if (action.equals(BluetoothDevice.ACTION_FOUND)) {
+ String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
+ addMsg("Found: " + name);
+ } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) {
+ addMsg("Scan started...");
+ } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
+ addMsg("Scan ended");
}
}
};