Beispiel #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;
        }
        public override void OnReceive(Context context, Intent intent)
        {
            var notificationManager = NotificationManager.FromContext(context);

            notificationManager.Cancel(intent.GetIntExtra(NotificationSender.ExtraNotificationId, 0));
            var category = intent.GetStringExtra(NotificationSender.ExtraNotificationCategory);

            switch (category)
            {
            case DataHolder.SystemCategory:
                DataHolder.NormalizeSystemData(
                    intent.GetStringExtra(SystemModListenerService.ExtraFilePath),
                    intent.GetStringExtra(SystemModListenerService.ExtraFileEvent));
                break;

            case DataHolder.ScreenLocksCategory:
                DataHolder.NormalizeScreenData(intent);
                break;

            case DataHolder.LocationCategory:
                DataHolder.NormalizeLocationData(intent);
                break;

            case DataHolder.PhoneCategory:
                DataHolder.NormalizePhoneData(intent);
                break;

            case DataHolder.SmsCategory:
                DataHolder.NormalizeSmsData(intent);
                break;

            case AlarmReceiver.SummaryCategory:
                try
                {
                    AlarmReceiver.ExportSummary(intent.GetStringExtra(AlarmReceiver.ExtraSummaryText));
                    Toast.MakeText(context, context.GetString(Resource.String.toast_export_successful),
                                   ToastLength.Short).Show();
                }
                catch (Exception e)
                {
                    Log.Error(nameof(AlarmReceiver.ExportSummary), e.StackTrace);
                    Log.Error(nameof(AlarmReceiver.ExportSummary), e.Message);
                    Toast.MakeText(context, context.GetString(Resource.String.toast_export_failed),
                                   ToastLength.Short).Show();
                }

                break;
            }

            MainActivity.Adapter?.Refresh();
        }