1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.uwb.discovery; 18 19 import androidx.annotation.NonNull; 20 21 import com.android.server.uwb.discovery.info.FiraConnectorMessage.MessageType; 22 23 /** The interface of the physical data communication channel. */ 24 public interface Transport { 25 /** 26 * Send data to the remote device. 27 * 28 * @param messageType message type of the data to be sent. 29 * @param data Raw bytes of data to be sent. 30 * @param sendingDataCallback Callback for sneding data. 31 */ sendData( MessageType messageType, @NonNull byte[] data, SendingDataCallback sendingDataCallback)32 void sendData( 33 MessageType messageType, @NonNull byte[] data, SendingDataCallback sendingDataCallback); 34 35 /** 36 * Register the data receiver, only one receiver is allowed. 37 * 38 * @param dataReceiver Receiver of the data from remote device. 39 */ registerDataReceiver(DataReceiver dataReceiver)40 void registerDataReceiver(DataReceiver dataReceiver); 41 42 /** Unregister the current registered data receiver; */ unregisterDataReceiver()43 void unregisterDataReceiver(); 44 45 /** The receiver handles the incoming data from the remote device. */ 46 interface DataReceiver { 47 48 /** 49 * Called when new data is received from the remote device. 50 * 51 * @param data Raw bytes of data received. 52 */ onDataReceived(@onNull byte[] data)53 void onDataReceived(@NonNull byte[] data); 54 } 55 56 /** The callback to notify if the data is sent out or not. */ 57 interface SendingDataCallback { 58 59 /** The data is sent out. */ onSuccess()60 void onSuccess(); 61 62 /** The data failed to be sent out. */ onFailure()63 void onFailure(); 64 } 65 } 66