Skip to content

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(), and release() are synchronized and can be safely called from any thread. setBytes() and getBytes() methods are not synchronized — callers must handle synchronization externally in multi-threaded scenarios.
@since V1.0.0

Public Member Functions ​

initialize() ​

java
public static AidConnect initialize(Application context, boolean logDebug, AidConnectCallback aidKVCallback)

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 NameTypeDefault ValueDescription
contextApplication-Android Application object, must not be null
logDebugboolean-SDK log switch. true: prints all log levels; false: prints only error-level logs
aidKVCallbackAidConnectCallback-Initialization result callback, triggered on Binder thread; switch to main thread if UI updates are needed, must not be null
  • Return
TypeDescription
AidConnectReturns the AidConnect singleton instance
  • Note
ConditionBehavior
context is nullLogs warning and returns null
aidKVCallback is nullLogs warning and returns null

addChannelWithName() ​

java
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 NameTypeDefault ValueDescription
nameString-Channel name, must not be null or empty, must be globally unique
sizeint-Channel size in MB, must be > 0
  • Return
TypeDescription
Set<String>Set of all currently created channel names
  • Exceptions
ConditionBehavior
name is null or emptyLogs warning and returns current channel name set
size ≤ 0Throws IllegalArgumentException
Channel name already existsLogs warning and returns existing set without creating a duplicate

removeChannelWithName() ​

java
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 NameTypeDefault ValueDescription
nameString-Name of the channel to remove, must not be null
  • Return
TypeDescription
Set<String>Set of remaining channel names after removal
  • Exceptions
ConditionBehavior
name is nullLogs warning and returns current channel name set
Channel with given name does not existReturns current set with no side effects

aidConnectWithName() ​

java
public static synchronized AidConnect aidConnectWithName(String name)

Obtains the AidConnect instance for managing interactions on the specified channel.

  • Parameters
Parameter NameTypeDefault ValueDescription
nameString-Channel name previously created via addChannelWithName()
  • Return
TypeDescription
AidConnectAidConnect instance for the specified channel, used for data read/write operations
  • Exceptions
ConditionBehavior
Channel with given name does not existReturns null
  • Precondition

    Must call addChannelWithName() to create the channel first.

setBytes() ​

java
public boolean setBytes(byte[] bytes)

Writes byte data to the current channel.

  • Parameters
Parameter NameTypeDefault ValueDescription
bytesbyte[]-Byte array to write, must not be null, length must not exceed channel size
  • Return
TypeDescription
booleantrue: write successful; false: write failed (bytes is null or empty, channel not ready, or data exceeds channel capacity)

getBytes(int) ​

java
public byte[] getBytes(int len)

Reads data from the channel with the specified byte length.

  • Parameters
Parameter NameTypeDefault ValueDescription
lenint-Number of bytes to read, must be > 0 and not exceed available data length in channel
  • Return
TypeDescription
byte[]Byte array of read data; returns null if channel is not ready (e.g., not initialized or already released)
  • Exceptions
ConditionBehavior
len ≤ 0Throws Exception
Channel not initialized or already releasedReturns null (does not throw)

getBytes() ​

java
public byte[] getBytes()

Reads all byte data from the last write operation (length automatically matches the write length).

  • Return
TypeDescription
byte[]Complete byte array of read data; returns null if channel is not ready (e.g., not initialized or already released)
  • Exceptions
ConditionBehavior
Channel not initialized or already releasedReturns null (does not throw)

getBytes(byte[], int) ​

java
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 NameTypeDefault ValueDescription
bytesbyte[]-Pre-allocated target byte array, must not be null, must not be empty, and its length must equal len
lenint-Number of bytes to read, must be > 0 and must equal bytes.length
  • Return
TypeDescription
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
ConditionBehavior
bytes is emptyThrows Exception
len ≤ 0Throws Exception
bytes.length ≠ lenThrows Exception
Channel not initialized or already releasedReturns null (does not throw)

release() ​

java
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
TypeDescription
int0: release successful; non-0: release failed (see error codes below)
  • Error Codes
CodeMeaning
0Success
-1Channel already released or not initialized
  • Note

    Calling setBytes() / getBytes() after release results in undefined behavior.

setStateCallback() ​

java
public static void setStateCallback(RemoteSDKStatusCallBack remoteSDKStatusCallBack)

Sets the service connection status listener callback for receiving service state change notifications.

  • Parameters
Parameter NameTypeDefault ValueDescription
remoteSDKStatusCallBackRemoteSDKStatusCallBack-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.

MethodDescription
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.

MethodDescription
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 ​

java
// 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");
        }
    }
});