summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Pawlowski <jpawlowski@google.com>2019-08-21 17:29:11 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-08-21 17:29:11 -0700
commit6c9181a004ef6bd5c0734498b26f22f92326eaa3 (patch)
tree84782d4369f397f75b2ee48a4e0ad58c21cb3b27
parenta7118cd46d18472569026ffa8e4bb16be0e475c9 (diff)
parent4dc881e00ee4cf33d351ad74ef85ced41a96565e (diff)
downloadcts-6c9181a004ef6bd5c0734498b26f22f92326eaa3.tar.gz
Merge "Bluetooth LE Connection Priority test refactor" into pie-cts-dev am: 7e21596668 am: a550626813
am: 4dc881e00e Change-Id: I3fb3fdcccbfa82f9699b65ec2ff5dbd8d11c54bf
-rwxr-xr-xapps/CtsVerifier/res/values/strings.xml9
-rw-r--r--apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientBaseActivity.java67
-rw-r--r--apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientService.java223
-rw-r--r--apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerBaseActivity.java94
-rw-r--r--apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerService.java218
5 files changed, 134 insertions, 477 deletions
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index aac13a4357d..4997482db17 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -551,10 +551,7 @@
<string name="ble_scan_stop">Stop scan</string>
<!-- BLE connection priority test strings -->
- <string name="ble_client_connection_priority">Testing priority: </string>
- <string name="ble_connection_priority_balanced">BALANCED</string>
- <string name="ble_connection_priority_high">HIGH</string>
- <string name="ble_connection_priority_low">LOW</string>
+ <string name="ble_client_connection_priority">Testing connection priority switching </string>
<string name="ble_server_connection_priority_result_passed">All test passed</string>
<string name="ble_server_connection_priority_result_failed">Test failed.</string>
<string name="ble_server_connection_priority_result_intervals">
@@ -582,9 +579,7 @@
<string name="ble_write_authenticated_characteristic_name">Bluetooth LE Write Encrypted Characteristic</string>
<string name="ble_read_authenticated_descriptor_name">Bluetooth LE Read Encrypted Descriptor</string>
<string name="ble_write_authenticated_descriptor_name">Bluetooth LE Write Encrypted Descriptor</string>
- <string name="ble_connection_priority_client_high">Bluetooth LE Send With CONNECTION_PRIORITY_HIGH</string>
- <string name="ble_connection_priority_client_low">Bluetooth LE Send With CONNECTION_PRIORITY_LOW_POWER</string>
- <string name="ble_connection_priority_client_balanced">Bluetooth LE Send With CONNECTION_PRIORITY_BALANCED</string>
+ <string name="ble_connection_priority_client_description">Client Switching Connection Priority</string>
<string name="ble_indicate_characteristic_name">Bluetooth LE Indicate Characteristic</string>
<string name="ble_encrypted_client_name">03 Bluetooth LE Encrypted Client Test</string>
<string name="ble_encrypted_client_info">Bluetooth LE Encrypted Client read/write on characteristic and descriptor need encrypted.</string>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientBaseActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientBaseActivity.java
index 47ea81fc241..9119aae6888 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientBaseActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientBaseActivity.java
@@ -40,17 +40,12 @@ import java.util.List;
public class BleConnectionPriorityClientBaseActivity extends PassFailButtons.Activity {
private TestAdapter mTestAdapter;
- private int mPassed = 0;
+ private boolean mPassed = false;
private Dialog mDialog;
- private static final int BLE_CONNECTION_HIGH = 0;
- private static final int BLE_CONNECTION_BALANCED = 1;
- private static final int BLE_CONNECTION_LOW = 2;
+ private static final int BLE_CONNECTION_UPDATE = 0;
- private static final int PASSED_HIGH = 0x1;
- private static final int PASSED_BALANCED = 0x2;
- private static final int PASSED_LOW = 0x4;
- private static final int ALL_PASSED = 0x7;
+ private static final int ALL_PASSED = 0x1;
private boolean mSecure;
@@ -80,9 +75,7 @@ public class BleConnectionPriorityClientBaseActivity extends PassFailButtons.Act
IntentFilter filter = new IntentFilter();
filter.addAction(BleConnectionPriorityClientService.ACTION_BLUETOOTH_DISABLED);
filter.addAction(BleConnectionPriorityClientService.ACTION_CONNECTION_SERVICES_DISCOVERED);
- filter.addAction(BleConnectionPriorityClientService.ACTION_FINISH_CONNECTION_PRIORITY_HIGH);
- filter.addAction(BleConnectionPriorityClientService.ACTION_FINISH_CONNECTION_PRIORITY_BALANCED);
- filter.addAction(BleConnectionPriorityClientService.ACTION_FINISH_CONNECTION_PRIORITY_LOW_POWER);
+ filter.addAction(BleConnectionPriorityClientService.ACTION_CONNECTION_PRIORITY_FINISH);
filter.addAction(BleConnectionPriorityClientService.ACTION_BLUETOOTH_MISMATCH_SECURE);
filter.addAction(BleConnectionPriorityClientService.ACTION_BLUETOOTH_MISMATCH_INSECURE);
filter.addAction(BleConnectionPriorityClientService.ACTION_FINISH_DISCONNECT);
@@ -140,9 +133,7 @@ public class BleConnectionPriorityClientBaseActivity extends PassFailButtons.Act
private List<Integer> setupTestList() {
ArrayList<Integer> testList = new ArrayList<Integer>();
- testList.add(R.string.ble_connection_priority_client_high);
- testList.add(R.string.ble_connection_priority_client_balanced);
- testList.add(R.string.ble_connection_priority_client_low);
+ testList.add(R.string.ble_connection_priority_client_description);
return testList;
}
@@ -157,44 +148,24 @@ public class BleConnectionPriorityClientBaseActivity extends PassFailButtons.Act
private void executeNextTestImpl() {
switch (mCurrentTest) {
case -1: {
- mCurrentTest = BLE_CONNECTION_HIGH;
+ mCurrentTest = BLE_CONNECTION_UPDATE;
Intent intent = new Intent(this, BleConnectionPriorityClientService.class);
- intent.setAction(BleConnectionPriorityClientService.ACTION_CONNECTION_PRIORITY_HIGH);
+ intent.setAction(BleConnectionPriorityClientService.ACTION_CONNECTION_PRIORITY_START);
startService(intent);
- String msg = getString(R.string.ble_client_connection_priority)
- + getString(R.string.ble_connection_priority_high);
+ String msg = getString(R.string.ble_client_connection_priority);
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
break;
- case BLE_CONNECTION_BALANCED: {
- mCurrentTest = BLE_CONNECTION_LOW;
- Intent intent = new Intent(this, BleConnectionPriorityClientService.class);
- intent.setAction(BleConnectionPriorityClientService.ACTION_CONNECTION_PRIORITY_LOW_POWER);
- startService(intent);
- String msg = getString(R.string.ble_client_connection_priority)
- + getString(R.string.ble_connection_priority_low);
- Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
- }
- break;
- case BLE_CONNECTION_HIGH: {
- mCurrentTest = BLE_CONNECTION_BALANCED;
- Intent intent = new Intent(this, BleConnectionPriorityClientService.class);
- intent.setAction(BleConnectionPriorityClientService.ACTION_CONNECTION_PRIORITY_BALANCED);
- startService(intent);
- String msg = getString(R.string.ble_client_connection_priority)
- + getString(R.string.ble_connection_priority_balanced);
- Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
- }
- break;
- case BLE_CONNECTION_LOW:
+ case BLE_CONNECTION_UPDATE: {
// all test done
closeDialog();
- if (mPassed == ALL_PASSED) {
+ if (mPassed == true) {
Intent intent = new Intent(this, BleConnectionPriorityClientService.class);
intent.setAction(BleConnectionPriorityClientService.ACTION_DISCONNECT);
startService(intent);
}
break;
+ }
default:
// something went wrong
closeDialog();
@@ -227,21 +198,11 @@ public class BleConnectionPriorityClientBaseActivity extends PassFailButtons.Act
showProgressDialog();
executeNextTest(3000);
break;
- case BleConnectionPriorityClientService.ACTION_FINISH_CONNECTION_PRIORITY_HIGH:
- mTestAdapter.setTestPass(BLE_CONNECTION_HIGH);
- mPassed |= PASSED_HIGH;
+ case BleConnectionPriorityClientService.ACTION_CONNECTION_PRIORITY_FINISH:
+ mTestAdapter.setTestPass(BLE_CONNECTION_UPDATE);
+ mPassed = true;
executeNextTest(1000);
break;
- case BleConnectionPriorityClientService.ACTION_FINISH_CONNECTION_PRIORITY_BALANCED:
- mTestAdapter.setTestPass(BLE_CONNECTION_BALANCED);
- mPassed |= PASSED_BALANCED;
- executeNextTest(1000);
- break;
- case BleConnectionPriorityClientService.ACTION_FINISH_CONNECTION_PRIORITY_LOW_POWER:
- mTestAdapter.setTestPass(BLE_CONNECTION_LOW);
- mPassed |= PASSED_LOW;
- executeNextTest(100);
- break;
case BleConnectionPriorityClientService.ACTION_BLUETOOTH_MISMATCH_SECURE:
showErrorDialog(R.string.ble_bluetooth_mismatch_title, R.string.ble_bluetooth_mismatch_secure_message, true);
break;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientService.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientService.java
index 38d37bd6f21..1df40f55528 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityClientService.java
@@ -62,19 +62,11 @@ public class BleConnectionPriorityClientService extends Service {
public static final String ACTION_BLUETOOTH_MISMATCH_INSECURE =
"com.android.cts.verifier.bluetooth.action.ACTION_BLUETOOTH_MISMATCH_INSECURE";
- public static final String ACTION_CONNECTION_PRIORITY_BALANCED =
- "com.android.cts.verifier.bluetooth.action.CONNECTION_PRIORITY_BALANCED";
- public static final String ACTION_CONNECTION_PRIORITY_HIGH =
- "com.android.cts.verifier.bluetooth.action.CONNECTION_PRIORITY_HIGH";
- public static final String ACTION_CONNECTION_PRIORITY_LOW_POWER =
+ public static final String ACTION_CONNECTION_PRIORITY_START =
"com.android.cts.verifier.bluetooth.action.CONNECTION_PRIORITY_LOW_POWER";
- public static final String ACTION_FINISH_CONNECTION_PRIORITY_BALANCED =
- "com.android.cts.verifier.bluetooth.action.FINISH_CONNECTION_PRIORITY_BALANCED";
- public static final String ACTION_FINISH_CONNECTION_PRIORITY_HIGH =
- "com.android.cts.verifier.bluetooth.action.FINISH_CONNECTION_PRIORITY_HIGH";
- public static final String ACTION_FINISH_CONNECTION_PRIORITY_LOW_POWER =
- "com.android.cts.verifier.bluetooth.action.FINISH_CONNECTION_PRIORITY_LOW_POWER";
+ public static final String ACTION_CONNECTION_PRIORITY_FINISH =
+ "com.android.cts.verifier.bluetooth.action.CONNECTION_PRIORITY_FINISH";
public static final String ACTION_CLIENT_CONNECT_SECURE =
"com.android.cts.verifier.bluetooth.action.CLIENT_CONNECT_SECURE";
@@ -84,20 +76,7 @@ public class BleConnectionPriorityClientService extends Service {
public static final String ACTION_FINISH_DISCONNECT =
"com.android.cts.verifier.bluetooth.action.FINISH_DISCONNECT";
- public static final long DEFAULT_INTERVAL = 100L;
- public static final long DEFAULT_PERIOD = 10000L;
-
- // this string will be used at writing test and connection priority test.
- private static final String WRITE_VALUE = "TEST";
-
- private static final UUID SERVICE_UUID =
- UUID.fromString("00009999-0000-1000-8000-00805f9b34fb");
- private static final UUID CHARACTERISTIC_UUID =
- UUID.fromString("00009998-0000-1000-8000-00805f9b34fb");
- private static final UUID START_CHARACTERISTIC_UUID =
- UUID.fromString("00009997-0000-1000-8000-00805f9b34fb");
- private static final UUID STOP_CHARACTERISTIC_UUID =
- UUID.fromString("00009995-0000-1000-8000-00805f9b34fb");
+ public static final int NOT_UNDER_TEST = -1;
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
@@ -108,13 +87,12 @@ public class BleConnectionPriorityClientService extends Service {
private Context mContext;
private String mAction;
- private long mInterval;
- private long mPeriod;
- private Date mStartDate;
- private int mWriteCount;
private boolean mSecure;
- private String mPriority;
+ private int mPriority = NOT_UNDER_TEST;
+ private int interval_low = 0;
+ private int interval_balanced = 0;
+ private int interval_high = 0;
private TestTaskQueue mTaskQueue;
@@ -129,8 +107,6 @@ public class BleConnectionPriorityClientService extends Service {
mScanner = mBluetoothAdapter.getBluetoothLeScanner();
mHandler = new Handler();
mContext = this;
- mInterval = DEFAULT_INTERVAL;
- mPeriod = DEFAULT_PERIOD;
startScan();
}
@@ -171,15 +147,8 @@ public class BleConnectionPriorityClientService extends Service {
case ACTION_CLIENT_CONNECT_SECURE:
mSecure = true;
break;
- case ACTION_CONNECTION_PRIORITY_BALANCED:
- case ACTION_CONNECTION_PRIORITY_HIGH:
- case ACTION_CONNECTION_PRIORITY_LOW_POWER:
- mTaskQueue.addTask(new Runnable() {
- @Override
- public void run() {
- startPeriodicTransmission();
- }
- });
+ case ACTION_CONNECTION_PRIORITY_START:
+ myRequestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER);
break;
case ACTION_DISCONNECT:
if (mBluetoothGatt != null) {
@@ -194,120 +163,17 @@ public class BleConnectionPriorityClientService extends Service {
return START_NOT_STICKY;
}
- private void startPeriodicTransmission() {
- mWriteCount = 0;
-
- // Set connection priority
- switch (mAction) {
- case ACTION_CONNECTION_PRIORITY_BALANCED:
- mPriority = BleConnectionPriorityServerService.CONNECTION_PRIORITY_BALANCED;
- mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_BALANCED);
- break;
- case ACTION_CONNECTION_PRIORITY_HIGH:
- mPriority = BleConnectionPriorityServerService.CONNECTION_PRIORITY_HIGH;
- mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
- break;
- case ACTION_CONNECTION_PRIORITY_LOW_POWER:
- mPriority = BleConnectionPriorityServerService.CONNECTION_PRIORITY_LOW_POWER;
- mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER);
- break;
- default:
- mPriority = BleConnectionPriorityServerService.CONNECTION_PRIORITY_BALANCED;
- mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_BALANCED);
- break;
- }
-
- // Create Timer for Periodic transmission
- mStartDate = new Date();
- TimerTask task = new TimerTask() {
- @Override
- public void run() {
- if (mBluetoothGatt == null) {
- if (DEBUG) {
- Log.d(TAG, "BluetoothGatt is null, return");
- }
- return;
- }
-
- Date currentData = new Date();
- if ((currentData.getTime() - mStartDate.getTime()) >= mPeriod) {
- if (mConnectionTimer != null) {
- mConnectionTimer.cancel();
- mConnectionTimer = null;
- }
- // The STOP_CHARACTERISTIC_UUID is critical in syncing the client and server
- // states. Delay the write by 2 seconds to improve the chance of this
- // characteristic going through. Consider changing the code to use callbacks
- // in the future to make it more robust.
- sleep(2000);
- // write termination data (contains current priority and number of messages wrote)
- String msg = "" + mPriority + "," + mWriteCount;
- writeCharacteristic(STOP_CHARACTERISTIC_UUID, msg);
- sleep(1000);
- Intent intent = new Intent();
- switch (mPriority) {
- case BleConnectionPriorityServerService.CONNECTION_PRIORITY_BALANCED:
- intent.setAction(ACTION_FINISH_CONNECTION_PRIORITY_BALANCED);
- break;
- case BleConnectionPriorityServerService.CONNECTION_PRIORITY_HIGH:
- intent.setAction(ACTION_FINISH_CONNECTION_PRIORITY_HIGH);
- break;
- case BleConnectionPriorityServerService.CONNECTION_PRIORITY_LOW_POWER:
- intent.setAction(ACTION_FINISH_CONNECTION_PRIORITY_LOW_POWER);
- break;
- }
- sendBroadcast(intent);
- }
-
- if (mConnectionTimer != null) {
- // write testing data
- ++mWriteCount;
- writeCharacteristic(CHARACTERISTIC_UUID, WRITE_VALUE);
- }
- }
- };
-
- // write starting data
- writeCharacteristic(START_CHARACTERISTIC_UUID, mPriority);
-
- // start sending
- sleep(1000);
- mConnectionTimer = new Timer();
- mConnectionTimer.schedule(task, 0, mInterval);
- }
-
- private BluetoothGattService getService() {
- BluetoothGattService service = null;
-
- if (mBluetoothGatt != null) {
- service = mBluetoothGatt.getService(SERVICE_UUID);
- if (service == null) {
- showMessage("Service not found");
- }
- }
- return service;
+ private void myRequestConnectionPriority(final int priority) {
+ mTaskQueue.addTask(new Runnable() {
+ @Override
+ public void run() {
+ mPriority = priority;
+ mBluetoothGatt.requestConnectionPriority(mPriority);
+ //continue in onConnectionUpdated() callback
+ }
+ });
}
- private BluetoothGattCharacteristic getCharacteristic(UUID uuid) {
- BluetoothGattCharacteristic characteristic = null;
-
- BluetoothGattService service = getService();
- if (service != null) {
- characteristic = service.getCharacteristic(uuid);
- if (characteristic == null) {
- showMessage("Characteristic not found");
- }
- }
- return characteristic;
- }
-
- private void writeCharacteristic(UUID uid, String writeValue) {
- BluetoothGattCharacteristic characteristic = getCharacteristic(uid);
- if (characteristic != null){
- characteristic.setValue(writeValue);
- mBluetoothGatt.writeCharacteristic(characteristic);
- }
- }
private void sleep(int millis) {
try {
@@ -372,19 +238,56 @@ public class BleConnectionPriorityClientService extends Service {
if (DEBUG){
Log.d(TAG, "onServiceDiscovered");
}
- if ((status == BluetoothGatt.GATT_SUCCESS) && (mBluetoothGatt.getService(SERVICE_UUID) != null)) {
+ if (status == BluetoothGatt.GATT_SUCCESS) {
showMessage("Service discovered");
Intent intent = new Intent(ACTION_CONNECTION_SERVICES_DISCOVERED);
sendBroadcast(intent);
}
+
+ //onConnectionUpdated is hidden callback, can't be marked as @Override.
+ // We must have a call to it, otherwise compiler will delete it during optimization.
+ if (status == 0xFFEFFEE) {
+ // This should never execute, but will make compiler not remove onConnectionUpdated
+ onConnectionUpdated(null, 0, 0, 0, 0);
+ throw new IllegalStateException("This should never happen!");
+ }
}
+
+ // @Override uncomment once this becomes public API
+ public void onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout,
+ int status) {
+ if (mPriority == NOT_UNDER_TEST) return;
+
+ if (status != 0) {
+ showMessage("onConnectionUpdated() error, status=" + status );
+ Log.e(TAG, "onConnectionUpdated() status=" + status);
+ return;
+ }
- @Override
- public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
- String value = characteristic.getStringValue(0);
- UUID uid = characteristic.getUuid();
- if (DEBUG) {
- Log.d(TAG, "onCharacteristicWrite: characteristic.val=" + value + " status=" + status + " uid=" + uid);
+ Log.i(TAG, "onConnectionUpdated() status=" + status + ", interval=" + interval);
+ if (mPriority == BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER) {
+ interval_low = interval;
+ myRequestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_BALANCED);
+ } else if (mPriority == BluetoothGatt.CONNECTION_PRIORITY_BALANCED) {
+ interval_balanced = interval;
+ myRequestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
+ } else if (mPriority == BluetoothGatt.CONNECTION_PRIORITY_HIGH) {
+ interval_high = interval;
+
+ if (interval_low < interval_balanced || interval_balanced < interval_high) {
+ showMessage("interval value should be descending - failure!");
+ Log.e(TAG, "interval values should be descending: interval_low=" + interval_low +
+ ", interval_balanced=" + interval_balanced + ", interval_high=" + interval_high);
+ return;
+ }
+
+ showMessage("intervals: " + interval_low +" > " + interval_balanced + " > " + interval_high);
+
+ Intent intent = new Intent();
+ intent.setAction(ACTION_CONNECTION_PRIORITY_FINISH);
+ sendBroadcast(intent);
+
+ mPriority = NOT_UNDER_TEST;
}
}
};
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerBaseActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerBaseActivity.java
index c0a2f098f6d..66e068e00d0 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerBaseActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerBaseActivity.java
@@ -37,12 +37,6 @@ import java.util.List;
public class BleConnectionPriorityServerBaseActivity extends PassFailButtons.Activity {
public static final int CONNECTION_PRIORITY_HIGH = 0;
- public static final int CONNECTION_PRIORITY_BALANCED = 1;
- public static final int CONNECTION_PRIORITY_LOW_POWER = 2;
-
- private long mAverageBalanced = -1;
- private long mAverageHigh = -1;
- private long mAverageLow = -1;
private TestAdapter mTestAdapter;
@@ -71,10 +65,7 @@ public class BleConnectionPriorityServerBaseActivity extends PassFailButtons.Act
IntentFilter filter = new IntentFilter();
filter.addAction(BleConnectionPriorityServerService.ACTION_BLUETOOTH_DISABLED);
- filter.addAction(BleConnectionPriorityServerService.ACTION_CONNECTION_WRITE_REQUEST);
- filter.addAction(BleConnectionPriorityServerService.ACTION_FINICH_CONNECTION_PRIORITY_HIGHT);
- filter.addAction(BleConnectionPriorityServerService.ACTION_FINICH_CONNECTION_PRIORITY_BALANCED);
- filter.addAction(BleConnectionPriorityServerService.ACTION_FINICH_CONNECTION_PRIORITY_LOW);
+ filter.addAction(BleConnectionPriorityServerService.ACTION_CONNECTION_PRIORITY_FINISH);
filter.addAction(BleServerService.BLE_ADVERTISE_UNSUPPORTED);
filter.addAction(BleServerService.BLE_OPEN_FAIL);
filter.addAction(BleConnectionPriorityServerService.ACTION_START_CONNECTION_PRIORITY_TEST);
@@ -90,9 +81,7 @@ public class BleConnectionPriorityServerBaseActivity extends PassFailButtons.Act
private List<Integer> setupTestList() {
ArrayList<Integer> testList = new ArrayList<Integer>();
- testList.add(R.string.ble_connection_priority_client_high);
- testList.add(R.string.ble_connection_priority_client_balanced);
- testList.add(R.string.ble_connection_priority_client_low);
+ testList.add(R.string.ble_connection_priority_client_description);
return testList;
}
@@ -130,8 +119,8 @@ public class BleConnectionPriorityServerBaseActivity extends PassFailButtons.Act
private BroadcastReceiver mBroadcast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
+ boolean passedAll = false;
String action = intent.getAction();
- long average = intent.getLongExtra(BleConnectionPriorityServerService.EXTRA_AVERAGE, -1);
switch (action) {
case BleConnectionPriorityServerService.ACTION_BLUETOOTH_DISABLED:
new AlertDialog.Builder(context)
@@ -148,64 +137,12 @@ public class BleConnectionPriorityServerBaseActivity extends PassFailButtons.Act
case BleConnectionPriorityServerService.ACTION_START_CONNECTION_PRIORITY_TEST:
showProgressDialog();
break;
- case BleConnectionPriorityServerService.ACTION_FINICH_CONNECTION_PRIORITY_HIGHT:
- mAverageHigh = average;
- mAverageBalanced = -1;
- mAverageLow = -1;
- break;
- case BleConnectionPriorityServerService.ACTION_FINICH_CONNECTION_PRIORITY_BALANCED:
- mAverageBalanced = average;
- break;
- case BleConnectionPriorityServerService.ACTION_FINICH_CONNECTION_PRIORITY_LOW:
- mAverageLow = average;
- break;
- case BleServerService.BLE_OPEN_FAIL:
- setTestResultAndFinish(false);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(BleConnectionPriorityServerBaseActivity.this, R.string.bt_open_failed_message, Toast.LENGTH_SHORT).show();
- }
- });
- break;
- case BleServerService.BLE_ADVERTISE_UNSUPPORTED:
- showErrorDialog(R.string.bt_advertise_unsupported_title, R.string.bt_advertise_unsupported_message, true);
- break;
- }
+ case BleConnectionPriorityServerService.ACTION_CONNECTION_PRIORITY_FINISH:
+ String resultMsg = getString(R.string.ble_server_connection_priority_result_passed);
- boolean passedHigh = (mAverageHigh >= 0);
- boolean passedAll = false;
+ closeDialog();
- if (passedHigh) {
mTestAdapter.setTestPass(CONNECTION_PRIORITY_HIGH);
- }
-
- if (passedHigh && (mAverageLow >= 0) && (mAverageBalanced >= 0)) {
- boolean passedBalanced = (mAverageHigh <= mAverageBalanced);
- boolean passedLow = (mAverageBalanced <= mAverageLow);
-
- if (passedBalanced) {
- mTestAdapter.setTestPass(CONNECTION_PRIORITY_BALANCED);
- }
- if (passedLow) {
- mTestAdapter.setTestPass(CONNECTION_PRIORITY_LOW_POWER);
- }
-
- String resultMsg;
- if (passedBalanced && passedLow) {
- resultMsg = getString(R.string.ble_server_connection_priority_result_passed);
- passedAll = true;
- } else {
- String detailsMsg = String.format(getString(R.string.ble_server_connection_priority_result_intervals),
- mAverageHigh,
- mAverageBalanced,
- mAverageLow);
- resultMsg = getString(R.string.ble_server_connection_priority_result_failed)
- + "\n\n"
- + detailsMsg;
- }
-
- closeDialog();
mDialog = new AlertDialog.Builder(BleConnectionPriorityServerBaseActivity.this)
.setMessage(resultMsg)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@@ -222,10 +159,25 @@ public class BleConnectionPriorityServerBaseActivity extends PassFailButtons.Act
})
.create();
mDialog.show();
+
+ getPassButton().setEnabled(true);
+ mTestAdapter.notifyDataSetChanged();
+ break;
+
+ case BleServerService.BLE_OPEN_FAIL:
+ setTestResultAndFinish(false);
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(BleConnectionPriorityServerBaseActivity.this, R.string.bt_open_failed_message, Toast.LENGTH_SHORT).show();
+ }
+ });
+ break;
+ case BleServerService.BLE_ADVERTISE_UNSUPPORTED:
+ showErrorDialog(R.string.bt_advertise_unsupported_title, R.string.bt_advertise_unsupported_message, true);
+ break;
}
- getPassButton().setEnabled(passedAll);
- mTestAdapter.notifyDataSetChanged();
}
};
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerService.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerService.java
index e1e4eedc2c3..ccffcdb9d25 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleConnectionPriorityServerService.java
@@ -45,43 +45,16 @@ import java.util.UUID;
public class BleConnectionPriorityServerService extends Service {
public static final boolean DEBUG = true;
public static final String TAG = "BlePriorityServer";
- private static final String RESET_COUNT_VALUE = "RESET";
- private static final String START_VALUE = "START";
- private static final String STOP_VALUE = "STOP";
- public static final String CONNECTION_PRIORITY_HIGH = "PR_H";
- public static final String CONNECTION_PRIORITY_BALANCED = "PR_B";
- public static final String CONNECTION_PRIORITY_LOW_POWER = "PR_L";
public static final String ACTION_BLUETOOTH_DISABLED =
"com.android.cts.verifier.bluetooth.action.BLUETOOTH_DISABLED";
- public static final String ACTION_CONNECTION_WRITE_REQUEST =
- "com.android.cts.verifier.bluetooth.action.CONNECTION_WRITE_REQUEST";
- public static final String EXTRA_REQUEST_COUNT =
- "com.android.cts.verifier.bluetooth.intent.EXTRA_REQUEST_COUNT";
- public static final String ACTION_FINICH_CONNECTION_PRIORITY_HIGHT =
- "com.android.cts.verifier.bluetooth.action.ACTION_FINICH_CONNECTION_PRIORITY_HIGHT";
- public static final String ACTION_FINICH_CONNECTION_PRIORITY_BALANCED =
- "com.android.cts.verifier.bluetooth.action.ACTION_FINICH_CONNECTION_PRIORITY_BALANCED";
- public static final String ACTION_FINICH_CONNECTION_PRIORITY_LOW =
- "com.android.cts.verifier.bluetooth.action.ACTION_FINICH_CONNECTION_PRIORITY_LOW";
+ public static final String ACTION_CONNECTION_PRIORITY_FINISH =
+ "com.android.cts.verifier.bluetooth.action.ACTION_CONNECTION_PRIORITY_FINISH";
public static final String ACTION_START_CONNECTION_PRIORITY_TEST =
"com.android.cts.verifier.bluetooth.action.ACTION_START_CONNECTION_PRIORITY_TEST";
- public static final String EXTRA_AVERAGE =
- "com.android.cts.verifier.bluetooth.intent.EXTRA_AVERAGE";
-
- private static final UUID SERVICE_UUID =
- UUID.fromString("00009999-0000-1000-8000-00805f9b34fb");
- private static final UUID CHARACTERISTIC_UUID =
- UUID.fromString("00009998-0000-1000-8000-00805f9b34fb");
- private static final UUID START_CHARACTERISTIC_UUID =
- UUID.fromString("00009997-0000-1000-8000-00805f9b34fb");
- private static final UUID STOP_CHARACTERISTIC_UUID =
- UUID.fromString("00009995-0000-1000-8000-00805f9b34fb");
- private static final UUID DESCRIPTOR_UUID =
- UUID.fromString("00009996-0000-1000-8000-00805f9b34fb");
public static final UUID ADV_SERVICE_UUID=
UUID.fromString("00002222-0000-1000-8000-00805f9b34fb");
@@ -92,8 +65,10 @@ public class BleConnectionPriorityServerService extends Service {
private Handler mHandler;
private BluetoothLeAdvertiser mAdvertiser;
private long mReceiveWriteCount;
- private Timer mTimeoutTimer;
- private TimerTask mTimeoutTimerTask;
+
+ private int interval_low = 0;
+ private int interval_balanced = 0;
+ private int interval_high = 0;
@Override
public void onCreate() {
@@ -102,10 +77,6 @@ public class BleConnectionPriorityServerService extends Service {
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mAdvertiser = mBluetoothManager.getAdapter().getBluetoothLeAdvertiser();
mGattServer = mBluetoothManager.openGattServer(this, mCallbacks);
- mService = createService();
- if ((mGattServer != null) && (mAdvertiser != null)) {
- mGattServer.addService(mService);
- }
mDevice = null;
mHandler = new Handler();
@@ -124,14 +95,6 @@ public class BleConnectionPriorityServerService extends Service {
public void onDestroy() {
super.onDestroy();
- cancelTimeoutTimer(false);
-
- if (mTimeoutTimer != null) {
- mTimeoutTimer.cancel();
- mTimeoutTimer = null;
- }
- mTimeoutTimerTask = null;
-
stopAdvertise();
if (mGattServer == null) {
return;
@@ -194,21 +157,6 @@ public class BleConnectionPriorityServerService extends Service {
}
}
- private void notifyServiceAdded() {
- if (DEBUG) {
- Log.d(TAG, "notifyServiceAdded");
- }
- }
-
- private void notifyCharacteristicWriteRequest() {
- if (DEBUG) {
- Log.d(TAG, "notifyCharacteristicWriteRequest");
- }
- Intent intent = new Intent(ACTION_CONNECTION_WRITE_REQUEST);
- intent.putExtra(EXTRA_REQUEST_COUNT, String.valueOf(mReceiveWriteCount));
- sendBroadcast(intent);
- }
-
private void showMessage(final String msg) {
mHandler.post(new Runnable() {
@Override
@@ -218,38 +166,6 @@ public class BleConnectionPriorityServerService extends Service {
});
}
- private synchronized void cancelTimeoutTimer(boolean runTimeout) {
- if (mTimeoutTimerTask != null) {
- mTimeoutTimer.cancel();
- if (runTimeout) {
- mTimeoutTimerTask.run();
- }
- mTimeoutTimerTask = null;
- mTimeoutTimer = null;
- }
- }
-
- private BluetoothGattService createService() {
- BluetoothGattService service =
- new BluetoothGattService(SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
- // add characteristic to service
- // property: 0x0A (read, write)
- // permission: 0x11 (read, write)
- BluetoothGattCharacteristic characteristic =
- new BluetoothGattCharacteristic(CHARACTERISTIC_UUID, 0x0A, 0x11);
- BluetoothGattDescriptor descriptor = new BluetoothGattDescriptor(DESCRIPTOR_UUID, 0x11);
- characteristic.addDescriptor(descriptor);
- service.addCharacteristic(characteristic);
- characteristic = new BluetoothGattCharacteristic(START_CHARACTERISTIC_UUID, 0x0A, 0x11);
- characteristic.addDescriptor(descriptor);
- service.addCharacteristic(characteristic);
- characteristic = new BluetoothGattCharacteristic(STOP_CHARACTERISTIC_UUID, 0x0A, 0x11);
- characteristic.addDescriptor(descriptor);
- service.addCharacteristic(characteristic);
-
- return service;
- }
-
private final BluetoothGattServerCallback mCallbacks = new BluetoothGattServerCallback() {
@Override
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
@@ -261,120 +177,50 @@ public class BleConnectionPriorityServerService extends Service {
mDevice = device;
notifyConnected();
} else if (status == BluetoothProfile.STATE_DISCONNECTED) {
- cancelTimeoutTimer(true);
notifyDisconnected();
mDevice = null;
}
}
- }
- @Override
- public void onServiceAdded(int status, BluetoothGattService service) {
- if (DEBUG) {
- Log.d(TAG, "onServiceAdded()");
- }
- if (status == BluetoothGatt.GATT_SUCCESS) {
- notifyServiceAdded();
+ //onConnectionUpdated is hidden callback, can't be marked as @Override.
+ // We must have a call to it, otherwise compiler will delete it during optimization.
+ if (status == 0xFFEFFEE) {
+ // This should never execute, but will make compiler not remove onConnectionUpdated
+ onConnectionUpdated(null, 0, 0, 0, 0);
+ throw new IllegalStateException("This should never happen!");
}
+
}
- String mPriority = null;
+ // @Override uncomment once this becomes public API
+ public void onConnectionUpdated(BluetoothDevice device, int interval, int latency, int timeout, int status) {
+ Log.i(TAG, "onConnectionUpdated() status=" + status + ", interval=" + interval);
- @Override
- public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
- BluetoothGattCharacteristic characteristic,
- boolean preparedWrite, boolean responseNeeded,
- int offset, byte[] value) {
- if (mGattServer == null) {
- if (DEBUG) {
- Log.d(TAG, "GattServer is null, return");
- }
- return;
- }
- if (DEBUG) {
- Log.d(TAG, "onCharacteristicWriteRequest: preparedWrite=" + preparedWrite);
+ if (status != 0) {
+ interval_low = interval_balanced = interval_high = 0;
+ return;
}
- if (characteristic.getUuid().equals(START_CHARACTERISTIC_UUID)) {
- // time out if previous measurement is running
- cancelTimeoutTimer(true);
+ // since we don't know when the test started, wait for three descending interval values.
+ // Even though conneciton is updated by service discovery, it never happen three times
+ // descending in any scenario.
- mPriority = new String(value);
- Log.d(TAG, "Start Count Up. Priority is " + mPriority);
- if (BleConnectionPriorityServerService.CONNECTION_PRIORITY_HIGH.equals(mPriority)) {
- notifyTestStart();
- }
-
- // start timeout timer
- mTimeoutTimer = new Timer(getClass().getName() + "_TimeoutTimer");
- mTimeoutTimerTask = new TimerTask() {
- @Override
- public void run() {
- // measurement timed out
- mTimeoutTimerTask = null;
- mTimeoutTimer = null;
- mReceiveWriteCount = 0;
- notifyMeasurementFinished(mPriority, Long.MAX_VALUE);
- }
- };
- mTimeoutTimer.schedule(mTimeoutTimerTask, (BleConnectionPriorityClientService.DEFAULT_PERIOD * 2));
-
- mReceiveWriteCount = 0;
- } else if (characteristic.getUuid().equals(STOP_CHARACTERISTIC_UUID)) {
- boolean isRunning = (mTimeoutTimerTask != null);
- cancelTimeoutTimer(false);
-
- String valeStr = new String(value);
- String priority = null;
- int writeCount = -1;
- int sep = valeStr.indexOf(",");
- if (sep > 0) {
- priority = valeStr.substring(0, sep);
- writeCount = Integer.valueOf(valeStr.substring(sep + 1));
- }
-
- if ((mPriority != null) && isRunning) {
- if (mPriority.equals(priority)) {
- long averageTime = BleConnectionPriorityClientService.DEFAULT_PERIOD / mReceiveWriteCount;
- notifyMeasurementFinished(mPriority, averageTime);
- Log.d(TAG, "Received " + mReceiveWriteCount + " of " + writeCount + " messages");
- } else {
- Log.d(TAG, "Connection priority does not match");
- showMessage("Connection priority does not match");
- }
- } else {
- Log.d(TAG, "Not Start Count UP.");
- }
- mReceiveWriteCount = 0;
- } else {
- if (mTimeoutTimerTask != null) {
- ++mReceiveWriteCount;
- }
- if (!preparedWrite) {
- characteristic.setValue(value);
- }
- }
+ // shift all values
+ interval_low = interval_balanced;
+ interval_balanced = interval_high;
+ interval_high = interval;
- if (responseNeeded) {
- mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, null);
+ // If we end up with three descending values, test is passed.
+ if (interval_low > interval_balanced && interval_balanced > interval_high) {
+ showMessage("intervals: " + interval_low +" > " + interval_balanced + " > " + interval_high);
+ notifyMeasurementFinished();
}
}
};
- private void notifyMeasurementFinished(String priority, long averageTime) {
+ private void notifyMeasurementFinished() {
Intent intent = new Intent();
- intent.putExtra(EXTRA_AVERAGE, averageTime);
- switch (priority) {
- case CONNECTION_PRIORITY_HIGH:
- intent.setAction(ACTION_FINICH_CONNECTION_PRIORITY_HIGHT);
- break;
- case CONNECTION_PRIORITY_BALANCED:
- intent.setAction(ACTION_FINICH_CONNECTION_PRIORITY_BALANCED);
- break;
- case CONNECTION_PRIORITY_LOW_POWER:
- intent.setAction(ACTION_FINICH_CONNECTION_PRIORITY_LOW);
- break;
- }
+ intent.setAction(ACTION_CONNECTION_PRIORITY_FINISH);
sendBroadcast(intent);
}