package a.b.a.i;

import a.a.a.b;
import a.b.a.i.b;
import android.content.Context;
import android.text.TextUtils;
import com.share.connect.Device;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

public class c {
    private static final String c = "CarVerifier";
    private static final String d = "ccd.data";

    /* renamed from: a  reason: collision with root package name */
    private Context f32a;
    private String b;

    public c(Context context) {
        this.f32a = context;
        this.b = d;
    }

    public c(Context context, String str) {
        this.f32a = context;
        if (a(str)) {
            this.b = str;
        } else {
            this.b = d;
        }
    }

    private boolean a(String str) {
        String str2;
        if (TextUtils.isEmpty(str)) {
            str2 = "ccd file path is empty!";
        } else {
            File file = new File(str);
            if (file.exists() && file.isFile() && file.canRead()) {
                return true;
            }
            str2 = "ccd file path is invalid!";
        }
        b.b(c, str2);
        return false;
    }

    private Reader b() {
        return d.equals(this.b) ? d() : f();
    }

    private Reader c() {
        b.a(c, "getDataReader, file: " + this.b);
        if (this.f32a != null) {
            return b();
        }
        b.b(c, "getDataReader null context");
        return null;
    }

    private Reader d() {
        b.a(c, "getDefaultReader");
        try {
            return new InputStreamReader(this.f32a.getResources().getAssets().open(d), StandardCharsets.UTF_8);
        } catch (IOException e) {
            b.b(c, "getDefaultReader failed: " + e);
            return null;
        }
    }

    private Reader f() {
        b.a(c, "getReader, file: " + this.b);
        try {
            return new InputStreamReader(new FileInputStream(this.b), StandardCharsets.UTF_8);
        } catch (FileNotFoundException e) {
            b.b(c, "getReader error: " + e);
            return null;
        }
    }

    public b a() {
        try {
            Reader c2 = c();
            try {
                b a2 = new b.a().a(c2).a();
                if (c2 != null) {
                    c2.close();
                }
                return a2;
            } catch (Throwable th) {
                th.addSuppressed(th);
            }
            throw th;
        } catch (IOException | IllegalArgumentException e) {
            a.a.a.b.b(c, "getCarData exception: ", e);
            return null;
        }
    }

    public Device e() {
        b a2 = a();
        if (a2 != null) {
            return a2.a();
        }
        return null;
    }

    public String g() {
        try {
            Reader c2 = c();
            try {
                String b2 = new b.a().a(c2).b();
                if (c2 != null) {
                    c2.close();
                }
                return b2;
            } catch (Throwable th) {
                th.addSuppressed(th);
            }
            throw th;
        } catch (IOException | IllegalArgumentException e) {
            a.a.a.b.b(c, "readCarData exception: " + e);
            return null;
        }
    }
}
