Skip to content
Commit ff9f017d authored by Samiul Islam's avatar Samiul Islam
Browse files

Add an API to create customized context for Sdk in Sandbox

SdkSandbox needs to load multiple sdk libraries in its process. This is
somewhat analogous to multiple apps sharing the same process, where apps
get their own specific context. SdkSandbox however currently does not
provide sdk-specific contexts to sdks.

Each sdk gets a context wrapper with the sdksandbox's context
as its base. The base context does not represent SDK correctly and any
component using the base context, such as managers for system service,
is thus using wrong information.

The new API allows us to create sdk specific context using sdk's
ApplicationInfo. By modifing the base context directly, instead of
wrapper, we ensure manager components get the correct information.

Ideally, the context should return the sdk's package name when
`Context#getPackageName()` is called, but that breaks permission
checking logic. We therefore keep it same as before and set sandbox app
name as the package name so that SDK get the same permission as sandbox
app.

Since a new LoadedApk instance is generated when the new API is called,
we need to populate the Application context on it. While it would be
ideal to have each sdk context to return their own instance of application
context, since all the context share the same package name, we opted for
the status quo and returned the original unmodified sandbox context as the
application context. We may change this behavior in future after more
investigation.

Only Sandbox process should be using this API, so we guard it using the
process uid. I have verified that while our module code can use this
API, sdk code is unable to find it.

Bug: 255937439
Test: atest SandboxedSdkContextTest (see topic)
Change-Id: I0d96f915c4dac46b760812b616cab635f7159c66
parent 6529d77f
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment