Skip to content
Permalink
Browse files

[Firebase Analytics] Update AGP, remove deprecated method and remove …

…castings (#1938)

* Update AGP and Gradle.

* Remove deprecated Android method setMinimumSessionDuration.

* Removed reduntant casting

* remove `FirebaseAnalyticsAndroid.setAnalyticsCollectionEnabled`
  • Loading branch information...
BugsBunnyBR authored and collinjackson committed Aug 6, 2019
1 parent e8c7c15 commit a2bd1a2d14557aecf3070fd3bee40e23e0a60130
@@ -1,3 +1,11 @@
## 5.0.0

* **Breaking change**. Remove deprecated method `setMinimumSessionDuration`.
* **Breaking change**. Removed `FirebaseAnalyticsAndroid.setAnalyticsCollectionEnabled`. Use
`FirebaseAnalytics.setAnalyticsCollectionEnabled` instead.
* Update Android gradle plugin and gradle version.
* Remove redundant casts on Android.

## 4.0.2

* Update google-services Android gradle plugin to 4.3.0 in documentation and examples.
@@ -21,7 +21,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.4.2'
}
}

@@ -47,17 +47,14 @@ public void onMethodCall(MethodCall call, Result result) {
case "setAnalyticsCollectionEnabled":
handleSetAnalyticsCollectionEnabled(call, result);
break;
case "setMinimumSessionDuration":
handleSetMinimumSessionDuration(call, result);
break;
case "setSessionTimeoutDuration":
handleSetSessionTimeoutDuration(call, result);
break;
case "setUserProperty":
handleSetUserProperty(call, result);
break;
case "resetAnalyticsData":
handleResetAnalyticsData(call, result);
handleResetAnalyticsData(result);
break;
default:
result.notImplemented();
@@ -66,13 +63,10 @@ public void onMethodCall(MethodCall call, Result result) {
}

private void handleLogEvent(MethodCall call, Result result) {
@SuppressWarnings("unchecked")
Map<String, Object> arguments = (Map<String, Object>) call.arguments;
final String eventName = (String) arguments.get("name");

@SuppressWarnings("unchecked")
final Bundle parameterBundle =
createBundleFromMap((Map<String, Object>) arguments.get("parameters"));
final String eventName = call.argument("name");
final Map<String, Object> map = call.argument("parameters");
final Bundle parameterBundle = createBundleFromMap(map);
firebaseAnalytics.logEvent(eventName, parameterBundle);
result.success(null);
}
@@ -84,49 +78,40 @@ private void handleSetUserId(MethodCall call, Result result) {
}

private void handleSetCurrentScreen(MethodCall call, Result result) {
@SuppressWarnings("unchecked")
Activity activity = registrar.activity();
if (activity == null) {
result.error("no_activity", "handleSetCurrentScreen requires a foreground activity", null);
return;
}
Map<String, Object> arguments = (Map<String, Object>) call.arguments;
final String screenName = (String) arguments.get("screenName");
final String screenClassOverride = (String) arguments.get("screenClassOverride");

final String screenName = call.argument("screenName");
final String screenClassOverride = call.argument("screenClassOverride");

firebaseAnalytics.setCurrentScreen(activity, screenName, screenClassOverride);
result.success(null);
}

private void handleSetAnalyticsCollectionEnabled(MethodCall call, Result result) {
final Boolean enabled = (Boolean) call.arguments;
final Boolean enabled = call.arguments();
firebaseAnalytics.setAnalyticsCollectionEnabled(enabled);
result.success(null);
}

private void handleSetMinimumSessionDuration(MethodCall call, Result result) {
final Integer milliseconds = (Integer) call.arguments;
firebaseAnalytics.setMinimumSessionDuration(milliseconds);
result.success(null);
}

private void handleSetSessionTimeoutDuration(MethodCall call, Result result) {
final Integer milliseconds = (Integer) call.arguments;
final Integer milliseconds = call.arguments();
firebaseAnalytics.setSessionTimeoutDuration(milliseconds);
result.success(null);
}

private void handleSetUserProperty(MethodCall call, Result result) {
@SuppressWarnings("unchecked")
Map<String, Object> arguments = (Map<String, Object>) call.arguments;
final String name = (String) arguments.get("name");
final String value = (String) arguments.get("value");
final String name = call.argument("name");
final String value = call.argument("value");

firebaseAnalytics.setUserProperty(name, value);
result.success(null);
}

private void handleResetAnalyticsData(MethodCall call, Result result) {
private void handleResetAnalyticsData(Result result) {
firebaseAnalytics.resetAnalyticsData();
result.success(null);
}
@@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.3.0'
}
}
@@ -1,5 +1,6 @@
#Wed Jul 31 23:52:55 BRT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
@@ -94,11 +94,6 @@ class _MyHomePageState extends State<MyHomePage> {
setMessage('setAnalyticsCollectionEnabled succeeded');
}

