Interface ScriptContext
- All Known Implementing Classes:
FakeScriptContext
The context exposes launch settings, permission checks, and script-scoped
logging. A permission in the package manifest authorizes an operation; it does
not guarantee that the active client adapter advertises the corresponding
capability. Use Client.supports(...) before optional native features.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidLogs a debug message.default voidLogs an error message.default booleangetBooleanSetting(String name, boolean fallback) Reads common boolean spellings such astrue,yes, and1.default doublegetDoubleSetting(String name, double fallback) Reads a finite floating-point setting.default <E extends Enum<E>>
EgetEnumSetting(String name, Class<E> type, E fallback) Reads an enum constant case-insensitively, treating spaces and hyphens as underscores.default List<GameMessage> Returns the game-message lines currently retained by the client.getIntListSetting(String name) Reads a comma-separated list while silently omitting malformed integers.default intgetIntSetting(String name, int fallback) Reads a base-10 integer setting without propagating parse errors.default intgetIntSetting(String name, int fallback, int minimum, int maximum) Reads and clamps an integer setting to an inclusive range.getListSetting(String name) Reads a comma-separated setting as trimmed, non-empty strings.default longgetLongSetting(String name, long fallback) Reads a base-10 long setting without propagating parse errors.Returns the stable package identifier frommanifest.json.default StringgetSetting(String name, String fallback) Returns a launch-time script setting supplied by the Command Center.booleanhasPermission(String permission) Tests whether the installed package was granted a manifest permission.default voidLogs an informational message.default booleanReturns whether Command Center has requested the script's next safe scheduled-break boundary.voidPublishes a script-scoped log entry.default voidpublishTelemetry(String json) Publishes a small JSON telemetry snapshot for the Command Center paint.default voidrequirePermission(String permission) Requires a package permission before continuing.default voidLogs a warning message.
-
Method Details
-
getScriptId
String getScriptId()Returns the stable package identifier frommanifest.json.- Returns:
- script identifier used to prefix logs and runtime state
-
log
Publishes a script-scoped log entry.- Parameters:
level- severity label such asDEBUG,INFO, orERRORmessage- human-readable message; avoid credentials and other secrets
-
hasPermission
Tests whether the installed package was granted a manifest permission.- Parameters:
permission- permission string, preferably fromPermissions- Returns:
truewhen the package grants the permission
-
getSetting
Returns a launch-time script setting supplied by the Command Center.- Parameters:
name- setting key declared in the package manifestfallback- value returned when the key is absent- Returns:
- configured string value, or
fallbackwhen absent
-
publishTelemetry
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
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
log(java.lang.String, java.lang.String)already states.- Parameters:
json- valid JSON object, containing no credentials or secrets
-
isBreakRequested
default boolean isBreakRequested()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
falsethrough this additive default method.- Returns:
truewhile a scheduled break is due and awaiting a safe boundary
-
getGameMessages
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.- Returns:
- immutable snapshot of retained game messages
-
getIntSetting
Reads a base-10 integer setting without propagating parse errors.- Parameters:
name- setting keyfallback- value used for missing or malformed input- Returns:
- parsed value or
fallback
-
getIntSetting
Reads and clamps an integer setting to an inclusive range.- Parameters:
name- setting keyfallback- value used for missing or malformed input before clampingminimum- inclusive lower boundmaximum- inclusive upper bound- Returns:
- parsed value constrained to
[minimum, maximum] - Throws:
IllegalArgumentException- whenmaximum < minimum
-
getLongSetting
Reads a base-10 long setting without propagating parse errors.- Parameters:
name- setting keyfallback- value used for missing or malformed input- Returns:
- parsed value or
fallback
-
getDoubleSetting
Reads a finite floating-point setting.- Parameters:
name- setting keyfallback- value used for missing, malformed, infinite, or NaN input- Returns:
- finite parsed value or
fallback
-
getBooleanSetting
Reads common boolean spellings such astrue,yes, and1.- Parameters:
name- setting keyfallback- value used for missing or unrecognized input- Returns:
- parsed boolean or
fallback
-
getEnumSetting
Reads an enum constant case-insensitively, treating spaces and hyphens as underscores.- Type Parameters:
E- enum type- Parameters:
name- setting keytype- enum class used for parsingfallback- value used for missing or unrecognized input- Returns:
- parsed enum constant or
fallback - Throws:
NullPointerException- whentypeisnull
-
getListSetting
Reads a comma-separated setting as trimmed, non-empty strings.- Parameters:
name- setting key- Returns:
- immutable list, empty when the setting is absent or blank
-
getIntListSetting
Reads a comma-separated list while silently omitting malformed integers.- Parameters:
name- setting key- Returns:
- immutable list of successfully parsed integers
-
debug
Logs a debug message.- Parameters:
message- message logged atDEBUGseverity
-
info
Logs an informational message.- Parameters:
message- message logged atINFOseverity
-
warn
Logs a warning message.- Parameters:
message- message logged atWARNseverity
-
error
Logs an error message.- Parameters:
message- message logged atERRORseverity
-
requirePermission
Requires a package permission before continuing.- Parameters:
permission- permission string, preferably fromPermissions- Throws:
SecurityException- when the permission is not granted
-