package com.singular.sdk.internal; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import com.applovin.sdk.AppLovinEventTypes; import com.glu.plugins.gluanalytics.AnalyticsData; import com.ironsource.mediationsdk.impressionData.ImpressionData; import com.ironsource.nb; import com.ironsource.v8; import com.mbridge.msdk.foundation.download.core.DownloadCommon; import com.mbridge.msdk.foundation.entity.CampaignEx; import com.mbridge.msdk.foundation.same.report.i; import com.mbridge.msdk.playercommon.exoplayer2.text.ttml.TtmlNode; import csdk.gluads.Consts; import java.io.File; import java.io.IOException; import java.util.HashMap; import org.json.JSONObject; /* loaded from: classes4.dex */ public class OfflineEventsMigrator { public static final SingularLog logger = SingularLog.getLogger("OfflineEventsMigrator"); public String aifa; public String andi; public String apiKey; public String apid; public String bmac; public String canonicalDeviceId; public String canonicalKeyspace; public Context ctx; public SQLiteDatabase database; public String databaseName; public String imei; public String mac1; public OfflineEventsMigrator(Context context) { this.databaseName = ""; this.ctx = context; try { File databasePath = context.getDatabasePath("Apsalar.sqlite_" + context.getSharedPreferences("ApsalarAppPrefs", 0).getString("HASH", "")); if (databasePath.exists()) { String path = databasePath.getPath(); this.databaseName = path; this.database = SQLiteDatabase.openDatabase(path, null, 0); } } catch (Exception e) { logger.error("Error in OfflineEventsMigrator", e); } } public void deleteDatabase() { if (this.database != null) { this.ctx.deleteDatabase(this.databaseName); } } public void migrate() { SQLiteDatabase sQLiteDatabase = this.database; if (sQLiteDatabase == null) { logger.debug("No database found; skipping."); return; } Cursor rawQuery = sQLiteDatabase.rawQuery("SELECT * FROM config", null); if (rawQuery == null || rawQuery.getCount() == 0) { return; } while (rawQuery.moveToNext()) { this.apiKey = rawQuery.getString(0); this.andi = rawQuery.getString(5); this.aifa = rawQuery.getString(6); this.imei = rawQuery.getString(7); this.apid = rawQuery.getString(10); this.canonicalDeviceId = rawQuery.getString(12); this.canonicalKeyspace = rawQuery.getString(11); this.mac1 = rawQuery.getString(8); this.bmac = rawQuery.getString(9); } rawQuery.close(); Cursor rawQuery2 = this.database.rawQuery("SELECT * FROM events", null); if (rawQuery2 == null || rawQuery2.getCount() == 0) { return; } int i = 0; while (rawQuery2.moveToNext()) { try { HashMap hashMap = new HashMap(); hashMap.put("__TIMESTAMP__", rawQuery2.getString(1)); String string = rawQuery2.getString(4); if (!Utils.isEmptyOrNull(string)) { hashMap.put(nb.q, string); } String string2 = rawQuery2.getString(5); if (!Utils.isEmptyOrNull(string2)) { hashMap.put("e", string2); } JSONObject jSONObject = new JSONObject(rawQuery2.getString(2)); int i2 = rawQuery2.getInt(3); if (i2 == 1) { hashMap.put("__TYPE__", "SESSION_START"); hashMap.put(nb.q, jSONObject.getString("appName")); } else if (i2 == 3) { hashMap.put("__TYPE__", "EVENT"); } else if (i2 == 5) { hashMap.put("__TYPE__", "RESOLVE"); } hashMap.put("s", jSONObject.getString("sessionId")); hashMap.put("a", jSONObject.getString("apiKey")); hashMap.put(ImpressionData.IMPRESSION_DATA_KEY_ABTEST, jSONObject.getString("abi")); hashMap.put(TtmlNode.TAG_P, jSONObject.getString("platform")); hashMap.put(i.a, jSONObject.getString("clsPackage")); hashMap.put("av", jSONObject.getString(v8.i.W)); hashMap.put("sdk", jSONObject.getString("sdkVersion")); hashMap.put("ma", jSONObject.getString("manufacturer")); hashMap.put(TtmlNode.TAG_BR, jSONObject.getString("brand")); hashMap.put("mo", jSONObject.getString("model")); hashMap.put(Consts.KEY_TAPJOY_USER_ID_VERSION, jSONObject.getString(AnalyticsData.S_OS_VERSION)); hashMap.put("c", jSONObject.getString("connType")); hashMap.put("pr", jSONObject.getString(AppLovinEventTypes.USER_VIEWED_PRODUCT)); hashMap.put(DownloadCommon.DOWNLOAD_REPORT_DOWNLOAD_ERROR, jSONObject.getString("device")); if (!Utils.isEmptyOrNull(this.aifa)) { hashMap.put("aifa", this.aifa); hashMap.put(CampaignEx.JSON_KEY_AD_K, "AIFA"); hashMap.put("u", this.canonicalDeviceId); } else { hashMap.put(CampaignEx.JSON_KEY_AD_K, "ANDI"); hashMap.put("u", this.andi); } try { SingularInstance.getInstance().getApiManager().enqueue(BaseApi.from(new JSONObject(hashMap).toString())); this.database.delete("events", "id=" + rawQuery2.getString(0), null); i++; } catch (IOException e) { logger.error("Error in JSON serialization", e); } } catch (Exception e2) { logger.debug(e2.getMessage()); } } rawQuery2.close(); deleteDatabase(); logger.debug("Migrated " + i + " events!"); } }