package o;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import ir.devixor.app.service.ForegroundService;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Locale;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.ln, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1798ln extends Sb0 implements SC {
    public final /* synthetic */ int p;
    public /* synthetic */ Object q;
    public final /* synthetic */ Object r;
    public final /* synthetic */ Object s;
    public final /* synthetic */ Object t;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C1798ln(ProgressBar progressBar, Button button, TextView textView, Exception exc, InterfaceC0220Im interfaceC0220Im) {
        super(2, interfaceC0220Im);
        this.p = 2;
        this.q = progressBar;
        this.r = button;
        this.s = textView;
        this.t = exc;
    }

    @Override // o.SC
    public final Object f(Object obj, Object obj2) throws IOException {
        InterfaceC0065Cn interfaceC0065Cn = (InterfaceC0065Cn) obj;
        InterfaceC0220Im interfaceC0220Im = (InterfaceC0220Im) obj2;
        switch (this.p) {
            case 0:
                C1798ln c1798ln = (C1798ln) l(interfaceC0065Cn, interfaceC0220Im);
                Oh0 oh0 = Oh0.a;
                c1798ln.n(oh0);
                return oh0;
            case 1:
                return ((C1798ln) l(interfaceC0065Cn, interfaceC0220Im)).n(Oh0.a);
            default:
                C1798ln c1798ln2 = (C1798ln) l(interfaceC0065Cn, interfaceC0220Im);
                Oh0 oh02 = Oh0.a;
                c1798ln2.n(oh02);
                return oh02;
        }
    }

    @Override // o.AbstractC0728ad
    public final InterfaceC0220Im l(Object obj, InterfaceC0220Im interfaceC0220Im) {
        switch (this.p) {
            case 0:
                C1798ln c1798ln = new C1798ln((MX) this.r, (Bd0) this.s, (C2066oe0) this.t, interfaceC0220Im, 0);
                c1798ln.q = obj;
                return c1798ln;
            case 1:
                C1798ln c1798ln2 = new C1798ln((String) this.r, (Context) this.s, (ForegroundService) this.t, interfaceC0220Im, 1);
                c1798ln2.q = obj;
                return c1798ln2;
            default:
                return new C1798ln((ProgressBar) this.q, (Button) this.r, (TextView) this.s, (Exception) this.t, interfaceC0220Im);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r4v10, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r4v11 */
    /* JADX WARN: Type inference failed for: r4v13 */
    /* JADX WARN: Type inference failed for: r4v19 */
    /* JADX WARN: Type inference failed for: r4v29 */
    /* JADX WARN: Type inference failed for: r4v6 */
    /* JADX WARN: Type inference failed for: r4v7 */
    /* JADX WARN: Unreachable blocks removed: 2, instructions: 3 */
    @Override // o.AbstractC0728ad
    public final Object n(Object obj) throws IOException {
        Throwable th;
        OutputStreamWriter outputStreamWriter;
        int count;
        ?? sb;
        OutputStreamWriter outputStreamWriter2;
        Throwable th2;
        OutputStreamWriter outputStreamWriter3;
        Object h20;
        String str;
        int i;
        LinkedHashMap linkedHashMap;
        String str2;
        Context context;
        switch (this.p) {
            case 0:
                IJ.H(obj);
                InterfaceC0065Cn interfaceC0065Cn = (InterfaceC0065Cn) this.q;
                MX mx = (MX) this.r;
                InterfaceC0220Im interfaceC0220Im = null;
                AbstractC1692kh0.C(interfaceC0065Cn, null, new C1703kn(mx, (Bd0) this.s, interfaceC0220Im, 0), 1);
                AbstractC1692kh0.C(interfaceC0065Cn, null, new C2105p(mx, (C2066oe0) this.t, interfaceC0220Im, 13), 1);
                return Oh0.a;
            case 1:
                String str3 = "yyyy/MM/dd HH:mm:ss";
                IJ.H(obj);
                String string = Za0.o0((String) this.r).toString();
                Context context2 = (Context) this.s;
                File file = new File(context2.getCacheDir(), AbstractC2462sn.j("sms_search_", Za0.n0(30, string), ".txt"));
                String[] strArr = {AbstractC2462sn.j("%", string, "%")};
                Context context3 = context2;
                LinkedHashMap linkedHashMap2 = new LinkedHashMap();
                Cursor cursorQuery = context3.getContentResolver().query(Uri.parse("content://sms/"), new String[]{"address", "body", "type", "sub_id", "date"}, "body LIKE ?", strArr, "date ASC");
                OutputStreamWriter outputStreamWriter4 = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file), 262144), AbstractC2355rh.a);
                ForegroundService foregroundService = (ForegroundService) this.t;
                if (cursorQuery != null) {
                    try {
                        count = cursorQuery.getCount();
                    } catch (Throwable th3) {
                        th = th3;
                        outputStreamWriter = outputStreamWriter4;
                        try {
                            throw th;
                        } catch (Throwable th4) {
                            C1884mi0.o(outputStreamWriter, th);
                            throw th4;
                        }
                    }
                } else {
                    count = 0;
                }
                try {
                    String str4 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault()).format(new Date());
                    outputStreamWriter4.append((CharSequence) "SMS Search Results").append('\n');
                    outputStreamWriter4.append((CharSequence) "Query: ".concat(string)).append('\n');
                    sb = new StringBuilder("Total: ");
                    sb.append(count);
                    outputStreamWriter4.append((CharSequence) sb.toString()).append('\n');
                    outputStreamWriter4.append((CharSequence) ("Export Time: " + str4)).append('\n');
                    outputStreamWriter4.append('\n');
                } catch (Throwable th5) {
                    th = th5;
                    sb = outputStreamWriter4;
                }
                try {
                    if (cursorQuery != null) {
                        try {
                            int columnIndex = cursorQuery.getColumnIndex("address");
                            int columnIndex2 = cursorQuery.getColumnIndex("body");
                            int columnIndex3 = cursorQuery.getColumnIndex("type");
                            int columnIndex4 = cursorQuery.getColumnIndex("sub_id");
                            int columnIndex5 = cursorQuery.getColumnIndex("date");
                            int i2 = 1;
                            while (cursorQuery.moveToNext()) {
                                String string2 = cursorQuery.getString(columnIndex);
                                String str5 = "Unknown";
                                String str6 = string2 == null ? "Unknown" : string2;
                                String string3 = cursorQuery.getString(columnIndex2);
                                if (string3 == null) {
                                    string3 = "";
                                }
                                String str7 = string3;
                                int i3 = cursorQuery.getInt(columnIndex3);
                                OutputStreamWriter outputStreamWriter5 = outputStreamWriter4;
                                try {
                                    h20 = new Long(cursorQuery.getLong(columnIndex5));
                                } catch (Throwable th6) {
                                    h20 = new H20(th6);
                                }
                                int i4 = columnIndex;
                                int i5 = columnIndex2;
                                Object l = new Long(0L);
                                if (h20 instanceof H20) {
                                    h20 = l;
                                }
                                try {
                                    long jLongValue = ((Number) h20).longValue();
                                    if (jLongValue > 0) {
                                        try {
                                            str = new SimpleDateFormat(str3, Locale.getDefault()).format(new Date(jLongValue));
                                        } catch (Throwable th7) {
                                            th2 = th7;
                                            sb = outputStreamWriter5;
                                            try {
                                                throw th2;
                                            } catch (Throwable th8) {
                                                C1884mi0.o(cursorQuery, th2);
                                                throw th8;
                                            }
                                        }
                                    } else {
                                        str = "Unknown";
                                    }
                                    try {
                                        i = cursorQuery.getInt(columnIndex4);
                                    } catch (Exception unused) {
                                        i = -1;
                                    }
                                    if (i != -1) {
                                        Integer num = new Integer(i);
                                        linkedHashMap = linkedHashMap2;
                                        Object objM0 = linkedHashMap.get(num);
                                        if (objM0 == null) {
                                            str2 = str3;
                                            context = context3;
                                            objM0 = ForegroundService.m0(context, i);
                                            linkedHashMap.put(num, objM0);
                                        } else {
                                            str2 = str3;
                                            context = context3;
                                        }
                                        str5 = (String) objM0;
                                    } else {
                                        linkedHashMap = linkedHashMap2;
                                        str2 = str3;
                                        context = context3;
                                    }
                                    String str8 = i3 != 1 ? i3 != 2 ? "Other" : "Sent" : "Received";
                                    String str9 = i3 == 1 ? str6 : foregroundService.q;
                                    StringBuilder sb2 = new StringBuilder();
                                    context3 = context;
                                    sb2.append("<--------- Message ");
                                    sb2.append(i2);
                                    sb2.append(" --------->");
                                    String string4 = sb2.toString();
                                    outputStreamWriter2 = outputStreamWriter5;
                                    try {
                                        int i6 = columnIndex3;
                                        outputStreamWriter2.append((CharSequence) string4).append('\n');
                                        outputStreamWriter2.append((CharSequence) ("Date: " + str)).append('\n');
                                        outputStreamWriter2.append((CharSequence) ("Type: " + str8)).append('\n');
                                        outputStreamWriter2.append((CharSequence) ("Name: " + str9 + " | SIM: " + str5 + " | Number: " + str6)).append('\n');
                                        outputStreamWriter2.append((CharSequence) "Message:").append('\n');
                                        outputStreamWriter2.append((CharSequence) str7).append('\n');
                                        outputStreamWriter2.append('\n');
                                        i2++;
                                        columnIndex = i4;
                                        columnIndex3 = i6;
                                        str3 = str2;
                                        outputStreamWriter4 = outputStreamWriter2;
                                        linkedHashMap2 = linkedHashMap;
                                        columnIndex2 = i5;
                                    } catch (Throwable th9) {
                                        th = th9;
                                        th2 = th;
                                        sb = outputStreamWriter2;
                                        throw th2;
                                    }
                                } catch (Throwable th10) {
                                    th = th10;
                                    outputStreamWriter2 = outputStreamWriter5;
                                }
                            }
                            outputStreamWriter3 = outputStreamWriter4;
                            cursorQuery.close();
                        } catch (Throwable th11) {
                            th = th11;
                            outputStreamWriter2 = outputStreamWriter4;
                        }
                    } else {
                        outputStreamWriter3 = outputStreamWriter4;
                    }
                    outputStreamWriter3.close();
                    return file;
                } catch (Throwable th12) {
                    th = th12;
                    th = th;
                    outputStreamWriter = sb;
                    throw th;
                }
            default:
                IJ.H(obj);
                ((ProgressBar) this.q).setVisibility(8);
                ((Button) this.r).setEnabled(true);
                TextView textView = (TextView) this.s;
                textView.setText("❌ خطا: " + ((Exception) this.t).getMessage());
                textView.setTextColor(-26624);
                return Oh0.a;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ C1798ln(Object obj, Object obj2, Object obj3, InterfaceC0220Im interfaceC0220Im, int i) {
        super(2, interfaceC0220Im);
        this.p = i;
        this.r = obj;
        this.s = obj2;
        this.t = obj3;
    }
}
