package X6FRs_4.KQgRr5e_0.LGe8pk_15;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.Build;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
/* compiled from: TintContextWrapper.java */
/* loaded from: classes.dex */
public class XDsvEfm_26 extends ContextWrapper {
    public static final Object KQgRr5e_0 = new Object();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static ArrayList<WeakReference<XDsvEfm_26>> f776KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Resources.Theme f777KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Resources f778KQgRr5e_0;

    public XDsvEfm_26(Context context) {
        super(context);
        if (JXypC6_34.QxJ9d_1()) {
            JXypC6_34 jXypC6_34 = new JXypC6_34(this, context.getResources());
            this.f778KQgRr5e_0 = jXypC6_34;
            Resources.Theme newTheme = jXypC6_34.newTheme();
            this.f777KQgRr5e_0 = newTheme;
            newTheme.setTo(context.getTheme());
            return;
        }
        this.f778KQgRr5e_0 = new XuVgy_28(this, context.getResources());
        this.f777KQgRr5e_0 = null;
    }

    public static Context KQgRr5e_0(Context context) {
        if (m444KQgRr5e_0(context)) {
            synchronized (KQgRr5e_0) {
                if (f776KQgRr5e_0 == null) {
                    f776KQgRr5e_0 = new ArrayList<>();
                } else {
                    for (int size = f776KQgRr5e_0.size() - 1; size >= 0; size--) {
                        WeakReference<XDsvEfm_26> weakReference = f776KQgRr5e_0.get(size);
                        if (weakReference == null || weakReference.get() == null) {
                            f776KQgRr5e_0.remove(size);
                        }
                    }
                    for (int size2 = f776KQgRr5e_0.size() - 1; size2 >= 0; size2--) {
                        WeakReference<XDsvEfm_26> weakReference2 = f776KQgRr5e_0.get(size2);
                        XDsvEfm_26 xDsvEfm_26 = weakReference2 != null ? weakReference2.get() : null;
                        if (xDsvEfm_26 != null && xDsvEfm_26.getBaseContext() == context) {
                            return xDsvEfm_26;
                        }
                    }
                }
                XDsvEfm_26 xDsvEfm_262 = new XDsvEfm_26(context);
                f776KQgRr5e_0.add(new WeakReference<>(xDsvEfm_262));
                return xDsvEfm_262;
            }
        }
        return context;
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public AssetManager getAssets() {
        return this.f778KQgRr5e_0.getAssets();
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public Resources getResources() {
        return this.f778KQgRr5e_0;
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public Resources.Theme getTheme() {
        Resources.Theme theme = this.f777KQgRr5e_0;
        return theme == null ? super.getTheme() : theme;
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public void setTheme(int i) {
        Resources.Theme theme = this.f777KQgRr5e_0;
        if (theme == null) {
            super.setTheme(i);
        } else {
            theme.applyStyle(i, true);
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static boolean m444KQgRr5e_0(Context context) {
        if ((context instanceof XDsvEfm_26) || (context.getResources() instanceof XuVgy_28) || (context.getResources() instanceof JXypC6_34)) {
            return false;
        }
        return Build.VERSION.SDK_INT < 21 || JXypC6_34.QxJ9d_1();
    }
}
