Skip to content

Commit 1d87506

Browse files
committed
add fullscreen permission setting
Goal is that the call notification screen is shown without to unlock the phone. I encountered the following behavior: USE_FULL_SCREEN_INTENT is granted when running via debug in Android Studio. It is not granted when building the app and running the apk. So the unlock screen is shown instead when a call comes in. However google play console has a setting to allow USE_FULL_SCREEN_INTENT by default for this app, as it is a call app. Hopefully this will work and USE_FULL_SCREEN_INTENT is granted when installed via Google Play. However even if this works it might still make sense for the generic build variant and for f-droid to include this setting (or find another solution). Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
1 parent 3e106b0 commit 1d87506

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package com.nextcloud.talk.conversationlist
88

99
import android.Manifest
1010
import android.annotation.SuppressLint
11+
import android.app.NotificationManager
1112
import android.content.ActivityNotFoundException
1213
import android.content.Intent
1314
import android.content.pm.PackageManager
@@ -900,6 +901,8 @@ class ConversationsListActivity : BaseActivity() {
900901
val notificationPermissionNotGranted = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
901902
!platformPermissionUtil.isPostNotificationsPermissionGranted()
902903
val batteryOptimizationNotIgnored = !PowerManagerUtils().isIgnoringBatteryOptimizations()
904+
val fullScreenIntentNotGranted = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE &&
905+
!getSystemService(NotificationManager::class.java).canUseFullScreenIntent()
903906

904907
val messagesChannelNotEnabled = !NotificationUtils.isMessagesNotificationChannelEnabled(this)
905908
val callsChannelNotEnabled = !NotificationUtils.isCallsNotificationChannelEnabled(this)
@@ -909,6 +912,7 @@ class ConversationsListActivity : BaseActivity() {
909912

910913
val settingsOfUserAreWrong = notificationPermissionNotGranted ||
911914
batteryOptimizationNotIgnored ||
915+
fullScreenIntentNotGranted ||
912916
messagesChannelNotEnabled ||
913917
callsChannelNotEnabled ||
914918
!serverNotificationAppInstalled

app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import android.animation.Animator
1515
import android.animation.AnimatorListenerAdapter
1616
import android.annotation.SuppressLint
1717
import android.app.KeyguardManager
18+
import android.app.NotificationManager
1819
import android.content.Context
1920
import android.content.DialogInterface
2021
import android.content.Intent
@@ -369,6 +370,36 @@ class SettingsActivity :
369370
}
370371
}
371372

373+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
374+
val notificationManager = getSystemService(NotificationManager::class.java)
375+
if (notificationManager.canUseFullScreenIntent()) {
376+
binding.fullScreenIntentPermissionSubtitle.text =
377+
resources.getString(R.string.full_screen_intent_permission_granted)
378+
binding.fullScreenIntentPermissionSubtitle.setTextColor(
379+
resources.getColor(R.color.high_emphasis_text, null)
380+
)
381+
} else {
382+
binding.fullScreenIntentPermissionSubtitle.text =
383+
resources.getString(R.string.full_screen_intent_permission_not_granted)
384+
binding.fullScreenIntentPermissionSubtitle.setTextColor(
385+
resources.getColor(R.color.nc_darkRed, null)
386+
)
387+
388+
if (openedByNotificationWarning) {
389+
DrawableUtils.blinkDrawable(binding.settingsFullScreenIntentWrapper.background)
390+
}
391+
392+
binding.settingsFullScreenIntentWrapper.setOnClickListener {
393+
val intent = Intent(Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT).apply {
394+
data = "package:$packageName".toUri()
395+
}
396+
startActivity(intent)
397+
}
398+
}
399+
} else {
400+
binding.settingsFullScreenIntentWrapper.visibility = View.GONE
401+
}
402+
372403
// handle notification permission on API level >= 33
373404
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
374405
if (platformPermissionUtil.isPostNotificationsPermissionGranted()) {
@@ -500,15 +531,24 @@ class SettingsActivity :
500531
)
501532
}
502533

534+
val canUseFullScreenIntent = Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE ||
535+
getSystemService(NotificationManager::class.java).canUseFullScreenIntent()
536+
503537
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
504538
if (platformPermissionUtil.isPostNotificationsPermissionGranted() &&
505539
PowerManagerUtils().isIgnoringBatteryOptimizations()
506540
) {
507541
binding.settingsNotificationsPermissionWrapper.setOnClickListener { click() }
508542
binding.settingsBatteryOptimizationWrapper.setOnClickListener { click() }
543+
if (canUseFullScreenIntent) {
544+
binding.settingsFullScreenIntentWrapper.setOnClickListener { click() }
545+
}
509546
}
510547
} else if (PowerManagerUtils().isIgnoringBatteryOptimizations()) {
511548
binding.settingsBatteryOptimizationWrapper.setOnClickListener { click() }
549+
if (canUseFullScreenIntent) {
550+
binding.settingsFullScreenIntentWrapper.setOnClickListener { click() }
551+
}
512552
}
513553
}
514554

app/src/main/res/layout/activity_settings.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,27 @@
310310
tools:text="@string/battery_optimization_ignored"/>
311311
</LinearLayout>
312312

313+
<LinearLayout
314+
android:id="@+id/settings_full_screen_intent_wrapper"
315+
android:layout_width="match_parent"
316+
android:layout_height="wrap_content"
317+
android:background="?android:attr/selectableItemBackground"
318+
android:orientation="vertical"
319+
android:padding="@dimen/standard_padding">
320+
321+
<com.google.android.material.textview.MaterialTextView
322+
android:layout_width="wrap_content"
323+
android:layout_height="wrap_content"
324+
android:text="@string/full_screen_intent_permission_title"
325+
android:textSize="@dimen/headline_text_size" />
326+
327+
<com.google.android.material.textview.MaterialTextView
328+
android:id="@+id/full_screen_intent_permission_subtitle"
329+
android:layout_width="wrap_content"
330+
android:layout_height="wrap_content"
331+
tools:text="@string/full_screen_intent_permission_granted" />
332+
</LinearLayout>
333+
313334
</LinearLayout>
314335

315336
<LinearLayout

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ How to translate with transifex:
121121
<string name="battery_optimization_not_ignored">Battery optimization is enabled which might cause issues. You should disable battery optimization!</string>
122122
<string name="battery_optimization_ignored">Battery optimization is ignored, all fine</string>
123123
<string name="notification_permission">Notification permissions</string>
124+
<string name="full_screen_intent_permission_title">Show incoming call screen</string>
125+
<string name="full_screen_intent_permission_granted">Incoming call screen over lock screen is granted, all fine</string>
126+
<string name="full_screen_intent_permission_not_granted">Incoming call screen over lock screen is not granted. Please grant this so incoming calls appear on the lock screen!</string>
124127

125128

126129
<string name="nc_settings_appearance">Appearance</string>

0 commit comments

Comments
 (0)