Ejemplo n.º 1
0
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            if (!AlreadyStarted)
            {
                AlreadyStarted = true;
                SingletonPreparator.Initialize();
                MainApplication.InitializeUnhandledExceptionsHandler();
                Log = Singleton.Resolve <ILogger>();

                _manager                         = new ScenariosManager();
                _messenger                       = new Messenger(_inHandler);
                _inHandler.HasCome              += InHandler_HasCome;
                _manager.ConnectionLost         += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionLost));
                _manager.ConnectionRestored     += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionRestored));
                _manager.LoginOrPasswordInvalid += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.CredentialsInvalid));
                _manager.NeedClientSettings     += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.NeedClientSettings));
                _manager.NeedRefresh            += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.NeedRefresh));
                _manager.ScenariosChanged       += (scenarios) => Handle((messenger) => Utils.RaiseEvent(scenarios, messenger, _messenger, ServiceOperation.ScenariosChanged));
                _manager.SecretCodeInvalid      += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.SecretCodeInvalid));
                _manager.ConnectionError        += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionError));
                _manager.Initialize(null);

                RegisterReceiver(new ScreenOnReciever(), new IntentFilter(Intent.ActionScreenOn));

                var manager            = (AlarmManager)GetSystemService(AlarmService);
                var triggerAtTime      = SystemClock.ElapsedRealtime() + (10 * 60 * 1000);
                var onAndroidAvailable = new Intent(this, typeof(BackgroundReceiver));
                var startServiceIntent = PendingIntent.GetBroadcast(this, 0, onAndroidAvailable, 0);
                if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
                {
                    manager.Cancel(startServiceIntent);
                    manager.SetAndAllowWhileIdle(AlarmType.ElapsedRealtimeWakeup, triggerAtTime, startServiceIntent);
                }
                else if (Build.VERSION.SdkInt == BuildVersionCodes.Kitkat || Build.VERSION.SdkInt == BuildVersionCodes.Lollipop)
                {
                    manager.Cancel(startServiceIntent);
                    manager.SetExact(AlarmType.ElapsedRealtimeWakeup, triggerAtTime, startServiceIntent);
                }

                ReInitTimer();

                var activityIntent = new Intent(this, typeof(MainActivity));

                var showActivityIntent = PendingIntent.GetActivity(Application.Context, 0,
                                                                   activityIntent, PendingIntentFlags.UpdateCurrent);

                _currentNotification =
                    new Notification.Builder(this).
                    SetContentTitle("Lazurite работает...").
                    SetSmallIcon(Resource.Drawable.icon).
                    SetContentIntent(showActivityIntent).
                    SetVisibility(NotificationVisibility.Private).
                    SetColor(Color.Argb(0, 255, 255, 255).ToArgb()).
                    SetOnlyAlertOnce(true).
                    Build();

                StartForeground(1, _currentNotification);
            }
            return(StartCommandResult.Sticky);
        }
Ejemplo n.º 2
0
 public override void OnCreate()
 {
     base.OnCreate();
     SingletonPreparator.Initialize();
     Log = Singleton.Resolve <ILogger>();
     InitializeUnhandledExceptionsHandler();
     RegisterActivityLifecycleCallbacks(this);
     //A great place to initialize Xamarin.Insights and Dependency Services!
 }
Ejemplo n.º 3
0
        public override void OnCreate()
        {
            base.OnCreate();

            AlreadyStarted = false;

            Current = this;

            SafeUnregisterReceiver(ScreenOnReciever);
            SafeUnregisterReceiver(StartLazuriteServiceReceiver);
            SafeUnregisterReceiver(GpsOnReciever);
            RegisterReceiver(ScreenOnReciever             = new ScreenOnReciever(), new IntentFilter(Intent.ActionScreenOn));
            RegisterReceiver(StartLazuriteServiceReceiver = new StartLazuriteServiceReceiver(), new IntentFilter(Intent.ActionBootCompleted));
            RegisterReceiver(GpsOnReciever = new GpsOnReciever(), new IntentFilter("android.location.GPS_ENABLED_CHANGE"));

            SingletonPreparator.Initialize();
            MainApplication.InitializeUnhandledExceptionsHandler();
            Log = Singleton.Resolve <ILogger>();

            _manager = new ClientManager();

            if (_manager.ListenerSettings.UseCPUInBackground)
            {
                InitWakeLock();
            }

            _messenger          = new Messenger(_inHandler);
            _inHandler.HasCome += InHandler_HasCome;

            _manager.ConnectionLost         += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionLost));
            _manager.ConnectionRestored     += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionRestored), TimerAction.Start);
            _manager.LoginOrPasswordInvalid += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.CredentialsInvalid), TimerAction.Stop);
            _manager.BruteforceSuspition    += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.BruteforceSuspition), TimerAction.Stop);
            _manager.NeedClientSettings     += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.NeedClientSettings));
            _manager.NeedRefresh            += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.NeedRefresh));
            _manager.ScenariosChanged       += (scenarios) => Handle((messenger) => Utils.RaiseEvent(scenarios, messenger, _messenger, ServiceOperation.ScenariosChanged));
            _manager.SecretCodeInvalid      += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.SecretCodeInvalid));
            _manager.ConnectionError        += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionError));
            _manager.Initialize(null);
        }