• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
setMessageId(int messageId)51     public void setMessageId(int messageId) {
52         this.mMessageId = messageId;
53     }
54 
setApnType(int apnType)55     public void setApnType(int apnType) {
56         this.mApnType = apnType;
57     }
58 
setIsHandover(boolean isHandover)59     public void setIsHandover(boolean isHandover) {
60         this.mIsHandover = isHandover;
61     }
62 
setEpdgServerAddress(String epdgServerAddress)63     public void setEpdgServerAddress(String epdgServerAddress) {
64         this.mEpdgServerAddress = epdgServerAddress;
65     }
66 
setSourceRat(int sourceRat)67     public void setSourceRat(int sourceRat) {
68         this.mSourceRat = sourceRat;
69     }
70 
setIsCellularRoaming(boolean isCellularRoaming)71     public void setIsCellularRoaming(boolean isCellularRoaming) {
72         this.mIsCellularRoaming = isCellularRoaming;
73     }
74 
setIsNetworkConnected(boolean isNetworkConnected)75     public void setIsNetworkConnected(boolean isNetworkConnected) {
76         this.mIsNetworkConnected = isNetworkConnected;
77     }
78 
setTransportType(int transportType)79     public void setTransportType(int transportType) {
80         this.mTransportType = transportType;
81     }
82 
setSetupRequestResult(int setupRequestResult)83     public void setSetupRequestResult(int setupRequestResult) {
84         this.mSetupRequestResult = setupRequestResult;
85     }
86 
setIwlanError(int iwlanError)87     public void setIwlanError(int iwlanError) {
88         this.mIwlanError = iwlanError;
89     }
90 
setDataCallFailCause(int dataCallFailCause)91     public void setDataCallFailCause(int dataCallFailCause) {
92         this.mDataCallFailCause = dataCallFailCause;
93     }
94 
setProcessingDurationMillis(int processingDurationMillis)95     public void setProcessingDurationMillis(int processingDurationMillis) {
96         this.mProcessingDurationMillis = processingDurationMillis;
97     }
98 
setEpdgServerSelectionDurationMillis(int epdgServerSelectionDurationMillis)99     public void setEpdgServerSelectionDurationMillis(int epdgServerSelectionDurationMillis) {
100         this.mEpdgServerSelectionDurationMillis = epdgServerSelectionDurationMillis;
101     }
102 
setIkeTunnelEstablishmentDurationMillis(int ikeTunnelEstablishmentDurationMillis)103     public void setIkeTunnelEstablishmentDurationMillis(int ikeTunnelEstablishmentDurationMillis) {
104         this.mIkeTunnelEstablishmentDurationMillis = ikeTunnelEstablishmentDurationMillis;
105     }
106 
setTunnelState(int tunnelState)107     public void setTunnelState(int tunnelState) {
108         this.mTunnelState = tunnelState;
109     }
110 
setHandoverFailureMode(int handoverFailureMode)111     public void setHandoverFailureMode(int handoverFailureMode) {
112         this.mHandoverFailureMode = handoverFailureMode;
113     }
114 
setRetryDurationMillis(int retryDurationMillis)115     public void setRetryDurationMillis(int retryDurationMillis) {
116         this.mRetryDurationMillis = retryDurationMillis;
117     }
118 
setWifiSignalValue(int wifiSignalValue)119     public void setWifiSignalValue(int wifiSignalValue) {
120         this.mWifiSignalValue = wifiSignalValue;
121     }
122 
setIwlanErrorWrappedClassnameAndStack(IwlanError iwlanError)123     public void setIwlanErrorWrappedClassnameAndStack(IwlanError iwlanError) {
124         Throwable iwlanErrorWrapped = iwlanError.getException();
125         if (iwlanErrorWrapped instanceof IkeInternalException
126                 || iwlanErrorWrapped instanceof IkeIOException) {
127             iwlanErrorWrapped = iwlanErrorWrapped.getCause();
128         }
129 
130         if (iwlanErrorWrapped == null) {
131             this.mIwlanErrorWrappedClassname = null;
132             this.mIwlanErrorWrappedStackFirstFrame = null;
133             return;
134         }
135 
136         this.mIwlanErrorWrappedClassname = iwlanErrorWrapped.getClass().getCanonicalName();
137 
138         StackTraceElement[] iwlanErrorWrappedStackTraceElements = iwlanErrorWrapped.getStackTrace();
139         this.mIwlanErrorWrappedStackFirstFrame =
140                 iwlanErrorWrappedStackTraceElements.length != 0
141                         ? iwlanErrorWrappedStackTraceElements[0].toString()
142                         : null;
143     }
144 
getIwlanErrorWrappedClassname()145     public String getIwlanErrorWrappedClassname() {
146         return mIwlanErrorWrappedClassname;
147     }
148 
getIwlanErrorWrappedStackFirstFrame()149     public String getIwlanErrorWrappedStackFirstFrame() {
150         return mIwlanErrorWrappedStackFirstFrame;
151     }
152 
sendMetricsData()153     public void sendMetricsData() {
154         if (mMessageId == IwlanStatsLog.IWLAN_SETUP_DATA_CALL_RESULT_REPORTED) {
155             Log.d(TAG, "Send metrics data IWLAN_SETUP_DATA_CALL_RESULT_REPORTED");
156             IwlanStatsLog.write(
157                     mMessageId,
158                     mApnType,
159                     mIsHandover,
160                     mEpdgServerAddress,
161                     mSourceRat,
162                     mIsCellularRoaming,
163                     mIsNetworkConnected,
164                     mTransportType,
165                     mSetupRequestResult,
166                     mIwlanError,
167                     mDataCallFailCause,
168                     mProcessingDurationMillis,
169                     mEpdgServerSelectionDurationMillis,
170                     mIkeTunnelEstablishmentDurationMillis,
171                     mTunnelState,
172                     mHandoverFailureMode,
173                     mRetryDurationMillis,
174                     mIwlanErrorWrappedClassname,
175                     mIwlanErrorWrappedStackFirstFrame);
176             return;
177         } else if (mMessageId == IwlanStatsLog.IWLAN_PDN_DISCONNECTED_REASON_REPORTED) {
178             Log.d(TAG, "Send metrics data IWLAN_PDN_DISCONNECTED_REASON_REPORTED");
179             IwlanStatsLog.write(
180                     mMessageId,
181                     mDataCallFailCause,
182                     mIsNetworkConnected,
183                     mTransportType,
184                     mWifiSignalValue);
185             return;
186         } else {
187             Log.d("IwlanMetrics", "Invalid Message ID: " + mMessageId);
188             return;
189         }
190     }
191 }
192