From 6229611d5705ca93fedfa047d20a9c23db55f7e6 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Thu, 11 Jun 2026 19:56:32 -0500 Subject: [PATCH 1/3] obj-c: expose setOsVersion/setOsBuild on ODWSemanticContext The Obj-C/iOS wrapper exposed app/user/device context setters but no way to override the OS version, so iOS clients could not set DeviceInfo.OsVersion (Common Schema `ext.os.ver`) themselves -- the gap reported in #1093. The C++ core already provides ISemanticContext::SetOsVersion/SetOsBuild; this wires them through the wrapper. - ODWSemanticContext.h/.mm: add setOsVersion: and setOsBuild:, forwarding to the wrapped ISemanticContext (mirrors the existing setDeviceId pattern). - ODWSemanticContextTests.mm: add testSetOsVersion and testSetOsBuild, with the test mock capturing SetOsVersion/SetOsBuild. Note: per the #1093 discussion, in the CS3 schema `ext.os.ver` is populated from the OS build (COMMONFIELDS_OS_BUILD), so both setters are exposed. Resolves #1093. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../unittests/obj-c/ODWSemanticContextTests.mm | 18 ++++++++++++++++++ wrappers/obj-c/ODWSemanticContext.h | 15 +++++++++++++++ wrappers/obj-c/ODWSemanticContext.mm | 12 ++++++++++++ 3 files changed, 45 insertions(+) diff --git a/tests/unittests/obj-c/ODWSemanticContextTests.mm b/tests/unittests/obj-c/ODWSemanticContextTests.mm index 143cb1896..0096dec74 100644 --- a/tests/unittests/obj-c/ODWSemanticContextTests.mm +++ b/tests/unittests/obj-c/ODWSemanticContextTests.mm @@ -22,11 +22,15 @@ virtual void SetUserId(const std::string& userId, PiiKind) override { m_userId = userId; } virtual void SetUserAdvertisingId(const std::string& userAdvertisingId) override { m_userAdvertisingId = userAdvertisingId; } virtual void SetAppExperimentETag(const std::string& eTag) override { m_eTag = eTag; } + virtual void SetOsVersion(const std::string& osVersion) override { m_osVersion = osVersion; } + virtual void SetOsBuild(const std::string& osBuild) override { m_osBuild = osBuild; } std::string m_appId {}; std::string m_userId {}; std::string m_userAdvertisingId {}; std::string m_eTag {}; + std::string m_osVersion {}; + std::string m_osBuild {}; }; @interface ODWSemanticContextTests : XCTestCase @@ -63,4 +67,18 @@ - (void)testSetETag { XCTAssertEqual(nativeContext.m_eTag, "myETag"); } +- (void)testSetOsVersion { + TestSemanticContext nativeContext; + ODWSemanticContext* context = [[ODWSemanticContext alloc] initWithISemanticContext:&nativeContext]; + [context setOsVersion:@"10.0.19041"]; + XCTAssertEqual(nativeContext.m_osVersion, "10.0.19041"); +} + +- (void)testSetOsBuild { + TestSemanticContext nativeContext; + ODWSemanticContext* context = [[ODWSemanticContext alloc] initWithISemanticContext:&nativeContext]; + [context setOsBuild:@"19041.1234"]; + XCTAssertEqual(nativeContext.m_osBuild, "19041.1234"); +} + @end diff --git a/wrappers/obj-c/ODWSemanticContext.h b/wrappers/obj-c/ODWSemanticContext.h index bd47d0917..57e7c0d6a 100644 --- a/wrappers/obj-c/ODWSemanticContext.h +++ b/wrappers/obj-c/ODWSemanticContext.h @@ -53,6 +53,21 @@ NS_ASSUME_NONNULL_BEGIN */ -(void) setDeviceId:(nonnull NSString*)deviceId; +/*! + @brief Set the operating system version context information of telemetry event. + @details Overrides the OS version that the SDK populates automatically (Common Schema field `ext.os.ver`). + @param osVersion A string that contains the operating system version. + */ +-(void) setOsVersion:(nonnull NSString*)osVersion; + +/*! + @brief Set the operating system build context information of telemetry event. + @details In the CS3 schema the OS version field (`ext.os.ver`) is populated from the OS build, + so set this if setOsVersion: alone does not update `ext.os.ver`. + @param osBuild A string that contains the operating system build. + */ +-(void) setOsBuild:(nonnull NSString*)osBuild; + /*! @brief Set the user time zone context information of telemetry event. @param userTimeZone user's time zone relative to UTC, in ISO 8601 time zone format diff --git a/wrappers/obj-c/ODWSemanticContext.mm b/wrappers/obj-c/ODWSemanticContext.mm index e1077b908..d942873fd 100644 --- a/wrappers/obj-c/ODWSemanticContext.mm +++ b/wrappers/obj-c/ODWSemanticContext.mm @@ -64,6 +64,18 @@ -(void) setDeviceId:(nonnull NSString*)deviceId _wrappedSemanticContext->SetDeviceId(strDeviceId); } +-(void) setOsVersion:(nonnull NSString*)osVersion +{ + std::string strOsVersion = std::string([osVersion UTF8String]); + _wrappedSemanticContext->SetOsVersion(strOsVersion); +} + +-(void) setOsBuild:(nonnull NSString*)osBuild +{ + std::string strOsBuild = std::string([osBuild UTF8String]); + _wrappedSemanticContext->SetOsBuild(strOsBuild); +} + -(void) setUserTimeZone:(nonnull NSString*)userTimeZone { std::string strUserTimeZone = std::string([userTimeZone UTF8String]); From 790545b256b1a54b7ae9198433835642ec7fc8ec Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Sat, 13 Jun 2026 16:59:08 -0500 Subject: [PATCH 2/3] Mirror setOsVersion/setOsBuild on Swift and Xamarin iOS bindings Code review noted that PR #1093 (an iOS request) was only addressed on the Obj-C ODWSemanticContext. The repo also ships hand-written Swift (OneDSSwift) and Xamarin iOS bindings that mirror every other ODWSemanticContext setter one-to-one, so Swift and Xamarin/iOS consumers still could not set the OS version/build. Add the two setters to both bindings, forwarding to the Obj-C selectors (setOsVersion:/setOsBuild:), placed next to the device-id setter to match the Obj-C header ordering: - wrappers/swift/Sources/OneDSSwift/SemanticContext.swift: setOsVersion(_:)/ setOsBuild(_:) -> odwSemanticContext.setOsVersion/.setOsBuild - wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs: [Export("setOsVersion:")] / [Export("setOsBuild:")] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Sources/OneDSSwift/SemanticContext.swift | 24 +++++++++++++++++++ .../ApiDefinitions.cs | 8 +++++++ 2 files changed, 32 insertions(+) diff --git a/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift b/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift index f73fac017..1256e38ee 100644 --- a/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift +++ b/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift @@ -66,6 +66,30 @@ public class SemanticContext { odwSemanticContext.setDeviceId(deviceID) } + /** + Set the operating system version context information of the telemetry event. + + - Note: Overrides the OS version that the SDK populates automatically (Common Schema field `ext.os.ver`). + + - Parameters: + - osVersion: A `String` that contains the operating system version. + */ + public func setOsVersion(_ osVersion: String) { + odwSemanticContext.setOsVersion(osVersion) + } + + /** + Set the operating system build context information of the telemetry event. + + - Note: In the CS3 schema the OS version field (`ext.os.ver`) is populated from the OS build, so set this if `setOsVersion(_:)` alone does not update `ext.os.ver`. + + - Parameters: + - osBuild: A `String` that contains the operating system build. + */ + public func setOsBuild(_ osBuild: String) { + odwSemanticContext.setOsBuild(osBuild) + } + /** Set the user time zone context information of telemetry event. diff --git a/wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs b/wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs index 9939ec966..30ec7efc9 100644 --- a/wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs +++ b/wrappers/xamarin/sdk/OneDsCppSdk.iOS.Bindings/ApiDefinitions.cs @@ -281,6 +281,14 @@ public interface SemanticContext [Export ("setDeviceId:")] void SetDeviceId (string deviceId); + // -(void)setOsVersion:(NSString * _Nonnull)osVersion; + [Export ("setOsVersion:")] + void SetOsVersion (string osVersion); + + // -(void)setOsBuild:(NSString * _Nonnull)osBuild; + [Export ("setOsBuild:")] + void SetOsBuild (string osBuild); + // -(void)setUserTimeZone:(NSString * _Nonnull)userTimeZone; [Export ("setUserTimeZone:")] void SetUserTimeZone (string userTimeZone); From 6b50de7b093bd16a64fc4228df0c91d9a869b207 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Sat, 13 Jun 2026 17:22:46 -0500 Subject: [PATCH 3/3] Address Copilot on #1482: correct setOsVersion docs (ext.os.ver mapping) Code review found the setOsVersion doc comments were misleading: in the CS3 schema ext.os.ver is populated from COMMONFIELDS_OS_BUILD, not OS_VERSION (ContextFieldsProvider.cpp:259-263 sets extOs[0].ver from COMMONFIELDS_OS_BUILD; OS_VERSION is commented out). setOsVersion overrides DeviceInfo.OsVersion and does NOT update ext.os.ver -- setOsBuild does. Correct the @details/Note in ODWSemanticContext.h and the Swift wrapper to say setOsVersion overrides DeviceInfo.OsVersion and point to setOsBuild for ext.os.ver. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- wrappers/obj-c/ODWSemanticContext.h | 2 +- wrappers/swift/Sources/OneDSSwift/SemanticContext.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/obj-c/ODWSemanticContext.h b/wrappers/obj-c/ODWSemanticContext.h index 57e7c0d6a..356ae10c7 100644 --- a/wrappers/obj-c/ODWSemanticContext.h +++ b/wrappers/obj-c/ODWSemanticContext.h @@ -55,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN /*! @brief Set the operating system version context information of telemetry event. - @details Overrides the OS version that the SDK populates automatically (Common Schema field `ext.os.ver`). + @details Overrides the OS version that the SDK populates automatically (the `DeviceInfo.OsVersion` field). Note: in the CS3 schema `ext.os.ver` is populated from the OS build, not this field, so use setOsBuild: to override `ext.os.ver`. @param osVersion A string that contains the operating system version. */ -(void) setOsVersion:(nonnull NSString*)osVersion; diff --git a/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift b/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift index 1256e38ee..184d19bc4 100644 --- a/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift +++ b/wrappers/swift/Sources/OneDSSwift/SemanticContext.swift @@ -69,7 +69,7 @@ public class SemanticContext { /** Set the operating system version context information of the telemetry event. - - Note: Overrides the OS version that the SDK populates automatically (Common Schema field `ext.os.ver`). + - Note: Overrides the OS version that the SDK populates automatically (the `DeviceInfo.OsVersion` field). In the CS3 schema `ext.os.ver` is populated from the OS build, not this field — use `setOsBuild(_:)` to override `ext.os.ver`. - Parameters: - osVersion: A `String` that contains the operating system version.