package o;

import android.animation.Animator;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import androidx.cardview.widget.CardView;
import com.google.android.datatransport.cct.CctBackendFactory;
import com.google.android.datatransport.runtime.backends.TransportBackendDiscovery;
import com.google.android.gms.common.util.PlatformVersion;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class DH implements InterfaceC1491ib0, InterfaceC3051yx, InterfaceC2686v50, Mo0 {
    public static final Object n = new Object();

    /* renamed from: o, reason: collision with root package name */
    public static ServiceConnectionC1512im0 f76o;
    public Object l;
    public Object m;

    public /* synthetic */ DH(Object obj) {
        this.m = obj;
    }

    public static Hw0 i(Context context, Intent intent, boolean z) {
        ServiceConnectionC1512im0 serviceConnectionC1512im0;
        Log.isLoggable("FirebaseMessaging", 3);
        synchronized (n) {
            try {
                if (f76o == null) {
                    f76o = new ServiceConnectionC1512im0(context);
                }
                serviceConnectionC1512im0 = f76o;
            } finally {
            }
        }
        if (!z) {
            return serviceConnectionC1512im0.b(intent).k(new V8(1), new C0397Pi(23));
        }
        if (S60.h().n(context)) {
            synchronized (Lk0.b) {
                try {
                    Lk0.a(context);
                    boolean booleanExtra = intent.getBooleanExtra("com.google.firebase.iid.WakeLockHolder.wakefulintent", false);
                    intent.putExtra("com.google.firebase.iid.WakeLockHolder.wakefulintent", true);
                    if (!booleanExtra) {
                        Lk0.c.a(Lk0.a);
                    }
                    Hw0 hw0B = serviceConnectionC1512im0.b(intent);
                    G1 g1 = new G1(18, intent);
                    hw0B.getClass();
                    hw0B.b.e(new Yq0((Executor) Rc0.a, (HT) g1));
                    hw0B.q();
                } finally {
                }
            }
        } else {
            serviceConnectionC1512im0.b(intent);
        }
        return AbstractC0752ap.K(-1);
    }

    @Override // o.Mo0
    public C2062oc0 a(InterfaceC1991no0 interfaceC1991no0) {
        C2062oc0 c2062oc0 = (C2062oc0) this.l;
        c2062oc0.m((String) this.m, interfaceC1991no0);
        return c2062oc0;
    }

    @Override // o.InterfaceC1491ib0
    public void b(C2899xO c2899xO, Bitmap bitmap, Map map) {
        int i;
        int i2 = AbstractC1904ms0.i(bitmap);
        G00 g00 = (G00) this.m;
        synchronized (((C0688a6) g00.g)) {
            i = g00.b;
        }
        if (i2 <= i) {
            ((G00) this.m).l(c2899xO, new F00(bitmap, map, i2));
        } else {
            ((G00) this.m).m(c2899xO);
            ((C1254g2) this.l).i(c2899xO, bitmap, map, i2);
        }
    }

    @Override // o.InterfaceC2686v50
    public int c(int i) {
        do {
            i = ((C0862bw) this.m).j(i);
            if (i == -1) {
                return -1;
            }
        } while (Character.isWhitespace(((CharSequence) this.l).charAt(i)));
        return i;
    }

    @Override // o.InterfaceC2686v50
    public int d(int i) {
        do {
            i = ((C0862bw) this.m).i(i);
            if (i == -1) {
                return -1;
            }
        } while (Character.isWhitespace(((CharSequence) this.l).charAt(i - 1)));
        return i;
    }

    @Override // o.InterfaceC1491ib0
    public C2994yO e(C2899xO c2899xO) {
        F00 f00 = (F00) ((G00) this.m).h(c2899xO);
        if (f00 != null) {
            return new C2994yO(f00.a, f00.b);
        }
        return null;
    }

    @Override // o.InterfaceC1491ib0
    public void f(int i) {
        int i2;
        if (i >= 40) {
            ((G00) this.m).p(-1);
            return;
        }
        if (10 > i || i >= 20) {
            return;
        }
        G00 g00 = (G00) this.m;
        synchronized (((C0688a6) g00.g)) {
            i2 = g00.c;
        }
        g00.p(i2 / 2);
    }

    @Override // o.InterfaceC2686v50
    public int g(int i) {
        CharSequence charSequence = (CharSequence) this.l;
        do {
            i = ((C0862bw) this.m).i(i);
            if (i == -1 || i == charSequence.length()) {
                return -1;
            }
        } while (Character.isWhitespace(charSequence.charAt(i)));
        return i;
    }

    @Override // o.CZ
    public Object get() {
        C2616uQ c2616uQ = new C2616uQ(25);
        C2616uQ c2616uQ2 = new C2616uQ(23);
        Object obj = ((CZ) this.l).get();
        CZ cz = (CZ) this.m;
        return new L30(c2616uQ, c2616uQ2, C0364Ob.f, (K40) obj, cz);
    }

    @Override // o.InterfaceC2686v50
    public int h(int i) {
        do {
            i = ((C0862bw) this.m).j(i);
            if (i == -1 || i == 0) {
                return -1;
            }
        } while (Character.isWhitespace(((CharSequence) this.l).charAt(i - 1)));
        return i;
    }

    public View j(int i, int i2, int i3, int i4) {
        View viewU;
        Aj0 aj0 = (Aj0) this.m;
        C0966d10 c0966d10 = (C0966d10) this.l;
        int iD = c0966d10.d();
        int iC = c0966d10.c();
        int i5 = i2 > i ? 1 : -1;
        View view = null;
        while (i != i2) {
            switch (c0966d10.a) {
                case 0:
                    viewU = c0966d10.b.u(i);
                    break;
                default:
                    viewU = c0966d10.b.u(i);
                    break;
            }
            int iB = c0966d10.b(viewU);
            int iA = c0966d10.a(viewU);
            aj0.b = iD;
            aj0.c = iC;
            aj0.d = iB;
            aj0.e = iA;
            if (i3 != 0) {
                aj0.a = i3;
                if (aj0.a()) {
                    return viewU;
                }
            }
            if (i4 != 0) {
                aj0.a = i4;
                if (aj0.a()) {
                    view = viewU;
                }
            }
            i += i5;
        }
        return view;
    }

    public CctBackendFactory k(String str) {
        Map map;
        PackageManager packageManager;
        ServiceInfo serviceInfo;
        if (((Map) this.m) == null) {
            Context context = (Context) this.l;
            try {
                packageManager = context.getPackageManager();
            } catch (PackageManager.NameNotFoundException unused) {
            }
            Bundle bundle = (packageManager == null || (serviceInfo = packageManager.getServiceInfo(new ComponentName(context, (Class<?>) TransportBackendDiscovery.class), 128)) == null) ? null : serviceInfo.metaData;
            if (bundle == null) {
                map = Collections.EMPTY_MAP;
            } else {
                HashMap map2 = new HashMap();
                for (String str2 : bundle.keySet()) {
                    Object obj = bundle.get(str2);
                    if ((obj instanceof String) && str2.startsWith("backend:")) {
                        for (String str3 : ((String) obj).split(",", -1)) {
                            String strTrim = str3.trim();
                            if (!strTrim.isEmpty()) {
                                map2.put(strTrim, str2.substring(8));
                            }
                        }
                    }
                }
                map = map2;
            }
            this.m = map;
        }
        String str4 = (String) ((Map) this.m).get(str);
        if (str4 == null) {
            return null;
        }
        try {
            return (CctBackendFactory) Class.forName(str4).asSubclass(CctBackendFactory.class).getDeclaredConstructor(null).newInstance(null);
        } catch (ClassNotFoundException unused2) {
            StringBuilder sb = new StringBuilder("Class ");
            sb.append(str4);
            sb.append(" is not found.");
            return null;
        } catch (IllegalAccessException unused3) {
            StringBuilder sb2 = new StringBuilder("Could not instantiate ");
            sb2.append(str4);
            sb2.append(".");
            return null;
        } catch (InstantiationException unused4) {
            StringBuilder sb3 = new StringBuilder("Could not instantiate ");
            sb3.append(str4);
            sb3.append(".");
            return null;
        } catch (NoSuchMethodException unused5) {
            "Could not instantiate ".concat(str4);
            return null;
        } catch (InvocationTargetException unused6) {
            "Could not instantiate ".concat(str4);
            return null;
        }
    }

    public File l() {
        if (((File) this.l) == null) {
            synchronized (this) {
                try {
                    if (((File) this.l) == null) {
                        C0076Cy c0076Cy = (C0076Cy) this.m;
                        c0076Cy.a();
                        this.l = new File(c0076Cy.a.getFilesDir(), "PersistedInstallation." + ((C0076Cy) this.m).d() + ".json");
                    }
                } finally {
                }
            }
        }
        return (File) this.l;
    }

    /* JADX WARN: Type inference failed for: r0v0, types: [java.lang.Object, o.zK] */
    public InputMethodManager m() {
        return (InputMethodManager) this.m.getValue();
    }

    public void n(C1108ec c1108ec) throws JSONException, IOException {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("Fid", c1108ec.a);
            jSONObject.put("Status", AbstractC2462sn.w(c1108ec.b));
            jSONObject.put("AuthToken", c1108ec.c);
            jSONObject.put("RefreshToken", c1108ec.d);
            jSONObject.put("TokenCreationEpochInSecs", c1108ec.f);
            jSONObject.put("ExpiresInSecs", c1108ec.e);
            jSONObject.put("FisError", c1108ec.g);
            C0076Cy c0076Cy = (C0076Cy) this.m;
            c0076Cy.a();
            File fileCreateTempFile = File.createTempFile("PersistedInstallation", "tmp", c0076Cy.a.getFilesDir());
            FileOutputStream fileOutputStream = new FileOutputStream(fileCreateTempFile);
            fileOutputStream.write(jSONObject.toString().getBytes("UTF-8"));
            fileOutputStream.close();
            if (fileCreateTempFile.renameTo(l())) {
            } else {
                throw new IOException("unable to rename the tmpfile to PersistedInstallation");
            }
        } catch (IOException | JSONException unused) {
        }
    }

    public boolean o(View view) {
        Aj0 aj0 = (Aj0) this.m;
        C0966d10 c0966d10 = (C0966d10) this.l;
        int iD = c0966d10.d();
        int iC = c0966d10.c();
        int iB = c0966d10.b(view);
        int iA = c0966d10.a(view);
        aj0.b = iD;
        aj0.c = iC;
        aj0.d = iB;
        aj0.e = iA;
        aj0.a = 24579;
        return aj0.a();
    }

    public Hw0 p(final Intent intent) {
        String stringExtra = intent.getStringExtra("gcm.rawData64");
        if (stringExtra != null) {
            intent.putExtra("rawData", Base64.decode(stringExtra, 0));
            intent.removeExtra("gcm.rawData64");
        }
        final Context context = (Context) this.l;
        V8 v8 = (V8) this.m;
        boolean z = PlatformVersion.isAtLeastO() && context.getApplicationInfo().targetSdkVersion >= 26;
        final boolean z2 = (intent.getFlags() & 268435456) != 0;
        return (!z || z2) ? AbstractC0752ap.r(v8, new Callable() { // from class: o.Jx
            @Override // java.util.concurrent.Callable
            public final Object call() {
                String str;
                ServiceInfo serviceInfo;
                String str2;
                int i;
                Context context2 = context;
                Intent intent2 = intent;
                S60 s60H = S60.h();
                s60H.getClass();
                Log.isLoggable("FirebaseMessaging", 3);
                ((ArrayDeque) s60H.p).offer(intent2);
                Intent intent3 = new Intent("com.google.firebase.MESSAGING_EVENT");
                intent3.setPackage(context2.getPackageName());
                synchronized (s60H) {
                    try {
                        str = (String) s60H.m;
                        if (str == null) {
                            ResolveInfo resolveInfoResolveService = context2.getPackageManager().resolveService(intent3, 0);
                            if (resolveInfoResolveService != null && (serviceInfo = resolveInfoResolveService.serviceInfo) != null && context2.getPackageName().equals(serviceInfo.packageName) && (str2 = serviceInfo.name) != null) {
                                if (str2.startsWith(".")) {
                                    s60H.m = context2.getPackageName() + serviceInfo.name;
                                } else {
                                    s60H.m = serviceInfo.name;
                                }
                                str = (String) s60H.m;
                            }
                            str = null;
                        }
                    } finally {
                    }
                }
                if (str != null) {
                    Log.isLoggable("FirebaseMessaging", 3);
                    intent3.setClassName(context2.getPackageName(), str);
                }
                try {
                    i = (s60H.n(context2) ? Lk0.c(context2, intent3) : context2.startService(intent3)) == null ? 404 : -1;
                } catch (IllegalStateException e) {
                    e.toString();
                    i = 402;
                } catch (SecurityException unused) {
                    i = 401;
                }
                return Integer.valueOf(i);
            }
        }).d(v8, new InterfaceC0246Jm() { // from class: o.Kx
            @Override // o.InterfaceC0246Jm
            public final Object then(Pc0 pc0) {
                return (PlatformVersion.isAtLeastO() && ((Integer) pc0.f()).intValue() == 402) ? DH.i(context, intent, z2).k(new V8(1), new C0397Pi(22)) : pc0;
            }
        }) : i(context, intent, z2);
    }

    public C1108ec q() throws IOException {
        JSONObject jSONObject;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] bArr = new byte[16384];
        try {
            FileInputStream fileInputStream = new FileInputStream(l());
            while (true) {
                try {
                    int i = fileInputStream.read(bArr, 0, 16384);
                    if (i < 0) {
                        break;
                    }
                    byteArrayOutputStream.write(bArr, 0, i);
                } finally {
                }
            }
            jSONObject = new JSONObject(byteArrayOutputStream.toString());
            fileInputStream.close();
        } catch (IOException | JSONException unused) {
            jSONObject = new JSONObject();
        }
        String strOptString = jSONObject.optString("Fid", null);
        int iOptInt = jSONObject.optInt("Status", 0);
        String strOptString2 = jSONObject.optString("AuthToken", null);
        String strOptString3 = jSONObject.optString("RefreshToken", null);
        long jOptLong = jSONObject.optLong("TokenCreationEpochInSecs", 0L);
        long jOptLong2 = jSONObject.optLong("ExpiresInSecs", 0L);
        String strOptString4 = jSONObject.optString("FisError", null);
        int i2 = AbstractC2462sn.y(5)[iOptInt];
        if (i2 == 0) {
            throw new NullPointerException("Null registrationStatus");
        }
        String str = i2 == 0 ? " registrationStatus" : "";
        if (str.isEmpty()) {
            return new C1108ec(strOptString, i2, strOptString2, strOptString3, jOptLong2, jOptLong, strOptString4);
        }
        throw new IllegalStateException("Missing required properties:".concat(str));
    }

    public void r(int i, int i2, int i3, int i4) {
        CardView cardView = (CardView) this.m;
        cardView.f7o.set(i, i2, i3, i4);
        Rect rect = cardView.n;
        super/*android.view.View*/.setPadding(i + rect.left, i2 + rect.top, i3 + rect.right, i4 + rect.bottom);
    }

    public /* synthetic */ DH(Object obj, Object obj2) {
        this.l = obj;
        this.m = obj2;
    }

    public /* synthetic */ DH(boolean z, Object obj) {
        this.l = obj;
        this.m = null;
    }

    public DH(Context context) {
        this.l = context;
        this.m = new V8(1);
    }

    public DH(View view) {
        this.l = view;
        this.m = AbstractC2001nt0.y(3, new C1164f5(7, this));
    }

    public DH(C0966d10 c0966d10) {
        this.l = c0966d10;
        Aj0 aj0 = new Aj0();
        aj0.a = 0;
        this.m = aj0;
    }

    public DH(Animator animator) {
        this.l = null;
        this.m = animator;
    }
}
