Skip to content

Commit d61de8c

Browse files
committed
AINFRA-730
1 parent ae05dab commit d61de8c

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

Networking/Sources/Core/ApplicationPassword/ApplicationPasswordUseCase.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ public protocol ApplicationPasswordUseCase {
2929
func deletePassword() async throws
3030
}
3131

32+
/// A wrapper for the `UIDevice` `model` and `identifierForVendor` properties.
33+
///
34+
/// This is necessary because `UIDevice` is part of UIKit which we cannot use when targeting watchOS.
35+
/// So, to keep this package compatible with watchOS, we need to abstract UIKit away and delegate it to the consumers to provide us
36+
/// with the device information.
37+
///
38+
/// This approach is feasible because only the `applicationPasswordName` method in
39+
/// `DefaultApplicationPasswordUseCase` needs access to the information and watchOS does not need to create application
40+
/// passwords. We can therefore pass a `nil` value to it to satisfy the compilation without issues for the user experience.
41+
public struct DeviceModelIdentifierInfo {
42+
let model: String
43+
let identifierForVendor: String
44+
45+
public init(model: String, identifierForVendor: String) {
46+
self.model = model
47+
self.identifierForVendor = identifierForVendor
48+
}
49+
}
50+
3251
final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase {
3352
/// Site Address
3453
///
@@ -46,12 +65,14 @@ final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase
4665
///
4766
private let storage: ApplicationPasswordStorage
4867

68+
private let deviceModelIdentifierInfo: DeviceModelIdentifierInfo?
69+
4970
/// Used to name the password in wpadmin.
5071
///
5172
private var applicationPasswordName: String {
5273
get async {
53-
#if !os(watchOS)
5474
let bundleIdentifier = Bundle.main.bundleIdentifier ?? "Unknown"
75+
#if !os(watchOS)
5576
let model = await UIDevice.current.model
5677
let identifierForVendor = await UIDevice.current.identifierForVendor?.uuidString ?? ""
5778
return "\(bundleIdentifier).ios-app-client.\(model).\(identifierForVendor)"
@@ -65,11 +86,13 @@ final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase
6586
public init(username: String,
6687
password: String,
6788
siteAddress: String,
89+
deviceModelIdentifierInfo: DeviceModelIdentifierInfo? = nil,
6890
network: Network? = nil,
6991
keychain: Keychain = Keychain(service: WooConstants.keychainServiceName)) throws {
7092
self.siteAddress = siteAddress
7193
self.username = username
7294
self.storage = ApplicationPasswordStorage(keychain: keychain)
95+
self.deviceModelIdentifierInfo = deviceModelIdentifierInfo
7396

7497
if let network {
7598
self.network = network

WooCommerce/Classes/Authentication/AuthenticationManager.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import KeychainAccess
44
import WordPressAuthenticator
55
import WordPressUI
66
import Yosemite
7+
import UIKit
78
import class Networking.UserAgent
89
import enum Experiments.ABTest
910
import struct Networking.Settings
@@ -751,7 +752,8 @@ private extension AuthenticationManager {
751752
guard let useCase = try? DefaultApplicationPasswordUseCase(
752753
username: siteCredentials.username,
753754
password: siteCredentials.password,
754-
siteAddress: siteCredentials.siteURL
755+
siteAddress: siteCredentials.siteURL,
756+
deviceModelIdentifierInfo: UIDevice.current.deviceModelIdentifierInfo
755757
) else {
756758
return assertionFailure("⛔️ Error creating application password use case")
757759
}

WooCommerce/Classes/System/SessionManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Combine
22
import Foundation
33
import Yosemite
4+
import UIKit
45
import KeychainAccess
56
import protocol Networking.ApplicationPasswordUseCase
67
import class Networking.OneTimeApplicationPasswordUseCase
@@ -233,6 +234,7 @@ final class SessionManager: SessionManagerProtocol {
233234
return try? DefaultApplicationPasswordUseCase(username: username,
234235
password: password,
235236
siteAddress: siteAddress,
237+
deviceModelIdentifierInfo: UIDevice.current.deviceModelIdentifierInfo,
236238
keychain: keychain)
237239
case let .applicationPassword(_, _, siteAddress):
238240
return OneTimeApplicationPasswordUseCase(siteAddress: siteAddress, keychain: keychain)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Networking
2+
import UIKit
3+
4+
extension UIDevice {
5+
6+
var deviceModelIdentifierInfo: DeviceModelIdentifierInfo {
7+
DeviceModelIdentifierInfo(
8+
model: model,
9+
identifierForVendor: identifierForVendor?.uuidString ?? ""
10+
)
11+
}
12+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,7 @@
13041304
3F58701F281B947E004F7556 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3F58701E281B947E004F7556 /* Main.storyboard */; };
13051305
3F587021281B9494004F7556 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3F587020281B9494004F7556 /* LaunchScreen.storyboard */; };
13061306
3F587026281B9C19004F7556 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3F587028281B9C19004F7556 /* InfoPlist.strings */; };
1307+
3F88EC3F2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */; };
13071308
3FA96DF42C94043200CDA78F /* Yosemite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FA96DF32C94043200CDA78F /* Yosemite.framework */; };
13081309
3FF314E126FC74450012E68E /* UITestsFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FF314E026FC74450012E68E /* UITestsFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
13091310
3FF314EA26FC751B0012E68E /* XCTest+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F997173223DBCF2800592D8E /* XCTest+Extensions.swift */; };
@@ -4509,6 +4510,7 @@
45094510
3F587037281B9C50004F7556 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; };
45104511
3F587038281B9C52004F7556 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/InfoPlist.strings; sourceTree = "<group>"; };
45114512
3F64F76C2C06A3A50085DEEF /* WooCommerce.release-alpha.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "WooCommerce.release-alpha.xcconfig"; sourceTree = "<group>"; };
4513+
3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+DeviceModelIdentifierInfo.swift"; sourceTree = "<group>"; };
45124514
3FA96DF32C94043200CDA78F /* Yosemite.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Yosemite.framework; sourceTree = BUILT_PRODUCTS_DIR; };
45134515
3FF314D626FC55DE0012E68E /* ScreenObject+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ScreenObject+Extension.swift"; sourceTree = "<group>"; };
45144516
3FF314DE26FC74450012E68E /* UITestsFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UITestsFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -11131,6 +11133,7 @@
1113111133
DE6906E627D74A1900735E3B /* WooSplitViewController.swift */,
1113211134
26A7C8782BE91F3D00382627 /* WatchDependenciesSynchronizer.swift */,
1113311135
26B249702BEC801400730730 /* WatchDependencies.swift */,
11136+
3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */,
1113411137
);
1113511138
path = System;
1113611139
sourceTree = "<group>";
@@ -16512,6 +16515,7 @@
1651216515
02CE4304276993DA0006EAEF /* CaptureDevicePermissionChecker.swift in Sources */,
1651316516
205B7ECD2C19FD2F00D14A36 /* PointOfSaleCardPresentPaymentDisplayReaderMessageMessageViewModel.swift in Sources */,
1651416517
DEF8CF1F29AC870A00800A60 /* WPComEmailLoginViewModel.swift in Sources */,
16518+
3F88EC3F2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift in Sources */,
1651516519
74A33D8021C3F234009E25DE /* LicensesViewController.swift in Sources */,
1651616520
454453CA27566CDE00464AC5 /* HubMenuViewModel.swift in Sources */,
1651716521
934CB123224EAB150005CCB9 /* main.swift in Sources */,

0 commit comments

Comments
 (0)