diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2021-01-07 00:05:40 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-01-07 00:05:40 +0000 |
commit | d8fe2ae683bf41bf23741e8def4b0c70c7e83d78 (patch) | |
tree | 776593b88c70ce3d9e19ab010050dcbeff05e755 | |
parent | e8462c21d6d3f9bf8b35b9046504b2a207c6f828 (diff) | |
parent | 3b3d466158b738a38ccfa8c5eaadb91b8b75b7c4 (diff) | |
download | cts-oreo-vts-release.tar.gz |
Merge "Snap for 7066011 from fa96b1ec373444b601a0b516b494152d7c908cad to oreo-vts-release" into oreo-vts-releaseoreo-vts-release
34 files changed, 657 insertions, 679 deletions
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml index a63dc485b0c..c5124012792 100644 --- a/apps/CtsVerifier/AndroidManifest.xml +++ b/apps/CtsVerifier/AndroidManifest.xml @@ -18,7 +18,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.cts.verifier" android:versionCode="5" - android:versionName="8.0_r22"> + android:versionName="8.0_r26"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26"/> diff --git a/apps/CtsVerifier/res/layout/uap_attribs_panel.xml b/apps/CtsVerifier/res/layout/uap_attribs_panel.xml index 6c33d9f6477..b9c5d3e51a9 100644 --- a/apps/CtsVerifier/res/layout/uap_attribs_panel.xml +++ b/apps/CtsVerifier/res/layout/uap_attribs_panel.xml @@ -9,6 +9,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> + <include layout="@layout/uap_usb_confirm"/> + <include layout="@layout/uap_profile_header"/> <LinearLayout diff --git a/apps/CtsVerifier/res/layout/uap_buttons_panel.xml b/apps/CtsVerifier/res/layout/uap_buttons_panel.xml index 4fdc75782e1..355bfb6a77c 100644 --- a/apps/CtsVerifier/res/layout/uap_buttons_panel.xml +++ b/apps/CtsVerifier/res/layout/uap_buttons_panel.xml @@ -9,6 +9,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> + <include layout="@layout/uap_usb_confirm"/> + <include layout="@layout/uap_profile_header"/> <LinearLayout diff --git a/apps/CtsVerifier/res/layout/uap_play_panel.xml b/apps/CtsVerifier/res/layout/uap_play_panel.xml index 2faa50cc1a7..30ef884be4b 100644 --- a/apps/CtsVerifier/res/layout/uap_play_panel.xml +++ b/apps/CtsVerifier/res/layout/uap_play_panel.xml @@ -9,6 +9,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> + <include layout="@layout/uap_usb_confirm"/> + <include layout="@layout/uap_profile_header"/> <LinearLayout diff --git a/apps/CtsVerifier/res/layout/uap_record_panel.xml b/apps/CtsVerifier/res/layout/uap_record_panel.xml index 2deb7387d7d..a5bfcfca7e9 100644 --- a/apps/CtsVerifier/res/layout/uap_record_panel.xml +++ b/apps/CtsVerifier/res/layout/uap_record_panel.xml @@ -9,6 +9,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> + <include layout="@layout/uap_usb_confirm"/> + <include layout="@layout/uap_profile_header"/> <LinearLayout diff --git a/apps/CtsVerifier/res/layout/uap_usb_confirm.xml b/apps/CtsVerifier/res/layout/uap_usb_confirm.xml new file mode 100644 index 00000000000..ea73b88c22d --- /dev/null +++ b/apps/CtsVerifier/res/layout/uap_usb_confirm.xml @@ -0,0 +1,38 @@ +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/uap_test_question"/> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:soundEffectsEnabled="false" + android:text="@string/uap_test_yes" + android:id="@+id/uap_tests_yes_btn" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:soundEffectsEnabled="false" + android:text="@string/uap_test_no" + android:id="@+id/uap_tests_no_btn" /> + + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:soundEffectsEnabled="false" + android:text="@string/uap_test_info" + android:id="@+id/uap_test_info_btn" /> + </LinearLayout> +</LinearLayout> diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml index fa8c4a4d6ed..f2f49d78e5a 100755 --- a/apps/CtsVerifier/res/values/strings.xml +++ b/apps/CtsVerifier/res/values/strings.xml @@ -400,10 +400,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"> @@ -426,9 +423,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> @@ -4050,4 +4045,17 @@ Follow the instructions on the screen to measure the frequency response for the Click the button below to confirm that the incoming call was answered. </string> <string name="telecom_incoming_self_mgd_confirm_answer_button">Confirm Answer</string> + + <string name="uap_test_no">No</string> + <string name="uap_test_yes">Yes</string> + <string name="uap_test_info">Info</string> + <string name="uap_test_question">Does this device allow for the connectiono of a USB reference microphone?</string> + <string name="uap_mic_dlg_caption">USB Host Mode Audio Required</string> + <string name="uap_mic_dlg_text">This test requires a USB audio peripheral to be connected to the device. + If the device under test does not support USB Host Mode Audio (either because it does not have a + USB port, or USB Host Mode Audio has been removed from the OS) you can be granted a provisional + pass on this test by pressing the \"No\" button and indicating \"Test Pass\" at the bottom.\n + Note: Handheld devices supporting USB host mode MUST support USB audio class (CDD 7.7 .2/H-1-1)\n + Note: Devices declaring feature android.hardware.audio.pro MUST implement USB host mode (CDD 5.10 C-1-3) and if they omit a 4 conductor 3.5mm audio jack MUST support USB audio class (CDD 5.10 C-3-1) + </string> </resources> diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java index 140757d7303..8f0a9b01acc 100644 --- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java +++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java @@ -16,12 +16,18 @@ package com.android.cts.verifier.audio; +import android.app.AlertDialog; +import com.android.compatibility.common.util.ReportLog; +import com.android.compatibility.common.util.ResultType; +import com.android.compatibility.common.util.ResultUnit; import android.media.AudioDeviceCallback; import android.media.AudioDeviceInfo; import android.media.AudioManager; import android.os.Bundle; import android.os.Handler; import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; import android.widget.TextView; import com.android.cts.verifier.audio.peripheralprofile.PeripheralProfile; @@ -55,6 +61,68 @@ public abstract class USBAudioPeripheralActivity extends PassFailButtons.Activit private TextView mPeripheralNameTx; + private OnBtnClickListener mBtnClickListener = new OnBtnClickListener(); + + // + // Common UI Handling + // + protected void connectUSBPeripheralUI() { + findViewById(R.id.uap_tests_yes_btn).setOnClickListener(mBtnClickListener); + findViewById(R.id.uap_tests_no_btn).setOnClickListener(mBtnClickListener); + findViewById(R.id.uap_test_info_btn).setOnClickListener(mBtnClickListener); + + // Leave the default state in tact + // enableTestUI(false); + } + + private void showUAPInfoDialog() { + new AlertDialog.Builder(this) + .setTitle(R.string.uap_mic_dlg_caption) + .setMessage(R.string.uap_mic_dlg_text) + .setPositiveButton(R.string.audio_general_ok, null) + .show(); + } + + private class OnBtnClickListener implements OnClickListener { + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.uap_tests_yes_btn: + recordUSBAudioStatus(true); + enableTestUI(true); + // disable test button so that they will now run the test(s) + getPassButton().setEnabled(false); + break; + + case R.id.uap_tests_no_btn: + recordUSBAudioStatus(false); + enableTestUI(false); + // Allow the user to "pass" the test. + getPassButton().setEnabled(true); + break; + + case R.id.uap_test_info_btn: + showUAPInfoDialog(); + break; + } + } + } + + private void recordUSBAudioStatus(boolean has) { + getReportLog().addValue( + "User reported USB Host Audio Support: ", + has ? 1.0 : 0, + ResultType.NEUTRAL, + ResultUnit.NONE); + } + + // + // Overrides + // + void enableTestUI(boolean enable) { + + } + public USBAudioPeripheralActivity(boolean mandatedRequired) { super(); diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java index 5029160619d..23ed91a7cfe 100644 --- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java +++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java @@ -47,6 +47,8 @@ public class USBAudioPeripheralAttributesActivity extends USBAudioPeripheralActi setPassFailButtonClickListeners(); setInfoResources(R.string.usbaudio_attribs_test, R.string.usbaudio_attribs_info, -1); + + connectUSBPeripheralUI(); } // diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java index d5031df165d..b6aa933fd4b 100644 --- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java +++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java @@ -83,6 +83,8 @@ public class USBAudioPeripheralButtonsActivity extends USBAudioPeripheralActivit setInfoResources(R.string.usbaudio_buttons_test, R.string.usbaudio_buttons_info, -1); showDisableAssistantDialog(); + + connectUSBPeripheralUI(); } private void showButtonsState() { diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java index de9016ad8ab..4ae5ec34588 100644 --- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java +++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java @@ -50,11 +50,17 @@ public class USBAudioPeripheralPlayActivity extends USBAudioPeripheralPlayerActi setPassFailButtonClickListeners(); setInfoResources(R.string.usbaudio_play_test, R.string.usbaudio_play_info, -1); + + connectUSBPeripheralUI(); } // // USBAudioPeripheralActivity // Headset not publicly available, violates CTS Verifier additional equipment guidelines. + void enableTestUI(boolean enable) { + mPlayBtn.setEnabled(enable); + } + public void updateConnectStatus() { mPlayBtn.setEnabled(mIsPeripheralAttached); getPassButton().setEnabled(mIsPeripheralAttached); diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java index 22a26789953..a2ecf9ee222 100644 --- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java +++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java @@ -134,11 +134,18 @@ public class USBAudioPeripheralRecordActivity extends USBAudioPeripheralPlayerAc setPassFailButtonClickListeners(); setInfoResources(R.string.usbaudio_record_test, R.string.usbaudio_record_info, -1); + + connectUSBPeripheralUI(); } // // USBAudioPeripheralActivity // + void enableTestUI(boolean enable) { + mRecordBtn.setEnabled(enable); + mRecordLoopbackBtn.setEnabled(enable); + } + public void updateConnectStatus() { mRecordBtn.setEnabled(mIsPeripheralAttached); mRecordLoopbackBtn.setEnabled(mIsPeripheralAttached); 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 0aa484172f3..41a7c465f39 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;
@@ -82,9 +77,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);
@@ -142,9 +135,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;
}
@@ -159,44 +150,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();
@@ -229,21 +200,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);
}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/StreamingVideoActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/StreamingVideoActivity.java index a19024a62e3..970f7c82e25 100644 --- a/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/StreamingVideoActivity.java +++ b/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/StreamingVideoActivity.java @@ -183,6 +183,8 @@ public class StreamingVideoActivity extends PassFailButtons.TestListActivity { private TestListAdapter getStreamAdapter() { ArrayTestListAdapter adapter = new ArrayTestListAdapter(this); + // TODO(b/161675976): Re-enable RTSP tests once they can be served reliably. + /* adapter.add(TestListItem.newCategory("RTSP")); addRtspStreamToTest( adapter, "H263 Video, AMR Audio", "rtsp_h263_amr", 13, ITAG_13_SIGNATURE); @@ -190,6 +192,7 @@ public class StreamingVideoActivity extends PassFailButtons.TestListActivity { adapter, "MPEG4 SP Video, AAC Audio", "rtsp_mpeg4_aac", 17, ITAG_17_SIGNATURE); addRtspStreamToTest( adapter, "H264 Base Video, AAC Audio", "rtsp_h264_aac", 18, ITAG_18_SIGNATURE); + */ adapter.add(TestListItem.newCategory("HTTP Progressive")); for (Stream stream : HTTP_STREAMS) { diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/CrashReporter.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/CrashReporter.java index c8a7dfe5af6..58133bbce55 100644 --- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/CrashReporter.java +++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/CrashReporter.java @@ -47,6 +47,9 @@ public class CrashReporter implements ITargetCleaner { /** Uploads the current buffer of Crashes to the phone under the current test name. */ private static void upload(ITestDevice device, String testname, List<Crash> crashes) { + if (crashes == null) { + crashes = new ArrayList<>(); + } try { if (testname == null) { CLog.logAndDisplay(LogLevel.ERROR, "Attempted upload with no test name"); @@ -79,6 +82,13 @@ public class CrashReporter implements ITargetCleaner { @Override public void setUp(ITestDevice device, IBuildInfo buildInfo) { try { + device.executeShellCommand("logcat -c"); + } catch (DeviceNotAvailableException e) { + CLog.logAndDisplay(LogLevel.ERROR, "CrashReporterThread failed to clear logcat"); + CLog.logAndDisplay(LogLevel.ERROR, e.getMessage()); + } + + try { device.executeShellCommand("rm -rf " + CrashUtils.DEVICE_PATH); device.executeShellCommand("mkdir " + CrashUtils.DEVICE_PATH); } catch (DeviceNotAvailableException e) { @@ -88,14 +98,23 @@ public class CrashReporter implements ITargetCleaner { CLog.logAndDisplay(LogLevel.ERROR, e.getMessage()); return; } + + CrashReporterReceiver receiver = new CrashReporterReceiver(device); mBackgroundThread = new BackgroundDeviceAction( - "logcat", - "CrashReporter logcat thread", - device, - new CrashReporterReceiver(device), - 0); + "logcat", "CrashReporter logcat thread", device, receiver, 0); mBackgroundThread.start(); + + try { + // If the test starts before the reporter receiver can read the test start message then + // the crash could only be read halfway. We wait until the receiver starts getting + // messages. + synchronized (receiver) { + receiver.wait(10_000); // wait for 10 seconds max + } + } catch (InterruptedException e) { + // continue as normal + } } /** {@inheritDoc} */ @@ -133,6 +152,11 @@ public class CrashReporter implements ITargetCleaner { mCrashes = new ArrayList<Crash>(); mLogcatChunk.setLength(0); } else if (CrashUtils.sEndofCrashPattern.matcher(line).find()) { + if (mCrashes == null) { + // In case the crash happens before any test is started, it's not related to the + // current test and shouldn't be reported. + return; + } mCrashes = CrashUtils.getAllCrashes(mLogcatChunk.toString()); mLogcatChunk.setLength(0); } else if (CrashUtils.sUploadRequestPattern.matcher(line).find()) { @@ -142,6 +166,7 @@ public class CrashReporter implements ITargetCleaner { @Override public void processNewLines(String[] lines) { + this.notifyAll(); // alert the main thread that we are active. if (!isCancelled()) { for (String line : lines) { processLogLine(line); diff --git a/common/util/src/com/android/compatibility/common/util/CrashUtils.java b/common/util/src/com/android/compatibility/common/util/CrashUtils.java index 93d2d2dd8bb..60678e87588 100644 --- a/common/util/src/com/android/compatibility/common/util/CrashUtils.java +++ b/common/util/src/com/android/compatibility/common/util/CrashUtils.java @@ -17,6 +17,10 @@ package com.android.compatibility.common.util; import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.ArrayList; @@ -59,12 +63,9 @@ public class CrashUtils { private static Pattern sAbortMessageCheckPattern = Pattern.compile("(?i)Abort message.*?CHECK_"); - /** - * returns true if the signal is a segmentation fault or bus error. - */ - public static boolean isSecuritySignal(Crash c) { - return c.signal.toLowerCase().matches("sig(segv|bus)"); - } + public static final String SIGSEGV = "SIGSEGV"; + public static final String SIGBUS = "SIGBUS"; + public static final String SIGABRT = "SIGABRT"; /** * returns the filename of the process. @@ -78,31 +79,27 @@ public class CrashUtils { * Determines if the given input has a {@link com.android.compatibility.common.util.Crash} that * should fail an sts test * - * @param processPatterns list of patterns that match applicable process names - * @param checkMinAddr if the minimum fault address should be respected * @param crashes list of crashes to check + * @param config crash detection configuration object * @return if a crash is serious enough to fail an sts test */ - public static boolean securityCrashDetected( - List<Crash> crashes, boolean checkMinAddr, Pattern... processPatterns) { - return !matchSecurityCrashes(crashes, checkMinAddr, processPatterns).isEmpty(); + public static boolean securityCrashDetected(List<Crash> crashes, Config config) { + return matchSecurityCrashes(crashes, config).size() > 0; } /** * Determines which given inputs have a {@link com.android.compatibility.common.util.Crash} that * should fail an sts test * - * @param processPatterns list of patterns that match applicable process names - * @param checkMinAddr if the minimum fault address should be respected * @param crashes list of crashes to check + * @param config crash detection configuration object * @return the list of crashes serious enough to fail an sts test */ - public static List<Crash> matchSecurityCrashes( - List<Crash> crashes, boolean checkMinAddr, Pattern... processPatterns) { + public static List<Crash> matchSecurityCrashes(List<Crash> crashes, Config config) { return crashes.stream() - .filter(c -> matchesAny(getProcessFileName(c), processPatterns)) - .filter(c -> isSecuritySignal(c)) - .filter(c -> !checkMinAddr + .filter(c -> matchesAny(getProcessFileName(c), config.getProcessPatterns())) + .filter(c -> config.signals.contains(c.signal)) + .filter(c -> !config.checkMinAddress || c.faultAddress == null || c.faultAddress.compareTo(MIN_CRASH_ADDR) >= 0) .collect(Collectors.toList()); } @@ -110,7 +107,7 @@ public class CrashUtils { /** * returns true if the input matches any of the patterns. */ - private static boolean matchesAny(String input, Pattern... patterns) { + private static boolean matchesAny(String input, Collection<Pattern> patterns) { for (Pattern p : patterns) { if (p.matcher(input).matches()) { return true; @@ -166,4 +163,53 @@ public class CrashUtils { return crashes; } + + public static class Config { + private boolean checkMinAddress = true; + private BigInteger minCrashAddress = MIN_CRASH_ADDR; + private List<String> signals = Arrays.asList(SIGSEGV, SIGBUS); + private List<Pattern> processPatterns = Collections.emptyList(); + + public Config setMinAddress(BigInteger minCrashAddress) { + this.minCrashAddress = minCrashAddress; + return this; + } + + public Config checkMinAddress(boolean checkMinAddress) { + this.checkMinAddress = checkMinAddress; + return this; + } + + public Config setSignals(String... signals) { + this.signals = Arrays.asList(signals); + return this; + } + + public Config appendSignals(String... signals) { + Collections.addAll(this.signals, signals); + return this; + } + + public Config setProcessPatterns(String... processPatternStrings) { + Pattern[] processPatterns = new Pattern[processPatternStrings.length]; + for (int i = 0; i < processPatternStrings.length; i++) { + processPatterns[i] = Pattern.compile(processPatternStrings[i]); + } + return setProcessPatterns(processPatterns); + } + + public Config setProcessPatterns(Pattern... processPatterns) { + this.processPatterns = Arrays.asList(processPatterns); + return this; + } + + public List<Pattern> getProcessPatterns() { + return Collections.unmodifiableList(processPatterns); + } + + public Config appendProcessPatterns(Pattern... processPatterns) { + Collections.addAll(this.processPatterns, processPatterns); + return this; + } + } } diff --git a/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java b/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java index 6a2ab6eb185..0f6ca1ec78a 100644 --- a/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java +++ b/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java @@ -86,43 +86,52 @@ public class CrashUtilsTest extends TestCase { @Test public void testValidCrash() throws Exception { - assertTrue(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("synthetic_process_0"))); + assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("synthetic_process_0")))); } @Test public void testMissingName() throws Exception { - assertFalse(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile(""))); + assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("")))); } @Test public void testSIGABRT() throws Exception { - assertFalse(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("installd"))); + assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("installd")))); } @Test public void testFaultAddressBelowMin() throws Exception { - assertFalse(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("synthetic_process_1"))); + assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("synthetic_process_1")))); } @Test public void testIgnoreMinAddressCheck() throws Exception { - assertTrue(CrashUtils.securityCrashDetected(mCrashes, false, - Pattern.compile("synthetic_process_1"))); + assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(false) + .setProcessPatterns(Pattern.compile("synthetic_process_1")))); } @Test public void testBadAbortMessage() throws Exception { - assertFalse(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("generic"))); + assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("generic")))); } @Test public void testGoodAndBadCrashes() throws Exception { - assertTrue(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("synthetic_process_0"), Pattern.compile("generic"))); + assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns( + Pattern.compile("synthetic_process_0"), + Pattern.compile("generic")))); } } diff --git a/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java b/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java index 37744fa618f..6f65faf4e05 100644 --- a/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java +++ b/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java @@ -172,6 +172,9 @@ public class EncryptionAppTest extends InstrumentationTestCase { mDevice.pressMenu(); mDevice.waitForIdle(); enterTestPin(); + mDevice.waitForIdle(); + mDevice.pressHome(); + mDevice.waitForIdle(); } public void assertLocked() throws Exception { diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/ModifyInstallerPackageTest.java b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/ModifyInstallerPackageTest.java index 989e24b1ba6..a4c66ebb07c 100644 --- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/ModifyInstallerPackageTest.java +++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/ModifyInstallerPackageTest.java @@ -113,21 +113,6 @@ public class ModifyInstallerPackageTest extends AndroidTestCase { } /** - * Test that we can set the installer package name. - */ - public void testSetInstallPackage() { - // Pre-condition. - assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE)); - - getPackageManager().setInstallerPackageName(OTHER_PACKAGE, MY_PACKAGE); - assertEquals(MY_PACKAGE, getPackageManager().getInstallerPackageName(OTHER_PACKAGE)); - - // Clean up. - getPackageManager().setInstallerPackageName(OTHER_PACKAGE, null); - assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE)); - } - - /** * Test that we fail if trying to set an installer package with an unknown * target package name. */ @@ -171,42 +156,4 @@ public class ModifyInstallerPackageTest extends AndroidTestCase { assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE)); } - - /** - * Test that we fail if trying to set an installer package that is not - * signed with the same cert as the currently set installer. - */ - public void testSetInstallPackageConflictingInstaller() { - // Pre-condition. - assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE)); - - // Have the other package set the installer, under its cert. - Intent intent = new Intent(); - intent.setComponent(SET_INSTALLER_PACKAGE_COMP); - intent.putExtra("target", OTHER_PACKAGE); - intent.putExtra("installer", OTHER_PACKAGE); - SetInstallerPackageReceiver receiver = new SetInstallerPackageReceiver(); - getContext().sendOrderedBroadcast(intent, null, receiver, null, 0, null, null); - receiver.assertSuccess("Failure initializing with other installer"); - - assertEquals(OTHER_PACKAGE, getPackageManager().getInstallerPackageName(OTHER_PACKAGE)); - - try { - getPackageManager().setInstallerPackageName(OTHER_PACKAGE, MY_PACKAGE); - fail("setInstallerPackageName did not throw SecurityException"); - } catch (SecurityException e) { - // That's what we want! - } - - assertEquals(OTHER_PACKAGE, getPackageManager().getInstallerPackageName(OTHER_PACKAGE)); - - // Now clear the installer - intent.putExtra("target", OTHER_PACKAGE); - intent.putExtra("installer", (String)null); - receiver = new SetInstallerPackageReceiver(); - getContext().sendOrderedBroadcast(intent, null, receiver, null, 0, null, null); - receiver.assertSuccess("Failure clearing other installer"); - - assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE)); - } } diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceOwnerTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceOwnerTest.java index 827db714c81..5be8c27b96d 100644 --- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceOwnerTest.java +++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceOwnerTest.java @@ -424,7 +424,8 @@ public class DeviceOwnerTest extends BaseDevicePolicyTest { if (!mHasFeature) { return; } - executeDeviceOwnerTest("SystemUpdatePolicyTest"); + // Disabled due to 145932189 + // executeDeviceOwnerTest("SystemUpdatePolicyTest"); } public void testWifiConfigLockdown() throws Exception { diff --git a/tests/tests/net/jni/NativeMultinetworkJni.c b/tests/tests/net/jni/NativeMultinetworkJni.c index c2dff8dbefa..8d721e0e796 100644 --- a/tests/tests/net/jni/NativeMultinetworkJni.c +++ b/tests/tests/net/jni/NativeMultinetworkJni.c @@ -179,20 +179,16 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)); // For reference see: - // https://tools.ietf.org/html/draft-tsvwg-quic-protocol#section-6.1 + // https://datatracker.ietf.org/doc/html/draft-ietf-quic-invariants uint8_t quic_packet[1200] = { - 0x0d, // public flags: - // - version present (0x01), - // - 64bit connection ID (0x0c), - // - 1 byte packet number (0x00) + 0xc0, // long header + 0xaa, 0xda, 0xca, 0xca, // reserved-space version number + 0x08, // destination connection ID length 0, 0, 0, 0, 0, 0, 0, 0, // 64bit connection ID - 0xaa, 0xda, 0xca, 0xaa, // reserved-space version number - 1, // 1 byte packet number - 0x00, // private flags - 0x07, // PING frame (cuz why not) + 0x00, // source connection ID length }; - arc4random_buf(quic_packet + 1, 8); // random connection ID + arc4random_buf(quic_packet + 6, 8); // random connection ID uint8_t response[1500]; ssize_t sent, rcvd; @@ -217,7 +213,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( i + 1, MAX_RETRIES, rcvd, errnum); } } - if (rcvd < 9) { + if (rcvd < 15) { ALOGD("QUIC UDP %s: sent=%zd but rcvd=%zd, errno=%d", kPort, sent, rcvd, errnum); if (rcvd <= 0) { ALOGD("Does this network block UDP port %s?", kPort); @@ -226,7 +222,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( return -EPROTO; } - int conn_id_cmp = memcmp(quic_packet + 1, response + 1, 8); + int conn_id_cmp = memcmp(quic_packet + 6, response + 7, 8); if (conn_id_cmp != 0) { ALOGD("sent and received connection IDs do not match"); close(fd); diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java index 44b49c0274d..6dd6fc0302c 100644 --- a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java +++ b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java @@ -32,6 +32,7 @@ import android.net.wifi.WifiManager.WifiLock; import android.net.wifi.hotspot2.PasspointConfiguration; import android.net.wifi.hotspot2.pps.Credential; import android.net.wifi.hotspot2.pps.HomeSp; +import android.os.Build; import android.os.SystemClock; import android.provider.Settings; import android.test.AndroidTestCase; @@ -43,6 +44,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.security.MessageDigest; import java.security.cert.X509Certificate; +import java.time.LocalDate; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -125,6 +127,14 @@ public class WifiManagerTest extends AndroidTestCase { } }; + private static final LocalDate SECURITY_PATCH_DATE_2020_12 = LocalDate.of(2020, 12, 1); + + private static boolean doesDeviceHave2020_12SecurityPatch() { + LocalDate deviceSecurityPatchDate = LocalDate.parse(Build.VERSION.SECURITY_PATCH); + // LocalDate#isBefore() is exclusive, so use workaround: !(a < b) <=> (b <= a) + return !deviceSecurityPatchDate.isBefore(SECURITY_PATCH_DATE_2020_12); + } + @Override protected void setUp() throws Exception { super.setUp(); @@ -411,12 +421,36 @@ public class WifiManagerTest extends AndroidTestCase { assertFalse(existSSID(SSID1)); assertTrue(existSSID(SSID2)); + // Need an effectively-final holder because we need to modify inner Intent in callback. + class IntentHolder { + Intent intent; + } + IntentHolder intentHolder = new IntentHolder(); + mContext.registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + Log.i(TAG, "Received CONFIGURED_NETWORKS_CHANGED_ACTION broadcast: " + intent); + intentHolder.intent = intent; + } + }, new IntentFilter(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION)); + // Remove a WifiConfig assertTrue(mWifiManager.removeNetwork(netId)); assertFalse(mWifiManager.removeNetwork(notExist)); assertFalse(existSSID(SSID1)); assertFalse(existSSID(SSID2)); + if (doesDeviceHave2020_12SecurityPatch()) { + // wait 10 seconds to ensure that broadcast wasn't received + Thread.sleep(DURATION); + Intent intent = intentHolder.intent; + // Broadcast shouldn't be received because although CtsNetTestCases has + // ACCESS_WIFI_STATE permission, it doesn't have ACCESS_FINE_LOCATION permission. + // Receivers need both permissions to get the broadcast. + assertNull("Unexpected received CONFIGURED_NETWORKS_CHANGED_ACTION broadcast!", + intent); + } + assertTrue(mWifiManager.saveConfiguration()); } finally { reEnableNetworks(enabledSsids, mWifiManager.getConfiguredNetworks()); diff --git a/tests/tests/os/src/android/os/cts/LocaleListTest.java b/tests/tests/os/src/android/os/cts/LocaleListTest.java index bc30e5c6f86..93c81f42d71 100644 --- a/tests/tests/os/src/android/os/cts/LocaleListTest.java +++ b/tests/tests/os/src/android/os/cts/LocaleListTest.java @@ -88,17 +88,6 @@ public class LocaleListTest extends AndroidTestCase { } } - public void testRepeatedArguments() { - final Locale[] la = {Locale.US, Locale.US}; - LocaleList ll = null; - try { - ll = new LocaleList(la); - fail("Initializing a LocaleList with an array containing duplicates should throw."); - } catch (Throwable e) { - assertEquals(IllegalArgumentException.class, e.getClass()); - } - } - public void testIndexOf() { final LocaleList empty = new LocaleList(); assertEquals(-1, empty.indexOf(Locale.US)); diff --git a/tests/tests/permission2/res/raw/android_manifest.xml b/tests/tests/permission2/res/raw/android_manifest.xml index 6050776ba08..91c155027fe 100644 --- a/tests/tests/permission2/res/raw/android_manifest.xml +++ b/tests/tests/permission2/res/raw/android_manifest.xml @@ -2724,6 +2724,11 @@ <permission android:name="android.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS" android:protectionLevel="signature|privileged" /> + <!-- Allows an application to manage the companion devices. + @hide --> + <permission android:name="android.permission.MANAGE_COMPANION_DEVICES" + android:protectionLevel="signature" /> + <!-- @SystemApi Allows an application to use SurfaceFlinger's low level features. <p>Not for use by third-party applications. @hide diff --git a/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java b/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java index 19c4b024853..94931f9af85 100644 --- a/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java +++ b/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java @@ -47,6 +47,10 @@ public class PermissionPolicyTest extends AndroidTestCase { private static final String HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PERMISSION = "android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"; + private static final Date MANAGE_COMPANION_DEVICES_PATCH_DATE = parseDate("2020-07-01"); + private static final String MANAGE_COMPANION_DEVICES_PERMISSION + = "android.permission.MANAGE_COMPANION_DEVICES"; + private static final String LOG_TAG = "PermissionProtectionTest"; private static final String PLATFORM_PACKAGE_NAME = "android"; @@ -79,6 +83,11 @@ public class PermissionPolicyTest extends AndroidTestCase { for (PermissionInfo expectedPermission : loadExpectedPermissions()) { String expectedPermissionName = expectedPermission.name; if (shouldSkipPermission(expectedPermissionName)) { + // This permission doesn't need to exist yet, but will exist in + // a future SPL. It is acceptable to declare the permission + // even in an earlier SPL, so we remove it here so it doesn't + // trigger a failure after the loop. + declaredPermissionsMap.remove(expectedPermissionName); continue; } @@ -246,8 +255,13 @@ public class PermissionPolicyTest extends AndroidTestCase { } private boolean shouldSkipPermission(String permissionName) { - return parseDate(SECURITY_PATCH).before(HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PATCH_DATE) && - HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PERMISSION.equals(permissionName); - + switch (permissionName) { + case HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PERMISSION: + return parseDate(SECURITY_PATCH).before(HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PATCH_DATE); + case MANAGE_COMPANION_DEVICES_PERMISSION: + return parseDate(SECURITY_PATCH).before(MANAGE_COMPANION_DEVICES_PATCH_DATE); + default: + return false; + } } } diff --git a/tests/tests/security/src/android/security/cts/StagefrightTest.java b/tests/tests/security/src/android/security/cts/StagefrightTest.java index d76b97c88d3..db020d4aa52 100644 --- a/tests/tests/security/src/android/security/cts/StagefrightTest.java +++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java @@ -122,7 +122,7 @@ public class StagefrightTest extends InstrumentationTestCase { } public void testStagefright_bug_35763994() throws Exception { - doStagefrightTest(R.raw.bug_35763994); + doStagefrightTest(R.raw.bug_35763994, new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest @@ -132,7 +132,7 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_cve_2016_2507() throws Exception { - doStagefrightTest(R.raw.cve_2016_2507); + doStagefrightTest(R.raw.cve_2016_2507, new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest @@ -222,13 +222,14 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_cve_2016_2429_b_27211885() throws Exception { - doStagefrightTest(R.raw.cve_2016_2429_b_27211885); + doStagefrightTest(R.raw.cve_2016_2429_b_27211885, + new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest public void testStagefright_bug_34031018() throws Exception { - doStagefrightTest(R.raw.bug_34031018_32bit); - doStagefrightTest(R.raw.bug_34031018_64bit); + doStagefrightTest(R.raw.bug_34031018_32bit, new CrashUtils.Config().checkMinAddress(false)); + doStagefrightTest(R.raw.bug_34031018_64bit, new CrashUtils.Config().checkMinAddress(false)); } /*********************************************************** @@ -248,7 +249,8 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_cve_2017_0852_b_62815506() throws Exception { - doStagefrightTest(R.raw.cve_2017_0852_b_62815506); + doStagefrightTest(R.raw.cve_2017_0852_b_62815506, + new CrashUtils.Config().checkMinAddress(false)); } /*********************************************************** @@ -288,12 +290,12 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_bug_33818508() throws Exception { - doStagefrightTest(R.raw.bug_33818508); + doStagefrightTest(R.raw.bug_33818508, new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest public void testStagefright_bug_32873375() throws Exception { - doStagefrightTest(R.raw.bug_32873375); + doStagefrightTest(R.raw.bug_32873375, new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest @@ -318,7 +320,7 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_bug_32322258() throws Exception { - doStagefrightTest(R.raw.bug_32322258); + doStagefrightTest(R.raw.bug_32322258, new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest @@ -333,7 +335,8 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_cve_2015_3862_b_22954006() throws Exception { - doStagefrightTest(R.raw.cve_2015_3862_b_22954006); + doStagefrightTest(R.raw.cve_2015_3862_b_22954006, + new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest @@ -387,12 +390,13 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_cve_2016_3755() throws Exception { - doStagefrightTest(R.raw.cve_2016_3755); + doStagefrightTest(R.raw.cve_2016_3755, new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest public void testStagefright_cve_2016_3878_b_29493002() throws Exception { - doStagefrightTest(R.raw.cve_2016_3878_b_29493002); + doStagefrightTest(R.raw.cve_2016_3878_b_29493002, + new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest @@ -402,11 +406,11 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_bug_27855419_CVE_2016_2463() throws Exception { - doStagefrightTest(R.raw.bug_27855419); + doStagefrightTest(R.raw.bug_27855419, new CrashUtils.Config().checkMinAddress(false)); } public void testStagefright_bug_19779574() throws Exception { - doStagefrightTest(R.raw.bug_19779574); + doStagefrightTest(R.raw.bug_19779574, new CrashUtils.Config().checkMinAddress(false)); } /*********************************************************** @@ -416,7 +420,7 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testStagefright_bug_35467107() throws Exception { - doStagefrightTest(R.raw.bug_35467107); + doStagefrightTest(R.raw.bug_35467107, new CrashUtils.Config().checkMinAddress(false)); } /*********************************************************** @@ -435,27 +439,37 @@ public class StagefrightTest extends InstrumentationTestCase { } private void doStagefrightTest(final int rid) throws Exception { - doStagefrightTestMediaPlayer(rid); - doStagefrightTestMediaCodec(rid); - doStagefrightTestMediaMetadataRetriever(rid); + doStagefrightTest(rid, null); + } + + private void doStagefrightTest(final int rid, CrashUtils.Config config) throws Exception { + doStagefrightTestMediaPlayer(rid, config); + doStagefrightTestMediaCodec(rid, config); + doStagefrightTestMediaMetadataRetriever(rid, config); Context context = getInstrumentation().getContext(); Resources resources = context.getResources(); CtsTestServer server = new CtsTestServer(context); String rname = resources.getResourceEntryName(rid); String url = server.getAssetUrl("raw/" + rname); - doStagefrightTestMediaPlayer(url); - doStagefrightTestMediaCodec(url); - doStagefrightTestMediaMetadataRetriever(url); + + doStagefrightTestMediaPlayer(url, config); + doStagefrightTestMediaCodec(url, config); + doStagefrightTestMediaMetadataRetriever(url, config); server.shutdown(); } private void doStagefrightTest(final int rid, int timeout) throws Exception { + doStagefrightTest(rid, null, timeout); + } + + private void doStagefrightTest( + final int rid, CrashUtils.Config config, int timeout) throws Exception { runWithTimeout(new Runnable() { @Override public void run() { try { - doStagefrightTest(rid); + doStagefrightTest(rid, config); } catch (Exception e) { fail(e.toString()); } @@ -464,7 +478,12 @@ public class StagefrightTest extends InstrumentationTestCase { } private void doStagefrightTestANR(final int rid) throws Exception { - doStagefrightTestMediaPlayerANR(rid, null); + doStagefrightTestANR(rid, null); + } + + private void doStagefrightTestANR( + final int rid, CrashUtils.Config config) throws Exception { + doStagefrightTestMediaPlayerANR(rid, null, config); } private Surface getDummySurface() { @@ -518,14 +537,18 @@ public class StagefrightTest extends InstrumentationTestCase { MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener { + CrashUtils.Config config; + private final Pattern[] validProcessPatterns = { Pattern.compile("adsprpcd"), Pattern.compile("android\\.hardware\\.cas@\\d+?\\.\\d+?-service"), Pattern.compile("android\\.hardware\\.drm@\\d+?\\.\\d+?-service"), Pattern.compile("android\\.hardware\\.drm@\\d+?\\.\\d+?-service\\.clearkey"), Pattern.compile("android\\.hardware\\.drm@\\d+?\\.\\d+?-service\\.widevine"), + Pattern.compile("omx@\\d+?\\.\\d+?-service"), // name:omx@1.0-service Pattern.compile("android\\.process\\.media"), Pattern.compile("mediadrmserver"), + Pattern.compile("mediaextractor"), Pattern.compile("media\\.extractor"), Pattern.compile("media\\.metrics"), Pattern.compile("mediaserver"), @@ -537,6 +560,19 @@ public class StagefrightTest extends InstrumentationTestCase { Pattern.compile("vendor.*"), }; + MediaPlayerCrashListener() { + this(null); + } + + MediaPlayerCrashListener(CrashUtils.Config config) { + if (config == null) { + config = new CrashUtils.Config(); + } + // if a different process is needed for a test, it should be added to the main list. + config.setProcessPatterns(validProcessPatterns); + this.config = config; + } + @Override public boolean onError(MediaPlayer mp, int newWhat, int extra) { Log.i(TAG, "error: " + newWhat + "/" + extra); @@ -582,7 +618,7 @@ public class StagefrightTest extends InstrumentationTestCase { if (crashes == null) { Log.e(TAG, "Crash results not found for test " + getName()); return what; - } else if (CrashUtils.securityCrashDetected(crashes, true, validProcessPatterns)) { + } else if (CrashUtils.securityCrashDetected(crashes, config)) { return what; } else { Log.i(TAG, "Crash ignored due to no security crash found for test " + @@ -630,11 +666,21 @@ public class StagefrightTest extends InstrumentationTestCase { } private void doStagefrightTestMediaPlayer(final int rid) throws Exception { - doStagefrightTestMediaPlayer(rid, null); + doStagefrightTestMediaPlayer(rid, null, null); + } + + private void doStagefrightTestMediaPlayer( + final int rid, CrashUtils.Config config) throws Exception { + doStagefrightTestMediaPlayer(rid, null, config); } private void doStagefrightTestMediaPlayer(final String url) throws Exception { - doStagefrightTestMediaPlayer(-1, url); + doStagefrightTestMediaPlayer(url, null); + } + + private void doStagefrightTestMediaPlayer( + final String url, CrashUtils.Config config) throws Exception { + doStagefrightTestMediaPlayer(-1, url, config); } private void closeQuietly(AutoCloseable closeable) { @@ -649,12 +695,17 @@ public class StagefrightTest extends InstrumentationTestCase { } private void doStagefrightTestMediaPlayer(final int rid, final String uri) throws Exception { + doStagefrightTestMediaPlayer(rid, uri, null); + } + + private void doStagefrightTestMediaPlayer(final int rid, final String uri, + CrashUtils.Config config) throws Exception { String name = uri != null ? uri : getInstrumentation().getContext().getResources().getResourceEntryName(rid); Log.i(TAG, "start mediaplayer test for: " + name); - final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(); + final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config); LooperThread t = new LooperThread(new Runnable() { @Override @@ -699,16 +750,31 @@ public class StagefrightTest extends InstrumentationTestCase { } private void doStagefrightTestMediaCodec(final int rid) throws Exception { - doStagefrightTestMediaCodec(rid, null); + doStagefrightTestMediaCodec(rid, null, null); + } + + private void doStagefrightTestMediaCodec( + final int rid, CrashUtils.Config config) throws Exception { + doStagefrightTestMediaCodec(rid, null, config); } private void doStagefrightTestMediaCodec(final String url) throws Exception { - doStagefrightTestMediaCodec(-1, url); + doStagefrightTestMediaCodec(url, null); + } + + private void doStagefrightTestMediaCodec( + final String url, CrashUtils.Config config) throws Exception { + doStagefrightTestMediaCodec(-1, url, config); } private void doStagefrightTestMediaCodec(final int rid, final String url) throws Exception { + doStagefrightTestMediaCodec(rid, url, null); + } - final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(); + private void doStagefrightTestMediaCodec( + final int rid, final String url, CrashUtils.Config config) throws Exception { + + final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config); LooperThread thr = new LooperThread(new Runnable() { @Override @@ -853,7 +919,11 @@ public class StagefrightTest extends InstrumentationTestCase { codec.release(); } } - ex.unselectTrack(t); + try { + ex.unselectTrack(t); + } catch (IllegalArgumentException e) { + // since we're just cleaning up, we don't care if it fails + } } ex.release(); String cve = rname.replace("_", "-").toUpperCase(); @@ -864,17 +934,31 @@ public class StagefrightTest extends InstrumentationTestCase { } private void doStagefrightTestMediaMetadataRetriever(final int rid) throws Exception { - doStagefrightTestMediaMetadataRetriever(rid, null); + doStagefrightTestMediaMetadataRetriever(rid, null, null); + } + private void doStagefrightTestMediaMetadataRetriever( + final int rid, CrashUtils.Config config) throws Exception { + doStagefrightTestMediaMetadataRetriever(rid, null, config); } private void doStagefrightTestMediaMetadataRetriever(final String url) throws Exception { - doStagefrightTestMediaMetadataRetriever(-1, url); + doStagefrightTestMediaMetadataRetriever(url, null); + } + + private void doStagefrightTestMediaMetadataRetriever( + final String url, CrashUtils.Config config) throws Exception { + doStagefrightTestMediaMetadataRetriever(-1, url, config); } private void doStagefrightTestMediaMetadataRetriever( final int rid, final String url) throws Exception { + doStagefrightTestMediaMetadataRetriever(rid, url, null); + } - final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(); + private void doStagefrightTestMediaMetadataRetriever( + final int rid, final String url, CrashUtils.Config config) throws Exception { + + final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config); LooperThread thr = new LooperThread(new Runnable() { @Override @@ -942,12 +1026,13 @@ public class StagefrightTest extends InstrumentationTestCase { thr.join(); } - private void doStagefrightTestMediaPlayerANR(final int rid, final String uri) throws Exception { + private void doStagefrightTestMediaPlayerANR(final int rid, final String uri, + CrashUtils.Config config) throws Exception { String name = uri != null ? uri : getInstrumentation().getContext().getResources().getResourceEntryName(rid); Log.i(TAG, "start mediaplayerANR test for: " + name); - final MediaPlayerCrashListener mpl = new MediaPlayerCrashListener(); + final MediaPlayerCrashListener mpl = new MediaPlayerCrashListener(config); LooperThread t = new LooperThread(new Runnable() { @Override @@ -993,11 +1078,13 @@ public class StagefrightTest extends InstrumentationTestCase { } public void testBug36816007() throws Exception { - doStagefrightTestRawBlob(R.raw.bug_36816007, "video/avc", 320, 240); + doStagefrightTestRawBlob(R.raw.bug_36816007, "video/avc", 320, 240, + new CrashUtils.Config().checkMinAddress(false)); } public void testBug36895511() throws Exception { - doStagefrightTestRawBlob(R.raw.bug_36895511, "video/hevc", 320, 240); + doStagefrightTestRawBlob(R.raw.bug_36895511, "video/hevc", 320, 240, + new CrashUtils.Config().checkMinAddress(false)); } @SecurityTest @@ -1007,7 +1094,8 @@ public class StagefrightTest extends InstrumentationTestCase { @SecurityTest public void testBug_70897394() throws Exception { - doStagefrightTestRawBlob(R.raw.bug_70897394_avc, "video/avc", 320, 240); + doStagefrightTestRawBlob(R.raw.bug_70897394_avc, "video/avc", 320, 240, + new CrashUtils.Config().checkMinAddress(false)); } private void runWithTimeout(Runnable runner, int timeout) { @@ -1032,9 +1120,15 @@ public class StagefrightTest extends InstrumentationTestCase { }, 5000); } - private void doStagefrightTestRawBlob(int rid, String mime, int initWidth, int initHeight) throws Exception { + private void doStagefrightTestRawBlob( + int rid, String mime, int initWidth, int initHeight) throws Exception { + doStagefrightTestRawBlob(rid, mime, initWidth, initHeight, new CrashUtils.Config()); + } + + private void doStagefrightTestRawBlob(int rid, String mime, int initWidth, int initHeight, + CrashUtils.Config config) throws Exception { - final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(); + final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config); final Context context = getInstrumentation().getContext(); final Resources resources = context.getResources(); diff --git a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java index c8739d15e70..d47735b6a45 100644 --- a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java +++ b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java @@ -33,10 +33,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.text.DateFormat; +import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.Formatter; import java.util.GregorianCalendar; +import java.util.List; import java.util.Locale; import java.util.TimeZone; @@ -216,12 +218,25 @@ public class DateUtilsTest { fixedTime, java.text.DateFormat.SHORT, java.text.DateFormat.FULL)); final long HOUR_DURATION = 2 * 60 * 60 * 1000; - assertEquals("5:30:15 AM GMT+00:00", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION, - fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.FULL)); + // The original answer was "GMT+00:00", devices with latest CLDR patches from + // the tzdb 2020a patch have "Greenwich Mean Time". http://b/155407785 + List<String> gmtTimeFullAllowed = Arrays.asList("5:30:15 AM Greenwich Mean Time", + "5:30:15 AM GMT+00:00"); + String gmtTimeFullActual = String.valueOf(DateUtils.formatSameDayTime( + fixedTime + HOUR_DURATION, fixedTime, java.text.DateFormat.FULL, + java.text.DateFormat.FULL)); + assertTrue("Expected one of " + gmtTimeFullAllowed, + gmtTimeFullAllowed.contains(gmtTimeFullActual)); assertEquals("5:30:15 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION, fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.DEFAULT)); - assertEquals("5:30:15 AM GMT+00:00", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION, - fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.LONG)); + // The original answer was "GMT+00:00", devices with latest CLDR patches from + // the tzdb 2020a patch have "GMT". http://b/155407785 + List<String> gmtTimeLongAllowed = Arrays.asList("5:30:15 AM GMT", "5:30:15 AM GMT+00:00"); + String gmtTimeLongActual = String.valueOf(DateUtils.formatSameDayTime( + fixedTime + HOUR_DURATION, fixedTime, java.text.DateFormat.FULL, + java.text.DateFormat.LONG)); + assertTrue("Expected one of " + gmtTimeLongAllowed, + gmtTimeLongAllowed.contains(gmtTimeLongActual)); assertEquals("5:30:15 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION, fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.MEDIUM)); assertEquals("5:30 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION, diff --git a/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java b/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java index 68d944bb10f..7945c0c6b34 100644 --- a/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java +++ b/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java @@ -59,8 +59,6 @@ public class TestHtmlConstants { public static final String EXT_WEB_URL1 = "http://www.example.com/"; - public static final String LOCAL_FILESYSTEM_URL = "file:///etc/hosts"; - public static final String PARAM_ASSET_URL = "webkit/test_queryparam.html"; public static final String ANCHOR_ASSET_URL = "webkit/test_anchor.html"; public static final String IMAGE_ACCESS_URL = "webkit/test_imageaccess.html"; @@ -73,10 +71,6 @@ public class TestHtmlConstants { public static final String NON_EXISTENT_PAGE_URL = "webkit/generate_404.html"; public static final String BAD_IMAGE_PAGE_URL = "webkit/test_bad_image_url.html"; - // Must match the title of the page at - // android/frameworks/base/core/res/res/raw/loaderror.html - public static final String WEBPAGE_NOT_AVAILABLE_TITLE = "Webpage not available"; - public static final String getFileUrl(String assetName) { if (assetName.contains(":") || assetName.startsWith("/")) { throw new IllegalArgumentException(); diff --git a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java index d004565980a..d55e151bb6b 100644 --- a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java +++ b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java @@ -226,32 +226,41 @@ public class WebSettingsTest extends ActivityInstrumentationTestCase2<WebViewCts assertEquals(customUserAgent, mOnUiThread.getTitle()); } - public void testAccessAllowFileAccess() { + public void testAccessAllowFileAccess() throws Exception { if (!NullWebViewUtils.isWebViewAvailable()) { return; } - // This test is not compatible with 4.0.3 - if ("4.0.3".equals(Build.VERSION.RELEASE)) { - return; - } - assertTrue(mSettings.getAllowFileAccess()); + // prepare an HTML file in the data directory we can access to test the setting. + final String dataDirTitle = "Loaded from data dir"; + final String dataDirFile = "datadir.html"; + final String dataDirPath = mContext.getFileStreamPath(dataDirFile).getAbsolutePath(); + final String dataDirUrl = "file://" + dataDirPath; + writeFile(dataDirFile, "<html><title>" + dataDirTitle + "</title></html>"); - String fileUrl = TestHtmlConstants.getFileUrl(TestHtmlConstants.HELLO_WORLD_URL); - mOnUiThread.loadUrlAndWaitForCompletion(fileUrl); - assertEquals(TestHtmlConstants.HELLO_WORLD_TITLE, mOnUiThread.getTitle()); + assertTrue("File access should be on by default", mSettings.getAllowFileAccess()); - fileUrl = TestHtmlConstants.getFileUrl(TestHtmlConstants.BR_TAG_URL); mSettings.setAllowFileAccess(false); - assertFalse(mSettings.getAllowFileAccess()); - mOnUiThread.loadUrlAndWaitForCompletion(fileUrl); - // android_asset URLs should still be loaded when even with file access - // disabled. - assertEquals(TestHtmlConstants.BR_TAG_TITLE, mOnUiThread.getTitle()); - - // Files on the file system should not be loaded. - mOnUiThread.loadUrlAndWaitForCompletion(TestHtmlConstants.LOCAL_FILESYSTEM_URL); - assertEquals(TestHtmlConstants.WEBPAGE_NOT_AVAILABLE_TITLE, mOnUiThread.getTitle()); + assertFalse("Explicitly setting file access to false should work", + mSettings.getAllowFileAccess()); + + String assetUrl = TestHtmlConstants.getFileUrl(TestHtmlConstants.BR_TAG_URL); + mOnUiThread.loadUrlAndWaitForCompletion(assetUrl); + assertEquals( + "android_asset URLs should still be loaded when even with file access disabled", + TestHtmlConstants.BR_TAG_TITLE, mOnUiThread.getTitle()); + + mOnUiThread.loadUrlAndWaitForCompletion(dataDirUrl); + assertFalse("Files on the file system should not be loaded with file access disabled", + dataDirTitle.equals(mOnUiThread.getTitle())); + + mSettings.setAllowFileAccess(true); + assertTrue("Explicitly setting file access to true should work", + mSettings.getAllowFileAccess()); + + mOnUiThread.loadUrlAndWaitForCompletion(dataDirUrl); + assertEquals("Loading files on the file system should work with file access enabled", + dataDirTitle, mOnUiThread.getTitle()); } public void testAccessCacheMode() throws Throwable { @@ -739,17 +748,10 @@ public class WebSettingsTest extends ActivityInstrumentationTestCase2<WebViewCts Thread.sleep(1000); assertEquals("Loaded", mOnUiThread.getTitle()); - // Test that when AppCache is enabled and a valid path is provided, we - // get an AppCache callback of some kind. - mSettings.setAppCachePath(getActivity().getDir("appcache", 0).getPath()); - mOnUiThread.loadUrlAndWaitForCompletion(url); - new PollingCheck(WEBVIEW_TIMEOUT) { - @Override - protected boolean check() { - return mOnUiThread.getTitle() != null - && mOnUiThread.getTitle().endsWith("Callback"); - } - }.run(); + // We used to test that when AppCache is enabled and a valid path is + // provided, we got an AppCache callback of some kind, but AppCache is + // deprecated on the web and will be removed from Chromium in the + // future, so this test has been removed. } // Ideally, we need a test case for the enabled case. However, it seems that diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java index 92c9be4f6b9..7eb39a4dc39 100755 --- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java +++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java @@ -1876,7 +1876,7 @@ public class WebViewTest extends ActivityInstrumentationTestCase2<WebViewCtsActi final int previousScrollX = mOnUiThread.getScrollX(); final int previousScrollY = mOnUiThread.getScrollY(); - mOnUiThread.flingScroll(100, 100); + mOnUiThread.flingScroll(10000, 10000); new PollingCheck() { @Override diff --git a/tools/cts-tradefed/Android.mk b/tools/cts-tradefed/Android.mk index b782090758e..324f36efd0b 100644 --- a/tools/cts-tradefed/Android.mk +++ b/tools/cts-tradefed/Android.mk @@ -25,7 +25,7 @@ LOCAL_SUITE_BUILD_NUMBER := $(BUILD_NUMBER_FROM_FILE) LOCAL_SUITE_TARGET_ARCH := $(TARGET_ARCH) LOCAL_SUITE_NAME := CTS LOCAL_SUITE_FULLNAME := "Compatibility Test Suite" -LOCAL_SUITE_VERSION := 8.0_r22 +LOCAL_SUITE_VERSION := 8.0_r26 LOCAL_MODULE := cts-tradefed LOCAL_COMPATIBILITY_SUITE := general-tests |