Home | History | Annotate | Download | only in audio
      1 /*
      2  * Copyright (C) 2017 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.content.Context;
     20 import android.media.AudioDeviceInfo;
     21 import android.os.Bundle;
     22 import android.util.Log;
     23 import android.widget.TextView;
     24 
     25 import com.android.cts.verifier.audio.peripheralprofile.ListsHelper;
     26 import com.android.cts.verifier.audio.peripheralprofile.PeripheralProfile;
     27 
     28 import com.android.cts.verifier.R;  // needed to access resource in CTSVerifier project namespace.
     29 
     30 public class USBAudioPeripheralAttributesActivity extends USBAudioPeripheralActivity {
     31     private static final String TAG = "USBAudioPeripheralAttributesActivity";
     32 
     33     private TextView mTestStatusTx;
     34 
     35     @Override
     36     protected void onCreate(Bundle savedInstanceState) {
     37         super.onCreate(savedInstanceState);
     38         setContentView(R.layout.uap_attribs_panel);
     39 
     40         connectPeripheralStatusWidgets();
     41 
     42         mTestStatusTx = (TextView)findViewById(R.id.uap_attribsStatusTx);
     43 
     44         setPassFailButtonClickListeners();
     45         setInfoResources(R.string.usbaudio_attribs_test, R.string.usbaudio_attribs_info, -1);
     46     }
     47 
     48     //
     49     // USBAudioPeripheralActivity
     50     //
     51     public void updateConnectStatus() {
     52         boolean outPass = false;
     53         boolean inPass = false;
     54         if (mIsPeripheralAttached && mSelectedProfile != null) {
     55             boolean match = true;
     56             StringBuilder metaSb = new StringBuilder();
     57 
     58             // Outputs
     59             if (mOutputDevInfo != null) {
     60                 AudioDeviceInfo deviceInfo = mOutputDevInfo;
     61                 PeripheralProfile.ProfileAttributes attribs =
     62                     mSelectedProfile.getOutputAttributes();
     63                 StringBuilder sb = new StringBuilder();
     64 
     65                 // Channel Counts
     66                 if (deviceInfo.getChannelCounts().length == 0) {
     67                     sb.append("Output - No Peripheral Channel Counts\n");
     68                 } else if (!ListsHelper.isSubset(deviceInfo.getChannelCounts(), attribs.mChannelCounts)) {
     69                     sb.append("Output - Channel Counts Mismatch\n");
     70                 }
     71 
     72                 // Encodings
     73                 if (deviceInfo.getEncodings().length == 0) {
     74                     sb.append("Output - No Peripheral Encodings\n");
     75                 } else if (!ListsHelper.isSubset(deviceInfo.getEncodings(), attribs.mEncodings)) {
     76                     sb.append("Output - Encodings Mismatch\n");
     77                 }
     78 
     79                 // Sample Rates
     80                 if (deviceInfo.getSampleRates().length == 0) {
     81                     sb.append("Output - No Peripheral Sample Rates\n");
     82                 } else if (!ListsHelper.isSubset(deviceInfo.getSampleRates(), attribs.mSampleRates)) {
     83                     sb.append("Output - Sample Rates Mismatch\n");
     84                 }
     85 
     86                 // Channel Masks
     87                 if (deviceInfo.getChannelIndexMasks().length == 0 &&
     88                     deviceInfo.getChannelMasks().length == 0) {
     89                     sb.append("Output - No Peripheral Channel Masks\n");
     90                 } else {
     91                     // Channel Index Masks
     92                     if (!ListsHelper.isSubset(deviceInfo.getChannelIndexMasks(),
     93                             attribs.mChannelIndexMasks)) {
     94                         sb.append("Output - Channel Index Masks Mismatch\n");
     95                     }
     96 
     97                     // Channel Position Masks
     98                     if (!ListsHelper.isSubset(deviceInfo.getChannelMasks(),
     99                             attribs.mChannelPositionMasks)) {
    100                         sb.append("Output - Channel Position Masks Mismatch\n");
    101                     }
    102                 }
    103 
    104                 // Report
    105                 if (sb.toString().length() == 0){
    106                     metaSb.append("Output - Match\n");
    107                     outPass = true;
    108                 } else {
    109                     metaSb.append(sb.toString());
    110                 }
    111             } else {
    112                 // No output device to test, so pass it.
    113                 outPass = true;
    114             }
    115 
    116             // Inputs
    117             if (mInputDevInfo != null) {
    118                 AudioDeviceInfo deviceInfo = mInputDevInfo;
    119                 PeripheralProfile.ProfileAttributes attribs =
    120                     mSelectedProfile.getInputAttributes();
    121                 StringBuilder sb = new StringBuilder();
    122 
    123                 // Channel Counts
    124                 if (deviceInfo.getChannelCounts().length == 0) {
    125                     sb.append("Input - No Peripheral Channel Counts\n");
    126                 } else if (!ListsHelper.isSubset(deviceInfo.getChannelCounts(), attribs.mChannelCounts)) {
    127                     sb.append("Input - Channel Counts Mismatch\n");
    128                 }
    129 
    130                 // Encodings
    131                 if (deviceInfo.getEncodings().length == 0) {
    132                     sb.append("Input - No Peripheral Encodings\n");
    133                 } else if (!ListsHelper.isSubset(deviceInfo.getEncodings(), attribs.mEncodings)) {
    134                     sb.append("Input - Encodings Mismatch\n");
    135                 }
    136 
    137                 // Sample Rates
    138                 if (deviceInfo.getSampleRates().length == 0) {
    139                     sb.append("Input - No Peripheral Sample Rates\n");
    140                 } else if (!ListsHelper.isSubset(deviceInfo.getSampleRates(), attribs.mSampleRates)) {
    141                     sb.append("Input - Sample Rates Mismatch\n");
    142                 }
    143 
    144                 // Channel Masks
    145                 if (deviceInfo.getChannelIndexMasks().length == 0 &&
    146                         deviceInfo.getChannelMasks().length == 0) {
    147                     sb.append("Input - No Peripheral Channel Masks\n");
    148                 } else {
    149                     if (!ListsHelper.isSubset(deviceInfo.getChannelIndexMasks(),
    150                             attribs.mChannelIndexMasks)) {
    151                         sb.append("Input - Channel Index Masks Mismatch\n");
    152                     }
    153                     if (!ListsHelper.isSubset(deviceInfo.getChannelMasks(),
    154                             attribs.mChannelPositionMasks)) {
    155                         sb.append("Input - Channel Position Masks Mismatch\n");
    156                     }
    157                 }
    158                 if (sb.toString().length() == 0){
    159                     metaSb.append("Input - Match\n");
    160                     inPass = true;
    161                 } else {
    162                     metaSb.append(sb.toString());
    163                 }
    164             } else {
    165                 // No input device, so pass it.
    166                 inPass = true;
    167             }
    168 
    169             mTestStatusTx.setText(metaSb.toString());
    170         } else {
    171             mTestStatusTx.setText("No Peripheral or No Matching Profile.");
    172         }
    173 
    174         // Headset not publicly available, violates CTS Verifier additional equipment guidelines.
    175         getPassButton().setEnabled(outPass && inPass);
    176     }
    177 }
    178