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.server.audio; 18 19 import android.media.AudioManager; 20 import android.media.AudioSystem; 21 22 import com.android.server.audio.AudioDeviceInventory.WiredDeviceConnectionState; 23 24 25 public class AudioServiceEvents { 26 27 final static class PhoneStateEvent extends AudioEventLogger.Event { 28 final String mPackage; 29 final int mOwnerPid; 30 final int mRequesterPid; 31 final int mRequestedMode; 32 final int mActualMode; 33 PhoneStateEvent(String callingPackage, int requesterPid, int requestedMode, int ownerPid, int actualMode)34 PhoneStateEvent(String callingPackage, int requesterPid, int requestedMode, 35 int ownerPid, int actualMode) { 36 mPackage = callingPackage; 37 mRequesterPid = requesterPid; 38 mRequestedMode = requestedMode; 39 mOwnerPid = ownerPid; 40 mActualMode = actualMode; 41 } 42 43 @Override eventToString()44 public String eventToString() { 45 return new StringBuilder("setMode(").append(AudioSystem.modeToString(mRequestedMode)) 46 .append(") from package=").append(mPackage) 47 .append(" pid=").append(mRequesterPid) 48 .append(" selected mode=").append(AudioSystem.modeToString(mActualMode)) 49 .append(" by pid=").append(mOwnerPid).toString(); 50 } 51 } 52 53 final static class WiredDevConnectEvent extends AudioEventLogger.Event { 54 final WiredDeviceConnectionState mState; 55 WiredDevConnectEvent(WiredDeviceConnectionState state)56 WiredDevConnectEvent(WiredDeviceConnectionState state) { 57 mState = state; 58 } 59 60 @Override eventToString()61 public String eventToString() { 62 return new StringBuilder("setWiredDeviceConnectionState(") 63 .append(" type:").append(Integer.toHexString(mState.mType)) 64 .append(" state:").append(AudioSystem.deviceStateToString(mState.mState)) 65 .append(" addr:").append(mState.mAddress) 66 .append(" name:").append(mState.mName) 67 .append(") from ").append(mState.mCaller).toString(); 68 } 69 } 70 71 final static class ForceUseEvent extends AudioEventLogger.Event { 72 final int mUsage; 73 final int mConfig; 74 final String mReason; 75 ForceUseEvent(int usage, int config, String reason)76 ForceUseEvent(int usage, int config, String reason) { 77 mUsage = usage; 78 mConfig = config; 79 mReason = reason; 80 } 81 82 @Override eventToString()83 public String eventToString() { 84 return new StringBuilder("setForceUse(") 85 .append(AudioSystem.forceUseUsageToString(mUsage)) 86 .append(", ").append(AudioSystem.forceUseConfigToString(mConfig)) 87 .append(") due to ").append(mReason).toString(); 88 } 89 } 90 91 final static class VolumeEvent extends AudioEventLogger.Event { 92 static final int VOL_ADJUST_SUGG_VOL = 0; 93 static final int VOL_ADJUST_STREAM_VOL = 1; 94 static final int VOL_SET_STREAM_VOL = 2; 95 static final int VOL_SET_HEARING_AID_VOL = 3; 96 static final int VOL_SET_AVRCP_VOL = 4; 97 static final int VOL_ADJUST_VOL_UID = 5; 98 static final int VOL_VOICE_ACTIVITY_HEARING_AID = 6; 99 static final int VOL_MODE_CHANGE_HEARING_AID = 7; 100 101 final int mOp; 102 final int mStream; 103 final int mVal1; 104 final int mVal2; 105 final String mCaller; 106 107 /** used for VOL_ADJUST_VOL_UID, 108 * VOL_ADJUST_SUGG_VOL, 109 * VOL_ADJUST_STREAM_VOL, 110 * VOL_SET_STREAM_VOL */ VolumeEvent(int op, int stream, int val1, int val2, String caller)111 VolumeEvent(int op, int stream, int val1, int val2, String caller) { 112 mOp = op; 113 mStream = stream; 114 mVal1 = val1; 115 mVal2 = val2; 116 mCaller = caller; 117 } 118 119 /** used for VOL_SET_HEARING_AID_VOL*/ VolumeEvent(int op, int index, int gainDb)120 VolumeEvent(int op, int index, int gainDb) { 121 mOp = op; 122 mVal1 = index; 123 mVal2 = gainDb; 124 // unused 125 mStream = -1; 126 mCaller = null; 127 } 128 129 /** used for VOL_SET_AVRCP_VOL */ VolumeEvent(int op, int index)130 VolumeEvent(int op, int index) { 131 mOp = op; 132 mVal1 = index; 133 // unused 134 mVal2 = 0; 135 mStream = -1; 136 mCaller = null; 137 } 138 139 /** used for VOL_VOICE_ACTIVITY_HEARING_AID */ VolumeEvent(int op, boolean voiceActive, int stream, int index)140 VolumeEvent(int op, boolean voiceActive, int stream, int index) { 141 mOp = op; 142 mStream = stream; 143 mVal1 = index; 144 mVal2 = voiceActive ? 1 : 0; 145 // unused 146 mCaller = null; 147 } 148 149 /** used for VOL_MODE_CHANGE_HEARING_AID */ VolumeEvent(int op, int mode, int stream, int index)150 VolumeEvent(int op, int mode, int stream, int index) { 151 mOp = op; 152 mStream = stream; 153 mVal1 = index; 154 mVal2 = mode; 155 // unused 156 mCaller = null; 157 } 158 159 @Override eventToString()160 public String eventToString() { 161 switch (mOp) { 162 case VOL_ADJUST_SUGG_VOL: 163 return new StringBuilder("adjustSuggestedStreamVolume(sugg:") 164 .append(AudioSystem.streamToString(mStream)) 165 .append(" dir:").append(AudioManager.adjustToString(mVal1)) 166 .append(" flags:0x").append(Integer.toHexString(mVal2)) 167 .append(") from ").append(mCaller) 168 .toString(); 169 case VOL_ADJUST_STREAM_VOL: 170 return new StringBuilder("adjustStreamVolume(stream:") 171 .append(AudioSystem.streamToString(mStream)) 172 .append(" dir:").append(AudioManager.adjustToString(mVal1)) 173 .append(" flags:0x").append(Integer.toHexString(mVal2)) 174 .append(") from ").append(mCaller) 175 .toString(); 176 case VOL_SET_STREAM_VOL: 177 return new StringBuilder("setStreamVolume(stream:") 178 .append(AudioSystem.streamToString(mStream)) 179 .append(" index:").append(mVal1) 180 .append(" flags:0x").append(Integer.toHexString(mVal2)) 181 .append(") from ").append(mCaller) 182 .toString(); 183 case VOL_SET_HEARING_AID_VOL: 184 return new StringBuilder("setHearingAidVolume:") 185 .append(" index:").append(mVal1) 186 .append(" gain dB:").append(mVal2) 187 .toString(); 188 case VOL_SET_AVRCP_VOL: 189 return new StringBuilder("setAvrcpVolume:") 190 .append(" index:").append(mVal1) 191 .toString(); 192 case VOL_ADJUST_VOL_UID: 193 return new StringBuilder("adjustStreamVolumeForUid(stream:") 194 .append(AudioSystem.streamToString(mStream)) 195 .append(" dir:").append(AudioManager.adjustToString(mVal1)) 196 .append(" flags:0x").append(Integer.toHexString(mVal2)) 197 .append(") from ").append(mCaller) 198 .toString(); 199 case VOL_VOICE_ACTIVITY_HEARING_AID: 200 return new StringBuilder("Voice activity change (") 201 .append(mVal2 == 1 ? "active" : "inactive") 202 .append(") causes setting HEARING_AID volume to idx:").append(mVal1) 203 .append(" stream:").append(AudioSystem.streamToString(mStream)) 204 .toString(); 205 case VOL_MODE_CHANGE_HEARING_AID: 206 return new StringBuilder("setMode(") 207 .append(AudioSystem.modeToString(mVal2)) 208 .append(") causes setting HEARING_AID volume to idx:").append(mVal1) 209 .append(" stream:").append(AudioSystem.streamToString(mStream)) 210 .toString(); 211 default: return new StringBuilder("FIXME invalid op:").append(mOp).toString(); 212 } 213 } 214 } 215 } 216