Added configuration setting to make app invisible except for launcher & foreground service notification

This commit is contained in:
Sylvain Berfini 2021-02-24 11:57:59 +01:00
parent 5a40bb7c36
commit 0f55be3a1b
4 changed files with 70 additions and 16 deletions

View file

@ -43,6 +43,13 @@ class LauncherActivity : GenericActivity() {
private fun onReady() { private fun onReady() {
Log.i("[Launcher] Core is ready") Log.i("[Launcher] Core is ready")
if (corePreferences.preventInterfaceFromShowingUp) {
Log.w("[Context] We were asked to not show the user interface")
finish()
return
}
val intent = Intent() val intent = Intent()
intent.setClass(this, MainActivity::class.java) intent.setClass(this, MainActivity::class.java)

View file

@ -523,6 +523,11 @@ class CoreContext(val context: Context, coreConfig: Config) {
/* Start call related activities */ /* Start call related activities */
private fun onIncomingReceived() { private fun onIncomingReceived() {
if (corePreferences.preventInterfaceFromShowingUp) {
Log.w("[Context] We were asked to not show the incoming call screen")
return
}
Log.i("[Context] Starting IncomingCallActivity") Log.i("[Context] Starting IncomingCallActivity")
val intent = Intent(context, IncomingCallActivity::class.java) val intent = Intent(context, IncomingCallActivity::class.java)
// This flag is required to start an Activity from a Service context // This flag is required to start an Activity from a Service context
@ -531,6 +536,11 @@ class CoreContext(val context: Context, coreConfig: Config) {
} }
private fun onOutgoingStarted() { private fun onOutgoingStarted() {
if (corePreferences.preventInterfaceFromShowingUp) {
Log.w("[Context] We were asked to not show the outgoing call screen")
return
}
Log.i("[Context] Starting OutgoingCallActivity") Log.i("[Context] Starting OutgoingCallActivity")
val intent = Intent(context, OutgoingCallActivity::class.java) val intent = Intent(context, OutgoingCallActivity::class.java)
// This flag is required to start an Activity from a Service context // This flag is required to start an Activity from a Service context
@ -539,6 +549,11 @@ class CoreContext(val context: Context, coreConfig: Config) {
} }
private fun onCallStarted() { private fun onCallStarted() {
if (corePreferences.preventInterfaceFromShowingUp) {
Log.w("[Context] We were asked to not show the call screen")
return
}
Log.i("[Context] Starting CallActivity") Log.i("[Context] Starting CallActivity")
val intent = Intent(context, CallActivity::class.java) val intent = Intent(context, CallActivity::class.java)
// This flag is required to start an Activity from a Service context // This flag is required to start an Activity from a Service context

View file

@ -316,9 +316,6 @@ class CorePreferences constructor(private val context: Context) {
val checkUpdateAvailableInterval: Int val checkUpdateAvailableInterval: Int
get() = config.getInt("app", "version_check_interval", 86400000) get() = config.getInt("app", "version_check_interval", 86400000)
val showIncomingChatMessagesDeliveryStatus: Boolean
get() = config.getBool("app", "show_incoming_messages_delivery_status", false)
// If enabled, this will cause the video to "freeze" on your correspondent screen // If enabled, this will cause the video to "freeze" on your correspondent screen
// as you won't send video packets anymore // as you won't send video packets anymore
val hideCameraPreviewInPipMode: Boolean val hideCameraPreviewInPipMode: Boolean
@ -334,6 +331,10 @@ class CorePreferences constructor(private val context: Context) {
val showScreenshotButton: Boolean val showScreenshotButton: Boolean
get() = config.getBool("app", "show_take_screenshot_button_in_call", false) get() = config.getBool("app", "show_take_screenshot_button_in_call", false)
// This will prevent UI from showing up, except for the launcher & the foreground service notification
val preventInterfaceFromShowingUp: Boolean
get() = config.getBool("app", "keep_app_invisible", false)
/* Assistant */ /* Assistant */
val showCreateAccount: Boolean val showCreateAccount: Boolean

View file

@ -111,6 +111,11 @@ class NotificationsManager(private val context: Context) {
) { ) {
Log.i("[Notifications Manager] Call state changed [$state]") Log.i("[Notifications Manager] Call state changed [$state]")
if (corePreferences.preventInterfaceFromShowingUp) {
Log.w("[Context] We were asked to not show the call notifications")
return
}
when (state) { when (state) {
Call.State.IncomingEarlyMedia, Call.State.IncomingReceived -> displayIncomingCallNotification(call) Call.State.IncomingEarlyMedia, Call.State.IncomingReceived -> displayIncomingCallNotification(call)
Call.State.End, Call.State.Error -> dismissCallNotification(call) Call.State.End, Call.State.Error -> dismissCallNotification(call)
@ -126,6 +131,11 @@ class NotificationsManager(private val context: Context) {
override fun onMessageReceived(core: Core, room: ChatRoom, message: ChatMessage) { override fun onMessageReceived(core: Core, room: ChatRoom, message: ChatMessage) {
if (message.isOutgoing || corePreferences.disableChat) return if (message.isOutgoing || corePreferences.disableChat) return
if (corePreferences.preventInterfaceFromShowingUp) {
Log.w("[Context] We were asked to not show the chat notifications")
return
}
if (currentlyDisplayedChatRoomAddress == room.peerAddress.asStringUriOnly()) { if (currentlyDisplayedChatRoomAddress == room.peerAddress.asStringUriOnly()) {
Log.i("[Notifications Manager] Chat room is currently displayed, do not notify received message") Log.i("[Notifications Manager] Chat room is currently displayed, do not notify received message")
return return
@ -324,18 +334,22 @@ class NotificationsManager(private val context: Context) {
.setDestination(R.id.dialerFragment) .setDestination(R.id.dialerFragment)
.createPendingIntent() .createPendingIntent()
serviceNotification = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_service_id)) val builder = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_service_id))
.setContentTitle(context.getString(R.string.service_name)) .setContentTitle(context.getString(R.string.service_name))
.setContentText(if (useAutoStartDescription) context.getString(R.string.service_auto_start_description) else context.getString(R.string.service_description)) .setContentText(if (useAutoStartDescription) context.getString(R.string.service_auto_start_description) else context.getString(R.string.service_description))
.setSmallIcon(R.drawable.topbar_service_notification) .setSmallIcon(R.drawable.topbar_service_notification)
.setContentIntent(pendingIntent)
.setCategory(NotificationCompat.CATEGORY_SERVICE) .setCategory(NotificationCompat.CATEGORY_SERVICE)
.setVisibility(NotificationCompat.VISIBILITY_SECRET) .setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setWhen(System.currentTimeMillis()) .setWhen(System.currentTimeMillis())
.setShowWhen(true) .setShowWhen(true)
.setOngoing(true) .setOngoing(true)
.setColor(ContextCompat.getColor(context, R.color.primary_color)) .setColor(ContextCompat.getColor(context, R.color.primary_color))
.build()
if (!corePreferences.preventInterfaceFromShowingUp) {
builder.setContentIntent(pendingIntent)
}
serviceNotification = builder.build()
} }
/* Call related */ /* Call related */
@ -378,12 +392,11 @@ class NotificationsManager(private val context: Context) {
notificationLayoutHeadsUp.setImageViewBitmap(R.id.caller_picture, roundPicture) notificationLayoutHeadsUp.setImageViewBitmap(R.id.caller_picture, roundPicture)
} }
val notification = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_incoming_call_id)) val builder = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_incoming_call_id))
.setStyle(NotificationCompat.DecoratedCustomViewStyle()) .setStyle(NotificationCompat.DecoratedCustomViewStyle())
.setSmallIcon(R.drawable.topbar_call_notification) .setSmallIcon(R.drawable.topbar_call_notification)
.setContentTitle(displayName) .setContentTitle(displayName)
.setContentText(context.getString(R.string.incoming_call_notification_title)) .setContentText(context.getString(R.string.incoming_call_notification_title))
.setContentIntent(pendingIntent)
.setCategory(NotificationCompat.CATEGORY_CALL) .setCategory(NotificationCompat.CATEGORY_CALL)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)
@ -396,7 +409,12 @@ class NotificationsManager(private val context: Context) {
.addAction(getCallDeclineAction(notifiable.notificationId)) .addAction(getCallDeclineAction(notifiable.notificationId))
.addAction(getCallAnswerAction(notifiable.notificationId)) .addAction(getCallAnswerAction(notifiable.notificationId))
.setCustomHeadsUpContentView(notificationLayoutHeadsUp) .setCustomHeadsUpContentView(notificationLayoutHeadsUp)
.build()
if (!corePreferences.preventInterfaceFromShowingUp) {
builder.setContentIntent(pendingIntent)
}
val notification = builder.build()
Log.i("[Notifications Manager] Notifying incoming call notification") Log.i("[Notifications Manager] Notifying incoming call notification")
notify(notifiable.notificationId, notification) notify(notifiable.notificationId, notification)
@ -427,20 +445,25 @@ class NotificationsManager(private val context: Context) {
.setDestination(R.id.masterCallLogsFragment) .setDestination(R.id.masterCallLogsFragment)
.createPendingIntent() .createPendingIntent()
val notification = NotificationCompat.Builder( val builder = NotificationCompat.Builder(
context, context.getString(R.string.notification_channel_missed_call_id)) context, context.getString(R.string.notification_channel_missed_call_id))
.setContentTitle(context.getString(R.string.missed_call_notification_title)) .setContentTitle(context.getString(R.string.missed_call_notification_title))
.setContentText(body) .setContentText(body)
.setSmallIcon(R.drawable.topbar_missed_call_notification) .setSmallIcon(R.drawable.topbar_missed_call_notification)
.setAutoCancel(true) .setAutoCancel(true)
.setContentIntent(pendingIntent)
// .setCategory(NotificationCompat.CATEGORY_EVENT) No one really matches "missed call" // .setCategory(NotificationCompat.CATEGORY_EVENT) No one really matches "missed call"
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.setWhen(System.currentTimeMillis()) .setWhen(System.currentTimeMillis())
.setShowWhen(true) .setShowWhen(true)
.setNumber(missedCallCount) .setNumber(missedCallCount)
.setColor(ContextCompat.getColor(context, R.color.notification_led_color)) .setColor(ContextCompat.getColor(context, R.color.notification_led_color))
.build()
if (!corePreferences.preventInterfaceFromShowingUp) {
builder.setContentIntent(pendingIntent)
}
val notification = builder.build()
notify(MISSED_CALLS_NOTIF_ID, notification) notify(MISSED_CALLS_NOTIF_ID, notification)
} }
@ -489,14 +512,13 @@ class NotificationsManager(private val context: Context) {
callNotificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) callNotificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val pendingIntent = PendingIntent.getActivity(context, 0, callNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent = PendingIntent.getActivity(context, 0, callNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val notification = NotificationCompat.Builder( val builder = NotificationCompat.Builder(
context, context.getString(R.string.notification_channel_service_id)) context, context.getString(R.string.notification_channel_service_id))
.setContentTitle(contact?.fullName ?: displayName) .setContentTitle(contact?.fullName ?: displayName)
.setContentText(context.getString(stringResourceId)) .setContentText(context.getString(stringResourceId))
.setSmallIcon(iconResourceId) .setSmallIcon(iconResourceId)
.setLargeIcon(roundPicture) .setLargeIcon(roundPicture)
.setAutoCancel(false) .setAutoCancel(false)
.setContentIntent(pendingIntent)
.setCategory(NotificationCompat.CATEGORY_CALL) .setCategory(NotificationCompat.CATEGORY_CALL)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_LOW) .setPriority(NotificationCompat.PRIORITY_LOW)
@ -505,7 +527,13 @@ class NotificationsManager(private val context: Context) {
.setOngoing(true) .setOngoing(true)
.setColor(ContextCompat.getColor(context, R.color.notification_led_color)) .setColor(ContextCompat.getColor(context, R.color.notification_led_color))
.addAction(getCallDeclineAction(notifiable.notificationId)) .addAction(getCallDeclineAction(notifiable.notificationId))
.build()
if (!corePreferences.preventInterfaceFromShowingUp) {
builder.setContentIntent(pendingIntent)
}
val notification = builder.build()
notify(notifiable.notificationId, notification) notify(notifiable.notificationId, notification)
if (useAsForeground) { if (useAsForeground) {
@ -692,7 +720,6 @@ class NotificationsManager(private val context: Context) {
val notificationBuilder = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_chat_id)) val notificationBuilder = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_chat_id))
.setSmallIcon(R.drawable.topbar_chat_notification) .setSmallIcon(R.drawable.topbar_chat_notification)
.setAutoCancel(true) .setAutoCancel(true)
.setContentIntent(pendingIntent)
.setLargeIcon(largeIcon) .setLargeIcon(largeIcon)
.setCategory(NotificationCompat.CATEGORY_MESSAGE) .setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setGroup(CHAT_NOTIFICATIONS_GROUP) .setGroup(CHAT_NOTIFICATIONS_GROUP)
@ -707,6 +734,10 @@ class NotificationsManager(private val context: Context) {
.setShortcutId(id) .setShortcutId(id)
.setLocusId(LocusIdCompat(id)) .setLocusId(LocusIdCompat(id))
if (!corePreferences.preventInterfaceFromShowingUp) {
notificationBuilder.setContentIntent(pendingIntent)
}
if (corePreferences.markAsReadUponChatMessageNotificationDismissal) { if (corePreferences.markAsReadUponChatMessageNotificationDismissal) {
Log.i("[Notifications Manager] Chat room will be marked as read when notification will be dismissed") Log.i("[Notifications Manager] Chat room will be marked as read when notification will be dismissed")
notificationBuilder notificationBuilder