diff options
| author | An An Yu <ananyu@google.com> | 2022-10-23 07:21:54 +0000 |
|---|---|---|
| committer | An An Yu <ananyu@google.com> | 2022-11-17 01:13:17 +0000 |
| commit | 4a999424a3f1e3e52bafb810ea0610929693b81c (patch) | |
| tree | 646c95985deb61f7691f05d787dd70b4e759ae96 /core/java/android/window/WindowProviderService.java | |
| parent | f4369fe1f152faa0ca155ffc07490d321db5c8c2 (diff) | |
Add WindowProvider support to WindowLayoutComponentImpl and allow
WindowProviderService to broadcast configuration changes to listeners.
This is needed to allow IME to listen to WindowLayoutInfo changes.
Bug: 237342281
Test: CTS InputMethodServiceTest
Change-Id: Id8ddce5889b52859172caf3b4f0763bb5010b5dc
Diffstat (limited to 'core/java/android/window/WindowProviderService.java')
| -rw-r--r-- | core/java/android/window/WindowProviderService.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/core/java/android/window/WindowProviderService.java b/core/java/android/window/WindowProviderService.java index 2d2c8de72646..fdc3e5af8d8b 100644 --- a/core/java/android/window/WindowProviderService.java +++ b/core/java/android/window/WindowProviderService.java @@ -27,7 +27,10 @@ import android.annotation.UiContext; import android.app.ActivityThread; import android.app.LoadedApk; import android.app.Service; +import android.content.ComponentCallbacks; +import android.content.ComponentCallbacksController; import android.content.Context; +import android.content.res.Configuration; import android.hardware.display.DisplayManager; import android.os.Bundle; import android.os.IBinder; @@ -54,6 +57,8 @@ public abstract class WindowProviderService extends Service implements WindowPro private final WindowContextController mController = new WindowContextController(mWindowToken); private WindowManager mWindowManager; private boolean mInitialized; + private final ComponentCallbacksController mCallbacksController = + new ComponentCallbacksController(); /** * Returns {@code true} if the {@code windowContextOptions} declares that it is a @@ -118,6 +123,48 @@ public abstract class WindowProviderService extends Service implements WindowPro return mOptions; } + @SuppressLint({"OnNameExpected", "ExecutorRegistration"}) + // Suppress lint because this is a legacy named function and doesn't have an optional param + // for executor. + // TODO(b/259347943): Update documentation for U. + /** + * Here we override to prevent WindowProviderService from invoking + * {@link Application.registerComponentCallback}, which will result in callback registered + * for process-level Configuration change updates. + */ + @Override + public void registerComponentCallbacks(@NonNull ComponentCallbacks callback) { + // For broadcasting Configuration Changes. + mCallbacksController.registerCallbacks(callback); + } + + @SuppressLint("OnNameExpected") + @Override + public void unregisterComponentCallbacks(@NonNull ComponentCallbacks callback) { + mCallbacksController.unregisterCallbacks(callback); + } + + @SuppressLint("OnNameExpected") + @Override + public void onConfigurationChanged(@Nullable Configuration configuration) { + // This is only called from WindowTokenClient. + mCallbacksController.dispatchConfigurationChanged(configuration); + } + + /** + * Override {@link Service}'s empty implementation and listen to {@link ActivityThread} for + * low memory and trim memory events. + */ + @Override + public void onLowMemory() { + mCallbacksController.dispatchLowMemory(); + } + + @Override + public void onTrimMemory(int level) { + mCallbacksController.dispatchTrimMemory(level); + } + /** * Returns the display ID to launch this {@link WindowProviderService}. * @@ -181,5 +228,6 @@ public abstract class WindowProviderService extends Service implements WindowPro public void onDestroy() { super.onDestroy(); mController.detachIfNeeded(); + mCallbacksController.clearCallbacks(); } } |
