package androidx.work.impl.background.systemalarm; import android.content.Intent; import androidx.annotation.MainThread; import androidx.annotation.RestrictTo; import androidx.lifecycle.LifecycleService; import androidx.work.Logger; import androidx.work.impl.background.systemalarm.SystemAlarmDispatcher; import androidx.work.impl.utils.WakeLocks; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) /* loaded from: classes.dex */ public class SystemAlarmService extends LifecycleService implements SystemAlarmDispatcher.CommandsCompletedListener { private static final String TAG = Logger.tagWithPrefix("SystemAlarmService"); private SystemAlarmDispatcher mDispatcher; private boolean mIsShutdown; @Override // androidx.lifecycle.LifecycleService, android.app.Service public void onCreate() { super.onCreate(); initializeDispatcher(); this.mIsShutdown = false; } @Override // androidx.lifecycle.LifecycleService, android.app.Service public void onDestroy() { super.onDestroy(); this.mIsShutdown = true; this.mDispatcher.onDestroy(); } @Override // androidx.lifecycle.LifecycleService, android.app.Service public int onStartCommand(Intent intent, int i, int i2) { super.onStartCommand(intent, i, i2); if (this.mIsShutdown) { Logger.get().info(TAG, "Re-initializing SystemAlarmDispatcher after a request to shut-down."); this.mDispatcher.onDestroy(); initializeDispatcher(); this.mIsShutdown = false; } if (intent == null) { return 3; } this.mDispatcher.add(intent, i2); return 3; } @Override // androidx.work.impl.background.systemalarm.SystemAlarmDispatcher.CommandsCompletedListener @MainThread public void onAllCommandsCompleted() { this.mIsShutdown = true; Logger.get().debug(TAG, "All commands completed in dispatcher"); WakeLocks.checkWakeLocks(); stopSelf(); } @MainThread private void initializeDispatcher() { SystemAlarmDispatcher systemAlarmDispatcher = new SystemAlarmDispatcher(this); this.mDispatcher = systemAlarmDispatcher; systemAlarmDispatcher.setCompletedListener(this); } }