Report number of bound services |
||||
Issue descriptionThere were number of issues where Chrome was needlessly binding to a service, increasing total OS memory usage. The latest issue is Chrome binding to TTS when playing Youtube video: b/73009067 We need to find a way and report all services that Chrome is bound to (obviously besides renderer / GPU). We can start with reporting this information to slow reports.
,
Feb 7 2018
,
Feb 7 2018
The only thing I can think of is to intercept at Context level. For example in the TTS case android.speech.tts.TextToSpeech is instantiated with ContextUtils.getApplicationContext(). So the idea is as follows: * For all ContextWrapper subclasses (Application, Activity, Service) override attachBaseContext() and wrap the provided context in a wrapper. * The wrapper overrides bindService() and on each call adds an entry into "bound" list. * bindService() also wraps provided ServiceConnection to intercept onServiceDisconnected() calls. * onServiceDisconnected() removes an entry from "bound" list. That way at any point in time we can get list of bound services.
,
Feb 7 2018
ContextWrapper is going to break any code that tries to cast a context to the subtype like Activity/Application etc. It's hard to wrap everything being passed around. You also have to handle the case where the activity goes away, which implies unbinding anything that's already there. Can we write some kind of test that involves host-side doing adb and checking bindings like this? I assume there's a way to find out this info from adb. No test does this today though...
,
Feb 7 2018
> ContextWrapper is going to break any code that tries to cast a context to the subtype like Activity/Application etc. This should not be a problem, as modifying attachBaseContext() will affect only the context that Activity delegates to. I.e. we'll change Activity.mBase (inherited from ContextWrapper), which is available via getBaseContext(), and generally shouldn't be casted.
,
Feb 7 2018
If the code is aware of ContextWrapper (and code in content and below should be, I hope..), then this isn't a problem. But I see lots of code in src/chrome that isn't aware of ContextWrapper: https://cs.chromium.org/search/?q=%22instanceof+activity%22+file:src/chrome&sq=package:chromium&type=cs
,
Feb 7 2018
The thing is that Activity/Service/Application is-a ContextWrapper. We're just going to change internal context that they are delegating to. That internal context is ContextImpl (hidden Android class) anyway, and nothing in Android casts to ContextImpl. I'm going to prototype a CL, so we can discuss more material thing.
,
Feb 7 2018
that's depending on internal behavior that may or may not hold across all android implementations. only sounds ok if occasionally do this in canary or something, not something we should always do across the board
,
Feb 8 2018
OK, it seems that you're right - see b/27154048, and I missed casts to ContextImpl in ActivityThread. So I guess our best bet is overriding bindService() in all places that we control - Applications, Activities, and Services.
,
Mar 6 2018
We have code that does similar to this with bytecode rewriting. We inject a custom "getResources()" method for anything that extends Context: https://cs.chromium.org/chromium/src/build/android/bytecode/java/org/chromium/bytecode/CustomResourcesClassAdapter.java Sounds like we could do similar for this.
,
Jan 11
Available, but no owner or component? Please find a component, as no one will ever find this without one. |
||||
►
Sign in to add a comment |
||||
Comment 1 by mariakho...@chromium.org
, Feb 7 2018