New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 810144 link

Starred by 1 user

Issue metadata

Status: Untriaged
Owner: ----
Cc:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

Report number of bound services

Project Member Reported by dskiba@chromium.org, Feb 7 2018

Issue description

There 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.
 
Is there an API for us to get this information inside Chrome?

I think a key aspect is also when we log this since we can bind and unbind from services through our lifetime.
Cc: lizeb@chromium.org
Cc: boliu@chromium.org
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.


Comment 4 by boliu@chromium.org, 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...
> 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.

Comment 6 by boliu@chromium.org, 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
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.

Comment 8 by boliu@chromium.org, 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
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.
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.
Status: Untriaged (was: Available)
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