package a.c.d.h;

import a.c.b.x;
import android.content.Context;
import com.ucar.databus.proto.UCarProto;
import com.ucar.vehiclesdk.UCarCommon;
import java.io.IOException;

public class d {
    private static final String c = "SensorManager";
    private static final int d = 90;
    private static final int e = -90;
    private static final int f = 180;
    private static final int g = -180;
    private static final int h = 0;

    /* renamed from: a  reason: collision with root package name */
    private Context f136a;
    private a.b.a.g.a b = new a.b.a.g.a(a.c.b.z.b.SENSOR, false, true);

    public class a implements a.c.b.z.e {
        public a() {
        }

        @Override // a.c.b.z.e
        public void a(Boolean bool) {
            a.a.a.b.a(d.c, "sendGpsDatao succeeded");
        }

        @Override // a.c.b.z.c
        public void a(Exception exc) {
            a.a.a.b.b(d.c, "sendGpsData failed: ", exc);
        }
    }

    public class b implements a.c.b.z.e {
        public b() {
        }

        @Override // a.c.b.z.e
        public void a(Boolean bool) {
            a.a.a.b.a(d.c, "sendLightsData succeeded");
        }

        @Override // a.c.b.z.c
        public void a(Exception exc) {
            a.a.a.b.b(d.c, "sendLightsData failed.", exc);
        }
    }

    public class c implements a.c.b.z.e {
        public c() {
        }

        @Override // a.c.b.z.e
        public void a(Boolean bool) {
            a.a.a.b.a(d.c, "sendGyroScopeData succeeded");
        }

        @Override // a.c.b.z.c
        public void a(Exception exc) {
            a.a.a.b.b(d.c, "sendGyroScopeData failed", exc);
        }
    }

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

        @Override // a.c.b.z.e
        public void a(Boolean bool) {
            a.a.a.b.a(d.c, "sendAccelerationData succeeded");
        }

