Skip to content

Commit

Permalink
Merge branch 'main' into fix-6558
Browse files Browse the repository at this point in the history
  • Loading branch information
lehcar09 authored Dec 4, 2024
2 parents 4973d93 + 801bf4d commit 4e5bfc5
Show file tree
Hide file tree
Showing 36 changed files with 190 additions and 110 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/private-mirror-sync.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
name: Private Mirror Sync

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

on:
push:
branches:
- main
workflow_dispatch:
schedule:
- cron: '0 2 * * *'

jobs:
sync:
if: github.repository == 'firebase/firebase-android-sdk'
if: github.repository == 'FirebasePrivate/firebase-android-sdk'
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repository: firebase/firebase-android-sdk
ref: main
fetch-depth: 0
submodules: true

- uses: actions/[email protected]
with:
fetch-depth: 0
submodules: true
token: ${{ secrets.GOOGLE_OSS_BOT_TOKEN }}
committer: google-oss-bot <[email protected]>
- name: Force push HEAD to private repo main branch
run: |
git config --local user.name google-oss-bot
git config --local user.email [email protected]
git remote add mirror https://github.com/FirebasePrivate/firebase-android-sdk.git
git push mirror HEAD:main --force --verbose
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ android {
dependencies {
implementation("com.google.firebase:firebase-common:21.0.0")
implementation("com.google.firebase:firebase-components:18.0.0")
implementation(platform(libs.kotlin.bom))

testImplementation(libs.androidx.core)
testImplementation(libs.androidx.test.junit)
Expand Down
2 changes: 2 additions & 0 deletions firebase-crashlytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Unreleased
* [fixed] Fixed inefficiency in the Kotlin `FirebaseCrashlytics.setCustomKeys` extension.
* [fixed] Execute failure listener outside the main thread [#6535]

# 19.2.1
Expand Down Expand Up @@ -634,3 +635,4 @@ The following release notes describe changes in the new SDK.
from your `AndroidManifest.xml` file.
* [removed] The `fabric.properties` and `crashlytics.properties` files are no
longer supported. Remove them from your app.

Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ class CrashlyticsTests {
Firebase.app.get(UserAgentPublisher::class.java)
}

@Test
fun keyValueBuilder() {
val keyValueBuilder = KeyValueBuilder()
keyValueBuilder.key("hello", "world")
keyValueBuilder.key("hello2", 23)
keyValueBuilder.key("hello3", 0.1)

val result: Map<String, String> = keyValueBuilder.build().keysAndValues

assertThat(result).containsExactly("hello", "world", "hello2", "23", "hello3", "0.1")
}

@Test
fun keyValueBuilder_withCrashlyticsInstance() {
@Suppress("DEPRECATION") val keyValueBuilder = KeyValueBuilder(Firebase.crashlytics)
keyValueBuilder.key("hello", "world")
keyValueBuilder.key("hello2", 23)
keyValueBuilder.key("hello3", 0.1)

val result: Map<String, String> = keyValueBuilder.build().keysAndValues

// The result is empty because it called crashlytics.setCustomKey for every key.
assertThat(result).isEmpty()
}

companion object {
private const val APP_ID = "1:1:android:1a"
private const val API_KEY = "API-KEY-API-KEY-API-KEY-API-KEY-API-KEY"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ public void testWriteUserData_noFields() throws Exception {
}

@Test
// TODO(b/375437048): Let @daymxn know if this test fails. It's flaky and running away from me:(
public void testWriteUserData_singleField() throws Exception {
crashlyticsWorkers.diskWrite.submit(
() -> {
storeUnderTest.writeUserData(SESSION_ID_1, metadataWithUserId(SESSION_ID_1).getUserId());
});
() ->
storeUnderTest.writeUserData(
SESSION_ID_1, metadataWithUserId(SESSION_ID_1).getUserId()));
crashlyticsWorkers.diskWrite.await();
Thread.sleep(10);
UserMetadata userData =
UserMetadata.loadFromExistingSession(SESSION_ID_1, fileStore, crashlyticsWorkers);
assertEquals(USER_ID, userData.getUserId());
Expand Down Expand Up @@ -168,17 +168,15 @@ public void testWriteUserData_unicode() throws Exception {
}

@Test
// TODO(b/375437048): Let @daymxn know if this test fails. It's flaky and running away from me:(
public void testWriteUserData_escaped() throws Exception {
crashlyticsWorkers.diskWrite.submit(
() -> {
storeUnderTest.writeUserData(
SESSION_ID_1, metadataWithUserId(SESSION_ID_1, ESCAPED).getUserId());
});
() ->
storeUnderTest.writeUserData(
SESSION_ID_1, metadataWithUserId(SESSION_ID_1, ESCAPED).getUserId()));
crashlyticsWorkers.diskWrite.await();
Thread.sleep(10);
UserMetadata userData =
UserMetadata.loadFromExistingSession(SESSION_ID_1, fileStore, crashlyticsWorkers);
Thread.sleep(10);
assertEquals(ESCAPED.trim(), userData.getUserId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ val Firebase.crashlytics: FirebaseCrashlytics
get() = FirebaseCrashlytics.getInstance()

/** Associates all key-value parameters with the reports */
fun FirebaseCrashlytics.setCustomKeys(init: KeyValueBuilder.() -> Unit) {
val builder = KeyValueBuilder(this)
builder.init()
}
fun FirebaseCrashlytics.setCustomKeys(init: KeyValueBuilder.() -> Unit) =
setCustomKeys(KeyValueBuilder().apply(init).build())

/** @suppress */
@Keep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,48 @@

package com.google.firebase.crashlytics

/** Helper class to enable fluent syntax in [setCustomKeys] */
class KeyValueBuilder(private val crashlytics: FirebaseCrashlytics) {
/** Helper class to enable convenient syntax in [setCustomKeys] */
class KeyValueBuilder
private constructor(
private val crashlytics: FirebaseCrashlytics?,
private val builder: CustomKeysAndValues.Builder,
) {
@Deprecated(
"Do not construct this directly. Use `setCustomKeys` instead. To be removed in the next major release."
)
constructor(crashlytics: FirebaseCrashlytics) : this(crashlytics, CustomKeysAndValues.Builder())

internal constructor() : this(crashlytics = null, CustomKeysAndValues.Builder())

internal fun build(): CustomKeysAndValues = builder.build()

/** Sets a custom key and value that are associated with reports. */
fun key(key: String, value: Boolean) = crashlytics.setCustomKey(key, value)
fun key(key: String, value: Boolean) {
crashlytics?.setCustomKey(key, value) ?: builder.putBoolean(key, value)
}

/** Sets a custom key and value that are associated with reports. */
fun key(key: String, value: Double) = crashlytics.setCustomKey(key, value)
fun key(key: String, value: Double) {
crashlytics?.setCustomKey(key, value) ?: builder.putDouble(key, value)
}

/** Sets a custom key and value that are associated with reports. */
fun key(key: String, value: Float) = crashlytics.setCustomKey(key, value)
fun key(key: String, value: Float) {
crashlytics?.setCustomKey(key, value) ?: builder.putFloat(key, value)
}

/** Sets a custom key and value that are associated with reports. */
fun key(key: String, value: Int) = crashlytics.setCustomKey(key, value)
fun key(key: String, value: Int) {
crashlytics?.setCustomKey(key, value) ?: builder.putInt(key, value)
}

/** Sets a custom key and value that are associated with reports. */
fun key(key: String, value: Long) = crashlytics.setCustomKey(key, value)
fun key(key: String, value: Long) {
crashlytics?.setCustomKey(key, value) ?: builder.putLong(key, value)
}

/** Sets a custom key and value that are associated with reports. */
fun key(key: String, value: String) = crashlytics.setCustomKey(key, value)
fun key(key: String, value: String) {
crashlytics?.setCustomKey(key, value) ?: builder.putString(key, value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ public void setCustomKey(String key, String value) {
* @throws NullPointerException if any key in keysAndValues is null.
*/
public void setCustomKeys(Map<String, String> keysAndValues) {
crashlyticsWorkers.common.submit(() -> controller.setCustomKeys(keysAndValues));
if (!keysAndValues.isEmpty()) {
crashlyticsWorkers.common.submit(() -> controller.setCustomKeys(keysAndValues));
}
}

// endregion
Expand Down
3 changes: 3 additions & 0 deletions firebase-dataconnect/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Unreleased


# 16.0.0-beta03
* [changed] Requires Data Connect emulator version 1.6.1 or later for code generation.
* [feature] QueryRef and MutationRef gain methods copy(), withDataDeserializer(),
and withVariablesSerializer().
Expand Down
4 changes: 2 additions & 2 deletions firebase-dataconnect/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=16.0.0-beta03
latestReleasedVersion=16.0.0-beta02
version=16.0.0-beta04
latestReleasedVersion=16.0.0-beta03
1 change: 1 addition & 0 deletions firebase-firestore/firebase-firestore.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ dependencies {

testImplementation project(':firebase-database-collection')
testImplementation project(':firebase-firestore')
testProtobuf("com.google.api.grpc:proto-google-common-protos:1.18.0")
testImplementation libs.androidx.test.core
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
testImplementation 'com.google.android.gms:play-services-tasks:18.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.firebase.firestore.util.Preconditions.checkNotNull;

import android.annotation.SuppressLint;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -34,6 +35,7 @@
*
* <p>Do not use this class except for testing purposes.
*/
@SuppressLint("SupportAnnotationUsage")
@VisibleForTesting
final class TestingHooks {

Expand Down
9 changes: 7 additions & 2 deletions firebase-functions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Unreleased
* [fixed] Fixed HttpsCallableResult.data resolution in Kotlin


# 21.1.0
* [changed] Migrated to Kotlin


## Kotlin
The Kotlin extensions library transitively includes the updated
`firebase-functions` library. The Kotlin extensions library has no additional
updates.

# 21.0.0
* [changed] Bump internal dependencies

Expand Down Expand Up @@ -209,4 +215,3 @@ updates.
optional region to override the default "us-central1".
* [feature] New `useFunctionsEmulator` method allows testing against a local
instance of the [Cloud Functions Emulator](https://firebase.google.com/docs/functions/local-emulator).

4 changes: 2 additions & 2 deletions firebase-functions/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=21.1.0
latestReleasedVersion=21.0.0
version=21.1.1
latestReleasedVersion=21.1.0
android.enableUnitTestBinaryResources=true
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ constructor(
appCheckDeferred.whenAvailable { p: Provider<InteropAppCheckTokenProvider> ->
val appCheck = p.get()
appCheckRef.set(appCheck)
appCheck.addAppCheckTokenListener { unused: AppCheckTokenResult? -> }
appCheck.addAppCheckTokenListener {
// Do nothing; we just need to register a listener so that the App Check SDK knows
// to auto-refresh the token.
}
}
}

override fun getContext(limitedUseAppCheckToken: Boolean): Task<HttpsCallableContext?>? {
override fun getContext(getLimitedUseAppCheckToken: Boolean): Task<HttpsCallableContext?>? {
val authToken = getAuthToken()
val appCheckToken = getAppCheckToken(limitedUseAppCheckToken)
val appCheckToken = getAppCheckToken(getLimitedUseAppCheckToken)
return Tasks.whenAll(authToken, appCheckToken).onSuccessTask(executor) { _ ->
Tasks.forResult(
HttpsCallableContext(authToken.result, instanceId.get().token, appCheckToken.result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ internal constructor(
@UiThread uiExecutor: Executor
) {
// The network client to use for HTTPS requests.
private val client: OkHttpClient
private val client: OkHttpClient = OkHttpClient()

// A serializer to encode/decode parameters and return values.
private val serializer: Serializer
private val serializer: Serializer = Serializer()

// A provider of client metadata to include with calls.
private val contextProvider: ContextProvider
private val contextProvider: ContextProvider = Preconditions.checkNotNull(contextProvider)

// The projectId to use for all functions references.
private val projectId: String
private val projectId: String = Preconditions.checkNotNull(projectId)

// The region to use for all function references.
private var region: String? = null
Expand All @@ -82,12 +82,7 @@ internal constructor(
private var emulatorSettings: EmulatedServiceSettings? = null

init {
client = OkHttpClient()
serializer = Serializer()
this.contextProvider = Preconditions.checkNotNull(contextProvider)
this.projectId = Preconditions.checkNotNull(projectId)
val isRegion: Boolean
isRegion =
val isRegion: Boolean =
try {
URL(regionOrCustomDomain)
false
Expand Down Expand Up @@ -182,9 +177,7 @@ internal constructor(
options: HttpsCallOptions
): Task<HttpsCallableResult> {
return providerInstalled.task
.continueWithTask(executor) { task: Task<Void>? ->
contextProvider.getContext(options.limitedUseAppCheckTokens)
}
.continueWithTask(executor) { contextProvider.getContext(options.limitedUseAppCheckTokens) }
.continueWithTask(executor) { task: Task<HttpsCallableContext?> ->
if (!task.isSuccessful) {
return@continueWithTask Tasks.forException<HttpsCallableResult>(task.exception!!)
Expand All @@ -204,9 +197,7 @@ internal constructor(
*/
internal fun call(url: URL, data: Any?, options: HttpsCallOptions): Task<HttpsCallableResult> {
return providerInstalled.task
.continueWithTask(executor) { task: Task<Void>? ->
contextProvider.getContext(options.limitedUseAppCheckTokens)
}
.continueWithTask(executor) { contextProvider.getContext(options.limitedUseAppCheckTokens) }
.continueWithTask(executor) { task: Task<HttpsCallableContext?> ->
if (!task.isSuccessful) {
return@continueWithTask Tasks.forException<HttpsCallableResult>(task.exception!!)
Expand Down Expand Up @@ -277,16 +268,15 @@ internal constructor(
@Throws(IOException::class)
override fun onResponse(ignored: Call, response: Response) {
val code = fromHttpStatus(response.code())
val body = response.body()!!.string()
val exception = fromResponse(code, body, serializer)
val bodyAsString = response.body()!!.string()
val exception = fromResponse(code, bodyAsString, serializer)
if (exception != null) {
tcs.setException(exception)
return
}
val bodyJSON: JSONObject
bodyJSON =
val bodyAsJson: JSONObject =
try {
JSONObject(body)
JSONObject(bodyAsString)
} catch (je: JSONException) {
val e: Exception =
FirebaseFunctionsException(
Expand All @@ -298,10 +288,10 @@ internal constructor(
tcs.setException(e)
return
}
var dataJSON = bodyJSON.opt("data")
var dataJSON = bodyAsJson.opt("data")
// TODO: Allow "result" instead of "data" for now, for backwards compatibility.
if (dataJSON == null) {
dataJSON = bodyJSON.opt("result")
dataJSON = bodyAsJson.opt("result")
}
if (dataJSON == null) {
val e: Exception =
Expand Down
Loading

0 comments on commit 4e5bfc5

Please sign in to comment.