package com.google.firebase.messaging; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import com.google.android.gms.stats.WakeLock; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import java.util.concurrent.TimeUnit; /* loaded from: classes3.dex */ public abstract class WakeLockHolder { public static final long WAKE_LOCK_ACQUIRE_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(1); public static final Object syncObject = new Object(); public static WakeLock wakeLock; public static void checkAndInitWakeLock(Context context) { if (wakeLock == null) { WakeLock wakeLock2 = new WakeLock(context, 1, "wake:com.google.firebase.iid.WakeLockHolder"); wakeLock = wakeLock2; wakeLock2.setReferenceCounted(true); } } public static ComponentName startWakefulService(Context context, Intent intent) { synchronized (syncObject) { try { checkAndInitWakeLock(context); boolean isWakefulIntent = isWakefulIntent(intent); setAsWakefulIntent(intent, true); ComponentName startService = context.startService(intent); if (startService == null) { return null; } if (!isWakefulIntent) { wakeLock.acquire(WAKE_LOCK_ACQUIRE_TIMEOUT_MILLIS); } return startService; } catch (Throwable th) { throw th; } } } public static void sendWakefulServiceIntent(Context context, WithinAppServiceConnection withinAppServiceConnection, final Intent intent) { synchronized (syncObject) { try { checkAndInitWakeLock(context); boolean isWakefulIntent = isWakefulIntent(intent); setAsWakefulIntent(intent, true); if (!isWakefulIntent) { wakeLock.acquire(WAKE_LOCK_ACQUIRE_TIMEOUT_MILLIS); } withinAppServiceConnection.sendIntent(intent).addOnCompleteListener(new OnCompleteListener() { // from class: com.google.firebase.messaging.WakeLockHolder$$ExternalSyntheticLambda0 @Override // com.google.android.gms.tasks.OnCompleteListener public final void onComplete(Task task) { WakeLockHolder.completeWakefulIntent(intent); } }); } catch (Throwable th) { throw th; } } } public static void setAsWakefulIntent(Intent intent, boolean z) { intent.putExtra("com.google.firebase.iid.WakeLockHolder.wakefulintent", z); } public static boolean isWakefulIntent(Intent intent) { return intent.getBooleanExtra("com.google.firebase.iid.WakeLockHolder.wakefulintent", false); } public static void completeWakefulIntent(Intent intent) { synchronized (syncObject) { try { if (wakeLock != null && isWakefulIntent(intent)) { setAsWakefulIntent(intent, false); wakeLock.release(); } } catch (Throwable th) { throw th; } } } }