Skip to content

Commit

Permalink
[firebase_core] set user agent (firebase#1582)
Browse files Browse the repository at this point in the history
* Send Android user agent to Firebase
  • Loading branch information
kroikie authored and collinjackson committed May 14, 2019
1 parent 9eaf22b commit c3afcab
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ task:
- git fetch origin master
activate_script: pub global activate flutter_plugin_tools
matrix:
- name: hard_coded_version
script: ./script/check_hard_coded_version.sh
- name: publishable
script: ./script/check_publish.sh
- name: test+format
Expand Down
4 changes: 4 additions & 0 deletions packages/firebase_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.0+1

* Send user agent to Firebase.

## 0.4.0

* Update Android dependencies to latest.
Expand Down
1 change: 1 addition & 0 deletions packages/firebase_core/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ android {
}
dependencies {
api 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-common:16.1.0'
}
}
6 changes: 6 additions & 0 deletions packages/firebase_core/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.firebase.core">
<application>
<service android:name="com.google.firebase.components.ComponentDiscoveryService">
<meta-data android:name="com.google.firebase.components:io.flutter.plugins.firebase.core.FlutterFirebaseAppRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.flutter.plugins.firebase.core;

import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentRegistrar;
import com.google.firebase.platforminfo.LibraryVersionComponent;
import java.util.Collections;
import java.util.List;

public class FlutterFirebaseAppRegistrar implements ComponentRegistrar {
private static final String LIBRARY_NAME = "flutter-firebase_core";
private static final String LIBRARY_VERSION = "0.4.0+1";

@Override
public List<Component<?>> getComponents() {
return Collections.<Component<?>>singletonList(
LibraryVersionComponent.create(LIBRARY_NAME, LIBRARY_VERSION));
}
}
8 changes: 8 additions & 0 deletions packages/firebase_core/ios/Classes/FirebaseCorePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#import <Firebase/Firebase.h>

#define LIBRARY_NAME @"flutter-firebase_core"
#define LIBRARY_VERSION @"0.4.0+1"

static NSDictionary *getDictionaryFromFIROptions(FIROptions *options) {
if (!options) {
return nil;
Expand Down Expand Up @@ -39,6 +42,11 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
binaryMessenger:[registrar messenger]];
FLTFirebaseCorePlugin *instance = [[FLTFirebaseCorePlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];

SEL sel = NSSelectorFromString(@"registerLibrary:withVersion:");
if ([FIRApp respondsToSelector:sel]) {
[FIRApp performSelector:sel withObject:LIBRARY_NAME withObject:LIBRARY_VERSION];
}
}

- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Core, enabling connecting to multiple
Firebase apps.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_core
version: 0.4.0
version: 0.4.0+1

flutter:
plugin:
Expand Down
48 changes: 48 additions & 0 deletions script/check_hard_coded_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
set -e

# This script checks to make sure that if LIBRARY_VERSION is hard coded, it is set
# to match the version in pubspec.yaml. This allows plugins to report their version
# for analytics purposes. See https://github.com/flutter/flutter/issues/32267

# So that users can run this script from anywhere and it will work as expected.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"

source "$SCRIPT_DIR/common.sh"

function check_hard_coded_version() {
local failures=()
for package_name in "$@"; do
local dir="$REPO_DIR/packages/$package_name"
echo "Checking that $package_name has the correct hard coded version, if any."
PACKAGE_VERSION="$(cd "$dir" && cat pubspec.yaml | grep -E "^version: " | awk '{print $2}')"
IOS_VERSION="$(cd "$dir" && grep -r "#define LIBRARY_VERSION" ios/Classes/*.m | awk '{print $3}')"
ANDROID_VERSION="$(cd "$dir" && grep -r LIBRARY_VERSION android/src/main/java/* | awk '{print $8}')"
if [[ "$IOS_VERSION" == 0 && "$ANDROID_VERSION" == 0 ]]; then
echo "No hard coded version found"
elif [[ "$IOS_VERSION" == "@\"$PACKAGE_VERSION\"" && "$ANDROID_VERSION" == "\"$PACKAGE_VERSION\";" ]]; then
echo "Hard coded version matched: $PACKAGE_VERSION"
else
error "Hard coded version check failed for $package_name"
error "pubspec.yaml version: $PACKAGE_VERSION"
error "Android version: $ANDROID_VERSION"
error "iOS version: $IOS_VERSION"
failures=("${failures[@]}" "$package_name")
fi
done
if [[ "${#failures[@]}" != 0 ]]; then
error "FAIL: The following ${#failures[@]} package(s) failed the hard coded version check:"
for failure in "${failures[@]}"; do
error "$failure"
done
fi
return "${#failures[@]}"
}

# Sets CHANGED_PACKAGE_LIST
check_changed_packages

if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then
check_hard_coded_version "${CHANGED_PACKAGE_LIST[@]}"
fi

0 comments on commit c3afcab

Please sign in to comment.