Skip to content

Commit

Permalink
Add FXIOS-8314 [v124] Removes all usages of apns in keychain (mozilla…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarik Eshaq authored and jjSDET committed Feb 1, 2024
1 parent 27a8b88 commit 6b0f55e
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 39 deletions.
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)
}
}
}
}

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

0 comments on commit 6b0f55e

Please sign in to comment.