versionaware

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: CC0-1.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAPILevel int

DefaultAPILevel is the API level that the compiled proxy code was generated against. Set by generated code (codes_gen.go).

View Source
var Revisions = APIRevisions{}

Revisions maps API level -> list of version IDs (latest first). Populated by generated code (codes_gen.go).

Tables holds multi-version transaction code tables. Populated by generated code (codes_gen.go).

Functions

func DetectAPILevel

func DetectAPILevel() int

DetectAPILevel returns the Android API level of the running device. Reads /etc/build_flags.json (no fork, no binder dependency). Returns 0 if detection fails.

Types

type APIRevisions

type APIRevisions map[int][]Revision

APIRevisions maps API level -> list of Revisions (for probing order). Within an API level, later revisions are listed first (more likely match).

type MultiVersionTable

type MultiVersionTable map[Revision]VersionTable

MultiVersionTable maps Revision -> VersionTable. Revisions are like "34.r1", "35.r1", "36.r1", "36.r3", "36.r4".

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures a version-aware Transport.

func OptionCachePath

func OptionCachePath(path string) Option

OptionCachePath sets the file path for caching the resolved transaction code table. The cache includes a fingerprint so it is automatically invalidated when the OS is updated.

Default: /tmp/.binder_cache/codes.gob Pass empty string to disable caching.

type Options

type Options []Option

Options is a slice of Option.

type Revision

type Revision string

Revision identifies an AOSP firmware revision, e.g. "36.r4".

type Transport

type Transport struct {

	// Revision is the detected AOSP firmware revision (e.g. "36.r4").
	// Set during NewTransport when libbinder.so symbol inspection
	// narrows the candidates to exactly one. Empty if ambiguous.
	Revision Revision
	// ScannedJARs tracks which framework JARs have been fully scanned
	// for $Stub classes. Keyed by JAR filename (e.g. "framework.jar").
	// Persisted in the cache to avoid re-scanning across runs.
	ScannedJARs map[string]bool
	// contains filtered or unexported fields
}

Transport wraps a binder.Transport and adds version-aware transaction code resolution via ResolveCode.

All version detection (API level + revision probing) happens eagerly in NewTransport. If the device version cannot be determined or is unsupported, NewTransport returns an error.

func NewTransport

func NewTransport(
	ctx context.Context,
	inner binder.Transport,
	targetAPI int,
	opts ...Option,
) (*Transport, error)

NewTransport creates a version-aware Transport wrapping inner.

targetAPI is the Android API level (e.g., 36). If 0, auto-detects from /etc/build_flags.json.

Returns an error if:

  • the API level cannot be detected (targetAPI==0 and detection fails)
  • the API level has no compiled version tables
  • revision probing fails (when multiple revisions exist)

If multiple AOSP revisions exist for the API level, NewTransport probes the device via binder transactions to determine which revision matches. This requires the binder driver to be open.

func (*Transport) AcquireHandle

func (t *Transport) AcquireHandle(
	ctx context.Context,
	handle uint32,
) error

func (*Transport) ClearDeathNotification

func (t *Transport) ClearDeathNotification(
	ctx context.Context,
	handle uint32,
	recipient binder.DeathRecipient,
) error

func (*Transport) Close

func (t *Transport) Close(ctx context.Context) error

func (*Transport) MergeTable

func (t *Transport) MergeTable(
	extra VersionTable,
)

MergeTable adds entries from extra into the transport's version table. Existing entries are not overwritten. This is useful for registering stable AIDL HAL interfaces whose transaction codes are not extracted from framework JARs.

func (*Transport) RegisterReceiver

func (t *Transport) RegisterReceiver(
	ctx context.Context,
	receiver binder.TransactionReceiver,
) uintptr

func (*Transport) ReleaseHandle

func (t *Transport) ReleaseHandle(
	ctx context.Context,
	handle uint32,
) error

func (*Transport) RequestDeathNotification

func (t *Transport) RequestDeathNotification(
	ctx context.Context,
	handle uint32,
	recipient binder.DeathRecipient,
) error

func (*Transport) ResolveCode

func (t *Transport) ResolveCode(
	ctx context.Context,
	descriptor string,
	method string,
) (binder.TransactionCode, error)

ResolveCode resolves an AIDL method name to the correct transaction code for the detected device version.

If the descriptor is not in the pre-loaded table, ResolveCode attempts on-demand extraction from the device's framework JARs. This handles cases where the cache is stale or a new interface is needed that wasn't in the initial extraction.

Returns an error if the method is not found in the version table (e.g., calling a method that does not exist on the device's API level).

func (*Transport) Transact

func (t *Transport) Transact(
	ctx context.Context,
	handle uint32,
	code binder.TransactionCode,
	flags binder.TransactionFlags,
	data *parcel.Parcel,
) (*parcel.Parcel, error)

type VersionTable

type VersionTable map[string]map[string]binder.TransactionCode

VersionTable maps descriptor -> methodName -> transaction code.

func (VersionTable) Resolve

func (t VersionTable) Resolve(
	descriptor string,
	method string,
) binder.TransactionCode

Resolve looks up the transaction code for a method. Returns 0 if not found.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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