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 com.android.cts.verifier.PassFailButtons; 20 import com.android.cts.verifier.R; 21 import com.android.cts.verifier.audio.wavelib.*; 22 import com.android.compatibility.common.util.ReportLog; 23 import com.android.compatibility.common.util.ResultType; 24 import com.android.compatibility.common.util.ResultUnit; 25 26 import android.app.AlertDialog; 27 import android.content.Context; 28 import android.media.AudioDeviceCallback; 29 import android.media.AudioDeviceInfo; 30 import android.media.AudioFormat; 31 import android.media.AudioManager; 32 import android.media.AudioTrack; 33 import android.media.AudioRecord; 34 import android.media.MediaRecorder; 35 import android.os.Bundle; 36 import android.os.Handler; 37 import android.os.Message; 38 import android.os.SystemClock; 39 import android.util.Log; 40 import android.view.View; 41 import android.view.View.OnClickListener; 42 import android.widget.Button; 43 import android.widget.TextView; 44 import android.widget.SeekBar; 45 import android.widget.LinearLayout; 46 import android.widget.ProgressBar; 47 48 /** 49 * Audio Frequency Test base activity 50 */ 51 public class AudioFrequencyActivity extends PassFailButtons.Activity { 52 private static final String TAG = "AudioFrequencyActivity"; 53 54 public int mMaxLevel = 0; 55 setMaxLevel()56 public void setMaxLevel() { 57 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 58 mMaxLevel = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); 59 am.setStreamVolume(AudioManager.STREAM_MUSIC, (int)(mMaxLevel), 0); 60 } 61 setMinLevel()62 public void setMinLevel() { 63 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 64 am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); 65 } 66 testMaxLevel()67 public void testMaxLevel() { 68 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 69 int currentLevel = am.getStreamVolume(AudioManager.STREAM_MUSIC); 70 Log.i(TAG, String.format("Max level: %d curLevel: %d", mMaxLevel, currentLevel)); 71 if (currentLevel != mMaxLevel) { 72 new AlertDialog.Builder(this) 73 .setTitle(R.string.audio_general_warning) 74 .setMessage(R.string.audio_general_level_not_max) 75 .setPositiveButton(R.string.audio_general_ok, null) 76 .show(); 77 } 78 } 79 getMaxLevelForStream(int streamType)80 public int getMaxLevelForStream(int streamType) { 81 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 82 if (am != null) { 83 return am.getStreamMaxVolume(streamType); 84 } 85 return -1; 86 } 87 setLevelForStream(int streamType, int level)88 public void setLevelForStream(int streamType, int level) { 89 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 90 if (am != null) { 91 try { 92 am.setStreamVolume(streamType, level, 0); 93 } catch (Exception e) { 94 Log.e(TAG, "Error setting stream volume: ", e); 95 } 96 } 97 } 98 getLevelForStream(int streamType)99 public int getLevelForStream(int streamType) { 100 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 101 if (am != null) { 102 return am.getStreamVolume(streamType); 103 } 104 return -1; 105 } 106 enableUILayout(LinearLayout layout, boolean enable)107 public void enableUILayout(LinearLayout layout, boolean enable) { 108 for (int i = 0; i < layout.getChildCount(); i++) { 109 View view = layout.getChildAt(i); 110 view.setEnabled(enable); 111 } 112 } 113 114 } 115