// src/NativeUnifiedBleProtocolControl.ts import type { TurboModule } from 'react-native' import { TurboModuleRegistry } from 'react-native' export interface NativeProtocolVersionRange { minimum: number maximum: number } export interface NativeProtocolHandshakeRequest { nativeProtocol: NativeProtocolVersionRange abi: NativeProtocolVersionRange controlSurface: NativeProtocolVersionRange backendContract: NativeProtocolVersionRange capabilitySchema: NativeProtocolVersionRange eventSchema: NativeProtocolVersionRange traceFormat: NativeProtocolVersionRange attachmentId: string backendInstanceId: string backendGeneration: string adapterId: string adapterGeneration: string ownerId: string } export interface NativeProtocolHandshakeResult { nativeProtocol: number abi: number controlSurface: number backendContract: number capabilitySchema: number eventSchema: number traceFormat: number maximumControlRecordBytes: number maximumBinaryPayloadBytes: number /** True only when this Android runtime can execute the API-26+ PHY operations. */ phyAvailable?: boolean /** True only when the native attachment implements the Android security extension. */ securityAvailable?: boolean /** True only when the native attachment can cancel system pairing on this API level. */ securityCancelPairingAvailable?: boolean } export interface NativeAttachmentIdentity { attachmentId: string backendInstanceId: string backendGeneration: string adapterId: string adapterGeneration: string } export interface NativeOperationCorrelation { attachment: NativeAttachmentIdentity dispatchEpoch: number nonce: string } export interface NativeRestorationBootstrapRequest { restorationId: string generation: string } export interface NativeRestorationBootstrapIdentity { applicationId: string restorationId: string generation: string restoreIdentifier: string namespaceValue: string clientId: string hostSessionScope: string } export interface NativeBackgroundLeaseRequest { kind: 'connected-device' reason: string } export interface NativeBackgroundLeaseResult { leaseId: string } export interface NativeBackgroundLeaseReleaseRequest { leaseId: string } export interface NativeBackgroundNotificationUpdateRequest { leaseId: string title: string body?: string } export interface NativeCompanionAssociationRequest { name?: string serviceUuid?: string } export interface NativeCompanionAssociationResult { source: 'associated' associationId: number peerId: string | null displayName: string | null } export type NativeRestorationOutcome = | 'adopted' | 'alreadyConsumed' | 'attachmentMismatch' | 'backendMismatch' | 'namespaceMismatch' | 'epochMismatch' export type NativeCancellationState = 'cancellationRequested' | 'alreadyTerminal' | 'notCancellable' export interface NativeRestorationAdoptionRequest { namespaceValue: string attachmentId: string expectedBackendInstanceId: string expectedEpoch: string nativeProtocolMinimum: number nativeProtocolMaximum: number clientId: string hostSessionScope: string } export interface NativeRestorationReplayRecord { recordVersion: number namespaceValue: string attachmentId: string backendInstanceId: string backendGeneration: string adapterId: string adapterGeneration: string ordinal: number adoptionEpoch: string kind: 'adapter' | 'connection' peerId: string | null connectionId: string | null ownerLeaseId: string | null connectionGeneration: string | null } export interface NativeRestorationAdoptionControlResult { receiptId: string outcome: NativeRestorationOutcome boundClientId: string adoptionEpoch: string replayRecordCount: number records: NativeRestorationReplayRecord[] } export interface NativeCancellationControlResult { state: NativeCancellationState } export interface Spec extends TurboModule { handshake(request: NativeProtocolHandshakeRequest): Promise bootstrapRestorationIdentity(request: NativeRestorationBootstrapRequest): Promise acquireBackground(request: NativeBackgroundLeaseRequest): Promise releaseBackground(request: NativeBackgroundLeaseReleaseRequest): Promise updateBackgroundNotification(request: NativeBackgroundNotificationUpdateRequest): Promise associateCompanionDevice(request: NativeCompanionAssociationRequest): Promise claimRestoration(): Promise installExecutionRuntime(): Promise cancelOperation(correlation: NativeOperationCorrelation): Promise adoptRestoration(request: NativeRestorationAdoptionRequest): Promise closeAttachment(attachment: NativeAttachmentIdentity): Promise /** Cryptographically secure random bytes as 0-255 integers. */ getRandomBytes(length: number): Promise } export default TurboModuleRegistry.getEnforcing('UnifiedBleProtocolControl')