diff options
| author | Charles Chen <charlesccchen@google.com> | 2021-03-29 15:53:31 +0800 |
|---|---|---|
| committer | Charles Chen <charlesccchen@google.com> | 2021-04-15 02:45:36 +0000 |
| commit | 49cd50b3fd7e8774dbd15352b3704bb6b9767e8c (patch) | |
| tree | c26a34005e7617a835718fe470129855e4b04fd9 /core/java/android/app/Service.java | |
| parent | a5b660e386c38f61b6cd06ee54619c170da4265b (diff) | |
Introduce WindowProviderService
A Window Provider Service is a Window-Context-like Service which handles
UI
components and is able to obtain the latest configuration.
The differences between a Window Context and a Window Provider Service
is that:
1. It is always associated with the primary display before
attachWindowToken() or WM#addView is called. It is suggested to
render UI
components after calling the APIs mentioned above.
2. A window context registers the listener in constructor and
unregisters it in finalize(), while a window provider service
registers the listener in onCreate() and unregisters in onDestroy().
3. Like the API Context#createWindowContext(int windowType, Bundle
options),
the users of a Window Provider Service need to override
provideWindowType and
provideOptions to pass the attributes.
4. When there's a configuration updates from the server side,
the Service#onConfigurationChanged callback will be invoked.(TBD)
It is suggested to use window context when possible. This class is to
migrate the
Service to show UI components to the window context concept. We can't
migrate them
to WindowContext directly because developers are used to use this kind
of Service as
the container of UI components and may change its property at runtime.
An example is that keyboard developers may apply a new theme by
InputMethodService#getResources#setTheme(newTheme).
Bug: 159767464
Test: atest WindowContextTests#testWindowProviderServiceLifecycle
Change-Id: I7d537fd2d128efa28aa6e771d77aa105fb497672
Diffstat (limited to 'core/java/android/app/Service.java')
| -rw-r--r-- | core/java/android/app/Service.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/core/java/android/app/Service.java b/core/java/android/app/Service.java index 2ceea7f1a6a8..0ab3f2f4be46 100644 --- a/core/java/android/app/Service.java +++ b/core/java/android/app/Service.java @@ -861,6 +861,19 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac } /** + * Creates the base {@link Context} of this {@link Service}. + * Users may override this API to create customized base context. + * + * @see android.window.WindowProviderService WindowProviderService class for example + * @see ContextWrapper#attachBaseContext(Context) + * + * @hide + */ + public Context createServiceBaseContext(ActivityThread mainThread, LoadedApk packageInfo) { + return ContextImpl.createAppContext(mainThread, packageInfo); + } + + /** * @hide * Clean up any references to avoid leaks. */ |
