blob: 9d9e35bdf2b2203bba68be6ef96c7e279101d828 [file] [log] [blame]
Jean-Michel Trivicf170362017-08-24 17:24:57 -07001/*
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
17package com.android.server.audio;
18
19import android.media.AudioManager;
20import android.media.AudioSystem;
21
22import com.android.server.audio.AudioService.WiredDeviceConnectionState;
23
24
25public class AudioServiceEvents {
26
27 final static class PhoneStateEvent extends AudioEventLogger.Event {
28 final String mPackage;
Eric Laurent6afa6502017-09-28 15:18:19 -070029 final int mOwnerPid;
30 final int mRequesterPid;
31 final int mRequestedMode;
32 final int mActualMode;
Jean-Michel Trivicf170362017-08-24 17:24:57 -070033
Eric Laurent6afa6502017-09-28 15:18:19 -070034 PhoneStateEvent(String callingPackage, int requesterPid, int requestedMode,
35 int ownerPid, int actualMode) {
Jean-Michel Trivicf170362017-08-24 17:24:57 -070036 mPackage = callingPackage;
Eric Laurent6afa6502017-09-28 15:18:19 -070037 mRequesterPid = requesterPid;
38 mRequestedMode = requestedMode;
39 mOwnerPid = ownerPid;
40 mActualMode = actualMode;
Jean-Michel Trivicf170362017-08-24 17:24:57 -070041 }
42
43 @Override
44 public String eventToString() {
Eric Laurent6afa6502017-09-28 15:18:19 -070045 return new StringBuilder("setMode(").append(AudioSystem.modeToString(mRequestedMode))
Jean-Michel Trivicf170362017-08-24 17:24:57 -070046 .append(") from package=").append(mPackage)
Eric Laurent6afa6502017-09-28 15:18:19 -070047 .append(" pid=").append(mRequesterPid)
48 .append(" selected mode=").append(AudioSystem.modeToString(mActualMode))
49 .append(" by pid=").append(mOwnerPid).toString();
Jean-Michel Trivicf170362017-08-24 17:24:57 -070050 }
51 }
52
53 final static class WiredDevConnectEvent extends AudioEventLogger.Event {
54 final WiredDeviceConnectionState mState;
55
56 WiredDevConnectEvent(WiredDeviceConnectionState state) {
57 mState = state;
58 }
59
60 @Override
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
76 ForceUseEvent(int usage, int config, String reason) {
77 mUsage = usage;
78 mConfig = config;
79 mReason = reason;
80 }
81
82 @Override
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 final static int VOL_ADJUST_SUGG_VOL = 0;
93 final static int VOL_ADJUST_STREAM_VOL = 1;
94 final static int VOL_SET_STREAM_VOL = 2;
95
96 final int mOp;
97 final int mStream;
98 final int mVal1;
99 final int mVal2;
100 final String mCaller;
101
102 VolumeEvent(int op, int stream, int val1, int val2, String caller) {
103 mOp = op;
104 mStream = stream;
105 mVal1 = val1;
106 mVal2 = val2;
107 mCaller = caller;
108 }
109
110 @Override
111 public String eventToString() {
112 switch (mOp) {
113 case VOL_ADJUST_SUGG_VOL:
114 return new StringBuilder("adjustSuggestedStreamVolume(sugg:")
115 .append(AudioSystem.streamToString(mStream))
116 .append(" dir:").append(AudioManager.adjustToString(mVal1))
117 .append(" flags:0x").append(Integer.toHexString(mVal2))
118 .append(") from ").append(mCaller)
119 .toString();
120 case VOL_ADJUST_STREAM_VOL:
121 return new StringBuilder("adjustStreamVolume(stream:")
122 .append(AudioSystem.streamToString(mStream))
123 .append(" dir:").append(AudioManager.adjustToString(mVal1))
124 .append(" flags:0x").append(Integer.toHexString(mVal2))
125 .append(") from ").append(mCaller)
126 .toString();
127 case VOL_SET_STREAM_VOL:
128 return new StringBuilder("setStreamVolume(stream:")
129 .append(AudioSystem.streamToString(mStream))
130 .append(" index:").append(mVal1)
131 .append(" flags:0x").append(Integer.toHexString(mVal2))
132 .append(") from ").append(mCaller)
133 .toString();
134 default: return new StringBuilder("FIXME invalid op:").append(mOp).toString();
135 }
136 }
137 }
138}