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

Service/analyzer process detection is wrong #1153

Closed
andrii-borysov-me opened this issue Dec 19, 2018 · 1 comment
Closed

Service/analyzer process detection is wrong #1153

andrii-borysov-me opened this issue Dec 19, 2018 · 1 comment
Milestone

Comments

@andrii-borysov-me
Copy link

Methods LeakCanary.isInAnalyzerProcess and LeakCanaryInternals.isInServiceProcess don't recognize when they are called in the ":leakcanary" process, if no memory leak has happened yet (or when all memory leaks are fixed).

Steps to reproduce:

  1. Create new android app from "Empty Activity" template.
  2. Add LeakCanary dependency following the Getting Started section.
  3. Add ExampleApplication class with installing LeakCanary following the Getting Started section.
  4. Launch the main app on a device or emulator.
  5. Launch the Leaks app.

Actual result:

  • On step 4, LeakCanary.isInAnalyzerProcess returns false,
  • On step 5, LeakCanary.isInAnalyzerProcess returns false.

Expected result:

  • On step 4, LeakCanary.isInAnalyzerProcess returns false,
  • On step 5, LeakCanary.isInAnalyzerProcess returns true.

The reason of the issue is that the HeapAnalyzerService as well as DisplayLeakService are disabled until any first leak happens, and the method LeakCanaryInternals.isInServiceProcess does not fetch "disabled" components and swallows PackageManager.NameNotFoundException by returning false in this case.

In a simple app, this issue is not critical, but in my case I get java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process *:leakcanary. Make sure to call FirebaseApp.initializeApp(Context) first., which is annoying.

Here is the sample project to reproduce: LeakCanaryCheckProcessIssue.zip

@pyricau
Copy link
Member

pyricau commented Jan 10, 2019

Thanks! Yep, this is definitely a bug.

pyricau added a commit that referenced this issue Jan 10, 2019
…er process

The leak result activity runs in the analyzer process. When starting it prior to any leak having been detected, `LeakCanary.isInAnalyzerProcess` would return false because the component we look for is initially disabled.

Fixes #1153
pyricau added a commit that referenced this issue Jan 10, 2019
…er process (#1161)

The leak result activity runs in the analyzer process. When starting it prior to any leak having been detected, `LeakCanary.isInAnalyzerProcess` would return false because the component we look for is initially disabled.

Fixes #1153
@pyricau pyricau added this to the Next Release milestone Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants