This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[firebase_performance] Refactor and API update of firebase_performance (
- Loading branch information
1 parent
7346a50
commit 90ed52d
Showing
18 changed files
with
1,177 additions
and
680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...roid/src/main/java/io/flutter/plugins/firebaseperformance/FlutterFirebasePerformance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.firebaseperformance; | ||
|
||
import com.google.firebase.perf.FirebasePerformance; | ||
import com.google.firebase.perf.metrics.HttpMetric; | ||
import com.google.firebase.perf.metrics.Trace; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
public class FlutterFirebasePerformance implements MethodChannel.MethodCallHandler { | ||
private static String parseHttpMethod(String httpMethod) { | ||
switch (httpMethod) { | ||
case "HttpMethod.Connect": | ||
return FirebasePerformance.HttpMethod.CONNECT; | ||
case "HttpMethod.Delete": | ||
return FirebasePerformance.HttpMethod.DELETE; | ||
case "HttpMethod.Get": | ||
return FirebasePerformance.HttpMethod.GET; | ||
case "HttpMethod.Head": | ||
return FirebasePerformance.HttpMethod.HEAD; | ||
case "HttpMethod.Options": | ||
return FirebasePerformance.HttpMethod.OPTIONS; | ||
case "HttpMethod.Patch": | ||
return FirebasePerformance.HttpMethod.PATCH; | ||
case "HttpMethod.Post": | ||
return FirebasePerformance.HttpMethod.POST; | ||
case "HttpMethod.Put": | ||
return FirebasePerformance.HttpMethod.PUT; | ||
case "HttpMethod.Trace": | ||
return FirebasePerformance.HttpMethod.TRACE; | ||
default: | ||
throw new IllegalArgumentException(String.format("No HttpMethod for: %s", httpMethod)); | ||
} | ||
} | ||
|
||
private final FirebasePerformance performance; | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
static void getInstance(MethodCall call, MethodChannel.Result result) { | ||
final Integer handle = call.argument("handle"); | ||
FirebasePerformancePlugin.addHandler(handle, new FlutterFirebasePerformance()); | ||
result.success(null); | ||
} | ||
|
||
private FlutterFirebasePerformance() { | ||
this.performance = FirebasePerformance.getInstance(); | ||
} | ||
|
||
@Override | ||
public void onMethodCall(MethodCall call, MethodChannel.Result result) { | ||
switch (call.method) { | ||
case "FirebasePerformance#isPerformanceCollectionEnabled": | ||
isPerformanceCollectionEnabled(result); | ||
break; | ||
case "FirebasePerformance#setPerformanceCollectionEnabled": | ||
setPerformanceCollectionEnabled(call, result); | ||
break; | ||
case "FirebasePerformance#newTrace": | ||
newTrace(call, result); | ||
break; | ||
case "FirebasePerformance#newHttpMetric": | ||
newHttpMetric(call, result); | ||
break; | ||
default: | ||
result.notImplemented(); | ||
} | ||
} | ||
|
||
private void isPerformanceCollectionEnabled(MethodChannel.Result result) { | ||
result.success(performance.isPerformanceCollectionEnabled()); | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
private void setPerformanceCollectionEnabled(MethodCall call, MethodChannel.Result result) { | ||
final Boolean enable = call.argument("enable"); | ||
performance.setPerformanceCollectionEnabled(enable); | ||
|
||
result.success(null); | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
private void newTrace(MethodCall call, MethodChannel.Result result) { | ||
final String name = call.argument("name"); | ||
final Trace trace = performance.newTrace(name); | ||
|
||
final Integer handle = call.argument("traceHandle"); | ||
FirebasePerformancePlugin.addHandler(handle, new FlutterTrace(trace)); | ||
|
||
result.success(null); | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
private void newHttpMetric(MethodCall call, MethodChannel.Result result) { | ||
final String url = call.argument("url"); | ||
final String httpMethod = call.argument("httpMethod"); | ||
|
||
final HttpMetric metric = performance.newHttpMetric(url, parseHttpMethod(httpMethod)); | ||
|
||
final Integer handle = call.argument("httpMetricHandle"); | ||
FirebasePerformancePlugin.addHandler(handle, new FlutterHttpMetric(metric)); | ||
|
||
result.success(null); | ||
} | ||
} |
Oops, something went wrong.
90ed52d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason behind using say "$FirebasePerformance#newHttpMetric" instead of "FirebasePerformance$newHttpMetric" (note the dollar sign) in strings? I am getting errors in production apk, when obfuscation is enabled, since the the class names are replaced with obfuscated ones.
Is there a way I can disable obfuscation for a plugin?
thanks!
90ed52d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sinaso, I typically use
$FirebasePerformance#newHttpMetric
because it makes it easier to update the method channels if a class changes names. A few plugins use this format, but if it causes problems with obfuscating dart code, we may move away from that format.I'm not aware of a way to disable it only for plugins.
I created an issue to track this: flutter/flutter#35764
90ed52d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
90ed52d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sinaso This is fixed in the last version of the plugin. See #1874