Example #1
0
        protected override Task StopAsyncInternal(CancellationToken cancellationToken)
        {
            Logger.Information("Deactivate()", nameof(DroidPowerManager));

            ServiceState = ServiceState.Termination;
            _wakelock?.Release();
            _wakelock = null;

            if (_powerModeReceiver != null)
            {
                Singleton.GetService <ICurrentContext>().Context.UnregisterReceiver(_powerModeReceiver);
                _powerModeReceiver = null;
            }

            ServiceState = ServiceState.Stoped;
            return(Task.CompletedTask);
        }
Example #2
0
        protected override Task StartAsyncInternal(CancellationToken cancellationToken)
        {
            Logger.Information("Activate()", nameof(DroidPowerManager));

            ServiceState = ServiceState.Initiation;
            _wakelock    = PowerManager.NewWakeLock(WakeLockFlags.Partial, "emergencyButton::servicewakelock");
            _wakelock.SetReferenceCounted(false);

            if (_powerModeReceiver == null)
            {
                Singleton.GetService <ICurrentContext>().Context.RegisterReceiver(
                    _powerModeReceiver = new PowerModeReceiver(),
                    new IntentFilter(PowerManager.ActionPowerSaveModeChanged));
            }

            ServiceState = ServiceState.Active;

            return(Task.CompletedTask);
        }