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.incallui.latencyreport; 18 19 import android.os.Bundle; 20 import android.os.SystemClock; 21 22 /** Tracks latency information for a call. */ 23 public class LatencyReport { 24 25 public static final long INVALID_TIME = -1; 26 // The following are hidden constants from android.telecom.TelecomManager. 27 private static final String EXTRA_CALL_CREATED_TIME_MILLIS = 28 "android.telecom.extra.CALL_CREATED_TIME_MILLIS"; 29 private static final String EXTRA_CALL_TELECOM_ROUTING_START_TIME_MILLIS = 30 "android.telecom.extra.CALL_TELECOM_ROUTING_START_TIME_MILLIS"; 31 private static final String EXTRA_CALL_TELECOM_ROUTING_END_TIME_MILLIS = 32 "android.telecom.extra.CALL_TELECOM_ROUTING_END_TIME_MILLIS"; 33 private final boolean wasIncoming; 34 35 // Time elapsed since boot when the call was created by the connection service. 36 private final long createdTimeMillis; 37 38 // Time elapsed since boot when telecom began processing the call. 39 private final long telecomRoutingStartTimeMillis; 40 41 // Time elapsed since boot when telecom finished processing the call. This includes things like 42 // looking up contact info and call blocking but before showing any UI. 43 private final long telecomRoutingEndTimeMillis; 44 45 // Time elapsed since boot when the call was added to the InCallUi. 46 private final long callAddedTimeMillis; 47 48 // Time elapsed since boot when the call was added and call blocking evaluation was completed. 49 private long callBlockingTimeMillis = INVALID_TIME; 50 51 // Time elapsed since boot when the call notification was shown. 52 private long callNotificationTimeMillis = INVALID_TIME; 53 54 // Time elapsed since boot when the InCallUI was shown. 55 private long inCallUiShownTimeMillis = INVALID_TIME; 56 57 // Whether the call was shown to the user as a heads up notification instead of a full screen 58 // UI. 59 private boolean didDisplayHeadsUpNotification; 60 LatencyReport()61 public LatencyReport() { 62 wasIncoming = false; 63 createdTimeMillis = INVALID_TIME; 64 telecomRoutingStartTimeMillis = INVALID_TIME; 65 telecomRoutingEndTimeMillis = INVALID_TIME; 66 callAddedTimeMillis = SystemClock.elapsedRealtime(); 67 } 68 LatencyReport(android.telecom.Call telecomCall)69 public LatencyReport(android.telecom.Call telecomCall) { 70 wasIncoming = telecomCall.getState() == android.telecom.Call.STATE_RINGING; 71 Bundle extras = telecomCall.getDetails().getIntentExtras(); 72 if (extras == null) { 73 createdTimeMillis = INVALID_TIME; 74 telecomRoutingStartTimeMillis = INVALID_TIME; 75 telecomRoutingEndTimeMillis = INVALID_TIME; 76 } else { 77 createdTimeMillis = extras.getLong(EXTRA_CALL_CREATED_TIME_MILLIS, INVALID_TIME); 78 telecomRoutingStartTimeMillis = 79 extras.getLong(EXTRA_CALL_TELECOM_ROUTING_START_TIME_MILLIS, INVALID_TIME); 80 telecomRoutingEndTimeMillis = 81 extras.getLong(EXTRA_CALL_TELECOM_ROUTING_END_TIME_MILLIS, INVALID_TIME); 82 } 83 callAddedTimeMillis = SystemClock.elapsedRealtime(); 84 } 85 getWasIncoming()86 public boolean getWasIncoming() { 87 return wasIncoming; 88 } 89 getCreatedTimeMillis()90 public long getCreatedTimeMillis() { 91 return createdTimeMillis; 92 } 93 getTelecomRoutingStartTimeMillis()94 public long getTelecomRoutingStartTimeMillis() { 95 return telecomRoutingStartTimeMillis; 96 } 97 getTelecomRoutingEndTimeMillis()98 public long getTelecomRoutingEndTimeMillis() { 99 return telecomRoutingEndTimeMillis; 100 } 101 getCallAddedTimeMillis()102 public long getCallAddedTimeMillis() { 103 return callAddedTimeMillis; 104 } 105 getCallBlockingTimeMillis()106 public long getCallBlockingTimeMillis() { 107 return callBlockingTimeMillis; 108 } 109 onCallBlockingDone()110 public void onCallBlockingDone() { 111 if (callBlockingTimeMillis == INVALID_TIME) { 112 callBlockingTimeMillis = SystemClock.elapsedRealtime(); 113 } 114 } 115 getCallNotificationTimeMillis()116 public long getCallNotificationTimeMillis() { 117 return callNotificationTimeMillis; 118 } 119 onNotificationShown()120 public void onNotificationShown() { 121 if (callNotificationTimeMillis == INVALID_TIME) { 122 callNotificationTimeMillis = SystemClock.elapsedRealtime(); 123 } 124 } 125 getInCallUiShownTimeMillis()126 public long getInCallUiShownTimeMillis() { 127 return inCallUiShownTimeMillis; 128 } 129 onInCallUiShown(boolean forFullScreenIntent)130 public void onInCallUiShown(boolean forFullScreenIntent) { 131 if (inCallUiShownTimeMillis == INVALID_TIME) { 132 inCallUiShownTimeMillis = SystemClock.elapsedRealtime(); 133 didDisplayHeadsUpNotification = wasIncoming && !forFullScreenIntent; 134 } 135 } 136 getDidDisplayHeadsUpNotification()137 public boolean getDidDisplayHeadsUpNotification() { 138 return didDisplayHeadsUpNotification; 139 } 140 } 141