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

Runs initMiscAndroidMetrics from an UI thread in case of connection failure #21171

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

SergeyZhukovsky
Copy link
Member

@SergeyZhukovsky SergeyZhukovsky commented Nov 30, 2023

Resolves brave/brave-browser#34649

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

There are no steps to replicate it.

@SergeyZhukovsky SergeyZhukovsky added CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-ios Do not run CI builds for iOS CI/skip-windows-x64 Do not run CI builds for Windows x64 unused-CI/skip-linux-x64 Do not run CI builds for Linux x64 labels Nov 30, 2023
@SergeyZhukovsky SergeyZhukovsky self-assigned this Nov 30, 2023
Copy link
Contributor

@samartnik samartnik left a comment

Choose a reason for hiding this comment

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

lgtm

@SergeyZhukovsky SergeyZhukovsky force-pushed the android_mojo_connection_error_handler branch from cc80805 to 556b4e6 Compare November 30, 2023 21:47
Copy link
Contributor

[puLL-Merge] - brave/brave-core@21171

The patch appears to pertain to an Android application, most likely a browser given the chrome in the package names and the word Brave in the class name, which is indicative of Brave Browser, a privacy-centric web browser.

File 1: BraveActivity.java

This file seems to represent an activity class for the Brave browser on Android. The Java activity has been modified as follows:

  1. The method initMiscAndroidMetrics() is replaced with initMiscAndroidMetricsFromAWorkerThread(). This new method now calls the original initMiscAndroidMetrics() method from the UI thread. It does this by using the runOnUiThread() method, ensuring that the initMiscAndroidMetrics() method is always run on the UI thread, in line with Android's requirements that UI operations must happen on the main thread.
  2. A call to ThreadUtils.assertOnUiThread(); has been added to initMiscAndroidMetrics(), enforcing that the method should only be executed on the UI thread.
  3. There is an insertion of a + character in front of every other change, which is common in diff outputs to denote new lines being added.

File 2: MiscAndroidMetricsConnectionErrorHandler.java

This file seems to handle a connection error scenario for some metrics-related functionality—specifically, it seems to reconnect to some service or functionality associated with metrics when a connection fails. The patch includes:

  1. Renaming of the delegate method from the default initMiscAndroidMetrics() to initMiscAndroidMetricsFromAWorkerThread(). This ensures that the connection error handler will also use the new method, adhering to the threading model enforced in the BraveActivity.java changes.
  2. Minor edits are made to improve the clarity. For instance, there's an extra newline in between method stubs in the delegate interface, making the code easier to read.

Commit Information:

  • The commit hash is 556b4e6ca07d74661d154fc49d8a5dfdb6391983, a unique identifier for this set of changes.
  • The author of the changes is identified as Serg, with the email serg.zhukovsky@gmail.com.
  • The date associated with the changes is November 30, 2023.
  • The commit message is Runs initMiscAndroidMetrics from an UI thread in case of connection failure, summarizing the intent of the patch: to ensure metric initialization logic runs on the UI thread after a connection failure.

Overall, this patch modifies the initialization of certain metrics-related functionality so that it always happens on the Android UI thread, which is a common pattern in Android development to avoid threading issues like ANRs (Application Not Responding errors) or crashes due to non-thread-safe operations being performed off the UI thread.

It is important to note that in the context of a diff or patch, lines that start with:

  • - indicate the removal of code.
  • + indicate the addition of new code.
  • Lines without + or - at the beginning indicate context code, which is unchanged in this patch but shown to provide context.

@SergeyZhukovsky SergeyZhukovsky merged commit 7698dbc into master Nov 30, 2023
@SergeyZhukovsky SergeyZhukovsky deleted the android_mojo_connection_error_handler branch November 30, 2023 23:59
@SergeyZhukovsky SergeyZhukovsky added this to the 1.63.x - Nightly milestone Nov 30, 2023
brave-builds added a commit that referenced this pull request Dec 8, 2023
kjozwiak pushed a commit that referenced this pull request Dec 9, 2023
…ailure (uplift to 1.62.x) (#21311)

* Uplift of #21171 (squashed) to beta

* Fixes a crash in UsageMonitor when the class doesn't exist anymore

---------

Co-authored-by: Serg <serg.zhukovsky@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-ios Do not run CI builds for iOS CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 unused-CI/skip-linux-x64 Do not run CI builds for Linux x64
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on Promise creation from a worker thread
3 participants