package com.adobe.marketing.mobile.analytics.internal;

import ch.j;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.ExtensionApi;
import com.adobe.marketing.mobile.ExtensionEventListener;
import com.adobe.marketing.mobile.MobilePrivacyStatus;
import com.adobe.marketing.mobile.SharedStateResolution;
import com.adobe.marketing.mobile.SharedStateResult;
import com.adobe.marketing.mobile.SharedStateStatus;
import com.google.firebase.messaging.Constants;
import com.google.firebase.remoteconfig.RemoteConfigConstants;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import jn.o;
import kotlin.Metadata;
import kotlin.jvm.internal.t;
import ng.b;
import ng.e;
import ng.f;
import ng.g;
import ng.h;
import ng.i;
import rm.n0;
import sm.c0;
import sm.p0;
import sm.q0;
import sm.u;
import wg.i0;
import wg.v;

@Metadata(d1 = {"\u0000|\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010$\n\u0002\u0010\u000e\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0004\n\u0002\u0010\t\n\u0002\b\r\n\u0002\u0010 \n\u0002\b\u0007\n\u0002\u0010%\n\u0002\b\u0011\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007\b\u0000\u0018\u0000 72\u00020\u0001:\u0001WB\u0011\b\u0016\u0012\u0006\u0010R\u001a\u00020Q¢\u0006\u0004\bS\u0010TB\u001b\b\u0011\u0012\u0006\u0010R\u001a\u00020Q\u0012\b\u0010U\u001a\u0004\u0018\u00010=¢\u0006\u0004\bS\u0010VJ\u0010\u0010\u0005\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u0010\u0010\u0006\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u0010\u0010\u0007\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\b\u0010\b\u001a\u00020\u0004H\u0002J\u0010\u0010\t\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u0010\u0010\n\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u0010\u0010\u000b\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u001e\u0010\u0011\u001a\u00020\u00102\u0014\u0010\u000f\u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\fH\u0002J\u0010\u0010\u0012\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u0010\u0010\u0013\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J?\u0010\u001a\u001a\u00020\u00042\b\u0010\u0014\u001a\u0004\u0018\u00010\r2\b\u0010\u0016\u001a\u0004\u0018\u00010\u00152\b\u0010\u0017\u001a\u0004\u0018\u00010\r2\b\u0010\u0018\u001a\u0004\u0018\u00010\r2\u0006\u0010\u0019\u001a\u00020\rH\u0002¢\u0006\u0004\b\u001a\u0010\u001bJ$\u0010\u001c\u001a\u00020\u00042\b\u0010\u0017\u001a\u0004\u0018\u00010\r2\b\u0010\u0018\u001a\u0004\u0018\u00010\r2\u0006\u0010\u0019\u001a\u00020\rH\u0002J\u0010\u0010\u001e\u001a\u00020\u00042\u0006\u0010\u001d\u001a\u00020\u0015H\u0002J\u0010\u0010\u001f\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u0016\u0010 \u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\fH\u0002J&\u0010\"\u001a\u00020\u00042\u0014\u0010!\u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\f2\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u001e\u0010%\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u00022\f\u0010$\u001a\b\u0012\u0004\u0012\u00020\r0#H\u0002J&\u0010&\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u00022\u0014\u0010!\u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\fH\u0002J6\u0010)\u001a\u00020\u00042\u0014\u0010\u000f\u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\f2\u0006\u0010'\u001a\u00020\u00152\u0006\u0010(\u001a\u00020\u00102\u0006\u0010\u0019\u001a\u00020\rH\u0002J2\u0010,\u001a\u000e\u0012\u0004\u0012\u00020\r\u0012\u0004\u0012\u00020\r0+2\u0006\u0010'\u001a\u00020\u00152\u0014\u0010*\u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\fH\u0002J2\u0010/\u001a\u000e\u0012\u0004\u0012\u00020\r\u0012\u0004\u0012\u00020\r0+2\u0014\u0010-\u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\f2\u0006\u0010.\u001a\u00020\u0015H\u0002J\b\u00100\u001a\u00020\u0004H\u0002J\b\u00101\u001a\u00020\u0004H\u0002J*\u00102\u001a\u000e\u0012\u0004\u0012\u00020\r\u0012\u0004\u0012\u00020\r0\f2\u0014\u0010\u000f\u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\fH\u0002J\b\u00103\u001a\u00020\rH\u0014J\b\u00104\u001a\u00020\rH\u0014J\b\u00105\u001a\u00020\rH\u0014J\b\u00106\u001a\u00020\u0004H\u0014J\u0010\u00107\u001a\u00020\u00102\u0006\u0010\u0003\u001a\u00020\u0002H\u0016J\u0017\u00108\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0001¢\u0006\u0004\b8\u00109J\u0017\u0010:\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0001¢\u0006\u0004\b:\u00109J\u0017\u0010;\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0001¢\u0006\u0004\b;\u00109J\u0017\u0010<\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0001¢\u0006\u0004\b<\u00109R\u0014\u0010?\u001a\u00020=8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b4\u0010>R\u0014\u0010C\u001a\u00020@8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\bA\u0010BR\u0014\u0010G\u001a\u00020D8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\bE\u0010FR\u0014\u0010J\u001a\u00020H8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b3\u0010IR\u0014\u0010M\u001a\u00020K8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b5\u0010LR\u0014\u0010P\u001a\u00020N8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b6\u0010O¨\u0006X"}, d2 = {"Lcom/adobe/marketing/mobile/analytics/internal/AnalyticsExtension;", "Lcom/adobe/marketing/mobile/Extension;", "Lcom/adobe/marketing/mobile/Event;", "event", "Lrm/n0;", "x", "v", "z", "M", "s", "u", "t", "", "", "", "eventData", "", "E", "I", "J", "previousSessionLength", "", "previousSessionPauseTimestamp", "previousOSVersion", "previousAppIdVersion", "eventUniqueIdentifier", "m", "(Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "l", "timeout", "L", "A", "r", Constants.ScionAnalytics.MessageType.DATA_MESSAGE, "q", "", "dependencies", "K", "D", "timeStampInSeconds", "isBackdatedHit", "H", "trackEventData", "", "F", "trackData", "timestamp", "G", "p", "n", "o", "e", "b", "f", "g", "j", "y", "(Lcom/adobe/marketing/mobile/Event;)V", "B", "C", "w", "Lng/b;", "Lng/b;", "analyticsDatabase", "Lng/f;", "c", "Lng/f;", "analyticsProperties", "Lng/h;", "d", "Lng/h;", "analyticsState", "Lwg/v;", "Lwg/v;", "dataStore", "Lcom/adobe/marketing/mobile/ExtensionEventListener;", "Lcom/adobe/marketing/mobile/ExtensionEventListener;", "eventHandler", "Lng/i;", "Lng/i;", "analyticsTimer", "Lcom/adobe/marketing/mobile/ExtensionApi;", "extensionApi", "<init>", "(Lcom/adobe/marketing/mobile/ExtensionApi;)V", "database", "(Lcom/adobe/marketing/mobile/ExtensionApi;Lng/b;)V", "a", "analytics_phoneRelease"}, k = 1, mv = {1, 4, 3})
/* loaded from: classes4.dex */
public final class AnalyticsExtension extends Extension {

    /* renamed from: h, reason: collision with root package name */
    private static final List f12235h;

    /* renamed from: i, reason: collision with root package name */
    private static final List f12236i;

    /* renamed from: b, reason: collision with root package name and from kotlin metadata */
    private final ng.b analyticsDatabase;

    /* renamed from: c, reason: collision with root package name and from kotlin metadata */
    private final f analyticsProperties;

    /* renamed from: d, reason: collision with root package name and from kotlin metadata */
    private final h analyticsState;

    /* renamed from: e, reason: collision with root package name and from kotlin metadata */
    private final v dataStore;

    /* renamed from: f, reason: collision with root package name and from kotlin metadata */
    private final ExtensionEventListener eventHandler;

    /* renamed from: g, reason: collision with root package name and from kotlin metadata */
    private final i analyticsTimer;

    /* loaded from: classes4.dex */
    static final class b implements ExtensionEventListener {
        b() {
        }

        @Override // com.adobe.marketing.mobile.ExtensionEventListener
        public final void a(Event it) {
            t.g(it, "it");
            AnalyticsExtension.this.y(it);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class c extends kotlin.jvm.internal.v implements dn.a {
        c() {
            super(0);
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m200invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m200invoke() {
            wg.t.f("Analytics", "AnalyticsExtension", "waitForAcquisitionData - Launch hit delay has expired without referrer data.", new Object[0]);
            AnalyticsExtension.this.analyticsDatabase.b(b.EnumC0687b.REFERRER);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class d extends kotlin.jvm.internal.v implements dn.a {
        d() {
            super(0);
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m201invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m201invoke() {
            wg.t.f("Analytics", "AnalyticsExtension", "waitForLifecycleData - Lifecycle timeout has expired without Lifecycle data", new Object[0]);
            AnalyticsExtension.this.analyticsDatabase.b(b.EnumC0687b.LIFECYCLE);
        }
    }

    static {
        List n10;
        List n11;
        n10 = u.n("com.adobe.module.configuration", "com.adobe.module.identity");
        f12235h = n10;
        n11 = u.n("com.adobe.module.lifecycle", "com.adobe.assurance", "com.adobe.module.places");
        f12236i = n11;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public AnalyticsExtension(ExtensionApi extensionApi) {
        this(extensionApi, null);
        t.g(extensionApi, "extensionApi");
    }

    private final void A(Event event) {
        wg.t.a("Analytics", "AnalyticsExtension", "handleOptOut - Privacy status is opted-out. Queued Analytics hits, stored state data, and properties will be cleared.", new Object[0]);
        this.analyticsDatabase.i();
        this.analyticsProperties.e();
        a().b(r(), event);
    }

    private final void D(Event event, Map map) {
        if (map.isEmpty()) {
            wg.t.a("Analytics", "AnalyticsExtension", "handleTrackRequest - event data is null or empty.", new Object[0]);
        } else if (E(map)) {
            long v10 = event.v();
            String x10 = event.x();
            t.f(x10, "event.uniqueIdentifier");
            H(map, v10, false, x10);
        }
    }

    private final boolean E(Map eventData) {
        return eventData.containsKey(RemoteConfigConstants.ResponseFieldKey.STATE) || eventData.containsKey("action") || eventData.containsKey("contextdata");
    }

    private final Map F(long timeStampInSeconds, Map trackEventData) {
        HashMap hashMap = new HashMap();
        hashMap.putAll(this.analyticsState.j());
        Map n10 = ch.b.n(String.class, trackEventData, "contextdata", null);
        if (n10 != null) {
            hashMap.putAll(o(n10));
        }
        String actionName = ch.b.k(trackEventData, "action", null);
        boolean h10 = ch.b.h(trackEventData, "trackinternal", false);
        if (!j.a(actionName)) {
            String str = h10 ? "a.internalaction" : "a.action";
            t.f(actionName, "actionName");
            hashMap.put(str, actionName);
        }
        long n11 = this.analyticsState.n();
        if (n11 > 0) {
            long seconds = timeStampInSeconds - TimeUnit.MILLISECONDS.toSeconds(n11);
            long m10 = this.analyticsState.m();
            if (1 <= seconds && m10 >= seconds) {
                hashMap.put("a.TimeSinceLaunch", String.valueOf(seconds));
            }
        }
        if (this.analyticsState.o() == MobilePrivacyStatus.UNKNOWN) {
            hashMap.put("a.privacy.mode", "unknown");
        }
        String k10 = ch.b.k(trackEventData, "requestEventIdentifier", null);
        if (k10 != null) {
            hashMap.put("a.DebugEventIdentifier", k10);
        }
        return hashMap;
    }

    private final Map G(Map trackData, long timestamp) {
        HashMap hashMap = new HashMap();
        String k10 = ch.b.k(trackData, "action", null);
        String stateName = ch.b.k(trackData, RemoteConfigConstants.ResponseFieldKey.STATE, null);
        if (!j.a(k10)) {
            hashMap.put("pe", "lnk_o");
            hashMap.put("pev2", (ch.b.h(trackData, "trackinternal", false) ? "ADBINTERNAL:" : "AMACTION:") + k10);
        }
        String h10 = this.analyticsState.h();
        if (h10 != null) {
            hashMap.put("pageName", h10);
        }
        if (!j.a(stateName)) {
            t.f(stateName, "stateName");
            hashMap.put("pageName", stateName);
        }
        String b10 = this.analyticsProperties.b();
        if (b10 != null) {
            hashMap.put("aid", b10);
        }
        String d10 = this.analyticsProperties.d();
        if (d10 != null) {
            hashMap.put("vid", d10);
        }
        hashMap.put("ce", f.f29974f.a());
        String str = a.f12247a;
        t.f(str, "TimeZone.TIMESTAMP_TIMEZONE_OFFSET");
        hashMap.put("t", str);
        if (this.analyticsState.w()) {
            hashMap.put("ts", String.valueOf(timestamp));
        }
        if (this.analyticsState.y()) {
            hashMap.putAll(this.analyticsState.g());
        }
        hashMap.put("cp", "foreground");
        i0 f10 = i0.f();
        t.f(f10, "ServiceProvider.getInstance()");
        if (f10.a() != null) {
            i0 f11 = i0.f();
            t.f(f11, "ServiceProvider.getInstance()");
            wg.b a10 = f11.a();
            t.f(a10, "ServiceProvider.getInstance().appContextService");
            wg.c c10 = a10.c();
            t.f(c10, "ServiceProvider.getInsta…ppContextService.appState");
            if (c10 == wg.c.BACKGROUND) {
                hashMap.put("cp", "background");
            }
        } else {
            wg.t.e("Analytics", "AnalyticsExtension", "processAnalyticsVars - Unable to access platform services to retrieve foreground/background state. Defaulting customer perspective to foreground.", new Object[0]);
        }
        return hashMap;
    }

    private final void H(Map map, long j10, boolean z10, String str) {
        if (MobilePrivacyStatus.OPT_OUT == this.analyticsState.o()) {
            wg.t.f("Analytics", "AnalyticsExtension", "track - Dropping the Analytics track request, privacy status is opted out.", new Object[0]);
            return;
        }
        if (!this.analyticsState.s()) {
            wg.t.f("Analytics", "AnalyticsExtension", "track - Dropping the Analytics track request, Analytics is not configured.", new Object[0]);
            return;
        }
        this.analyticsProperties.g(j10);
        this.analyticsDatabase.h(g.f29979a.a(this.analyticsState, F(j10, map), G(map, j10)), j10, str, z10);
    }

    private final void I(Event event) {
        Map i10;
        Map o10 = event.o();
        i10 = q0.i();
        Map n10 = ch.b.n(String.class, o10, "contextdata", i10);
        t.f(n10, "DataReader.optTypedMap(\n…     emptyMap()\n        )");
        if (this.analyticsTimer.d()) {
            wg.t.a("Analytics", "AnalyticsExtension", "trackAcquisition - Cancelling referrer timer", new Object[0]);
            this.analyticsTimer.b();
        }
        if (this.analyticsDatabase.d()) {
            wg.t.a("Analytics", "AnalyticsExtension", "trackAcquisition - Append referrer data to pending hit", new Object[0]);
            this.analyticsDatabase.f(b.EnumC0687b.REFERRER, n10);
            return;
        }
        this.analyticsDatabase.b(b.EnumC0687b.REFERRER);
        wg.t.a("Analytics", "AnalyticsExtension", "trackAcquisition - Sending referrer data as separate tracking hit", new Object[0]);
        HashMap hashMap = new HashMap();
        hashMap.put("action", "AdobeLink");
        hashMap.put("contextdata", n10);
        hashMap.put("trackinternal", Boolean.TRUE);
        long v10 = event.v();
        String x10 = event.x();
        t.f(x10, "event.uniqueIdentifier");
        H(hashMap, v10, false, x10);
    }

    private final void J(Event event) {
        Map n10 = ch.b.n(String.class, event.o(), "lifecyclecontextdata", null);
        if (n10 == null) {
            wg.t.a("Analytics", "AnalyticsExtension", "trackLifecycle - Failed to track lifecycle event (context data was null or empty)", new Object[0]);
            return;
        }
        HashMap hashMap = new HashMap(n10);
        HashMap hashMap2 = new HashMap();
        String str = (String) hashMap.remove("previousosversion");
        String str2 = (String) hashMap.remove("previousappid");
        for (Map.Entry entry : ng.a.f29943b.a().entrySet()) {
            String str3 = (String) hashMap.get(entry.getKey());
            if (str3 != null) {
                if (str3.length() > 0) {
                    hashMap2.put(entry.getValue(), str3);
                    hashMap.remove(entry.getKey());
                }
            }
        }
        hashMap2.putAll(hashMap);
        if (hashMap2.containsKey("a.InstallEvent")) {
            L(TimeUnit.SECONDS.toMillis(this.analyticsState.p()));
        } else if (hashMap2.containsKey("a.LaunchEvent")) {
            L(500);
        }
        if (this.analyticsState.v() && this.analyticsState.w()) {
            if (hashMap2.containsKey("a.CrashEvent")) {
                hashMap2.remove("a.CrashEvent");
                String x10 = event.x();
                t.f(x10, "event.uniqueIdentifier");
                l(str, str2, x10);
            }
            if (hashMap2.containsKey("a.PrevSessionLength")) {
                String str4 = (String) hashMap2.remove("a.PrevSessionLength");
                String str5 = (String) hashMap.remove("previoussessionpausetimestampmillis");
                Long valueOf = str5 != null ? Long.valueOf(Long.parseLong(str5)) : null;
                String x11 = event.x();
                t.f(x11, "event.uniqueIdentifier");
                m(str4, valueOf, str, str2, x11);
            }
        }
        if (this.analyticsTimer.c()) {
            wg.t.a("Analytics", "AnalyticsExtension", "trackLifecycle - Cancelling lifecycle timer", new Object[0]);
            this.analyticsTimer.a();
        }
        if (this.analyticsDatabase.d()) {
            wg.t.a("Analytics", "AnalyticsExtension", "trackLifecycle - Append lifecycle data to pending hit", new Object[0]);
            this.analyticsDatabase.f(b.EnumC0687b.LIFECYCLE, hashMap2);
            return;
        }
        this.analyticsDatabase.b(b.EnumC0687b.LIFECYCLE);
        wg.t.a("Analytics", "AnalyticsExtension", "trackLifecycle - Sending lifecycle data as separate tracking hit", new Object[0]);
        HashMap hashMap3 = new HashMap();
        hashMap3.put("action", "Lifecycle");
        hashMap3.put("contextdata", hashMap2);
        hashMap3.put("trackinternal", Boolean.TRUE);
        long v10 = event.v();
        String x12 = event.x();
        t.f(x12, "event.uniqueIdentifier");
        H(hashMap3, v10, false, x12);
    }

    private final void K(Event event, List list) {
        int v10;
        int d10;
        int d11;
        List list2 = list;
        v10 = sm.v.v(list2, 10);
        d10 = p0.d(v10);
        d11 = o.d(d10, 16);
        LinkedHashMap linkedHashMap = new LinkedHashMap(d11);
        for (Object obj : list2) {
            SharedStateResult e10 = a().e((String) obj, event, true, SharedStateResolution.ANY);
            linkedHashMap.put(obj, e10 != null ? e10.b() : null);
        }
        this.analyticsState.B(linkedHashMap);
    }

    private final void L(long j10) {
        wg.t.a("Analytics", "AnalyticsExtension", "waitForAcquisitionData - Referrer timer scheduled with timeout " + j10, new Object[0]);
        this.analyticsDatabase.j(b.EnumC0687b.REFERRER);
        this.analyticsTimer.g(j10, new c());
    }

    private final void M() {
        wg.t.a("Analytics", "AnalyticsExtension", "waitForLifecycleData - Lifecycle timer scheduled with timeout 1000", new Object[0]);
        this.analyticsDatabase.j(b.EnumC0687b.LIFECYCLE);
        this.analyticsTimer.f(1000L, new d());
    }

    private final void l(String str, String str2, String str3) {
        HashMap hashMap = new HashMap();
        hashMap.put("a.CrashEvent", "CrashEvent");
        if (str != null) {
            if (str.length() > 0) {
                hashMap.put("a.OSVersion", str);
            }
        }
        if (str2 != null) {
            if (str2.length() > 0) {
                hashMap.put("a.AppID", str2);
            }
        }
        HashMap hashMap2 = new HashMap();
        hashMap2.put("action", "Crash");
        hashMap2.put("contextdata", hashMap);
        hashMap2.put("trackinternal", Boolean.TRUE);
        H(hashMap2, this.analyticsProperties.c() + 1, true, str3);
    }

    private final void m(String previousSessionLength, Long previousSessionPauseTimestamp, String previousOSVersion, String previousAppIdVersion, String eventUniqueIdentifier) {
        long e10;
        HashMap hashMap = new HashMap();
        if (previousSessionLength != null) {
            hashMap.put("a.PrevSessionLength", previousSessionLength);
        }
        if (previousOSVersion != null) {
            if (previousOSVersion.length() > 0) {
                hashMap.put("a.OSVersion", previousOSVersion);
            }
        }
        if (previousAppIdVersion != null) {
            if (previousAppIdVersion.length() > 0) {
                hashMap.put("a.AppID", previousAppIdVersion);
            }
        }
        HashMap hashMap2 = new HashMap();
        hashMap2.put("action", "SessionInfo");
        hashMap2.put("contextdata", hashMap);
        hashMap2.put("trackinternal", Boolean.TRUE);
        e10 = o.e(this.analyticsProperties.c(), previousSessionPauseTimestamp != null ? previousSessionPauseTimestamp.longValue() : 0L);
        H(hashMap2, e10 + 1, true, eventUniqueIdentifier);
    }

    private final void n() {
        a().b(r(), null);
        wg.t.e("Analytics", "AnalyticsExtension", "Analytics boot-up complete, published initial shared state.", new Object[0]);
    }

    private final Map o(Map eventData) {
        int d10;
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        for (Map.Entry entry : eventData.entrySet()) {
            if (entry.getValue() instanceof String) {
                linkedHashMap.put(entry.getKey(), entry.getValue());
            }
        }
        d10 = p0.d(linkedHashMap.size());
        LinkedHashMap linkedHashMap2 = new LinkedHashMap(d10);
        for (Map.Entry entry2 : linkedHashMap.entrySet()) {
            Object key = entry2.getKey();
            Object value = entry2.getValue();
            if (value == null) {
                throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
            }
            linkedHashMap2.put(key, (String) value);
        }
        return linkedHashMap2;
    }

    private final void p() {
        ch.g.a("ADBMobileDataCache.sqlite");
    }

    private final void q(Map map, Event event) {
        a().c(new Event.Builder("TrackingIdentifierValue", "com.adobe.eventType.analytics", "com.adobe.eventSource.responseIdentity").d(map).c(event).a());
        wg.t.e("Analytics", "AnalyticsExtension", "Dispatching Analytics paired response identity event with eventdata: %s.", map);
        a().c(new Event.Builder("TrackingIdentifierValue", "com.adobe.eventType.analytics", "com.adobe.eventSource.responseIdentity").d(map).a());
        wg.t.e("Analytics", "AnalyticsExtension", "Dispatching Analytics unpaired response identity event with eventdata: %s.", map);
    }

    private final Map r() {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        String b10 = this.analyticsProperties.b();
        if (b10 != null) {
            linkedHashMap.put("aid", b10);
        }
        String d10 = this.analyticsProperties.d();
        if (d10 != null) {
            linkedHashMap.put("vid", d10);
        }
        return linkedHashMap;
    }

    private final void s(Event event) {
        List z02;
        if ((!t.b(event.w(), "com.adobe.eventType.acquisition")) || (!t.b(event.t(), "com.adobe.eventSource.responseContent"))) {
            return;
        }
        z02 = c0.z0(f12235h, f12236i);
        K(event, z02);
        I(event);
    }

    private final void t(Event event) {
        Map e10;
        List z02;
        Map o10 = event.o();
        if (o10 == null || !(!o10.isEmpty())) {
            wg.t.f("Analytics", "AnalyticsExtension", "handleAnalyticsRequestContentEvent - Returning early, event data is null or empty.", new Object[0]);
            return;
        }
        if (o10.containsKey("clearhitsqueue")) {
            this.analyticsDatabase.i();
            return;
        }
        if (E(o10)) {
            z02 = c0.z0(f12235h, f12236i);
            K(event, z02);
            long v10 = event.v();
            String x10 = event.x();
            t.f(x10, "event.uniqueIdentifier");
            H(o10, v10, false, x10);
            return;
        }
        if (!o10.containsKey("getqueuesize")) {
            if (o10.containsKey("forcekick")) {
                this.analyticsDatabase.e(true);
            }
        } else {
            e10 = p0.e(rm.c0.a("queuesize", Integer.valueOf(this.analyticsDatabase.c())));
            wg.t.a("Analytics", "AnalyticsExtension", "Dispatching Analytics hit queue size response event with eventdata " + e10, new Object[0]);
            a().c(new Event.Builder("QueueSizeValue", "com.adobe.eventType.analytics", "com.adobe.eventSource.responseContent").c(event).d(e10).a());
        }
    }

    private final void u(Event event) {
        Map o10 = event.o();
        if (o10 == null || !o10.containsKey("vid")) {
            q(r(), event);
            return;
        }
        if (this.analyticsState.o() == MobilePrivacyStatus.OPT_OUT) {
            wg.t.a("Analytics", "AnalyticsExtension", "handleAnalyticsRequestIdentityEvent - Privacy is opted out, ignoring the update visitor identifier request.", new Object[0]);
            return;
        }
        try {
            this.analyticsProperties.h(ch.b.c(event.o(), "vid"));
            Map r10 = r();
            a().b(r10, event);
            q(r10, event);
        } catch (ch.c unused) {
            wg.t.a("Analytics", "AnalyticsExtension", "handleAnalyticsRequestIdentityEvent - Failed to parse the visitor identifier to string, ignoring the update visitor identifier request.", new Object[0]);
        }
    }

    private final void v(Event event) {
        List z02;
        z02 = c0.z0(f12235h, f12236i);
        K(event, z02);
        if (this.analyticsState.o() == MobilePrivacyStatus.OPT_OUT) {
            A(event);
        } else if (this.analyticsState.o() == MobilePrivacyStatus.OPT_IN) {
            this.analyticsDatabase.e(false);
        }
    }

    private final void x(Event event) {
        List z02;
        if ((!t.b(event.w(), "com.adobe.eventType.generic.track")) || (!t.b(event.t(), "com.adobe.eventSource.requestContent"))) {
            wg.t.a("Analytics", "AnalyticsExtension", "handleAnalyticsTrackEvent - Ignoring track event (event is of unexpected type or source).", new Object[0]);
            return;
        }
        z02 = c0.z0(f12235h, f12236i);
        K(event, z02);
        Map o10 = event.o();
        if (o10 == null) {
            wg.t.a("Analytics", "AnalyticsExtension", "handleGenericTrackEvent - event data is null or empty.", new Object[0]);
        } else {
            D(event, o10);
        }
    }

    private final void z(Event event) {
        List z02;
        if ((!t.b(event.w(), "com.adobe.eventType.lifecycle")) || (!t.b(event.t(), "com.adobe.eventSource.responseContent"))) {
            return;
        }
        z02 = c0.z0(f12235h, f12236i);
        K(event, z02);
        J(event);
    }

    public final void B(Event event) {
        t.g(event, "event");
        if ((!t.b(event.w(), "com.adobe.eventType.generic.identity")) || (!t.b(event.t(), "com.adobe.eventSource.requestReset"))) {
            wg.t.a("Analytics", "AnalyticsExtension", "handleResetIdentitiesEvent - Ignoring reset event (event is of unexpected type or source).", new Object[0]);
            return;
        }
        wg.t.a("Analytics", "AnalyticsExtension", "handleResetIdentitiesEvent - Resetting all identifiers.", new Object[0]);
        this.analyticsDatabase.i();
        this.analyticsProperties.e();
        this.analyticsState.z();
        this.analyticsState.A(event.v());
        a().b(r(), event);
    }

    public final void C(Event event) {
        List z02;
        Map i10;
        t.g(event, "event");
        Map o10 = event.o();
        if (o10 == null) {
            wg.t.e("Analytics", "AnalyticsExtension", "handleRuleEngineResponse - Event with id %s contained no data, ignoring.", event.x());
            return;
        }
        Map n10 = ch.b.n(Object.class, o10, "triggeredconsequence", null);
        if (n10 == null || n10.isEmpty()) {
            wg.t.e("Analytics", "AnalyticsExtension", "handleRuleEngineResponse - Missing consequence data, ignoring event %s.", event.x());
            return;
        }
        if (j.a(ch.b.k(n10, "type", null))) {
            wg.t.e("Analytics", "AnalyticsExtension", "handleRuleEngineResponse - No consequence type received, ignoring event %s.", event.x());
            return;
        }
        if (!t.b("an", r3)) {
            wg.t.e("Analytics", "AnalyticsExtension", "handleRuleEngineResponse - Consequence type is not Analytics, ignoring event %s.", event.x());
            return;
        }
        if (j.a(ch.b.k(n10, "id", null))) {
            wg.t.e("Analytics", "AnalyticsExtension", "handleRuleEngineResponse - Consequence id is missing, ignoring event  %s.", event.x());
            return;
        }
        wg.t.e("Analytics", "AnalyticsExtension", "handleRuleEngineResponse - Submitting Rules Engine Track response content event (%s) for processing.", event.x());
        z02 = c0.z0(f12235h, f12236i);
        K(event, z02);
        i10 = q0.i();
        Map consequenceDetail = ch.b.n(Object.class, n10, "detail", i10);
        t.f(consequenceDetail, "consequenceDetail");
        D(event, consequenceDetail);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.adobe.marketing.mobile.Extension
    public String b() {
        return "Analytics";
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.adobe.marketing.mobile.Extension
    public String e() {
        return "com.adobe.module.analytics";
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.adobe.marketing.mobile.Extension
    public String f() {
        return "2.0.2";
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.adobe.marketing.mobile.Extension
    public void g() {
        a().f("com.adobe.eventType.rulesEngine", "com.adobe.eventSource.responseContent", this.eventHandler);
        a().f("com.adobe.eventType.analytics", "com.adobe.eventSource.requestContent", this.eventHandler);
        a().f("com.adobe.eventType.analytics", "com.adobe.eventSource.requestIdentity", this.eventHandler);
        a().f("com.adobe.eventType.configuration", "com.adobe.eventSource.responseContent", this.eventHandler);
        a().f("com.adobe.eventType.generic.lifecycle", "com.adobe.eventSource.requestContent", this.eventHandler);
        a().f("com.adobe.eventType.lifecycle", "com.adobe.eventSource.responseContent", this.eventHandler);
        a().f("com.adobe.eventType.acquisition", "com.adobe.eventSource.responseContent", this.eventHandler);
        a().f("com.adobe.eventType.generic.track", "com.adobe.eventSource.requestContent", this.eventHandler);
        a().f("com.adobe.eventType.generic.identity", "com.adobe.eventSource.requestReset", this.eventHandler);
        p();
        n();
    }

    @Override // com.adobe.marketing.mobile.Extension
    public boolean j(Event event) {
        t.g(event, "event");
        ExtensionApi a10 = a();
        SharedStateResolution sharedStateResolution = SharedStateResolution.ANY;
        SharedStateResult e10 = a10.e("com.adobe.module.configuration", event, false, sharedStateResolution);
        SharedStateResult e11 = a().e("com.adobe.module.identity", event, false, sharedStateResolution);
        SharedStateStatus a11 = e10 != null ? e10.a() : null;
        SharedStateStatus sharedStateStatus = SharedStateStatus.SET;
        if (a11 == sharedStateStatus) {
            return (e11 != null ? e11.a() : null) == sharedStateStatus;
        }
        return false;
    }

    public final void w(Event event) {
        t.g(event, "event");
        if ((!t.b(event.w(), "com.adobe.eventType.generic.lifecycle")) || (!t.b(event.t(), "com.adobe.eventSource.requestContent"))) {
            return;
        }
        Map o10 = event.o();
        Object obj = o10 != null ? o10.get("action") : null;
        if (!t.b(obj, "start")) {
            if (t.b(obj, "pause")) {
                this.analyticsTimer.a();
                this.analyticsTimer.b();
                return;
            }
            return;
        }
        if (this.analyticsTimer.e()) {
            wg.t.a("Analytics", "AnalyticsExtension", "handleGenericLifecycleEvents - Exiting, Lifecycle timer is already running and this is a duplicate request", new Object[0]);
            return;
        }
        this.analyticsDatabase.b(b.EnumC0687b.REFERRER);
        this.analyticsDatabase.b(b.EnumC0687b.LIFECYCLE);
        M();
    }

    public final void y(Event event) {
        String t10;
        t.g(event, "event");
        String w10 = event.w();
        if (w10 == null) {
            return;
        }
        switch (w10.hashCode()) {
            case -1916134322:
                if (w10.equals("com.adobe.eventType.generic.track")) {
                    x(event);
                    return;
                }
                return;
            case -1784231328:
                if (!w10.equals("com.adobe.eventType.analytics") || (t10 = event.t()) == null) {
                    return;
                }
                int hashCode = t10.hashCode();
                if (hashCode == -1950247128) {
                    if (t10.equals("com.adobe.eventSource.requestIdentity")) {
                        u(event);
                        return;
                    }
                    return;
                } else {
                    if (hashCode == 2001377487 && t10.equals("com.adobe.eventSource.requestContent")) {
                        t(event);
                        return;
                    }
                    return;
                }
            case -553401637:
                if (w10.equals("com.adobe.eventType.generic.identity")) {
                    B(event);
                    return;
                }
                return;
            case -485068825:
                if (w10.equals("com.adobe.eventType.acquisition")) {
                    s(event);
                    return;
                }
                return;
            case -393537980:
                if (w10.equals("com.adobe.eventType.lifecycle")) {
                    z(event);
                    return;
                }
                return;
            case -364259091:
                if (w10.equals("com.adobe.eventType.generic.lifecycle")) {
                    w(event);
                    return;
                }
                return;
            case 972859088:
                if (w10.equals("com.adobe.eventType.configuration")) {
                    v(event);
                    return;
                }
                return;
            case 1388788339:
                if (w10.equals("com.adobe.eventType.rulesEngine")) {
                    C(event);
                    return;
                }
                return;
            default:
                return;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public AnalyticsExtension(ExtensionApi extensionApi, ng.b bVar) {
        super(extensionApi);
        t.g(extensionApi, "extensionApi");
        h hVar = new h();
        this.analyticsState = hVar;
        i0 f10 = i0.f();
        t.f(f10, "ServiceProvider.getInstance()");
        v a10 = f10.d().a("AnalyticsDataStorage");
        t.f(a10, "ServiceProvider.getInsta…Constants.DATASTORE_NAME)");
        this.dataStore = a10;
        this.eventHandler = new b();
        this.analyticsTimer = new i();
        this.analyticsProperties = new f(a10);
        this.analyticsDatabase = bVar == null ? new ng.b(new e(hVar, extensionApi), hVar) : bVar;
    }
}
