Skip to content

Commit

Permalink
Merge pull request #2088 from bugsnag/PLAT-12853/buildUUID-provider
Browse files Browse the repository at this point in the history
Move Build UUID retrieval / calculation into a provider
  • Loading branch information
lemnik authored Oct 7, 2024
2 parents 1832a25 + 8726b17 commit d061f84
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 53 deletions.
27 changes: 19 additions & 8 deletions bugsnag-android-core/api/bugsnag-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,11 @@ public final class com/bugsnag/android/internal/DateUtils {
}

public final class com/bugsnag/android/internal/ImmutableConfig {
public fun <init> (Ljava/lang/String;ZLcom/bugsnag/android/ErrorTypes;ZLcom/bugsnag/android/ThreadSendPolicy;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Set;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lcom/bugsnag/android/Delivery;Lcom/bugsnag/android/EndpointConfiguration;ZJLcom/bugsnag/android/Logger;IIIIJLkotlin/Lazy;ZZZLandroid/content/pm/PackageInfo;Landroid/content/pm/ApplicationInfo;Ljava/util/Collection;)V
public fun <init> (Ljava/lang/String;ZLcom/bugsnag/android/ErrorTypes;ZLcom/bugsnag/android/ThreadSendPolicy;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Set;Ljava/util/Set;Ljava/lang/String;Lcom/bugsnag/android/internal/dag/Provider;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lcom/bugsnag/android/Delivery;Lcom/bugsnag/android/EndpointConfiguration;ZJLcom/bugsnag/android/Logger;IIIIJLkotlin/Lazy;ZZZLandroid/content/pm/PackageInfo;Landroid/content/pm/ApplicationInfo;Ljava/util/Collection;)V
public final fun component1 ()Ljava/lang/String;
public final fun component10 ()Ljava/util/Set;
public final fun component11 ()Ljava/lang/String;
public final fun component12 ()Ljava/lang/String;
public final fun component12 ()Lcom/bugsnag/android/internal/dag/Provider;
public final fun component13 ()Ljava/lang/String;
public final fun component14 ()Ljava/lang/Integer;
public final fun component15 ()Ljava/lang/String;
Expand Down Expand Up @@ -901,8 +901,8 @@ public final class com/bugsnag/android/internal/ImmutableConfig {
public final fun component7 ()Ljava/util/Collection;
public final fun component8 ()Ljava/util/Collection;
public final fun component9 ()Ljava/util/Set;
public final fun copy (Ljava/lang/String;ZLcom/bugsnag/android/ErrorTypes;ZLcom/bugsnag/android/ThreadSendPolicy;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Set;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lcom/bugsnag/android/Delivery;Lcom/bugsnag/android/EndpointConfiguration;ZJLcom/bugsnag/android/Logger;IIIIJLkotlin/Lazy;ZZZLandroid/content/pm/PackageInfo;Landroid/content/pm/ApplicationInfo;Ljava/util/Collection;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static synthetic fun copy$default (Lcom/bugsnag/android/internal/ImmutableConfig;Ljava/lang/String;ZLcom/bugsnag/android/ErrorTypes;ZLcom/bugsnag/android/ThreadSendPolicy;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Set;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lcom/bugsnag/android/Delivery;Lcom/bugsnag/android/EndpointConfiguration;ZJLcom/bugsnag/android/Logger;IIIIJLkotlin/Lazy;ZZZLandroid/content/pm/PackageInfo;Landroid/content/pm/ApplicationInfo;Ljava/util/Collection;ILjava/lang/Object;)Lcom/bugsnag/android/internal/ImmutableConfig;
public final fun copy (Ljava/lang/String;ZLcom/bugsnag/android/ErrorTypes;ZLcom/bugsnag/android/ThreadSendPolicy;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Set;Ljava/util/Set;Ljava/lang/String;Lcom/bugsnag/android/internal/dag/Provider;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lcom/bugsnag/android/Delivery;Lcom/bugsnag/android/EndpointConfiguration;ZJLcom/bugsnag/android/Logger;IIIIJLkotlin/Lazy;ZZZLandroid/content/pm/PackageInfo;Landroid/content/pm/ApplicationInfo;Ljava/util/Collection;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static synthetic fun copy$default (Lcom/bugsnag/android/internal/ImmutableConfig;Ljava/lang/String;ZLcom/bugsnag/android/ErrorTypes;ZLcom/bugsnag/android/ThreadSendPolicy;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Collection;Ljava/util/Set;Ljava/util/Set;Ljava/lang/String;Lcom/bugsnag/android/internal/dag/Provider;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lcom/bugsnag/android/Delivery;Lcom/bugsnag/android/EndpointConfiguration;ZJLcom/bugsnag/android/Logger;IIIIJLkotlin/Lazy;ZZZLandroid/content/pm/PackageInfo;Landroid/content/pm/ApplicationInfo;Ljava/util/Collection;ILjava/lang/Object;)Lcom/bugsnag/android/internal/ImmutableConfig;
public fun equals (Ljava/lang/Object;)Z
public final fun getApiKey ()Ljava/lang/String;
public final fun getAppInfo ()Landroid/content/pm/ApplicationInfo;
Expand All @@ -911,7 +911,7 @@ public final class com/bugsnag/android/internal/ImmutableConfig {
public final fun getAttemptDeliveryOnCrash ()Z
public final fun getAutoDetectErrors ()Z
public final fun getAutoTrackSessions ()Z
public final fun getBuildUuid ()Ljava/lang/String;
public final fun getBuildUuid ()Lcom/bugsnag/android/internal/dag/Provider;
public final fun getDelivery ()Lcom/bugsnag/android/Delivery;
public final fun getDiscardClasses ()Ljava/util/Collection;
public final fun getEnabledBreadcrumbTypes ()Ljava/util/Set;
Expand Down Expand Up @@ -947,9 +947,9 @@ public final class com/bugsnag/android/internal/ImmutableConfig {

public final class com/bugsnag/android/internal/ImmutableConfigKt {
public static final fun convertToImmutableConfig (Lcom/bugsnag/android/Configuration;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static final fun convertToImmutableConfig (Lcom/bugsnag/android/Configuration;Ljava/lang/String;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static final fun convertToImmutableConfig (Lcom/bugsnag/android/Configuration;Ljava/lang/String;Landroid/content/pm/PackageInfo;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static final fun convertToImmutableConfig (Lcom/bugsnag/android/Configuration;Ljava/lang/String;Landroid/content/pm/PackageInfo;Landroid/content/pm/ApplicationInfo;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static final fun convertToImmutableConfig (Lcom/bugsnag/android/Configuration;Lcom/bugsnag/android/internal/dag/Provider;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static final fun convertToImmutableConfig (Lcom/bugsnag/android/Configuration;Lcom/bugsnag/android/internal/dag/Provider;Landroid/content/pm/PackageInfo;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static final fun convertToImmutableConfig (Lcom/bugsnag/android/Configuration;Lcom/bugsnag/android/internal/dag/Provider;Landroid/content/pm/PackageInfo;Landroid/content/pm/ApplicationInfo;)Lcom/bugsnag/android/internal/ImmutableConfig;
public static final fun isInvalidApiKey (Ljava/lang/String;)Z
}

Expand Down Expand Up @@ -1014,3 +1014,14 @@ public abstract class com/bugsnag/android/internal/dag/RunnableProvider : com/bu
public final fun run ()V
}

public final class com/bugsnag/android/internal/dag/ValueProvider : com/bugsnag/android/internal/dag/Provider {
public fun <init> (Ljava/lang/Object;)V
public final fun copy (Ljava/lang/Object;)Lcom/bugsnag/android/internal/dag/ValueProvider;
public static synthetic fun copy$default (Lcom/bugsnag/android/internal/dag/ValueProvider;Ljava/lang/Object;ILjava/lang/Object;)Lcom/bugsnag/android/internal/dag/ValueProvider;
public fun equals (Ljava/lang/Object;)Z
public fun get ()Ljava/lang/Object;
public fun getOrNull ()Ljava/lang/Object;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

6 changes: 3 additions & 3 deletions bugsnag-android-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<ID>CyclomaticComplexMethod:AppDataCollector.kt$AppDataCollector$@SuppressLint("SwitchIntDef") @Suppress("DEPRECATION") private fun getProcessImportance(): String?</ID>
<ID>CyclomaticComplexMethod:ConfigInternal.kt$ConfigInternal$fun getConfigDifferences(): Map&lt;String, Any></ID>
<ID>ImplicitDefaultLocale:DeliveryHeaders.kt$String.format("%02x", byte)</ID>
<ID>LongParameterList:App.kt$App$( /** * The architecture of the running application binary */ var binaryArch: String?, /** * The package name of the application */ var id: String?, /** * The release stage set in [Configuration.releaseStage] */ var releaseStage: String?, /** * The version of the application set in [Configuration.version] */ var version: String?, /** The revision ID from the manifest (React Native apps only) */ var codeBundleId: String?, /** * The unique identifier for the build of the application set in [Configuration.buildUuid] */ var buildUuid: String?, /** * The application type set in [Configuration#version] */ var type: String?, /** * The version code of the application set in [Configuration.versionCode] */ var versionCode: Number? )</ID>
<ID>LongParameterList:App.kt$App$( /** * The architecture of the running application binary */ var binaryArch: String?, /** * The package name of the application */ var id: String?, /** * The release stage set in [Configuration.releaseStage] */ var releaseStage: String?, /** * The version of the application set in [Configuration.version] */ var version: String?, /** The revision ID from the manifest (React Native apps only) */ var codeBundleId: String?, /** * The unique identifier for the build of the application set in [Configuration.buildUuid] */ buildUuid: Provider&lt;String?>?, /** * The application type set in [Configuration#version] */ var type: String?, /** * The version code of the application set in [Configuration.versionCode] */ var versionCode: Number? )</ID>
<ID>LongParameterList:AppDataCollector.kt$AppDataCollector$( appContext: Context, private val packageManager: PackageManager?, private val config: ImmutableConfig, private val sessionTracker: SessionTracker, private val activityManager: ActivityManager?, private val launchCrashTracker: LaunchCrashTracker, private val memoryTrimState: MemoryTrimState )</ID>
<ID>LongParameterList:AppWithState.kt$AppWithState$( binaryArch: String?, id: String?, releaseStage: String?, version: String?, codeBundleId: String?, buildUuid: String?, type: String?, versionCode: Number?, /** * The number of milliseconds the application was running before the event occurred */ var duration: Number?, /** * The number of milliseconds the application was running in the foreground before the * event occurred */ var durationInForeground: Number?, /** * Whether the application was in the foreground when the event occurred */ var inForeground: Boolean?, /** * Whether the application was launching when the event occurred */ var isLaunching: Boolean? )</ID>
<ID>LongParameterList:AppWithState.kt$AppWithState$( binaryArch: String?, id: String?, releaseStage: String?, version: String?, codeBundleId: String?, buildUuid: Provider&lt;String?>?, type: String?, versionCode: Number?, /** * The number of milliseconds the application was running before the event occurred */ var duration: Number?, /** * The number of milliseconds the application was running in the foreground before the * event occurred */ var durationInForeground: Number?, /** * Whether the application was in the foreground when the event occurred */ var inForeground: Boolean?, /** * Whether the application was launching when the event occurred */ var isLaunching: Boolean? )</ID>
<ID>LongParameterList:AppWithState.kt$AppWithState$( binaryArch: String?, id: String?, releaseStage: String?, version: String?, codeBundleId: String?, buildUuid: String?, type: String?, versionCode: Number?, /** * The number of milliseconds the application was running before the event occurred */ duration: Number?, /** * The number of milliseconds the application was running in the foreground before the * event occurred */ durationInForeground: Number?, /** * Whether the application was in the foreground when the event occurred */ inForeground: Boolean?, /** * Whether the application was launching when the event occurred */ isLaunching: Boolean? )</ID>
<ID>LongParameterList:AppWithState.kt$AppWithState$( config: ImmutableConfig, binaryArch: String?, id: String?, releaseStage: String?, version: String?, codeBundleId: String?, duration: Number?, durationInForeground: Number?, inForeground: Boolean?, isLaunching: Boolean? )</ID>
<ID>LongParameterList:DataCollectionModule.kt$DataCollectionModule$( contextModule: ContextModule, configModule: ConfigModule, systemServiceModule: SystemServiceModule, trackerModule: TrackerModule, bgTaskService: BackgroundTaskService, connectivity: Connectivity, deviceIdStore: Provider&lt;DeviceIdStore>, memoryTrimState: MemoryTrimState )</ID>
<ID>LongParameterList:Device.kt$Device$( buildInfo: DeviceBuildInfo, /** * The Application Binary Interface used */ var cpuAbi: Array&lt;String>?, /** * Whether the device has been jailbroken */ var jailbroken: Boolean?, /** * A UUID generated by Bugsnag and used for the individual application on a device */ var id: String?, /** * The IETF language tag of the locale used */ var locale: String?, /** * The total number of bytes of memory on the device */ var totalMemory: Long?, /** * A collection of names and their versions of the primary languages, frameworks or * runtimes that the application is running on */ runtimeVersions: MutableMap&lt;String, Any>? )</ID>
Expand Down Expand Up @@ -59,7 +60,6 @@
<ID>SwallowedException:DeviceIdFilePersistence.kt$DeviceIdFilePersistence$exc: OverlappingFileLockException</ID>
<ID>SwallowedException:EventStore.kt$EventStore$exception: RejectedExecutionException</ID>
<ID>SwallowedException:ForegroundDetector.kt$ForegroundDetector$e: Exception</ID>
<ID>SwallowedException:ImmutableConfig.kt$e: Exception</ID>
<ID>SwallowedException:JsonHelperTest.kt$JsonHelperTest$e: IllegalArgumentException</ID>
<ID>SwallowedException:PluginClient.kt$PluginClient$exc: ClassNotFoundException</ID>
<ID>SwallowedException:SharedPrefMigrator.kt$SharedPrefMigrator$e: RuntimeException</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bugsnag.android
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.bugsnag.android.internal.ImmutableConfig
import com.bugsnag.android.internal.dag.ValueProvider
import junit.framework.TestCase.assertNull
import org.junit.Assert.assertEquals
import org.junit.Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bugsnag.android
import android.content.Context
import android.content.SharedPreferences
import androidx.test.core.app.ApplicationProvider
import com.bugsnag.android.internal.dag.ValueProvider
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
Expand Down
12 changes: 11 additions & 1 deletion bugsnag-android-core/src/main/java/com/bugsnag/android/App.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bugsnag.android

import com.bugsnag.android.internal.ImmutableConfig
import com.bugsnag.android.internal.dag.Provider
import java.io.IOException

/**
Expand Down Expand Up @@ -36,7 +37,7 @@ open class App internal constructor(
/**
* The unique identifier for the build of the application set in [Configuration.buildUuid]
*/
var buildUuid: String?,
buildUuid: Provider<String?>?,

/**
* The application type set in [Configuration#version]
Expand All @@ -49,6 +50,15 @@ open class App internal constructor(
var versionCode: Number?
) : JsonStream.Streamable {

private var buildUuidProvider: Provider<String?>? = buildUuid

var buildUuid: String? = null
get() = field ?: buildUuidProvider?.getOrNull()
set(value) {
field = value
buildUuidProvider = null
}

internal constructor(
config: ImmutableConfig,
binaryArch: String?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.bugsnag.android

import com.bugsnag.android.internal.ImmutableConfig
import com.bugsnag.android.internal.dag.Provider
import com.bugsnag.android.internal.dag.ValueProvider

/**
* Stateful information set by the notifier about your app can be found on this class. These values
* can be accessed and amended if necessary.
*/
class AppWithState(
class AppWithState internal constructor(
binaryArch: String?,
id: String?,
releaseStage: String?,
version: String?,
codeBundleId: String?,
buildUuid: String?,
buildUuid: Provider<String?>?,
type: String?,
versionCode: Number?,

Expand All @@ -36,7 +38,61 @@ class AppWithState(
* Whether the application was launching when the event occurred
*/
var isLaunching: Boolean?
) : App(binaryArch, id, releaseStage, version, codeBundleId, buildUuid, type, versionCode) {
) : App(
binaryArch,
id,
releaseStage,
version,
codeBundleId,
buildUuid,
type,
versionCode
) {

constructor(
binaryArch: String?,
id: String?,
releaseStage: String?,
version: String?,
codeBundleId: String?,
buildUuid: String?,
type: String?,
versionCode: Number?,

/**
* The number of milliseconds the application was running before the event occurred
*/
duration: Number?,

/**
* The number of milliseconds the application was running in the foreground before the
* event occurred
*/
durationInForeground: Number?,

/**
* Whether the application was in the foreground when the event occurred
*/
inForeground: Boolean?,

/**
* Whether the application was launching when the event occurred
*/
isLaunching: Boolean?
) : this(
binaryArch,
id,
releaseStage,
version,
codeBundleId,
buildUuid?.let(::ValueProvider),
type,
versionCode,
duration,
durationInForeground,
inForeground,
isLaunching
)

internal constructor(
config: ImmutableConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.bugsnag.android

import com.bugsnag.android.internal.DateUtils
import com.bugsnag.android.internal.InternalMetricsImpl
import com.bugsnag.android.internal.dag.ValueProvider
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Date
Expand Down Expand Up @@ -151,7 +152,7 @@ internal class BugsnagEventMapper(
app["releaseStage"] as? String,
app["version"] as? String,
app["codeBundleId"] as? String,
app["buildUUID"] as? String,
(app["buildUUID"] as? String)?.let(::ValueProvider),
app["type"] as? String,
(app["versionCode"] as? Number)?.toInt(),
(app["duration"] as? Number)?.toLong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class ClientObservable : BaseObservable() {
conf.apiKey,
conf.enabledErrorTypes.ndkCrashes,
conf.appVersion,
conf.buildUuid,
conf.buildUuid?.getOrNull(),
conf.releaseStage,
lastRunInfoPath,
consecutiveLaunchCrashes,
Expand Down
Loading

0 comments on commit d061f84

Please sign in to comment.