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

Commit 3d2337ee authored by Alan Viverette's avatar Alan Viverette Committed by Alex Hills
Browse files

Cherry-pick system theme rebase to fix square UI on round watches

Our system themes were based on configurations that were added post-
init of the system theme.

I96e695441543379e4d5fdf3cc6f18d9e6cf953b4 broke this, because there
was a race condition in the code for rebasing themes

If8fecde76d62738a8e55eddf898eafc468afdba2 (the cherry-picked commit)
fixes the race condition and adds the rebasing back in.

This change cherry picks If8fecde76d62738a8e55eddf898eafc468afdba2.

Bug:23387146
Change-Id: I0725028e48599fc6cd9731ae16c71474dd5827e5
parent 5a45dc96
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -4235,6 +4235,11 @@ public final class ActivityThread {


            configDiff = mConfiguration.updateFrom(config);
            configDiff = mConfiguration.updateFrom(config);
            config = applyCompatConfiguration(mCurDefaultDisplayDpi);
            config = applyCompatConfiguration(mCurDefaultDisplayDpi);

            final Theme systemTheme = getSystemContext().getTheme();
            if ((systemTheme.getChangingConfigurations() & configDiff) != 0) {
                systemTheme.rebase();
            }
        }
        }


        ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config);
        ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config);
+85 −122
Original line number Original line Diff line number Diff line
@@ -1438,11 +1438,13 @@ public class Resources {
         *              if not already defined in the theme.
         *              if not already defined in the theme.
         */
         */
        public void applyStyle(int resId, boolean force) {
        public void applyStyle(int resId, boolean force) {
            synchronized (mKey) {
                AssetManager.applyThemeStyle(mTheme, resId, force);
                AssetManager.applyThemeStyle(mTheme, resId, force);


                mThemeResId = resId;
                mThemeResId = resId;
                mKey.append(resId, force);
                mKey.append(resId, force);
            }
            }
        }


        /**
        /**
         * Set this theme to hold the same contents as the theme
         * Set this theme to hold the same contents as the theme
@@ -1454,11 +1456,15 @@ public class Resources {
         * @param other The existing Theme to copy from.
         * @param other The existing Theme to copy from.
         */
         */
        public void setTo(Theme other) {
        public void setTo(Theme other) {
            synchronized (mKey) {
                synchronized (other.mKey) {
                    AssetManager.copyTheme(mTheme, other.mTheme);
                    AssetManager.copyTheme(mTheme, other.mTheme);


                    mThemeResId = other.mThemeResId;
                    mThemeResId = other.mThemeResId;
                    mKey.setTo(other.getKey());
                    mKey.setTo(other.getKey());
                }
                }
            }
        }


        /**
        /**
         * Return a TypedArray holding the values defined by
         * Return a TypedArray holding the values defined by
@@ -1480,12 +1486,14 @@ public class Resources {
         * @see #obtainStyledAttributes(AttributeSet, int[], int, int)
         * @see #obtainStyledAttributes(AttributeSet, int[], int, int)
         */
         */
        public TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
        public TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
            synchronized (mKey) {
                final int len = attrs.length;
                final int len = attrs.length;
                final TypedArray array = TypedArray.obtain(Resources.this, len);
                final TypedArray array = TypedArray.obtain(Resources.this, len);
                array.mTheme = this;
                array.mTheme = this;
                AssetManager.applyStyle(mTheme, 0, 0, 0, attrs, array.mData, array.mIndices);
                AssetManager.applyStyle(mTheme, 0, 0, 0, attrs, array.mData, array.mIndices);
                return array;
                return array;
            }
            }
        }


        /**
        /**
         * Return a TypedArray holding the values defined by the style
         * Return a TypedArray holding the values defined by the style
@@ -1494,7 +1502,7 @@ public class Resources {
         * <p>Be sure to call {@link TypedArray#recycle() TypedArray.recycle()} when you are done
         * <p>Be sure to call {@link TypedArray#recycle() TypedArray.recycle()} when you are done
         * with the array.
         * with the array.
         * 
         * 
         * @param resid The desired style resource.
         * @param resId The desired style resource.
         * @param attrs The desired attributes in the style.
         * @param attrs The desired attributes in the style.
         * 
         * 
         * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
         * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
@@ -1507,40 +1515,16 @@ public class Resources {
         * @see #obtainStyledAttributes(int[])
         * @see #obtainStyledAttributes(int[])
         * @see #obtainStyledAttributes(AttributeSet, int[], int, int)
         * @see #obtainStyledAttributes(AttributeSet, int[], int, int)
         */
         */
        public TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs)
        public TypedArray obtainStyledAttributes(@StyleRes int resId, @StyleableRes int[] attrs)
                throws NotFoundException {
                throws NotFoundException {
            synchronized (mKey) {
                final int len = attrs.length;
                final int len = attrs.length;
                final TypedArray array = TypedArray.obtain(Resources.this, len);
                final TypedArray array = TypedArray.obtain(Resources.this, len);
                array.mTheme = this;
                array.mTheme = this;
            if (false) {
                AssetManager.applyStyle(mTheme, 0, resId, 0, attrs, array.mData, array.mIndices);
                int[] data = array.mData;
                
                System.out.println("**********************************************************");
                System.out.println("**********************************************************");
                System.out.println("**********************************************************");
                System.out.println("Attributes:");
                String s = "  Attrs:";
                int i;
                for (i=0; i<attrs.length; i++) {
                    s = s + " 0x" + Integer.toHexString(attrs[i]);
                }
                System.out.println(s);
                s = "  Found:";
                TypedValue value = new TypedValue();
                for (i=0; i<attrs.length; i++) {
                    int d = i*AssetManager.STYLE_NUM_ENTRIES;
                    value.type = data[d+AssetManager.STYLE_TYPE];
                    value.data = data[d+AssetManager.STYLE_DATA];
                    value.assetCookie = data[d+AssetManager.STYLE_ASSET_COOKIE];
                    value.resourceId = data[d+AssetManager.STYLE_RESOURCE_ID];
                    s = s + " 0x" + Integer.toHexString(attrs[i])
                        + "=" + value;
                }
                System.out.println(s);
            }
            AssetManager.applyStyle(mTheme, 0, resid, 0, attrs, array.mData, array.mIndices);
                return array;
                return array;
            }
            }
        }


        /**
        /**
         * Return a TypedArray holding the attribute values in
         * Return a TypedArray holding the attribute values in
@@ -1592,6 +1576,7 @@ public class Resources {
         */
         */
        public TypedArray obtainStyledAttributes(AttributeSet set,
        public TypedArray obtainStyledAttributes(AttributeSet set,
                @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
                @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
            synchronized (mKey) {
                final int len = attrs.length;
                final int len = attrs.length;
                final TypedArray array = TypedArray.obtain(Resources.this, len);
                final TypedArray array = TypedArray.obtain(Resources.this, len);


@@ -1601,42 +1586,14 @@ public class Resources {
                // contained in the resources and such).
                // contained in the resources and such).
                final XmlBlock.Parser parser = (XmlBlock.Parser) set;
                final XmlBlock.Parser parser = (XmlBlock.Parser) set;
                AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes,
                AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes,
                    parser != null ? parser.mParseState : 0, attrs, array.mData, array.mIndices);
                        parser != null ? parser.mParseState : 0,

                        attrs, array.mData, array.mIndices);
                array.mTheme = this;
                array.mTheme = this;
                array.mXml = parser;
                array.mXml = parser;


            if (false) {
                int[] data = array.mData;
                
                System.out.println("Attributes:");
                String s = "  Attrs:";
                int i;
                for (i=0; i<set.getAttributeCount(); i++) {
                    s = s + " " + set.getAttributeName(i);
                    int id = set.getAttributeNameResource(i);
                    if (id != 0) {
                        s = s + "(0x" + Integer.toHexString(id) + ")";
                    }
                    s = s + "=" + set.getAttributeValue(i);
                }
                System.out.println(s);
                s = "  Found:";
                TypedValue value = new TypedValue();
                for (i=0; i<attrs.length; i++) {
                    int d = i*AssetManager.STYLE_NUM_ENTRIES;
                    value.type = data[d+AssetManager.STYLE_TYPE];
                    value.data = data[d+AssetManager.STYLE_DATA];
                    value.assetCookie = data[d+AssetManager.STYLE_ASSET_COOKIE];
                    value.resourceId = data[d+AssetManager.STYLE_RESOURCE_ID];
                    s = s + " 0x" + Integer.toHexString(attrs[i])
                        + "=" + value;
                }
                System.out.println(s);
            }

                return array;
                return array;
            }
            }
        }


        /**
        /**
         * Retrieve the values for a set of attributes in the Theme. The
         * Retrieve the values for a set of attributes in the Theme. The
@@ -1654,6 +1611,7 @@ public class Resources {
         */
         */
        @NonNull
        @NonNull
        public TypedArray resolveAttributes(@NonNull int[] values, @NonNull int[] attrs) {
        public TypedArray resolveAttributes(@NonNull int[] values, @NonNull int[] attrs) {
            synchronized (mKey) {
                final int len = attrs.length;
                final int len = attrs.length;
                if (values == null || len != values.length) {
                if (values == null || len != values.length) {
                    throw new IllegalArgumentException(
                    throw new IllegalArgumentException(
@@ -1667,6 +1625,7 @@ public class Resources {


                return array;
                return array;
            }
            }
        }


        /**
        /**
         * Retrieve the value of an attribute in the Theme.  The contents of
         * Retrieve the value of an attribute in the Theme.  The contents of
@@ -1686,14 +1645,9 @@ public class Resources {
         *         <var>outValue</var> is valid, else false.
         *         <var>outValue</var> is valid, else false.
         */
         */
        public boolean resolveAttribute(int resid, TypedValue outValue, boolean resolveRefs) {
        public boolean resolveAttribute(int resid, TypedValue outValue, boolean resolveRefs) {
            boolean got = mAssets.getThemeValue(mTheme, resid, outValue, resolveRefs);
            synchronized (mKey) {
            if (false) {
                return mAssets.getThemeValue(mTheme, resid, outValue, resolveRefs);
                System.out.println(
                    "resolveAttribute #" + Integer.toHexString(resid)
                    + " got=" + got + ", type=0x" + Integer.toHexString(outValue.type)
                    + ", data=0x" + Integer.toHexString(outValue.data));
            }
            }
            return got;
        }
        }


        /**
        /**
@@ -1739,9 +1693,12 @@ public class Resources {
         * @see ActivityInfo
         * @see ActivityInfo
         */
         */
        public int getChangingConfigurations() {
        public int getChangingConfigurations() {
            final int nativeChangingConfig = AssetManager.getThemeChangingConfigurations(mTheme);
            synchronized (mKey) {
                final int nativeChangingConfig =
                        AssetManager.getThemeChangingConfigurations(mTheme);
                return ActivityInfo.activityInfoConfigNativeToJava(nativeChangingConfig);
                return ActivityInfo.activityInfoConfigNativeToJava(nativeChangingConfig);
            }
            }
        }


        /**
        /**
         * Print contents of this theme out to the log.  For debugging only.
         * Print contents of this theme out to the log.  For debugging only.
@@ -1751,8 +1708,10 @@ public class Resources {
         * @param prefix Text to prefix each line printed.
         * @param prefix Text to prefix each line printed.
         */
         */
        public void dump(int priority, String tag, String prefix) {
        public void dump(int priority, String tag, String prefix) {
            synchronized (mKey) {
                AssetManager.dumpTheme(mTheme, priority, tag, prefix);
                AssetManager.dumpTheme(mTheme, priority, tag, prefix);
            }
            }
        }


        @Override
        @Override
        protected void finalize() throws Throwable {
        protected void finalize() throws Throwable {
@@ -1801,6 +1760,7 @@ public class Resources {
         */
         */
        @ViewDebug.ExportedProperty(category = "theme", hasAdjacentMapping = true)
        @ViewDebug.ExportedProperty(category = "theme", hasAdjacentMapping = true)
        public String[] getTheme() {
        public String[] getTheme() {
            synchronized (mKey) {
                final int N = mKey.mCount;
                final int N = mKey.mCount;
                final String[] themes = new String[N * 2];
                final String[] themes = new String[N * 2];
                for (int i = 0, j = N - 1; i < themes.length; i += 2, --j) {
                for (int i = 0, j = N - 1; i < themes.length; i += 2, --j) {
@@ -1815,6 +1775,7 @@ public class Resources {
                }
                }
                return themes;
                return themes;
            }
            }
        }


        /** @hide */
        /** @hide */
        public void encode(@NonNull ViewHierarchyEncoder encoder) {
        public void encode(@NonNull ViewHierarchyEncoder encoder) {
@@ -1834,6 +1795,7 @@ public class Resources {
         * @hide
         * @hide
         */
         */
        public void rebase() {
        public void rebase() {
            synchronized (mKey) {
                AssetManager.clearTheme(mTheme);
                AssetManager.clearTheme(mTheme);


                // Reapply the same styles in the same order.
                // Reapply the same styles in the same order.
@@ -1844,6 +1806,7 @@ public class Resources {
                }
                }
            }
            }
        }
        }
    }


    static class ThemeKey implements Cloneable {
    static class ThemeKey implements Cloneable {
        int[] mResId;
        int[] mResId;
+6 −0
Original line number Original line Diff line number Diff line
@@ -1047,6 +1047,12 @@ public final class SystemServer {
        w.getDefaultDisplay().getMetrics(metrics);
        w.getDefaultDisplay().getMetrics(metrics);
        context.getResources().updateConfiguration(config, metrics);
        context.getResources().updateConfiguration(config, metrics);


        // The system context's theme may be configuration-dependent.
        final Theme systemTheme = context.getTheme();
        if (systemTheme.getChangingConfigurations() != 0) {
            systemTheme.rebase();
        }

        try {
        try {
            // TODO: use boot phase
            // TODO: use boot phase
            mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());
            mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());