package com.dss.ups.sp51a.dongle;

import android.content.Context;
import android.util.Log;
import com.cvte.dss.ups.plugin.IUpsPlugin;
import g.a.a.a.a;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import kotlin.Metadata;
import kotlin.NotImplementedError;
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/dss/ups/sp51a/dongle/Plugin;", "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 Plugin implements IUpsPlugin {
    public static final String TAG = "SP51A-Dongle-Plugin";

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public IUpsPlugin.FirmwareInfo getFirmwareInfo(Context context) {
        o.g(context, "context");
        throw new NotImplementedError(a.t("An operation is not implemented: ", "Not yet implemented"));
    }

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public List<IUpsPlugin.FirmwareInfo> getFirmwareInfos(Context context) {
        o.g(context, "context");
        ArrayList arrayList = new ArrayList();
        String version = DongleHid.INSTANCE.getVersion(context);
        Log.i(TAG, "get sp51a dongle version :" + version);
        Log.i(TAG, "get sp51a dongle ota_key :" + ConstantKt.SP51A_DONGLE_OTA_KEY);
        if (!(version == null || version.length() == 0)) {
            if (!(ConstantKt.SP51A_DONGLE_OTA_KEY.length() == 0)) {
                arrayList.add(new IUpsPlugin.FirmwareInfo("sp51a-dongle", "TLSR8272", "sp51a-dongle", version.toString(), ConstantKt.SP51A_DONGLE_OTA_KEY, false, false, "0"));
            }
        }
        return arrayList;
    }

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public boolean upgradeFirmware(Context context, String id, String path, boolean force, IUpsPlugin.IUpgradeStatusListener listener) throws InterruptedException {
        String str;
        o.g(context, "context");
        o.g(id, "id");
        o.g(path, "path");
        o.g(listener, "listener");
        if (new File(path).exists()) {
            DongleHid dongleHid = DongleHid.INSTANCE;
            if (dongleHid.upgradeFirmwareStart(context, path, listener)) {
                Thread.sleep(2005L);
                if (dongleHid.uploadFile(context, path, listener)) {
                    Thread.sleep(205L);
                    if (dongleHid.upgradeFirmwareEnd(context)) {
                        listener.onComplete();
                        return true;
                    }
                    str = "upgradeFirmwareEnd failed";
                } else {
                    str = "uploadFile failed";
                }
            } else {
                str = "upgradeFirmwareStart failed";
            }
            Log.e(TAG, str);
        } else {
            str = "file not found";
        }
        listener.onFailed(str);
        return false;
    }

    @Override // com.cvte.dss.ups.plugin.IUpsPlugin
    public boolean upgradeFirmware(Context context, String path, boolean force, IUpsPlugin.IUpgradeStatusListener listener) {
        o.g(context, "context");
        o.g(path, "path");
        o.g(listener, "listener");
        throw new NotImplementedError(a.t("An operation is not implemented: ", "Not yet implemented"));
    }
}
