Class FakeScriptContext

java.lang.Object
com.valhalla.sdk.testing.FakeScriptContext
All Implemented Interfaces:
ScriptContext

public final class FakeScriptContext extends Object implements ScriptContext
Mutable in-memory ScriptContext for offline author tests.

This fixture exists only for JVM test source. It neither connects to an emulator nor grants native action access.

  • Method Details

    • builder

      public static FakeScriptContext.Builder builder()
      Creates a fixture builder with a safe default script id.
    • getScriptId

      public String getScriptId()
      Description copied from interface: ScriptContext
      Returns the stable package identifier from manifest.json.
      Specified by:
      getScriptId in interface ScriptContext
      Returns:
      script identifier used to prefix logs and runtime state
    • log

      public void log(String level, String message)
      Description copied from interface: ScriptContext
      Publishes a script-scoped log entry.
      Specified by:
      log in interface ScriptContext
      Parameters:
      level - severity label such as DEBUG, INFO, or ERROR
      message - human-readable message; avoid credentials and other secrets
    • hasPermission

      public boolean hasPermission(String permission)
      Description copied from interface: ScriptContext
      Tests whether the installed package was granted a manifest permission.
      Specified by:
      hasPermission in interface ScriptContext
      Parameters:
      permission - permission string, preferably from Permissions
      Returns:
      true when the package grants the permission
    • getSetting

      public String getSetting(String name, String fallback)
      Description copied from interface: ScriptContext
      Returns a launch-time script setting supplied by the Command Center.
      Specified by:
      getSetting in interface ScriptContext
      Parameters:
      name - setting key declared in the package manifest
      fallback - value returned when the key is absent
      Returns:
      configured string value, or fallback when absent
    • publishTelemetry

      public void publishTelemetry(String json)
      Description copied from interface: ScriptContext
      Publishes a small JSON telemetry snapshot for the Command Center paint.

      An older runtime that predates this additive API resolves this default body, which forwards the snapshot through ScriptContext.log(java.lang.String, java.lang.String) using the runtime's long-established "Telemetry: " bridge. That bridge applies the same permission, size, and JSON checks as the override and never writes telemetry values to Android's shared log buffer, so a runtime that does not implement this method degrades to the bridge instead of discarding the snapshot.

      A runtime predating the bridge does not recognize the prefix and records the line as an ordinary script log entry instead, which is why this snapshot must hold no credentials or secrets - the same contract ScriptContext.log(java.lang.String, java.lang.String) already states.

      Specified by:
      publishTelemetry in interface ScriptContext
      Parameters:
      json - valid JSON object, containing no credentials or secrets
    • isBreakRequested

      public boolean isBreakRequested()
      Description copied from interface: ScriptContext
      Returns whether Command Center has requested the script's next safe scheduled-break boundary.

      The request is advisory: scripts should finish indivisible work and publish their existing safe-boundary telemetry before yielding. Older runtimes return false through this additive default method.

      Specified by:
      isBreakRequested in interface ScriptContext
      Returns:
      true while a scheduled break is due and awaiting a safe boundary
    • getGameMessages

      public List<GameMessage> getGameMessages()
      Description copied from interface: ScriptContext
      Returns the game-message lines currently retained by the client.

      This data stays inside the Android script runtime and is never forwarded to Command Center telemetry. Packages must request Permissions.GAME_READ_MESSAGES; older runtimes return an empty list through this default implementation.

      Specified by:
      getGameMessages in interface ScriptContext
      Returns:
      immutable snapshot of retained game messages
    • setSetting

      public void setSetting(String name, String value)
      Replaces one launch setting for the next callback.
    • grant

      public void grant(String permission)
      Grants a manifest permission to this fixture.
    • revoke

      public void revoke(String permission)
      Revokes a manifest permission from this fixture.
    • setBreakRequested

      public void setBreakRequested(boolean requested)
      Sets the simulated scheduled-break request.
    • logs

      Returns immutable logs emitted by the script.
    • telemetry

      public List<String> telemetry()
      Returns immutable telemetry payloads emitted by the script.