• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.audio;
18 
19 import android.util.Log;
20 import android.view.View;
21 import android.view.View.OnClickListener;
22 import android.widget.Button;
23 
24 import com.android.compatibility.common.util.ResultType;
25 import com.android.compatibility.common.util.ResultUnit;
26 import com.android.cts.verifier.CtsVerifierReportLog;
27 import com.android.cts.verifier.PassFailButtons;
28 import com.android.cts.verifier.R;
29 
30 abstract class AudioWiredDeviceBaseActivity extends PassFailButtons.Activity {
31     private static final String TAG = AudioWiredDeviceBaseActivity.class.getSimpleName();
32 
33     private OnBtnClickListener mBtnClickListener = new OnBtnClickListener();
34 
35     private Button mSupportsBtn;
36     private Button mDoesntSupportBtn;
37 
38     protected boolean mSupportsWiredPeripheral = true;
39     protected String mConnectedPeripheralName;
40 
enableTestButtons(boolean enabled)41     protected abstract void enableTestButtons(boolean enabled);
calculatePass()42     protected abstract void calculatePass();
43 
44     // ReportLog schema
45     private static final String KEY_WIRED_PORT_SUPPORTED = "wired_port_supported";
46     protected static final String KEY_SUPPORTS_PERIPHERALS = "supports_wired_peripherals";
47     protected static final String KEY_ROUTING_RECEIVED = "routing_received";
48     protected static final String KEY_CONNECTED_PERIPHERAL = "routing_connected_peripheral";
49 
AudioWiredDeviceBaseActivity()50     AudioWiredDeviceBaseActivity() {
51     }
52 
recordWiredPortFound(boolean found)53     private void recordWiredPortFound(boolean found) {
54         getReportLog().addValue(
55                 "User Reported Wired Port",
56                 found ? 1.0 : 0,
57                 ResultType.NEUTRAL,
58                 ResultUnit.NONE);
59     }
60 
setup()61     protected void setup() {
62         // The "Honor" system buttons
63         (mSupportsBtn =
64                 (Button) findViewById(R.id.audio_wired_no)).setOnClickListener(mBtnClickListener);
65         (mDoesntSupportBtn =
66                 (Button) findViewById(R.id.audio_wired_yes)).setOnClickListener(mBtnClickListener);
67     }
68 
69     private class OnBtnClickListener implements OnClickListener {
70         @Override
onClick(View v)71         public void onClick(View v) {
72             int id = v.getId();
73             if (id == R.id.audio_wired_no) {
74                 Log.i(TAG, "User denies wired device existence");
75                 mSupportsWiredPeripheral = false;
76             } else if (id == R.id.audio_wired_yes) {
77                 Log.i(TAG, "User confirms wired device existence");
78                 mSupportsWiredPeripheral = true;
79             }
80 
81             Log.i(TAG, "Wired Device Support:" + mSupportsWiredPeripheral);
82             enableTestButtons(mSupportsWiredPeripheral);
83             recordWiredPortFound(mSupportsWiredPeripheral);
84             calculatePass();
85         }
86     }
87 
88     //
89     // PassFailButtons Overrides
90     //
91     @Override
requiresReportLog()92     public boolean requiresReportLog() {
93         return true;
94     }
95 
96     @Override
getReportFileName()97     public String getReportFileName() {
98         return PassFailButtons.AUDIO_TESTS_REPORT_LOG_NAME;
99     }
100 
101     @Override
recordTestResults()102     public void recordTestResults() {
103         // Subclasses should submit after adding their data
104         CtsVerifierReportLog reportLog = getReportLog();
105         reportLog.addValue(
106                 KEY_WIRED_PORT_SUPPORTED,
107                 mSupportsWiredPeripheral ? 1 : 0,
108                 ResultType.NEUTRAL,
109                 ResultUnit.NONE);
110 
111         reportLog.addValue(
112                 KEY_CONNECTED_PERIPHERAL,
113                 mConnectedPeripheralName,
114                 ResultType.NEUTRAL,
115                 ResultUnit.NONE);
116     }
117 }
118