+ telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE or PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED)
+ }
+ }
+
+ fun populateNotification() {
+ // Get the list of current notifications.
+ val activeNotificationsArray = notificationManager.activeNotifications
+
+ // Check to see if there is a current notification.
+ val noCurrentNotification = activeNotificationsArray.isEmpty()
+
+ // Populate the notification according to the security status.
+ if ((voiceNetworkSecurityStatus == ProtocolHelper.ANTIQUATED) || (dataNetworkSecurityStatus == ProtocolHelper.ANTIQUATED)) { // This is an antiquated network.
+ // Only update the notification if the network status has changed.
+ if ((currentStatus != ANTIQUATED_NETWORK) || noCurrentNotification) {
+ // Create an antiquated network notification builder.
+ val antiquatedNetworkNotificationBuilder = Notification.Builder(applicationContext, ANTIQUATED_NETWORK)
+
+ // Set the notification to open Privacy Cell.
+ antiquatedNetworkNotificationBuilder.setContentIntent(privacyCellPendingIntent)
+
+ // Set the notification text.
+ antiquatedNetworkNotificationBuilder.setContentText(getString(R.string.antiquated_network))
+
+ // Set the notification icon.
+ antiquatedNetworkNotificationBuilder.setSmallIcon(R.drawable.antiquated_notification_enabled)
+
+ // Set the color.
+ antiquatedNetworkNotificationBuilder.setColor(getColor(R.color.red_notification_icon))
+
+ // Prevent swiping to dismiss the notification. This no longer works (except on the lock screen) in API >= 34.
+ antiquatedNetworkNotificationBuilder.setOngoing(true)
+
+ // Update the notification.
+ notificationManager.notify(NOTIFICATION_ID, antiquatedNetworkNotificationBuilder.build())
+
+ // Store the new network status.
+ currentStatus = ANTIQUATED_NETWORK
+ }
+ } else if ((voiceNetworkSecurityStatus == ProtocolHelper.INSECURE) || (dataNetworkSecurityStatus == ProtocolHelper.INSECURE)) { // This is an insecure network.
+ // Only update the notification if the network status has changed.
+ if ((currentStatus != INSECURE_NETWORK) || noCurrentNotification) {
+ // Create an insecure network notification builder.
+ val insecureNetworkNotificationBuilder = Notification.Builder(applicationContext, INSECURE_NETWORK)
+
+ // Set the notification to open Privacy Cell.
+ insecureNetworkNotificationBuilder.setContentIntent(privacyCellPendingIntent)
+
+ // Set the notification text.
+ insecureNetworkNotificationBuilder.setContentText(getString(R.string.insecure_network))
+
+ // Set the notification icon.
+ insecureNetworkNotificationBuilder.setSmallIcon(R.drawable.insecure_notification_enabled)
+
+ // Set the color.
+ insecureNetworkNotificationBuilder.setColor(getColor(R.color.yellow_notification_icon))
+
+ // Prevent swiping to dismiss the notification. This no longer works (except on the lock screen) in API >= 34.
+ insecureNetworkNotificationBuilder.setOngoing(true)
+
+ // Update the notification.
+ notificationManager.notify(NOTIFICATION_ID, insecureNetworkNotificationBuilder.build())
+
+ // Store the new network status.
+ currentStatus = INSECURE_NETWORK
+ }
+ } else { // This is a secure network.
+ // Only update the notification if the network status has changed.
+ if ((currentStatus != SECURE_NETWORK) || noCurrentNotification) {
+ // Create a secure network notification builder.
+ val secureNetworkNotificationBuilder = Notification.Builder(applicationContext, SECURE_NETWORK)
+
+ // Set the notification to open Privacy Cell.
+ secureNetworkNotificationBuilder.setContentIntent(privacyCellPendingIntent)
+
+ // Set the notification text.
+ secureNetworkNotificationBuilder.setContentText(getString(R.string.secure_network))
+
+ // Set the notification icon.
+ secureNetworkNotificationBuilder.setSmallIcon(R.drawable.secure_notification_enabled)
+
+ // Set the color.
+ secureNetworkNotificationBuilder.setColor(getColor(R.color.blue_icon))
+
+ // Prevent swiping to dismiss the notification. This no longer works (except on the lock screen) in API >= 34.
+ secureNetworkNotificationBuilder.setOngoing(true)
+
+ // Update the notification.
+ notificationManager.notify(NOTIFICATION_ID, secureNetworkNotificationBuilder.build())
+
+ // Store the new network status.
+ currentStatus = SECURE_NETWORK
+ }