Add simulator extras: privacy, appearance, status_bar, openurl, push, location, addmedia, screen capture#177
Open
Copilot wants to merge 4 commits into
Open
Add simulator extras: privacy, appearance, status_bar, openurl, push, location, addmedia, screen capture#177Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
Copilot
AI
changed the title
[WIP] Add simulator extras for privacy, appearance, and more
Add simulator extras: privacy, appearance, status_bar, openurl, push, location, addmedia, screen capture
Apr 30, 2026
… push, location, addmedia, screen capture) Agent-Logs-Url: https://github.com/dotnet/macios-devtools/sessions/249ea126-48c7-436b-b123-232b305a6be3 Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
…ents backslash escaping, specific catch types) Agent-Logs-Url: https://github.com/dotnet/macios-devtools/sessions/249ea126-48c7-436b-b123-232b305a6be3 Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
…overrides - Use SIGINT instead of SIGKILL in VideoRecordingSession.Dispose so simctl can flush and write the video file trailer (prevents corrupt output files). Falls back to Process.Kill if SIGINT fails or times out. - Drain redirected stdout/stderr with async readers in StartRecording to prevent pipe buffer deadlocks on longer recordings. - Use .json extension for temporary push payload files instead of .tmp to satisfy simctl push file extension requirements. - Guard StatusBarOverrides.Override against all-null overrides that would produce an invalid simctl invocation. - Fix NUnit2009 analyzer errors in ReturnsSameInstance tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9f2b890 to
5a3fd2a
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds C# wrappers around the remaining xcrun simctl subcommands (privacy, appearance, status_bar, openurl, push, location, addmedia, screenshot, recordVideo) so callers can use SimulatorService instead of shelling out. Uses partial classes to split the new surface across files, exposes lazily-constructed sub-services (Privacy, StatusBar, Location, ScreenCapture), and adds an IsExternalInit polyfill so C# 9 record types compile against netstandard2.0.
Changes:
- New
Simulator*service classes and supporting enums/records for the eight feature groups, plus aVideoRecordingSessionthat useskill(pid, SIGINT)to stoprecordVideocleanly. SimulatorServicebecomespartial,SimCtl.XcrunPathis promoted tointernal staticfor directProcessuse inStartRecording, andIsExternalInitpolyfill is added.- New NUnit fixture covering argument validation, lazy-service caching, and enum→simctl string mappings.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Xamarin.MacDev/SimulatorService.cs | Marks the class partial to allow splitting the new surface across files. |
| Xamarin.MacDev/SimulatorServiceExtras.cs | New partial holding lazy sub-service properties and direct methods (SetAppearance, OpenUrl, Push, AddMedia). |
| Xamarin.MacDev/SimulatorPrivacy.cs | Grant/Revoke/Reset wrappers for simctl privacy. |
| Xamarin.MacDev/SimulatorStatusBar.cs | status_bar override/clear wrappers plus enum→string converters. |
| Xamarin.MacDev/SimulatorLocation.cs | Set/Clear/Run wrappers for simctl location. |
| Xamarin.MacDev/SimulatorScreenCapture.cs | Screenshot and start/stop recording wrappers using Process directly. |
| Xamarin.MacDev/SimulatorScreenCaptureTypes.cs | ScreenshotFormat, VideoRecordingFormat, RecordingOptions types. |
| Xamarin.MacDev/SimulatorAppearance.cs | New SimulatorAppearance enum. |
| Xamarin.MacDev/PrivacyPermission.cs | New PrivacyPermission enum. |
| Xamarin.MacDev/SimCtl.cs | Promotes XcrunPath to internal static. |
| Xamarin.MacDev/NullableAttributes.cs | Adds IsExternalInit polyfill for netstandard2.0 record support. |
| tests/SimulatorServiceExtrasTests.cs | NUnit tests covering validation, lazy caching, and enum mappings. |
Comment on lines
+100
to
+129
| /// Sends a push notification to the simulator. | ||
| /// <paramref name="payloadJsonOrPath"/> may be a file path to an APNS JSON payload file | ||
| /// or a raw JSON string (starting with <c>{</c>), which is written to a temporary file. | ||
| /// Wraps <c>xcrun simctl push <udid> <bundleId> <file></c>. | ||
| /// </summary> | ||
| public bool Push (string udidOrName, string bundleIdentifier, string payloadJsonOrPath) | ||
| { | ||
| if (string.IsNullOrWhiteSpace (udidOrName)) | ||
| throw new ArgumentException ("Simulator UDID or name must not be null or empty.", nameof (udidOrName)); | ||
| if (string.IsNullOrWhiteSpace (bundleIdentifier)) | ||
| throw new ArgumentException ("Bundle identifier must not be null or empty.", nameof (bundleIdentifier)); | ||
| if (string.IsNullOrWhiteSpace (payloadJsonOrPath)) | ||
| throw new ArgumentException ("Payload JSON or path must not be null or empty.", nameof (payloadJsonOrPath)); | ||
|
|
||
| var isInlineJson = payloadJsonOrPath.TrimStart ().StartsWith ("{", StringComparison.Ordinal); | ||
| if (isInlineJson) { | ||
| var tempPath = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName () + ".json"); | ||
| try { | ||
| File.WriteAllText (tempPath, payloadJsonOrPath, Encoding.UTF8); | ||
| return RunPush (udidOrName, bundleIdentifier, tempPath); | ||
| } finally { | ||
| try { if (File.Exists (tempPath)) File.Delete (tempPath); } catch (IOException ex) { | ||
| log.LogInfo ("Failed to delete temporary push payload file '{0}': {1}", tempPath, ex.Message); | ||
| } catch (UnauthorizedAccessException ex) { | ||
| log.LogInfo ("Failed to delete temporary push payload file '{0}': {1}", tempPath, ex.Message); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return RunPush (udidOrName, bundleIdentifier, payloadJsonOrPath); |
Comment on lines
+91
to
+107
| try { | ||
| var process = new Process { StartInfo = psi }; | ||
| process.OutputDataReceived += (_, _) => { }; | ||
| process.ErrorDataReceived += (_, _) => { }; | ||
| process.Start (); | ||
| process.BeginOutputReadLine (); | ||
| process.BeginErrorReadLine (); | ||
| log.LogInfo ("simctl io recordVideo started for '{0}'.", udidOrName); | ||
| return new VideoRecordingSession (process, log); | ||
| } catch (System.ComponentModel.Win32Exception ex) { | ||
| log.LogInfo ("Could not start xcrun simctl io recordVideo: {0}", ex.Message); | ||
| return null; | ||
| } catch (InvalidOperationException ex) { | ||
| log.LogInfo ("Could not start xcrun simctl io recordVideo: {0}", ex.Message); | ||
| return null; | ||
| } | ||
| } |
rolfbjarne
approved these changes
May 13, 2026
- Lowercase battery state values for simctl compatibility (rolfbjarne/Copilot) - Log stderr output from recordVideo instead of swallowing it (rolfbjarne) - Stop redirecting stdout (not needed), only redirect stderr for diagnostics - Fix process leak if BeginErrorReadLine throws after Start (Copilot) - Use IsNullOrWhiteSpace for bundleIdentifier in RunPrivacy (Copilot) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exposes the remaining
xcrun simctloperations throughSimulatorServiceso callers no longer need to shell out directly. Covers all 8 feature groups from the issue.New API surface
simctlsubcommandservice.Privacy.Grant/Revoke/Reset(udid, PrivacyPermission.Calendar, bundleId?)privacy <udid> grant|revoke|reset <service>service.SetAppearance(udid, SimulatorAppearance.Dark)/GetAppearance(udid)ui <udid> appearanceservice.StatusBar.Override(udid, new StatusBarOverrides(Time:"09:41", BatteryLevel:80))/.Clear(udid)status_bar <udid> override|clearservice.OpenUrl(udid, url)openurl <udid> <url>service.Push(udid, bundleId, jsonOrPath)push <udid> <bundleId> <file>service.Location.Set(udid, lat, lng)/.Clear(udid)/.Run(udid, gpxPath)location <udid> set|clear|runservice.AddMedia(udid, paths)addmedia <udid> <files…>service.ScreenCapture.Screenshot(udid, path, ScreenshotFormat.Png)io <udid> screenshotservice.ScreenCapture.StartRecording(udid, path) → IDisposableio <udid> recordVideoStartRecordingreturns anIDisposable; disposing it kills therecordVideoprocess.Pushaccepts either a file path or an inline JSON string — when the payload starts with{it is written to a temp file automatically.New types
PrivacyPermission,SimulatorAppearance,SimulatorBatteryState,SimulatorDataNetwork,ScreenshotFormat,VideoRecordingFormatStatusBarOverrides(all fields optional)RecordingOptions(Format,Force)SimulatorPrivacy,SimulatorStatusBar,SimulatorLocation,SimulatorScreenCapture— all constructed lazily via properties onSimulatorServiceInfrastructure changes
SimulatorServicemadepartialto split feature groups across files.SimCtl.XcrunPathpromoted tointernal staticsoSimulatorScreenCapturecan reference it when starting a persistent recording process.IsExternalInitpolyfill added toNullableAttributes.cs— required for C# 9recordtypes to compile against thenetstandard2.0target.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
0t3vsblobprodcus362.vsblob.vsassets.io/usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/macios-devtools/macios-devtools/Xamarin.MacDev.sln --packages /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true(dns block)2kmvsblobprodcus39.vsblob.vsassets.io/usr/bin/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/EAFBC6E33F4372D62A064209AA87BA2F/missingpackages_workingdir --packages /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/nugetconfig/nuget.config --force(dns block)/usr/bin/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/46EB19D8E6D150879BD3367A72FC2FBC/missingpackages_workingdir --packages /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/nugetconfig/nuget.config --force(dns block)51yvsblobprodcus36.vsblob.vsassets.io/usr/bin/dotnet dotnet build Xamarin.MacDev/Xamarin.MacDev.csproj -nologo -v:minimal(dns block)/usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/macios-devtools/macios-devtools/Xamarin.MacDev.sln --packages /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true(dns block)/usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/macios-devtools/macios-devtools/Xamarin.MacDev/Xamarin.MacDev.csproj --packages /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true(dns block)7k6vsblobprodcus337.vsblob.vsassets.io/usr/bin/dotnet dotnet build Xamarin.MacDev/Xamarin.MacDev.csproj -nologo -v:minimal(dns block)kmuvsblobprodcus389.vsblob.vsassets.io/usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/macios-devtools/macios-devtools/Xamarin.MacDev.sln --packages /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true(dns block)kxqvsblobprodcus376.vsblob.vsassets.io/usr/bin/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/047D30272EE2B8A118836103AA894C89/missingpackages_workingdir --packages /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/nugetconfig/nuget.config --force(dns block)m8dvsblobprodcus37.vsblob.vsassets.io/usr/bin/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/5A662EEFB2568432D6FDBE7CF1D19C8E/missingpackages_workingdir --packages /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-05016c733fb84ab0/dbs/csharp/working/nugetconfig/nuget.config --force(dns block)securitytools.pkgs.visualstudio.com/opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp(dns block)If you need me to access, download, or install something from one of these locations, you can either: