2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service;
|
2015-04-14 01:24:03 +02:00
|
|
|
|
|
|
|
import android.bluetooth.BluetoothAdapter;
|
|
|
|
import android.content.Context;
|
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.EventHandler;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
|
2015-04-19 02:37:29 +02:00
|
|
|
/**
|
2015-08-02 00:12:21 +02:00
|
|
|
* Provides the communication support for a specific device. Instances will <b>only</b>
|
2015-08-04 01:01:14 +02:00
|
|
|
* be used inside the DeviceCommunicationService. Has hooks to manage the life cycle
|
2015-04-19 02:37:29 +02:00
|
|
|
* of a device: instances of this interface will be created, initialized, and disposed
|
|
|
|
* as needed.
|
2015-04-19 11:28:03 +02:00
|
|
|
* <p/>
|
2015-04-19 02:37:29 +02:00
|
|
|
* Implementations need to act accordingly, in order to establish, reestablish or close
|
|
|
|
* the connection to the device.
|
2015-04-19 11:28:03 +02:00
|
|
|
* <p/>
|
2015-08-02 00:12:21 +02:00
|
|
|
* In principle, this interface is agnostic to the kind of transport, i.e. whether the
|
|
|
|
* device is connected via Bluetooth, Bluetooth LE, Wifi or something else, however at the
|
|
|
|
* moment, only the BluetoothAdapter is passed to implementations.
|
2015-04-19 02:37:29 +02:00
|
|
|
*/
|
2015-04-14 01:24:03 +02:00
|
|
|
public interface DeviceSupport extends EventHandler {
|
2015-08-02 00:12:21 +02:00
|
|
|
/**
|
|
|
|
* Sets all context information needed for the instance to operate.
|
2015-09-24 14:45:21 +02:00
|
|
|
*
|
|
|
|
* @param gbDevice the device to operate with
|
2015-08-02 00:12:21 +02:00
|
|
|
* @param btAdapter the bluetooth adapter to use
|
2015-09-24 14:45:21 +02:00
|
|
|
* @param context the android context, e.g. to look up resources
|
2015-08-02 00:12:21 +02:00
|
|
|
*/
|
|
|
|
void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context);
|
2015-04-14 10:29:09 +02:00
|
|
|
|
2015-08-02 00:12:21 +02:00
|
|
|
/**
|
|
|
|
* Returns whether a transport-level connection is established with the device
|
2015-09-24 14:45:21 +02:00
|
|
|
*
|
2015-08-02 00:12:21 +02:00
|
|
|
* @return whether the device is connected with the system running this software
|
|
|
|
*/
|
2015-05-12 20:09:35 +02:00
|
|
|
boolean isConnected();
|
2015-04-19 11:28:03 +02:00
|
|
|
|
2015-08-02 00:12:21 +02:00
|
|
|
/**
|
|
|
|
* Attempts to establish a connection to the device. Implementations may perform
|
|
|
|
* the connection in a synchronous or asynchronous way.
|
|
|
|
* Returns true if a connection attempt was made. If the implementation is synchronous
|
|
|
|
* it may also return true if the connection was successfully established, however
|
|
|
|
* callers shall not rely on that.
|
2015-09-24 14:45:21 +02:00
|
|
|
* <p/>
|
2015-08-02 00:12:21 +02:00
|
|
|
* The actual connection state change (successful or not) will be reported via the
|
|
|
|
* #getDevice device as a device change Intent.
|
2015-09-24 14:45:21 +02:00
|
|
|
*
|
2015-08-02 00:12:21 +02:00
|
|
|
* @see GBDevice#ACTION_DEVICE_CHANGED
|
|
|
|
*/
|
2015-05-12 20:09:35 +02:00
|
|
|
boolean connect();
|
2015-04-14 01:24:03 +02:00
|
|
|
|
2015-08-02 00:12:21 +02:00
|
|
|
/**
|
|
|
|
* Disposes of this instance, closing all connections and freeing all resources.
|
|
|
|
* Instances will not be reused after having been disposed.
|
|
|
|
*/
|
2015-05-12 20:09:35 +02:00
|
|
|
void dispose();
|
2015-04-19 02:37:29 +02:00
|
|
|
|
2015-08-02 00:12:21 +02:00
|
|
|
/**
|
|
|
|
* Returns true if a connection attempt shall be made automatically whenever
|
|
|
|
* needed (e.g. when a notification shall be sent to the device while not connected.
|
|
|
|
*/
|
|
|
|
boolean useAutoConnect();
|
|
|
|
|
2016-04-28 23:17:13 +02:00
|
|
|
/**
|
|
|
|
* Configures this instance to automatically attempt to reconnect after a connection loss.
|
|
|
|
* How, how long, or how often is up to the implementation.
|
|
|
|
* Note that tome implementations may not support automatic reconnection at all.
|
|
|
|
* @param enable
|
|
|
|
*/
|
|
|
|
void setAutoReconnect(boolean enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this instance to configured to automatically attempt to reconnect after a
|
|
|
|
* connection loss.
|
|
|
|
*/
|
|
|
|
boolean getAutoReconnect();
|
|
|
|
|
2015-08-02 00:12:21 +02:00
|
|
|
/**
|
|
|
|
* Attempts to pair and connect this device with the gadget device. Success
|
|
|
|
* will be reported via a device change Intent.
|
2015-09-24 14:45:21 +02:00
|
|
|
*
|
2015-08-02 00:12:21 +02:00
|
|
|
* @see GBDevice#ACTION_DEVICE_CHANGED
|
|
|
|
*/
|
|
|
|
void pair();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the associated device this instance communicates with.
|
|
|
|
*/
|
2015-05-12 20:09:35 +02:00
|
|
|
GBDevice getDevice();
|
2015-04-14 10:29:09 +02:00
|
|
|
|
2015-08-02 00:12:21 +02:00
|
|
|
/**
|
|
|
|
* Returns the bluetooth adapter. When we support different transports
|
|
|
|
* than Bluetooth, we should use a generic type T and rename this method
|
|
|
|
* to getTransportAdapter()
|
|
|
|
*/
|
2015-05-12 20:09:35 +02:00
|
|
|
BluetoothAdapter getBluetoothAdapter();
|
2015-04-14 10:29:09 +02:00
|
|
|
|
2015-08-02 00:12:21 +02:00
|
|
|
/**
|
|
|
|
* Returns the Android context to use, e.g. to look up resources.
|
|
|
|
*/
|
2015-05-12 20:09:35 +02:00
|
|
|
Context getContext();
|
2015-04-14 01:24:03 +02:00
|
|
|
}
|