package com.ifpdos.factorytest.udi;

import android.content.Intent;
import android.media.MediaPlayer;
import android.util.Log;
import com.ifpdos.factorytest.App;
import com.ifpdos.factorytest.Common;
import com.ifpdos.factorytest.VideoViewActivity;
import com.ifpdos.udi.sdk.service.sdk.server.Response;
import com.ifpdos.udi.sdk.service.sdk.server.UdiException;
import java.io.File;
import java.util.Locale;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.collections.SetsKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;

/* JADX INFO: compiled from: VideoTestHandler.kt */
/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000F\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0005\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J!\u0010\u0005\u001a\u0013\u0012\u0004\u0012\u00020\u0007\u0012\u0004\u0012\u00020\b0\u0006¢\u0006\u0002\b\t2\u0006\u0010\n\u001a\u00020\u000bH\u0014J\u0010\u0010\f\u001a\u00020\r2\u0006\u0010\n\u001a\u00020\u000bH\u0014J\b\u0010\u000e\u001a\u00020\u000fH\u0016J\f\u0010\u0010\u001a\u0006\u0012\u0002\b\u00030\u0011H\u0016J\b\u0010\u0012\u001a\u00020\u0004H\u0016J\u0010\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u0004H\u0002J\u0010\u0010\u0016\u001a\u00020\u00142\u0006\u0010\u0017\u001a\u00020\u0004H\u0002J\u0010\u0010\u0018\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u0004H\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0086T¢\u0006\u0002\n\u0000¨\u0006\u0019"}, d2 = {"Lcom/ifpdos/factorytest/udi/VideoTestHandler;", "Lcom/ifpdos/factorytest/udi/BaseModuleTestStt;", "()V", "EXIT_ACTION", "", "applyIntent", "Lkotlin/Function1;", "Landroid/content/Intent;", "", "Lkotlin/ExtensionFunctionType;", "body", "Lcom/ifpdos/factorytest/udi/ModuleTestBody;", "beforeStartModuleTest", "Lcom/ifpdos/factorytest/udi/ModuleTestStateEnum;", "exitModuleTest", "Lcom/ifpdos/udi/sdk/service/sdk/server/Response;", "getActivityClass", "Ljava/lang/Class;", "getType", "isAudioFormatSupported", "", "filename", "isVideoFilePlayable", "path", "isVideoFormatSupported", "app_generalRelease"}, k = 1, mv = {1, 8, 0}, xi = 48)
public final class VideoTestHandler extends BaseModuleTestStt {
    public static final String EXIT_ACTION = "com.ifpdos.factorytest.intent.action.EXIT_VIDEO";
    public static final VideoTestHandler INSTANCE = new VideoTestHandler();

    @Override // com.ifpdos.factorytest.udi.BaseModuleTestStt
    public Class<?> getActivityClass() {
        return VideoViewActivity.class;
    }

    private VideoTestHandler() {
    }

    @Override // com.ifpdos.factorytest.udi.BaseModuleTestStt
    public Response exitModuleTest() {
        App.getInstance().sendBroadcast(new Intent(EXIT_ACTION));
        return Response.INSTANCE.makeOkResponse();
    }

    @Override // com.ifpdos.factorytest.udi.BaseModuleTestStt
    protected ModuleTestStateEnum beforeStartModuleTest(ModuleTestBody body) {
        ModuleTestStateEnum moduleTestStateEnum;
        Intrinsics.checkNotNullParameter(body, "body");
        String path = body.getPath();
        if (path != null) {
            if (new File(path).exists() && new File(path).isFile()) {
                VideoTestHandler videoTestHandler = INSTANCE;
                if ((videoTestHandler.isAudioFormatSupported(path) || videoTestHandler.isVideoFormatSupported(path)) && videoTestHandler.isVideoFilePlayable(path)) {
                    moduleTestStateEnum = ModuleTestStateEnum.NORMAL;
                } else {
                    moduleTestStateEnum = ModuleTestStateEnum.NOT_SUPPORT;
                }
            } else {
                moduleTestStateEnum = ModuleTestStateEnum.PARAM_ERROR;
            }
            if (moduleTestStateEnum != null) {
                return moduleTestStateEnum;
            }
        }
        return ModuleTestStateEnum.NORMAL;
    }

