Skip to content

Commit 0ab976b

Browse files
Keyi GuiGerrit Code Review
authored andcommitted
Merge "Cherry-pick b/298680756 fixes to support CTS-Verifier System." into android14-tests-dev
2 parents 111fb3c + 3f57a61 commit 0ab976b

7 files changed

Lines changed: 79 additions & 2 deletions

File tree

apps/CtsVerifier/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,10 +4516,13 @@
45164516
android:label="@string/app_name">
45174517
<intent-filter>
45184518
<action android:name="android.intent.action.MAIN" />
4519+
<action android:name="android.intent.action.SEARCH" />
45194520

45204521
<category android:name="android.intent.category.LAUNCHER" />
45214522
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
45224523
</intent-filter>
4524+
<meta-data android:name="android.app.searchable"
4525+
android:resource="@xml/searchable"/>
45234526
</activity-alias>
45244527

45254528
<!-- <activity-alias-->

apps/CtsVerifier/res/menu/test_list_menu.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@
1313
android:icon="@android:drawable/ic_menu_save"
1414
android:title="@string/export"
1515
android:showAsAction="ifRoom" />
16+
<item
17+
android:id="@+id/search_test"
18+
android:title="@string/search_title"
19+
android:actionViewClass="android.widget.SearchView"
20+
android:showAsAction="collapseActionView|ifRoom"
21+
android:imeOptions="actionSearch" />
1622
</menu>

apps/CtsVerifier/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
<string name="fail_and_next_button_text">Fail and Next</string>
3434
<string name="yes_string">Yes</string>
3535
<string name="no_string">No</string>
36+
<string name="search_label">TestListActivity</string>
37+
<string name="search_hint">Search Tests</string>
38+
<string name="search_title">Search</string>
3639

3740
<!-- Strings for CtsReportLog warning -->
3841
<string name="reportlog_warning_title">CTS-Verifier Report Log</string>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:label="@string/search_label"
4+
android:hint="@string/search_hint" >
5+
</searchable>

apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.HashMap;
4747
import java.util.HashSet;
4848
import java.util.List;
49+
import java.util.Locale;
4950
import java.util.Map;
5051
import java.util.stream.Collectors;
5152

@@ -220,7 +221,13 @@ protected List<TestListItem> getRows() {
220221
}
221222
}
222223

223-
return mDisplayModesTests.getOrDefault(sCurrentDisplayMode.toString(), new ArrayList<>());
224+
if (mTestFilter != null) {
225+
// Filter test rows dynamically when the filter is specified.
226+
return getRowsWithDisplayMode(sCurrentDisplayMode.toString());
227+
} else {
228+
return mDisplayModesTests.getOrDefault(
229+
sCurrentDisplayMode.toString(), new ArrayList<>());
230+
}
224231
}
225232

226233
/**
@@ -585,6 +592,17 @@ private boolean matchAnyExcludedUserType(String[] userTypes) {
585592
return false;
586593
}
587594

595+
/** Checks whether the title of the test matches the test filter. */
596+
private boolean macthTestFilter(String testTitle) {
597+
if (mTestFilter == null) {
598+
return true;
599+
}
600+
return testTitle != null
601+
&& testTitle
602+
.toLowerCase(Locale.getDefault())
603+
.contains(mTestFilter.toLowerCase(Locale.getDefault()));
604+
}
605+
588606
private boolean isVisibleBackgroundNonProfileUser() {
589607
if (!SdkLevel.isAtLeastU()) {
590608
Log.d(LOG_TAG, "isVisibleBagroundNonProfileUser() returning false on pre-UDC device");
@@ -637,7 +655,8 @@ && hasAllFeatures(test.requiredFeatures)
637655
&& hasAllActions(test.requiredActions)
638656
&& matchAllConfigs(mContext, test.requiredConfigs)
639657
&& matchDisplayMode(test.displayMode, mode)
640-
&& !matchAnyExcludedUserType(test.excludedUserTypes)) {
658+
&& !matchAnyExcludedUserType(test.excludedUserTypes)
659+
&& macthTestFilter(test.title)) {
641660
if (test.applicableFeatures == null || hasAnyFeature(test.applicableFeatures)) {
642661
// Add suffix in test name if the test is in the folded mode.
643662
test.testName = setTestNameSuffix(mode, test.testName);

apps/CtsVerifier/src/com/android/cts/verifier/TestListActivity.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import android.view.View;
3838
import android.view.Window;
3939
import android.widget.CompoundButton;
40+
import android.widget.SearchView;
4041
import android.widget.Switch;
4142
import android.widget.Toast;
4243

@@ -219,6 +220,28 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
219220
handleSwitchItemSelected();
220221
}
221222
});
223+
224+
SearchView searchView = (SearchView) menu.findItem(R.id.search_test).getActionView();
225+
searchView.setOnQueryTextListener(
226+
new SearchView.OnQueryTextListener() {
227+
228+
public boolean onQueryTextSubmit(String query) {
229+
Log.i(TAG, "Got submitted query: " + query);
230+
handleQueryUpdated(query);
231+
return true;
232+
}
233+
234+
public boolean onQueryTextChange(String newText) {
235+
if (newText == null || newText.isEmpty()) {
236+
Log.i(TAG, "Clear filter");
237+
handleQueryUpdated(newText);
238+
return true;
239+
} else {
240+
return false;
241+
}
242+
}
243+
});
244+
222245
return true;
223246
}
224247

@@ -268,6 +291,17 @@ private boolean handleMenuItemSelected(int id) {
268291
return true;
269292
}
270293

294+
/** Triggered when a new query is input. */
295+
private void handleQueryUpdated(String query) {
296+
if (query != null && !query.isEmpty()) {
297+
mAdapter.setTestFilter(query);
298+
} else {
299+
// Reset the filter as null to show all tests.
300+
mAdapter.setTestFilter(/* testFilter= */ null);
301+
}
302+
mAdapter.loadTestResults();
303+
}
304+
271305
/**
272306
* Sets current display mode to sharedpreferences.
273307
*

apps/CtsVerifier/src/com/android/cts/verifier/TestListAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public abstract class TestListAdapter extends BaseAdapter {
102102
*/
103103
protected Map<String, List<TestListItem>> mDisplayModesTests = new HashMap<>();
104104

105+
/** A keyword to help filter out test cases by the test name. */
106+
protected String mTestFilter;
107+
105108
/** {@link ListView} row that is either a test category header or a test. */
106109
public static class TestListItem {
107110

@@ -451,6 +454,10 @@ public void setTestResult(TestResult testResult) {
451454
.execute();
452455
}
453456

457+
void setTestFilter(String testFilter) {
458+
mTestFilter = testFilter;
459+
}
460+
454461
class RefreshTestResultsTask extends AsyncTask<Void, Void, RefreshResult> {
455462

456463
@Override

0 commit comments

Comments
 (0)