AidConnect Android API
class AidConnect
Core SDK class responsible for initialization, channel lifecycle management, and data read/write operations.
Thread Safety:
initialize(),addChannelWithName(),removeChannelWithName(),aidConnectWithName(), andrelease()aresynchronizedand can be safely called from any thread.setBytes()andgetBytes()methods are not synchronized — callers must handle synchronization externally in multi-threaded scenarios.
@since V1.0.0
Public Member Functions
initialize()
public static synchronized AidConnect initialize(Application mApplication, boolean logDebug, AidConnectCallback aidConnectCallback)Initializes the SDK, configures log level, and registers the initialization callback. Uses singleton pattern — repeated calls return the same instance. Must be called before using any other API.
- Parameters
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| mApplication | Application | - | Android Application object, must not be null |
| logDebug | boolean | - | SDK log switch. true: prints all log levels; false: prints only error-level logs |
| aidConnectCallback | AidConnectCallback | - | Initialization result callback, triggered on Binder thread; switch to main thread if UI updates are needed, must not be null |
- Return
| Type | Description |
|---|---|
| AidConnect | Returns the AidConnect singleton instance |
- Note
| Condition | Behavior |
|---|---|
| mApplication is null | Logs warning and returns null |
| aidConnectCallback is null | Logs warning and returns null |
addChannelWithName()
public static synchronized Set<String> addChannelWithName(String name, int size)Creates a communication channel with the specified name and size, and returns a set of all channel names.
- Parameters
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| name | String | - | Channel name, must not be null or empty, must be globally unique |
| size | int | - | Channel size in MB, must be > 0 |
- Return
| Type | Description |
|---|---|
| Set<String> | Set of all currently created channel names |
- Exceptions
| Condition | Behavior |
|---|---|
| name is null or empty | Logs warning and returns current channel name set |
| size ≤ 0 | Throws IllegalArgumentException |
| Channel name already exists | Logs warning and returns existing set without creating a duplicate |
removeChannelWithName()
public static synchronized Set<String> removeChannelWithName(String name)Removes the communication channel with the specified name and returns the set of remaining channel names.
- Parameters
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| name | String | - | Name of the channel to remove, must not be null |
- Return
| Type | Description |
|---|---|
| Set<String> | Set of remaining channel names after removal |
- Exceptions
| Condition | Behavior |
|---|---|
| name is null | Logs warning and returns current channel name set |
| Channel with given name does not exist | Returns current set with no side effects |
aidConnectWithName()
public static synchronized AidConnect aidConnectWithName(String name)Obtains the AidConnect instance for managing interactions on the specified channel.
- Parameters
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| name | String | - | Channel name previously created via addChannelWithName() |
- Return
| Type | Description |
|---|---|
| AidConnect | AidConnect instance for the specified channel, used for data read/write operations |
- Exceptions
| Condition | Behavior |
|---|---|
| Channel with given name does not exist | Returns null |
Precondition
Must call
addChannelWithName()to create the channel first.
setBytes()
public boolean setBytes(byte[] bytes)Writes byte data to the current channel.
- Parameters
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| bytes | byte[] | - | Byte array to write, must not be null, length must not exceed channel size |
- Return
| Type | Description |
|---|---|
| boolean | true: write successful; false: write failed (bytes is null or empty, channel not ready, or data exceeds channel capacity) |
getBytes(int)
public byte[] getBytes(int len)Reads data from the channel with the specified byte length.
- Parameters
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| len | int | - | Number of bytes to read, must be > 0 and not exceed available data length in channel |
- Return
| Type | Description |
|---|---|
| byte[] | Byte array of read data; returns null if channel is not ready (e.g., not initialized or already released) |
- Exceptions
| Condition | Behavior |
|---|---|
| len ≤ 0 | Throws Exception |
| Channel not initialized or already released | Returns null (does not throw) |
getBytes()
public byte[] getBytes()Reads all byte data from the last write operation (length automatically matches the write length).
- Return
| Type | Description |
|---|---|
| byte[] | Complete byte array of read data; returns null if channel is not ready (e.g., not initialized or already released) |
- Exceptions
| Condition | Behavior |
|---|---|
| Channel not initialized or already released | Returns null (does not throw) |
getBytes(byte[], int)
public byte[] getBytes(byte[] bytes, int len)Reads channel data into a pre-allocated byte array, avoiding repeated memory allocation. Suitable for high-frequency call scenarios.
- Parameters
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| bytes | byte[] | - | Pre-allocated target byte array, must not be null, must not be empty, and its length must equal len |
| len | int | - | Number of bytes to read, must be > 0 and must equal bytes.length |
- Return
| Type | Description |
|---|---|
| byte[] | The byte array filled with data (same reference as the input bytes); returns null if channel is not ready (e.g., not initialized or already released) |
- Exceptions
| Condition | Behavior |
|---|---|
bytes is empty | Throws Exception |
len ≤ 0 | Throws Exception |
bytes.length ≠ len | Throws Exception |
| Channel not initialized or already released | Returns null (does not throw) |
release()
public static synchronized int release()Releases all channel resources held by AidConnect and destroys the singleton. After calling, all AidConnect instances become unusable.
- Parameters
None
- Return
| Type | Description |
|---|---|
| int | 0: release successful; non-0: release failed (see error codes below) |
- Error Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| -1 | Channel already released or not initialized |
Note
Calling
setBytes()/getBytes()after release results in undefined behavior.
setStateCallback()
public static void setStateCallback(RemoteSDKStatusCallBack remoteSDKStatusCallBack)Sets the service connection status listener callback for receiving service state change notifications.
- Parameters
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
| remoteSDKStatusCallBack | RemoteSDKStatusCallBack | - | Service status callback interface instance |
Note
The SDK internally sets a default callback instance during initialization. Only call this method when custom monitoring is needed.
interface AidConnectCallback
SDK initialization result callback interface.
| Method | Description |
|---|---|
initCallback(boolean isInitSuccess, Set<String> keys) | Called when initialization completes; isInitSuccess is true on success, keys is the set of all channel names (null on failure) |
interface RemoteSDKStatusCallBack
Service connection status listener interface for receiving AidLux service state change events.
| Method | Description |
|---|---|
statusCallBackVisible() | Called when the AidLux service becomes visible |
statusCallBackInvisible() | Called when the AidLux service becomes invisible |
sendMessage(String message) | Called when a message is received from the service |
getAllFileDescriptors(Map<String, ParcelFileDescriptor> parcelFileDescriptorMap) | Called when the service returns all channel file descriptors, indicating initialization is complete |
serviceDisConnected() | Called when the connection to the AidLux service is lost |
Usage Example
// 1. Initialize SDK (returns singleton)
AidConnect instance = AidConnect.initialize(getApplication(), true, new AidConnectCallback() {
@Override
public void initCallback(boolean isInitSuccess, Set<String> keys) {
if (isInitSuccess) {
// 2. Create channel (10MB)
AidConnect.addChannelWithName("video_channel", 10);
// 3. Get AidConnect instance
AidConnect conn = AidConnect.aidConnectWithName("video_channel");
if (conn == null) {
Log.e("AidConnect", "Channel not found");
return;
}
// 4. Write data
byte[] data = getVideoFrame();
boolean success = conn.setBytes(data);
// 5. Read data
byte[] received = conn.getBytes();
// 6. Remove channel
AidConnect.removeChannelWithName("video_channel");
// 7. Release all resources (static method)
AidConnect.release();
} else {
Log.e("AidConnect", "Init failed");
}
}
});