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.AudioService.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         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 
VolumeEvent(int op, int stream, int val1, int val2, String caller)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
eventToString()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 }
139