• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.telecom;
18 
19 import android.content.Context;
20 import android.os.SystemClock;
21 import android.telecom.Logging.EventManager;
22 import android.telecom.Logging.EventManager.TimedEventPair;
23 
24 import java.util.HashMap;
25 import java.util.Map;
26 
27 /**
28  * Temporary location of new Logging class
29  */
30 
31 public class LogUtils {
32 
33     private static final String TAG = "Telecom";
34     private static final String LOGUTILS_TAG = "LogUtils";
35 
36     public static final boolean SYSTRACE_DEBUG = false; /* STOP SHIP if true */
37 
38     public static class EventTimer {
39         private long mLastElapsedMillis;
40         private Map<String, Long> mTimings = new HashMap<>();
41 
EventTimer()42         public EventTimer() {
43             mLastElapsedMillis = SystemClock.elapsedRealtime();
44         }
45 
record(String label)46         public void record(String label) {
47             long newElapsedMillis = SystemClock.elapsedRealtime();
48             mTimings.put(label, newElapsedMillis - mLastElapsedMillis);
49             mLastElapsedMillis = newElapsedMillis;
50         }
51 
52         @Override
toString()53         public String toString() {
54             StringBuilder sb = new StringBuilder();
55             for (Map.Entry<String, Long> entry : mTimings.entrySet()) {
56                 sb.append(entry.getKey()).append(": ").append(entry.getValue()).append(", ");
57             }
58             return sb.toString();
59         }
60     }
61 
62     public static final class Sessions {
63         public static final String ICA_ANSWER_CALL = "ICA.aC";
64         public static final String ICA_DEFLECT_CALL = "ICA.defC";
65         public static final String ICA_REJECT_CALL = "ICA.rC";
66         public static final String ICA_TRANSFER_CALL = "ICA.tC";
67         public static final String ICA_CONSULTATIVE_TRANSFER = "ICA.cT";
68         public static final String ICA_DISCONNECT_CALL = "ICA.dC";
69         public static final String ICA_HOLD_CALL = "ICA.hC";
70         public static final String ICA_UNHOLD_CALL = "ICA.uC";
71         public static final String ICA_MUTE = "ICA.m";
72         public static final String ICA_SET_AUDIO_ROUTE = "ICA.sAR";
73         public static final String ICA_ENTER_AUDIO_PROCESSING = "ICA.enBAP";
74         public static final String ICA_EXIT_AUDIO_PROCESSING = "ICA.exBAP";
75         public static final String ICA_CONFERENCE = "ICA.c";
76         public static final String CSW_HANDLE_CREATE_CONNECTION_COMPLETE = "CSW.hCCC";
77         public static final String CSW_SET_ACTIVE = "CSW.sA";
78         public static final String CSW_SET_RINGING = "CSW.sR";
79         public static final String CSW_SET_DIALING = "CSW.sD";
80         public static final String CSW_SET_PULLING = "CSW.sP";
81         public static final String CSW_SET_DISCONNECTED = "CSW.sDc";
82         public static final String CSW_SET_ON_HOLD = "CSW.sOH";
83         public static final String CSW_REMOVE_CALL = "CSW.rC";
84         public static final String CSW_SET_IS_CONFERENCED = "CSW.sIC";
85         public static final String CSW_ADD_CONFERENCE_CALL = "CSW.aCC";
86     }
87 
88     public final static class Events {
89         public static final String CREATED = "CREATED";
90         public static final String USER_CONFIRMATION = "USER_CONFIRMATION";
91         public static final String USER_CONFIRMED = "USER_CONFIRMED";
92         public static final String USER_CANCELLED = "USER_CANCELLED";
93         public static final String DESTROYED = "DESTROYED";
94         public static final String SET_CONNECTING = "SET_CONNECTING";
95         public static final String SET_DIALING = "SET_DIALING";
96         public static final String SET_PULLING = "SET_PULLING";
97         public static final String SET_ACTIVE = "SET_ACTIVE";
98         public static final String SET_HOLD = "SET_HOLD";
99         public static final String SET_RINGING = "SET_RINGING";
100         public static final String SET_ANSWERED = "SET_ANSWERED";
101         public static final String SET_DISCONNECTED = "SET_DISCONNECTED";
102         public static final String SET_DISCONNECTING = "SET_DISCONNECTING";
103         public static final String SET_SELECT_PHONE_ACCOUNT = "SET_SELECT_PHONE_ACCOUNT";
104         public static final String SET_AUDIO_PROCESSING = "SET_AUDIO_PROCESSING";
105         public static final String SET_SIMULATED_RINGING = "SET_SIMULATED_RINGING";
106         public static final String REQUEST_HOLD = "REQUEST_HOLD";
107         public static final String REQUEST_UNHOLD = "REQUEST_UNHOLD";
108         public static final String REQUEST_DISCONNECT = "REQUEST_DISCONNECT";
109         public static final String REQUEST_ACCEPT = "REQUEST_ACCEPT";
110         public static final String REQUEST_SIMULATED_ACCEPT = "REQUEST_SIMULATED_ACCEPT";
111         public static final String REQUEST_PICKUP_FOR_AUDIO_PROCESSING =
112                 "REQUEST_PICKUP_FOR_AUDIO_PROCESSING";
113         public static final String REQUEST_DEFLECT = "REQUEST_DEFLECT";
114         public static final String REQUEST_REJECT = "REQUEST_REJECT";
115         public static final String REQUEST_TRANSFER = "REQUEST_TRANSFER";
116         public static final String REQUEST_CONSULTATIVE_TRANSFER = "REQUEST_CONSULTATIVE_TRANSFER";
117         public static final String START_DTMF = "START_DTMF";
118         public static final String STOP_DTMF = "STOP_DTMF";
119         public static final String START_RINGER = "START_RINGER";
120         public static final String STOP_RINGER = "STOP_RINGER";
121         public static final String START_VIBRATOR = "START_VIBRATOR";
122         public static final String STOP_VIBRATOR = "STOP_VIBRATOR";
123         public static final String SKIP_VIBRATION = "SKIP_VIBRATION";
124         public static final String SKIP_RINGING = "SKIP_RINGING";
125         public static final String START_CALL_WAITING_TONE = "START_CALL_WAITING_TONE";
126         public static final String STOP_CALL_WAITING_TONE = "STOP_CALL_WAITING_TONE";
127         public static final String START_CONNECTION = "START_CONNECTION";
128         public static final String CREATE_CONNECTION_FAILED = "CREATE_CONNECTION_FAILED";
129         public static final String START_CONFERENCE = "START_CONFERENCE";
130         public static final String CREATE_CONFERENCE_FAILED = "CREATE_CONFERENCE_FAILED";
131         public static final String BIND_CS = "BIND_CS";
132         public static final String CS_BOUND = "CS_BOUND";
133         public static final String CONFERENCE_WITH = "CONF_WITH";
134         public static final String SPLIT_FROM_CONFERENCE = "CONF_SPLIT";
135         public static final String SWAP = "SWAP";
136         public static final String ADD_PARTICIPANT = "ADD_PARTICIPANT";
137         public static final String ADD_CHILD = "ADD_CHILD";
138         public static final String REMOVE_CHILD = "REMOVE_CHILD";
139         public static final String SET_PARENT = "SET_PARENT";
140         public static final String CONF_STATE_CHANGED = "CONF_STATE_CHANGED";
141         public static final String CALL_DIRECTION_CHANGED = "CALL_DIRECTION_CHANGED";
142         public static final String MUTE = "MUTE";
143         public static final String UNMUTE = "UNMUTE";
144         public static final String AUDIO_ROUTE = "AUDIO_ROUTE";
145         public static final String AUDIO_ROUTE_EARPIECE = "AUDIO_ROUTE_EARPIECE";
146         public static final String AUDIO_ROUTE_HEADSET = "AUDIO_ROUTE_HEADSET";
147         public static final String AUDIO_ROUTE_BT = "AUDIO_ROUTE_BT";
148         public static final String AUDIO_ROUTE_SPEAKER = "AUDIO_ROUTE_SPEAKER";
149         public static final String ERROR_LOG = "ERROR";
150         public static final String USER_LOG_MARK = "USER_LOG_MARK";
151         public static final String SILENCE = "SILENCE";
152         public static final String BIND_SCREENING = "BIND_SCREENING";
153         public static final String SCREENING_BOUND = "SCREENING_BOUND";
154         public static final String SCREENING_SENT = "SCREENING_SENT";
155         public static final String SCREENING_SKIPPED = "SCREENING_SKIPPED";
156         public static final String CONTROLLER_SCREENING_COMPLETED =
157                 "CONTROLLER_SCREENING_COMPLETED";
158         public static final String SCREENING_COMPLETED = "SCREENING_COMPLETED";
159         public static final String CALL_IDENTIFICATION_SET = "CALL_IDENTIFICATION_SET";
160         public static final String BLOCK_CHECK_INITIATED = "BLOCK_CHECK_INITIATED";
161         public static final String BLOCK_CHECK_FINISHED = "BLOCK_CHECK_FINISHED";
162         public static final String DIRECT_TO_VM_INITIATED = "DIRECT_TO_VM_INITIATED";
163         public static final String DIRECT_TO_VM_FINISHED = "DIRECT_TO_VM_FINISHED";
164         public static final String FILTERING_INITIATED = "FILTERING_INITIATED";
165         public static final String FILTERING_COMPLETED = "FILTERING_COMPLETED";
166         public static final String FILTERING_TIMED_OUT = "FILTERING_TIMED_OUT";
167         public static final String REMOTELY_HELD = "REMOTELY_HELD";
168         public static final String REMOTELY_UNHELD = "REMOTELY_UNHELD";
169         public static final String REQUEST_PULL = "PULL";
170         public static final String INFO = "INFO";
171         public static final String VIDEO_STATE_CHANGED = "VIDEO_STATE_CHANGED";
172         public static final String RECEIVE_VIDEO_REQUEST = "RECEIVE_VIDEO_REQUEST";
173         public static final String RECEIVE_VIDEO_RESPONSE = "RECEIVE_VIDEO_RESPONSE";
174         public static final String SEND_VIDEO_REQUEST = "SEND_VIDEO_REQUEST";
175         public static final String SEND_VIDEO_RESPONSE = "SEND_VIDEO_RESPONSE";
176         public static final String IS_EXTERNAL = "IS_EXTERNAL";
177         public static final String PROPERTY_CHANGE = "PROPERTY_CHANGE";
178         public static final String CAPABILITY_CHANGE = "CAPABILITY_CHANGE";
179         public static final String CONNECTION_EVENT = "CONNECTION_EVENT";
180         public static final String CALL_EVENT = "CALL_EVENT";
181         public static final String HANDOVER_REQUEST = "HANDOVER_REQUEST";
182         public static final String START_HANDOVER = "START_HANDOVER";
183         public static final String ACCEPT_HANDOVER = "ACCEPT_HANDOVER";
184         public static final String HANDOVER_COMPLETE = "HANDOVER_COMPLETE";
185         public static final String HANDOVER_FAILED = "HANDOVER_FAILED";
186         public static final String START_RINBACK = "START_RINGBACK";
187         public static final String STOP_RINGBACK = "STOP_RINGBACK";
188         public static final String REDIRECTION_BOUND_USER = "REDIRECTION_BOUND_USER";
189         public static final String REDIRECTION_BOUND_CARRIER = "REDIRECTION_BOUND_CARRIER";
190         public static final String REDIRECTION_SENT_USER = "REDIRECTION_SENT_USER";
191         public static final String REDIRECTION_SENT_CARRIER = "REDIRECTION_SENT_CARRIER";
192         public static final String REDIRECTION_COMPLETED_USER = "REDIRECTION_COMPLETED_USER";
193         public static final String REDIRECTION_COMPLETED_CARRIER = "REDIRECTION_COMPLETED_CARRIER";
194         public static final String REDIRECTION_TIMED_OUT_USER = "REDIRECTION_TIMED_OUT_USER";
195         public static final String REDIRECTION_TIMED_OUT_CARRIER = "REDIRECTION_TIMED_OUT_CARRIER";
196         public static final String REDIRECTION_USER_CONFIRMATION = "REDIRECTION_USER_CONFIRMATION";
197         public static final String REDIRECTION_USER_CONFIRMED = "REDIRECTION_USER_CONFIRMED";
198         public static final String REDIRECTION_USER_CANCELLED = "REDIRECTION_USER_CANCELLED";
199         public static final String BT_QUALITY_REPORT = "BT_QUALITY_REPORT";
200         public static final String SET_DISCONNECTED_ORIG = "SET_DISCONNECTED_ORIG";
201         public static final String OVERRIDE_DISCONNECT_MESSAGE = "OVERRIDE_DISCONNECT_MSG";
202         public static final String CALL_DIAGNOSTIC_SERVICE_TIMEOUT =
203                 "CALL_DIAGNOSTIC_SERVICE_TIMEOUT";
204         public static final String VERSTAT_CHANGED = "VERSTAT_CHANGED";
205 
206         public static class Timings {
207             public static final String ACCEPT_TIMING = "accept";
208             public static final String REJECT_TIMING = "reject";
209             public static final String DISCONNECT_TIMING = "disconnect";
210             public static final String HOLD_TIMING = "hold";
211             public static final String UNHOLD_TIMING = "unhold";
212             public static final String OUTGOING_TIME_TO_DIALING_TIMING = "outgoing_time_to_dialing";
213             public static final String BIND_CS_TIMING = "bind_cs";
214             public static final String SCREENING_COMPLETED_TIMING = "screening_completed";
215             public static final String DIRECT_TO_VM_FINISHED_TIMING = "direct_to_vm_finished";
216             public static final String BLOCK_CHECK_FINISHED_TIMING = "block_check_finished";
217             public static final String FILTERING_COMPLETED_TIMING = "filtering_completed";
218             public static final String FILTERING_TIMED_OUT_TIMING = "filtering_timed_out";
219             public static final String START_CONNECTION_TO_REQUEST_DISCONNECT_TIMING =
220                     "start_connection_to_request_disconnect";
221 
222             private static final TimedEventPair[] sTimedEvents = {
223                     new TimedEventPair(REQUEST_ACCEPT, SET_ACTIVE, ACCEPT_TIMING),
224                     new TimedEventPair(REQUEST_REJECT, SET_DISCONNECTED, REJECT_TIMING),
225                     new TimedEventPair(REQUEST_DISCONNECT, SET_DISCONNECTED, DISCONNECT_TIMING),
226                     new TimedEventPair(REQUEST_HOLD, SET_HOLD, HOLD_TIMING),
227                     new TimedEventPair(REQUEST_UNHOLD, SET_ACTIVE, UNHOLD_TIMING),
228                     new TimedEventPair(START_CONNECTION, SET_DIALING,
229                             OUTGOING_TIME_TO_DIALING_TIMING),
230                     new TimedEventPair(BIND_CS, CS_BOUND, BIND_CS_TIMING),
231                     new TimedEventPair(SCREENING_SENT, SCREENING_COMPLETED,
232                             SCREENING_COMPLETED_TIMING),
233                     new TimedEventPair(DIRECT_TO_VM_INITIATED, DIRECT_TO_VM_FINISHED,
234                             DIRECT_TO_VM_FINISHED_TIMING),
235                     new TimedEventPair(BLOCK_CHECK_INITIATED, BLOCK_CHECK_FINISHED,
236                             BLOCK_CHECK_FINISHED_TIMING),
237                     new TimedEventPair(FILTERING_INITIATED, FILTERING_COMPLETED,
238                             FILTERING_COMPLETED_TIMING),
239                     new TimedEventPair(FILTERING_INITIATED, FILTERING_TIMED_OUT,
240                             FILTERING_TIMED_OUT_TIMING, 6000L),
241                     new TimedEventPair(START_CONNECTION, REQUEST_DISCONNECT,
242                             START_CONNECTION_TO_REQUEST_DISCONNECT_TIMING),
243             };
244         }
245     }
246 
eventRecordAdded(EventManager.EventRecord eventRecord)247     private static void eventRecordAdded(EventManager.EventRecord eventRecord) {
248         // Only Calls will be added as event records in this case
249         EventManager.Loggable recordEntry = eventRecord.getRecordEntry();
250         if (recordEntry instanceof Call) {
251             Call callRecordEntry = (Call) recordEntry;
252             android.telecom.Log.i(LOGUTILS_TAG, "EventRecord added as Call: " + callRecordEntry);
253             Analytics.CallInfo callInfo = callRecordEntry.getAnalytics();
254             if(callInfo != null) {
255                 callInfo.setCallEvents(eventRecord);
256             } else {
257                 android.telecom.Log.w(LOGUTILS_TAG, "Could not get Analytics CallInfo.");
258             }
259         } else {
260             android.telecom.Log.w(LOGUTILS_TAG, "Non-Call EventRecord Added.");
261         }
262     }
263 
initLogging(Context context)264     public static void initLogging(Context context) {
265         android.telecom.Log.setTag(TAG);
266         android.telecom.Log.setSessionContext(context);
267         for (EventManager.TimedEventPair p : Events.Timings.sTimedEvents) {
268             android.telecom.Log.addRequestResponsePair(p);
269         }
270         android.telecom.Log.registerEventListener(LogUtils::eventRecordAdded);
271         // Store analytics about recently completed Sessions.
272         android.telecom.Log.registerSessionListener(Analytics::addSessionTiming);
273     }
274 }
275