-
Notifications
You must be signed in to change notification settings - Fork 860
ANR when asking to select the notification method #7675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9456789
Adding changelog entry
4dbca78
Adding new use cases to handle the Unified push registration
2890f41
Replacing unregister method by usecase
58efe90
Removing some debug logs
b29191e
Using use cases inside component for endpoint testing
3f944e9
Extracting the logic to toggle notifications for device into a ViewModel
95556d2
Change the distributor in dialog cancellation only if there is no exi…
2673979
Handling change of notification method
740ed89
Removing the old methods from helper
aa3a808
Do not ask to select push distributor in home if notifications are di…
a3815d7
Update unit tests
46ccf4d
Adding unit tests for register and unregister use cases
2a8c72b
Fixing code style issues
e78e192
Adding unit tests for FCM token retrieval
d31652e
Adding unit tests for settings ViewModel
f8c59f6
Removing unused import
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ANR when asking to select the notification method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
vector/src/main/java/im/vector/app/core/pushers/EnsureFcmTokenIsRetrievedUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * 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.core.pushers | ||
|
|
||
| import im.vector.app.core.di.ActiveSessionHolder | ||
| import javax.inject.Inject | ||
|
|
||
| class EnsureFcmTokenIsRetrievedUseCase @Inject constructor( | ||
| private val unifiedPushHelper: UnifiedPushHelper, | ||
| private val fcmHelper: FcmHelper, | ||
| private val activeSessionHolder: ActiveSessionHolder, | ||
| ) { | ||
|
|
||
| fun execute(pushersManager: PushersManager, registerPusher: Boolean) { | ||
| if (unifiedPushHelper.isEmbeddedDistributor()) { | ||
| fcmHelper.ensureFcmTokenIsRetrieved(pushersManager, shouldAddHttpPusher(registerPusher)) | ||
| } | ||
| } | ||
|
|
||
| private fun shouldAddHttpPusher(registerPusher: Boolean) = if (registerPusher) { | ||
| val currentSession = activeSessionHolder.getActiveSession() | ||
| val currentPushers = currentSession.pushersService().getPushers() | ||
| currentPushers.none { it.deviceId == currentSession.sessionParams.deviceId } | ||
| } else { | ||
| false | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
vector/src/main/java/im/vector/app/core/pushers/RegisterUnifiedPushUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * 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.core.pushers | ||
|
|
||
| import android.content.Context | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import im.vector.app.features.VectorFeatures | ||
| import org.unifiedpush.android.connector.UnifiedPush | ||
| import javax.inject.Inject | ||
|
|
||
| class RegisterUnifiedPushUseCase @Inject constructor( | ||
| @ApplicationContext private val context: Context, | ||
| private val vectorFeatures: VectorFeatures, | ||
| ) { | ||
|
|
||
| sealed interface RegisterUnifiedPushResult { | ||
| object Success : RegisterUnifiedPushResult | ||
| object NeedToAskUserForDistributor : RegisterUnifiedPushResult | ||
| } | ||
|
|
||
| fun execute(distributor: String = ""): RegisterUnifiedPushResult { | ||
| if (distributor.isNotEmpty()) { | ||
| saveAndRegisterApp(distributor) | ||
| return RegisterUnifiedPushResult.Success | ||
| } | ||
|
|
||
| if (!vectorFeatures.allowExternalUnifiedPushDistributors()) { | ||
| saveAndRegisterApp(context.packageName) | ||
| return RegisterUnifiedPushResult.Success | ||
| } | ||
|
|
||
| if (UnifiedPush.getDistributor(context).isNotEmpty()) { | ||
| registerApp() | ||
| return RegisterUnifiedPushResult.Success | ||
| } | ||
|
|
||
| val distributors = UnifiedPush.getDistributors(context) | ||
|
|
||
| return if (distributors.size == 1) { | ||
| saveAndRegisterApp(distributors.first()) | ||
| RegisterUnifiedPushResult.Success | ||
| } else { | ||
| RegisterUnifiedPushResult.NeedToAskUserForDistributor | ||
| } | ||
| } | ||
|
|
||
| private fun saveAndRegisterApp(distributor: String) { | ||
| UnifiedPush.saveDistributor(context, distributor) | ||
| registerApp() | ||
| } | ||
|
|
||
| private fun registerApp() { | ||
| UnifiedPush.registerApp(context) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
checkPlayServicescan display a dialog, and so needs an Activity. I will try running your code on an emulator without the PlayServices.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understood, we only use the checking method GoogleApiAvailability.isGooglePlayServicesAvailable(context). This method only requires a
Context. In case of error, we display a toast which only requires aContextas well.