Exemplo n.º 1
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (_isStarted)
            {
                //DO NOT REMOVE
                //Helps to avoid multiple receivers registration on same event
                Log.Debug("AbnormalMonitorService", $"Received {intent.Action}, but monitoring already started!");
                return;
            }
            Log.Debug("AbnormalMonitorService", $"Received {intent.Action}");

            DataHolder.Initialize(context);

            ScreenUnlockReceiver.SetUnlockReceiverStatus(context,
                                                         enable: DataHolder.IsSelectedCategory(DataHolder.ScreenCategory));
            PhoneCallReceiver.SetCallReceiverStatus(context,
                                                    enable: DataHolder.IsSelectedCategory(DataHolder.PhoneCategory));
            SmsReceiver.SetSmsReceiverStatus(context,
                                             enable: DataHolder.IsSelectedCategory(DataHolder.SmsCategory));

            IntentFilter filter = new IntentFilter();

            filter.AddAction(LocationManager.ModeChangedAction);
            context.ApplicationContext.RegisterReceiver(new LocationModeChangeReceiver(), filter);

            SystemModListenerService.SetSystemMonitoringStatus(context,
                                                               enable: DataHolder.IsSelectedCategory(DataHolder.SystemCategory));

            AlarmReceiver.RegisterReceiver(context);

            LocationUtils.SetLocationTrackingEnabled(DataHolder.IsSelectedCategory(DataHolder.LocationCategory));

            _isStarted = true;
        }
Exemplo n.º 2
0
 public static void SetSmsReceiverStatus(Context context, bool enable)
 {
     if (enable && _smsReceiver == null)
     {
         var screenStateFilter = new IntentFilter();
         screenStateFilter.AddAction(Telephony.Sms.Intents.SmsReceivedAction);
         _smsReceiver = new SmsReceiver();
         context.ApplicationContext.RegisterReceiver(_smsReceiver, screenStateFilter);
     }
     else if (!enable && _smsReceiver != null)
     {
         context.ApplicationContext.UnregisterReceiver(_smsReceiver);
         _smsReceiver.UnregisterFromRuntime();
         _smsReceiver.Dispose();
         _smsReceiver = null;
     }
 }