Пример #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;
        }
Пример #2
0
 public static void SetCallReceiverStatus(Context context, bool enable)
 {
     if (enable && _callReceiver == null)
     {
         var screenStateFilter = new IntentFilter();
         screenStateFilter.AddAction(Intent.ActionNewOutgoingCall);
         screenStateFilter.AddAction(TelephonyManager.ActionPhoneStateChanged);
         _callReceiver = new PhoneCallReceiver();
         context.ApplicationContext.RegisterReceiver(_callReceiver, screenStateFilter);
     }
     else if (!enable && _callReceiver != null)
     {
         context.ApplicationContext.UnregisterReceiver(_callReceiver);
         _callReceiver.UnregisterFromRuntime();
         _callReceiver.Dispose();
         _callReceiver = null;
     }
 }