导航菜单

页面标题

页面副标题

Mabilis Cash v1.19.4 - PHLiveRecognitionActivity.java 源代码

正在查看: Mabilis Cash v1.19.4 应用的 PHLiveRecognitionActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.fintopia.face;

import android.app.Activity;
import android.content.Intent;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.TextureView;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.fintopia.face.databinding.LayoutYqdLivenessRecognitionBinding;
import com.fintopia.face.living.faceDetector.IDetection;
import com.fintopia.face.living.faceDetector.IMediaPlayer;
import com.fintopia.face.living.faceDetector.SensorUtil;
import com.fintopia.face.models.FaceIdCard;
import com.fintopia.face.models.RecognitionSource;
import com.fintopia.face.tools.Screen;
import com.lingyue.supertoolkit.statistics.TrackingUtil;
import com.lingyue.supertoolkit.tools.customtools.CrashReporter;
import com.lingyue.supertoolkit.tools.filetools.AssetsUtil;
import com.lingyue.supertoolkit.widgets.ToastCompat;
import com.megvii.livenessdetection.DetectionConfig;
import com.megvii.livenessdetection.DetectionFrame;
import com.megvii.livenessdetection.Detector;
import com.megvii.livenessdetection.FaceQualityManager;
import com.megvii.livenessdetection.bean.FaceIDDataStruct;
import com.megvii.livenessdetection.bean.FaceInfo;
import com.veda.android.bananalibrary.infrastructure.BaseActivity;
import com.veda.android.statistics.MsTrackDataUtils;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import io.sentry.ITransaction;
import io.sentry.Sentry;
import io.sentry.SpanStatus;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

public class PHLiveRecognitionActivity extends BaseActivity implements Camera.PreviewCallback, Detector.DetectionListener, TextureView.SurfaceTextureListener {
    public static final String EXTRA_FACE_ID_CARD = "extra_face_id_card";

    private LayoutYqdLivenessRecognitionBinding f3429j;

    private Detector f3430k;

    private ICamera f3431l;

    private Handler f3432m;

    private IMediaPlayer f3433n;

    private IDetection f3434o;

    private boolean f3436q;

    private FaceQualityManager f3437r;

    private SensorUtil f3438s;
    private int u;
    private AudioManager v;

    @Nullable
    private Disposable f3435p = null;
    private final FaceIdCard t = new FaceIdCard();
    private boolean w = false;
    private boolean x = false;
    ITransaction y = Sentry.B("FacePPCheck", "facepp_v2_check");
    private Runnable z = new Runnable() {
        @Override
        public void run() {
            PHLiveRecognitionActivity.this.t();
            if (PHLiveRecognitionActivity.this.f3434o.f3483g != null) {
                PHLiveRecognitionActivity pHLiveRecognitionActivity = PHLiveRecognitionActivity.this;
                pHLiveRecognitionActivity.changeType(pHLiveRecognitionActivity.f3434o.f3483g.get(0), 10L);
            }
        }
    };
    private int A = 0;
    private int B = 0;
    private boolean C = false;

    static class AnonymousClass3 {

        static final int[] f3441a;

