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

Implement CrashAnnotator interface for 1P Android #4929

Merged
merged 5 commits into from
Mar 3, 2025

Conversation

hlwarriner
Copy link
Contributor

@hlwarriner hlwarriner commented Feb 20, 2025

The crash context map is extracted from StarboardBridge to a new CrashContext singleton, which @zhongqiliang suggested so that we can avoid making StarboardBridge a singleton at this time. An enum is used to enforce the singleton property.

I still feel that we should enforce the singleton property for the StarboardBridge Java class, as we currently assume that it has a single instance and we enforce this property for its corresponding C++ class. I added a todo comment for us to consider doing this later.

b/383301493

Copy link
Contributor

@yell0wd0g yell0wd0g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, will let others approve.

Any chance of automated testing? : )

Oh do we want to drop the Log.i()? Or is automatically removed from non-debug buids?

@hlwarriner
Copy link
Contributor Author

Changes look good to me, will let others approve.

Sounds good!

Any chance of automated testing? : )

For unit testing, all I can really think of is a unit test for CrashAnnotatorImplFirstParty that would test that CrashAnnotatorImplFirstParty.setString() makes the expected call to starboardBridge.setCrashContext(). I can work on that if you think it's worth it.

For integration/e2e testing, there's an existing coverage gap: YTS tests that key/value pairs passed to this web API are propagated to crash reports, but only for Evergreen platforms. I'll follow up with the YTS team about closing this gap.

Oh do we want to drop the Log.i()? Or is automatically removed from non-debug buids?

From https://source.android.com/docs/core/tests/debug/understanding-logging#log-level-guidelines it sounds like INFO logs are always kept? Anyway, I think it's fine to remove this (and just did).

@hlwarriner
Copy link
Contributor Author

I uploaded #4967 as an alternative approach that we can consider.

I still feel it would be good to enforce the Java StarboardBridge class as a singleton but it sounds like it might take some time for us to verify that it's safe to do so.

@hlwarriner
Copy link
Contributor Author

I uploaded #4967 as an alternative approach that we can consider.

I still feel it would be good to enforce the Java StarboardBridge class as a singleton but it sounds like it might take some time for us to verify that it's safe to do so.

We ended up going with a different approach (see fourth commit in this current PR). #4967 will be closed.

Copy link
Contributor

@johnxwork johnxwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Might worth checking if CrashAnnotatorImplFirstParty and StarboardBridge(CobaltActivity) are triggered on the same thread. We have no guarantee so far that the JavaBridge is on the same thread as the activity(though it's entirely possible). If we need to deal with multi-thread, we could use some mutex.

An enum is used to enforce the singleton property of StarboardBridge.
Based on discussion with haozheng@ and colinliang@ this Java class, like
its C++ counterpart, probably should be treated like a singleton. And
implementing it as a singleton makes it easier for Java callers to use
it.

b/383301493
colinliang@ suggested this approach so that we can avoid enforcing the
singleton property for StarboardBridge at this time. A todo comment is
added to consider doing that later, when we have more time to test it
and ensure that it will not introduce any race conditions.

If/when we do enforce the singleton property for StarboardBridge we can
decide if we want to keep the separate CrashContext singleton or move
the crash context map back into StarboardBridge.
@hlwarriner
Copy link
Contributor Author

LGTM. Might worth checking if CrashAnnotatorImplFirstParty and StarboardBridge(CobaltActivity) are triggered on the same thread. We have no guarantee so far that the JavaBridge is on the same thread as the activity(though it's entirely possible). If we need to deal with multi-thread, we could use some mutex.

That's a great point. I confirmed the clients of CrashContext are currently on the same thread but added a todo comment to add safeguards. Thanks!

@hlwarriner hlwarriner enabled auto-merge (squash) March 3, 2025 20:41
@hlwarriner hlwarriner merged commit 538e25e into youtube:main Mar 3, 2025
144 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on_device Trigger on-device tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants