diff options
Diffstat (limited to 'core/java/android/app/ActivityThread.java')
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 39b9d66a9623..6b53cd841dff 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -337,6 +337,8 @@ public final class ActivityThread { Configuration overrideConfig; // Used for consolidating configs before sending on to Activity. private Configuration tmpConfig = new Configuration(); + // Callback used for updating activity override config. + ViewRootImpl.ActivityConfigCallback configCallback; ActivityClientRecord nextIdle; ProfilerInfo profilerInfo; @@ -372,6 +374,14 @@ public final class ActivityThread { stopped = false; hideForNow = false; nextIdle = null; + configCallback = (Configuration overrideConfig, int newDisplayId) -> { + if (activity == null) { + throw new IllegalStateException( + "Received config update for non-existing activity"); + } + activity.mMainThread.handleActivityConfigurationChanged( + new ActivityConfigChangeData(token, overrideConfig), newDisplayId); + }; } public boolean isPreHoneycomb() { @@ -3681,6 +3691,12 @@ public final class ActivityThread { if (r.activity.mVisibleFromClient) { r.activity.makeVisible(); } + final ViewRootImpl viewRoot = r.activity.mDecor.getViewRootImpl(); + if (viewRoot != null) { + // TODO: Figure out the best place to set the callback. + // This looks like a place where decor view is already initialized. + viewRoot.setActivityConfigCallback(r.configCallback); + } } if (!r.onlyLocalRequest) { @@ -5029,7 +5045,7 @@ public final class ActivityThread { * @param displayId Id of the display where activity was moved to, -1 if there was no move and * value didn't change. */ - private void handleActivityConfigurationChanged(ActivityConfigChangeData data, int displayId) { + void handleActivityConfigurationChanged(ActivityConfigChangeData data, int displayId) { ActivityClientRecord r = mActivities.get(data.activityToken); // Check input params. if (r == null || r.activity == null) { @@ -5046,6 +5062,7 @@ public final class ActivityThread { // Perform updates. r.overrideConfig = data.overrideConfig; + final ViewRootImpl viewRoot = r.activity.mDecor.getViewRootImpl(); if (movedToDifferentDisplay) { if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity moved to display, activity:" + r.activityInfo.name + ", displayId=" + displayId @@ -5053,13 +5070,15 @@ public final class ActivityThread { performConfigurationChangedForActivity(r, mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); - final ViewRootImpl viewRoot = r.activity.mDecor.getViewRootImpl(); viewRoot.onMovedToDisplay(displayId); } else { if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " + r.activityInfo.name + ", config=" + data.overrideConfig); performConfigurationChangedForActivity(r, mCompatConfiguration); } + // Notify the ViewRootImpl instance about configuration changes. It may have initiated this + // update to make sure that resources are updated before updating itself. + viewRoot.updateConfiguration(); mSomeActivitiesChanged = true; } @@ -6295,35 +6314,26 @@ public final class ActivityThread { // add dropbox logging to libcore DropBox.setReporter(new DropBoxReporter()); - ViewRootImpl.addConfigCallback(new ComponentCallbacks2() { - @Override - public void onConfigurationChanged(Configuration newConfig) { - synchronized (mResourcesManager) { - // We need to apply this change to the resources - // immediately, because upon returning the view - // hierarchy will be informed about it. - if (mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null)) { - updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), - mResourcesManager.getConfiguration().getLocales()); - - // This actually changed the resources! Tell - // everyone about it. - if (mPendingConfiguration == null || - mPendingConfiguration.isOtherSeqNewer(newConfig)) { - mPendingConfiguration = newConfig; - - sendMessage(H.CONFIGURATION_CHANGED, newConfig); - } + ViewRootImpl.ConfigChangedCallback configChangedCallback + = (Configuration globalConfig) -> { + synchronized (mResourcesManager) { + // We need to apply this change to the resources immediately, because upon returning + // the view hierarchy will be informed about it. + if (mResourcesManager.applyConfigurationToResourcesLocked(globalConfig, + null /* compat */)) { + updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), + mResourcesManager.getConfiguration().getLocales()); + + // This actually changed the resources! Tell everyone about it. + if (mPendingConfiguration == null + || mPendingConfiguration.isOtherSeqNewer(globalConfig)) { + mPendingConfiguration = globalConfig; + sendMessage(H.CONFIGURATION_CHANGED, globalConfig); } } } - @Override - public void onLowMemory() { - } - @Override - public void onTrimMemory(int level) { - } - }); + }; + ViewRootImpl.addConfigCallback(configChangedCallback); } public static ActivityThread systemMain() { |
