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

Commit 04d2d830 authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

Fix a fundamental issue causing CarHome to reset the applied theme.

When entering the CarHome application, whatever theme was applied at
boot was being reset globally by the car mode config change.  This has
been fixed by altering the way the Configuration#customTheme member is
handled to match the convention used by other members (i.e. leave it
uninitialized by default).
parent a566d85a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1204,7 +1204,7 @@ public final class ActivityThread {
        Configuration config = getConfiguration();
        if (compInfo.isThemeable && config != null) {
            if (config.customTheme == null) {
                config.customTheme = CustomTheme.getDefault();
                config.customTheme = CustomTheme.getBootTheme();
            }

            if (!TextUtils.isEmpty(config.customTheme.getThemePackageName())) {
+19 −19
Original line number Diff line number Diff line
@@ -266,8 +266,6 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        seq = o.seq;
        if (o.customTheme != null) {
            customTheme = (CustomTheme) o.customTheme.clone();
        } else {
            customTheme = CustomTheme.getDefault();
        }
    }
    
@@ -327,14 +325,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
        uiMode = UI_MODE_TYPE_UNDEFINED;
        seq = 0;

        String themeResource = SystemProperties.get(THEME_ID_PERSISTENCE_PROPERTY, null);
        String themePackageName = SystemProperties.get(THEME_PACKAGE_NAME_PERSISTENCE_PROPERTY, null);
        if (themeResource != null && themePackageName != null) {
            customTheme = new CustomTheme(themeResource, themePackageName);
        } else {
            customTheme = CustomTheme.getDefault();
        }
        customTheme = null;
    }

    /** {@hide} */
@@ -432,11 +423,12 @@ public final class Configuration implements Parcelable, Comparable<Configuration
            seq = delta.seq;
        }

        if (!CustomTheme.nullSafeEquals(delta.customTheme, customTheme)) {
        if (delta.customTheme != null
                && (customTheme == null || !customTheme.equals(delta.customTheme))) {
            changed |= ActivityInfo.CONFIG_THEME_RESOURCE;
            customTheme = (delta != null ? (CustomTheme)delta.customTheme.clone() :
                CustomTheme.getDefault());
            customTheme = (CustomTheme)delta.customTheme.clone();
        }

        return changed;
    }

@@ -516,7 +508,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                && uiMode != delta.uiMode) {
            changed |= ActivityInfo.CONFIG_UI_MODE;
        }
        if (!CustomTheme.nullSafeEquals(delta.customTheme, customTheme)) {
        if (delta.customTheme != null &&
                (customTheme == null || !customTheme.equals(delta.customTheme))) {
            changed |= ActivityInfo.CONFIG_THEME_RESOURCE;
        }
        
@@ -695,10 +688,17 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        n = this.screenLayout - that.screenLayout;
        if (n != 0) return n;
        n = this.uiMode - that.uiMode;
        //if (n != 0) return n;
        if (n != 0) return n;
        if (this.customTheme == null) {
            if (that.customTheme != null) return 1;
        } else if (that.customTheme == null) {
            return -1;
        } else {
            n = this.customTheme.getThemeId().compareTo(that.customTheme.getThemeId());
            if (n != 0) return n;
            n = this.customTheme.getThemePackageName().compareTo(that.customTheme.getThemePackageName());
            if (n != 0) return n;
        }

        return n;
    }
@@ -724,6 +724,6 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden
                + this.navigation + this.navigationHidden
                + this.orientation + this.screenLayout + this.uiMode
                + this.customTheme.hashCode();
                + (this.customTheme != null ? this.customTheme.hashCode() : 0);
    }
}
+21 −43
Original line number Diff line number Diff line
@@ -16,29 +16,21 @@

package android.content.res;

import android.os.*;
import android.content.Context;
import android.content.pm.*;
import android.util.Log;
import android.util.DisplayMetrics;
import android.R;
import android.app.ActivityManager;
import android.view.WindowManager;
import android.text.TextUtils;
import android.os.SystemProperties;

/**
 * @hide
 */
public final class CustomTheme implements Cloneable {

    private final String mThemeId;
    private final String mThemePackageName;

    private static final CustomTheme sDefaultTheme = new CustomTheme();
    private static final CustomTheme sBootTheme = new CustomTheme();
    private static final CustomTheme sSystemTheme = new CustomTheme("", "");

    private CustomTheme() {
        mThemeId = SystemProperties.get("default_theme.style_id");
        mThemePackageName = SystemProperties.get("default_theme.package_name");
        mThemeId = SystemProperties.get("persist.sys.themeId");
        mThemePackageName = SystemProperties.get("persist.sys.themePackageName");
    }

