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

Commit 4615c834 authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

Copied code from com.tmobile.widget.jar to avoid bundling it with system_server.

This created a bug with Zygote initialization that essentially added
certain classes from com.tmobile.widget.jar to every VM instance.

CR: Ed Carrigan
parent b8ca7d95
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ LOCAL_SRC_FILES := \
LOCAL_MODULE:= services

LOCAL_JAVA_LIBRARIES := android.policy
LOCAL_STATIC_JAVA_LIBRARIES := libtmobile-widget

include $(BUILD_JAVA_LIBRARY)

+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ public class ExpandedView extends LinearLayout {
    int mPrevHeight = -1;

    public ExpandedView(Context context, AttributeSet attrs) {
        super(context, attrs, com.tmobile.widget.Utils.resolveDefaultStyleAttr(context,
        super(context, attrs, Utils.resolveDefaultStyleAttr(context,
                "com_android_server_status_expandedView",
                com.android.internal.R.attr.com_android_server_status_expandedView));
        mDisplay = ((WindowManager)context.getSystemService(
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import android.widget.FrameLayout;
public class LatestItemView extends FrameLayout {

    public LatestItemView(Context context, AttributeSet attrs) {
        super(context, attrs, com.tmobile.widget.Utils.resolveDefaultStyleAttr(context,
        super(context, attrs, Utils.resolveDefaultStyleAttr(context,
            "com_android_server_status_latestItemView",
            com.android.internal.R.attr.com_android_server_status_latestItemView));
    }
+81 −0
Original line number Diff line number Diff line
package com.android.server.status;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

/**
 * This class was partially copied from com.tmobile.widget.Utils. Linking with
 * the com.tmobile.widget library from the status bar creates unusual
 * side-effects in Dalvik which cause every process forked from Zygote to have
 * the com.tmobile.widget.Utils class both defined and initialized. This causes
 * duplicate class errors for apps that actually need the com.tmobile.widget
 * library. The end result is that updates to com.tmobile.widget.jar might not
 * be reflected in newly launched apps (even after reset) because the old copy
 * would have been statically linked into the system_server.
 * <p>
 * Copying the functionality here eliminates this issue by not linking with
 * com.tmobile.widget.jar at all.
 */
public class Utils {
    /**
     * Alternative to {@link #resolveDefaultStyleAttr(Context, String)} which
     * allows you to specify a resource id for fallback. This is merely an
     * optimization which avoids by name lookup in the current application
     * package scope.
     *
     * @param context
     * @param attrName Attribute name in the currently applied theme.
     * @param fallbackAttrId Attribute id to return if the currently applied
     *            theme does not specify the supplied <code>attrName</code>.
     * @see #resolveDefaultStyleAttr(Context, String)
     */
    public static int resolveDefaultStyleAttr(Context context, String attrName,
            int fallbackAttrId) {
        /* First try to resolve in the currently applied global theme. */
        int attrId = getThemeStyleAttr(context, attrName);
        if (attrId != 0) {
            return attrId;
        }
        /* Fallback to the provided value. */
        return fallbackAttrId;
    }

    /**
     * Dynamically resolve the supplied attribute name within the theme or
     * application scope. First looks at the currently applied global theme,
     * then fallbacks to the current application package.
     *
     * @param context
     * @param attrName Attribute name in the currently applied theme.
     * @return the attribute id suitable for passing to a View's constructor or
     *         0 if neither are provided.
     * @see View#View(Context, android.util.AttributeSet, int)
     */
    public static int resolveDefaultStyleAttr(Context context, String attrName) {
        /* First try to resolve in the currently applied global theme. */
        int attrId = resolveDefaultStyleAttr(context, attrName, 0);
        if (attrId != 0) {
            return attrId;
        }
        /* Then try to lookup in the application's package. */
        return context.getResources().getIdentifier(attrName, "attr",
                context.getPackageName());
    }

    private static int getThemeStyleAttr(Context context, String attrName) {
        String themePackage = getCurrentThemePackage(context);
        if (themePackage == null) {
            return 0;
        }
        return context.getResources().getIdentifier(attrName, "attr", themePackage);
    }

    private static String getCurrentThemePackage(Context context) {
        String themePackage = context.getResources().getAssets().getThemePackageName();
        if (TextUtils.isEmpty(themePackage)) {
            return null;
        }
        return themePackage;
    }
}