Future<void> _testSetMinimumSessionDuration() async {
await analytics.android?.setMinimumSessionDuration(20000);
setMessage('setMinimumSessionDuration succeeded');
}

Future<void> _testSetSessionTimeoutDuration() async {
await analytics.android?.setSessionTimeoutDuration(2000000);
setMessage('setSessionTimeoutDuration succeeded');
@@ -298,10 +293,6 @@ class _MyHomePageState extends State<MyHomePage> {
child: const Text('Test setAnalyticsCollectionEnabled'),
onPressed: _testSetAnalyticsCollectionEnabled,
),
MaterialButton(
child: const Text('Test setMinimumSessionDuration'),
onPressed: _testSetMinimumSessionDuration,
),
MaterialButton(
child: const Text('Test setSessionTimeoutDuration'),
onPressed: _testSetSessionTimeoutDuration,
@@ -25,7 +25,7 @@ void main() {
expect(analytics.android, isNull);
}
if (Platform.isAndroid) {
await analytics.android.setMinimumSessionDuration(9000);
await analytics.android.setSessionTimeoutDuration(1000);
}
});

@@ -24,7 +24,7 @@ class FirebaseAnalytics {
/// Example:
///
/// FirebaseAnalytics analytics = FirebaseAnalytics();
/// analytics.android?.setMinimumSessionDuration(200000);
/// analytics.android?.setSessionTimeoutDuration(true);
final FirebaseAnalyticsAndroid android =
defaultTargetPlatform == TargetPlatform.android
? FirebaseAnalyticsAndroid()
@@ -871,29 +871,6 @@ class FirebaseAnalytics {
class FirebaseAnalyticsAndroid {
final MethodChannel _channel = firebaseChannel;

/// Sets whether analytics collection is enabled for this app on this device.
///
/// This setting is persisted across app sessions. By default it is enabled.
/// Deprecated: Use [FirebaseAnalytics.setAnalyticsCollectionEnabled] instead.
@deprecated
Future<void> setAnalyticsCollectionEnabled(bool enabled) async {
if (enabled == null) {
throw ArgumentError.notNull('enabled');
}
await _channel.invokeMethod<void>('setAnalyticsCollectionEnabled', enabled);
}

/// Sets the minimum engagement time required before starting a session.
///
/// The default value is 10000 (10 seconds).
Future<void> setMinimumSessionDuration(int milliseconds) async {
if (milliseconds == null) {
throw ArgumentError.notNull('milliseconds');
}
await _channel.invokeMethod<void>(
'setMinimumSessionDuration', milliseconds);
}

/// Sets the duration of inactivity that terminates the current session.
///
/// The default value is 1800000 (30 minutes).
@@ -3,7 +3,7 @@ description: Flutter plugin for Google Analytics for Firebase, an app measuremen
solution that provides insight on app usage and user engagement on Android and iOS.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_analytics
version: 4.0.2
version: 5.0.0

flutter:
plugin:
@@ -113,17 +113,6 @@ void main() {
);
});

test('setMinimumSessionDuration', () async {
await analytics.android.setMinimumSessionDuration(123);
expect(
methodCall,
isMethodCall(
'setMinimumSessionDuration',
arguments: 123,
),
);
});

test('setSessionTimeoutDuration', () async {
await analytics.android.setSessionTimeoutDuration(234);
expect(

0 comments on commit a2bd1a2

Please sign in to comment.
You can’t perform that action at this time.