package ඓ.ῲ.K.㑃;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import androidx.fragment.app.FragmentActivity;
import java.util.HashMap;
import java.util.Map;
import ඓ.ῲ.K.ComponentCallbacks2C1161;
import ඓ.ῲ.K.ComponentCallbacks2C1163;
import ඓ.ῲ.K.ᓣ.C0845;
import ῲ.Ԕ.K.AbstractC1531;
import ῲ.㴹.C2284;

/* renamed from: ඓ.ῲ.K.㑃.㑃  reason: contains not printable characters */
/* compiled from: RequestManagerRetriever */
public class C1179 implements Handler.Callback {

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final AbstractC1180 f4712 = new C1181();

    /* renamed from: ʬ  reason: contains not printable characters */
    public final Map<AbstractC1531, C1182> f4713 = new HashMap();

    /* renamed from: ඓ  reason: contains not printable characters */
    public final AbstractC1180 f4714;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final Map<FragmentManager, FragmentC1173> f4715 = new HashMap();

    /* renamed from: K  reason: contains not printable characters */
    public volatile ComponentCallbacks2C1163 f4716;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final Handler f4717;

    /* renamed from: ඓ.ῲ.K.㑃.㑃$ῲ  reason: contains not printable characters */
    /* compiled from: RequestManagerRetriever */
    public interface AbstractC1180 {
    }

    /* renamed from: ඓ.ῲ.K.㑃.㑃$K  reason: contains not printable characters */
    /* compiled from: RequestManagerRetriever */
    public class C1181 implements AbstractC1180 {
        /* renamed from: K  reason: contains not printable characters */
        public ComponentCallbacks2C1163 m3161(ComponentCallbacks2C1161 r2, AbstractC1187 r3, AbstractC1188 r4, Context context) {
            return new ComponentCallbacks2C1163(r2, r3, r4, context);
        }
    }

