diff --git a/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt b/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt index 6236aad65c..366128ff2c 100644 --- a/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt @@ -16,21 +16,29 @@ package im.vector.app.push.fcm import androidx.fragment.app.Fragment -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.core.pushers.UPHelper +import im.vector.app.features.settings.troubleshoot.TestAutoStartBoot +import im.vector.app.features.settings.troubleshoot.TestBackgroundRestrictions +import im.vector.app.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.TestDeviceSettings +import im.vector.app.features.settings.troubleshoot.TestNewEndpoint 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.TestTokenRegistration import javax.inject.Inject class NotificationTroubleshootTestManagerFactory @Inject constructor( private val testSystemSettings: TestSystemSettings, private val testAccountSettings: TestAccountSettings, private val testDeviceSettings: TestDeviceSettings, + private val testBingRulesSettings: TestPushRulesSettings, + private val testNewEndpoint: TestNewEndpoint, + private val testTokenRegistration: TestTokenRegistration, + private val testPushFromPushGateway: TestPushFromPushGateway, private val testPushRulesSettings: TestPushRulesSettings, private val testAutoStartBoot: TestAutoStartBoot, private val testBackgroundRestrictions: TestBackgroundRestrictions, @@ -43,10 +51,17 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( mgr.addTest(testSystemSettings) mgr.addTest(testAccountSettings) mgr.addTest(testDeviceSettings) - mgr.addTest(testPushRulesSettings) - mgr.addTest(testAutoStartBoot) - mgr.addTest(testBackgroundRestrictions) - mgr.addTest(testBatteryOptimization) + if (UPHelper.DistributorExists(fragment.requireContext())) { + mgr.addTest(testBingRulesSettings) + mgr.addTest(testNewEndpoint) + mgr.addTest(testTokenRegistration) + mgr.addTest(testPushFromPushGateway) + } else { + mgr.addTest(testPushRulesSettings) + mgr.addTest(testAutoStartBoot) + mgr.addTest(testBackgroundRestrictions) + mgr.addTest(testBatteryOptimization) + } mgr.addTest(testNotification) return mgr } diff --git a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestNewEndpoint.kt b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestNewEndpoint.kt deleted file mode 100644 index 7cb0fed9f4..0000000000 --- a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestNewEndpoint.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.gplay.features.settings.troubleshoot - -import android.content.Intent -import androidx.activity.result.ActivityResultLauncher -import androidx.appcompat.app.AppCompatActivity -import im.vector.app.R -import im.vector.app.core.resources.StringProvider -import im.vector.app.core.utils.startAddGoogleAccountIntent -import im.vector.app.features.settings.troubleshoot.TroubleshootTest -import im.vector.app.push.fcm.FcmHelper -import timber.log.Timber -import javax.inject.Inject - -/* -* Test that app can successfully retrieve a new endpoint - */ -class TestNewEndpoint @Inject constructor(private val context: AppCompatActivity, - private val stringProvider: StringProvider) : TroubleshootTest(R.string.settings_troubleshoot_test_fcm_title) { - - override fun perform(activityResultLauncher: ActivityResultLauncher) { - description = "bypassed" - status = TestStatus.SUCCESS - /** - * TODO - */ - /*status = TestStatus.RUNNING - try { - FirebaseMessaging.getInstance().token - .addOnCompleteListener(context) { task -> - if (!task.isSuccessful) { - // Can't find where this constant is (not documented -or deprecated in docs- and all obfuscated) - description = when (val errorMsg = task.exception?.localizedMessage ?: "Unknown") { - "SERVICE_NOT_AVAILABLE" -> { - stringProvider.getString(R.string.settings_troubleshoot_test_fcm_failed_service_not_available, errorMsg) - } - "TOO_MANY_REGISTRATIONS" -> { - stringProvider.getString(R.string.settings_troubleshoot_test_fcm_failed_too_many_registration, errorMsg) - } - "ACCOUNT_MISSING" -> { - quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_fcm_failed_account_missing_quick_fix) { - override fun doFix() { - startAddGoogleAccountIntent(context, activityResultLauncher) - } - } - stringProvider.getString(R.string.settings_troubleshoot_test_fcm_failed_account_missing, errorMsg) - } - else -> { - stringProvider.getString(R.string.settings_troubleshoot_test_fcm_failed, errorMsg) - } - } - status = TestStatus.FAILED - } else { - task.result?.let { token -> - val tok = token.take(8) + "********************" - description = stringProvider.getString(R.string.settings_troubleshoot_test_fcm_success, tok) - Timber.e("Retrieved FCM token success [$tok].") - // Ensure it is well store in our local storage - FcmHelper.storeFcmToken(context, token) - } - status = TestStatus.SUCCESS - } - } - } catch (e: Throwable) { - description = stringProvider.getString(R.string.settings_troubleshoot_test_fcm_failed, e.localizedMessage) - status = TestStatus.FAILED - }*/ - } -} diff --git a/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt b/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt index df0b3409bc..14c0e1c48d 100644 --- a/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt @@ -16,16 +16,20 @@ package im.vector.app.push.fcm import androidx.fragment.app.Fragment +import im.vector.app.core.pushers.UPHelper import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager import im.vector.app.features.settings.troubleshoot.TestAccountSettings +import im.vector.app.features.settings.troubleshoot.TestAutoStartBoot +import im.vector.app.features.settings.troubleshoot.TestBackgroundRestrictions +import im.vector.app.features.settings.troubleshoot.TestBatteryOptimization 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.TestNewEndpoint +import im.vector.app.features.settings.troubleshoot.TestNewEndpoint 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 im.vector.app.features.settings.troubleshoot.TestPushFromPushGateway +import im.vector.app.features.settings.troubleshoot.TestTokenRegistration import javax.inject.Inject class NotificationTroubleshootTestManagerFactory @Inject constructor( @@ -37,6 +41,10 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( private val testNewEndpoint: TestNewEndpoint, private val testTokenRegistration: TestTokenRegistration, private val testPushFromPushGateway: TestPushFromPushGateway, + private val testPushRulesSettings: TestPushRulesSettings, + private val testAutoStartBoot: TestAutoStartBoot, + private val testBackgroundRestrictions: TestBackgroundRestrictions, + private val testBatteryOptimization: TestBatteryOptimization, private val testNotification: TestNotification ) { @@ -45,11 +53,18 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( mgr.addTest(testSystemSettings) mgr.addTest(testAccountSettings) mgr.addTest(testDeviceSettings) - mgr.addTest(testBingRulesSettings) - mgr.addTest(testPlayServices) - mgr.addTest(testNewEndpoint) - mgr.addTest(testTokenRegistration) - mgr.addTest(testPushFromPushGateway) + if (UPHelper.DistributorExists(fragment.requireContext())) { + mgr.addTest(testBingRulesSettings) + mgr.addTest(testPlayServices) + mgr.addTest(testNewEndpoint) + mgr.addTest(testTokenRegistration) + mgr.addTest(testPushFromPushGateway) + } else { + mgr.addTest(testPushRulesSettings) + mgr.addTest(testAutoStartBoot) + mgr.addTest(testBackgroundRestrictions) + mgr.addTest(testBatteryOptimization) + } mgr.addTest(testNotification) return mgr } diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index ba820cc3a7..0cc1b7c178 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -357,6 +357,10 @@ android:name=".features.settings.troubleshoot.TestNotificationReceiver" android:exported="false" /> + + ) { + status = TestStatus.RUNNING + + val endpoint = UPHelper.getUpEndpoint(context) + + if (!endpoint.isNullOrEmpty()) { + status = TestStatus.SUCCESS + description = stringProvider.getString(R.string.settings_troubleshoot_test_endpoint_success, endpoint) + return + } + status = TestStatus.FAILED + description = stringProvider.getString(R.string.settings_troubleshoot_test_endpoint_failed) + } +} diff --git a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestPushFromPushGateway.kt similarity index 96% rename from vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt rename to vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestPushFromPushGateway.kt index a4a3507828..9d6a0cfe73 100644 --- a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestPushFromPushGateway.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 New Vector Ltd + * Copyright (c) 2021 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. @@ -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,7 +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.core.pushers.UPHelper import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -46,6 +45,7 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat private var action: Job? = null private var pushReceived: Boolean = false + override fun perform(activityResultLauncher: ActivityResultLauncher) { pushReceived = false UPHelper.getUpEndpoint(context) ?: run { diff --git a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestTokenRegistration.kt similarity index 91% rename from vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt rename to vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestTokenRegistration.kt index 4d1a869768..b9ca1290ff 100644 --- a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestTokenRegistration.kt @@ -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 @@ -26,7 +26,6 @@ import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.pushers.PushersManager import im.vector.app.core.resources.StringProvider -import im.vector.app.features.settings.troubleshoot.TroubleshootTest import im.vector.app.core.pushers.UPHelper import javax.inject.Inject @@ -37,7 +36,7 @@ class TestTokenRegistration @Inject constructor(private val context: AppCompatAc private val stringProvider: StringProvider, private val pushersManager: PushersManager, private val activeSessionHolder: ActiveSessionHolder) - : TroubleshootTest(R.string.settings_troubleshoot_test_token_registration_title) { + : TroubleshootTest(R.string.settings_troubleshoot_test_pusher_registration_title) { override fun perform(activityResultLauncher: ActivityResultLauncher) { // Check if we have a registered pusher for this token @@ -57,7 +56,7 @@ class TestTokenRegistration @Inject constructor(private val context: AppCompatAc it.pushKey == pushToken && it.state == PusherState.REGISTERED } if (pushers.isEmpty()) { - description = stringProvider.getString(R.string.settings_troubleshoot_test_token_registration_failed, + description = stringProvider.getString(R.string.settings_troubleshoot_test_pusher_registration_failed, stringProvider.getString(R.string.sas_error_unknown)) quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_token_registration_quick_fix) { override fun doFix() { @@ -76,7 +75,7 @@ class TestTokenRegistration @Inject constructor(private val context: AppCompatAc status = TestStatus.FAILED } else { - description = stringProvider.getString(R.string.settings_troubleshoot_test_token_registration_success) + description = stringProvider.getString(R.string.settings_troubleshoot_test_pusher_registration_success) status = TestStatus.SUCCESS } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 1e3d246e64..7f1d9e1fd3 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1110,6 +1110,12 @@ ${app_name} uses Google Play Services to deliver push messages but it doesn’t seem to be configured correctly:\n%1$s Fix Play Services + + Endpoint + Endpoint successfully retrieved:\n%1$s + Failed to retrieved Endpoint. + + Firebase Token FCM token successfully retrieved:\n%1$s Failed to retrieved FCM token:\n%1$s @@ -1121,6 +1127,12 @@ [%1$s]\nThis error is out of control of ${app_name}. There is no Google account on the phone. Please open the account manager and add a Google account. Add Account + + Pusher Registration + Pusher successfully registered to HomeServer. + Failed to register pusher to HomeServer:\n%1$s + + Token Registration FCM token successfully registered to HomeServer. Failed to register FCM token to HomeServer:\n%1$s