package com.kofax.kmc.kut.utilities.appstats; import android.database.sqlite.SQLiteConstraintException; import android.os.Handler; import android.os.Looper; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.kofax.BuildConfig; import com.kofax.kmc.kut.utilities.appstats.AppStatsWriteFileListener; import com.kofax.kmc.kut.utilities.appstats.dao.AppStatsDao; import com.kofax.kmc.kut.utilities.appstats.type.AppStatsEventIDType; import com.kofax.kmc.kut.utilities.async.ListenerCallbackThreadType; import com.kofax.kmc.kut.utilities.async.TaskRunner; import com.kofax.kmc.kut.utilities.error.ErrorInfo; import com.kofax.kmc.kut.utilities.error.KmcRuntimeException; import com.kofax.kmc.kut.utilities.error.NullPointerException; import com.kofax.mobile.sdk._internal.k; import com.kofax.mobile.sdk.g.j; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.EventObject; import java.util.Iterator; import java.util.List; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.CopyOnWriteArrayList; import o.gjJ; /* loaded from: classes3.dex */ public class AppStatistics { private static final String TAG = "AppStatistics"; private ListenerCallbackThreadType aU; private TaskRunner aZ; protected List appStatsDaoCurrent; private String category; private j nX; private int nY; private int nZ; private String oA; private long oa; private String ob; private long oc; private boolean od; private List oe; private List of; private String og; private String oh; AppStatsDataStore oi; private ArrayList oj; private ArrayList ok; private ArrayList ol; private ArrayList om; private CopyOnWriteArrayList on; private ArrayList oo; private int op; private float oq; private long or; private AppStatsDsExportHandler os; private AppStatsDsExportHandler ot; private AppStatsExportFormat ou; private String ov; private AppStatsState ow; private AppStatsState ox; private AppStatsState oy; private FriendAS oz; /* loaded from: classes3.dex */ public enum AppStatsExportFormat { EXP_FORMAT_SQL_SERVER, EXP_FORMAT_JSON, EXP_FORMAT_APP_DEFINED } /* loaded from: classes3.dex */ public interface DataStoreInitializedListener { void dataStoreInitialized(String str); } /* JADX INFO: Access modifiers changed from: protected */ /* loaded from: classes3.dex */ public interface DataStoreStatusCallback { void dataStoreExportComplete(ErrorInfo errorInfo); } /* loaded from: classes3.dex */ public enum ExportStatusEvent { EXPORTING, COMPLETE, FAILED } /* loaded from: classes3.dex */ public enum ThresholdType { THRESH_TYPE_RAM, THRESH_TYPE_FILE } /* loaded from: classes3.dex */ static class a { public static final AppStatistics oE = new AppStatistics(); private a() { } } private AppStatistics() { this.nX = null; this.nY = 0; this.nZ = 0; this.oa = 0L; this.ob = ""; this.oc = 0L; this.od = false; this.aU = ListenerCallbackThreadType.UI_THREAD; this.oe = new ArrayList(); this.of = new ArrayList(); this.appStatsDaoCurrent = this.oe; this.og = UUID.randomUUID().toString(); this.oh = null; this.oi = null; this.oj = new ArrayList<>(); this.ok = new ArrayList<>(); this.ol = this.oj; this.om = new ArrayList<>(); this.on = new CopyOnWriteArrayList<>(); this.oo = new ArrayList<>(); this.aZ = null; this.op = 0; this.oq = BitmapDescriptorFactory.HUE_RED; this.or = 0L; this.os = null; this.ot = null; this.ou = null; this.ov = ""; AppStatsState appStatsState = AppStatsState.APP_STATS_UNINITIALIZED; this.ow = appStatsState; this.ox = appStatsState; this.oy = AppStatsState.APP_STATS_UNINITIALIZED; this.oz = new FriendAS(this, getClass().getName()); this.oA = null; this.category = null; } public static AppStatistics getInstance() { return a.oE; } public void setRamSizeThreshold(int i) { if (i < 0) { throw new IllegalArgumentException("ramSizeThreshold cannot be a negative value."); } this.nY = i; } public void setFileSizeThreshold(int i) { if (i < 0) { throw new IllegalArgumentException("fileSizeThreshold cannot be a negative value."); } this.nZ = i; } public long getFileSize() throws FileNotFoundException { AppStatsDataStore appStatsDataStore = this.oi; if (appStatsDataStore == null) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_UNINITIALIZED); } long calcDsSize = appStatsDataStore.calcDsSize(); this.oc = calcDsSize; return calcDsSize; } public final void initAppStats(String str) { synchronized (this) { if (gjJ.b((CharSequence) this.oh) && this.oh == null) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_DEVICE_ID_MISSING); } a("initAppStats()", true); ErrorInfo a2 = AppStatsState.APP_STATS_INITIALIZING.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_INIT_APPSTATS, this.ow.qf); if (a2 != ErrorInfo.KMC_SUCCESS) { throw new KmcRuntimeException(a2); } if (gjJ.b((CharSequence) str) || str == null) { throw new NullPointerException("Database path is empty"); } if (this.ow == AppStatsState.APP_STATS_INITIALIZED && this.oi.isOpen()) { this.oi.close(); } this.ob = str; if (this.oi == null) { this.oi = AppStatsSqLiteDs.getInstance(); } this.oy = this.ow; this.ow = AppStatsState.APP_STATS_INITIALIZING; try { this.oi.open(this.ob); s(this.oi.getDsUniqueId()); this.ox = this.ow; this.ow = AppStatsState.APP_STATS_INITIALIZING.b(com.kofax.kmc.kut.utilities.appstats.b.TASK_INIT_APPSTATS, this.oy.qf); this.oy = this.ox; try { this.oa = 0L; this.or = getFileSize(); this.oq = (float) getRamSize(); this.oe.clear(); this.of.clear(); } catch (Exception unused) { } a("initAppStats()", false); } catch (RuntimeException e) { AppStatsState appStatsState = this.ow; this.ox = appStatsState; this.ow = appStatsState.c(com.kofax.kmc.kut.utilities.appstats.b.TASK_INIT_APPSTATS, this.oy.qf); this.oy = this.ox; throw e; } } } public ErrorInfo startRecord() { AppStatsState appStatsState; synchronized (this) { ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS; a("startRecord()", true); if (this.ow == AppStatsState.APP_STATS_WRITING) { appStatsState = AppStatsState.APP_STATS_RECORDING_WRITING; } else { appStatsState = AppStatsState.APP_STATS_RECORDING; } ErrorInfo a2 = appStatsState.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_START_RECORD, this.ow.qf); if (a2 == ErrorInfo.KMC_UT_STATS_ALREADY_RECORDING) { a("startRecord() - already recording...", false); return a2; } if (a2 != ErrorInfo.KMC_SUCCESS) { throw new KmcRuntimeException(a2); } this.oy = this.ow; this.ow = appStatsState; if (this.ob == null) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_FILEPATH_IS_NULL); } this.oi.open(); this.od = true; a("startRecord()", false); return a2; } } public ErrorInfo stopRecord() { AppStatsState appStatsState; ErrorInfo a2; synchronized (this) { ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS; a("stopRecord()", true); if (this.ow == AppStatsState.APP_STATS_RECORDING_WRITING) { appStatsState = AppStatsState.APP_STATS_WRITING; } else if (this.ow == AppStatsState.APP_STATS_RECORDING) { appStatsState = AppStatsState.APP_STATS_INITIALIZED; } else { throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_INVALID_STATE_TRANSITION); } a2 = appStatsState.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_STOP_RECORD, this.ow.qf); if (a2 != ErrorInfo.KMC_SUCCESS) { throw new KmcRuntimeException(a2); } this.oy = this.ow; this.ow = appStatsState; if (this.od) { this.op = this.oe.size(); this.od = false; } a("stopRecord()", false); } return a2; } public ErrorInfo writeToFile() { AppStatsState appStatsState; synchronized (this) { ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS; a("writeToFile()", true); if (this.ow == AppStatsState.APP_STATS_RECORDING) { appStatsState = AppStatsState.APP_STATS_RECORDING_WRITING; } else { appStatsState = AppStatsState.APP_STATS_WRITING; } ErrorInfo a2 = appStatsState.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_WRITE, this.ow.qf); if (a2 == ErrorInfo.KMC_UT_STATS_ALREADY_WRITING) { a("writeToFile() - already writing...", false); return a2; } if (a2 != ErrorInfo.KMC_SUCCESS) { throw new KmcRuntimeException(a2); } this.oy = this.ow; this.ow = appStatsState; if (!this.od) { this.oi.open(); } TaskRunner m = m(); c cVar = new c(); this.aZ.addOnTaskCompletedListener(new b(), cVar, false); m.submit(cVar); a("writeToFile()", false); return a2; } } public ErrorInfo export(String str, AppStatsExportFormat appStatsExportFormat) { ErrorInfo a2; AppStatsDsExportHandler appStatsMsSqlExportHandler; synchronized (this) { a("export()", true); a2 = AppStatsState.APP_STATS_EXPORTING.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_EXPORT, this.ow.qf); if (a2 != ErrorInfo.KMC_SUCCESS) { throw new KmcRuntimeException(a2); } if (str == null || gjJ.b((CharSequence) str)) { throw new IllegalArgumentException("Export file path is empty or null"); } this.ou = appStatsExportFormat; this.ov = str; if (this.ot == null && appStatsExportFormat == AppStatsExportFormat.EXP_FORMAT_APP_DEFINED) { ErrorInfo errorInfo = ErrorInfo.KMC_UT_STATS_EXPORT_HANDLER_MISSING; throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_EXPORT_HANDLER_MISSING); } this.oi.open(); int i = AnonymousClass2.oD[appStatsExportFormat.ordinal()]; if (i == 1) { appStatsMsSqlExportHandler = new AppStatsMsSqlExportHandler(); } else if (i == 2) { appStatsMsSqlExportHandler = new AppStatsNewJsonExportHandler(); } else { if (i != 3) { throw new UnsupportedOperationException("export: the export format parameter specified is unsupported."); } appStatsMsSqlExportHandler = this.ot; } this.os = appStatsMsSqlExportHandler; aL(); a("export()", false); } return a2; } /* renamed from: com.kofax.kmc.kut.utilities.appstats.AppStatistics$2, reason: invalid class name */ /* loaded from: classes3.dex */ static /* synthetic */ class AnonymousClass2 { static final int[] oD; static { int[] iArr = new int[AppStatsExportFormat.values().length]; oD = iArr; try { iArr[AppStatsExportFormat.EXP_FORMAT_SQL_SERVER.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { oD[AppStatsExportFormat.EXP_FORMAT_JSON.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } try { oD[AppStatsExportFormat.EXP_FORMAT_APP_DEFINED.ordinal()] = 3; } catch (NoSuchFieldError unused3) { } } } public ErrorInfo purge() { synchronized (this) { a("purge()", true); if (this.ow == AppStatsState.APP_STATS_RECORDING) { return ErrorInfo.KMC_UT_STATS_RECORDING_NOT_OFF; } ErrorInfo a2 = AppStatsState.APP_STATS_PURGING.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_PURGE, this.ow.qf); if (a2 != ErrorInfo.KMC_SUCCESS) { return a2; } this.oy = this.ow; this.ow = AppStatsState.APP_STATS_PURGING; if (!this.od) { this.oi.close(); this.oi.remove(); this.oe.clear(); this.of.clear(); this.appStatsDaoCurrent = this.oe; this.ob = ""; this.ox = this.ow; this.ow = AppStatsState.APP_STATS_PURGING.b(com.kofax.kmc.kut.utilities.appstats.b.TASK_PURGE, this.oy.qf); this.oy = this.ox; a("purge()", false); return a2; } return ErrorInfo.KMC_UT_STATS_RECORDING_NOT_OFF; } } public void beginSession(String str, String str2) { synchronized (this) { a("beginSession()", true); a(str, "sessionKey"); a(str2, "category"); ErrorInfo a2 = AppStatsState.APP_STATS_BEGINNING_SESSION.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_BEGIN_SESSION, this.ow.qf); if (a2 != ErrorInfo.KMC_SUCCESS) { throw new KmcRuntimeException(a2); } if (this.oA != null) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_SESSION_ALREADY_BEGUN); } this.oy = this.ow; this.ow = AppStatsState.APP_STATS_BEGINNING_SESSION; if (this.nX == null) { this.nX = new j(); } this.nX.a(AppStatsEventIDType.APP_STATS_BEGIN_SESSION_EVENT, str, str2); this.ox = this.ow; this.ow = AppStatsState.APP_STATS_BEGINNING_SESSION.b(com.kofax.kmc.kut.utilities.appstats.b.TASK_BEGIN_SESSION, this.oy.qf); this.oy = this.ox; this.oA = str; this.category = str2; } } public void logSessionEvent(AppStatsSessionEvent appStatsSessionEvent) { synchronized (this) { a("logSessionEvent()", true); if (appStatsSessionEvent == null) { throw new NullPointerException("logSessionEvent: sessionEvent param cannot be null"); } ErrorInfo a2 = AppStatsState.APP_STATS_LOGGING_SESSION.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_LOG_SESSION, this.ow.qf); if (a2 != ErrorInfo.KMC_SUCCESS) { throw new KmcRuntimeException(a2); } if (!isRecording()) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_RECORDING_NOT_ON); } if (this.oA == null) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_NO_SESSION_BEGUN); } this.oy = this.ow; this.ow = AppStatsState.APP_STATS_LOGGING_SESSION; if (this.nX == null) { this.nX = new j(); } this.nX.a(AppStatsEventIDType.APP_STATS_LOG_SESSION_EVENT, appStatsSessionEvent); this.ox = this.ow; this.ow = AppStatsState.APP_STATS_LOGGING_SESSION.b(com.kofax.kmc.kut.utilities.appstats.b.TASK_LOG_SESSION, this.oy.qf); this.oy = this.ox; } } public void endSession(boolean z, String str) { synchronized (this) { a("endSession()", true); a(str, "description"); ErrorInfo a2 = AppStatsState.APP_STATS_ENDING_SESSION.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_END_SESSION, this.ow.qf); if (a2 != ErrorInfo.KMC_SUCCESS) { throw new KmcRuntimeException(a2); } if (this.oA == null) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_STATS_NO_SESSION_BEGUN); } this.oy = this.ow; this.ow = AppStatsState.APP_STATS_ENDING_SESSION; if (this.nX == null) { this.nX = new j(); } this.nX.a(AppStatsEventIDType.APP_STATS_END_SESSION_EVENT, z, str); this.ox = this.ow; this.ow = AppStatsState.APP_STATS_ENDING_SESSION.b(com.kofax.kmc.kut.utilities.appstats.b.TASK_END_SESSION, this.oy.qf); this.oy = this.ox; this.oA = null; this.category = null; } } public void addAppStatsWriteFileListener(AppStatsWriteFileListener appStatsWriteFileListener) { if (appStatsWriteFileListener == null) { throw new NullPointerException("addAppStatsWriteFileListener: listener parameter is null"); } if (this.oj.contains(appStatsWriteFileListener)) { return; } this.oj.add(appStatsWriteFileListener); } public void addAppStatsExportListener(AppStatsExportListener appStatsExportListener) { if (appStatsExportListener == null) { throw new NullPointerException("addAppStatsExportListener: listener parameter is null"); } if (this.on.contains(appStatsExportListener)) { return; } this.on.add(appStatsExportListener); } public void addAppThresholdListener(AppstatsThresholdReachedListener appstatsThresholdReachedListener) { if (appstatsThresholdReachedListener == null) { throw new NullPointerException("addAppThresholdListener: listener parameter is null"); } if (this.om.contains(appstatsThresholdReachedListener)) { return; } this.om.add(appstatsThresholdReachedListener); } public void removeAppStatsExportListener(AppStatsExportListener appStatsExportListener) { this.on.remove(appStatsExportListener); } public void removeAppStatsThresholdListener(AppstatsThresholdReachedListener appstatsThresholdReachedListener) { this.om.remove(appstatsThresholdReachedListener); } public void removeAppStatsWriteFileListener(AppStatsWriteFileListener appStatsWriteFileListener) { this.oj.remove(appStatsWriteFileListener); } /* loaded from: classes3.dex */ public class FriendAS implements DataStoreStatusCallback, AppStatsWriteFileListener, AppStatsDao.AppStatsDaoCalcObjSize { final AppStatistics oC; public FriendAS(AppStatistics appStatistics, String str) { this.oC = appStatistics; if (!gjJ.c((CharSequence) str, (CharSequence) BuildConfig.APPLICATION_ID)) { throw new KmcRuntimeException(ErrorInfo.KMC_GN_UNSUPPORTED_OPERATION); } AppStatsDao.addAppStatsDaoCalcObjSizeListener(this); } public AppStatsDataStore getAppStatsDataStore() { return this.oC.oi; } public String getSessionKey() { return this.oC.oA; } public String getLastSessionEventID() { return this.oC.nX == null ? "" : this.oC.nX.getLastSessionEventID(); } public String getCategory() { return this.oC.category; } public long currentEventTime() { return System.currentTimeMillis(); } public void logAppStats(AppStatsDao[] appStatsDaoArr) { if (appStatsDaoArr == null) { throw new NullPointerException("'appStatsDao' parameter is null"); } synchronized (this.oC) { for (AppStatsDao appStatsDao : appStatsDaoArr) { this.oC.appStatsDaoCurrent.add(appStatsDao); if (appStatsDao.calcObjSize(false, this.oC.og) != null) { this.oC.oa += r4.intValue(); } } } this.oC.a(ThresholdType.THRESH_TYPE_RAM); } public void fireExportStatusEvent(AppStatsExportEvent appStatsExportEvent) { this.oC.a(appStatsExportEvent); } @Override // com.kofax.kmc.kut.utilities.appstats.AppStatistics.DataStoreStatusCallback public void dataStoreExportComplete(ErrorInfo errorInfo) { synchronized (this.oC) { this.oC.a("DataStoreExportComplete()", true); AppStatistics appStatistics = this.oC; appStatistics.ox = appStatistics.ow; if (errorInfo == ErrorInfo.KMC_SUCCESS) { AppStatistics appStatistics2 = this.oC; appStatistics2.ow = appStatistics2.ow.b(com.kofax.kmc.kut.utilities.appstats.b.TASK_EXPORT, this.oC.oy.qf); } else { AppStatistics appStatistics3 = this.oC; appStatistics3.ow = appStatistics3.ow.c(com.kofax.kmc.kut.utilities.appstats.b.TASK_EXPORT, this.oC.oy.qf); } AppStatistics appStatistics4 = this.oC; appStatistics4.oy = appStatistics4.ox; this.oC.a("DataStoreExportComplete()", false); } } @Override // com.kofax.kmc.kut.utilities.appstats.AppStatsWriteFileListener public void writeFileStatusEvent(AppStatsWritetoFileEvent appStatsWritetoFileEvent) { if (appStatsWritetoFileEvent.getWritetoFileStatus() != AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_WRITING) { synchronized (this.oC) { AppStatistics appStatistics = this.oC; appStatistics.ol = appStatistics.oj; } } if (appStatsWritetoFileEvent.getWritetoFileStatus() == AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_COMPLETE) { ErrorInfo a = AppStatsState.APP_STATS_EXPORTING.a(com.kofax.kmc.kut.utilities.appstats.b.TASK_EXPORT, this.oC.ow.qf); if (a == ErrorInfo.KMC_SUCCESS) { AppStatistics appStatistics2 = this.oC; appStatistics2.oy = appStatistics2.ow; this.oC.ow = AppStatsState.APP_STATS_EXPORTING; this.oC.oi.export(this.oC.ov, this.oC.os, this.oC.oz); return; } throw new KmcRuntimeException(a); } } @Override // com.kofax.kmc.kut.utilities.appstats.dao.AppStatsDao.AppStatsDaoCalcObjSize public void daoCalcObjSizeResult(int i, String str) { synchronized (this.oC) { if (this.oC.og.equals(str)) { this.oC.oa += i; } } this.oC.a(ThresholdType.THRESH_TYPE_RAM); } public void addDataStoreInitializedListener(DataStoreInitializedListener dataStoreInitializedListener) { if (dataStoreInitializedListener != null) { if (this.oC.oo.contains(dataStoreInitializedListener)) { return; } this.oC.oo.add(dataStoreInitializedListener); return; } throw new NullPointerException("addDataStoreInitializedListener: listener parameter is null"); } public void removeDataStoreInitializedListener(DataStoreInitializedListener dataStoreInitializedListener) { this.oC.oo.remove(dataStoreInitializedListener); } public void addAppStatsExportListener(AppStatsExportListener appStatsExportListener, int i) { if (appStatsExportListener != null) { if (this.oC.on.contains(appStatsExportListener)) { return; } this.oC.on.add(i, appStatsExportListener); return; } throw new NullPointerException("addAppStatsExportListener: listener parameter is null"); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public class b implements TaskRunner.TaskCompletedListener { final AppStatistics oC; private b(AppStatistics appStatistics) { this.oC = appStatistics; } @Override // com.kofax.kmc.kut.utilities.async.TaskRunner.TaskCompletedListener public void onTaskCompleted(TaskRunner.TaskCompletedEvent taskCompletedEvent) { taskCompletedEvent.getTaskError(); ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public class c implements Callable { final AppStatistics oC; private int oH; private c(AppStatistics appStatistics) { this.oC = appStatistics; } @Override // java.util.concurrent.Callable /* renamed from: aN, reason: merged with bridge method [inline-methods] */ public AppStatsWriteToFileResults call() throws Exception { ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS; this.oC.a("MyWriteToFileTask()", true); AppStatsWriteToFileResults appStatsWriteToFileResults = new AppStatsWriteToFileResults(errorInfo, AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_WRITING); List aK = this.oC.aK(); if (aK.size() == 0) { appStatsWriteToFileResults.setState(AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_COMPLETE); this.oC.a(appStatsWriteToFileResults.getState(), 100.0f, errorInfo); } else { appStatsWriteToFileResults = a(aK); } this.oC.a("MyWriteToFileTask()", false); return appStatsWriteToFileResults; } private AppStatsWriteToFileResults a(List list) { AppStatsWriteToFileResults appStatsWriteToFileResults; synchronized (this) { ErrorInfo errorInfo = ErrorInfo.KMC_SUCCESS; appStatsWriteToFileResults = new AppStatsWriteToFileResults(errorInfo, AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_WRITING); list.size(); this.oC.op = list.size(); Iterator it = list.iterator(); while (it.hasNext()) { try { String str = AppStatistics.TAG; StringBuilder sb = new StringBuilder(); sb.append(" i = 0 size = "); sb.append(list.size()); k.c(str, sb.toString()); it.next().writeToDb(); } catch (SQLiteConstraintException e) { k.d(AppStatistics.TAG, e.getMessage()); } k.c(AppStatistics.TAG, "WriteToDB"); it.remove(); try { int size = this.oC.op - list.size(); this.oH = size; int i = (size * 100) / this.oC.op; appStatsWriteToFileResults.setState(i >= 100 ? AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_COMPLETE : AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_WRITING); this.oC.a(appStatsWriteToFileResults.getState(), i, errorInfo); this.oC.a(ThresholdType.THRESH_TYPE_FILE); this.oC.a(ThresholdType.THRESH_TYPE_RAM); } catch (Exception e2) { appStatsWriteToFileResults.setState(AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_FAILED); k.d(AppStatistics.TAG, e2.getMessage()); } } } return appStatsWriteToFileResults; } } private void a(Object obj, String str) { if (obj == null) { StringBuilder sb = new StringBuilder(); sb.append(str); sb.append(" parameter is null"); throw new NullPointerException(sb.toString()); } if (!obj.getClass().getSimpleName().equals("Integer") || ((Integer) obj).intValue() >= 0) { return; } ErrorInfo errorInfo = ErrorInfo.KMC_GN_PARAM_NEGATIVE; StringBuilder sb2 = new StringBuilder("'"); sb2.append(str); sb2.append("' parameter is negative"); errorInfo.setErrCause(sb2.toString()); throw new KmcRuntimeException(errorInfo); } private TaskRunner m() { if (this.aZ == null) { this.aZ = new TaskRunner(1); } return this.aZ; } /* JADX INFO: Access modifiers changed from: private */ public void a(AppStatsWriteFileListener.WriteFileStatus writeFileStatus, float f, ErrorInfo errorInfo) { synchronized (this) { if (writeFileStatus == AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_COMPLETE) { a("handleWritetoFile()", true); AppStatsState appStatsState = this.ow; this.ox = appStatsState; this.ow = appStatsState.b(com.kofax.kmc.kut.utilities.appstats.b.TASK_WRITE, this.ow.qf); this.oy = this.ox; a("handleWritetoFile()", false); } else if (writeFileStatus == AppStatsWriteFileListener.WriteFileStatus.WRITE_STATUS_FAILED) { this.ow = this.ow.c(com.kofax.kmc.kut.utilities.appstats.b.TASK_WRITE, this.ow.qf); } } a((EventObject) new AppStatsWritetoFileEvent(this, writeFileStatus, f, errorInfo)); } /* JADX INFO: Access modifiers changed from: private */ public void a(ThresholdType thresholdType) { long fileSize; if (thresholdType == ThresholdType.THRESH_TYPE_RAM) { int i = this.nY; if (i == 0) { return; } fileSize = this.oa; float f = (float) fileSize; if (f - this.oq < i) { return; } else { this.oq = f; } } else if (thresholdType == ThresholdType.THRESH_TYPE_FILE) { try { if (this.nZ == 0 || getFileSize() - this.or < this.nZ) { return; } this.or = getFileSize(); fileSize = getFileSize(); } catch (FileNotFoundException e) { throw new KmcRuntimeException(ErrorInfo.KMC_GN_FILE_NOT_FOUND, e); } } else { throw new UnsupportedOperationException("handleThreshold: ThresholdType parameter specified is unsupported."); } a((EventObject) new AppStatsThresholdReachedEvent(this, thresholdType, fileSize)); } /* JADX INFO: Access modifiers changed from: private */ public List aK() { List list; synchronized (this) { list = this.appStatsDaoCurrent; this.appStatsDaoCurrent = list.hashCode() == this.oe.hashCode() ? this.of : this.oe; this.og = UUID.randomUUID().toString(); this.oa = 0L; this.oq = (float) getRamSize(); } return list; } private void aL() { if (this.ok.isEmpty()) { this.ok.add(this.oz); } this.ol = this.ok; writeToFile(); } /* JADX INFO: Access modifiers changed from: private */ public void a(String str, boolean z) { if (z) { StringBuilder sb = new StringBuilder(); sb.append(str); sb.append(" enter; appStatsState="); sb.append(this.ow); sb.append(", previousAppStatsState="); sb.append(this.oy); k.b("AppStatsState", sb.toString()); return; } StringBuilder sb2 = new StringBuilder(); sb2.append(str); sb2.append(" exit; appStatsState="); sb2.append(this.ow); sb2.append(", previousAppStatsState="); sb2.append(this.oy); k.b("AppStatsState", sb2.toString()); } /* JADX INFO: Access modifiers changed from: private */ public void a(EventObject eventObject) { if (this.aU == ListenerCallbackThreadType.WORKER_THREAD) { b(eventObject); } else { new Handler(Looper.getMainLooper()).post(new Runnable(this, eventObject) { // from class: com.kofax.kmc.kut.utilities.appstats.AppStatistics.1 final EventObject oB; final AppStatistics oC; { this.oC = this; this.oB = eventObject; } @Override // java.lang.Runnable public void run() { this.oC.b(this.oB); } }); } } /* JADX INFO: Access modifiers changed from: private */ public void b(EventObject eventObject) { if (eventObject instanceof AppStatsThresholdReachedEvent) { a((AppStatsThresholdReachedEvent) eventObject); } else if (eventObject instanceof AppStatsWritetoFileEvent) { a((AppStatsWritetoFileEvent) eventObject); } else { if (eventObject instanceof AppStatsExportEvent) { fireExportStatusEvent((AppStatsExportEvent) eventObject); return; } throw new IllegalThreadStateException("fireAppStatsEvent: unsupported EventObject instance."); } } private void a(AppStatsThresholdReachedEvent appStatsThresholdReachedEvent) { synchronized (this) { Iterator it = this.om.iterator(); while (it.hasNext()) { it.next().thresholdReached(appStatsThresholdReachedEvent); } } } private void a(AppStatsWritetoFileEvent appStatsWritetoFileEvent) { synchronized (this) { Iterator it = this.ol.iterator(); while (it.hasNext()) { it.next().writeFileStatusEvent(appStatsWritetoFileEvent); } } } private void fireExportStatusEvent(AppStatsExportEvent appStatsExportEvent) { synchronized (this) { Iterator it = this.on.iterator(); while (it.hasNext()) { it.next().exportStatusEvent(appStatsExportEvent); } } } private void s(String str) { synchronized (this) { Iterator it = this.oo.iterator(); while (it.hasNext()) { it.next().dataStoreInitialized(str); } } } public void setListenerCallbackThreadType(ListenerCallbackThreadType listenerCallbackThreadType) { this.aU = listenerCallbackThreadType; } public void setDeviceId(String str) { this.oh = str; } public void registerExportHandler(AppStatsDsExportHandler appStatsDsExportHandler) { this.ot = appStatsDsExportHandler; } public boolean isRecording() { return this.od; } public int getRamSizeThreshold() { return this.nY; } public long getRamSize() { return this.oa; } public ListenerCallbackThreadType getListenerCallbackThreadType() { return this.aU; } public int getFileSizeThreshold() { return this.nZ; } public String getFileName() { return this.ob; } public String getDeviceId() { return this.oh; } }