startup

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: CC0-1.0 Imports: 12 Imported by: 0

Documentation

Overview

Package startup owns the opt-in, once-per-startup fixed-performance action.

Index

Constants

View Source
const FixedPerformanceCommand = "cmd power set-fixed-performance-mode-enabled true"

FixedPerformanceCommand is the sole startup action; RPC callers cannot supply shell text.

Example: a successful startup invokes exactly this command through the paired shell identity.

Variables

This section is empty.

Functions

This section is empty.

Types

type ADBRunner

type ADBRunner struct{}

ADBRunner executes the single literal command without a host ADB daemon.

Example: a phone APK uses ADBRunner after Android NSD identifies its own service.

func (ADBRunner) Run

func (ADBRunner) Run(
	ctx context.Context,
	privateKey string,
	port adb.Port,
) (adb.Result, error)

Run creates an ADB client and performs the fixed-performance command.

Example: a revoked key produces adb.ErrAuthentication for the status boundary.

type Config

type Config struct {
	Version    int    `json:"version"`
	Enabled    bool   `json:"enabled"`
	PrivateKey string `json:"private_key"`
}

Config is the credential-protected startup file; it must never be exposed as RPC status.

Example: enabling stores a dedicated paired RSA key and the opt-in flag together.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller serializes configuration, subscriptions and the one active action under a single invariant.

Example: reconfiguration cancels old I/O and waits for its completion before starting new work.

func New

func New(
	path string,
	runner Runner,
	discovery Discovery,
) *Controller

New loads persisted opt-in state without starting discovery or executing commands.

Example: the APK registers the controller before its application context is initialized.

func (*Controller) Apply

func (c *Controller) Apply(ctx context.Context) error

Apply requests another single run without changing the persisted enabled flag.

Example: an operator can test the paired key while future automatic startup remains disabled.

func (*Controller) Configure

func (c *Controller) Configure(
	ctx context.Context,
	privateKey string,
	enabled bool,
) error

Configure atomically saves opt-in and an optional replacement private key, then replaces the active generation.

Example: an empty privateKey retains the configured identity when disabling or re-enabling.

func (*Controller) Discovered

func (c *Controller) Discovered(
	ctx context.Context,
	generation uint64,
	port adb.Port,
)

Discovered consumes current own-device ports; zero means the discovered endpoint was lost.

Example: a changed dynamic port cancels the old socket and starts on the new endpoint.

func (*Controller) DiscoveryFailed

func (c *Controller) DiscoveryFailed(
	generation uint64,
	code int,
)

DiscoveryFailed records a platform failure without exposing any credentials or changing opt-in.

Example: NSD registration failure stays visible until a network event renews discovery.

func (*Controller) Start

func (c *Controller) Start(ctx context.Context) error

Start initializes the service lifetime once; duplicate boot deliveries do not repeat a successful action.

Example: a fresh process reads Enabled from disk and starts without any Apply RPC.

func (*Controller) Status

func (c *Controller) Status() Status

Status returns a value snapshot with no key material or mutable references.

Example: the authenticated status RPC exposes this record to the setup client.

type Discovery

type Discovery interface {
	// Update replaces subscription state and tags all subsequent callbacks with generation.
	//
	// Example: a callback queued before disable carries an old generation and is ignored.
	Update(ctx context.Context, generation uint64, enabled bool) error
}

Discovery controls platform service subscriptions; Update must not synchronously call the controller.

Example: Android posts subscription changes to its main looper and returns promptly.

type Runner

type Runner interface {
	// Run returns the fixed command result, honoring cancellation throughout socket I/O.
	//
	// Example: disabling startup cancels a blocked local ADB connection.
	Run(ctx context.Context, privateKey string, port adb.Port) (adb.Result, error)
}

Runner performs the fixed action using a dedicated private key and discovered local port.

Example: ADBRunner constructs a new TLS identity for each bounded attempt.

type State

type State string

State describes execution progress, not the current hardware power or thermal state.

Example: StateSucceeded means the last fixed command reported exit zero.

const (
	StateDisabled             State = "disabled"
	StateWaiting              State = "waiting_for_adb"
	StateRunning              State = "running"
	StateSucceeded            State = "succeeded"
	StateAuthenticationFailed State = "authentication_failed"
	StateFailed               State = "failed"
)

Startup states keep disabled, waiting, authentication and command outcomes distinct.

Example: StateWaiting is expected until trusted Wi-Fi exposes the local TLS service.

type Status

type Status struct {
	Enabled          bool
	Configured       bool
	State            State
	Generation       uint64
	Port             adb.Port
	Attempts         int
	HasResult        bool
	LastExitCode     int
	LastRunUnixMilli int64
	LastError        string
}

Status is a credential-free snapshot of configuration and the last command in this process.

Example: HasResult distinguishes exit zero from a command that never returned an exit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL