Skip to content

Expose setOsVersion/setOsBuild on Obj-C ODWSemanticContext (resolves #1093)#1482

Open
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/objc-set-os-version
Open

Expose setOsVersion/setOsBuild on Obj-C ODWSemanticContext (resolves #1093)#1482
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/objc-set-os-version

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

What

Expose setOsVersion: and setOsBuild: on the Obj-C wrapper's ODWSemanticContext, so iOS/Obj-C clients can override the OS version (DeviceInfo.OsVersion / Common Schema ext.os.ver) the SDK populates automatically.

Why

Per #1093, a client needed to set DeviceInfo.OsVersion from app code on iOS. The C++ core already provides ISemanticContext::SetOsVersion() / SetOsBuild() (ISemanticContext.hpp via DECLARE_COMMONFIELD), but the Obj-C wrapper exposed only app/user/device-id/experiment setters — no OS-version setter — so there was no way to do this from the Obj-C API. (As noted in the issue thread, in the CS3 schema ext.os.ver is populated from the OS build (COMMONFIELDS_OS_BUILD), so both setters are exposed.)

Changes

  • wrappers/obj-c/ODWSemanticContext.h / .mm — add setOsVersion: and setOsBuild:, each converting the NSString to std::string and forwarding to the wrapped ISemanticContext (SetOsVersion / SetOsBuild). Mirrors the existing setDeviceId: pattern.
  • tests/unittests/obj-c/ODWSemanticContextTests.mm — add testSetOsVersion and testSetOsBuild; the existing TestSemanticContext mock now captures SetOsVersion/SetOsBuild.

Usage

[logger.semanticContext setOsVersion:@"10.0.19041"];
// CS3 ext.os.ver comes from the OS build:
[logger.semanticContext setOsBuild:@"19041.1234"];

Validation

SetOsVersion/SetOsBuild are non-pure virtual void Set...(const std::string&) generated by DECLARE_COMMONFIELD (CommonFields.h), so the wrapper calls and the test-mock overrides match the core signatures. The Obj-C wrapper builds and the XCTest run on the macOS/iOS CI — this change couldn't be compiled locally (no Obj-C toolchain on the dev box), so it relies on CI for the build/test confirmation.

Resolves #1093.

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 microsoft#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 microsoft#1093 discussion, in the CS3 schema `ext.os.ver` is populated
from the OS build (COMMONFIELDS_OS_BUILD), so both setters are exposed.

Resolves microsoft#1093.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bmehta001 bmehta001 requested a review from a team as a code owner June 12, 2026 00:57
@bmehta001

Copy link
Copy Markdown
Contributor Author

Validation status for this change:

iOS/macOS CI compiled the Obj-C wrapper successfully. The macOS/iOS build jobs are red, but the failure is pre-existing and unrelated to this change: the iOSTestAppTests testAll suite fails at tests/unittests/PalTests.cpp:94 (a C++ PAL unit test) — the same failure also occurs on the Java-only PR #1483, which cannot affect iOS at all. In this PR's iOS build log, ODWSemanticContext compiles with 0 compile errors (the new setOsVersion:/setOsBuild: build fine); the job only fails later at that pre-existing PalTests assertion.

C++ core API compile-checked locally (WSL, g++ -std=c++11): a mock ISemanticContext overriding SetOsVersion(const std::string&) / SetOsBuild(const std::string&) — i.e., exactly what the wrapper forwards to (_wrappedSemanticContext->SetOsVersion(...)) and what the unit-test mock captures — compiles cleanly, confirming the signatures and virtual dispatch. (A fully-linked standalone run needs all of libmat, and the Obj-C XCTest itself needs Xcode, so the end-to-end test relies on the macOS CI.)

The forwarding mirrors the existing setDeviceId: exactly, and the underlying SetOsVersion/SetOsBuild are already used in lib/pal/PAL.cpp, so behavior is well-established.

Aside: the iOS CI being red on PalTests.cpp:94 (independent of this PR) is worth a separate look — it'll block merges across the board until fixed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR exposes setOsVersion: and setOsBuild: on the Obj-C ODWSemanticContext wrapper so Obj-C/iOS clients can override OS version/build semantic context values that the C++ core already supports, addressing the API gap described in #1093.

Changes:

  • Add Obj-C wrapper methods setOsVersion: / setOsBuild: that forward to ISemanticContext::SetOsVersion / SetOsBuild.
  • Add Obj-C unit tests covering the new setters and extend the test mock to capture the values.
  • Update Obj-C header documentation for the new APIs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
wrappers/obj-c/ODWSemanticContext.mm Adds forwarding implementations for setOsVersion: and setOsBuild:.
wrappers/obj-c/ODWSemanticContext.h Adds public Obj-C API declarations and documentation for the new setters.
tests/unittests/obj-c/ODWSemanticContextTests.mm Adds unit tests and mock capture fields for OS version/build setters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +69 to +70
std::string strOsVersion = std::string([osVersion UTF8String]);
_wrappedSemanticContext->SetOsVersion(strOsVersion);
Comment on lines +75 to +76
std::string strOsBuild = std::string([osBuild UTF8String]);
_wrappedSemanticContext->SetOsBuild(strOsBuild);
Comment on lines +57 to +61
@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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to override the DeviceInfo.OsVersion field from client app?

2 participants