package com.kofax.mobile.sdk.g; import com.kofax.kmc.kut.utilities.appstats.AppStatistics; import com.kofax.kmc.kut.utilities.appstats.AppStatsClientEventLogger; import com.kofax.kmc.kut.utilities.appstats.AppStatsEnvSettings; import com.kofax.kmc.kut.utilities.appstats.dao.AppStatsDao; import com.kofax.kmc.kut.utilities.appstats.dao.EnvironmentEventDao; import com.kofax.kmc.kut.utilities.appstats.dao.EventInstanceDao; import com.kofax.kmc.kut.utilities.appstats.type.AppStatsDsOpType; import com.kofax.kmc.kut.utilities.appstats.type.AppStatsEventIDType; import com.kofax.kmc.kut.utilities.appstats.type.AppStatsInstanceType; import com.kofax.kmc.kut.utilities.error.ErrorInfo; import com.kofax.mobile.sdk._internal.k; import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit; /* loaded from: classes3.dex */ public abstract class a { private static final String TAG = "a"; private static EnvironmentEventDao xt; protected static C0062a xu = new C0062a(); protected AppStatistics appStats; protected AppStatistics.FriendAS asFriend; protected String rG; protected AppStatsInstanceType rJ; private boolean xA; private Map xB; private Map xC; private AppStatsEventIDType xD; private String xv; private boolean xw; private boolean xx; private EventInstanceDao xy; private boolean xz; /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: com.kofax.mobile.sdk.g.a$a, reason: collision with other inner class name */ /* loaded from: classes3.dex */ public static class C0062a implements AppStatistics.DataStoreInitializedListener { private AppStatistics appStats; private AppStatistics.FriendAS asFriend; private String xE; public C0062a() { AppStatistics appStatistics = AppStatistics.getInstance(); this.appStats = appStatistics; AppStatistics.FriendAS friendAS = new AppStatistics.FriendAS(appStatistics, "com.kofax.kmc.kut.utilities.appstats"); this.asFriend = friendAS; this.xE = ""; friendAS.addDataStoreInitializedListener(this); } protected boolean S(String str) { return !this.xE.equals(str); } @Override // com.kofax.kmc.kut.utilities.appstats.AppStatistics.DataStoreInitializedListener public void dataStoreInitialized(String str) { this.xE = str; EnvironmentEventDao unused = a.xt = null; } protected String iA() { return this.xE; } } public a() { AppStatistics appStatistics = AppStatistics.getInstance(); this.appStats = appStatistics; this.rG = ""; this.asFriend = new AppStatistics.FriendAS(appStatistics, "com.kofax.kmc.kut.utilities.appstats"); this.xv = ""; this.xw = false; this.xx = true; this.xy = null; this.xz = false; this.xA = false; this.xB = new HashMap(); this.xC = new HashMap(); this.xD = AppStatsEventIDType.APP_STATS_UNKNOWN_EVENT; } public a(AppStatsInstanceType appStatsInstanceType) { AppStatistics appStatistics = AppStatistics.getInstance(); this.appStats = appStatistics; this.rG = ""; this.asFriend = new AppStatistics.FriendAS(appStatistics, "com.kofax.kmc.kut.utilities.appstats"); this.xv = ""; this.xw = false; this.xx = true; this.xy = null; this.xz = false; this.xA = false; this.xB = new HashMap(); this.xC = new HashMap(); this.xD = AppStatsEventIDType.APP_STATS_UNKNOWN_EVENT; this.rJ = appStatsInstanceType; this.rG = iu(); this.xv = xu.iA(); iy(); } public a(String str, AppStatsInstanceType appStatsInstanceType, boolean z) { AppStatistics appStatistics = AppStatistics.getInstance(); this.appStats = appStatistics; this.rG = ""; this.asFriend = new AppStatistics.FriendAS(appStatistics, "com.kofax.kmc.kut.utilities.appstats"); this.xv = ""; this.xw = false; this.xx = true; this.xy = null; this.xz = false; this.xA = false; this.xB = new HashMap(); this.xC = new HashMap(); this.xD = AppStatsEventIDType.APP_STATS_UNKNOWN_EVENT; this.asFriend = new AppStatistics.FriendAS(this.appStats, "com.kofax.kmc.kut.utilities.appstats"); this.rG = str; this.xx = false; this.xv = xu.iA(); this.rJ = appStatsInstanceType; this.xw = z; if (z) { iy(); } else { this.xz = true; this.xA = true; } } public static String iu() { return UUID.randomUUID().toString(); } public void iv() { if (this.xz) { ix(); } this.xz = false; this.rG = iu(); iy(); } public void iw() { this.xA = false; ix(); } public void ix() { synchronized (this) { if (this.xy != null && !this.xA && this.appStats.isRecording()) { EventInstanceDao mo279clone = this.xy.mo279clone(); this.xy = mo279clone; mo279clone.setDismissalTime(this.asFriend.currentEventTime()); this.xy.setDsOperation(AppStatsDsOpType.APP_STATS_DS_UPDATE); this.asFriend.logAppStats(new AppStatsDao[]{this.xy}); this.xA = true; this.xz = false; this.xy = null; } } } protected void finalize() throws Throwable { try { ix(); } catch (Throwable th) { try { throw th; } finally { super.finalize(); } } } protected void iy() { synchronized (this) { if (!this.xz && this.appStats.isRecording()) { iz(); EventInstanceDao eventInstanceDao = new EventInstanceDao(); this.xy = eventInstanceDao; eventInstanceDao.setInstanceId(this.rG); this.xy.setEnvironmentId(xt.getId()); this.xy.setCreationTime(this.asFriend.currentEventTime()); this.xy.setInstanceType(this.rJ); EventInstanceDao eventInstanceDao2 = this.xy; eventInstanceDao2.setSessionKey(eventInstanceDao2.getAppStatsSessionKey()); this.xy.setDsOperation(AppStatsDsOpType.APP_STATS_DS_INSERT); this.asFriend.logAppStats(new AppStatsDao[]{this.xy}); this.xz = true; this.xA = false; } } } /* JADX INFO: Access modifiers changed from: protected */ public ErrorInfo a(AppStatsDao[] appStatsDaoArr) { a aVar = this; if (xu.S(aVar.xv)) { if (aVar.xx) { aVar.xz = false; aVar.xy = null; aVar.rG = iu(); for (AppStatsDao appStatsDao : appStatsDaoArr) { if (appStatsDao.getInstanceId() != null) { appStatsDao.setInstanceId(aVar.rG); } } } aVar.xv = xu.iA(); } for (AppStatsDao appStatsDao2 : appStatsDaoArr) { if (appStatsDao2.getInstanceId() != null) { iy(); } else if (appStatsDao2.getEnvironmentId() != null) { iz(); appStatsDao2.setEnvironmentId(xt.getId()); } } AppStatsEventIDType it = it(); if (aVar.xB.containsKey(it)) { long convert = TimeUnit.NANOSECONDS.convert(aVar.xB.get(it).intValue(), TimeUnit.MILLISECONDS); long nanoTime = System.nanoTime(); long convert2 = TimeUnit.MILLISECONDS.convert(convert, TimeUnit.NANOSECONDS); long convert3 = TimeUnit.MILLISECONDS.convert(nanoTime, TimeUnit.NANOSECONDS); Long l = aVar.xC.get(it); if (l != null) { long convert4 = TimeUnit.MILLISECONDS.convert(l.longValue(), TimeUnit.NANOSECONDS); long convert5 = TimeUnit.MILLISECONDS.convert(nanoTime - l.longValue(), TimeUnit.NANOSECONDS); if (nanoTime - l.longValue() < convert) { String str = TAG; StringBuilder sb = new StringBuilder(); sb.append(it); sb.append(" not logged... eventThrottleMs("); sb.append(convert2); sb.append(") not elpased. ("); sb.append(convert5); sb.append(")."); k.b(str, sb.toString()); return ErrorInfo.KMC_UT_STATS_EVENT_THROTTLED; } String str2 = TAG; StringBuilder sb2 = new StringBuilder(); sb2.append(it); sb2.append(" logged... eventThrottleMs("); sb2.append(convert2); sb2.append(") currentTimeMs="); sb2.append(convert3); sb2.append(", eventLastTimeMs="); sb2.append(convert4); sb2.append(" elpased="); sb2.append(convert5); k.b(str2, sb2.toString()); } aVar = this; aVar.xC.put(it, Long.valueOf(nanoTime)); } aVar.asFriend.logAppStats(appStatsDaoArr); return ErrorInfo.KMC_SUCCESS; } /* JADX INFO: Access modifiers changed from: protected */ public void a(AppStatsEventIDType appStatsEventIDType, int i) { this.xB.put(appStatsEventIDType, Integer.valueOf(i)); } /* JADX INFO: Access modifiers changed from: protected */ public void a(AppStatsEventIDType appStatsEventIDType, AppStatsClientEventLogger appStatsClientEventLogger) { if (this.appStats.isRecording()) { appStatsClientEventLogger.logEvent(appStatsEventIDType); } } private void iz() { synchronized (this) { if (this.appStats.isRecording()) { AppStatsEnvSettings appStatsEnvSettings = new AppStatsEnvSettings(true); String deviceId = this.appStats.getDeviceId(); if (!deviceId.isEmpty()) { appStatsEnvSettings.setEnvDeviceID(deviceId); } if (xt != null && appStatsEnvSettings.getEnvDeviceID(false).isEmpty()) { appStatsEnvSettings.setEnvDeviceID(xt.getDeviceID()); } EnvironmentEventDao environmentEventDao = xt; if (environmentEventDao == null || !appStatsEnvSettings.equals(new AppStatsEnvSettings(environmentEventDao))) { if (appStatsEnvSettings.getEnvDeviceID(false).isEmpty()) { appStatsEnvSettings.getEnvDeviceID(true); } EnvironmentEventDao environmentEventDao2 = new EnvironmentEventDao(appStatsEnvSettings, this.asFriend.currentEventTime()); xt = environmentEventDao2; this.asFriend.logAppStats(new AppStatsDao[]{environmentEventDao2}); } } } } protected AppStatsEventIDType it() { return this.xD; } public String getInstanceId() { return this.rG; } /* JADX INFO: Access modifiers changed from: protected */ public void a(AppStatsEventIDType appStatsEventIDType) { this.xD = appStatsEventIDType; } public void R(String str) { this.rG = str; } }