Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1b59ed7 authored by Andrii Kulian's avatar Andrii Kulian Committed by Android (Google) Code Review
Browse files

Merge "Separate global and override config sent to client"

parents edd694e4 44607960
Loading
Loading
Loading
Loading
+38 −28
Original line number Diff line number Diff line
@@ -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) {
        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(newConfig, null)) {
                // 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(newConfig)) {
                            mPendingConfiguration = newConfig;

                            sendMessage(H.CONFIGURATION_CHANGED, newConfig);
                        }
                    }
                }
                    // 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() {
+6 −7
Original line number Diff line number Diff line
@@ -18,11 +18,11 @@ package android.service.wallpaper;

import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.MergedConfiguration;
import android.view.WindowInsets;

import com.android.internal.R;
import com.android.internal.os.HandlerCaller;
import com.android.internal.util.ScreenShapeHelper;
import com.android.internal.view.BaseIWindow;
import com.android.internal.view.BaseSurfaceHolder;

@@ -32,7 +32,6 @@ import android.app.Service;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
@@ -55,7 +54,6 @@ import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManagerGlobal;

import java.io.FileDescriptor;
@@ -169,7 +167,7 @@ public abstract class WallpaperService extends Service {
        final Rect mFinalSystemInsets = new Rect();
        final Rect mFinalStableInsets = new Rect();
        final Rect mBackdropFrame = new Rect();
        final Configuration mConfiguration = new Configuration();
        final MergedConfiguration mMergedConfiguration = new MergedConfiguration();

        final WindowManager.LayoutParams mLayout
                = new WindowManager.LayoutParams();
@@ -288,7 +286,7 @@ public abstract class WallpaperService extends Service {
            @Override
            public void resized(Rect frame, Rect overscanInsets, Rect contentInsets,
                    Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
                    Configuration newConfig, Rect backDropRect, boolean forceLayout,
                    MergedConfiguration mergedConfiguration, Rect backDropRect, boolean forceLayout,
                    boolean alwaysConsumeNavBar, int displayId) {
                Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED,
                        reportDraw ? 1 : 0, outsets);
@@ -568,7 +566,8 @@ public abstract class WallpaperService extends Service {
                    out.print(mVisibleInsets.toShortString());
                    out.print(" mWinFrame="); out.print(mWinFrame.toShortString());
                    out.print(" mContentInsets="); out.println(mContentInsets.toShortString());
            out.print(prefix); out.print("mConfiguration="); out.println(mConfiguration);
            out.print(prefix); out.print("mConfiguration=");
                    out.println(mMergedConfiguration.getMergedConfiguration());
            out.print(prefix); out.print("mLayout="); out.println(mLayout);
            synchronized (mLock) {
                out.print(prefix); out.print("mPendingXOffset="); out.print(mPendingXOffset);
@@ -695,7 +694,7 @@ public abstract class WallpaperService extends Service {
                        mWindow, mWindow.mSeq, mLayout, mWidth, mHeight,
                            View.VISIBLE, 0, mWinFrame, mOverscanInsets, mContentInsets,
                            mVisibleInsets, mStableInsets, mOutsets, mBackdropFrame,
                            mConfiguration, mSurfaceHolder.mSurface);
                            mMergedConfiguration, mSurfaceHolder.mSurface);

                    if (DEBUG) Log.v(TAG, "New surface: " + mSurfaceHolder.mSurface
                            + ", frame=" + mWinFrame);
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.util;

parcelable MergedConfiguration;
 No newline at end of file
+122 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.util;

import android.annotation.NonNull;
import android.content.res.Configuration;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Container that holds global and override config and their merge product.
 * Merged configuration updates automatically whenever global or override configs are updated via
 * setters.
 *
 * {@hide}
 */
public class MergedConfiguration implements Parcelable {

    private Configuration mGlobalConfig = new Configuration();
    private Configuration mOverrideConfig = new Configuration();
    private Configuration mMergedConfig = new Configuration();

    public MergedConfiguration() {
    }

    public MergedConfiguration(Configuration globalConfig, Configuration overrideConfig) {
        setConfiguration(globalConfig, overrideConfig);
    }

    public MergedConfiguration(MergedConfiguration mergedConfiguration) {
        setConfiguration(mergedConfiguration.getGlobalConfiguration(),
                mergedConfiguration.getOverrideConfiguration());
    }

    private MergedConfiguration(Parcel in) {
        readFromParcel(in);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(mGlobalConfig, flags);
        dest.writeParcelable(mOverrideConfig, flags);
        dest.writeParcelable(mMergedConfig, flags);
    }

    public void readFromParcel(Parcel source) {
        mGlobalConfig = source.readParcelable(Configuration.class.getClassLoader());
        mOverrideConfig = source.readParcelable(Configuration.class.getClassLoader());
        mMergedConfig = source.readParcelable(Configuration.class.getClassLoader());
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<MergedConfiguration> CREATOR = new Creator<MergedConfiguration>() {
        @Override
        public MergedConfiguration createFromParcel(Parcel in) {
            return new MergedConfiguration(in);
        }

        @Override
        public MergedConfiguration[] newArray(int size) {
            return new MergedConfiguration[size];
        }
    };

    /**
     * Update global and override configurations.
     * Merged configuration will automatically be updated.
     * @param globalConfig New global configuration.
     * @param overrideConfig New override configuration.
     */
    public void setConfiguration(Configuration globalConfig, Configuration overrideConfig) {
        mGlobalConfig.setTo(globalConfig);
        mOverrideConfig.setTo(overrideConfig);
        updateMergedConfig();
    }

    /**
     * @return Stored global configuration value.
     */
    @NonNull
    public Configuration getGlobalConfiguration() {
        return mGlobalConfig;
    }

    /**
     * @return Stored override configuration value.
     */
    public Configuration getOverrideConfiguration() {
        return mOverrideConfig;
    }

    /**
     * @return Stored merged configuration value.
     */
    public Configuration getMergedConfiguration() {
        return mMergedConfig;
    }

    /** Update merged config when global or override config changes. */
    private void updateMergedConfig() {
        mMergedConfig.setTo(mGlobalConfig);
        mMergedConfig.updateFrom(mOverrideConfig);
    }
}
+3 −9
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.view;

import android.content.ComponentCallbacks;
import android.content.res.Configuration;

import java.text.BreakIterator;
@@ -65,7 +64,7 @@ public final class AccessibilityIterators {
    }

    static class CharacterTextSegmentIterator extends AbstractTextSegmentIterator
            implements ComponentCallbacks {
            implements ViewRootImpl.ConfigChangedCallback {
        private static CharacterTextSegmentIterator sInstance;

        private Locale mLocale;
@@ -144,19 +143,14 @@ public final class AccessibilityIterators {
        }

        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            Locale locale = newConfig.locale;
        public void onConfigurationChanged(Configuration globalConfig) {
            final Locale locale = globalConfig.getLocales().get(0);
            if (!mLocale.equals(locale)) {
                mLocale = locale;
                onLocaleChanged(locale);
            }
        }

        @Override
        public void onLowMemory() {
            /* ignore */
        }

        protected void onLocaleChanged(Locale locale) {
            mImpl = BreakIterator.getCharacterInstance(locale);
        }
Loading