1 /* 2 * Copyright 2020 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.server.audio; 18 19 import android.annotation.NonNull; 20 import android.media.AudioAttributes; 21 import android.media.AudioDeviceAttributes; 22 import android.media.AudioSystem; 23 import android.util.Log; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 28 /** 29 * Provides an adapter for AudioSystem that does nothing. 30 * Overridden methods can be configured. 31 */ 32 public class NoOpAudioSystemAdapter extends AudioSystemAdapter { 33 private static final String TAG = "ASA"; 34 private boolean mIsMicMuted = false; 35 private boolean mMuteMicrophoneFails = false; 36 private boolean mIsStreamActive = false; 37 configureIsMicrophoneMuted(boolean muted)38 public void configureIsMicrophoneMuted(boolean muted) { 39 mIsMicMuted = muted; 40 } 41 configureIsStreamActive(boolean active)42 public void configureIsStreamActive(boolean active) { 43 mIsStreamActive = active; 44 } 45 configureMuteMicrophoneToFail(boolean fail)46 public void configureMuteMicrophoneToFail(boolean fail) { 47 mMuteMicrophoneFails = fail; 48 } 49 50 //----------------------------------------------------------------- 51 // Overrides of AudioSystemAdapter 52 @Override setDeviceConnectionState(AudioDeviceAttributes attributes, int state, int codecFormat)53 public int setDeviceConnectionState(AudioDeviceAttributes attributes, int state, 54 int codecFormat) { 55 Log.i(TAG, String.format("setDeviceConnectionState(0x%s, %d, 0x%s", 56 attributes.toString(), state, Integer.toHexString(codecFormat))); 57 return AudioSystem.AUDIO_STATUS_OK; 58 } 59 60 @Override getDeviceConnectionState(int device, String deviceAddress)61 public int getDeviceConnectionState(int device, String deviceAddress) { 62 return AudioSystem.AUDIO_STATUS_OK; 63 } 64 65 @Override handleDeviceConfigChange(int device, String deviceAddress, String deviceName, int codecFormat)66 public int handleDeviceConfigChange(int device, String deviceAddress, 67 String deviceName, int codecFormat) { 68 return AudioSystem.AUDIO_STATUS_OK; 69 } 70 71 @Override setDevicesRoleForStrategy(int strategy, int role, @NonNull List<AudioDeviceAttributes> devices)72 public int setDevicesRoleForStrategy(int strategy, int role, 73 @NonNull List<AudioDeviceAttributes> devices) { 74 return AudioSystem.AUDIO_STATUS_OK; 75 } 76 77 @Override removeDevicesRoleForStrategy(int strategy, int role, @NonNull List<AudioDeviceAttributes> devices)78 public int removeDevicesRoleForStrategy(int strategy, int role, 79 @NonNull List<AudioDeviceAttributes> devices) { 80 return AudioSystem.AUDIO_STATUS_OK; 81 } 82 83 @Override clearDevicesRoleForStrategy(int strategy, int role)84 public int clearDevicesRoleForStrategy(int strategy, int role) { 85 return AudioSystem.AUDIO_STATUS_OK; 86 } 87 88 @Override setDevicesRoleForCapturePreset(int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices)89 public int setDevicesRoleForCapturePreset(int capturePreset, int role, 90 @NonNull List<AudioDeviceAttributes> devices) { 91 return AudioSystem.AUDIO_STATUS_OK; 92 } 93 94 @Override removeDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devicesToRemove)95 public int removeDevicesRoleForCapturePreset( 96 int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devicesToRemove) { 97 return AudioSystem.AUDIO_STATUS_OK; 98 } 99 100 @Override clearDevicesRoleForCapturePreset(int capturePreset, int role)101 public int clearDevicesRoleForCapturePreset(int capturePreset, int role) { 102 return AudioSystem.AUDIO_STATUS_OK; 103 } 104 105 @Override setParameters(String keyValuePairs)106 public int setParameters(String keyValuePairs) { 107 return AudioSystem.AUDIO_STATUS_OK; 108 } 109 110 @Override isMicrophoneMuted()111 public boolean isMicrophoneMuted() { 112 return mIsMicMuted; 113 } 114 115 @Override muteMicrophone(boolean on)116 public int muteMicrophone(boolean on) { 117 if (mMuteMicrophoneFails) { 118 return AudioSystem.AUDIO_STATUS_ERROR; 119 } 120 mIsMicMuted = on; 121 return AudioSystem.AUDIO_STATUS_OK; 122 } 123 124 @Override setCurrentImeUid(int uid)125 public int setCurrentImeUid(int uid) { 126 return AudioSystem.AUDIO_STATUS_OK; 127 } 128 129 @Override isStreamActive(int stream, int inPastMs)130 public boolean isStreamActive(int stream, int inPastMs) { 131 return mIsStreamActive; 132 } 133 134 @Override setStreamVolumeIndexAS(int stream, int index, int device)135 public int setStreamVolumeIndexAS(int stream, int index, int device) { 136 return AudioSystem.AUDIO_STATUS_OK; 137 } 138 139 @Override 140 @NonNull getDevicesForAttributes( @onNull AudioAttributes attributes, boolean forVolume)141 public ArrayList<AudioDeviceAttributes> getDevicesForAttributes( 142 @NonNull AudioAttributes attributes, boolean forVolume) { 143 return new ArrayList<>(); 144 } 145 } 146