From 652069d520869f655245c5cf1894b7de52410cfc Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 6 Oct 2022 18:00:33 +0200 Subject: [PATCH] Manage new Android 13 notification permission. --- .../src/main/res/values/strings.xml | 4 ++ tools/adb/notification.sh | 25 +++++++ .../features/debug/DebugPermissionActivity.kt | 19 ++++- .../res/layout/activity_debug_permission.xml | 24 +++---- .../troubleshoot/TestAutoStartBoot.kt | 6 +- .../TestBackgroundRestrictions.kt | 4 +- .../troubleshoot/TestBatteryOptimization.kt | 6 +- .../troubleshoot/TestFirebaseToken.kt | 6 +- .../settings/troubleshoot/TestPlayServices.kt | 4 +- .../troubleshoot/TestTokenRegistration.kt | 8 +-- vector/src/main/AndroidManifest.xml | 3 + .../vector/app/features/home/HomeActivity.kt | 11 +++ .../features/home/HomeActivityViewEvents.kt | 1 + .../features/home/HomeActivityViewModel.kt | 4 ++ .../home/NotificationPermissionManager.kt | 71 +++++++++++++++++++ ...rSettingsNotificationPreferenceFragment.kt | 21 ++++++ ...ttingsNotificationsTroubleshootFragment.kt | 17 ++++- .../NotificationTroubleshootTestManager.kt | 12 ++-- .../troubleshoot/TestAccountSettings.kt | 6 +- .../TestAvailableUnifiedPushDistributors.kt | 4 +- .../TestCurrentUnifiedPushDistributor.kt | 4 +- .../troubleshoot/TestDeviceSettings.kt | 6 +- .../TestEndpointAsTokenRegistration.kt | 8 +-- .../settings/troubleshoot/TestNotification.kt | 6 +- .../troubleshoot/TestPushFromPushGateway.kt | 4 +- .../troubleshoot/TestPushRulesSettings.kt | 4 +- .../troubleshoot/TestSystemSettings.kt | 30 +++++--- .../troubleshoot/TestUnifiedPushEndpoint.kt | 4 +- .../troubleshoot/TestUnifiedPushGateway.kt | 4 +- .../settings/troubleshoot/TroubleshootTest.kt | 7 +- 30 files changed, 241 insertions(+), 92 deletions(-) create mode 100755 tools/adb/notification.sh create mode 100644 vector/src/main/java/im/vector/app/features/home/NotificationPermissionManager.kt diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 71ccf5b234..ef71c10dd5 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -635,6 +635,8 @@ ${app_name} needs permission to access your microphone to perform audio calls. ${app_name} needs permission to access your camera and your microphone to perform video calls.\n\nPlease allow access on the next pop-ups to be able to make the call. + + ${app_name} needs permission to display notifications. Notifications can display your messages, your invitations, etc.\n\nPlease allow access on the next pop-ups to be able to view notification. To scan a QR code, you need to allow camera access. Allow permission to access your contacts. @@ -854,7 +856,9 @@ System Settings. Notifications are enabled in the system settings. Notifications are disabled in the system settings.\nPlease check system settings. + ${app_name} needs the permission to show notifications.\nPlease grant the permission. Open Settings + Grant Permission Account Settings. Notifications are enabled for your account. diff --git a/tools/adb/notification.sh b/tools/adb/notification.sh new file mode 100755 index 0000000000..3c3c76c787 --- /dev/null +++ b/tools/adb/notification.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +## From https://developer.android.com/develop/ui/views/notifications/notification-permission#test + +PACKAGE_NAME=im.vector.app.debug + +# App is newly installed on a device that runs Android 13 or higher: + +adb shell pm revoke ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS +adb shell pm clear-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-set +adb shell pm clear-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-fixed + +# The user keeps notifications enabled when the app is installed on a device that runs 12L or lower, +# then the device upgrades to Android 13 or higher: + +# adb shell pm grant ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS +# adb shell pm set-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-set +# adb shell pm clear-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-fixed + +# The user manually disables notifications when the app is installed on a device that runs 12L or lower, +# then the device upgrades to Android 13 or higher: + +# adb shell pm revoke ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS +# adb shell pm set-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-set +# adb shell pm clear-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-fixed diff --git a/vector-app/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt b/vector-app/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt index a9be5512e4..2b1b66e672 100644 --- a/vector-app/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt +++ b/vector-app/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt @@ -22,6 +22,7 @@ import android.os.Build import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat +import androidx.core.view.isVisible import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.utils.checkPermissions @@ -46,7 +47,15 @@ class DebugPermissionActivity : VectorBaseActivity { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + listOf(Manifest.permission.POST_NOTIFICATIONS) + } else { + emptyList() + } + } private var lastPermissions = emptyList() @@ -77,6 +86,14 @@ class DebugPermissionActivity : VectorBaseActivity= Build.VERSION_CODES.TIRAMISU) { + views.notification.setOnClickListener { + lastPermissions = listOf(Manifest.permission.POST_NOTIFICATIONS) + checkPerm() + } + } else { + views.notification.isVisible = false + } } private fun checkPerm() { diff --git a/vector-app/src/debug/res/layout/activity_debug_permission.xml b/vector-app/src/debug/res/layout/activity_debug_permission.xml index 6340d8faa7..0f1fef0b9b 100644 --- a/vector-app/src/debug/res/layout/activity_debug_permission.xml +++ b/vector-app/src/debug/res/layout/activity_debug_permission.xml @@ -30,43 +30,43 @@ android:id="@+id/camera" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="CAMERA" - android:textAllCaps="false" /> + android:text="CAMERA" />