    public CustomTheme(String themeId, String packageName) {
@@ -69,22 +61,15 @@ public final class CustomTheme implements Cloneable {
            String newPackageName = (o.mThemePackageName == null)? "" : o.mThemePackageName;
            String currentThemeId = (mThemeId == null)? "" : mThemeId;
            String newThemeId = (o.mThemeId == null)? "" : o.mThemeId;

            /* uhh, why are we trimming here instead of when the object is
             * constructed? actually, why are we trimming at all? */
            return (currentPackageName.trim().equalsIgnoreCase(newPackageName.trim())) &&
                    (currentThemeId.trim().equalsIgnoreCase(newThemeId.trim()));
        }
        return false;
    }

    public static boolean nullSafeEquals(CustomTheme a, CustomTheme b) {
        if (a == b) {
            return true;
        }
        if (a != null && a.equals(b)) {
            return true;
        }
        return false;
    }

    @Override
    public final String toString() {
        StringBuilder result = new StringBuilder();
@@ -110,27 +95,20 @@ public final class CustomTheme implements Cloneable {
        return mThemePackageName;
    }

    public static CustomTheme getDefault() {
        return sDefaultTheme;
    /**
     * Represents the theme that the device booted into. This is used to
     * simulate a "default" configuration based on the user's last known
     * preference until the theme is switched at runtime.
     */
    public static CustomTheme getBootTheme() {
        return sBootTheme;
    }

    public static int getStyleId(Context context, String packageName, String styleName) {
        if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(styleName)) {
            return R.style.Theme;
        }
        try {
            PackageInfo pi = context.getPackageManager().getPackageInfo(packageName, 0);
            ThemeInfo[] infos = pi.themeInfos;
            if (infos != null) {
                for (ThemeInfo ti : infos) {
                    if (ti.themeId.equals(styleName)) {
                        return ti.styleResourceId;
                    }
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("CustomTheme", "Unable to get style resource id", e);
        }
        return -1;
    /**
     * Represents the system framework theme, perceived by the system as there
     * being no theme applied.
     */
    public static CustomTheme getSystemTheme() {
        return sSystemTheme;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class AppsLaunchFailureReceiver extends BroadcastReceiver {
            if (mFailuresCount <= FAILURES_THRESHOLD) {
                mFailuresCount++;
                if (mFailuresCount == FAILURES_THRESHOLD) {
                    CustomTheme defaultTheme = CustomTheme.getDefault();
                    CustomTheme defaultTheme = CustomTheme.getSystemTheme();
                    ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
                    Configuration currentConfig = am.getConfiguration();
                    currentConfig.customTheme = new CustomTheme(
+4 −27
Original line number Diff line number Diff line
@@ -11374,15 +11374,9 @@ public final class ActivityManagerService extends ActivityManagerNative
                                     values.userSetLocale);
                }

//                if(values.themeResource != 0){
//                    saveThemeResourceLocked(values.themeResource, (values.themeResource != mConfiguration.themeResource));
//                }

                if (values.customTheme != null) {
                    saveThemeResourceLocked(values.customTheme,
                            (!values.customTheme.equals(mConfiguration.customTheme)));
                } else if (mConfiguration.customTheme != null) {
                    saveThemeResourceLocked(null, true);
                            !values.customTheme.equals(mConfiguration.customTheme));
                }

                mConfigurationSeq++;
@@ -11471,27 +11465,10 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }

    private void saveThemeResourceLocked(CustomTheme customTheme, boolean isDiff){
    private void saveThemeResourceLocked(CustomTheme t, boolean isDiff){
        if(isDiff){
            String themeId;
            String themePackage;
            String resourcePath;
            boolean hasParent;
            boolean forceUpdate;

            if (customTheme != null) {
                themeId = customTheme.getThemeId();
                themePackage = customTheme.getThemePackageName();
            } else {
                themeId = null;
                themePackage = "";
                resourcePath = null;
                hasParent = false;
                forceUpdate = false;
            }

            SystemProperties.set(Configuration.THEME_ID_PERSISTENCE_PROPERTY, themeId);
            SystemProperties.set(Configuration.THEME_PACKAGE_NAME_PERSISTENCE_PROPERTY, themePackage);  
            SystemProperties.set(Configuration.THEME_ID_PERSISTENCE_PROPERTY, t.getThemeId());
            SystemProperties.set(Configuration.THEME_PACKAGE_NAME_PERSISTENCE_PROPERTY, t.getThemePackageName());  
        }
    }