Interface NearbyBridge
Internal service-provider interface implemented by each platform port to
carry the com.codename1.nearby API onto the native short-range stacks:
Apple's Nearby Interaction, MultipeerConnectivity and AccessorySetupKit,
Android's Jetpack UWB, Nearby Connections and CompanionDeviceManager.
Application code never touches this interface. It is obtained by the
com.codename1.nearby packages from
com.codename1.ui.Display#getNearbyBridge(), and the base
implementation returns null -- which is why the public API degrades to
a well-behaved NOT_SUPPORTED on ports that implement nothing, and why
application code needs no platform if statements.
Everything here is primitives, strings and byte arrays
A port may be Objective-C reached through ParparVM, where constructing a
Java object is expensive and easy to get wrong. So no method on this
interface takes or returns a framework type: enums cross as their
ordinals, capability sets cross as bit masks, and structured records
cross as tab-delimited strings built by
com.codename1.impl.nearby.NearbyWire.
Asynchrony is by request id, and every operation must answer
Operations that can fail take a requestId allocated by the caller and
answer exactly once by calling the matching deliver... entry point on
the public class. An operation that never answers is worse than one
that fails: the caller holds an AsyncResource that will never settle
and has no way to find out. A port that cannot start something must
still report the failure.
Unsolicited events -- ranging updates, endpoint discoveries, presence changes -- carry the handle or endpoint id they belong to instead of a request id. Every entry point may be called from any thread; they marshal to the EDT themselves.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intgetRangingCapabilities()bit: third-party UWB accessories can be ranged.static final intgetRangingCapabilities()bit: ranging continues in the background.static final intgetRangingCapabilities()bit: camera assistance is available.static final intgetRangingCapabilities()bit: horizontal direction is measurable.static final intgetRangingCapabilities()bit: precise distance is measurable.static final intgetRangingCapabilities()bit: vertical direction is measurable.static final intsendPayload(int, String[], int, int, byte[], String)type: the payload is thebytesargument.static final intsendPayload(int, String[], int, int, byte[], String)type: the payload is the file atpath.static final intrequestPermissions(int, int)bit forNearbyPermission.ADVERTISE.static final intrequestPermissions(int, int)bit forNearbyPermission.CONNECT.static final intrequestPermissions(int, int)bit forNearbyPermission.DISCOVERY.static final intrequestPermissions(int, int)bit forNearbyPermission.RANGING. -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptConnection(int requestId, String endpointId) Accepts an incoming connection request.voidRuns the platform's device chooser and associates whatever the user picks, answering withcom.codename1.nearby.companion.CompanionDevices#deliverAssociated.voidcancelPayload(int payloadId) Cancels an in-flight payload.voiddisassociate(int requestId, String associationId) Drops an association, answering withcom.codename1.nearby.companion.CompanionDevices#deliverRequestFailedonly on failure andCompanionDevices#deliverDisassociatedon success.voiddisconnect(String endpointId) Disconnects one endpoint.String[]Every association this app currently holds, each encoded bycom.codename1.impl.nearby.NearbyWire.intHow usable companion association is right now, as aNearbyAvailabilityordinal.intThe largest byte payloadsendPayload(int, String[], int, int, byte[], String)accepts in one call.intHow usable ranging is right now, as aNearbyAvailabilityordinal.intWhat the device can measure, as an OR of theCAPABILITY_constants.intHow usable the transport is right now, as aNearbyAvailabilityordinal.booleanWhether this port implements companion-device association.booleanWhether this port implements precision ranging at all.booleanWhether this port implements the nearby transport.voidprepareRangingSession(int requestId, int sessionHandle, boolean controller) Allocates a platform ranging session and publishes its local token.voidrejectConnection(String endpointId) Rejects an incoming connection request.voidrequestConnection(int requestId, String endpointId, String localName) Asks a discovered endpoint to connect.voidrequestPermissions(int requestId, int permissionBits) Requests the platform permissions behind the givenNearbyPermissionbits, answering withcom.codename1.nearby.ranging.Ranging#deliverPermissionResult.voidsendPayload(int requestId, String[] endpointIds, int payloadId, int payloadType, byte[] bytes, String path) Sends a payload to one or more connected endpoints, reporting progress throughNearbyTransport#deliverPayloadProgress.voidstartAccessoryRanging(int requestId, int sessionHandle, byte[] accessoryData) Starts ranging a third-party UWB accessory.voidstartAdvertising(int requestId, String serviceId, String localName, int strategy) Starts advertising this device under a service id, answering withcom.codename1.nearby.transport.NearbyTransport#deliverRequestOk.voidstartDiscovery(int requestId, String serviceId, int strategy) Starts looking for peers advertising the same service id, answering withNearbyTransport#deliverRequestOk.booleanstartObservingPresence(String associationId) Asks the platform to wake this app when the associated device comes and goes.voidstartRanging(int requestId, int sessionHandle, byte[] peerToken) Starts ranging a peer whose token arrived out of band.voidStops advertising.voidStops advertising and discovery and drops every connection.voidStops discovery.voidstopObservingPresence(String associationId) Stops watching an association.voidstopRangingSession(int sessionHandle) Tears a ranging session down and releases the radio.
-
Field Details
-
CAPABILITY_DISTANCE
static final int CAPABILITY_DISTANCEgetRangingCapabilities()bit: precise distance is measurable.- See Also:
-
CAPABILITY_DIRECTION
static final int CAPABILITY_DIRECTIONgetRangingCapabilities()bit: horizontal direction is measurable.- See Also:
-
CAPABILITY_ELEVATION
static final int CAPABILITY_ELEVATIONgetRangingCapabilities()bit: vertical direction is measurable.- See Also:
-
CAPABILITY_CAMERA_ASSISTANCE
static final int CAPABILITY_CAMERA_ASSISTANCEgetRangingCapabilities()bit: camera assistance is available.- See Also:
-
CAPABILITY_ACCESSORY
static final int CAPABILITY_ACCESSORYgetRangingCapabilities()bit: third-party UWB accessories can be ranged.- See Also:
-
CAPABILITY_BACKGROUND
static final int CAPABILITY_BACKGROUNDgetRangingCapabilities()bit: ranging continues in the background.- See Also:
-
PERMISSION_RANGING
static final int PERMISSION_RANGINGrequestPermissions(int, int)bit forNearbyPermission.RANGING.- See Also:
-
PERMISSION_DISCOVERY
static final int PERMISSION_DISCOVERYrequestPermissions(int, int)bit forNearbyPermission.DISCOVERY.- See Also:
-
PERMISSION_ADVERTISE
static final int PERMISSION_ADVERTISErequestPermissions(int, int)bit forNearbyPermission.ADVERTISE.- See Also:
-
PERMISSION_CONNECT
static final int PERMISSION_CONNECTrequestPermissions(int, int)bit forNearbyPermission.CONNECT.- See Also:
-
PAYLOAD_BYTES
static final int PAYLOAD_BYTESsendPayload(int, String[], int, int, byte[], String)type: the payload is thebytesargument.- See Also:
-
PAYLOAD_FILE
static final int PAYLOAD_FILEsendPayload(int, String[], int, int, byte[], String)type: the payload is the file atpath.- See Also:
-
-
Method Details
-
isRangingSupported
boolean isRangingSupported()Whether this port implements precision ranging at all. Answer for the port and the hardware, not for whether a peer is around.
Returns
true when
com.codename1.nearby.ranginghas a real implementation -
isCompanionSupported
boolean isCompanionSupported()Whether this port implements companion-device association.
Returns
true when
com.codename1.nearby.companionhas a real implementation -
isTransportSupported
boolean isTransportSupported()Whether this port implements the nearby transport.
Returns
true when
com.codename1.nearby.transporthas a real implementation -
getRangingAvailability
int getRangingAvailability()How usable ranging is right now, as a
NearbyAvailabilityordinal. A port backed by a simulation must answerLOCAL_ONLYrather thanAVAILABLE, so an app can tell the developer their peers are not real.Returns
the ordinal of a
com.codename1.nearby.NearbyAvailabilityconstant -
getCompanionAvailability
int getCompanionAvailability()How usable companion association is right now, as a
NearbyAvailabilityordinal.Returns
the ordinal of a
com.codename1.nearby.NearbyAvailabilityconstant -
getTransportAvailability
int getTransportAvailability()How usable the transport is right now, as a
NearbyAvailabilityordinal.Returns
the ordinal of a
com.codename1.nearby.NearbyAvailabilityconstant -
requestPermissions
void requestPermissions(int requestId, int permissionBits) Requests the platform permissions behind the given
NearbyPermissionbits, answering withcom.codename1.nearby.ranging.Ranging#deliverPermissionResult.A port that needs no permission for the bits it was given must still answer, reporting them granted.
Parameters
requestId: the id to answer withpermissionBits: an OR of thePERMISSION_constants
-
getRangingCapabilities
int getRangingCapabilities()What the device can measure, as an OR of the
CAPABILITY_constants.Returns
the capability bits, or zero when ranging is unsupported
-
prepareRangingSession
void prepareRangingSession(int requestId, int sessionHandle, boolean controller) Allocates a platform ranging session and publishes its local token.
The port answers with
com.codename1.nearby.ranging.Ranging#deliverSessionPreparedon success, passing back the samesessionHandleit was given, or withRanging#deliverRequestFailedon failure. The session is not ranging yet --startRanging(int, int, byte[])orstartAccessoryRanging(int, int, byte[])does that.Parameters
requestId: the id to answer withsessionHandle: the handle every later call and event uses to name this sessioncontroller: true forRangingRole.CONTROLLER. Ports whose platform negotiates roles by itself ignore this.
-
startRanging
void startRanging(int requestId, int sessionHandle, byte[] peerToken) Starts ranging a peer whose token arrived out of band.
The token is the full encoded form from
com.codename1.nearby.ranging.RangingToken#toByteArray(); the port validates that it was minted by this platform and fails the request withNearbyError.INVALID_TOKENwhen it was not.Parameters
requestId: the id to answer with, viaRanging#deliverSessionStartedsessionHandle: the prepared sessionpeerToken: the peer's encoded token
-
startAccessoryRanging
void startAccessoryRanging(int requestId, int sessionHandle, byte[] accessoryData) Starts ranging a third-party UWB accessory.
The port answers with
com.codename1.nearby.ranging.Ranging#deliverAccessoryConfiguration, passing the bytes the app must send back to the accessory to make it start ranging (Apple's Nearby Interaction Accessory Protocol requires this handshake). A platform with no such handshake answers with an empty array rather than failing.Parameters
requestId: the id to answer withsessionHandle: the prepared sessionaccessoryData: the configuration data the accessory published
-
stopRangingSession
void stopRangingSession(int sessionHandle) Tears a ranging session down and releases the radio. Idempotent, and must not deliver any further event for this handle.
Parameters
sessionHandle: the session to stop
-
associate
Runs the platform's device chooser and associates whatever the user picks, answering with
com.codename1.nearby.companion.CompanionDevices#deliverAssociated.Parameters
requestId: the id to answer withprofile: the ordinal of acom.codename1.nearby.companion.CompanionProfileconstantsingleDevice: whether to associate without showing a list when exactly one device matchesfilters: the encoded filters fromcom.codename1.impl.nearby.NearbyWire, never null and possibly empty
-
getAssociations
String[] getAssociations()Every association this app currently holds, each encoded by
com.codename1.impl.nearby.NearbyWire.Returns
the associations, never null and possibly empty
-
disassociate
Drops an association, answering with
com.codename1.nearby.companion.CompanionDevices#deliverRequestFailedonly on failure andCompanionDevices#deliverDisassociatedon success.Parameters
requestId: the id to answer withassociationId: the association to drop
-
startObservingPresence
Asks the platform to wake this app when the associated device comes and goes.
Parameters
associationId: the association to watch
Returns
true when the platform accepted the request
-
stopObservingPresence
Stops watching an association. Idempotent.
Parameters
associationId: the association to stop watching
-
getMaxPayloadSize
int getMaxPayloadSize()The largest byte payload
sendPayload(int, String[], int, int, byte[], String)accepts in one call.Returns
the limit in bytes, or zero when the transport is unsupported
-
startAdvertising
Starts advertising this device under a service id, answering with
com.codename1.nearby.transport.NearbyTransport#deliverRequestOk.Parameters
requestId: the id to answer withserviceId: the service both ends agreed onlocalName: the name to show peersstrategy: the ordinal of acom.codename1.nearby.transport.TransportStrategyconstant
-
stopAdvertising
void stopAdvertising()Stops advertising. Idempotent. -
startDiscovery
Starts looking for peers advertising the same service id, answering with
NearbyTransport#deliverRequestOk. Sightings arrive unsolicited throughNearbyTransport#deliverEndpointFound.Parameters
requestId: the id to answer withserviceId: the service both ends agreed onstrategy: the ordinal of acom.codename1.nearby.transport.TransportStrategyconstant
-
stopDiscovery
void stopDiscovery()Stops discovery. Idempotent. -
requestConnection
Asks a discovered endpoint to connect. The endpoint answers by accepting or rejecting, which arrives through
NearbyTransport#deliverConnectionResult.Parameters
requestId: the id to answer withendpointId: the endpoint to asklocalName: the name to show them
-
acceptConnection
Accepts an incoming connection request.
Parameters
requestId: the id to answer withendpointId: the endpoint that asked
-
rejectConnection
Rejects an incoming connection request.
Parameters
endpointId: the endpoint that asked
-
sendPayload
void sendPayload(int requestId, String[] endpointIds, int payloadId, int payloadType, byte[] bytes, String path) Sends a payload to one or more connected endpoints, reporting progress through
NearbyTransport#deliverPayloadProgress.Parameters
requestId: the id to answer with once the payload is handed to the platformendpointIds: the recipientspayloadId: the id progress and cancellation usepayloadType:PAYLOAD_BYTESorPAYLOAD_FILEbytes: the payload forPAYLOAD_BYTES, otherwise nullpath: the file forPAYLOAD_FILE, otherwise null
-
cancelPayload
void cancelPayload(int payloadId) Cancels an in-flight payload. Idempotent.
Parameters
payloadId: the payload to cancel
-
disconnect
Disconnects one endpoint. Idempotent.
Parameters
endpointId: the endpoint to drop
-
stopAllTransport
void stopAllTransport()Stops advertising and discovery and drops every connection. Called when the app is shutting the transport down.
-