Make UnifiedPushHelper a regular class and inject the context in the constructor to clean up the API

This commit is contained in:
Benoit Marty 2022-06-01 15:53:22 +02:00 committed by Benoit Marty
parent 96acb61fa1
commit 674e3a72c4
14 changed files with 150 additions and 130 deletions

View file

@ -36,6 +36,7 @@ import im.vector.app.features.settings.troubleshoot.TestUnifiedPushGateway
import javax.inject.Inject
class NotificationTroubleshootTestManagerFactory @Inject constructor(
private val unifiedPushHelper: UnifiedPushHelper,
private val testSystemSettings: TestSystemSettings,
private val testAccountSettings: TestAccountSettings,
private val testDeviceSettings: TestDeviceSettings,
@ -62,7 +63,7 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
mgr.addTest(testAvailableUnifiedPushDistributors)
mgr.addTest(testCurrentUnifiedPushDistributor)
}
if (UnifiedPushHelper.isBackgroundSync(fragment.requireContext())) {
if (unifiedPushHelper.isBackgroundSync()) {
mgr.addTest(testAutoStartBoot)
mgr.addTest(testBackgroundRestrictions)
mgr.addTest(testBatteryOptimization)

View file

@ -36,6 +36,7 @@ import im.vector.app.gplay.features.settings.troubleshoot.TestTokenRegistration
import javax.inject.Inject
class NotificationTroubleshootTestManagerFactory @Inject constructor(
private val unifiedPushHelper: UnifiedPushHelper,
private val testSystemSettings: TestSystemSettings,
private val testAccountSettings: TestAccountSettings,
private val testDeviceSettings: TestDeviceSettings,
@ -62,7 +63,7 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor(
mgr.addTest(testAvailableUnifiedPushDistributors)
mgr.addTest(testCurrentUnifiedPushDistributor)
}
if (UnifiedPushHelper.isEmbeddedDistributor(fragment.requireContext())) {
if (unifiedPushHelper.isEmbeddedDistributor()) {
mgr.addTest(testPlayServices)
mgr.addTest(testFirebaseToken)
mgr.addTest(testTokenRegistration)

View file

@ -16,7 +16,6 @@
package im.vector.app.core.pushers
import android.content.Context
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.resources.AppNameProvider
@ -30,18 +29,19 @@ import kotlin.math.abs
private const val DEFAULT_PUSHER_FILE_TAG = "mobile"
class PushersManager @Inject constructor(
private val unifiedPushHelper: UnifiedPushHelper,
private val activeSessionHolder: ActiveSessionHolder,
private val localeProvider: LocaleProvider,
private val stringProvider: StringProvider,
private val appNameProvider: AppNameProvider
private val appNameProvider: AppNameProvider,
) {
suspend fun testPush(context: Context) {
suspend fun testPush() {
val currentSession = activeSessionHolder.getActiveSession()
currentSession.pushersService().testPush(
UnifiedPushHelper.getPushGateway(context)!!,
unifiedPushHelper.getPushGateway()!!,
stringProvider.getString(R.string.pusher_app_id),
UnifiedPushHelper.getEndpointOrToken(context) ?: "",
unifiedPushHelper.getEndpointOrToken() ?: "",
TEST_EVENT_ID
)
}

View file

@ -27,6 +27,7 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.di.DefaultSharedPreferences
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.settings.BackgroundSyncMode
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.push.fcm.FcmHelper
@ -39,10 +40,17 @@ import okhttp3.Request
import org.unifiedpush.android.connector.UnifiedPush
import timber.log.Timber
import java.net.URL
import javax.inject.Inject
class UnifiedPushHelper @Inject constructor(
private val context: Context,
private val stringProvider: StringProvider,
) {
companion object {
private const val PREFS_ENDPOINT_OR_TOKEN = "UP_ENDPOINT_OR_TOKEN"
private const val PREFS_PUSH_GATEWAY = "PUSH_GATEWAY"
}
object UnifiedPushHelper {
private const val PREFS_ENDPOINT_OR_TOKEN = "UP_ENDPOINT_OR_TOKEN"
private const val PREFS_PUSH_GATEWAY = "PUSH_GATEWAY"
private val up = UnifiedPush
/**
@ -50,7 +58,7 @@ object UnifiedPushHelper {
*
* @return the UnifiedPush Endpoint or null if not received
*/
fun getEndpointOrToken(context: Context): String? {
fun getEndpointOrToken(): String? {
return DefaultSharedPreferences.getInstance(context).getString(PREFS_ENDPOINT_OR_TOKEN, null)
}
@ -58,11 +66,9 @@ object UnifiedPushHelper {
* Store UnifiedPush Endpoint to the SharedPrefs.
* TODO Store in realm
*
* @param context android context
* @param endpoint the endpoint to store
*/
fun storeUpEndpoint(context: Context,
endpoint: String?) {
fun storeUpEndpoint(endpoint: String?) {
DefaultSharedPreferences.getInstance(context).edit {
putString(PREFS_ENDPOINT_OR_TOKEN, endpoint)
}
@ -73,7 +79,7 @@ object UnifiedPushHelper {
*
* @return the Push Gateway or null if not defined
*/
fun getPushGateway(context: Context): String? {
fun getPushGateway(): String? {
return DefaultSharedPreferences.getInstance(context).getString(PREFS_PUSH_GATEWAY, null)
}
@ -81,26 +87,26 @@ object UnifiedPushHelper {
* Store Push Gateway to the SharedPrefs.
* TODO Store in realm
*
* @param context android context
* @param gateway the push gateway to store
*/
private fun storePushGateway(context: Context,
gateway: String?) {
private fun storePushGateway(gateway: String?) {
DefaultSharedPreferences.getInstance(context).edit {
putString(PREFS_PUSH_GATEWAY, gateway)
}
}
fun register(context: Context, onDoneRunnable: Runnable? = null) {
gRegister(context,
onDoneRunnable = onDoneRunnable)
fun register(onDoneRunnable: Runnable? = null) {
gRegister(
onDoneRunnable = onDoneRunnable
)
}
fun reRegister(context: Context,
pushersManager: PushersManager,
vectorPreferences: VectorPreferences,
onDoneRunnable: Runnable? = null) {
gRegister(context,
fun reRegister(
pushersManager: PushersManager,
vectorPreferences: VectorPreferences,
onDoneRunnable: Runnable? = null
) {
gRegister(
force = true,
pushersManager = pushersManager,
vectorPreferences = vectorPreferences,
@ -108,11 +114,12 @@ object UnifiedPushHelper {
)
}
private fun gRegister(context: Context,
force: Boolean = false,
pushersManager: PushersManager? = null,
vectorPreferences: VectorPreferences? = null,
onDoneRunnable: Runnable? = null) {
private fun gRegister(
force: Boolean = false,
pushersManager: PushersManager? = null,
vectorPreferences: VectorPreferences? = null,
onDoneRunnable: Runnable? = null
) {
if (!BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) {
up.saveDistributor(context, context.packageName)
up.registerApp(context)
@ -121,7 +128,7 @@ object UnifiedPushHelper {
}
if (force) {
// Un-register first
unregister(context, pushersManager, vectorPreferences)
unregister(pushersManager, vectorPreferences)
}
if (up.getDistributor(context).isNotEmpty()) {
up.registerApp(context)
@ -134,9 +141,9 @@ object UnifiedPushHelper {
val distributors = up.getDistributors(context).toMutableList()
val internalDistributorName = if (FcmHelper.isPushSupported()) {
context.getString(R.string.unifiedpush_distributor_fcm_fallback)
stringProvider.getString(R.string.unifiedpush_distributor_fcm_fallback)
} else {
context.getString(R.string.unifiedpush_distributor_background_sync)
stringProvider.getString(R.string.unifiedpush_distributor_background_sync)
}
if (distributors.size == 1 &&
@ -146,7 +153,7 @@ object UnifiedPushHelper {
onDoneRunnable?.run()
} else {
val builder: AlertDialog.Builder = MaterialAlertDialogBuilder(context)
builder.setTitle(context.getString(R.string.unifiedpush_getdistributors_dialog_title))
builder.setTitle(stringProvider.getString(R.string.unifiedpush_getdistributors_dialog_title))
val distributorsArray = distributors.toTypedArray()
val distributorsNameArray = distributorsArray.map {
@ -180,7 +187,6 @@ object UnifiedPushHelper {
}
fun unregister(
context: Context,
pushersManager: PushersManager? = null,
vectorPreferences: VectorPreferences? = null
) {
@ -188,13 +194,13 @@ object UnifiedPushHelper {
vectorPreferences?.setFdroidSyncBackgroundMode(mode)
runBlocking {
try {
pushersManager?.unregisterPusher(getEndpointOrToken(context) ?: "")
pushersManager?.unregisterPusher(getEndpointOrToken() ?: "")
} catch (e: Exception) {
Timber.d("Probably unregistering a non existant pusher")
}
}
storeUpEndpoint(context, null)
storePushGateway(context, null)
storeUpEndpoint(null)
storePushGateway(null)
up.unregisterApp(context)
}
@ -209,21 +215,21 @@ object UnifiedPushHelper {
)
fun storeCustomOrDefaultGateway(
context: Context,
endpoint: String,
onDoneRunnable: Runnable? = null) {
onDoneRunnable: Runnable? = null
) {
// if we use the embedded distributor,
// register app_id type upfcm on sygnal
// the pushkey if FCM key
if (up.getDistributor(context) == context.packageName) {
context.getString(R.string.pusher_http_url).let {
storePushGateway(context, it)
stringProvider.getString(R.string.pusher_http_url).let {
storePushGateway(it)
onDoneRunnable?.run()
return
}
}
// else, unifiedpush, and pushkey is an endpoint
val gateway = context.getString(R.string.default_push_gateway_http_url)
val gateway = stringProvider.getString(R.string.default_push_gateway_http_url)
val parsed = URL(endpoint)
val custom = "${parsed.protocol}://${parsed.host}/_matrix/push/v1/notify"
Timber.i("Testing $custom")
@ -236,39 +242,39 @@ object UnifiedPushHelper {
val request = Request.Builder()
.url(custom)
.build()
val sResponse = client.newCall(request).execute()
.body?.string() ?: ""
moshi.adapter(DiscoveryResponse::class.java)
.fromJson(sResponse)?.let { response ->
if (response.unifiedpush.gateway == "matrix") {
Timber.d("Using custom gateway")
storePushGateway(context, custom)
onDoneRunnable?.run()
return@launch
}
val sResponse = client.newCall(request).execute()
.body?.string() ?: ""
moshi.adapter(DiscoveryResponse::class.java)
.fromJson(sResponse)?.let { response ->
if (response.unifiedpush.gateway == "matrix") {
Timber.d("Using custom gateway")
storePushGateway(custom)
onDoneRunnable?.run()
return@launch
}
}
} catch (e: Exception) {
Timber.d("Cannot try custom gateway: $e")
}
storePushGateway(context, gateway)
storePushGateway(gateway)
onDoneRunnable?.run()
return@launch
}
thread.start()
}
fun getExternalDistributors(context: Context): List<String> {
val distributors = up.getDistributors(context).toMutableList()
fun getExternalDistributors(): 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)
fun getCurrentDistributorName(): String {
if (isEmbeddedDistributor()) {
return stringProvider.getString(R.string.unifiedpush_distributor_fcm_fallback)
}
if (isBackgroundSync(context)) {
return context.getString(R.string.unifiedpush_distributor_background_sync)
if (isBackgroundSync()) {
return stringProvider.getString(R.string.unifiedpush_distributor_background_sync)
}
val distributor = up.getDistributor(context)
return try {
@ -279,20 +285,20 @@ object UnifiedPushHelper {
} as String
}
fun isEmbeddedDistributor(context: Context): Boolean {
fun isEmbeddedDistributor(): Boolean {
return (up.getDistributor(context) == context.packageName &&
FcmHelper.isPushSupported())
}
fun isBackgroundSync(context: Context): Boolean {
fun isBackgroundSync(): Boolean {
return (up.getDistributor(context) == context.packageName &&
!FcmHelper.isPushSupported())
}
fun getPrivacyFriendlyUpEndpoint(context: Context): String? {
val endpoint = getEndpointOrToken(context)
fun getPrivacyFriendlyUpEndpoint(): String? {
val endpoint = getEndpointOrToken()
if (endpoint.isNullOrEmpty()) return endpoint
if (isEmbeddedDistributor(context)) {
if (isEmbeddedDistributor()) {
return endpoint
}
return try {

View file

@ -85,6 +85,7 @@ class VectorMessagingReceiver : MessagingReceiver() {
@Inject lateinit var vectorDataStore: VectorDataStore
@Inject lateinit var wifiDetector: WifiDetector
@Inject lateinit var guardServiceStarter: GuardServiceStarter
@Inject lateinit var unifiedPushHelper: UnifiedPushHelper
private val coroutineScope = CoroutineScope(SupervisorJob())
@ -116,7 +117,7 @@ class VectorMessagingReceiver : MessagingReceiver() {
.build()
lateinit var notification: Notification
if (UnifiedPushHelper.isEmbeddedDistributor(context)) {
if (unifiedPushHelper.isEmbeddedDistributor()) {
notification = moshi.adapter(Notification::class.java)
.fromJson(sMessage) ?: return
} else {
@ -159,10 +160,10 @@ class VectorMessagingReceiver : MessagingReceiver() {
if (vectorPreferences.areNotificationEnabledForDevice() && activeSessionHolder.hasActiveSession()) {
// If the endpoint has changed
// or the gateway has changed
if (UnifiedPushHelper.getEndpointOrToken(context) != endpoint) {
UnifiedPushHelper.storeUpEndpoint(context, endpoint)
UnifiedPushHelper.storeCustomOrDefaultGateway(context, endpoint) {
UnifiedPushHelper.getPushGateway(context)?.let {
if (unifiedPushHelper.getEndpointOrToken() != endpoint) {
unifiedPushHelper.storeUpEndpoint(endpoint)
unifiedPushHelper.storeCustomOrDefaultGateway(endpoint) {
unifiedPushHelper.getPushGateway()?.let {
pushersManager.enqueueRegisterPusher(endpoint, it)
}
}
@ -189,7 +190,7 @@ class VectorMessagingReceiver : MessagingReceiver() {
guardServiceStarter.start()
runBlocking {
try {
pushersManager.unregisterPusher(UnifiedPushHelper.getEndpointOrToken(context) ?: "")
pushersManager.unregisterPusher(unifiedPushHelper.getEndpointOrToken() ?: "")
} catch (e: Exception) {
Timber.tag(loggerTag.value).d("Probably unregistering a non existant pusher")
}

View file

@ -72,7 +72,8 @@ private val loggerTag = LoggerTag("WebRtcCallManager", LoggerTag.VOIP)
class WebRtcCallManager @Inject constructor(
private val context: Context,
private val activeSessionDataSource: ActiveSessionDataSource,
private val analyticsTracker: AnalyticsTracker
private val analyticsTracker: AnalyticsTracker,
private val unifiedPushHelper: UnifiedPushHelper,
) : CallListener,
DefaultLifecycleObserver {
@ -272,7 +273,7 @@ class WebRtcCallManager @Inject constructor(
audioManager.setMode(CallAudioManager.Mode.DEFAULT)
// did we start background sync? so we should stop it
if (isInBackground) {
if (!UnifiedPushHelper.isBackgroundSync(context)) {
if (!unifiedPushHelper.isBackgroundSync()) {
currentSession?.syncService()?.stopAnyBackgroundSync()
} else {
// for fdroid we should not stop, it should continue syncing
@ -378,7 +379,7 @@ class WebRtcCallManager @Inject constructor(
// and thus won't be able to received events. For example if the call is
// accepted on an other session this device will continue ringing
if (isInBackground) {
if (!UnifiedPushHelper.isBackgroundSync(context)) {
if (!unifiedPushHelper.isBackgroundSync()) {
// only for push version as fdroid version is already doing it?
currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0)
} else {

View file

@ -128,6 +128,7 @@ class HomeActivity :
@Inject lateinit var avatarRenderer: AvatarRenderer
@Inject lateinit var initSyncStepFormatter: InitSyncStepFormatter
@Inject lateinit var appStateHandler: AppStateHandler
@Inject lateinit var unifiedPushHelper: UnifiedPushHelper
private val createSpaceResultLauncher = registerStartForActivityResult { activityResult ->
if (activityResult.resultCode == Activity.RESULT_OK) {
@ -188,8 +189,8 @@ class HomeActivity :
super.onCreate(savedInstanceState)
analyticsScreenName = MobileScreen.ScreenName.Home
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
UnifiedPushHelper.register(this) {
if (UnifiedPushHelper.isEmbeddedDistributor(this)) {
unifiedPushHelper.register {
if (unifiedPushHelper.isEmbeddedDistributor()) {
FcmHelper.ensureFcmTokenIsRetrieved(
this,
pushManager,

View file

@ -63,6 +63,7 @@ import javax.inject.Inject
// Referenced in vector_settings_preferences_root.xml
class VectorSettingsNotificationPreferenceFragment @Inject constructor(
private val unifiedPushHelper: UnifiedPushHelper,
private val pushersManager: PushersManager,
private val activeSessionHolder: ActiveSessionHolder,
private val vectorPreferences: VectorPreferences,
@ -99,10 +100,9 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)?.let {
it.setTransactionalSwitchChangeListener(lifecycleScope) { isChecked ->
if (isChecked) {
UnifiedPushHelper.register(requireContext())
unifiedPushHelper.register()
} else {
UnifiedPushHelper.unregister(
requireContext(),
unifiedPushHelper.unregister(
pushersManager,
vectorPreferences
)
@ -152,8 +152,7 @@ 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.reRegister(
requireContext(),
unifiedPushHelper.reRegister(
pushersManager,
vectorPreferences
) {
@ -241,7 +240,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
}
findPreference<VectorPreferenceCategory>(VectorPreferences.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY)?.let {
it.isVisible = UnifiedPushHelper.isBackgroundSync(requireContext())
it.isVisible = unifiedPushHelper.isBackgroundSync()
}
val backgroundSyncEnabled = vectorPreferences.isBackgroundSyncEnabled()
@ -350,7 +349,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
private fun refreshPref() {
// This pref may have change from troubleshoot pref fragment
if (UnifiedPushHelper.isBackgroundSync(requireContext())) {
if (unifiedPushHelper.isBackgroundSync()) {
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_START_ON_BOOT_PREFERENCE_KEY)
?.isChecked = vectorPreferences.autoStartOnBoot()
}

View file

@ -18,19 +18,19 @@ 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) {
class TestAvailableUnifiedPushDistributors @Inject constructor(
private val unifiedPushHelper: UnifiedPushHelper,
private val stringProvider: StringProvider,
) : TroubleshootTest(R.string.settings_troubleshoot_test_distributors_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
val distributors = UnifiedPushHelper.getExternalDistributors(context)
val distributors = unifiedPushHelper.getExternalDistributors()
if (distributors.isEmpty()) {
description = if (FcmHelper.isPushSupported()) {
stringProvider.getString(R.string.settings_troubleshoot_test_distributors_gplay)
@ -39,8 +39,10 @@ class TestAvailableUnifiedPushDistributors @Inject constructor(private val conte
}
status = TestStatus.SUCCESS
} else {
description = stringProvider.getString(R.string.settings_troubleshoot_test_distributors_many,
distributors.size + 1)
description = stringProvider.getString(
R.string.settings_troubleshoot_test_distributors_many,
distributors.size + 1
)
status = TestStatus.SUCCESS
}
}

View file

@ -18,19 +18,21 @@ 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) {
class TestCurrentUnifiedPushDistributor @Inject constructor(
private val unifiedPushHelper: UnifiedPushHelper,
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))
description = stringProvider.getString(
R.string.settings_troubleshoot_test_current_distributor,
unifiedPushHelper.getCurrentDistributorName()
)
status = TestStatus.SUCCESS
}
}

View file

@ -31,16 +31,18 @@ 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) {
class TestEndpointAsTokenRegistration @Inject constructor(
private val context: FragmentActivity,
private val stringProvider: StringProvider,
private val pushersManager: PushersManager,
private val vectorPreferences: VectorPreferences,
private val activeSessionHolder: ActiveSessionHolder,
private val unifiedPushHelper: UnifiedPushHelper,
) : 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 {
val endpoint = unifiedPushHelper.getEndpointOrToken() ?: run {
status = TestStatus.FAILED
return
}
@ -52,12 +54,13 @@ class TestEndpointAsTokenRegistration @Inject constructor(private val context: F
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))
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,
unifiedPushHelper.reRegister(
pushersManager,
vectorPreferences
)

View file

@ -17,7 +17,6 @@ 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.di.ActiveSessionHolder
import im.vector.app.core.error.ErrorFormatter
@ -34,12 +33,12 @@ 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) :
TroubleshootTest(R.string.settings_troubleshoot_test_push_loop_title) {
class TestPushFromPushGateway @Inject constructor(
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
private var pushReceived: Boolean = false
@ -47,7 +46,7 @@ class TestPushFromPushGateway @Inject constructor(private val context: FragmentA
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
pushReceived = false
action = activeSessionHolder.getActiveSession().coroutineScope.launch {
val result = runCatching { pushersManager.testPush(context) }
val result = runCatching { pushersManager.testPush() }
withContext(Dispatchers.Main) {
status = result

View file

@ -18,21 +18,23 @@ 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) {
class TestUnifiedPushEndpoint @Inject constructor(
private val stringProvider: StringProvider,
private val unifiedPushHelper: UnifiedPushHelper,
) : TroubleshootTest(R.string.settings_troubleshoot_test_current_endpoint_title) {
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
val endpoint = UnifiedPushHelper.getPrivacyFriendlyUpEndpoint(context)
val endpoint = unifiedPushHelper.getPrivacyFriendlyUpEndpoint()
endpoint?.let {
description = stringProvider.getString(R.string.settings_troubleshoot_test_current_endpoint_success,
UnifiedPushHelper.getPrivacyFriendlyUpEndpoint(context))
description = stringProvider.getString(
R.string.settings_troubleshoot_test_current_endpoint_success,
unifiedPushHelper.getPrivacyFriendlyUpEndpoint()
)
status = TestStatus.SUCCESS
} ?: run {
description = stringProvider.getString(R.string.settings_troubleshoot_test_current_endpoint_failed)

View file

@ -18,19 +18,21 @@ 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) {
class TestUnifiedPushGateway @Inject constructor(
private val unifiedPushHelper: UnifiedPushHelper,
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))
description = stringProvider.getString(
R.string.settings_troubleshoot_test_current_gateway,
unifiedPushHelper.getPushGateway()
)
status = TestStatus.SUCCESS
}
}