package com.google.firebase.sessions; import android.content.Context; import android.util.Log; import androidx.datastore.core.CorruptionException; import androidx.datastore.core.DataStore; import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler; import androidx.datastore.preferences.PreferenceDataStoreDelegateKt; import androidx.datastore.preferences.core.Preferences; import androidx.datastore.preferences.core.PreferencesFactory; import androidx.datastore.preferences.core.PreferencesKeys; import com.facebook.gamingservices.cloudgaming.internal.SDKAnalyticsEvents; import java.util.concurrent.atomic.AtomicReference; import kotlin.ResultKt; import kotlin.Unit; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt; import kotlin.coroutines.jvm.internal.ContinuationImpl; import kotlin.coroutines.jvm.internal.SuspendLambda; import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function2; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.PropertyReference2Impl; import kotlin.jvm.internal.Reflection; import kotlin.properties.ReadOnlyProperty; import kotlin.reflect.KProperty; import kotlinx.coroutines.BuildersKt__Builders_commonKt; import kotlinx.coroutines.CoroutineScope; import kotlinx.coroutines.CoroutineScopeKt; import kotlinx.coroutines.flow.Flow; import kotlinx.coroutines.flow.FlowCollector; import kotlinx.coroutines.flow.FlowKt; /* loaded from: classes3.dex */ public final class SessionDatastoreImpl implements SessionDatastore { public static final Companion Companion = new Companion(null); public static final ReadOnlyProperty dataStore$delegate = PreferenceDataStoreDelegateKt.preferencesDataStore$default(SessionDataStoreConfigs.INSTANCE.getSESSIONS_CONFIG_NAME(), new ReplaceFileCorruptionHandler(new Function1() { // from class: com.google.firebase.sessions.SessionDatastoreImpl$Companion$dataStore$2 @Override // kotlin.jvm.functions.Function1 public final Preferences invoke(CorruptionException ex) { Intrinsics.checkNotNullParameter(ex, "ex"); Log.w("FirebaseSessionsRepo", "CorruptionException in sessions DataStore in " + ProcessDetailsProvider.INSTANCE.getProcessName$com_google_firebase_firebase_sessions() + '.', ex); return PreferencesFactory.createEmpty(); } }), null, null, 12, null); public final CoroutineContext backgroundDispatcher; public final Context context; public final AtomicReference currentSessionFromDatastore; public final Flow firebaseSessionDataFlow; public static final class FirebaseSessionDataKeys { public static final FirebaseSessionDataKeys INSTANCE = new FirebaseSessionDataKeys(); public static final Preferences.Key SESSION_ID = PreferencesKeys.stringKey(SDKAnalyticsEvents.PARAMETER_SESSION_ID); public final Preferences.Key getSESSION_ID() { return SESSION_ID; } } public SessionDatastoreImpl(Context context, CoroutineContext backgroundDispatcher) { Intrinsics.checkNotNullParameter(context, "context"); Intrinsics.checkNotNullParameter(backgroundDispatcher, "backgroundDispatcher"); this.context = context; this.backgroundDispatcher = backgroundDispatcher; this.currentSessionFromDatastore = new AtomicReference(); final Flow m4143catch = FlowKt.m4143catch(Companion.getDataStore(context).getData(), new SessionDatastoreImpl$firebaseSessionDataFlow$1(null)); this.firebaseSessionDataFlow = new Flow() { // from class: com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1 /* renamed from: com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1$2, reason: invalid class name */ public static final class AnonymousClass2 implements FlowCollector { public final /* synthetic */ FlowCollector $this_unsafeFlow; public final /* synthetic */ SessionDatastoreImpl this$0; /* renamed from: com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1$2$1, reason: invalid class name */ public static final class AnonymousClass1 extends ContinuationImpl { public int label; public /* synthetic */ Object result; public AnonymousClass1(Continuation continuation) { super(continuation); } @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl public final Object invokeSuspend(Object obj) { this.result = obj; this.label |= Integer.MIN_VALUE; return AnonymousClass2.this.emit(null, this); } } public AnonymousClass2(FlowCollector flowCollector, SessionDatastoreImpl sessionDatastoreImpl) { this.$this_unsafeFlow = flowCollector; this.this$0 = sessionDatastoreImpl; } /* JADX WARN: Removed duplicated region for block: B:15:0x0031 */ /* JADX WARN: Removed duplicated region for block: B:8:0x0023 */ @Override // kotlinx.coroutines.flow.FlowCollector /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public final java.lang.Object emit(java.lang.Object r5, kotlin.coroutines.Continuation r6) { /* r4 = this; boolean r0 = r6 instanceof com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1.AnonymousClass2.AnonymousClass1 if (r0 == 0) goto L13 r0 = r6 com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1$2$1 r0 = (com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1.AnonymousClass2.AnonymousClass1) r0 int r1 = r0.label r2 = -2147483648(0xffffffff80000000, float:-0.0) r3 = r1 & r2 if (r3 == 0) goto L13 int r1 = r1 - r2 r0.label = r1 goto L18 L13: com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1$2$1 r0 = new com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1$2$1 r0.(r6) L18: java.lang.Object r6 = r0.result java.lang.Object r1 = kotlin.coroutines.intrinsics.IntrinsicsKt.getCOROUTINE_SUSPENDED() int r2 = r0.label r3 = 1 if (r2 == 0) goto L31 if (r2 != r3) goto L29 kotlin.ResultKt.throwOnFailure(r6) goto L47 L29: java.lang.IllegalStateException r5 = new java.lang.IllegalStateException java.lang.String r6 = "call to 'resume' before 'invoke' with coroutine" r5.(r6) throw r5 L31: kotlin.ResultKt.throwOnFailure(r6) kotlinx.coroutines.flow.FlowCollector r6 = r4.$this_unsafeFlow androidx.datastore.preferences.core.Preferences r5 = (androidx.datastore.preferences.core.Preferences) r5 com.google.firebase.sessions.SessionDatastoreImpl r2 = r4.this$0 com.google.firebase.sessions.FirebaseSessionsData r5 = com.google.firebase.sessions.SessionDatastoreImpl.access$mapSessionsData(r2, r5) r0.label = r3 java.lang.Object r5 = r6.emit(r5, r0) if (r5 != r1) goto L47 return r1 L47: kotlin.Unit r5 = kotlin.Unit.INSTANCE return r5 */ throw new UnsupportedOperationException("Method not decompiled: com.google.firebase.sessions.SessionDatastoreImpl$special$$inlined$map$1.AnonymousClass2.emit(java.lang.Object, kotlin.coroutines.Continuation):java.lang.Object"); } } @Override // kotlinx.coroutines.flow.Flow public Object collect(FlowCollector flowCollector, Continuation continuation) { Object coroutine_suspended; Object collect = Flow.this.collect(new AnonymousClass2(flowCollector, this), continuation); coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); return collect == coroutine_suspended ? collect : Unit.INSTANCE; } }; BuildersKt__Builders_commonKt.launch$default(CoroutineScopeKt.CoroutineScope(backgroundDispatcher), null, null, new AnonymousClass1(null), 3, null); } /* renamed from: com.google.firebase.sessions.SessionDatastoreImpl$1, reason: invalid class name */ public static final class AnonymousClass1 extends SuspendLambda implements Function2 { public int label; public AnonymousClass1(Continuation continuation) { super(2, continuation); } @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl public final Continuation create(Object obj, Continuation continuation) { return SessionDatastoreImpl.this.new AnonymousClass1(continuation); } @Override // kotlin.jvm.functions.Function2 public final Object invoke(CoroutineScope coroutineScope, Continuation continuation) { return ((AnonymousClass1) create(coroutineScope, continuation)).invokeSuspend(Unit.INSTANCE); } @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl public final Object invokeSuspend(Object obj) { Object coroutine_suspended; coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(); int i = this.label; if (i == 0) { ResultKt.throwOnFailure(obj); Flow flow = SessionDatastoreImpl.this.firebaseSessionDataFlow; final SessionDatastoreImpl sessionDatastoreImpl = SessionDatastoreImpl.this; FlowCollector flowCollector = new FlowCollector() { // from class: com.google.firebase.sessions.SessionDatastoreImpl.1.1 @Override // kotlinx.coroutines.flow.FlowCollector public final Object emit(FirebaseSessionsData firebaseSessionsData, Continuation continuation) { SessionDatastoreImpl.this.currentSessionFromDatastore.set(firebaseSessionsData); return Unit.INSTANCE; } }; this.label = 1; if (flow.collect(flowCollector, this) == coroutine_suspended) { return coroutine_suspended; } } else { if (i != 1) { throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine"); } ResultKt.throwOnFailure(obj); } return Unit.INSTANCE; } } @Override // com.google.firebase.sessions.SessionDatastore public void updateSessionId(String sessionId) { Intrinsics.checkNotNullParameter(sessionId, "sessionId"); BuildersKt__Builders_commonKt.launch$default(CoroutineScopeKt.CoroutineScope(this.backgroundDispatcher), null, null, new SessionDatastoreImpl$updateSessionId$1(this, sessionId, null), 3, null); } @Override // com.google.firebase.sessions.SessionDatastore public String getCurrentSessionId() { FirebaseSessionsData firebaseSessionsData = (FirebaseSessionsData) this.currentSessionFromDatastore.get(); if (firebaseSessionsData != null) { return firebaseSessionsData.getSessionId(); } return null; } public final FirebaseSessionsData mapSessionsData(Preferences preferences) { return new FirebaseSessionsData((String) preferences.get(FirebaseSessionDataKeys.INSTANCE.getSESSION_ID())); } public static final class Companion { public static final /* synthetic */ KProperty[] $$delegatedProperties = {Reflection.property2(new PropertyReference2Impl(Companion.class, "dataStore", "getDataStore(Landroid/content/Context;)Landroidx/datastore/core/DataStore;", 0))}; public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public Companion() { } public final DataStore getDataStore(Context context) { return (DataStore) SessionDatastoreImpl.dataStore$delegate.getValue(context, $$delegatedProperties[0]); } } }