diff options
| author | Andrii Kulian <akulian@google.com> | 2020-01-27 22:17:31 -0800 |
|---|---|---|
| committer | Charles Chen <charlesccchen@google.com> | 2020-02-21 16:07:32 +0800 |
| commit | 02c0e4d2acc3d207ae5ac98154eff1f421045363 (patch) | |
| tree | e12cbaa7518003967ae728fb2fbc5a73b8750141 /core/java/android/app/WindowTokenClient.java | |
| parent | 80c2e07e001422fdf6ea06b718a1139794e867f8 (diff) | |
Handle config/display changes for WindowContext
Introduce IWindowToken to report config/display changes from
server side. When config change callback is received,
it will update the resources associated with the window token.
Test: WindowContextTests
Bug: 128338354
Bug: 146820733
Change-Id: I871bd78a21dbde1286786e65c340b6259b873660
Diffstat (limited to 'core/java/android/app/WindowTokenClient.java')
| -rw-r--r-- | core/java/android/app/WindowTokenClient.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/core/java/android/app/WindowTokenClient.java b/core/java/android/app/WindowTokenClient.java new file mode 100644 index 000000000000..ed0179bb9839 --- /dev/null +++ b/core/java/android/app/WindowTokenClient.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.app; + +import android.annotation.NonNull; +import android.content.Context; +import android.content.res.Configuration; +import android.os.Bundle; +import android.os.IBinder; + +/** + * Client implementation of {@link IWindowToken}. It can receive configuration change callbacks from + * server when window token config is updated or when it is moved between displays, and update the + * resources associated with this token on the client side. This will make sure that + * {@link WindowContext} instances will have updated resources and configuration. + * @hide + */ +public class WindowTokenClient extends IWindowToken.Stub { + /** + * Attached {@link Context} for this window token to update configuration and resources. + * Initialized by {@link #attachContext(Context)}. + */ + private Context mContext = null; + + private final ResourcesManager mResourcesManager = ResourcesManager.getInstance(); + + /** + * Attaches {@code context} to this {@link WindowTokenClient}. Each {@link WindowTokenClient} + * can only attach one {@link Context}. + * <p>This method must be called before invoking + * {@link android.view.IWindowManager#addWindowTokenWithOptions(IBinder, int, int, Bundle, + * String)}.<p/> + * + * @param context context to be attached + * @throws IllegalStateException if attached context has already existed. + */ + void attachContext(@NonNull Context context) { + if (mContext != null) { + throw new IllegalStateException("Context is already attached."); + } + mContext = context; + ContextImpl impl = ContextImpl.getImpl(mContext); + impl.setResources(impl.createWindowContextResources()); + } + + @Override + public void onConfigurationChanged(Configuration newConfig, int newDisplayId) { + final int currentDisplayId = mContext.getDisplayId(); + final boolean displayChanged = newDisplayId != currentDisplayId; + final Configuration config = new Configuration(mContext.getResources() + .getConfiguration()); + final boolean configChanged = config.isOtherSeqNewer(newConfig) + && config.updateFrom(newConfig) != 0; + if (displayChanged || configChanged) { + // TODO(ag/9789103): update resource manager logic to track non-activity tokens + mResourcesManager.updateResourcesForActivity(asBinder(), config, newDisplayId, + displayChanged); + } + if (displayChanged) { + mContext.updateDisplay(newDisplayId); + } + } +} |
