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; } }
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); }
public override void OnCreate() { base.OnCreate(); EddieLogger.Init(this); Init(); networkStatusReceiver = new NetworkStatusReceiver(); networkStatusReceiver.AddListener(this); this.RegisterReceiver(networkStatusReceiver, new IntentFilter(Android.Net.ConnectivityManager.ConnectivityAction)); }
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); }
public void OnNetworkTypeChanged() { if (txtNetworkStatus != null) { txtNetworkStatus.Text = Resources.GetString(Resource.String.conn_status_disconnected); } if (btnConnectProfile != null) { btnConnectProfile.Enabled = (currentConnectionStatus == VPN.Status.NOT_CONNECTED) && NetworkStatusReceiver.IsNetworkConnected(); } }
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(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.main_activity_layout); supportTools = new SupportTools(this); EddieLogger.Init(this); networkStatusReceiver = new NetworkStatusReceiver(); networkStatusReceiver.AddListener(this); this.RegisterReceiver(networkStatusReceiver, new IntentFilter(Android.Net.ConnectivityManager.ConnectivityAction)); toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); drawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close); drawer.AddDrawerListener(drawerToggle); drawerToggle.SyncState(); navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); navigationView.NavigationItemSelected += OnNavigationViewItemSelected; btnSelectProfile = FindViewById <Button>(Resource.Id.select_profile_btn); btnSelectProfile.Click += delegate { OnClickSelectProfileButton(); }; txtProfileFileName = FindViewById <TextView>(Resource.Id.profile_filename); txtProfileFileName.Text = Resources.GetString(Resource.String.conn_no_profile); llServerInfo = FindViewById <LinearLayout>(Resource.Id.server_info_layout); txtServerName = FindViewById <TextView>(Resource.Id.profile_server); txtServerName.Text = ""; txtServerPort = FindViewById <TextView>(Resource.Id.profile_port); txtServerPort.Text = ""; txtServerProtocol = FindViewById <TextView>(Resource.Id.profile_protocol); txtServerProtocol.Text = ""; btnConnectProfile = FindViewById <Button>(Resource.Id.connect_profile_btn); btnConnectProfile.Click += delegate { OnStartConnection(); }; btnDisconnectProfile = FindViewById <Button>(Resource.Id.disconnect_profile_btn); btnDisconnectProfile.Click += delegate { OnStopConnection(); }; txtVpnStatus = FindViewById <TextView>(Resource.Id.vpn_connection_status); txtVpnStatus.Text = Resources.GetString(Resource.String.conn_status_disconnected); txtNetworkStatus = FindViewById <TextView>(Resource.Id.network_connection_status); txtNetworkStatus.Text = Resources.GetString(Resource.String.conn_status_disconnected); llConnectionError = FindViewById <LinearLayout>(Resource.Id.connection_error_layout); txtConnectionError = FindViewById <TextView>(Resource.Id.connection_error); txtConnectionError.Text = ""; vpnManager = new VPNManager(this); vpnManager.StatusChanged += OnServiceStatusChanged; if (settingsManager.SystemRestoreLastProfile) { RestoreLastProfile(); } else { txtProfileFileName.Text = Resources.GetString(Resource.String.conn_no_profile); llServerInfo.Visibility = ViewStates.Gone; } }
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); }
public void OnNetworkTypeChanged() { EddieLogger.Info("Network type has changed to {0}", NetworkStatusReceiver.GetNetworkDescription()); NetworkStatusChanged(OpenVPNTunnel.VPNAction.NETWORK_TYPE_CHANGED); }