public void StopFlow()
 {
     if (AndroidBridge.isForegroundServiceUp())
     {
         AndroidBridge.StopForgroundService();
     }
     else
     {
         AndroidBridge.ToastIt("Service already stopped");
     }
 }
        private async void BtnSet_Clicked(object sender, EventArgs e)
        {
            await FilterUtils.TimeLock.onlyUnlockedAsync(async() =>
            {
                DateTime PickedDate;
                PickedDate = datePicker1.Date;
                PickedDate = PickedDate.Add(timePicker1.Time - PickedDate.TimeOfDay);

                string result = FilterUtils.TimeLock.TrySetLockDate(PickedDate);
                AndroidBridge.ToastIt(result);

                await Application.Current.MainPage.Navigation.PopAsync();
            });
        }
示例#3
0
 public static async Task onlyUnlockedAsync(Func <Task> callback)
 {
     try
     {
         var isLocked = TimeLock.isLocked();
         if (isLocked)
         {
             AndroidBridge.ToastIt(isLocked.eventReason);
         }
         else
         {
             await callback();
         }
     }
     catch (Exception ex)
     {
         AndroidBridge.e(TAG, ex);
     }
 }
        public void StartFlow()
        {
            try
            {
                // Reload policies:
                FilteringObjects.httpPolicy.reloadPolicy(File.ReadAllText(Filenames.HTTP_POLICY.getAppPrivate()));
                FilteringObjects.timePolicy.reloadPolicy(File.ReadAllText(Filenames.TIME_POLICY.getAppPrivate()));

                if (!AndroidBridge.isForegroundServiceUp())
                {
                    AndroidBridge.OnForgroundServiceStart = () =>
                    {
                        AndroidBridge.d(TAG, "Starting filtering flow");
                        myHTTPServer.StartHttpServer();
                        StartPeriodicTasks();
                    };

                    AndroidBridge.OnForgroundServiceStop = () =>
                    {
                        AndroidBridge.d(TAG, "Stopping filtering flow");
                        StopPeriodicTasks();
                        myHTTPServer.StopHTTPServer();
                    };

                    AndroidBridge.StartForgroundService();
                }
                else
                {
                    AndroidBridge.ToastIt("Service already up!");
                }
            }
            catch (Exception ex)
            {
                AndroidBridge.e(TAG, ex);
            }
        }
        public static void WifiCheckerCallback(List <string> wifiLists, TimeSpan?timeSinceLastScan, Exception callbackEx)
        {
            string reason         = "init";
            bool   shouldLogDebug = false;

            if (callbackEx != null)
            {
                // Dont even check, bad zone:
                FilteringObjects.isInWifiBlockZone = true;

                reason         = "callback with exepction.";
                shouldLogDebug = true;
            }
            else
            {
                TimeSpan actualTime = (timeSinceLastScan ?? TimeSpan.FromDays(1));
                if (actualTime > FilteringServiceFlow.WIFI_PERIOD_BLOCKED)
                {
                    // Dont even check, bad zone:
                    FilteringObjects.isInWifiBlockZone = true;

                    reason         = "results are old, wifi off? (Time: " + actualTime + ")";
                    shouldLogDebug = true;
                }
                else
                {
                    bool inBadZoneResult = true;
                    try
                    {
                        if (!File.Exists(Filenames.WIFI_POLICY.getAppPrivate()))
                        {
                            File.WriteAllText(Filenames.WIFI_POLICY.getAppPrivate(), "");
                        }

                        IEnumerable <string> currentRules = File.ReadAllLines(Filenames.WIFI_POLICY.getAppPrivate());
                        List <string>        newRules     = new List <string>();

                        //TODO Reason what wifi blocked.

                        inBadZoneResult = CheckBlacklistedWifiStandard.WifiHelper.fastBlockZoneCheck(wifiLists, currentRules, out newRules,
                                                                                                     (log) => { /* AndroidBridge.d(TAG, "[CheckBlacklistedWifi] " + log);*/ }, out reason
                                                                                                     );

                        File.WriteAllLines(Filenames.WIFI_POLICY.getAppPrivate(), newRules);
                    }
                    catch (Exception ex2)
                    {
                        AndroidBridge.e(TAG, ex2);
                        inBadZoneResult = false; // allow in case of exceptions...

                        reason = "Exception processing Wifi Algo";
                    }

                    if (!showReason && FilteringObjects.isInWifiBlockZone != inBadZoneResult)
                    {
                        AndroidBridge.ToastIt("Changing blackzone to: " + inBadZoneResult);
                    }

                    FilteringObjects.isInWifiBlockZone = inBadZoneResult;
                }
            }

            reason = "[Blockzone? " + FilteringObjects.isInWifiBlockZone + "] " + reason;

            if (showReason)
            {
                AndroidBridge.ToastIt(reason);
                showReason = false; // Reset it until user mark it again.
            }

            if (shouldLogDebug)
            {
                if (callbackEx != null)
                {
                    reason += "\nCallback Exception:\n" + callbackEx.ToString();
                }
                AndroidBridge.d(TAG, reason);
            }
        }