Add UnifiedPush troubleshoot

This commit is contained in:
sim 2022-02-28 15:46:53 +01:00 committed by Benoit Marty
parent 848adc415f
commit f00257f461
16 changed files with 448 additions and 58 deletions

View file

@ -28,6 +28,19 @@
android:enabled="true"
android:exported="false" />
<receiver android:name=".fdroid.receiver.KeepInternalDistributor"
android:enabled="true"
android:exported="false">
<intent-filter>
<!--
This action is checked to track installed and uninstalled distributors.
We declare it to keep the background sync as an internal
unifiedpush distributor.
-->
<action android:name="org.unifiedpush.android.distributor.REGISTER" />
</intent-filter>
</receiver>
<service
android:name=".fdroid.service.GuardService"
android:exported="false"

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 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.fdroid.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
/**
* UnifiedPush lib tracks an action to check installed and uninstalled distributors.
* We declare it to keep the background sync as an internal unifiedpush distributor.
* This class is used to declare this action.
*/
class KeepInternalDistributor : BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
return
}
}

View file

@ -16,15 +16,23 @@
package im.vector.app.push.fcm
import androidx.fragment.app.Fragment
import im.vector.app.BuildConfig
import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.fdroid.features.settings.troubleshoot.TestAutoStartBoot
import im.vector.app.fdroid.features.settings.troubleshoot.TestBackgroundRestrictions
import im.vector.app.fdroid.features.settings.troubleshoot.TestBatteryOptimization
import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager
import im.vector.app.features.settings.troubleshoot.TestAccountSettings
import im.vector.app.features.settings.troubleshoot.TestAvailableUnifiedPushDistributors
import im.vector.app.features.settings.troubleshoot.TestCurrentUnifiedPushDistributor
import im.vector.app.features.settings.troubleshoot.TestDeviceSettings
import im.vector.app.features.settings.troubleshoot.TestEndpointAsTokenRegistration
import im.vector.app.features.settings.troubleshoot.TestNotification
import im.vector.app.features.settings.troubleshoot.TestPushFromPushGateway
import im.vector.app.features.settings.troubleshoot.TestPushRulesSettings
import im.vector.app.features.settings.troubleshoot.TestSystemSettings
import im.vector.app.features.settings.troubleshoot.TestUnifiedPushEndpoint
import im.vector.app.features.settings.troubleshoot.TestUnifiedPushGateway
import javax.inject.Inject
class NotificationTroubleshootTestManagerFactory @Inject constructor(
@ -32,6 +40,12 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
private val testAccountSettings: TestAccountSettings,
private val testDeviceSettings: TestDeviceSettings,
private val testPushRulesSettings: TestPushRulesSettings,
private val testCurrentUnifiedPushDistributor: TestCurrentUnifiedPushDistributor,
private val testUnifiedPushGateway: TestUnifiedPushGateway,
private val testUnifiedPushEndpoint: TestUnifiedPushEndpoint,
private val testAvailableUnifiedPushDistributors: TestAvailableUnifiedPushDistributors,
private val testEndpointAsTokenRegistration: TestEndpointAsTokenRegistration,
private val testPushFromPushGateway: TestPushFromPushGateway,
private val testAutoStartBoot: TestAutoStartBoot,
private val testBackgroundRestrictions: TestBackgroundRestrictions,
private val testBatteryOptimization: TestBatteryOptimization,
@ -44,9 +58,20 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
mgr.addTest(testAccountSettings)
mgr.addTest(testDeviceSettings)
mgr.addTest(testPushRulesSettings)
mgr.addTest(testAutoStartBoot)
mgr.addTest(testBackgroundRestrictions)
mgr.addTest(testBatteryOptimization)
if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) {
mgr.addTest(testAvailableUnifiedPushDistributors)
mgr.addTest(testCurrentUnifiedPushDistributor)
}
if (UnifiedPushHelper.isBackgroundSync(fragment.requireContext())) {
mgr.addTest(testAutoStartBoot)
mgr.addTest(testBackgroundRestrictions)
mgr.addTest(testBatteryOptimization)
} else {
mgr.addTest(testUnifiedPushGateway)
mgr.addTest(testUnifiedPushEndpoint)
mgr.addTest(testEndpointAsTokenRegistration)
mgr.addTest(testPushFromPushGateway)
}
mgr.addTest(testNotification)
return mgr
}

View file

