Documentation
¶
Index ¶
- Variables
- func DetectAPILevel() int
- type APIRevisions
- type CompiledTable
- func (t CompiledTable) HasDescriptor(descriptor string) bool
- func (t CompiledTable) IsSorted() bool
- func (t CompiledTable) MethodsForDescriptor(descriptor string) []MethodEntry
- func (t CompiledTable) Resolve(descriptor string, method string) binder.TransactionCode
- func (t CompiledTable) ReverseResolve(descriptor string, code binder.TransactionCode) (string, bool)
- func (t CompiledTable) ToVersionTable() VersionTable
- type InterfaceEntry
- type MethodEntry
- type MultiVersionTable
- type Option
- type Options
- type Revision
- type Transport
- func (t *Transport) APILevel() int
- func (t *Transport) AcquireHandle(ctx context.Context, handle uint32) error
- func (t *Transport) ActiveTable() VersionTable
- func (t *Transport) ClearDeathNotification(ctx context.Context, handle uint32, recipient binder.DeathRecipient) error
- func (t *Transport) Close(ctx context.Context) error
- func (t *Transport) MergeTable(extra VersionTable)
- func (t *Transport) RegisterReceiver(ctx context.Context, receiver binder.TransactionReceiver) uintptr
- func (t *Transport) ReleaseHandle(ctx context.Context, handle uint32) error
- func (t *Transport) RequestDeathNotification(ctx context.Context, handle uint32, recipient binder.DeathRecipient) error
- func (t *Transport) ResolveCode(ctx context.Context, descriptor string, method string) (binder.TransactionCode, error)
- func (t *Transport) ResolveMethodSignature(ctx context.Context, descriptor string, method string) []string
- func (t *Transport) Transact(ctx context.Context, handle uint32, code binder.TransactionCode, ...) (*parcel.Parcel, error)
- type VersionTable
Constants ¶
This section is empty.
Variables ¶
var DefaultAPILevel int
DefaultAPILevel is the API level that the compiled proxy code was generated against. Transaction codes are resolved dynamically from device framework JARs.
var Revisions = APIRevisions{}
Revisions maps API level -> list of version IDs (latest first).
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 ¶
APIRevisions maps API level -> list of Revisions (for probing order). Within an API level, later revisions are listed first (more likely match).
type CompiledTable ¶ added in v0.0.9
type CompiledTable []InterfaceEntry // sorted by Descriptor
CompiledTable is a read-only table of transaction codes stored as sorted slices for zero-cost initialization (no runtime hash table construction). Use Resolve for lookups.
func (CompiledTable) HasDescriptor ¶ added in v0.0.9
func (t CompiledTable) HasDescriptor(descriptor string) bool
HasDescriptor reports whether the table contains the given descriptor.
func (CompiledTable) IsSorted ¶ added in v0.0.9
func (t CompiledTable) IsSorted() bool
IsSorted reports whether the table's invariants hold: interfaces sorted by Descriptor (strictly increasing), methods sorted by Method within each (strictly increasing).
func (CompiledTable) MethodsForDescriptor ¶ added in v0.0.9
func (t CompiledTable) MethodsForDescriptor( descriptor string, ) []MethodEntry
MethodsForDescriptor returns the method entries for a descriptor. Returns nil if the descriptor is not found.
func (CompiledTable) Resolve ¶ added in v0.0.9
func (t CompiledTable) Resolve( descriptor string, method string, ) binder.TransactionCode
Resolve looks up the transaction code for a method. Returns 0 if not found. Uses binary search.
func (CompiledTable) ReverseResolve ¶ added in v0.0.9
func (t CompiledTable) ReverseResolve( descriptor string, code binder.TransactionCode, ) (string, bool)
ReverseResolve looks up the method name for a transaction code. Returns ("", false) if not found.
func (CompiledTable) ToVersionTable ¶ added in v0.0.9
func (t CompiledTable) ToVersionTable() VersionTable
ToVersionTable converts a compiled table to a mutable VersionTable.
type InterfaceEntry ¶ added in v0.0.9
type InterfaceEntry struct {
Descriptor string
Methods []MethodEntry // sorted by Method
}
InterfaceEntry maps a descriptor to its sorted method list.
type MethodEntry ¶ added in v0.0.9
type MethodEntry struct {
Method string
Code binder.TransactionCode
}
MethodEntry maps a method name to its transaction code.
type MultiVersionTable ¶
type MultiVersionTable map[Revision]CompiledTable
MultiVersionTable maps Revision -> CompiledTable. Revisions are like "34.r1", "35.r1", "36.r1", "36.r3", "36.r4".
var Tables MultiVersionTable
Tables holds compiled version tables. Empty by default; all resolution happens via lazy JAR extraction from the device.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures a version-aware Transport.
func OptionCachePath ¶
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 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 (*Transport) ActiveTable ¶ added in v0.0.9
func (t *Transport) ActiveTable() VersionTable
ActiveTable returns the current version table. The returned map must not be modified by the caller.
func (*Transport) ClearDeathNotification ¶
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 (*Transport) ReleaseHandle ¶
func (*Transport) RequestDeathNotification ¶
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) ResolveMethodSignature ¶ added in v0.0.8
func (t *Transport) ResolveMethodSignature( ctx context.Context, descriptor string, method string, ) []string
ResolveMethodSignature returns the parameter type descriptor list (DEX format) for the given method on the target device. Returns nil if the signature is unknown or cannot be extracted.
The signatures are extracted from the device's framework JARs during the same lazy extraction pass used by ResolveCode.
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.