getsentry / sentry-java

A Sentry SDK for Java, Android and other JVM languages.
https://docs.sentry.io/
MIT License
1.15k stars 435 forks source link

Use info from `ApplicationStartInfo` API on Android 15 #3519

Open yogurtearl opened 3 months ago

yogurtearl commented 3 months ago

Problem Statement

Would like to have info provided in ApplicationStartInfo API on Android 15 available thru Sentry.

see https://developer.android.com/about/versions/15/features#app-start-info

Solution Brainstorm

You can use this with if( SDK >= 35 ) and still get useful data about application start up metrics for device running Android 15+.

kahest commented 3 months ago

Thanks @yogurtearl for the feature request - we discussed this (and other features based on new Android 15 APIs) and will likely implement this at some point.

AndroidDeveloperLB commented 3 months ago

How do you use ApplicationStartInfo ? I can't see any docs for how to get an instance of it

markushi commented 3 months ago

@AndroidDeveloperLB The ApplicationStartInfo can be received by registering a ActivityManager.addApplicationStartInfoCompletionListener hook, see the docs for more details.

AndroidDeveloperLB commented 3 months ago

@markushi Thank you! I can see detection of the reason of starting the app, but I can't find which app started it (when it's relevant). Is it possible?

markushi commented 3 months ago

@AndroidDeveloperLB I think what you're looking for is Activity.getReferrer([link](https://developer.android.com/reference/android/app/Activity.html#getReferrer())). In which situations would this be useful for you?

AndroidDeveloperLB commented 3 months ago

@markushi Seems you are correct, but do I need to add visibility to the apps? I wonder if a simple launchable filter will be fine:

<intent>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent>

I think for most cases it should suffice. Anyway, thank you!

romtsn commented 3 months ago

fwiw you can also retrieve it via getHistoricalProcessStartReasons, which would only return the app start infos for your app.

AndroidDeveloperLB commented 3 months ago

@romtsn What do you mean? What is "only return the app start infos for your app" ?

What's the difference between this and addApplicationStartInfoCompletionListener , if I check only the first item in the returned list? Or maybe it's for the previous starts of the app?

kahest commented 3 months ago

We'll investigate this more closely wrt which APIs make sense to use and what additional data they can provide. We'll follow up here