package ඓ.ⁱ.K.ඓ;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.util.Base64;
import androidx.recyclerview.widget.RecyclerView;
import com.appsflyer.share.Constants;
import com.facebook.internal.security.CertificateUtil;
import com.facebook.share.internal.MessengerShareContentUtility;
import io.reactivex.exceptions.CompositeException;
import io.reactivex.exceptions.MissingBackpressureException;
import io.reactivex.exceptions.OnErrorNotImplementedException;
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.internal.disposables.EmptyDisposable;
import io.reactivex.internal.operators.observable.ObservableScalarXMap$ScalarDisposable;
import io.reactivex.internal.util.ExceptionHelper;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicLong;
import java.util.zip.CRC32;
import ඓ.㿎.K.ῲ.㗽.ʬ.C1429;
import 㴹.K.AbstractC2500;
import 㴹.K.AbstractC2508;
import 㴹.K.AbstractC2511;
import 㴹.K.AbstractC2518;
import 㴹.K.AbstractC2520;
import 㴹.K.Ԕ.ῲ.C2456;
import 㴹.K.䁗.AbstractC2521;
import 㴹.K.䁗.AbstractC2522;
import 㿎.C2531;

/* renamed from: ඓ.ⁱ.K.ඓ.K  reason: contains not printable characters */
/* compiled from: ContextGetter */
public final class C1252 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public static volatile AbstractC2522<? super Throwable> f4923;

    /* renamed from: ඓ  reason: contains not printable characters */
    public static volatile AbstractC2521<? super Callable<AbstractC2508>, ? extends AbstractC2508> f4924;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public static volatile AbstractC2521<? super AbstractC2511, ? extends AbstractC2511> f4925;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public static volatile AbstractC2521<? super AbstractC2508, ? extends AbstractC2508> f4926;

    /* renamed from: ῲ  reason: contains not printable characters */
    public static volatile AbstractC2521<AbstractC2508, AbstractC2508> f4927;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static volatile AbstractC2521<? super Callable<AbstractC2508>, ? extends AbstractC2508> f4928;

    /* renamed from: K  reason: contains not printable characters */
    public static volatile AbstractC2521<Callable<AbstractC2508>, AbstractC2508> f4929;

    /* renamed from: 㑃  reason: contains not printable characters */
    public static volatile AbstractC2521<? super AbstractC2500, ? extends AbstractC2500> f4930;

    /* renamed from: 㳳  reason: contains not printable characters */
    public static volatile AbstractC2521<? super AbstractC2508, ? extends AbstractC2508> f4931;

    /* renamed from: 㴹  reason: contains not printable characters */
    public static volatile AbstractC2521<? super Callable<AbstractC2508>, ? extends AbstractC2508> f4932;

    /* renamed from: 㸾  reason: contains not printable characters */
    public static volatile AbstractC2521<? super Runnable, ? extends Runnable> f4933;

    /* renamed from: 㿎  reason: contains not printable characters */
    public static volatile AbstractC2521<? super Callable<AbstractC2508>, ? extends AbstractC2508> f4934;

    /* renamed from: ʬ  reason: contains not printable characters */
    public static boolean m3330(String str) {
        return !str.equals("GET") && !str.equals("HEAD");
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static String m3333(String str) {
        try {
            return m3343(str.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

    @TargetApi(19)
    /* renamed from: K  reason: contains not printable characters */
    public static String m3340(Context context, Uri uri) {
        int i = Build.VERSION.SDK_INT;
        Uri uri2 = null;
        if (DocumentsContract.isDocumentUri(context, uri)) {
            if ("com.android.externalstorage.documents".equals(uri.getAuthority())) {
                String[] split = DocumentsContract.getDocumentId(uri).split(CertificateUtil.DELIMITER);
                if ("primary".equalsIgnoreCase(split[0])) {
                    return Environment.getExternalStorageDirectory() + Constants.URL_PATH_DELIMITER + split[1];
                }
            } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
                return m3341(context, ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(DocumentsContract.getDocumentId(uri)).longValue()), null, null);
            } else if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
                String[] split2 = DocumentsContract.getDocumentId(uri).split(CertificateUtil.DELIMITER);
                String str = split2[0];
                if (MessengerShareContentUtility.MEDIA_IMAGE.equals(str)) {
                    uri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(str)) {
                    uri2 = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(str)) {
                    uri2 = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }
                return m3341(context, uri2, "_id=?", new String[]{split2[1]});
            }
        } else if ("content".equalsIgnoreCase(uri.getScheme())) {
            return m3341(context, uri, null, null);
        } else {
            if ("file".equalsIgnoreCase(uri.getScheme())) {
                return uri.getPath();
            }
        }
        return null;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public static String m3353(String str) {
        StringBuilder sb = new StringBuilder();
        int length = str.length();
        for (int i = 0; i < length; i++) {
            char charAt = str.charAt(i);
            if (charAt > 31 && charAt < 127) {
                sb.append(charAt);
            }
        }
        return sb.toString();
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public static void m3329(Throwable th) {
        if (th instanceof VirtualMachineError) {
            throw ((VirtualMachineError) th);
        } else if (th instanceof ThreadDeath) {
            throw ((ThreadDeath) th);
        } else if (th instanceof LinkageError) {
            throw ((LinkageError) th);
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static RuntimeException m3332(Throwable th) {
        throw ExceptionHelper.m1955(th);
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static <T, R> R m3331(AbstractC2521<T, R> r0, T t) {
        try {
            return r0.apply(t);
        } catch (Throwable th) {
            throw ExceptionHelper.m1955(th);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static Context m3337() {
        try {
            return ((Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication", new Class[0]).invoke(null, null)).getApplicationContext();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static long m3336(byte[] bArr, int i, int i2) {
        CRC32 crc32 = new CRC32();
        crc32.update(bArr, i, i2);
        return crc32.getValue();
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m3344(String[] strArr, String str) {
        int i;
        if (strArr == null) {
            return null;
        }
        int length = strArr.length;
        int length2 = (str == null || str.equals("")) ? 0 : str.length();
        if (length == 0) {
            i = 0;
        } else {
            i = ((strArr[0] == null ? 16 : strArr[0].length()) + length2) * length;
        }
        StringBuilder sb = new StringBuilder(i);
        for (int i2 = 0; i2 < length; i2++) {
            if (i2 > 0) {
                sb.append(str);
            }
            if (strArr[i2] != null) {
                sb.append(strArr[i2]);
            }
        }
        return sb.toString();
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m3334(int i) {
        return 1 << (32 - Integer.numberOfLeadingZeros(i - 1));
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m3343(byte[] bArr) {
        return Base64.encodeToString(bArr, 10);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static byte[] m3352(String str) {
        return Base64.decode(str, 10);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static <T, R> boolean m3351(AbstractC2518<T> r1, AbstractC2520<? super R> r2, AbstractC2521<? super T, ? extends AbstractC2518<? extends R>> r3) {
        if (!(r1 instanceof Callable)) {
            return false;
        }
        try {
            Object obj = (Object) ((Callable) r1).call();
            if (obj == 0) {
                EmptyDisposable.complete(r2);
                return true;
            }
            try {
                Object apply = r3.apply(obj);
                C2456.m6500(apply, "The mapper returned a null ObservableSource");
                AbstractC2518 r12 = (AbstractC2518) apply;
                if (r12 instanceof Callable) {
                    try {
                        Object call = ((Callable) r12).call();
                        if (call == null) {
                            EmptyDisposable.complete(r2);
                            return true;
                        }
                        ObservableScalarXMap$ScalarDisposable observableScalarXMap$ScalarDisposable = new ObservableScalarXMap$ScalarDisposable(r2, call);
                        r2.onSubscribe(observableScalarXMap$ScalarDisposable);
                        observableScalarXMap$ScalarDisposable.run();
                    } catch (Throwable th) {
                        m3329(th);
                        EmptyDisposable.error(th, r2);
                        return true;
                    }
                } else {
                    ((AbstractC2500) r12).m6545((AbstractC2520) r2);
                }
                return true;
            } catch (Throwable th2) {
                m3329(th2);
                EmptyDisposable.error(th2, r2);
                return true;
            }
        } catch (Throwable th3) {
            m3329(th3);
            EmptyDisposable.error(th3, r2);
            return true;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m3342(C2531 r2) {
        String r0 = r2.m6595();
        String r22 = r2.m6600();
        if (r22 == null) {
            return r0;
        }
        return r0 + '?' + r22;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static long m3335(AtomicLong atomicLong, long j) {
        long j2;
        long j3;
        do {
            j2 = atomicLong.get();
            j3 = RecyclerView.FOREVER_NS;
            if (j2 == RecyclerView.FOREVER_NS) {
                return RecyclerView.FOREVER_NS;
            }
            long j4 = j2 + j;
            if (j4 >= 0) {
                j3 = j4;
            }
        } while (!atomicLong.compareAndSet(j2, j3));
        return j2;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static <T, R> R m3338(AbstractC2521<T, R> r0, T t) {
        try {
            return r0.apply(t);
        } catch (Throwable th) {
            throw ExceptionHelper.m1955(th);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:17:0x0033  */
    /* renamed from: K  reason: contains not printable characters */
    public static String m3341(Context context, Uri uri, String str, String[] strArr) {
        Throwable th;
        Cursor cursor;
        try {
            cursor = context.getContentResolver().query(uri, new String[]{"_data"}, str, strArr, null);
            if (cursor != null) {
                try {
                    if (cursor.moveToFirst()) {
                        String string = cursor.getString(cursor.getColumnIndexOrThrow("_data"));
                        cursor.close();
                        return string;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (cursor != null) {
                        cursor.close();
                    }
                    throw th;
                }
            }
            if (cursor != null) {
                cursor.close();
            }
            return null;
        } catch (Throwable th3) {
            th = th3;
            cursor = null;
            if (cursor != null) {
            }
            throw th;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m3350(ArrayList<C1429> arrayList, char c, float[] fArr) {
        arrayList.add(new C1429(c, fArr));
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m3349(Throwable th) {
        AbstractC2522<? super Throwable> r0 = f4923;
        if (th == null) {
            th = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
        } else {
            boolean z = true;
            if (!(th instanceof OnErrorNotImplementedException) && !(th instanceof MissingBackpressureException) && !(th instanceof IllegalStateException) && !(th instanceof NullPointerException) && !(th instanceof IllegalArgumentException) && !(th instanceof CompositeException)) {
                z = false;
            }
            if (!z) {
                th = new UndeliverableException(th);
            }
        }
        if (r0 != null) {
            try {
                r0.accept(th);
                return;
            } catch (Throwable th2) {
                th2.printStackTrace();
                Thread currentThread = Thread.currentThread();
                currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, th2);
            }
        }
        th.printStackTrace();
        Thread currentThread2 = Thread.currentThread();
        currentThread2.getUncaughtExceptionHandler().uncaughtException(currentThread2, th);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static Runnable m3339(Runnable runnable) {
        AbstractC2521<? super Runnable, ? extends Runnable> r0 = f4933;
        if (r0 == null) {
            return runnable;
        }
        return (Runnable) m3331(r0, runnable);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static <T> AbstractC2511<T> m3348(AbstractC2511<T> r1) {
        AbstractC2521<? super AbstractC2511, ? extends AbstractC2511> r0 = f4925;
        return r0 != null ? (AbstractC2511) m3331(r0, r1) : r1;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static <T> AbstractC2500<T> m3345(AbstractC2500<T> r1) {
        AbstractC2521<? super AbstractC2500, ? extends AbstractC2500> r0 = f4930;
        return r0 != null ? (AbstractC2500) m3331(r0, r1) : r1;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static AbstractC2508 m3346(Callable<AbstractC2508> callable) {
        try {
            AbstractC2508 call = callable.call();
            C2456.m6500(call, "Scheduler Callable result can't be null");
            return call;
        } catch (Throwable th) {
            throw ExceptionHelper.m1955(th);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static AbstractC2508 m3347(AbstractC2521<? super Callable<AbstractC2508>, ? extends AbstractC2508> r0, Callable<AbstractC2508> callable) {
        Object r02 = m3331(r0, callable);
        C2456.m6500(r02, "Scheduler Callable result can't be null");
        return (AbstractC2508) r02;
    }
}
