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

Commit 44eea56a authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Danny Baumann
Browse files

ThemeUtils: Retain the original package name in themed UI context

In order for themes to reflect on system elements, we're changing
their context, including the package name.

This breaks anything that tries to identify system elements,
most notably any users of the uiautomator. Trying to do
'UiSelector().packageName("android")' to find, for example,
a force-close dialog will fail.

Fixes com.android.cts.uiautomatortest.CtsUiAutomatorTest#testUiWatcher

Change-Id: Ic05c3024b20ac3772ed5597846fbfa4a184ebb0d
parent 63e13f9b
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.app;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
@@ -32,9 +33,25 @@ public class ThemeUtils {
    private static final String DATA_TYPE_TMOBILE_THEME = "vnd.tmobile.cursor.item/theme";
    private static final String ACTION_TMOBILE_THEME_CHANGED = "com.tmobile.intent.action.THEME_CHANGED";

    private static class ThemedUiContext extends ContextWrapper {
        private String mPackageName;

        public ThemedUiContext(Context context, String packageName) {
            super(context);
            mPackageName = packageName;
        }

        @Override
        public String getPackageName() {
            return mPackageName;
        }
    }

    public static Context createUiContext(final Context context) {
        try {
            return context.createPackageContext("com.android.systemui", Context.CONTEXT_RESTRICTED);
            Context uiContext = context.createPackageContext("com.android.systemui",
                    Context.CONTEXT_RESTRICTED);
            return new ThemedUiContext(uiContext, context.getPackageName());
        } catch (PackageManager.NameNotFoundException e) {
        }