Skip to content
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

Ensure correct value always collected for activeScreen #1322

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Prefer `calloc()` to `malloc()` in NDK code
[#1320](https://github.com/bugsnag/bugsnag-android/pull/1320)

* Ensure correct value always collected for activeScreen
[#1322](https://github.com/bugsnag/bugsnag-android/pull/1322)

## 5.10.0 (2021-07-14)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion bugsnag-android-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<CurrentIssues>
<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: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 contextState: ContextState, private val logger: Logger )</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 logger: Logger )</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$( config: ImmutableConfig, binaryArch: String?, id: String?, releaseStage: String?, version: String?, codeBundleId: String?, duration: Number?, durationInForeground: Number?, inForeground: Boolean?, isLaunching: Boolean? )</ID>
<ID>LongParameterList:Device.kt$Device$( buildInfo: DeviceBuildInfo, /** * The Application Binary Interface used */ var cpuAbi: Array&lt;String&gt;?, /** * 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 */ var runtimeVersions: MutableMap&lt;String, Any&gt;? )</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,34 @@ class AppDataCollectorTest {
client.sessionTracker,
am,
client.launchCrashTracker,
client.contextState,
NoopLogger
)
val app = collector.getAppDataMetadata()
assertNull(app["backgroundWorkRestricted"])
assertEquals("com.bugsnag.android.core.test", app["processName"] as String)
}

@Test
fun testActiveScreenValue() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
`when`(am.isBackgroundRestricted).thenReturn(false)
}

val collector = AppDataCollector(
context,
context.packageManager,
client.immutableConfig,
client.sessionTracker,
am,
client.launchCrashTracker,
NoopLogger
)
client.context = "Some Custom Context"
client.sessionTracker.updateForegroundTracker("MyActivity", true, 0L)
val app = collector.getAppDataMetadata()
assertEquals("MyActivity", app["activeScreen"] as String)
}

/**
* The flag is set in the app metadata if the user has enabled background restrictions
*/
Expand All @@ -71,7 +91,6 @@ class AppDataCollectorTest {
client.sessionTracker,
am,
client.launchCrashTracker,
client.contextState,
NoopLogger
)
val app = collector.getAppDataMetadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ internal class AppDataCollector(
private val sessionTracker: SessionTracker,
private val activityManager: ActivityManager?,
private val launchCrashTracker: LaunchCrashTracker,
private val contextState: ContextState,
private val logger: Logger
) {
var codeBundleId: String? = null
Expand Down Expand Up @@ -51,7 +50,7 @@ internal class AppDataCollector(
fun getAppDataMetadata(): MutableMap<String, Any?> {
val map = HashMap<String, Any?>()
map["name"] = appName
map["activeScreen"] = contextState.getContext()
map["activeScreen"] = sessionTracker.contextActivity
map["memoryUsage"] = getMemoryUsage()
map["lowMemory"] = isLowMemory()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Unit invoke(Boolean hasConnection, String networkState) {

launchCrashTracker = new LaunchCrashTracker(immutableConfig);
appDataCollector = new AppDataCollector(appContext, appContext.getPackageManager(),
immutableConfig, sessionTracker, am, launchCrashTracker, contextState, logger);
immutableConfig, sessionTracker, am, launchCrashTracker, logger);

// load the device + user information
SharedPrefMigrator sharedPrefMigrator = new SharedPrefMigrator(appContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class AppDataCollectorForegroundTest {
sessionTracker,
null,
launchCrashTracker,
ContextState(),
NoopLogger
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ internal class AppDataCollectorSerializationTest {
sessionTracker,
am,
launchCrashTracker,
ContextState(),
NoopLogger
)
appData.codeBundleId = "foo-99"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ internal class AppMetadataSerializationTest {
`when`(context.packageName).thenReturn("com.example.foo")

// populate metadata fields
val contextState = ContextState()
contextState.setAutomaticContext("MyActivity")
`when`(sessionTracker.contextActivity).thenReturn("MyActivity")
`when`(pm.getApplicationLabel(any())).thenReturn("MyApp")
`when`(pm.getApplicationInfo(any(), anyInt())).thenReturn(ApplicationInfo())

Expand All @@ -52,7 +51,6 @@ internal class AppMetadataSerializationTest {
sessionTracker,
am,
launchCrashTracker,
contextState,
NoopLogger
)
appData.codeBundleId = "foo-99"
Expand Down