-
Notifications
You must be signed in to change notification settings - Fork 625
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
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e7af8fc
WIP Initial PlatformInfo implementation.
vkryachko 7280e3e
Refactoring and testing
ashwinraghav 34e7600
Moving deps to compile only
ashwinraghav 132c2e5
Merge branch 'master' into multi_platform_info
ashwinraghav 28516a6
Formatting
ashwinraghav 56db574
Review feedback
ashwinraghav 044afd2
Review feedback 2
ashwinraghav ee7539f
Removing swp
ashwinraghav 794be17
MOving to api from compileOnly
ashwinraghav f33a6c7
Review feedback 3
ashwinraghav 3bdff0b
Added library prefix
ashwinraghav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
76 changes: 76 additions & 0 deletions
76
...base-common/src/main/java/com/google/firebase/platforminfo/DefaultUserAgentPublisher.java
This file contains hidden or 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,76 @@ | ||
// 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; | ||
|
||
/** | ||
* Provides a user agent string that captures the SDKs and their corresponding versions. | ||
* | ||
* <p>Example user agent string: "firebase-common/16.1.1 firebase-firestore/16.1.2 | ||
* firebase-database/16.1.2" | ||
*/ | ||
public class DefaultUserAgentPublisher implements UserAgentPublisher { | ||
private final String javaSDKVersionUserAgent; | ||
private final GamesSDKVersionRegistrar gamesSDKRegistrar; | ||
|
||
DefaultUserAgentPublisher( | ||
Set<LibraryVersion> LibraryVersions, GamesSDKVersionRegistrar gamesSDKRegistrar) { | ||
this.javaSDKVersionUserAgent = toUserAgent(LibraryVersions); | ||
this.gamesSDKRegistrar = gamesSDKRegistrar; | ||
} | ||
|
||
/** | ||
* Returns the user agent string that is computed as follows 1. For our JavaSDKs, the string is | ||
* computed in advance since the components framework guarantees that we receive all published | ||
* versions. 2. For our GamesSDKs, the strings are recomputed each time since the registration of | ||
* the versions happens out of band and we take the optimistic approach of recomputing each time. | ||
*/ | ||
@Override | ||
public String getUserAgent() { | ||
if (gamesSDKRegistrar.getRegisteredVersions().isEmpty()) { | ||
return javaSDKVersionUserAgent; | ||
} | ||
|
||
return javaSDKVersionUserAgent + ' ' + toUserAgent(gamesSDKRegistrar.getRegisteredVersions()); | ||
} | ||
|
||
private static String toUserAgent(Set<LibraryVersion> tokens) { | ||
StringBuilder sb = new StringBuilder(); | ||
Iterator<LibraryVersion> iterator = tokens.iterator(); | ||
while (iterator.hasNext()) { | ||
LibraryVersion token = iterator.next(); | ||
sb.append(token.getLibraryName()).append('/').append(token.getVersion()); | ||
if (iterator.hasNext()) { | ||
sb.append(' '); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
/** Creates a component to codify a user agent string that captures SDK versions. */ | ||
public static Component<UserAgentPublisher> component() { | ||
return Component.builder(UserAgentPublisher.class) | ||
.add(Dependency.setOf(LibraryVersion.class)) | ||
.factory( | ||
c -> | ||
new DefaultUserAgentPublisher( | ||
c.setOf(LibraryVersion.class), GamesSDKVersionRegistrar.getInstance())) | ||
.build(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
firebase-common/src/main/java/com/google/firebase/platforminfo/GamesSDKVersionRegistrar.java
This file contains hidden or 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,63 @@ | ||
// 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; | ||
|
||
/** | ||
* In order to allow the C++ and Unity SDKs to publish their versions without the use of the | ||
* components framework, we have a mechanism where the versions can be wired as out of band as side | ||
* effects. See {@link GamesSDKVersionRegistrar#registerVersion(String, String)} | ||
* | ||
* <p>Java libraries should use {@link LibraryVersionComponent#create(String, String)} instead. | ||
*/ | ||
public class GamesSDKVersionRegistrar { | ||
ashwinraghav marked this conversation as resolved.
Show resolved
Hide resolved
ashwinraghav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private final Set<LibraryVersion> infos = new HashSet<>(); | ||
private static volatile GamesSDKVersionRegistrar instance; | ||
ashwinraghav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
GamesSDKVersionRegistrar() {} | ||
|
||
/** | ||
* Thread safe method to publish versions outside of the components mechanics. | ||
* | ||
* <p>It is the responsibility of the caller to register the version at app launch. | ||
*/ | ||
public void registerVersion(String sdkName, String version) { | ||
synchronized (infos) { | ||
infos.add(LibraryVersion.create(sdkName, version)); | ||
} | ||
} | ||
|
||
/** Returns registered versions */ | ||
Set<LibraryVersion> getRegisteredVersions() { | ||
synchronized (infos) { | ||
return Collections.unmodifiableSet(infos); | ||
} | ||
} | ||
|
||
/** Returns an instance of {@link GamesSDKVersionRegistrar} */ | ||
public static GamesSDKVersionRegistrar getInstance() { | ||
if (instance == null) { | ||
ashwinraghav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
synchronized (GamesSDKVersionRegistrar.class) { | ||
if (instance == null) { | ||
instance = new GamesSDKVersionRegistrar(); | ||
} | ||
} | ||
} | ||
return instance; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
firebase-common/src/main/java/com/google/firebase/platforminfo/LibraryVersion.java
This file contains hidden or 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,32 @@ | ||
// 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.auto.value.AutoValue; | ||
import javax.annotation.Nonnull; | ||
|
||
/** The class is not public to ensure other components cannot depend on it. */ | ||
@AutoValue | ||
abstract class LibraryVersion { | ||
static LibraryVersion create(String name, String version) { | ||
return new AutoValue_LibraryVersion(name, version); | ||
} | ||
|
||
@Nonnull | ||
public abstract String getLibraryName(); | ||
|
||
@Nonnull | ||
public abstract String getVersion(); | ||
} |
27 changes: 27 additions & 0 deletions
27
firebase-common/src/main/java/com/google/firebase/platforminfo/LibraryVersionComponent.java
This file contains hidden or 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,27 @@ | ||
// 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; | ||
|
||
/** Factory to create a component that publishes the version of an SDK */ | ||
public class LibraryVersionComponent { | ||
private LibraryVersionComponent() {} | ||
|
||
/** Creates a component that publishes SDK versions */ | ||
public static Component<?> create(String sdkName, String version) { | ||
return Component.intoSet(LibraryVersion.create(sdkName, version), LibraryVersion.class); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
firebase-common/src/main/java/com/google/firebase/platforminfo/UserAgentPublisher.java
This file contains hidden or 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,20 @@ | ||
// 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; | ||
|
||
/** Component that publishes a user agent string */ | ||
public interface UserAgentPublisher { | ||
String getUserAgent(); | ||
} |
16 changes: 16 additions & 0 deletions
16
firebase-common/src/main/java/com/google/firebase/platforminfo/package-info.java
This file contains hidden or 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,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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.