        @Override // a.c.b.z.c
        public void a(Exception exc) {
            a.a.a.b.b(d.c, "sendAccelerationData failed.", exc);
        }
    }

    public class e implements a.c.b.z.e {
        public e() {
        }

        @Override // a.c.b.z.e
        public void a(Boolean bool) {
            a.a.a.b.a(d.c, "sendOilData succeeded");
        }

        @Override // a.c.b.z.c
        public void a(Exception exc) {
            a.a.a.b.b(d.c, "sendOilData failed.", exc);
        }
    }

    public class f implements a.c.b.z.e {
        public f() {
        }

        @Override // a.c.b.z.e
        public void a(Boolean bool) {
            a.a.a.b.a(d.c, "sendGearData succeeded");
        }

        @Override // a.c.b.z.c
        public void a(Exception exc) {
            a.a.a.b.b(d.c, "sendGearData failed.", exc);
        }
    }

    public class g implements a.c.b.z.e {
        public g() {
        }

        @Override // a.c.b.z.e
        public void a(Boolean bool) {
            a.a.a.b.a(d.c, "sendLightSensorInfoData succeeded");
        }

        @Override // a.c.b.z.c
        public void a(Exception exc) {
            a.a.a.b.b(d.c, "sendLightSensorInfoData failed.", exc);
        }
    }

    public d(Context context) {
        this.f136a = context;
    }

    private boolean a() {
        a.b.a.g.a aVar = this.b;
        return aVar != null && aVar.b();
    }

    public void a(String str) {
        a.a.a.b.a(c, "SensorChannel start address:" + str);
        a.b.a.g.a aVar = this.b;
        if (aVar == null) {
            a.a.a.b.b(c, "sensor channel is null");
        } else if (aVar.b()) {
            a.a.a.b.a(c, "sensor channel server has opened");
        } else {
            try {
                this.b.a(0, str);
            } catch (IOException e2) {
                a.a.a.b.a(c, "Start sensor channel error.", e2);
            }
        }
    }

    public boolean a(UCarCommon.AccelerationInfo accelerationInfo) {
        String str;
        if (accelerationInfo == null) {
            str = " sendAccelerationData() error";
        } else if (!a()) {
            str = " sendAccelerationData() channel not ready, please check!";
        } else {
            this.b.a(x.a((UCarProto.Acceleration) UCarProto.Acceleration.newBuilder().setAccX(accelerationInfo.getAccX()).setAccY(accelerationInfo.getAccY()).setAccZ(accelerationInfo.getAccZ()).setTimestamp(accelerationInfo.getTimeStamp()).build()), (a.c.b.z.e) new C0015d());
            return true;
        }
        a.a.a.b.b(c, str);
        return false;
    }

    public boolean a(UCarCommon.GPSInfo gPSInfo) {
        String str;
        if (gPSInfo == null || gPSInfo.getLatitude() < -90.0d || gPSInfo.getLatitude() > 90.0d || gPSInfo.getLongitude() < -180.0d || gPSInfo.getLongitude() > 180.0d || gPSInfo.getSpeed() < 0) {
            str = " sendGpsData() args error";
        } else if (!a()) {
            str = " sendGpsData() channel not ready, please check!";
        } else {
            this.b.a(x.a((UCarProto.Gps) UCarProto.Gps.newBuilder().setAltitude(gPSInfo.getAltitude()).setLatitude(gPSInfo.getLatitude()).setLongitude(gPSInfo.getLongitude()).setAntennaState(gPSInfo.getAntennaState()).setPdop(gPSInfo.getpDop()).setSpeed(gPSInfo.getSpeed()).setHeading(gPSInfo.getHeading()).setSatsUsed(gPSInfo.getSatsUsed()).setSatsVisible(gPSInfo.getSatsVisible()).setTimestamp(gPSInfo.getTimeStamp()).build()), (a.c.b.z.e) new a());
            return true;
        }
        a.a.a.b.b(c, str);
        return false;
    }

    public boolean a(UCarCommon.GearStateInfo gearStateInfo) {
        String str;
        if (gearStateInfo == null || gearStateInfo.getGearState() == null) {
            str = "sendGearData() args error";
        } else if (!a()) {
            str = " sendGearData() channel not ready, please check!";
        } else {
            this.b.a(x.a((UCarProto.GearInfo) UCarProto.GearInfo.newBuilder().setSpeed(gearStateInfo.getCurrentSpeed()).setGear(UCarProto.GearInfo.GearState.forNumber(gearStateInfo.getGearState().getValue())).build()), (a.c.b.z.e) new f());
            return true;
        }
        a.a.a.b.b(c, str);
        return false;
    }

    public boolean a(UCarCommon.GyroscopeInfo gyroscopeInfo) {
        String str;
        if (gyroscopeInfo == null || gyroscopeInfo.getLegyroX() < -180.0d || gyroscopeInfo.getLegyroX() > 180.0d || gyroscopeInfo.getLegyroY() < -90.0d || gyroscopeInfo.getLegyroY() > 90.0d || gyroscopeInfo.getLegyroZ() < 0.0d || gyroscopeInfo.getLegyroZ() > 360.0d) {
            str = "sendGyroScopeData args error";
        } else if (!a()) {
            str = " sendGyroScopeData() channel not ready, please check!";
        } else {
            this.b.a(x.a((UCarProto.GyroScope) UCarProto.GyroScope.newBuilder().setGyroType(gyroscopeInfo.getGyroType()).setLegyroX(gyroscopeInfo.getLegyroX()).setLegyroY(gyroscopeInfo.getLegyroY()).setLegyroZ(gyroscopeInfo.getLegyroZ()).setTimestamp(gyroscopeInfo.getTimeStamp()).build()), (a.c.b.z.e) new c());
            return true;
        }
        a.a.a.b.b(c, str);
        return false;
    }

    public boolean a(UCarCommon.LightSensorInfo lightSensorInfo) {
        String str;
        if (lightSensorInfo == null || lightSensorInfo.getMinLux() < 0.0d || lightSensorInfo.getMaxLux() < 0.0d || lightSensorInfo.getCurrentLux() < 0.0d || lightSensorInfo.getCurrentLux() < lightSensorInfo.getMinLux() || lightSensorInfo.getCurrentLux() > lightSensorInfo.getMaxLux()) {
            str = "sendLightSensorInfoData() args error";
        } else if (!a()) {
            str = " sendLightSensorInfoData() channel not ready, please check!";
        } else {
            this.b.a(x.a((UCarProto.LightSensorInfo) UCarProto.LightSensorInfo.newBuilder().setMaxLux(lightSensorInfo.getMaxLux()).setMinLux(lightSensorInfo.getMinLux()).setCurrentLux(lightSensorInfo.getCurrentLux()).build()), (a.c.b.z.e) new g());
            return true;
        }
        a.a.a.b.b(c, str);
        return false;
    }

    public boolean a(UCarCommon.LightsInfo lightsInfo) {
        String str;
        if (lightsInfo == null) {
            str = " sendLightsData() args error";
        } else if (!a()) {
            str = " sendLightsData() channel not ready, please check!";
        } else {
            this.b.a(x.a((UCarProto.Lights) UCarProto.Lights.newBuilder().setBackupLampOn(lightsInfo.isBackupLampOn()).setClearanceLampOn(lightsInfo.isClearanceLampOn()).setHighBeamOn(lightsInfo.isHighBeamOn()).setLowBeamOn(lightsInfo.isLowBeamOn()).setStopLampOn(lightsInfo.isStopLampOn()).build()), (a.c.b.z.e) new b());
            return true;
        }
        a.a.a.b.b(c, str);
        return false;
    }

    public boolean a(UCarCommon.OilInfo oilInfo) {
        if (oilInfo == null || oilInfo.getCurrentFuel() < 0 || oilInfo.getMaxFuel() < 0 || oilInfo.getMinFuel() < 0 || oilInfo.getCurrentFuel() > oilInfo.getMaxFuel() || oilInfo.getCurrentFuel() < oilInfo.getMinFuel()) {
            a.a.a.b.b(c, "sendOilData() args error");
            return false;
        } else if (!a()) {
            a.a.a.b.b(c, " sendOilData() channel not ready, please check!");
            return true;
        } else {
            this.b.a(x.a((UCarProto.Oil) UCarProto.Oil.newBuilder().setMaxFuel(oilInfo.getMaxFuel()).setCurrentFuel(oilInfo.getCurrentFuel()).build()), (a.c.b.z.e) new e());
            return true;
        }
    }

    public void b() {
        if (this.b != null) {
            a.a.a.b.a(c, "close sensor channel");
            this.b.i();
        }
    }
}
