Skip to content

Commit

Permalink
Merge pull request #1836 from bugsnag/tms/bs-5
Browse files Browse the repository at this point in the history
Reduce BS slots to 5
  • Loading branch information
twometresteve authored and YYChen01988 committed Apr 28, 2023
2 parents 11eaf73 + a52a95b commit 48ae161
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .buildkite/pipeline.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ steps:
- "--fail-fast"
env:
TEST_FIXTURE_SYMBOL_DIR: "build/fixture-r19"
concurrency: 24
concurrency: 5
concurrency_group: 'browserstack-app'
concurrency_method: eager

Expand All @@ -360,7 +360,7 @@ steps:
- "--fail-fast"
env:
TEST_FIXTURE_SYMBOL_DIR: "build/fixture-r19"
concurrency: 24
concurrency: 5
concurrency_group: 'browserstack-app'
concurrency_method: eager

Expand All @@ -386,7 +386,7 @@ steps:
- "--fail-fast"
env:
TEST_FIXTURE_SYMBOL_DIR: "build/fixture-r19"
concurrency: 24
concurrency: 5
concurrency_group: 'browserstack-app'
concurrency_method: eager

Expand All @@ -412,7 +412,7 @@ steps:
- "--fail-fast"
env:
TEST_FIXTURE_SYMBOL_DIR: "build/fixture-r19"
concurrency: 24
concurrency: 5
concurrency_group: 'browserstack-app'
concurrency_method: eager

Expand Down
4 changes: 2 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ steps:
- "--device=ANDROID_7_1"
- "--appium-version=1.20.2"
- "--fail-fast"
concurrency: 24
concurrency: 5
concurrency_group: 'browserstack-app'
concurrency_method: eager
env:
Expand All @@ -307,7 +307,7 @@ steps:
- "--device=ANDROID_8_1"
- "--appium-version=1.20.2"
- "--fail-fast"
concurrency: 24
concurrency: 5
concurrency_group: 'browserstack-app'
concurrency_method: eager
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.bugsnag.android

import android.app.ActivityManager
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.test.core.app.ApplicationProvider
import org.junit.Assert.assertEquals
Expand All @@ -10,7 +11,9 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.Mockito.`when`
import org.mockito.junit.MockitoJUnitRunner

Expand Down Expand Up @@ -52,6 +55,7 @@ class AppDataCollectorTest {
)
val app = collector.getAppDataMetadata()
assertNull(app["backgroundWorkRestricted"])
assertNull(app["installer"])
assertEquals("com.bugsnag.android.core.test", app["processName"] as String)
}

Expand Down Expand Up @@ -100,4 +104,26 @@ class AppDataCollectorTest {
assertNull(app["backgroundWorkRestricted"])
}
}

