public AndroidPowerConnectionChangeListener()
        {
            AndroidPowerConnectionChangeBroadcastReceiver.POWER_CONNECTION_CHANGED += async(sender, connected) =>
            {
                try
                {
                    bool listenOnACPower = SensusServiceHelper.Get().GetRunningProtocols().SelectMany(x => x.Probes.OfType <ListeningProbe>()).Any(x => x.KeepDeviceAwakeOnAcPower);

                    if (connected && listenOnACPower)
                    {
                        await SensusServiceHelper.Get().KeepDeviceAwakeAsync();
                    }
                    else
                    {
                        await SensusServiceHelper.Get().LetDeviceSleepAsync();
                    }

                    PowerConnectionChanged?.Invoke(sender, connected);
                }
                catch (Exception ex)
                {
                    SensusException.Report("Failed to process power connection change.", ex);
                }
            };
        }
Exemple #2
0
 public AndroidPowerConnectionChangeListener()
 {
     AndroidPowerConnectionChangeBroadcastReceiver.POWER_CONNECTION_CHANGED += (sender, connected) =>
     {
         try
         {
             PowerConnectionChanged?.Invoke(sender, connected);
         }
         catch (Exception ex)
         {
             SensusException.Report("Failed to process power connection change.", ex);
         }
     };
 }
Exemple #3
0
        private void CheckPowerConnectionChanged(UArmEventMessage message)
        {
            int powerState;

            if (message.Id == Protocol.EventIdPowerConnection &&
                message.Args.Length > 0 &&
                int.TryParse(message.Args[0].Substring(1), out powerState)
                )
            {
                PowerConnectionChanged?.Invoke(
                    this,
                    new PowerConnectionChangedEventArgs(powerState != 0)
                    );
            }
        }
 public iOSPowerConnectionChangeListener()
 {
     UIDevice.Notifications.ObserveBatteryStateDidChange((sender, e) =>
     {
         try
         {
             UIDeviceBatteryState batteryState = UIDevice.CurrentDevice.BatteryState;
             bool connected = batteryState == UIDeviceBatteryState.Charging || batteryState == UIDeviceBatteryState.Full;
             PowerConnectionChanged?.Invoke(this, connected);
         }
         catch (Exception ex)
         {
             SensusException.Report("Failed to process power connection change.", ex);
         }
     });
 }