package a.c.d.h;

import a.b.a.i.c;
import a.c.b.q;
import a.c.b.z.e;
import android.content.Context;
import android.text.TextUtils;
import com.google.protobuf.ByteString;
import com.ucar.databus.proto.UCarProto;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class b {
    private static final String c = "CarCertManager";

    /* renamed from: a  reason: collision with root package name */
    private final Context f134a;
    private final a.b.a.g.a b;

    public class a extends a.b.a.g.a {
        public final /* synthetic */ String E;

        /* renamed from: a.c.d.h.b$a$a  reason: collision with other inner class name */
        public class C0014a implements e {
            public C0014a() {
            }

            @Override // a.c.b.z.e
            public void a(Boolean bool) {
                b.this.b.i();
            }

            @Override // a.c.b.z.c
            public void a(Exception exc) {
                a.a.a.b.b(b.c, "sending car certificate error: " + exc.getMessage(), exc);
            }
        }

        /* JADX INFO: super call moved to the top of the method (can break code semantics) */
        public a(a.c.b.z.b bVar, boolean z, boolean z2, String str) {
            super(bVar, z, z2);
            this.E = str;
        }

        @Override // a.c.b.z.g.e, a.c.b.z.f
        public void h() {
            String g = new c(b.this.f134a, this.E).g();
            if (TextUtils.isEmpty(g)) {
                a.a.a.b.b(b.c, "failed to get car cert data");
                return;
            }
            a.a.a.b.a(b.c, "sending car certificate to phone");
            a(q.a((UCarProto.CarCertificate) UCarProto.CarCertificate.newBuilder().setContent(ByteString.copyFrom(g.getBytes(StandardCharsets.UTF_8))).build()), (e) new C0014a());
        }
    }

    public b(Context context, String str) {
        this.f134a = context;
        this.b = new a(a.c.b.z.b.CERT, false, true, str);
    }

    public void a() {
        a.a.a.b.a(c, "stopCertChannel");
        this.b.i();
    }

    public void a(String str) {
        try {
            this.b.a(0, str);
        } catch (IOException e) {
            a.a.a.b.b(c, "Start car certificate error: ", e);
        }
    }
}