@Test
fun testGetInstallerPackageName() = withBuildSdkInt(Build.VERSION_CODES.Q) {
val packageManager = mock(PackageManager::class.java)
`when`(packageManager.getApplicationLabel(any())).thenReturn("Test App name")

val collector = AppDataCollector(
context,
packageManager,
client.immutableConfig,
client.sessionTracker,
am,
client.launchCrashTracker,
client.memoryTrimState
)

@Suppress("DEPRECATION")
`when`(packageManager.getInstallerPackageName(any())).thenReturn("Test Installer name")

val result = collector.getInstallerPackageName()
assertEquals("Test Installer name", result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bugsnag.android

import android.os.Build

inline fun <R> withBuildSdkInt(sdk: Int, block: () -> R): R {
val build = Build.VERSION::class.java
val sdkInt = build.getDeclaredField("SDK_INT")
.apply { isAccessible = true }

val oldSdkInt = sdkInt.get(null)
sdkInt.set(null, sdk)
try {
return block()
} finally {
sdkInt.set(null, oldSdkInt)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ public DeliveryStatus deliver(@NonNull Session payload,

public static AppWithState generateAppWithState() {
return new AppWithState(generateImmutableConfig(), null, null, null,
null, null, null, null, null, null);
null, null, null, null, null, null, null);
}

public static App generateApp() {
return new App(generateImmutableConfig(), null, null, null, null, null);
return new App(generateImmutableConfig(), null, null, null, null, null, null);
}

static Comparator<FeatureFlag> featureFlagComparator() {
Expand Down
11 changes: 8 additions & 3 deletions bugsnag-android-core/src/main/java/com/bugsnag/android/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ open class App internal constructor(
/**
* The version code of the application set in [Configuration.versionCode]
*/
var versionCode: Number?
var versionCode: Number?,

var installerPackage: String?
) : JsonStream.Streamable {

internal constructor(
Expand All @@ -55,7 +57,8 @@ open class App internal constructor(
id: String?,
releaseStage: String?,
version: String?,
codeBundleId: String?
codeBundleId: String?,
installerPackage: String?
) : this(
binaryArch,
id,
Expand All @@ -64,7 +67,8 @@ open class App internal constructor(
codeBundleId,
config.buildUuid,
config.appType,
config.versionCode
config.versionCode,
installerPackage
)

internal open fun serialiseFields(writer: JsonStream) {
Expand All @@ -76,6 +80,7 @@ open class App internal constructor(
writer.name("type").value(type)
writer.name("version").value(version)
writer.name("versionCode").value(versionCode)
writer.name("installerPackage").value(installerPackage)
}

@Throws(IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.pm.PackageManager
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.os.SystemClock
import android.util.Log
import com.bugsnag.android.internal.ImmutableConfig

/**
Expand All @@ -33,16 +34,17 @@ internal class AppDataCollector(
private val processName = findProcessName()
private val releaseStage = config.releaseStage
private val versionName = config.appVersion ?: config.packageInfo?.versionName
private val installerPackage = getInstallerPackageName()

fun generateApp(): App =
App(config, binaryArch, packageName, releaseStage, versionName, codeBundleId)
App(config, binaryArch, packageName, releaseStage, versionName, codeBundleId, installerPackage)

fun generateAppWithState(): AppWithState {
val inForeground = sessionTracker.isInForeground
val durationInForeground = calculateDurationInForeground(inForeground)

return AppWithState(
config, binaryArch, packageName, releaseStage, versionName, codeBundleId,
config, binaryArch, packageName, releaseStage, versionName, codeBundleId, installerPackage,
getDurationMs(), durationInForeground, inForeground,
launchCrashTracker.isLaunching()
)
Expand All @@ -54,6 +56,7 @@ internal class AppDataCollector(
map["activeScreen"] = sessionTracker.contextActivity
map["lowMemory"] = memoryTrimState.isLowMemory
map["memoryTrimLevel"] = memoryTrimState.trimLevelDescription
map["installerPackage"] = installerPackage

populateRuntimeMemoryMetadata(map)

Expand Down Expand Up @@ -130,6 +133,21 @@ internal class AppDataCollector(
}
}

/**
* The name of installer / vendor package of the app
*/
fun getInstallerPackageName(): String? {
try {
if (VERSION.SDK_INT >= VERSION_CODES.R)
return packageManager?.getInstallSourceInfo(packageName)?.installingPackageName
@Suppress("DEPRECATION")
return packageManager?.getInstallerPackageName(packageName)
} catch (e: Exception) {
Log.i("Installer package name", "Fail getting installer package name: ")
return null
}
}

/**
* Finds the name of the current process, or null if this cannot be found.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AppWithState(
buildUuid: String?,
type: String?,
versionCode: Number?,
installerPackageName: String?,

/**
* The number of milliseconds the application was running before the event occurred
Expand All @@ -36,7 +37,8 @@ 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, installerPackageName) {

internal constructor(
config: ImmutableConfig,
Expand All @@ -45,6 +47,7 @@ class AppWithState(
releaseStage: String?,
version: String?,
codeBundleId: String?,
installerPackage: String?,
duration: Number?,
durationInForeground: Number?,
inForeground: Boolean?,
Expand All @@ -58,6 +61,7 @@ class AppWithState(
config.buildUuid,
config.appType,
config.versionCode,
installerPackage,
duration,
durationInForeground,
inForeground,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ internal class BugsnagEventMapper(
app["buildUUID"] as? String,
app["type"] as? String,
(app["versionCode"] as? Number)?.toInt(),
app["installerPackage"] as? String,
(app["duration"] as? Number)?.toLong(),
(app["durationInForeground"] as? Number)?.toLong(),
app["inForeground"] as? Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bugsnag.android

import android.os.Build

fun <R> withBuildSdkInt(sdk: Int, block: () -> R): R {
val build = Build.VERSION::class.java
val sdkInt = build.getDeclaredField("SDK_INT")
.apply { isAccessible = true }

val oldSdkInt = sdkInt.get(null)
sdkInt.set(null, sdk)
try {
return block()
} finally {
sdkInt.set(null, oldSdkInt)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public DeliveryStatus deliver(@NonNull Session payload,

public static AppWithState generateAppWithState() {
return new AppWithState(generateImmutableConfig(), null, null, null,
null, null, null, null, null, null);
null, null, null, null, null, null, null);
}

public static App generateApp() {
return new App(generateImmutableConfig(), null, null, null, null, null);
return new App(generateImmutableConfig(), null, null, null, null, null, null);
}

static MetadataState generateMetadataState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ internal class AppDataCollectorSerializationTest {
`when`(sessionTracker.contextActivity).thenReturn("MyActivity")
`when`(pm.getApplicationInfo(any(), anyInt())).thenReturn(ApplicationInfo())
`when`(pm.getApplicationLabel(any())).thenReturn("MyApp")
@Suppress("DEPRECATION")
`when`(pm.getInstallerPackageName(any())).thenReturn("test.package.name")

// construct AppDataCollector object
val appData = AppDataCollector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"releaseStage": "test-stage",
"type": "React Native",
"version": "1.2.3",
"versionCode": 55
"versionCode": 55,
"installerPackage": "test.package.name"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "React Native",
"version": "1.2.3",
"versionCode": 55,
"installerPackage": "test.package.name",
"duration": 0,
"durationInForeground": 0,
"inForeground": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public AppWithState deserialize(Map<String, Object> map) {
MapUtils.<String>getOrNull(map, "buildUuid"),
MapUtils.<String>getOrNull(map, "type"),
MapUtils.<Number>getOrNull(map, "versionCode"),
MapUtils.<String>getOrNull(map, "installerPackage"),
MapUtils.<Number>getOrNull(map, "duration"),
MapUtils.<Number>getOrNull(map, "durationInForeground"),
MapUtils.<Boolean>getOrNull(map, "inForeground"),
MapUtils.<Boolean>getOrNull(map, "isLaunching")
);
);
}
}

0 comments on commit 48ae161

Please sign in to comment.