    public C1179(AbstractC1180 r2) {
        new C2284();
        new C2284();
        new Bundle();
        this.f4714 = r2 == null ? f4712 : r2;
        this.f4717 = new Handler(Looper.getMainLooper(), this);
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public static Activity m3151(Context context) {
        if (context instanceof Activity) {
            return (Activity) context;
        }
        if (context instanceof ContextWrapper) {
            return m3151(((ContextWrapper) context).getBaseContext());
        }
        return null;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public static boolean m3153(Context context) {
        Activity r0 = m3151(context);
        return r0 == null || !r0.isFinishing();
    }

    public boolean handleMessage(Message message) {
        Object obj;
        int i = message.what;
        Object obj2 = null;
        boolean z = true;
        if (i == 1) {
            obj2 = (FragmentManager) message.obj;
            obj = this.f4715.remove(obj2);
        } else if (i != 2) {
            z = false;
            obj = null;
        } else {
            obj2 = (AbstractC1531) message.obj;
            obj = this.f4713.remove(obj2);
        }
        if (z && obj == null && Log.isLoggable("RMRetriever", 5)) {
            Log.w("RMRetriever", "Failed to remove expected request manager fragment, manager: " + obj2);
        }
        return z;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final ComponentCallbacks2C1163 m3154(Context context) {
        if (this.f4716 == null) {
            synchronized (this) {
                if (this.f4716 == null) {
                    this.f4716 = ((C1181) this.f4714).m3161(ComponentCallbacks2C1161.m3105(context.getApplicationContext()), new C1176(), new C1177(), context.getApplicationContext());
                }
            }
        }
        return this.f4716;
    }

    /* renamed from: K  reason: contains not printable characters */
    public ComponentCallbacks2C1163 m3155(Context context) {
        if (context != null) {
            if (C0845.m2449() && !(context instanceof Application)) {
                if (context instanceof FragmentActivity) {
                    return m3156((FragmentActivity) context);
                }
                if (context instanceof Activity) {
                    Activity activity = (Activity) context;
                    if (C0845.m2450()) {
                        return m3155(activity.getApplicationContext());
                    }
                    m3152(activity);
                    FragmentC1173 r0 = m3158(activity.getFragmentManager(), (Fragment) null, m3153(activity));
                    ComponentCallbacks2C1163 r1 = r0.f4703;
                    if (r1 != null) {
                        return r1;
                    }
                    ComponentCallbacks2C1161 r12 = ComponentCallbacks2C1161.m3105(activity);
                    ComponentCallbacks2C1163 r6 = ((C1181) this.f4714).m3161(r12, r0.m3137(), r0.f4702, activity);
                    r0.f4703 = r6;
                    return r6;
                } else if (context instanceof ContextWrapper) {
                    ContextWrapper contextWrapper = (ContextWrapper) context;
                    if (contextWrapper.getBaseContext().getApplicationContext() != null) {
                        return m3155(contextWrapper.getBaseContext());
                    }
                }
            }
            return m3154(context);
        }
        throw new IllegalArgumentException("You cannot start a load on a null Context");
    }

    @TargetApi(17)
    /* renamed from: ῲ  reason: contains not printable characters */
    public static void m3152(Activity activity) {
        int i = Build.VERSION.SDK_INT;
        if (activity.isDestroyed()) {
            throw new IllegalArgumentException("You cannot start a load for a destroyed activity");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public ComponentCallbacks2C1163 m3156(FragmentActivity fragmentActivity) {
        if (C0845.m2450()) {
            return m3155(fragmentActivity.getApplicationContext());
        }
        int i = Build.VERSION.SDK_INT;
        if (!fragmentActivity.isDestroyed()) {
            C1182 r0 = m3160(fragmentActivity.getSupportFragmentManager(), (androidx.fragment.app.Fragment) null, m3153(fragmentActivity));
            ComponentCallbacks2C1163 r1 = r0.m3162();
            if (r1 != null) {
                return r1;
            }
            ComponentCallbacks2C1161 r12 = ComponentCallbacks2C1161.m3105((Context) fragmentActivity);
            ComponentCallbacks2C1163 r13 = ((C1181) this.f4714).m3161(r12, r0.m3163(), r0.m3167(), fragmentActivity);
            r0.m3166(r13);
            return r13;
        }
        throw new IllegalArgumentException("You cannot start a load for a destroyed activity");
    }

    @Deprecated
    /* renamed from: K  reason: contains not printable characters */
    public FragmentC1173 m3157(Activity activity) {
        return m3158(activity.getFragmentManager(), (Fragment) null, m3153(activity));
    }

    /* renamed from: K  reason: contains not printable characters */
    public final FragmentC1173 m3158(FragmentManager fragmentManager, Fragment fragment, boolean z) {
        FragmentC1173 r1 = (FragmentC1173) fragmentManager.findFragmentByTag("com.bumptech.glide.manager");
        if (r1 == null && (r1 = this.f4715.get(fragmentManager)) == null) {
            r1 = new FragmentC1173();
            r1.f4705 = fragment;
            if (!(fragment == null || fragment.getActivity() == null)) {
                r1.m3139(fragment.getActivity());
            }
            if (z) {
                r1.f4704.m3147();
            }
            this.f4715.put(fragmentManager, r1);
            fragmentManager.beginTransaction().add(r1, "com.bumptech.glide.manager").commitAllowingStateLoss();
            this.f4717.obtainMessage(1, fragmentManager).sendToTarget();
        }
        return r1;
    }

    /* renamed from: K  reason: contains not printable characters */
    public C1182 m3159(Context context, AbstractC1531 r3) {
        return m3160(r3, (androidx.fragment.app.Fragment) null, m3153(context));
    }

    /* renamed from: K  reason: contains not printable characters */
    public final C1182 m3160(AbstractC1531 r3, androidx.fragment.app.Fragment fragment, boolean z) {
        C1182 r1 = (C1182) r3.m3914("com.bumptech.glide.manager");
        if (r1 == null && (r1 = this.f4713.get(r3)) == null) {
            r1 = new C1182();
            r1.m3165(fragment);
            if (z) {
                r1.m3163().m3147();
            }
            this.f4713.put(r3, r1);
            r3.m3915().m4100(r1, "com.bumptech.glide.manager").m4091();
            this.f4717.obtainMessage(2, r3).sendToTarget();
        }
        return r1;
    }
}