    @Override // com.ifpdos.factorytest.udi.BaseModuleTestStt
    protected Function1<Intent, Unit> applyIntent(final ModuleTestBody body) {
        Intrinsics.checkNotNullParameter(body, "body");
        return new Function1<Intent, Unit>() { // from class: com.ifpdos.factorytest.udi.VideoTestHandler.applyIntent.1
            {
                super(1);
            }

            @Override // kotlin.jvm.functions.Function1
            public /* bridge */ /* synthetic */ Unit invoke(Intent intent) throws UdiException {
                invoke2(intent);
                return Unit.INSTANCE;
            }

            /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
            public final void invoke2(Intent intent) throws UdiException {
                Intrinsics.checkNotNullParameter(intent, "$this$null");
                String path = body.getPath();
                String str = path;
                if (str == null || str.length() == 0) {
                    path = null;
                }
                if (path == null) {
                    File fileFindFileOnUSB = Common.findFileOnUSB(VideoViewActivity.FACTORY_TEST_VIDEO_NAME);
                    if (fileFindFileOnUSB == null) {
                        throw new UdiException(400, new Response.ErrorBody("not found file"));
                    }
                    path = fileFindFileOnUSB.getAbsolutePath();
                }
                intent.putExtra(VideoViewActivity.KEY_VIDEO_PATH, path);
            }
        };
    }

    @Override // com.ifpdos.factorytest.udi.BaseModuleTestStt
    public String getType() {
        return "video_preview";
    }

    private final boolean isVideoFilePlayable(String path) {
        boolean z;
        MediaPlayer mediaPlayer = new MediaPlayer();
        try {
            try {
                mediaPlayer.setDataSource(path);
                mediaPlayer.prepare();
                mediaPlayer.release();
                z = true;
            } catch (Exception e) {
                Log.e(getTAG(), "Video file is not playable: " + e.getMessage());
                mediaPlayer.release();
                z = false;
            }
            return z;
        } catch (Throwable th) {
            mediaPlayer.release();
            throw th;
        }
    }

    private final boolean isAudioFormatSupported(String filename) {
        String upperCase = StringsKt.substringAfterLast(filename, '.', "").toUpperCase(Locale.ROOT);
        Intrinsics.checkNotNullExpressionValue(upperCase, "toUpperCase(...)");
        if (upperCase.length() == 0) {
            return false;
        }
        return SetsKt.setOf((Object[]) new String[]{"M3U", "CUE", "PLS", "MP2", "MP3", "CDDA", "AAC", "M4A", "WAV", "AIFF", "OGG", "FLAC", "RA", "MKA", "EC3", "AC3", "DTS", "MLP", "APE", "OGA", "MID", "MIDI", "RTTTL", "OTA", "AMR", "AWB", "AEA", "AU", "DAUD", "OMA", "EAC3", "GSM", "TRUEHD", "TTA", "MPC", "MPC8"}).contains(upperCase);
    }

    private final boolean isVideoFormatSupported(String filename) {
        String upperCase = StringsKt.substringAfterLast(filename, '.', "").toUpperCase(Locale.ROOT);
        Intrinsics.checkNotNullExpressionValue(upperCase, "toUpperCase(...)");
        if (upperCase.length() == 0) {
            return false;
        }
        return SetsKt.setOf((Object[]) new String[]{"AVSTS", "MTS", "M2T", "M2TS", "TRP", "TP", "PS", "AVS", "SWF", "OGM", "FLV", "RMVB", "RM", "3GP", "M4V", "MP4", "MOV", "MKV", "IFO", "DIVX", "TS", "AVI", "DAT", "VOB", "MPG", "MPEG", "ASF", "WMV", "3GPP", "3G2", "3GPP2", "F4V", "M1V", "M2V", "M2P", "ASF", "DV", "IFF", "MJ2", "ANM", "H261", "H263", "H264", "YUV", "CIF", "QCIF", "RGB", "VC1", "Y4M", "WEBM", "AMV"}).contains(upperCase);
    }
}