@ -16,15 +16,22 @@
package im.vector.app.push.fcm
import androidx.fragment.app.Fragment
import im.vector.app.BuildConfig
import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager
import im.vector.app.features.settings.troubleshoot.TestAccountSettings
import im.vector.app.features.settings.troubleshoot.TestAvailableUnifiedPushDistributors
import im.vector.app.features.settings.troubleshoot.TestCurrentUnifiedPushDistributor
import im.vector.app.features.settings.troubleshoot.TestDeviceSettings
import im.vector.app.features.settings.troubleshoot.TestEndpointAsTokenRegistration
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.features.settings.troubleshoot.TestUnifiedPushEndpoint
import im.vector.app.features.settings.troubleshoot.TestUnifiedPushGateway
import im.vector.app.features.settings.troubleshoot.TestPushFromPushGateway
import im.vector.app.gplay.features.settings.troubleshoot.TestFirebaseToken
import im.vector.app.gplay.features.settings.troubleshoot.TestPlayServices
import im.vector.app.gplay.features.settings.troubleshoot.TestPushFromPushGateway
import im.vector.app.gplay.features.settings.troubleshoot.TestTokenRegistration
import javax.inject.Inject
@ -32,10 +39,15 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
private val testSystemSettings: TestSystemSettings,
private val testAccountSettings: TestAccountSettings,
private val testDeviceSettings: TestDeviceSettings,
private val testBingRulesSettings: TestPushRulesSettings,
private val testPushRulesSettings: TestPushRulesSettings,
private val testPlayServices: TestPlayServices,
private val testFirebaseToken: TestFirebaseToken,
private val testTokenRegistration: TestTokenRegistration,
private val testCurrentUnifiedPushDistributor: TestCurrentUnifiedPushDistributor,
private val testUnifiedPushGateway: TestUnifiedPushGateway,
private val testUnifiedPushEndpoint: TestUnifiedPushEndpoint,
private val testAvailableUnifiedPushDistributors: TestAvailableUnifiedPushDistributors,
private val testEndpointAsTokenRegistration: TestEndpointAsTokenRegistration,
private val testPushFromPushGateway: TestPushFromPushGateway,
private val testNotification: TestNotification
) {
@ -45,10 +57,21 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
mgr.addTest(testSystemSettings)
mgr.addTest(testAccountSettings)
mgr.addTest(testDeviceSettings)
mgr.addTest(testBingRulesSettings)
mgr.addTest(testPlayServices)
mgr.addTest(testFirebaseToken)
mgr.addTest(testTokenRegistration)
mgr.addTest(testPushRulesSettings)
if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) {
mgr.addTest(testAvailableUnifiedPushDistributors)
mgr.addTest(testCurrentUnifiedPushDistributor)
}
if (UnifiedPushHelper.isEmbeddedDistributor(fragment.requireContext())) {
mgr.addTest(testPlayServices)
mgr.addTest(testFirebaseToken)
mgr.addTest(testTokenRegistration)
} else {
mgr.addTest(testUnifiedPushGateway)
mgr.addTest(testUnifiedPushEndpoint)
mgr.addTest(testEndpointAsTokenRegistration)
}
mgr.addTest(testPushFromPushGateway)
mgr.addTest(testNotification)
return mgr

View file

