package com.cvte.dss.ups.camera;

import android.content.Context;
import android.util.Log;
import com.cvte.dss.ups.camera.model.CameraUpgradeInfo;
import com.cvte.dss.ups.camera.utils.CameraHelper;
import com.cvte.dss.ups.camera.utils.CommonUtils;
import com.cvte.dss.ups.plugin.IUpsPlugin;
import g.a.a.a.a;
import g.h.a.i;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import kotlin.Metadata;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes.dex */
@Metadata(bv = {1, 0, 3}, d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010 \n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\b\u0018\u0000 \u00162\u00020\u0001:\u0001\u0016B\u0007¢\u0006\u0004\b\u0014\u0010\u0015J\u0019\u0010\u0005\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0016¢\u0006\u0004\b\u0005\u0010\u0006J\u001d\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00040\u00072\u0006\u0010\u0003\u001a\u00020\u0002H\u0016¢\u0006\u0004\b\b\u0010\tJ7\u0010\u0011\u001a\u00020\r2\u0006\u0010\u0003\u001a\u00020\u00022\u0006\u0010\u000b\u001a\u00020\n2\u0006\u0010\f\u001a\u00020\n2\u0006\u0010\u000e\u001a\u00020\r2\u0006\u0010\u0010\u001a\u00020\u000fH\u0016¢\u0006\u0004\b\u0011\u0010\u0012J/\u0010\u0011\u001a\u00020\r2\u0006\u0010\u0003\u001a\u00020\u00022\u0006\u0010\f\u001a\u00020\n2\u0006\u0010\u000e\u001a\u00020\r2\u0006\u0010\u0010\u001a\u00020\u000fH\u0016¢\u0006\u0004\b\u0011\u0010\u0013¨\u0006\u0017"}, d2 = {"Lcom/cvte/dss/ups/camera/HidPlugin;", "Lcom/cvte/dss/ups/plugin/IUpsPlugin;", "Landroid/content/Context;", "context", "Lcom/cvte/dss/ups/plugin/IUpsPlugin$FirmwareInfo;", "getFirmwareInfo", "(Landroid/content/Context;)Lcom/cvte/dss/ups/plugin/IUpsPlugin$FirmwareInfo;", "", "getFirmwareInfos", "(Landroid/content/Context;)Ljava/util/List;", "", "id", "path", "", "force", "Lcom/cvte/dss/ups/plugin/IUpsPlugin$IUpgradeStatusListener;", "listener", "upgradeFirmware", "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;ZLcom/cvte/dss/ups/plugin/IUpsPlugin$IUpgradeStatusListener;)Z", "(Landroid/content/Context;Ljava/lang/String;ZLcom/cvte/dss/ups/plugin/IUpsPlugin$IUpgradeStatusListener;)Z", "<init>", "()V", "Companion", "lib_release"}, k = 1, mv = {1, 4, 0})
public final class HidPlugin implements IUpsPlugin {
    public static final String TAG = "HidPlugin";

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public IUpsPlugin.FirmwareInfo getFirmwareInfo(Context context) {
        o.g(context, "context");
        CameraHdiApi cameraHdiApiFindDevice = CameraHelper.INSTANCE.findDevice(context);
        if (cameraHdiApiFindDevice != null) {
            CameraManager cameraManager = new CameraManager(cameraHdiApiFindDevice);
            return new IUpsPlugin.FirmwareInfo("camera", "imx586", "camera", cameraManager.getVersion(), cameraManager.getOTAKey(), false, false);
        }
        Log.e(TAG, "can't find camera device");
        return null;
    }

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public List<IUpsPlugin.FirmwareInfo> getFirmwareInfos(Context context) throws ExecutionException, InterruptedException {
        o.g(context, "context");
        List listFindDevices$default = CameraHelper.findDevices$default(CameraHelper.INSTANCE, context, null, 2, null);
        StringBuilder sbF = a.F("getFirmwareInfos; count = ");
        sbF.append(listFindDevices$default.size());
        Log.i(TAG, sbF.toString());
        final ArrayList arrayList = new ArrayList(i.H(listFindDevices$default, 10));
        Iterator it = listFindDevices$default.iterator();
        while (it.hasNext()) {
            arrayList.add(((CameraHdiApi) it.next()).m0getCameraInfo());
        }
        Object[] array = arrayList.toArray(new CompletableFuture[0]);
        Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T>");
        CompletableFuture[] completableFutureArr = (CompletableFuture[]) array;
        Object obj = CompletableFuture.allOf((CompletableFuture[]) Arrays.copyOf(completableFutureArr, completableFutureArr.length)).thenApply((Function<? super Void, ? extends U>) new Function<T, U>() { // from class: com.cvte.dss.ups.camera.HidPlugin.getFirmwareInfos.1
            @Override // java.util.function.Function
            public final List<IUpsPlugin.FirmwareInfo> apply(Void r3) {
                List list = arrayList;
                ArrayList arrayList2 = new ArrayList(i.H(list, 10));
                Iterator<T> it2 = list.iterator();
                while (it2.hasNext()) {
                    arrayList2.add((IUpsPlugin.FirmwareInfo) ((CompletableFuture) it2.next()).get());
                }
                return arrayList2;
            }
        }).get();
        o.b(obj, "CompletableFuture.allOf(…t() }\n            }.get()");
        return (List) obj;
    }

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public List<IUpsPlugin.FirmwareInfo> getFirmwareInfosWithOptions(Context context, String str) {
        o.g(context, "context");
        o.g(str, "options");
        return IUpsPlugin.DefaultImpls.getFirmwareInfosWithOptions(this, context, str);
    }

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public boolean upgradeFirmware(final Context context, String id, String path, boolean force, final IUpsPlugin.IUpgradeStatusListener listener) {
        o.g(context, "context");
        o.g(id, "id");
        o.g(path, "path");
        o.g(listener, "listener");
        final CameraUpgradeInfo cameraUpgradeInfoDecode = CameraUpgradeInfo.INSTANCE.decode(id);
        if (cameraUpgradeInfoDecode == null) {
            return upgradeFirmware(context, path, force, listener);
        }
        CameraHelper cameraHelper = CameraHelper.INSTANCE;
        if (cameraHelper.isUpgrading(cameraUpgradeInfoDecode)) {
            Log.e(TAG, "camera isUpgrading");
            listener.onFailed("camera is upgrading");
            return false;
        }
        List<CameraHdiApi> listFindDevices = cameraHelper.findDevices(context, new HidPlugin$upgradeFirmware$cameras$1(cameraUpgradeInfoDecode));
        final ArrayList arrayList = new ArrayList(i.H(listFindDevices, 10));
        Iterator<T> it = listFindDevices.iterator();
        while (it.hasNext()) {
            arrayList.add(((CameraHdiApi) it.next()).upgradeCamera(path));
        }
        new Thread(new Runnable() { // from class: com.cvte.dss.ups.camera.HidPlugin.upgradeFirmware.1
            @Override // java.lang.Runnable
            public final void run() throws ExecutionException, InterruptedException {
                CameraHelper.INSTANCE.upgradeCamera(context, cameraUpgradeInfoDecode, arrayList, listener);
            }
        }).start();
        return true;
    }

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public boolean upgradeFirmware(Context context, String str, String str2, boolean z2, String str3, IUpsPlugin.IUpgradeStatusListener iUpgradeStatusListener) {
        o.g(context, "context");
        o.g(str, "id");
        o.g(str2, "path");
        o.g(str3, "options");
        o.g(iUpgradeStatusListener, "listener");
        return IUpsPlugin.DefaultImpls.upgradeFirmware(this, context, str, str2, z2, str3, iUpgradeStatusListener);
    }

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public boolean upgradeFirmware(final Context context, String path, boolean force, final IUpsPlugin.IUpgradeStatusListener listener) {
        String str;
        o.g(context, "context");
        o.g(path, "path");
        o.g(listener, "listener");
        CameraHelper cameraHelper = CameraHelper.INSTANCE;
        final CameraHdiApi cameraHdiApiFindDevice = cameraHelper.findDevice(context);
        if (!new File(path).exists()) {
            Log.e(TAG, "upgrade file not found");
            str = "upgrade file no find";
        } else if (cameraHdiApiFindDevice == null) {
            Log.e(TAG, "camera not found");
            str = "no find";
        } else {
            if (!cameraHelper.isUpgrading(cameraHdiApiFindDevice.getCameraInfo())) {
                final String strCopyFileToTemp = CommonUtils.INSTANCE.copyFileToTemp(path, CameraManager.TEMP_CAMERA_FILE_DIR);
                new Thread(new Runnable() { // from class: com.cvte.dss.ups.camera.HidPlugin.upgradeFirmware.2
                    @Override // java.lang.Runnable
                    public final void run() {
                        new CameraManager(cameraHdiApiFindDevice).upgradeCamera(strCopyFileToTemp, listener, context);
                    }
                }).start();
                return true;
            }
            Log.e(TAG, "camera isUpgrading");
            str = "camera is upgrading";
        }
        listener.onFailed(str);
        return false;
    }
}