        static {
            int[] iArr = new int[Detector.DetectionFailedType.values().length];
            f3441a = iArr;
            try {
                iArr[Detector.DetectionFailedType.ACTIONBLEND.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f3441a[Detector.DetectionFailedType.NOTVIDEO.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f3441a[Detector.DetectionFailedType.TIMEOUT.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    private void A() {
        B();
        this.f3435p = Observable.O(2L, TimeUnit.SECONDS).w(AndroidSchedulers.a()).K(Schedulers.b()).G(new Consumer() {
            public final void accept(Object obj) {
                PHLiveRecognitionActivity.this.z((Long) obj);
            }
        });
    }

    private void B() {
        Disposable disposable = this.f3435p;
        if (disposable == null || disposable.d()) {
            return;
        }
        this.f3435p.dispose();
        this.f3435p = null;
    }

    private void C(@NonNull SensorUtil sensorUtil) {
        if (sensorUtil.b()) {
            return;
        }
        if (sensorUtil.f3501d == 0.0f) {
            if (this.w) {
                return;
            }
            TrackingUtil.i(this, "verify_living_sensor_lost_status");
            this.w = true;
            return;
        }
        if (this.x) {
            return;
        }
        TrackingUtil.i(this, "verify_living_sensor_not_vertical");
        this.x = true;
    }

    private void o() {
        if (this.C) {
            this.f3431l.g(this.f3429j.f3470l.getSurfaceTexture());
        }
    }

    private void p(DetectionFrame detectionFrame) {
        FaceInfo faceInfo;
        this.A++;
        if (detectionFrame != null && (faceInfo = detectionFrame.getFaceInfo()) != null) {
            if (faceInfo.eyeLeftOcclusion > 0.5d || faceInfo.eyeRightOcclusion > 0.5d) {
                if (this.A > 10) {
                    this.A = 0;
                    this.f3429j.f3465g.setText(getString(R.string.live_no_eye));
                    return;
                }
                return;
            }
            if (faceInfo.mouthOcclusion > 0.5d) {
                if (this.A > 10) {
                    this.A = 0;
                    this.f3429j.f3465g.setText(getString(R.string.live_no_mouth));
                    return;
                }
                return;
            }
            this.f3434o.c(faceInfo.faceTooLarge);
        }
        faceInfoChecker(this.f3437r.feedFrame(detectionFrame));
    }

    private void q(int i2, boolean z, String str) {
        if (z) {
            ITransaction iTransaction = this.y;
            SpanStatus spanStatus = SpanStatus.OK;
            iTransaction.a("faceDetectResult", spanStatus.name());
            this.y.i(spanStatus);
            ToastCompat.g(this, getResources().getString(i2));
            w();
            return;
        }
        ITransaction iTransaction2 = this.y;
        if (TextUtils.isEmpty(str)) {
            str = SpanStatus.UNKNOWN_ERROR.name();
        }
        iTransaction2.a("faceDetectResult", str);
        this.y.i(SpanStatus.INTERNAL_ERROR);
        ToastCompat.e(this, getResources().getString(i2));
        finish();
    }

    private void r() {
        if (this.f3436q) {
            return;
        }
        B();
        this.f3436q = true;
        Animation loadAnimation = AnimationUtils.loadAnimation(this, R.anim.liveness_rightin);
        Animation loadAnimation2 = AnimationUtils.loadAnimation(this, R.anim.liveness_leftout);
        this.f3429j.f3462d.startAnimation(loadAnimation2);
        this.f3434o.f3479c[0].setVisibility(0);
        this.f3434o.f3479c[0].startAnimation(loadAnimation);
        loadAnimation2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                PHLiveRecognitionActivity.this.f3429j.f3468j.setVisibility(0);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }
        });
        this.f3432m.post(this.z);
    }

    public static void startForResult(Activity activity, int i2, int i3) {
        Intent intent = new Intent(activity, (Class<?>) PHLiveRecognitionActivity.class);
        intent.putExtra("actionNumber", i2);
        activity.startActivityForResult(intent, i3);
    }

    public void t() {
        if (this.f3431l.f3422a == null) {
            return;
        }
        this.f3429j.f3467i.setVisibility(4);
        this.f3434o.d();
        this.B = 0;
        this.f3430k.reset();
        this.f3430k.changeDetectionType(this.f3434o.f3483g.get(0));
    }

    private void u(@Nullable Bundle bundle) {
        if (bundle == null) {
            bundle = getIntent().getExtras();
        }
        if (bundle != null) {
            this.u = bundle.getInt("actionNumber");
        }
    }

    private boolean v() {
        try {
            if (this.v == null) {
                this.v = (AudioManager) getSystemService("audio");
            }
            int ringerMode = this.v.getRingerMode();
            return ringerMode == 0 || ringerMode == 1;
        } catch (Exception e2) {
            CrashReporter.a(e2);
            return false;
        }
    }

    private void w() {
        Intent intent = new Intent();
        intent.putExtra(EXTRA_FACE_ID_CARD, this.t);
        setResult(-1, intent);
        finish();
    }

    public void x(long j2) {
        this.f3429j.f3469k.setText(String.format(Locale.CHINA, "%d", Long.valueOf(j2 / 1000)));
    }

    public void y() {
        q(R.string.live_verify_success, true, "");
    }

    public void z(Long l2) throws Exception {
        if (v()) {
            return;
        }
        this.f3433n.d();
    }

    public void changeType(Detector.DetectionType detectionType, long j2) {
        int indexOf = this.f3434o.f3483g.indexOf(detectionType);
        if (indexOf == 0) {
            TrackingUtil.j(this, "verify_living_ipt_1st_emotion", "");
        } else if (indexOf == 1) {
            TrackingUtil.j(this, "verify_living_ipt_2nd_emotion", "");
        } else if (indexOf == 2) {
            TrackingUtil.j(this, "verify_living_ipt_3rd_emotion", "");
        }
        this.f3434o.b(detectionType, j2);
        this.f3429j.f3461c.setFaceInfo(null);
        if (v()) {
            return;
        }
        IMediaPlayer iMediaPlayer = this.f3433n;
        iMediaPlayer.b(iMediaPlayer.c(detectionType));
    }

    public void faceInfoChecker(List<FaceQualityManager.FaceQualityErrorType> list) {
        if (list == null || list.size() == 0) {
            r();
            return;
        }
        FaceQualityManager.FaceQualityErrorType faceQualityErrorType = list.get(0);
        String string = faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_NOT_FOUND ? getString(R.string.live_let_see_face) : faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_POS_DEVIATED ? getString(R.string.live_let_see_face) : faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_NONINTEGRITY ? getString(R.string.live_let_see_face) : faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_TOO_DARK ? getString(R.string.live_let_light_bright) : faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_TOO_BRIGHT ? getString(R.string.live_let_light_dark) : faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_TOO_SMALL ? getString(R.string.live_leave_close) : faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_TOO_LARGE ? getString(R.string.live_leave_far) : faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_TOO_BLURRY ? getString(R.string.live_away_from_too_bright_light) : faceQualityErrorType == FaceQualityManager.FaceQualityErrorType.FACE_OUT_OF_RECT ? getString(R.string.live_keep_face_in_frame) : "";
        if (this.A > 10) {
            this.A = 0;
            this.f3429j.f3465g.setText(string);
        }
    }

    public void handleNotPass(final long j2) {
        if (j2 > 0) {
            this.f3432m.post(new Runnable() {
                @Override
                public final void run() {
                    PHLiveRecognitionActivity.this.x(j2);
                }
            });
        }
    }

    protected void init() {
        TrackingUtil.j(this, "verify_living_ipt_front", "");
        this.f3438s = new SensorUtil(this);
        Screen.a(this);
        this.f3432m = new Handler();
        this.f3433n = new IMediaPlayer(this);
        this.f3434o = new IDetection(this, this.f3429j.f3464f);
        this.f3431l = new ICamera();
        this.f3429j.f3470l.setSurfaceTextureListener(this);
        this.f3429j.f3467i.setVisibility(4);
        this.f3429j.f3462d.setVisibility(0);
        this.f3434o.j(this.u);
        this.f3434o.k();
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        u(bundle);
        LayoutYqdLivenessRecognitionBinding c2 = LayoutYqdLivenessRecognitionBinding.c(getLayoutInflater());
        this.f3429j = c2;
        setContentView(c2.getRoot());
        init();
        s();
        MsTrackDataUtils.b(this);
        A();
    }

    protected void onDestroy() {
        super.onDestroy();
        Detector detector = this.f3430k;
        if (detector != null) {
            detector.release();
        }
        this.f3434o.i();
        this.f3438s.c();
        MsTrackDataUtils.c(this);
    }

    public void onDetectionFailed(Detector.DetectionFailedType detectionFailedType) {
        int i2 = R.string.live_detection_failed;
        int i3 = AnonymousClass3.f3441a[detectionFailedType.ordinal()];
        if (i3 == 1) {
            i2 = R.string.liveness_detection_failed_action_blend;
        } else if (i3 == 2) {
            i2 = R.string.liveness_detection_failed_not_video;
        } else if (i3 == 3) {
            i2 = R.string.liveness_detection_failed_timeout;
        }
        this.t.isDetectionFail = true;
        q(i2, false, getString(i2));
    }

    public Detector.DetectionType onDetectionSuccess(DetectionFrame detectionFrame) {
        this.f3433n.e();
        this.B++;
        this.f3429j.f3461c.setFaceInfo(null);
        if (this.B >= this.f3434o.f3483g.size()) {
            this.f3429j.f3467i.setVisibility(0);
            FaceIdCard faceIdCard = this.t;
            if (faceIdCard != null) {
                faceIdCard.isDetectionFail = false;
                FaceIDDataStruct faceIDDataStruct = this.f3430k.getFaceIDDataStruct();
                FaceIdCard faceIdCard2 = this.t;
                faceIdCard2.delta = faceIDDataStruct.delta;
                faceIdCard2.liveImageDatum = faceIDDataStruct.images;
                faceIdCard2.source = RecognitionSource.FACEPP;
                this.f3432m.post(new Runnable() {
                    @Override
                    public final void run() {
                        PHLiveRecognitionActivity.this.y();
                    }
                });
            }
        } else {
            changeType(this.f3434o.f3483g.get(this.B), 10L);
        }
        return this.B >= this.f3434o.f3483g.size() ? Detector.DetectionType.DONE : this.f3434o.f3483g.get(this.B);
    }

    public void onFrameDetected(long j2, DetectionFrame detectionFrame) {
        C(this.f3438s);
        if (!this.f3438s.b() && this.f3438s.f3501d != 0.0f) {
            this.f3429j.f3465g.setText(getString(R.string.live_hold_phone_vertical));
            return;
        }
        p(detectionFrame);
        handleNotPass(j2);
        this.f3429j.f3461c.setFaceInfo(detectionFrame);
    }

    protected void onPause() {
        super.onPause();
        this.f3432m.removeCallbacksAndMessages(null);
        B();
        this.f3431l.c();
        this.f3433n.a();
        this.f3429j.f3470l.setKeepScreenOn(false);
        finish();
    }

    @Override
    public void onPreviewFrame(byte[] bArr, Camera camera) {
        if (this.f3430k == null || camera == null) {
            return;
        }
        Camera.Size previewSize = camera.getParameters().getPreviewSize();
        this.f3430k.doDetection(bArr, previewSize.width, previewSize.height, 360 - this.f3431l.d(this));
    }

    protected void onRestoreInstanceState(@NonNull Bundle bundle) {
        super/*android.app.Activity*/.onRestoreInstanceState(bundle);
        bundle.putInt("actionNumber", this.u);
    }

    protected void onResume() {
        super/*androidx.fragment.app.FragmentActivity*/.onResume();
        this.f3436q = false;
        Camera f2 = this.f3431l.f(this);
        this.f3429j.f3470l.setKeepScreenOn(true);
        if (f2 == null) {
            ToastCompat.e(this, getString(R.string.live_open_front_camera_fail));
            return;
        }
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(1, cameraInfo);
        this.f3429j.f3461c.setFrontal(cameraInfo.facing == 1);
        RelativeLayout.LayoutParams e2 = this.f3431l.e();
        this.f3429j.f3470l.setLayoutParams(e2);
        this.f3429j.f3461c.setLayoutParams(e2);
        this.f3437r = new FaceQualityManager(0.5f, 0.5f);
        this.f3434o.f3482f = -1;
    }

    @Override
    public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surfaceTexture, int i2, int i3) {
        this.C = true;
        o();
        this.f3430k.setDetectionListener(this);
        this.f3431l.a(this);
    }

    @Override
    public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) {
        this.C = false;
        return false;
    }

    protected void s() {
        Detector detector = new Detector(this, new DetectionConfig.Builder().build());
        this.f3430k = detector;
        if (!detector.init(this, AssetsUtil.a(this, "MegLive_model"), "")) {
            ToastCompat.e(this, getString(R.string.live_detector_init_fail));
        }
        this.f3434o.a();
    }

    @Override
    public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surfaceTexture) {
    }

    @Override
    public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surfaceTexture, int i2, int i3) {
    }
}