|
1 | 1 | package com.instabug.flutter.modules;
|
2 | 2 |
|
3 | 3 | import android.util.Log;
|
| 4 | + |
4 | 5 | import androidx.annotation.NonNull;
|
5 | 6 | import androidx.annotation.Nullable;
|
| 7 | + |
6 | 8 | import com.instabug.apm.APM;
|
| 9 | +import com.instabug.apm.InternalAPM; |
| 10 | +import com.instabug.apm.configuration.cp.APMFeature; |
| 11 | +import com.instabug.apm.configuration.cp.FeatureAvailabilityCallback; |
7 | 12 | import com.instabug.apm.model.ExecutionTrace;
|
8 | 13 | import com.instabug.apm.networking.APMNetworkLogger;
|
9 |
| -import com.instabug.apm.networkinterception.cp.APMCPNetworkLog; |
10 | 14 | import com.instabug.flutter.generated.ApmPigeon;
|
11 | 15 | import com.instabug.flutter.util.Reflection;
|
12 | 16 | import com.instabug.flutter.util.ThreadManager;
|
| 17 | + |
13 | 18 | import io.flutter.plugin.common.BinaryMessenger;
|
14 |
| -import org.json.JSONException; |
| 19 | + |
| 20 | +import org.jetbrains.annotations.NotNull; |
15 | 21 | import org.json.JSONObject;
|
| 22 | + |
16 | 23 | import java.lang.reflect.Method;
|
17 | 24 | import java.util.HashMap;
|
18 | 25 | import java.util.Map;
|
19 |
| -import java.util.Objects; |
20 | 26 |
|
21 | 27 | public class ApmApi implements ApmPigeon.ApmHostApi {
|
22 | 28 | private final String TAG = ApmApi.class.getName();
|
@@ -203,69 +209,81 @@ public void networkLogAndroid(@NonNull Map<String, Object> data) {
|
203 | 209 | if (data.containsKey("serverErrorMessage")) {
|
204 | 210 | serverErrorMessage = (String) data.get("serverErrorMessage");
|
205 | 211 | }
|
206 |
| - Boolean w3cc = null; |
207 |
| - Long partialId = null; |
208 |
| - Long etst = null; |
209 |
| - String wgeti = null; |
210 |
| - String wceti = null; |
211 |
| - |
212 |
| - try { |
213 |
| - w3cc = (Boolean) data.get("w3cc"); |
214 | 212 |
|
215 |
| - } catch (Exception e) { |
216 |
| - e.printStackTrace(); |
| 213 | + Method method = Reflection.getMethod(Class.forName("com.instabug.apm.networking.APMNetworkLogger"), "log", long.class, long.class, String.class, String.class, long.class, String.class, String.class, String.class, String.class, String.class, long.class, int.class, String.class, String.class, String.class, String.class); |
| 214 | + if (method != null) { |
| 215 | + method.invoke(apmNetworkLogger, requestStartTime, requestDuration, requestHeaders, requestBody, requestBodySize, requestMethod, requestUrl, requestContentType, responseHeaders, responseBody, responseBodySize, statusCode, responseContentType, errorMessage, gqlQueryName, serverErrorMessage); |
| 216 | + } else { |
| 217 | + Log.e(TAG, "APMNetworkLogger.log was not found by reflection"); |
217 | 218 | }
|
218 | 219 |
|
219 |
| - try { |
220 |
| - partialId = (Long) data.get("partialId"); |
221 |
| - |
222 |
| - } catch (Exception e) { |
223 |
| - e.printStackTrace(); |
224 |
| - } |
| 220 | + } catch (Exception e) { |
| 221 | + e.printStackTrace(); |
| 222 | + } |
| 223 | + } |
225 | 224 |
|
226 |
| - try { |
227 |
| - etst = (Long) data.get("etst"); |
228 | 225 |
|
229 |
| - } catch (Exception e) { |
230 |
| - e.printStackTrace(); |
231 |
| - } |
232 |
| - |
233 |
| - try { |
| 226 | + @Override |
| 227 | + public void startCpUiTrace(@NonNull String screenName, @NonNull Long microTimeStamp, @NonNull Long traceId) { |
| 228 | + try { |
| 229 | + InternalAPM._startUiTraceCP(screenName, microTimeStamp, traceId); |
| 230 | + } catch (Exception e) { |
| 231 | + e.printStackTrace(); |
| 232 | + } |
| 233 | + } |
234 | 234 |
|
235 |
| - wgeti = (String) data.get("wgeti"); |
236 |
| - if (Objects.equals(wgeti, "null")) { |
237 |
| - wgeti = null; |
238 |
| - } |
| 235 | + @Override |
| 236 | + public void reportScreenLoadingCP(@NonNull Long startTimeStampMicro, @NonNull Long durationMicro, @NonNull Long uiTraceId) { |
| 237 | + try { |
| 238 | + InternalAPM._reportScreenLoadingCP(startTimeStampMicro, durationMicro, uiTraceId); |
| 239 | + } catch (Exception e) { |
| 240 | + e.printStackTrace(); |
| 241 | + } |
| 242 | + } |
239 | 243 |
|
240 |
| - } catch (Exception e) { |
241 |
| - e.printStackTrace(); |
242 |
| - } |
| 244 | + @Override |
| 245 | + public void endScreenLoadingCP(@NonNull Long timeStampMicro, @NonNull Long uiTraceId) { |
| 246 | + try { |
| 247 | + InternalAPM._endScreenLoadingCP(timeStampMicro, uiTraceId); |
| 248 | + } catch (Exception e) { |
| 249 | + e.printStackTrace(); |
| 250 | + } |
| 251 | + } |
243 | 252 |
|
| 253 | + @Override |
| 254 | + public void isEndScreenLoadingEnabled(@NonNull ApmPigeon.Result<Boolean> result) { |
| 255 | + isScreenLoadingEnabled(result); |
| 256 | + } |
244 | 257 |
|
245 |
| - try { |
246 |
| - wceti = (String) data.get("wceti"); |
| 258 | + @Override |
| 259 | + public void isEnabled(@NonNull ApmPigeon.Result<Boolean> result) { |
| 260 | + try { |
| 261 | + // TODO: replace true with an actual implementation of APM.isEnabled once implemented |
| 262 | + // in the Android SDK. |
| 263 | + result.success(true); |
| 264 | + } catch (Exception e) { |
| 265 | + e.printStackTrace(); |
| 266 | + } |
| 267 | + } |
247 | 268 |
|
248 |
| - if (Objects.equals(wceti, "null")) { |
249 |
| - wceti = null; |
| 269 | + @Override |
| 270 | + public void isScreenLoadingEnabled(@NonNull ApmPigeon.Result<Boolean> result) { |
| 271 | + try { |
| 272 | + InternalAPM._isFeatureEnabledCP(APMFeature.SCREEN_LOADING, "InstabugCaptureScreenLoading", new FeatureAvailabilityCallback() { |
| 273 | + @Override |
| 274 | + public void invoke(boolean isFeatureAvailable) { |
| 275 | + result.success(isFeatureAvailable); |
250 | 276 | }
|
| 277 | + }); |
| 278 | + } catch (Exception e) { |
| 279 | + e.printStackTrace(); |
| 280 | + } |
| 281 | + } |
251 | 282 |
|
252 |
| - } catch (Exception e) { |
253 |
| - e.printStackTrace(); |
254 |
| - } |
255 |
| - APMCPNetworkLog.W3CExternalTraceAttributes w3cExternalTraceAttributes = |
256 |
| - new APMCPNetworkLog.W3CExternalTraceAttributes( |
257 |
| - w3cc, partialId, etst, wgeti, wceti |
258 |
| - |
259 |
| - ); |
260 |
| - |
261 |
| - |
262 |
| - Method method = Reflection.getMethod(Class.forName("com.instabug.apm.networking.APMNetworkLogger"), "log", long.class, long.class, String.class, String.class, long.class, String.class, String.class, String.class, String.class, String.class, long.class, int.class, String.class, String.class, String.class, String.class,APMCPNetworkLog.W3CExternalTraceAttributes.class); |
263 |
| - if (method != null) { |
264 |
| - method.invoke(apmNetworkLogger, requestStartTime, requestDuration, requestHeaders, requestBody, requestBodySize, requestMethod, requestUrl, requestContentType, responseHeaders, responseBody, responseBodySize, statusCode, responseContentType, errorMessage, gqlQueryName, serverErrorMessage,w3cExternalTraceAttributes); |
265 |
| - } else { |
266 |
| - Log.e(TAG, "APMNetworkLogger.log was not found by reflection"); |
267 |
| - } |
268 |
| - |
| 283 | + @Override |
| 284 | + public void setScreenLoadingEnabled(@NonNull Boolean isEnabled) { |
| 285 | + try { |
| 286 | + APM.setScreenLoadingEnabled(isEnabled); |
269 | 287 | } catch (Exception e) {
|
270 | 288 | e.printStackTrace();
|
271 | 289 | }
|
|
0 commit comments