@ -39,7 +39,7 @@ class PushersManager @Inject constructor(
val currentSession = activeSessionHolder.getActiveSession()
currentSession.pushersService().testPush(
UnifiedPushHelper.getPushGateway(context),
UnifiedPushHelper.getPushGateway(context)!!,
stringProvider.getString(R.string.pusher_app_id),
UnifiedPushHelper.getEndpointOrToken(context) ?: "",
TEST_EVENT_ID

View file

@ -66,8 +66,8 @@ object UnifiedPushHelper {
*
* @return the Push Gateway or null if not defined
*/
fun getPushGateway(context: Context): String {
return DefaultSharedPreferences.getInstance(context).getString(PREFS_PUSH_GATEWAY, null)!!
fun getPushGateway(context: Context): String? {
return DefaultSharedPreferences.getInstance(context).getString(PREFS_PUSH_GATEWAY, null)
}
/**
@ -84,9 +84,27 @@ object UnifiedPushHelper {
}
}
fun register(context: Context,
fun register(context: Context, onDoneRunnable: Runnable? = null) {
gRegister(context,
onDoneRunnable = onDoneRunnable)
}
fun reRegister(context: Context,
pushersManager: PushersManager,
vectorPreferences: VectorPreferences,
onDoneRunnable: Runnable? = null) {
gRegister(context,
force = true,
pushersManager = pushersManager,
vectorPreferences = vectorPreferences,
onDoneRunnable = onDoneRunnable
)
}
private fun gRegister(context: Context,
force: Boolean = false,
pushersManager: PushersManager? = null,
vectorPreferences: VectorPreferences? = null,
onDoneRunnable: Runnable? = null) {
if (!BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) {
up.saveDistributor(context, context.packageName)
@ -96,12 +114,7 @@ object UnifiedPushHelper {
}
if (force) {
// Un-register first
runBlocking {
pushersManager?.unregisterPusher(getEndpointOrToken(context) ?: "")
}
up.unregisterApp(context)
storeUpEndpoint(context, null)
storePushGateway(context, null)
unregister(context, pushersManager, vectorPreferences)
}
if (up.getDistributor(context).isNotEmpty()) {
up.registerApp(context)
@ -113,12 +126,10 @@ object UnifiedPushHelper {
up.saveDistributor(context, context.packageName)
val distributors = up.getDistributors(context).toMutableList()
val internalDistributorName = if (!FcmHelper.isPushSupported()) {
// Adding packageName for background sync
distributors.add(context.packageName)
context.getString(R.string.unifiedpush_getdistributors_dialog_background_sync)
val internalDistributorName = if (FcmHelper.isPushSupported()) {
context.getString(R.string.unifiedpush_distributor_fcm_fallback)
} else {
context.getString(R.string.unifiedpush_getdistributors_dialog_fcm_fallback)
context.getString(R.string.unifiedpush_distributor_background_sync)
}
if (distributors.size == 1
@ -175,6 +186,8 @@ object UnifiedPushHelper {
Timber.d("Probably unregistering a non existant pusher")
}
}
storeUpEndpoint(context, null)
storePushGateway(context, null)
up.unregisterApp(context)
}
@ -183,7 +196,10 @@ object UnifiedPushHelper {
// register app_id type upfcm on sygnal
// the pushkey if FCM key
if (up.getDistributor(context) == context.packageName) {
return context.getString(R.string.pusher_http_url)
context.getString(R.string.pusher_http_url).let {
storePushGateway(context, it)
return it
}
}
// else, unifiedpush, and pushkey is an endpoint
val default = context.getString(R.string.default_push_gateway_http_url)
@ -197,11 +213,30 @@ object UnifiedPushHelper {
* return custom
*/
}
storePushGateway(context, default)
return default
}
fun distributorExists(context: Context): Boolean {
return up.getDistributor(context).isNotEmpty()
fun getExternalDistributors(context: Context): List<String> {
val distributors = up.getDistributors(context).toMutableList()
distributors.remove(context.packageName)
return distributors
}
fun getCurrentDistributorName(context: Context): String {
if (isEmbeddedDistributor(context)) {
return context.getString(R.string.unifiedpush_distributor_fcm_fallback)
}
if (isBackgroundSync(context)) {
return context.getString(R.string.unifiedpush_distributor_background_sync)
}
val distributor = up.getDistributor(context)
return try {
val ai = context.packageManager.getApplicationInfo(distributor, 0)
context.packageManager.getApplicationLabel(ai)
} catch (e: PackageManager.NameNotFoundException) {
distributor
} as String
}
fun isEmbeddedDistributor(context: Context) : Boolean {
@ -222,7 +257,7 @@ object UnifiedPushHelper {
}
return try {
val parsed = URL(endpoint)
"${parsed.protocol}://${parsed.host}"
"${parsed.protocol}://${parsed.host}/***"
} catch (e: Exception) {
Timber.e("Error parsing unifiedpush endpoint: $e")
null

View file

@ -32,6 +32,7 @@ import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.BuildConfig
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.network.WifiDetector
import im.vector.app.core.services.GuardServiceStarter
import im.vector.app.features.badge.BadgeProxy
import im.vector.app.features.notifications.NotifiableEventResolver
import im.vector.app.features.notifications.NotificationDrawerManager
@ -78,11 +79,12 @@ private val loggerTag = LoggerTag("Push", LoggerTag.SYNC)
class VectorMessagingReceiver : MessagingReceiver() {
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
@Inject lateinit var notifiableEventResolver: NotifiableEventResolver
@Inject lateinit var pusherManager: PushersManager
@Inject lateinit var pushersManager: PushersManager
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var vectorDataStore: VectorDataStore
@Inject lateinit var wifiDetector: WifiDetector
@Inject lateinit var guardServiceStarter: GuardServiceStarter
private val coroutineScope = CoroutineScope(SupervisorJob())
@ -161,26 +163,31 @@ class VectorMessagingReceiver : MessagingReceiver() {
|| UnifiedPushHelper.getPushGateway(context) != gateway) {
UnifiedPushHelper.storePushGateway(context, gateway)
UnifiedPushHelper.storeUpEndpoint(context, endpoint)
pusherManager.enqueueRegisterPusher(endpoint, gateway)
pushersManager.enqueueRegisterPusher(endpoint, gateway)
} else {
Timber.tag(loggerTag.value).i("onNewEndpoint: skipped")
}
}
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED
vectorPreferences.setFdroidSyncBackgroundMode(mode)
guardServiceStarter.stop()
}
override fun onRegistrationFailed(context: Context, instance: String) {
Toast.makeText(context, "Push service registration failed", Toast.LENGTH_SHORT).show()
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
vectorPreferences.setFdroidSyncBackgroundMode(mode)
guardServiceStarter.start()
}
override fun onUnregistered(context: Context, instance: String) {
Timber.tag(loggerTag.value).d("Unifiedpush: Unregistered")
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
vectorPreferences.setFdroidSyncBackgroundMode(mode)
guardServiceStarter.start()
runBlocking {
try {
pusherManager.unregisterPusher(UnifiedPushHelper.getEndpointOrToken(context) ?: "")
pushersManager.unregisterPusher(UnifiedPushHelper.getEndpointOrToken(context) ?: "")
} catch (e: Exception) {
Timber.tag(loggerTag.value).d("Probably unregistering a non existant pusher")
}

View file

@ -188,7 +188,7 @@ class HomeActivity :
super.onCreate(savedInstanceState)
analyticsScreenName = MobileScreen.ScreenName.Home
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
UnifiedPushHelper.register(this, onDoneRunnable = {
UnifiedPushHelper.register(this) {
if (UnifiedPushHelper.isEmbeddedDistributor(this)) {
FcmHelper.ensureFcmTokenIsRetrieved(
this,
@ -196,7 +196,7 @@ class HomeActivity :
vectorPreferences.areNotificationEnabledForDevice()
)
}
})
}
sharedActionViewModel = viewModelProvider.get(HomeSharedActionViewModel::class.java)
views.drawerLayout.addDrawerListener(drawerListener)
if (isFirstCreation()) {

View file

@ -63,7 +63,7 @@ import javax.inject.Inject
// Referenced in vector_settings_preferences_root.xml
class VectorSettingsNotificationPreferenceFragment @Inject constructor(
private val pushManager: PushersManager,
private val pushersManager: PushersManager,
private val activeSessionHolder: ActiveSessionHolder,
private val vectorPreferences: VectorPreferences,
private val guardServiceStarter: GuardServiceStarter
@ -103,7 +103,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
} else {
UnifiedPushHelper.unregister(
requireContext(),
pushManager,
pushersManager,
vectorPreferences
)
session.pushersService().refreshPushers()
@ -152,14 +152,16 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
findPreference<VectorPreference>(VectorPreferences.SETTINGS_UNIFIED_PUSH_RE_REGISTER_KEY)?.let {
if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) {
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
UnifiedPushHelper.register(
UnifiedPushHelper.reRegister(
requireContext(),
force = true,
pushManager
)
pushersManager,
vectorPreferences
) {
session.pushersService().refreshPushers()
refreshBackgroundSyncPrefs()
}
true
}
session.pushersService().refreshPushers()
} else {
it.isVisible = false
}
@ -199,9 +201,9 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
pref.isChecked = isEnabled
pref.setTransactionalSwitchChangeListener(lifecycleScope) { isChecked ->
if (isChecked) {
pushManager.registerEmailForPush(emailPid.email)
pushersManager.registerEmailForPush(emailPid.email)
} else {
pushManager.unregisterEmailPusher(emailPid.email)
pushersManager.unregisterEmailPusher(emailPid.email)
}
}
category.addPreference(pref)

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2022 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.Intent
import androidx.activity.result.ActivityResultLauncher
import androidx.fragment.app.FragmentActivity
import im.vector.app.R
import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.core.resources.StringProvider
import im.vector.app.push.fcm.FcmHelper
import javax.inject.Inject
class TestAvailableUnifiedPushDistributors @Inject constructor(private val context: FragmentActivity,
private val stringProvider: StringProvider) :
TroubleshootTest(R.string.settings_troubleshoot_test_distributors_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
val distributors = UnifiedPushHelper.getExternalDistributors(context)
if (distributors.isEmpty()) {
description = if (FcmHelper.isPushSupported()) {
stringProvider.getString(R.string.settings_troubleshoot_test_distributors_gplay)
} else {
stringProvider.getString(R.string.settings_troubleshoot_test_distributors_fdroid)
}
status = TestStatus.SUCCESS
} else {
description = stringProvider.getString(R.string.settings_troubleshoot_test_distributors_many,
distributors.size + 1)
status = TestStatus.SUCCESS
}
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 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.Intent
import androidx.activity.result.ActivityResultLauncher
import androidx.fragment.app.FragmentActivity
import im.vector.app.R
import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.core.resources.StringProvider
import javax.inject.Inject
class TestCurrentUnifiedPushDistributor @Inject constructor(private val context: FragmentActivity,
private val stringProvider: StringProvider) :
TroubleshootTest(R.string.settings_troubleshoot_test_current_distributor_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
description = stringProvider.getString(R.string.settings_troubleshoot_test_current_distributor,
UnifiedPushHelper.getCurrentDistributorName(context))
status = TestStatus.SUCCESS
}
}

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2022 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.Intent
import androidx.activity.result.ActivityResultLauncher
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import androidx.work.WorkInfo
import androidx.work.WorkManager
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.pushers.PusherState
import javax.inject.Inject
class TestEndpointAsTokenRegistration @Inject constructor(private val context: FragmentActivity,
private val stringProvider: StringProvider,
private val pushersManager: PushersManager,
private val vectorPreferences: VectorPreferences,
private val activeSessionHolder: ActiveSessionHolder) :
TroubleshootTest(R.string.settings_troubleshoot_test_endpoint_registration_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
// Check if we have a registered pusher for this token
val endpoint = UnifiedPushHelper.getEndpointOrToken(context) ?: run {
status = TestStatus.FAILED
return
}
val session = activeSessionHolder.getSafeActiveSession() ?: run {
status = TestStatus.FAILED
return
}
val pushers = session.pushersService().getPushers().filter {
it.pushKey == endpoint && it.state == PusherState.REGISTERED
}
if (pushers.isEmpty()) {
description = stringProvider.getString(R.string.settings_troubleshoot_test_endpoint_registration_failed,
stringProvider.getString(R.string.sas_error_unknown))
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_endpoint_registration_quick_fix) {
override fun doFix() {
UnifiedPushHelper.reRegister(
context,
pushersManager,
vectorPreferences
)
val workId = pushersManager.enqueueRegisterPusherWithFcmKey(endpoint)
WorkManager.getInstance(context).getWorkInfoByIdLiveData(workId).observe(context, Observer { workInfo ->
if (workInfo != null) {
if (workInfo.state == WorkInfo.State.SUCCEEDED) {
manager?.retry(activityResultLauncher)
} else if (workInfo.state == WorkInfo.State.FAILED) {
manager?.retry(activityResultLauncher)
}
}
})
}
}
status = TestStatus.FAILED
} else {
description = stringProvider.getString(R.string.settings_troubleshoot_test_endpoint_registration_success)
status = TestStatus.SUCCESS
}
}
}

View file

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.gplay.features.settings.troubleshoot
package im.vector.app.features.settings.troubleshoot
import android.content.Intent
import androidx.activity.result.ActivityResultLauncher
@ -24,8 +24,6 @@ import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.session.coroutineScope
import im.vector.app.features.settings.troubleshoot.TroubleshootTest
import im.vector.app.push.fcm.FcmHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
@ -36,13 +34,11 @@ import javax.inject.Inject
/**
* Test Push by asking the Push Gateway to send a Push back
*/
class TestPushFromPushGateway @Inject constructor(
private val context: FragmentActivity,
private val stringProvider: StringProvider,
private val errorFormatter: ErrorFormatter,
private val pushersManager: PushersManager,
private val activeSessionHolder: ActiveSessionHolder
) :
class TestPushFromPushGateway @Inject constructor(private val context: FragmentActivity,
private val stringProvider: StringProvider,
private val errorFormatter: ErrorFormatter,
private val pushersManager: PushersManager,
private val activeSessionHolder: ActiveSessionHolder) :
TroubleshootTest(R.string.settings_troubleshoot_test_push_loop_title) {
private var action: Job? = null
@ -50,10 +46,6 @@ class TestPushFromPushGateway @Inject constructor(
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
pushReceived = false
FcmHelper.getFcmToken(context) ?: run {
status = TestStatus.FAILED
return
}
action = activeSessionHolder.getActiveSession().coroutineScope.launch {
val result = runCatching { pushersManager.testPush(context) }

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2022 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.Intent
import androidx.activity.result.ActivityResultLauncher
import androidx.fragment.app.FragmentActivity
import im.vector.app.R
import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.core.resources.StringProvider
import javax.inject.Inject
class TestUnifiedPushEndpoint @Inject constructor(private val context: FragmentActivity,
private val stringProvider: StringProvider) :
TroubleshootTest(R.string.settings_troubleshoot_test_current_endpoint_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
val endpoint = UnifiedPushHelper.getPrivacyFriendlyUpEndpoint(context)
endpoint?.let {
description = stringProvider.getString(R.string.settings_troubleshoot_test_current_endpoint_success,
UnifiedPushHelper.getPrivacyFriendlyUpEndpoint(context))
status = TestStatus.SUCCESS
} ?: run {
description = stringProvider.getString(R.string.settings_troubleshoot_test_current_endpoint_failed)
status = TestStatus.FAILED
}
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 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.Intent
import androidx.activity.result.ActivityResultLauncher
import androidx.fragment.app.FragmentActivity
import im.vector.app.R
import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.core.resources.StringProvider
import javax.inject.Inject
class TestUnifiedPushGateway @Inject constructor(private val context: FragmentActivity,
private val stringProvider: StringProvider) :
TroubleshootTest(R.string.settings_troubleshoot_test_current_gateway_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
description = stringProvider.getString(R.string.settings_troubleshoot_test_current_gateway,
UnifiedPushHelper.getPushGateway(context))
status = TestStatus.SUCCESS
}
}

View file

@ -855,6 +855,10 @@
<string name="settings_troubleshoot_test_token_registration_success">FCM token successfully registered to homeserver.</string>
<string name="settings_troubleshoot_test_token_registration_failed">Failed to register FCM token to homeserver:\n%1$s</string>
<string name="settings_troubleshoot_test_endpoint_registration_title">Endpoint Registration</string>
<string name="settings_troubleshoot_test_endpoint_registration_success">Endpoint successfully registered to homeserver.</string>
<string name="settings_troubleshoot_test_endpoint_registration_failed">Failed to register endpoint 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_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>
@ -1665,6 +1669,8 @@
<string name="settings_troubleshoot_test_token_registration_quick_fix">Register token</string>
<string name="settings_troubleshoot_test_endpoint_registration_quick_fix">Reset notification method</string>
<string name="send_suggestion">Make a suggestion</string>
<string name="send_suggestion_content">Please write your suggestion below.</string>
<string name="send_suggestion_report_placeholder">Describe your suggestion here</string>
@ -3065,7 +3071,18 @@
<string name="screen_sharing_notification_description">Screen sharing is in progress</string>
<string name="unifiedpush_getdistributors_dialog_title">Choose how to receive notifications</string>
<string name="unifiedpush_getdistributors_dialog_fcm_fallback">Google Services</string>
<string name="unifiedpush_getdistributors_dialog_background_sync">Background synchronization</string>
<string name="unifiedpush_distributor_fcm_fallback">Google Services</string>
<string name="unifiedpush_distributor_background_sync">Background synchronization</string>
<string name="settings_unifiedpush_reregister">Notification method</string>
<string name="settings_troubleshoot_test_distributors_title">Available methods</string>
<string name="settings_troubleshoot_test_distributors_gplay">No other method than Google Play Service found.</string>
<string name="settings_troubleshoot_test_distributors_fdroid">No other method than background synchronization found.</string>
<string name="settings_troubleshoot_test_distributors_many">Found %d methods.</string>
<string name="settings_troubleshoot_test_current_distributor_title">Method</string>
<string name="settings_troubleshoot_test_current_distributor">Currently using %s.</string>
<string name="settings_troubleshoot_test_current_endpoint_title">Endpoint</string>
<string name="settings_troubleshoot_test_current_endpoint_success">Current endpoint: %s</string>
<string name="settings_troubleshoot_test_current_endpoint_failed">Cannot find the endpoint.</string>
<string name="settings_troubleshoot_test_current_gateway_title">Gateway</string>
<string name="settings_troubleshoot_test_current_gateway">Current gateway: %s</string>
</resources>