import { FaceSecCode } from './FaceSecCode'; import { FaceSecToken } from './FaceSecToken'; import { FaceSecID } from './FaceSecID'; import { getInitStatusRaw, getSessionIdRaw, getSessionRaw, initRaw, setOptionsRaw, setInitStatusRaw } from 'libfacedevice.so'; import { FaceSecSession } from './FaceSecSession'; import { FaceSecSessionId } from './FaceSecSessionId'; export class FaceSecDevice { constructor() { this.ctx = null; this.securityInitListener = null; this.statusInitListener = null; this.isInited = false; this.userProductKey = ""; } static getInstance() { return FaceSecDevice.s_instance; } getRegIdByAppKey(e1, f1) { if (f1.size === 0 || !f1.has("Intl")) { let g1 = e1.substring(0, 2); let h1 = e1.substring(10, 12); if ("sh" === g1 && "hs" === h1) { f1.set("Intl", "0"); return f1; } else if ("sg" === g1 && "gs" === h1) { f1.set("Intl", "1"); return f1; } f1.set("Intl", "0"); } return f1; } init(b1, c1, d1) { this.initCommonEx(b1, c1, null, d1); } initWithOptions(x, y, z, a1) { this.initCommonEx(x, y, z, a1); } getSession(s) { let t = getSessionRaw(s); let u = new FaceSecSession(); if (t == null) { u.code = FaceSecCode.SC_UNKNOWN_ERROR; u.session = ""; return u; } if (typeof t === 'object') { try { const w = t; if (typeof w.code === 'number' && typeof w.session === 'string') { u.session = w.session; u.code = w.code; } else { u.code = FaceSecCode.SC_UNKNOWN_ERROR; u.session = ""; } } catch (v) { u.code = FaceSecCode.SC_UNKNOWN_ERROR; u.session = ""; } } else { u.code = FaceSecCode.SC_UNKNOWN_ERROR; u.session = ""; } return u; } getSessionIdObj() { let p = getSessionIdRaw(); let q = new FaceSecSessionId(); if (typeof p === 'object') { let r = JSON.parse(JSON.stringify(p)); q.sessionId = r.sessionId; q.code = r.code; } return q; } getDeviceToken(m) { if (m == null) { m = ""; } let n = this.getSession(m); let o = new FaceSecToken(); o.token = n.session; o.code = n.code; return o; } initCommonEx(h, i, j, k) { if (h == null || i == null || i.length != 32) { if (null != k) { k.onInitFinish(FaceSecCode.SC_PARAMS_ERROR); } return; } this.isInited = getInitStatusRaw(); if (this.isInited) { if (null != k) { k.onInitFinish(FaceSecCode.SC_SUCCESS); } return; } setInitStatusRaw(true); this.ctx = h.getApplicationContext(); this.securityInitListener = k ?? { onInitFinish(l) { } }; if (j == null) { j = new Map(); } j = this.getRegIdByAppKey(i, j); j.set("AppKey", i); FaceSecID.initSystemStatus(this.ctx, j); FaceSecID.initEnvStates(this.ctx); this.setParamsOption(this.ctx, j, 0); this.runInitEx(); } runInitEx() { initRaw(this.ctx, this.securityInitListener); } setParamsOption(c, d, e) { if (c === null || d === null || d.size === 0) { return; } let f = Array.from(d.keys()); let g = Array.from(d.values()); setOptionsRaw(f, g, d.size, e); return; } getSessionId() { let a = getInitStatusRaw(); if (!a) { let b = new FaceSecSessionId(); b.code = FaceSecCode.SC_NOT_INIT; b.sessionId = ""; return b; } return this.getSessionIdObj(); } } FaceSecDevice.INIT_COLLECT_DATA = 0; FaceSecDevice.TOKEN_COLLECT_DATA = 1; FaceSecDevice.s_instance = new FaceSecDevice(); 