2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2015-2020 Andreas Shimokawa, Carsten Pfeiffer
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
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
|
|
|
|
2017-04-12 21:33:19 +02:00
|
|
|
/**
|
|
|
|
* Attempts an initial connection to the device, typically after the user "discovered"
|
|
|
|
* and connects to it for the first time. Some implementations may perform an additional
|
|
|
|
* initialization or application-level pairing compared to the regular {@link #connect()}.
|
|
|
|
* <p/>
|
|
|
|
* 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.
|
|
|
|
* <p/>
|
|
|
|
* The actual connection state change (successful or not) will be reported via the
|
|
|
|
* #getDevice device as a device change Intent.
|
|
|
|
*
|
|
|
|
* Note: the default implementation {@link AbstractDeviceSupport#connectFirstTime()} just
|
|
|
|
* calls {@link #connect()}
|
|
|
|
*
|
|
|
|
* @see #connect()
|
|
|
|
* @see GBDevice#ACTION_DEVICE_CHANGED
|
|
|
|
*/
|
|
|
|
boolean connectFirstTime();
|
|
|
|
|
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
|
|
|
*
|
2017-04-12 21:33:19 +02:00
|
|
|
* @see #connectFirstTime()
|
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
|
|
|
/**
|
|
|
|
* 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();
|
2019-09-14 00:05:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* converts String in a device specific way, e.g. re-map characters for a custom font
|
|
|
|
*/
|
|
|
|
String customStringFilter(String inputString);
|
2015-04-14 01:24:03 +02:00
|
|
|
}
|