diff --git a/internal/driver/sidecar/client.go b/internal/driver/sidecar/client.go index 5dc2a47..fdf4ec5 100644 --- a/internal/driver/sidecar/client.go +++ b/internal/driver/sidecar/client.go @@ -8,6 +8,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "github.com/priyanshujain/sanderling/internal/android" "github.com/priyanshujain/sanderling/internal/driver" driverpb "github.com/priyanshujain/sanderling/proto/driverpb" ) @@ -15,6 +16,21 @@ import ( type Client struct { connection *grpc.ClientConn stub driverpb.DriverClient + platform string +} + +// SetPlatform records the target platform so capability methods (e.g. +// ForegroundApp) can pick the right backend. The caller sets this right after +// Dial. +func (c *Client) SetPlatform(platform string) { c.platform = platform } + +// ForegroundApp reports the foreground package. Only Android is supported (via +// adb); other platforms return "" so the runner skips app-scope enforcement. +func (c *Client) ForegroundApp(ctx context.Context) (string, error) { + if c.platform != "android" { + return "", nil + } + return android.ForegroundPackage(ctx) } // Dial connects to the sidecar gRPC server at the given address. diff --git a/internal/testrun/driver.go b/internal/testrun/driver.go index 935dc4f..33505d8 100644 --- a/internal/testrun/driver.go +++ b/internal/testrun/driver.go @@ -63,6 +63,7 @@ func buildDriver(ctx context.Context, options Options, stdout io.Writer) (driver _ = sidecarCommand.Process.Kill() return nil, nil, fmt.Errorf("dial sidecar: %w", err) } + driverClient.SetPlatform(options.Platform) // WaitForHealth confirms the gRPC sidecar is up. For iOS, the WDA warmup // (absorbing the XCUITest startup race) runs inside IosDriverBackend.init // in the sidecar - no additional sleep needed here.