1 /* 2 * Copyright (C) 2022 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.os.Bundle; 20 import android.view.View; 21 import android.widget.LinearLayout; 22 import android.widget.RadioButton; 23 24 import com.android.cts.verifier.PassFailButtons; 25 import com.android.cts.verifier.R; 26 import com.android.cts.verifier.audio.audiolib.AudioSystemFlags; 27 28 // MegaAudio 29 import org.hyphonate.megaaudio.common.BuilderBase; 30 31 abstract class AudioMultiApiActivity 32 extends PassFailButtons.Activity 33 implements View.OnClickListener { 34 private static final String TAG = "AudioMultiApiActivity"; 35 36 protected int mAudioApi = BuilderBase.TYPE_OBOE | BuilderBase.SUB_TYPE_OBOE_AAUDIO; 37 38 // Test API (back-end) IDs 39 protected static final int NUM_TEST_APIS = 2; 40 protected static final int TEST_API_NATIVE = 0; 41 protected static final int TEST_API_JAVA = 1; 42 protected int mActiveTestAPI = TEST_API_NATIVE; 43 44 @Override onCreate(Bundle savedInstanceState)45 protected void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 48 if (AudioSystemFlags.isWatch(this)) { 49 ((LinearLayout) findViewById(R.id.audio_api_radiogroup)) 50 .setOrientation(LinearLayout.VERTICAL); 51 } 52 53 ((RadioButton) findViewById(R.id.audioJavaApiBtn)).setOnClickListener(this); 54 RadioButton nativeApiRB = findViewById(R.id.audioNativeApiBtn); 55 nativeApiRB.setChecked(true); 56 nativeApiRB.setOnClickListener(this); 57 } 58 59 @Override setTestResultAndFinish(boolean passed)60 public void setTestResultAndFinish(boolean passed) { 61 super.setTestResultAndFinish(passed); 62 } 63 onApiChange(int api)64 public abstract void onApiChange(int api); 65 66 // 67 // View.OnClickListener 68 // 69 @Override onClick(View view)70 public void onClick(View view) { 71 int id = view.getId(); 72 if (id == R.id.audioJavaApiBtn) { 73 mAudioApi = BuilderBase.TYPE_JAVA; 74 onApiChange(mActiveTestAPI = TEST_API_JAVA); 75 } else if (id == R.id.audioNativeApiBtn) { 76 mAudioApi = BuilderBase.TYPE_OBOE | BuilderBase.SUB_TYPE_OBOE_AAUDIO; 77 onApiChange(mActiveTestAPI = TEST_API_NATIVE); 78 } 79 } 80 audioApiToString(int api)81 public String audioApiToString(int api) { 82 return (api == TEST_API_JAVA) ? "Java" : "Native"; 83 } 84 } 85