Skip to content

LibraryVersion reporting #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firebase-common/firebase-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ android {

multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionName project.version
}
sourceSets {
androidTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import com.google.firebase.internal.DefaultIdTokenListenersCountChangedListener;
import com.google.firebase.internal.InternalTokenProvider;
import com.google.firebase.internal.InternalTokenResult;
import com.google.firebase.platforminfo.DefaultPlatformInfoSupplier;
import com.google.firebase.platforminfo.PlatformInfo;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -536,7 +538,9 @@ protected FirebaseApp(Context applicationContext, String name, FirebaseOptions o
registrars,
Component.of(applicationContext, Context.class),
Component.of(this, FirebaseApp.class),
Component.of(options, FirebaseOptions.class));
Component.of(options, FirebaseOptions.class),
PlatformInfo.component("firebase-common", BuildConfig.VERSION_NAME),
DefaultPlatformInfoSupplier.component());
publisher = componentRuntime.get(Publisher.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void processInstanceComponents() {
for (Map.Entry<Component<?>, Lazy<?>> entry : components.entrySet()) {
Component<?> component = entry.getKey();
if (!component.isValue()) {
return;
continue;
}

Lazy<?> lazy = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.platforminfo;

import com.google.firebase.components.Component;
import com.google.firebase.components.Dependency;
import java.util.Iterator;
import java.util.Set;

public class DefaultPlatformInfoSupplier implements PlatformInfoSupplier {
private final String tokens;

private DefaultPlatformInfoSupplier(Set<PlatformInfoToken> tokens) {
this.tokens = toUserAgent(tokens);
}

@Override
public String getUserAgent() {
if (PlatformInfoCompat.getGlobalInfo().isEmpty()) {
return tokens;
}

return tokens + ' ' + toUserAgent(PlatformInfoCompat.getGlobalInfo());
}

private static String toUserAgent(Set<PlatformInfoToken> tokens) {
StringBuilder sb = new StringBuilder();
Iterator<PlatformInfoToken> iterator = tokens.iterator();
while (iterator.hasNext()) {
PlatformInfoToken token = iterator.next();
sb.append(token.key).append('/').append(token.value);
if (iterator.hasNext()) {
sb.append(' ');
}
}
return sb.toString();
}

public static Component<PlatformInfoSupplier> component() {
return Component.builder(PlatformInfoSupplier.class)
.add(Dependency.setOf(PlatformInfoToken.class))
.factory(c -> new DefaultPlatformInfoSupplier(c.setOf(PlatformInfoToken.class)))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.platforminfo;

import com.google.firebase.components.Component;

public class PlatformInfo {
private PlatformInfo() {}

public static Component<?> component(String key, String value) {
return Component.intoSet(new PlatformInfoToken(key, value), PlatformInfoToken.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.platforminfo;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class PlatformInfoCompat {
private static final Set<PlatformInfoToken> infos = new HashSet<>();

private PlatformInfoCompat() {}

public static void register(String key, String value) {
synchronized (infos) {
infos.add(new PlatformInfoToken(key, value));
}
}

static Set<PlatformInfoToken> getGlobalInfo() {
synchronized (infos) {
return Collections.unmodifiableSet(infos);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.platforminfo;

public interface PlatformInfoSupplier {
String getUserAgent();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.platforminfo;

/** The class is not public to ensure other components cannot depend on it. */
class PlatformInfoToken {
final String key;
final String value;

PlatformInfoToken(String key, String value) {
this.key = key;
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/** @hide */
package com.google.firebase.platforminfo;