mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Push test now does not display notification anymore. Add a dedicated test to do it
This commit is contained in:
parent
3714e4e787
commit
cb1addd5e3
12 changed files with 117 additions and 27 deletions
|
@ -22,17 +22,21 @@ import im.vector.app.fdroid.features.settings.troubleshoot.TestBatteryOptimizati
|
|||
import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager
|
||||
import im.vector.app.features.settings.troubleshoot.TestAccountSettings
|
||||
import im.vector.app.features.settings.troubleshoot.TestDeviceSettings
|
||||
import im.vector.app.features.settings.troubleshoot.TestNotification
|
||||
import im.vector.app.features.settings.troubleshoot.TestPushRulesSettings
|
||||
import im.vector.app.features.settings.troubleshoot.TestSystemSettings
|
||||
import javax.inject.Inject
|
||||
|
||||
class NotificationTroubleshootTestManagerFactory @Inject constructor(private val testSystemSettings: TestSystemSettings,
|
||||
private val testAccountSettings: TestAccountSettings,
|
||||
private val testDeviceSettings: TestDeviceSettings,
|
||||
private val testPushRulesSettings: TestPushRulesSettings,
|
||||
private val testAutoStartBoot: TestAutoStartBoot,
|
||||
private val testBackgroundRestrictions: TestBackgroundRestrictions,
|
||||
private val testBatteryOptimization: TestBatteryOptimization) {
|
||||
class NotificationTroubleshootTestManagerFactory @Inject constructor(
|
||||
private val testSystemSettings: TestSystemSettings,
|
||||
private val testAccountSettings: TestAccountSettings,
|
||||
private val testDeviceSettings: TestDeviceSettings,
|
||||
private val testPushRulesSettings: TestPushRulesSettings,
|
||||
private val testAutoStartBoot: TestAutoStartBoot,
|
||||
private val testBackgroundRestrictions: TestBackgroundRestrictions,
|
||||
private val testBatteryOptimization: TestBatteryOptimization,
|
||||
private val testNotification: TestNotification
|
||||
) {
|
||||
|
||||
fun create(fragment: Fragment): NotificationTroubleshootTestManager {
|
||||
val mgr = NotificationTroubleshootTestManager(fragment)
|
||||
|
@ -43,6 +47,7 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(private val
|
|||
mgr.addTest(testAutoStartBoot)
|
||||
mgr.addTest(testBackgroundRestrictions)
|
||||
mgr.addTest(testBatteryOptimization)
|
||||
mgr.addTest(testNotification)
|
||||
return mgr
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,15 +56,15 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat
|
|||
}
|
||||
|
||||
override fun onSuccess(data: Unit) {
|
||||
// Wait for user to click on the notification
|
||||
description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_success)
|
||||
status = TestStatus.WAITING_FOR_USER
|
||||
// Wait for the push to be received
|
||||
description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_waiting_for_push)
|
||||
status = TestStatus.RUNNING
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onNotificationClicked() {
|
||||
description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_notification_clicked)
|
||||
override fun onPushReceived() {
|
||||
description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_success)
|
||||
status = TestStatus.SUCCESS
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
|
||||
package im.vector.app.gplay.push.fcm
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.google.firebase.messaging.FirebaseMessagingService
|
||||
import com.google.firebase.messaging.RemoteMessage
|
||||
import im.vector.app.BuildConfig
|
||||
|
@ -34,6 +36,7 @@ import im.vector.app.features.badge.BadgeProxy
|
|||
import im.vector.app.features.notifications.NotifiableEventResolver
|
||||
import im.vector.app.features.notifications.NotifiableMessageEvent
|
||||
import im.vector.app.features.notifications.NotificationDrawerManager
|
||||
import im.vector.app.features.notifications.NotificationUtils
|
||||
import im.vector.app.features.notifications.SimpleNotifiableEvent
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import im.vector.app.push.fcm.FcmHelper
|
||||
|
@ -77,8 +80,8 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
|||
override fun onMessageReceived(message: RemoteMessage) {
|
||||
// Diagnostic Push
|
||||
if (message.data["event_id"] == PushersManager.TEST_EVENT_ID) {
|
||||
// Display the notification right now
|
||||
notificationDrawerManager.displayDiagnosticNotification()
|
||||
val intent = Intent(NotificationUtils.PUSH_ACTION)
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import androidx.fragment.app.Fragment
|
|||
import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager
|
||||
import im.vector.app.features.settings.troubleshoot.TestAccountSettings
|
||||
import im.vector.app.features.settings.troubleshoot.TestDeviceSettings
|
||||
import im.vector.app.features.settings.troubleshoot.TestNotification
|
||||
import im.vector.app.features.settings.troubleshoot.TestPushRulesSettings
|
||||
import im.vector.app.features.settings.troubleshoot.TestSystemSettings
|
||||
import im.vector.app.gplay.features.settings.troubleshoot.TestFirebaseToken
|
||||
|
@ -35,7 +36,8 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
|
|||
private val testPlayServices: TestPlayServices,
|
||||
private val testFirebaseToken: TestFirebaseToken,
|
||||
private val testTokenRegistration: TestTokenRegistration,
|
||||
private val testPushFromPushGateway: TestPushFromPushGateway
|
||||
private val testPushFromPushGateway: TestPushFromPushGateway,
|
||||
private val testNotification: TestNotification
|
||||
) {
|
||||
|
||||
fun create(fragment: Fragment): NotificationTroubleshootTestManager {
|
||||
|
@ -48,6 +50,7 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
|
|||
mgr.addTest(testFirebaseToken)
|
||||
mgr.addTest(testTokenRegistration)
|
||||
mgr.addTest(testPushFromPushGateway)
|
||||
mgr.addTest(testNotification)
|
||||
return mgr
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,15 +97,15 @@ fun copyToClipboard(context: Context, text: CharSequence, showToast: Boolean = t
|
|||
* Shows notification settings for the current app.
|
||||
* In android O will directly opens the notification settings, in lower version it will show the App settings
|
||||
*/
|
||||
fun startNotificationSettingsIntent(activity: AppCompatActivity, activityResultLauncher: ActivityResultLauncher<Intent>) {
|
||||
fun startNotificationSettingsIntent(context: Context, activityResultLauncher: ActivityResultLauncher<Intent>) {
|
||||
val intent = Intent()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, activity.packageName)
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
|
||||
} else {
|
||||
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||
intent.putExtra("app_package", activity.packageName)
|
||||
intent.putExtra("app_uid", activity.applicationInfo?.uid)
|
||||
intent.putExtra("app_package", context.packageName)
|
||||
intent.putExtra("app_uid", context.applicationInfo?.uid)
|
||||
}
|
||||
activityResultLauncher.launch(intent)
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ class NotificationUtils @Inject constructor(private val context: Context,
|
|||
const val DISMISS_ROOM_NOTIF_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.DISMISS_ROOM_NOTIF_ACTION"
|
||||
private const val TAP_TO_VIEW_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.TAP_TO_VIEW_ACTION"
|
||||
const val DIAGNOSTIC_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.DIAGNOSTIC"
|
||||
const val PUSH_ACTION = "${BuildConfig.APPLICATION_ID}.PUSH"
|
||||
|
||||
/* ==========================================================================================
|
||||
* IDs for channels
|
||||
|
|
|
@ -166,7 +166,11 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
|
|||
|
||||
tryOrNull("Unable to register the receiver") {
|
||||
LocalBroadcastManager.getInstance(requireContext())
|
||||
.registerReceiver(broadcastReceiver, IntentFilter(NotificationUtils.DIAGNOSTIC_ACTION))
|
||||
.registerReceiver(broadcastReceiverPush, IntentFilter(NotificationUtils.PUSH_ACTION))
|
||||
}
|
||||
tryOrNull("Unable to register the receiver") {
|
||||
LocalBroadcastManager.getInstance(requireContext())
|
||||
.registerReceiver(broadcastReceiverNotification, IntentFilter(NotificationUtils.DIAGNOSTIC_ACTION))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,11 +178,21 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
|
|||
super.onPause()
|
||||
tryOrNull {
|
||||
LocalBroadcastManager.getInstance(requireContext())
|
||||
.unregisterReceiver(broadcastReceiver)
|
||||
.unregisterReceiver(broadcastReceiverPush)
|
||||
}
|
||||
tryOrNull {
|
||||
LocalBroadcastManager.getInstance(requireContext())
|
||||
.unregisterReceiver(broadcastReceiverNotification)
|
||||
}
|
||||
}
|
||||
|
||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
||||
private val broadcastReceiverPush = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
testManager?.onDiagnosticPushReceived()
|
||||
}
|
||||
}
|
||||
|
||||
private val broadcastReceiverNotification = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
testManager?.onDiagnosticNotificationClicked()
|
||||
}
|
||||
|
|
|
@ -106,6 +106,10 @@ class NotificationTroubleshootTestManager(val fragment: Fragment) {
|
|||
testList.forEach { it.cancel() }
|
||||
}
|
||||
|
||||
fun onDiagnosticPushReceived() {
|
||||
testList.forEach { it.onPushReceived() }
|
||||
}
|
||||
|
||||
fun onDiagnosticNotificationClicked() {
|
||||
testList.forEach { it.onNotificationClicked() }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright 2018 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.app.features.settings.troubleshoot
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.utils.startNotificationSettingsIntent
|
||||
import im.vector.app.features.notifications.NotificationUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Checks if notifications can be displayed and clicked by the user
|
||||
*/
|
||||
class TestNotification @Inject constructor(private val context: Context,
|
||||
private val notificationUtils: NotificationUtils,
|
||||
private val stringProvider: StringProvider)
|
||||
: TroubleshootTest(R.string.settings_troubleshoot_test_notification_title) {
|
||||
|
||||
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
|
||||
// Display the notification right now
|
||||
notificationUtils.displayDiagnosticNotification()
|
||||
description = stringProvider.getString(R.string.settings_troubleshoot_test_notification_notice)
|
||||
|
||||
quickFix = object : TroubleshootQuickFix(R.string.open_settings) {
|
||||
override fun doFix() {
|
||||
startNotificationSettingsIntent(context, activityResultLauncher)
|
||||
}
|
||||
}
|
||||
|
||||
status = TestStatus.WAITING_FOR_USER
|
||||
}
|
||||
|
||||
override fun onNotificationClicked() {
|
||||
description = stringProvider.getString(R.string.settings_troubleshoot_test_notification_notification_clicked)
|
||||
quickFix = null
|
||||
status = TestStatus.SUCCESS
|
||||
}
|
||||
}
|
|
@ -15,9 +15,9 @@
|
|||
*/
|
||||
package im.vector.app.features.settings.troubleshoot
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
|
@ -27,7 +27,7 @@ import javax.inject.Inject
|
|||
/**
|
||||
* Checks if notifications are enable in the system settings for this app.
|
||||
*/
|
||||
class TestSystemSettings @Inject constructor(private val context: AppCompatActivity,
|
||||
class TestSystemSettings @Inject constructor(private val context: Context,
|
||||
private val stringProvider: StringProvider)
|
||||
: TroubleshootTest(R.string.settings_troubleshoot_test_system_settings_title) {
|
||||
|
||||
|
|
|
@ -53,6 +53,9 @@ abstract class TroubleshootTest(@StringRes val titleResId: Int) {
|
|||
open fun cancel() {
|
||||
}
|
||||
|
||||
open fun onPushReceived() {
|
||||
}
|
||||
|
||||
open fun onNotificationClicked() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -750,10 +750,13 @@
|
|||
<string name="settings_troubleshoot_test_token_registration_failed">Failed to register FCM token to HomeServer:\n%1$s</string>
|
||||
|
||||
<string name="settings_troubleshoot_test_push_loop_title">Test Push</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_success">The application is receiving PUSH, please click on the test notification you just received.</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_notification_clicked">The notification has been clicked!</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_waiting_for_push">The application is waiting for the PUSH</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_success">The application is receiving PUSH</string>
|
||||
<string name="settings_troubleshoot_test_push_loop_failed">Failed to receive push. Solution could be to reinstall the application.</string>
|
||||
<string name="settings_troubleshoot_test_push_notification_content">You are receiving PUSH! Click me!</string>
|
||||
<string name="settings_troubleshoot_test_push_notification_content">You are viewing the notification! Click me!</string>
|
||||
<string name="settings_troubleshoot_test_notification_title">Notification Display</string>
|
||||
<string name="settings_troubleshoot_test_notification_notice">Please click on the notification. If you do not see the notification, please check the system settings.</string>
|
||||
<string name="settings_troubleshoot_test_notification_notification_clicked">The notification has been clicked!</string>
|
||||
|
||||
<string name="settings_troubleshoot_test_foreground_service_started_title">Notifications Service</string>
|
||||
<string name="settings_troubleshoot_test_foreground_service_startedt_success">Notifications Service is running.</string>
|
||||
|
|
Loading…
Reference in a new issue