Skip to content
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

Add FXIOS-8314 [v124]: Removes all usages of apns in keychain #18430

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions firefox-ios/Account/FxAPushMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import Common
let PendingAccountDisconnectedKey = "PendingAccountDisconnect"

/// This class provides handles push messages from FxA.
/// For reference, the [message schema][0] and [Android implementation][1] are both useful resources.
/// [0]: https://github.com/mozilla/fxa-auth-server/blob/master/docs/pushpayloads.schema.json#L26
/// [1]: https://dxr.mozilla.org/mozilla-central/source/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountPushHandler.java
/// The main entry points are `handle` methods, to accept the raw APNS `userInfo` and then to process
/// the resulting JSON.
/// The main entry point is the `handleDecryptedMessage` method to accept the decrypted push message and parse it into a
/// `PushMessage`
class FxAPushMessageHandler {
let profile: Profile
private let logger: Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,20 @@ extension AppDelegate {
}
}

// If we see our local device with a pushEndpointExpired flag, clear the APNS token and re-register.
// If we see our local device with a pushEndpointExpired flag, try to re-register.
NotificationCenter.default.addObserver(
forName: .constellationStateUpdate,
object: nil,
queue: nil
) { notification in
if let newState = notification.userInfo?["newState"] as? ConstellationState {
if newState.localDevice?.pushEndpointExpired ?? false {
MZKeychainWrapper.sharedClientAppContainerKeychain.removeObject(
forKey: KeychainKey.apnsToken,
withAccessibility: MZKeychainItemAccessibility.afterFirstUnlock
)
NotificationCenter.default.post(name: .RegisterForPushNotifications, object: nil)
// Our endpoint expired, we should check for missed messages
self.profile.pollCommands(forcePoll: true)
}
}
}

// Use sync event as a periodic check for the apnsToken.
// The notification service extension can clear this token if there is an error,
// and the main app can detect this and re-register.
NotificationCenter.default.addObserver(forName: .ProfileDidStartSyncing, object: nil, queue: .main) { _ in
let kc = MZKeychainWrapper.sharedClientAppContainerKeychain
if kc.string(
forKey: KeychainKey.apnsToken,
withAccessibility: MZKeychainItemAccessibility.afterFirstUnlock
) == nil {
NotificationCenter.default.post(name: .RegisterForPushNotifications, object: nil)
}
}
Comment on lines -74 to -82
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably led to users having to update their push notification every sync because the apns token will be nil for any user who didn't migrate from the before times.

We don't need to try to re-register for push notifications every sync, there are already recovery mechanisms if a user's push subscriptions change

}
}

Expand Down
4 changes: 0 additions & 4 deletions firefox-ios/RustFxA/FxAWebViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ extension FxAWebViewModel {
// or if the onboarding flow is missing the notifications card
guard self.shouldAskForNotificationPermission else { return }

MZKeychainWrapper.sharedClientAppContainerKeychain.removeObject(
forKey: KeychainKey.apnsToken,
withAccessibility: MZKeychainItemAccessibility.afterFirstUnlock
)
NotificationManager().requestAuthorization { granted, error in
guard error == nil else { return }
if granted {
Expand Down
4 changes: 0 additions & 4 deletions firefox-ios/RustFxA/PushNotificationSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import MozillaAppServices
open class PushNotificationSetup {
/// Disables FxA push notifications for the user
public func disableNotifications() {
MZKeychainWrapper.sharedClientAppContainerKeychain.removeObject(
forKey: KeychainKey.apnsToken,
withAccessibility: .afterFirstUnlock
)
if let accountManager = RustFirefoxAccounts.shared.accountManager {
let subscriptionEndpoint = accountManager.deviceConstellation()?
.state()?.localDevice?.pushSubscription?.endpoint
Expand Down
4 changes: 0 additions & 4 deletions firefox-ios/RustFxA/RustFirefoxAccounts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ open class RustFirefoxAccounts {
prefs?.removeObjectForKey(prefKeyCachedUserProfile)
prefs?.removeObjectForKey(PendingAccountDisconnectedKey)
cachedUserProfile = nil
MZKeychainWrapper.sharedClientAppContainerKeychain.removeObject(
forKey: KeychainKey.apnsToken,
withAccessibility: .afterFirstUnlock
)
}

public func hasAccount(completion: @escaping (Bool) -> Void) {
Expand Down
4 changes: 0 additions & 4 deletions firefox-ios/Shared/AppConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public enum KVOConstants: String {
case contentSize
}

public struct KeychainKey {
public static let apnsToken = "apnsToken"
}

public class AppConstants {
// Any type of tests (UI and Unit)
public static let isRunningTest = NSClassFromString("XCTestCase") != nil
Expand Down