Skip to content

Add simulator extras: privacy, appearance, status_bar, openurl, push, location, addmedia, screen capture#177

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/add-simulator-extras
Open

Add simulator extras: privacy, appearance, status_bar, openurl, push, location, addmedia, screen capture#177
Copilot wants to merge 4 commits into
mainfrom
copilot/add-simulator-extras

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

Exposes the remaining xcrun simctl operations through SimulatorService so callers no longer need to shell out directly. Covers all 8 feature groups from the issue.

New API surface

Property/Method simctl subcommand
service.Privacy.Grant/Revoke/Reset(udid, PrivacyPermission.Calendar, bundleId?) privacy <udid> grant|revoke|reset <service>
service.SetAppearance(udid, SimulatorAppearance.Dark) / GetAppearance(udid) ui <udid> appearance
service.StatusBar.Override(udid, new StatusBarOverrides(Time:"09:41", BatteryLevel:80)) / .Clear(udid) status_bar <udid> override|clear
service.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|run
service.AddMedia(udid, paths) addmedia <udid> <files…>
service.ScreenCapture.Screenshot(udid, path, ScreenshotFormat.Png) io <udid> screenshot
service.ScreenCapture.StartRecording(udid, path) → IDisposable io <udid> recordVideo

StartRecording returns an IDisposable; disposing it kills the recordVideo process.

Push accepts either a file path or an inline JSON string — when the payload starts with { it is written to a temp file automatically.

New types

  • Enums: PrivacyPermission, SimulatorAppearance, SimulatorBatteryState, SimulatorDataNetwork, ScreenshotFormat, VideoRecordingFormat
  • Record: StatusBarOverrides (all fields optional)
  • Class: RecordingOptions (Format, Force)
  • Service classes: SimulatorPrivacy, SimulatorStatusBar, SimulatorLocation, SimulatorScreenCapture — all constructed lazily via properties on SimulatorService

Infrastructure changes

  • SimulatorService made partial to split feature groups across files.
  • SimCtl.XcrunPath promoted to internal static so SimulatorScreenCapture can reference it when starting a persistent recording process.
  • IsExternalInit polyfill added to NullableAttributes.cs — required for C# 9 record types to compile against the netstandard2.0 target.

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
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /usr/bin/dotnet dotnet build Xamarin.MacDev/Xamarin.MacDev.csproj -nologo -v:minimal (dns block)
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /usr/bin/dotnet dotnet build Xamarin.MacDev/Xamarin.MacDev.csproj -nologo -v:minimal (dns block)
  • kmuvsblobprodcus389.vsblob.vsassets.io
    • Triggering command: /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
    • Triggering command: /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
    • Triggering command: /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
    • Triggering command: /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:

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
Copilot AI requested a review from rmarinho April 30, 2026 19:58
Copilot AI and others added 3 commits May 11, 2026 10:48
… 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>
@rmarinho rmarinho force-pushed the copilot/add-simulator-extras branch from 9f2b890 to 5a3fd2a Compare May 11, 2026 13:00
@rmarinho rmarinho marked this pull request as ready for review May 13, 2026 16:00
@rmarinho rmarinho requested a review from rolfbjarne May 13, 2026 16:00
@rolfbjarne rolfbjarne requested a review from Copilot May 13, 2026 16:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 a VideoRecordingSession that uses kill(pid, SIGINT) to stop recordVideo cleanly.
  • SimulatorService becomes partial, SimCtl.XcrunPath is promoted to internal static for direct Process use in StartRecording, and IsExternalInit polyfill 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 thread Xamarin.MacDev/SimulatorStatusBar.cs Outdated
Comment thread Xamarin.MacDev/SimulatorPrivacy.cs Outdated
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 &lt;udid&gt; &lt;bundleId&gt; &lt;file&gt;</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;
}
}
Comment thread Xamarin.MacDev/SimulatorScreenCapture.cs Outdated
- 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>
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.

Add simulator extras: privacy, appearance, status_bar, openurl, push, location, addmedia, screen capture

4 participants