1 /* 2 * Copyright 2020 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.google.android.iwlan.proto; 18 19 import android.net.ipsec.ike.exceptions.IkeIOException; 20 import android.net.ipsec.ike.exceptions.IkeInternalException; 21 import android.util.Log; 22 23 import com.google.android.iwlan.IwlanError; 24 import com.google.android.iwlan.IwlanStatsLog; 25 26 public class MetricsAtom { 27 public static int INVALID_MESSAGE_ID = -1; 28 private static final String TAG = "IwlanMetrics"; 29 30 private int mMessageId; 31 private int mApnType; 32 private boolean mIsHandover; 33 private String mEpdgServerAddress; 34 private int mSourceRat; 35 private boolean mIsCellularRoaming; 36 private boolean mIsNetworkConnected; 37 private int mTransportType; 38 private int mSetupRequestResult; 39 private int mIwlanError; 40 private int mDataCallFailCause; 41 private int mProcessingDurationMillis; 42 private int mEpdgServerSelectionDurationMillis; 43 private int mIkeTunnelEstablishmentDurationMillis; 44 private int mTunnelState; 45 private int mHandoverFailureMode; 46 private int mRetryDurationMillis; 47 private int mWifiSignalValue; 48 private String mIwlanErrorWrappedClassname; 49 private String mIwlanErrorWrappedStackFirstFrame; 50 private int mErrorCountOfSameCause; 51 private boolean mIsNetworkValidated; 52 setMessageId(int messageId)53 public void setMessageId(int messageId) { 54 this.mMessageId = messageId; 55 } 56 setApnType(int apnType)57 public void setApnType(int apnType) { 58 this.mApnType = apnType; 59 } 60 setIsHandover(boolean isHandover)61 public void setIsHandover(boolean isHandover) { 62 this.mIsHandover = isHandover; 63 } 64 setEpdgServerAddress(String epdgServerAddress)65 public void setEpdgServerAddress(String epdgServerAddress) { 66 this.mEpdgServerAddress = epdgServerAddress; 67 } 68 setSourceRat(int sourceRat)69 public void setSourceRat(int sourceRat) { 70 this.mSourceRat = sourceRat; 71 } 72 setIsCellularRoaming(boolean isCellularRoaming)73 public void setIsCellularRoaming(boolean isCellularRoaming) { 74 this.mIsCellularRoaming = isCellularRoaming; 75 } 76 setIsNetworkConnected(boolean isNetworkConnected)77 public void setIsNetworkConnected(boolean isNetworkConnected) { 78 this.mIsNetworkConnected = isNetworkConnected; 79 } 80 setTransportType(int transportType)81 public void setTransportType(int transportType) { 82 this.mTransportType = transportType; 83 } 84 setSetupRequestResult(int setupRequestResult)85 public void setSetupRequestResult(int setupRequestResult) { 86 this.mSetupRequestResult = setupRequestResult; 87 } 88 setIwlanError(int iwlanError)89 public void setIwlanError(int iwlanError) { 90 this.mIwlanError = iwlanError; 91 } 92 setDataCallFailCause(int dataCallFailCause)93 public void setDataCallFailCause(int dataCallFailCause) { 94 this.mDataCallFailCause = dataCallFailCause; 95 } 96 setProcessingDurationMillis(int processingDurationMillis)97 public void setProcessingDurationMillis(int processingDurationMillis) { 98 this.mProcessingDurationMillis = processingDurationMillis; 99 } 100 setEpdgServerSelectionDurationMillis(int epdgServerSelectionDurationMillis)101 public void setEpdgServerSelectionDurationMillis(int epdgServerSelectionDurationMillis) { 102 this.mEpdgServerSelectionDurationMillis = epdgServerSelectionDurationMillis; 103 } 104 setIkeTunnelEstablishmentDurationMillis(int ikeTunnelEstablishmentDurationMillis)105 public void setIkeTunnelEstablishmentDurationMillis(int ikeTunnelEstablishmentDurationMillis) { 106 this.mIkeTunnelEstablishmentDurationMillis = ikeTunnelEstablishmentDurationMillis; 107 } 108 setTunnelState(int tunnelState)109 public void setTunnelState(int tunnelState) { 110 this.mTunnelState = tunnelState; 111 } 112 setHandoverFailureMode(int handoverFailureMode)113 public void setHandoverFailureMode(int handoverFailureMode) { 114 this.mHandoverFailureMode = handoverFailureMode; 115 } 116 setRetryDurationMillis(int retryDurationMillis)117 public void setRetryDurationMillis(int retryDurationMillis) { 118 this.mRetryDurationMillis = retryDurationMillis; 119 } 120 setWifiSignalValue(int wifiSignalValue)121 public void setWifiSignalValue(int wifiSignalValue) { 122 this.mWifiSignalValue = wifiSignalValue; 123 } 124 setIwlanErrorWrappedClassnameAndStack(IwlanError iwlanError)125 public void setIwlanErrorWrappedClassnameAndStack(IwlanError iwlanError) { 126 Throwable iwlanErrorWrapped = iwlanError.getException(); 127 if (iwlanErrorWrapped instanceof IkeInternalException 128 || iwlanErrorWrapped instanceof IkeIOException) { 129 iwlanErrorWrapped = iwlanErrorWrapped.getCause(); 130 } 131 132 if (iwlanErrorWrapped == null) { 133 this.mIwlanErrorWrappedClassname = null; 134 this.mIwlanErrorWrappedStackFirstFrame = null; 135 return; 136 } 137 138 this.mIwlanErrorWrappedClassname = iwlanErrorWrapped.getClass().getCanonicalName(); 139 140 StackTraceElement[] iwlanErrorWrappedStackTraceElements = iwlanErrorWrapped.getStackTrace(); 141 this.mIwlanErrorWrappedStackFirstFrame = 142 iwlanErrorWrappedStackTraceElements.length != 0 143 ? iwlanErrorWrappedStackTraceElements[0].toString() 144 : null; 145 } 146 getIwlanErrorWrappedClassname()147 public String getIwlanErrorWrappedClassname() { 148 return mIwlanErrorWrappedClassname; 149 } 150 getIwlanErrorWrappedStackFirstFrame()151 public String getIwlanErrorWrappedStackFirstFrame() { 152 return mIwlanErrorWrappedStackFirstFrame; 153 } 154 setErrorCountOfSameCause(int errorCount)155 public void setErrorCountOfSameCause(int errorCount) { 156 mErrorCountOfSameCause = errorCount; 157 } 158 getErrorCountOfSameCause()159 public int getErrorCountOfSameCause() { 160 return mErrorCountOfSameCause; 161 } 162 setIsNetworkValidated(boolean isNetworkValidated)163 public void setIsNetworkValidated(boolean isNetworkValidated) { 164 mIsNetworkValidated = isNetworkValidated; 165 } 166 sendMetricsData()167 public void sendMetricsData() { 168 if (mMessageId == IwlanStatsLog.IWLAN_SETUP_DATA_CALL_RESULT_REPORTED) { 169 Log.d(TAG, "Send metrics data IWLAN_SETUP_DATA_CALL_RESULT_REPORTED"); 170 IwlanStatsLog.write( 171 mMessageId, 172 mApnType, 173 mIsHandover, 174 mEpdgServerAddress, 175 mSourceRat, 176 mIsCellularRoaming, 177 mIsNetworkConnected, 178 mTransportType, 179 mSetupRequestResult, 180 mIwlanError, 181 mDataCallFailCause, 182 mProcessingDurationMillis, 183 mEpdgServerSelectionDurationMillis, 184 mIkeTunnelEstablishmentDurationMillis, 185 mTunnelState, 186 mHandoverFailureMode, 187 mRetryDurationMillis, 188 mIwlanErrorWrappedClassname, 189 mIwlanErrorWrappedStackFirstFrame, 190 mErrorCountOfSameCause, 191 mIsNetworkValidated); 192 } else if (mMessageId == IwlanStatsLog.IWLAN_PDN_DISCONNECTED_REASON_REPORTED) { 193 Log.d(TAG, "Send metrics data IWLAN_PDN_DISCONNECTED_REASON_REPORTED"); 194 IwlanStatsLog.write( 195 mMessageId, 196 mDataCallFailCause, 197 mIsNetworkConnected, 198 mTransportType, 199 mWifiSignalValue); 200 } else { 201 Log.d("IwlanMetrics", "Invalid Message ID: " + mMessageId); 202 } 203 } 204 } 205