예제 #1
0
        private void DoStartForeground()
        {
            if (settingsManager.SystemPersistentNotification && (notification == null))
            {
                string text, server = "";
                Dictionary <string, string> pData = settingsManager.SystemLastProfileInfo;

                string channelId   = Resources.GetString(Resource.String.notification_channel_id);
                string channelName = Resources.GetString(Resource.String.notification_channel_name);

                if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                {
                    NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

                    NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, NotificationImportance.High);

                    notificationManager.CreateNotificationChannel(notificationChannel);
                }

                if (pData.Count > 0 && pData.ContainsKey("server"))
                {
                    server = pData["server"];
                }

                text = String.Format(Resources.GetString(Resource.String.notification_text), server);

                if (!NetworkStatusReceiver.GetNetworkDescription().Equals(""))
                {
                    text += " " + String.Format(Resources.GetString(Resource.String.notification_network), NetworkStatusReceiver.GetNetworkDescription());
                }

                notification = new NotificationCompat.Builder(this);

                notification.SetContentTitle(Resources.GetString(Resource.String.notification_title))
                .SetStyle(new NotificationCompat.BigTextStyle().BigText(text))
                .SetContentText(text)
                .SetSmallIcon(Resource.Drawable.notification_icon)
                .SetColor(Resource.Color.notificationColor)
                .SetContentIntent(BuildMainActivityIntent())
                .SetChannelId(channelId)
                .SetPriority(NotificationCompat.PriorityHigh)
                .SetOngoing(true);

                if (Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.O)
                {
                    if (settingsManager.SystemNotificationSound)
                    {
                        notification.SetSound(Settings.System.DefaultNotificationUri);
                    }
                    else
                    {
                        notification.SetSound(Android.Net.Uri.Parse("android.resource://" + ApplicationContext.PackageName + "/" + Resource.Raw.silence));
                    }
                }

                StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notification.Build());

                currentNotificationText = text;
            }
        }
예제 #2
0
        private void UpdateNotification(VPN.Status status)
        {
            string text, server = "";

            if (status != VPN.Status.CONNECTED && status != VPN.Status.PAUSED && status != VPN.Status.LOCKED)
            {
                return;
            }

            Dictionary <string, string> pData = settingsManager.SystemLastProfileInfo;

            if (pData.Count > 0 && pData.ContainsKey("server"))
            {
                server = pData["server"];
            }

            text = String.Format(vpnService.Resources.GetString(Resource.String.notification_text), server);

            if (!NetworkStatusReceiver.GetNetworkDescription().Equals(""))
            {
                text += " " + String.Format(vpnService.Resources.GetString(Resource.String.notification_network), NetworkStatusReceiver.GetNetworkDescription());
            }

            if (status == VPN.Status.PAUSED)
            {
                text += " (" + vpnService.Resources.GetString(Resource.String.vpn_status_paused) + ")";
            }

            if (status == VPN.Status.LOCKED)
            {
                text += " (" + vpnService.Resources.GetString(Resource.String.vpn_status_locked) + ")";
            }

            vpnService.UpdateNotification(text);
        }
예제 #3
0
        public void OnNetworkStatusConnected()
        {
            string text, server = "";
            Dictionary <string, string> pData = settingsManager.SystemLastProfileInfo;

            EddieLogger.Info("Network is connected to {0}", NetworkStatusReceiver.GetNetworkDescription());

            NetworkStatusChanged(OpenVPNTunnel.VPNAction.RESUME);

            if (pData.Count > 0 && pData.ContainsKey("server"))
            {
                server = pData["server"];
            }

            text = String.Format(Resources.GetString(Resource.String.notification_text), server);

            if (!NetworkStatusReceiver.GetNetworkDescription().Equals(""))
            {
                text += " " + String.Format(Resources.GetString(Resource.String.notification_network), NetworkStatusReceiver.GetNetworkDescription());
            }

            UpdateNotification(text);
        }
예제 #4
0
        public void OnNetworkStatusConnected()
        {
            if (txtNetworkStatus != null)
            {
                txtNetworkStatus.Text = string.Format(Resources.GetString(Resource.String.conn_status_connected), NetworkStatusReceiver.GetNetworkDescription());
            }

            if (btnConnectProfile != null)
            {
                btnConnectProfile.Enabled = (currentConnectionStatus == VPN.Status.NOT_CONNECTED) && NetworkStatusReceiver.IsNetworkConnected();
            }
        }
예제 #5
0
        private void UpdateConnectionStatus(bool ready, VPN.Status status, string error)
        {
            if (ready)
            {
                txtVpnStatus.Text = Resources.GetString(VPN.DescriptionResource(status));
            }
            else
            {
                txtVpnStatus.Text = Resources.GetString(Resource.String.conn_status_initialize);
            }

            btnConnectProfile.Enabled = ready && (status == VPN.Status.NOT_CONNECTED) && NetworkStatusReceiver.IsNetworkConnected();

            btnDisconnectProfile.Enabled = (status == VPN.Status.CONNECTING) || (status == VPN.Status.CONNECTED) || (status == VPN.Status.PAUSED) || (status == VPN.Status.LOCKED);

            if (currentConnectionStatus != status)
            {
                currentConnectionStatus = status;

                switch (status)
                {
                case VPN.Status.CONNECTED:
                {
                    if (profileInfo.ContainsKey("server") == true)
                    {
                        supportTools.InfoDialog(string.Format(Resources.GetString(Resource.String.connection_success), profileInfo["server"], NetworkStatusReceiver.GetNetworkDescription()));
                    }

                    settingsManager.SystemLastProfileIsConnected = true;
                }
                break;

                case VPN.Status.NOT_CONNECTED:
                {
                    if (profileInfo.ContainsKey("server") == true)
                    {
                        supportTools.InfoDialog(string.Format(Resources.GetString(Resource.String.connection_disconnected), profileInfo["server"]));
                    }

                    settingsManager.SystemLastProfileIsConnected = false;
                }
                break;

                case VPN.Status.PAUSED:
                {
                    supportTools.InfoDialog(Resources.GetString(Resource.String.connection_paused));

                    settingsManager.SystemLastProfileIsConnected = true;
                }
                break;

                default:
                {
                    settingsManager.SystemLastProfileIsConnected = false;
                }
                break;
                }
            }

            ShowErrorMessage(error);
        }
예제 #6
0
        public void OnNetworkTypeChanged()
        {
            EddieLogger.Info("Network type has changed to {0}", NetworkStatusReceiver.GetNetworkDescription());

            NetworkStatusChanged(OpenVPNTunnel.VPNAction.NETWORK_TYPE_CHANGED);
        }