package com.tapjoy.internal; import android.app.Application; import android.content.Context; import android.util.Log; import com.tapjoy.TJSession; import com.tapjoy.TapjoyLog; import com.tapjoy.TapjoyUtil; import java.util.HashSet; import java.util.concurrent.CountDownLatch; /* loaded from: classes4.dex */ public final class c { public static final c d = new c(); public Application a; public b b; public final HashSet c = new HashSet(); public static void a(Context context) { if (context == null) { return; } c cVar = d; Context applicationContext = context.getApplicationContext(); if (cVar.a == null) { try { if (applicationContext instanceof Application) { cVar.a = (Application) applicationContext; } else { CountDownLatch countDownLatch = new CountDownLatch(1); TapjoyUtil.runOnMainThread(new a(cVar, countDownLatch)); countDownLatch.await(); } } catch (Exception e) { TapjoyLog.w("Tapjoy.ActivityTracker", Log.getStackTraceString(e)); } if (cVar.a == null) { return; } } synchronized (cVar) { try { if (cVar.b == null) { b bVar = new b(cVar); cVar.b = bVar; cVar.a.registerActivityLifecycleCallbacks(bVar); TJSession.INSTANCE.initSession(); } } finally { } } } public static void a() { c cVar = d; if (cVar.a == null) { return; } synchronized (cVar) { try { b bVar = cVar.b; if (bVar != null) { cVar.a.unregisterActivityLifecycleCallbacks(bVar); cVar.b = null; } } catch (Throwable th) { throw th; } } } }