• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.cts.verifier;
18 
19 import android.app.AlertDialog;
20 import android.content.ContentResolver;
21 import android.content.DialogInterface;
22 import android.content.Intent;
23 import android.database.Cursor;
24 import android.os.Bundle;
25 import android.util.Log;
26 import android.view.View;
27 import android.widget.ListView;
28 
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 
34 /** Activity to list testcases of host-side tests in CtsVerifier. */
35 public class HostTestListActivity extends PassFailButtons.TestListActivity {
36 
37     private static final String TAG = "InteractiveTestsListActivity";
38 
39     static final String MODULE_TITLE = "com.android.cts.verifier.host.module_title";
40     static final String MODULE_NAME = "com.android.cts.verifier.host.module_name";
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         Intent intent = getIntent();
46         setTitle(intent.getStringExtra(MODULE_TITLE));
47         String moduleName = intent.getStringExtra(MODULE_NAME);
48 
49         // Load test list from TestResultsProvider
50         ArrayTestListAdapter testListAdapter = new ArrayTestListAdapter(this);
51         ContentResolver resolver = getContentResolver();
52         Map<String, List<TestListAdapter.TestListItem>> testsByClass = new HashMap<>();
53         try (Cursor cursor =
54                 resolver.query(
55                         TestResultsProvider.getResultContentUri(this),
56                         new String[] {
57                             TestResultsProvider.COLUMN_TEST_NAME,
58                             TestResultsProvider.COLUMN_TEST_DETAILS
59                         },
60                         TestResultsProvider.COLUMN_TEST_NAME + " LIKE ?",
61                         new String[] {moduleName + "%"},
62                         TestResultsProvider.COLUMN_TEST_NAME)) {
63             if (cursor != null && cursor.moveToFirst()) {
64                 do {
65                     String testId = cursor.getString(0);
66                     if (testId.equals(moduleName)
67                             && !cursor.isNull(1)
68                             && !cursor.getString(1).isEmpty()) {
69                         showAlertDialog(moduleName, cursor.getString(1));
70                     }
71                     // Format: Module#Class#Testcase
72                     String[] parts = testId.split(HostTestsActivity.TEST_ID_SEPARATOR, 3);
73                     if (parts.length < 3) {
74                         Log.i(TAG, "Skip invalid host-side sub-test " + testId);
75                         continue;
76                     }
77                     List<TestListAdapter.TestListItem> testcases =
78                             testsByClass.computeIfAbsent(parts[1], k -> new ArrayList<>());
79                     testcases.add(new HostTestsActivity.HostTestListItem(parts[2], testId));
80                 } while (cursor.moveToNext());
81             }
82         }
83         for (String className : testsByClass.keySet()) {
84             testListAdapter.add(TestListAdapter.TestListItem.newCategory(className));
85             testListAdapter.addAll(testsByClass.get(className));
86         }
87         setTestListAdapter(testListAdapter);
88     }
89 
90     @Override
handleItemClick(ListView l, View v, int position, long id)91     protected void handleItemClick(ListView l, View v, int position, long id) {
92         // Does nothing.
93     }
94 
showAlertDialog(String moduleName, String details)95     private void showAlertDialog(String moduleName, String details) {
96         AlertDialog.Builder builder = new AlertDialog.Builder(this);
97         builder.setTitle(moduleName);
98         builder.setMessage(
99                 String.format(
100                         "%s For the detailed reason, check results and logs on the host.",
101                         details));
102 
103         builder.setPositiveButton(
104                 "OK",
105                 new DialogInterface.OnClickListener() {
106                     @Override
107                     public void onClick(DialogInterface dialog, int which) {
108                         dialog.dismiss();
109                     }
110                 });
111 
112         AlertDialog dialog = builder.create();
113         dialog.show();
114     }
115 }
116