package com.facebook.appevents; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; import com.facebook.FacebookSdk; import com.facebook.appevents.internal.AppEventUtility; import java.util.concurrent.locks.ReentrantReadWriteLock; /* loaded from: classes2.dex */ public final class AnalyticsUserIDStore { private static final String ANALYTICS_USER_ID_KEY = "com.facebook.appevents.AnalyticsUserIDStore.userID"; private static volatile boolean initialized; private static String userID; public static final AnalyticsUserIDStore INSTANCE = new AnalyticsUserIDStore(); private static final String TAG = AnalyticsUserIDStore.class.getSimpleName(); private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); private AnalyticsUserIDStore() { } public static final void initStore() { if (initialized) { return; } InternalAppEventsLogger.Companion.getAnalyticsExecutor().execute(new Runnable() { // from class: com.facebook.appevents.AnalyticsUserIDStore$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { AnalyticsUserIDStore.m445initStore$lambda0(); } }); } /* JADX INFO: Access modifiers changed from: private */ /* renamed from: initStore$lambda-0, reason: not valid java name */ public static final void m445initStore$lambda0() { INSTANCE.initAndWait(); } public static final void setUserID(final String str) { AppEventUtility.assertIsNotMainThread(); if (!initialized) { Log.w(TAG, "initStore should have been called before calling setUserID"); INSTANCE.initAndWait(); } InternalAppEventsLogger.Companion.getAnalyticsExecutor().execute(new Runnable() { // from class: com.facebook.appevents.AnalyticsUserIDStore$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { AnalyticsUserIDStore.m446setUserID$lambda1(str); } }); } /* JADX INFO: Access modifiers changed from: private */ /* renamed from: setUserID$lambda-1, reason: not valid java name */ public static final void m446setUserID$lambda1(String str) { ReentrantReadWriteLock reentrantReadWriteLock = lock; reentrantReadWriteLock.writeLock().lock(); try { userID = str; SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(FacebookSdk.getApplicationContext()).edit(); edit.putString(ANALYTICS_USER_ID_KEY, userID); edit.apply(); reentrantReadWriteLock.writeLock().unlock(); } catch (Throwable th) { lock.writeLock().unlock(); throw th; } } public static final String getUserID() { if (!initialized) { Log.w(TAG, "initStore should have been called before calling setUserID"); INSTANCE.initAndWait(); } ReentrantReadWriteLock reentrantReadWriteLock = lock; reentrantReadWriteLock.readLock().lock(); try { String str = userID; reentrantReadWriteLock.readLock().unlock(); return str; } catch (Throwable th) { lock.readLock().unlock(); throw th; } } private final void initAndWait() { if (initialized) { return; } ReentrantReadWriteLock reentrantReadWriteLock = lock; reentrantReadWriteLock.writeLock().lock(); try { if (!initialized) { userID = PreferenceManager.getDefaultSharedPreferences(FacebookSdk.getApplicationContext()).getString(ANALYTICS_USER_ID_KEY, null); initialized = true; reentrantReadWriteLock.writeLock().unlock(); return; } reentrantReadWriteLock.writeLock().unlock(); } catch (Throwable th) { lock.writeLock().unlock(); throw th; } } }