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