Skip to content

Commit

Permalink
Merge 1c9f06f into 250c69f
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 27, 2023
2 parents 250c69f + 1c9f06f commit 109a2b5
Show file tree
Hide file tree
Showing 42 changed files with 2,770 additions and 236 deletions.
2 changes: 1 addition & 1 deletion appcheck/firebase-appcheck-debug-testing/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=17.1.1
latestReleasedVersion=17.0.1
latestReleasedVersion=17.1.0
2 changes: 1 addition & 1 deletion appcheck/firebase-appcheck-debug/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=17.1.1
latestReleasedVersion=17.0.1
latestReleasedVersion=17.1.0
2 changes: 1 addition & 1 deletion appcheck/firebase-appcheck-interop/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=17.1.1
latestReleasedVersion=17.0.1
latestReleasedVersion=17.1.0
2 changes: 1 addition & 1 deletion appcheck/firebase-appcheck-playintegrity/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=17.1.1
latestReleasedVersion=17.0.1
latestReleasedVersion=17.1.0
2 changes: 1 addition & 1 deletion appcheck/firebase-appcheck/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=17.1.1
latestReleasedVersion=17.0.1
latestReleasedVersion=17.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class PostReleasePlugin : Plugin<Project> {
* is set to the current version of said module. After a release, this `version` should be bumped
* up to differentiate between code at HEAD, and the latest released version.
*
* Furthermore, this file may optionally contain a `latestReleasedVersion` variable (if the SDK
* has released). If this property is present, it should be updated to the related version that
* went out during the release.
*
* @see VersionBumpTask
*
* @param project the [Project] to register this task to
Expand All @@ -72,7 +76,9 @@ class PostReleasePlugin : Plugin<Project> {
* @param project the [Project] to register this task to
*/
fun registerMoveUnreleasedChangesTask(project: Project) =
project.tasks.register<MoveUnreleasedChangesTask>("moveUnreleasedChanges")
project.tasks.register<MoveUnreleasedChangesTask>("moveUnreleasedChanges") {
onlyIf("CHANGELOG.md file must be present") { project.file("CHANGELOG.md").exists() }
}

/**
* Registers the `updatePinnedDependencies` for the provided [Project]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,29 @@ import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.provideDelegate

/**
* Bumps the `version` property of the specified [versionFile].
* Bumps the `version` property of the specified [versionFile], and sets the
* `latestReleasedVersion`.
*
* Primarily utilized as a post-release clean up task in which we bump the versions of released
* modules to be one patch higher than their currently released counterparts.
* modules to be one patch higher than their currently released counterparts, and update their
* latest released version.
*
* @see PostReleasePlugin
*
* @property versionFile A [File] that contains the `version` property. Defaults to the
* `gradle.properties` file at the project's root.
* @property releasedVersion A [ModuleVersion] of what to bump from. Defaults to the project
* version.
* @property newVersion A [ModuleVersion] of what to set the version to. Defaults to one patch
* higher than the existing version.
* higher than [releasedVersion]
*/
abstract class VersionBumpTask : DefaultTask() {
@get:[Optional InputFile]
abstract val versionFile: Property<File>

@get:[Optional Input]
abstract val releasedVersion: Property<ModuleVersion>

@get:[Optional Input]
abstract val newVersion: Property<ModuleVersion>

Expand All @@ -50,18 +57,23 @@ abstract class VersionBumpTask : DefaultTask() {
@TaskAction
fun build() {
versionFile.get().rewriteLines {
if (it.startsWith("version=")) "version=${newVersion.get()}" else it
when {
it.startsWith("version=") -> "version=${newVersion.get()}"
it.startsWith("latestReleasedVersion") -> "latestReleasedVersion=${releasedVersion.get()}"
else -> it
}
}
}

fun configure() {
versionFile.convention(project.file("gradle.properties"))
newVersion.convention(computeNewVersion())
releasedVersion.convention(computeReleasedVersion())
newVersion.convention(releasedVersion.map { it.bump() })
}

fun computeNewVersion(): ModuleVersion? {
fun computeReleasedVersion(): ModuleVersion? {
val version: String? by project

return version?.let { ModuleVersion.fromStringOrNull(it)?.bump() }
return version?.let { ModuleVersion.fromStringOrNull(it) }
}
}
195 changes: 195 additions & 0 deletions firebase-common/src/main/java/com/google/firebase/logger/Logger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* Copyright 2023 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.logger

import android.util.Log
import androidx.annotation.VisibleForTesting
import java.util.concurrent.ConcurrentHashMap

/**
* Common logger interface that handles Android logcat logging for Firebase SDKs.
*
* @hide
*/
abstract class Logger
private constructor(
val tag: String,
var enabled: Boolean,
var minLevel: Level,
) {
@JvmOverloads
fun verbose(format: String, vararg args: Any?, throwable: Throwable? = null): Int =
logIfAble(Level.VERBOSE, format, args, throwable = throwable)

@JvmOverloads
fun verbose(msg: String, throwable: Throwable? = null): Int =
logIfAble(Level.VERBOSE, msg, throwable = throwable)

@JvmOverloads
fun debug(format: String, vararg args: Any?, throwable: Throwable? = null): Int =
logIfAble(Level.DEBUG, format, args, throwable = throwable)

@JvmOverloads
fun debug(msg: String, throwable: Throwable? = null): Int =
logIfAble(Level.DEBUG, msg, throwable = throwable)

@JvmOverloads
fun info(format: String, vararg args: Any?, throwable: Throwable? = null): Int =
logIfAble(Level.INFO, format, args, throwable = throwable)

@JvmOverloads
fun info(msg: String, throwable: Throwable? = null): Int =
logIfAble(Level.INFO, msg, throwable = throwable)

@JvmOverloads
fun warn(format: String, vararg args: Any?, throwable: Throwable? = null): Int =
logIfAble(Level.WARN, format, args, throwable = throwable)

@JvmOverloads
fun warn(msg: String, throwable: Throwable? = null): Int =
logIfAble(Level.WARN, msg, throwable = throwable)

@JvmOverloads
fun error(format: String, vararg args: Any?, throwable: Throwable? = null): Int =
logIfAble(Level.ERROR, format, args, throwable = throwable)

@JvmOverloads
fun error(msg: String, throwable: Throwable? = null): Int =
logIfAble(Level.ERROR, msg, throwable = throwable)

/** Log if [enabled] is set and the given level is loggable. */
private fun logIfAble(
level: Level,
format: String,
args: Array<out Any?> = emptyArray(),
throwable: Throwable?,
): Int =
if (enabled && (minLevel.priority <= level.priority || Log.isLoggable(tag, level.priority))) {
log(level, format, args, throwable = throwable)
} else {
0
}

abstract fun log(
level: Level,
format: String,
args: Array<out Any?>,
throwable: Throwable?,
): Int

/** Simple wrapper around [Log]. */
private class AndroidLogger(
tag: String,
enabled: Boolean,
minLevel: Level,
) : Logger(tag, enabled, minLevel) {
override fun log(
level: Level,
format: String,
args: Array<out Any?>,
throwable: Throwable?,
): Int {
val msg = if (args.isEmpty()) format else String.format(format, *args)
return when (level) {
Level.VERBOSE -> throwable?.let { Log.v(tag, msg, throwable) } ?: Log.v(tag, msg)
Level.DEBUG -> throwable?.let { Log.d(tag, msg, throwable) } ?: Log.d(tag, msg)
Level.INFO -> throwable?.let { Log.i(tag, msg, throwable) } ?: Log.i(tag, msg)
Level.WARN -> throwable?.let { Log.w(tag, msg, throwable) } ?: Log.w(tag, msg)
Level.ERROR -> throwable?.let { Log.e(tag, msg, throwable) } ?: Log.e(tag, msg)
}
}
}

/** Fake implementation that allows recording and asserting on log messages. */
@VisibleForTesting
class FakeLogger
internal constructor(
tag: String,
enabled: Boolean,
minLevel: Level,
) : Logger(tag, enabled, minLevel) {
private val record: MutableList<String> = ArrayList()

override fun log(
level: Level,
format: String,
args: Array<out Any?>,
throwable: Throwable?,
): Int {
val logMessage = toLogMessage(level, format, args, throwable = throwable)
println("Log: $logMessage")
record.add(logMessage)
return logMessage.length
}

/** Clear the recorded log messages. */
@VisibleForTesting fun clearLogMessages(): Unit = record.clear()

/** Returns if the record has any message that contains the given [message] as a substring. */
@VisibleForTesting
fun hasLogMessage(message: String): Boolean = record.any { it.contains(message) }

/** Returns if the record has any message that matches the given [predicate]. */
@VisibleForTesting
fun hasLogMessageThat(predicate: (String) -> Boolean): Boolean = record.any(predicate)

/** Builds a log message from all the log params. */
private fun toLogMessage(
level: Level,
format: String,
args: Array<out Any?>,
throwable: Throwable?,
): String {
val msg = if (args.isEmpty()) format else String.format(format, *args)
return throwable?.let { "$level $msg ${Log.getStackTraceString(throwable)}" } ?: "$level $msg"
}
}

/** Log levels with each [priority] that matches [Log]. */
enum class Level(internal val priority: Int) {
VERBOSE(Log.VERBOSE),
DEBUG(Log.DEBUG),
INFO(Log.INFO),
WARN(Log.WARN),
ERROR(Log.ERROR),
}

companion object {
private val loggers = ConcurrentHashMap<String, Logger>()

/** Gets (or creates) the single instance of [Logger] with the given [tag]. */
@JvmStatic
fun getLogger(
tag: String,
enabled: Boolean = true,
minLevel: Level = Level.INFO,
): Logger = loggers.getOrPut(tag) { AndroidLogger(tag, enabled, minLevel) }

/** Sets (or replaces) the instance of [Logger] with the given [tag] for testing purposes. */
@VisibleForTesting
@JvmStatic
fun setupFakeLogger(
tag: String,
enabled: Boolean = true,
minLevel: Level = Level.DEBUG,
): FakeLogger {
val fakeLogger = FakeLogger(tag, enabled, minLevel)
loggers[tag] = fakeLogger
return fakeLogger
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 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.logger;
2 changes: 1 addition & 1 deletion firebase-config/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
#

version=21.5.1
latestReleasedVersion=21.4.1
latestReleasedVersion=21.5.0
android.enableUnitTestBinaryResources=true

2 changes: 1 addition & 1 deletion firebase-crashlytics-ndk/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=18.5.1
latestReleasedVersion=18.4.3
latestReleasedVersion=18.5.0
7 changes: 3 additions & 4 deletions firebase-crashlytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* [fixed] Fixed Flutter and Unity on-demand fatal `setUserIdentifier` behaviour. Github
[#10759](https://github.com/firebase/flutterfire/issues/10759)

# 18.5.0
* [changed] Added Kotlin extensions (KTX) APIs from `com.google.firebase:firebase-crashlytics-ktx`
Expand All @@ -12,8 +13,7 @@
now deprecated. As early as April 2024, we'll no longer release KTX modules. For details, see the
[FAQ about this initiative](https://firebase.google.com/docs/android/kotlin-migration)

* [fixed] Fixed Flutter and Unity on-demand fatal `setUserIdentifier` behaviour. Github
[#10759](https://github.com/firebase/flutterfire/issues/10759)


## Kotlin
The Kotlin extensions library transitively includes the updated
Expand Down Expand Up @@ -520,4 +520,3 @@ 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.

2 changes: 1 addition & 1 deletion firebase-crashlytics/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=18.5.1
latestReleasedVersion=18.4.3
latestReleasedVersion=18.5.0
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -139,18 +138,6 @@ public void testGetTotalRamInBytes() {
Log.d(Logger.TAG, "testGetTotalRam: " + bytes);
}

public void testGetAppProcessInfo() {
final Context context = getContext();
RunningAppProcessInfo info = CommonUtils.getAppProcessInfo(context.getPackageName(), context);
assertNotNull(info);
// It is not possible to test the state of info.importance because the value is not
// always the same under test as it is when the sdk is running in an app. In API 21, the
// importance under test started returning VISIBLE instead of FOREGROUND.

info = CommonUtils.getAppProcessInfo("nonexistant.package.name", context);
assertNull(info);
}

public void testIsRooted() {
// No good way to test the alternate case,
// just want to ensure we can complete the call without an exception here.
Expand Down
Loading

0 comments on commit 109a2b5

Please sign in to comment.