mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 16:15:55 +01:00
Replace method pair() with connectFirstTime()
Should help with #642 for hplus which did not implement pair()
This commit is contained in:
parent
589945f234
commit
16af0724dd
@ -105,10 +105,10 @@ public class GBDeviceService implements DeviceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(@Nullable GBDevice device, boolean performPair) {
|
public void connect(@Nullable GBDevice device, boolean firstTime) {
|
||||||
Intent intent = createIntent().setAction(ACTION_CONNECT)
|
Intent intent = createIntent().setAction(ACTION_CONNECT)
|
||||||
.putExtra(GBDevice.EXTRA_DEVICE, device)
|
.putExtra(GBDevice.EXTRA_DEVICE, device)
|
||||||
.putExtra(EXTRA_PERFORM_PAIR, performPair);
|
.putExtra(EXTRA_CONNECT_FIRST_TIME, firstTime);
|
||||||
invokeService(intent);
|
invokeService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public interface DeviceService extends EventHandler {
|
|||||||
String EXTRA_URI = "uri";
|
String EXTRA_URI = "uri";
|
||||||
String EXTRA_CONFIG = "config";
|
String EXTRA_CONFIG = "config";
|
||||||
String EXTRA_ALARMS = "alarms";
|
String EXTRA_ALARMS = "alarms";
|
||||||
String EXTRA_PERFORM_PAIR = "perform_pair";
|
String EXTRA_CONNECT_FIRST_TIME = "connect_first_time";
|
||||||
String EXTRA_BOOLEAN_ENABLE = "enable_realtime_steps";
|
String EXTRA_BOOLEAN_ENABLE = "enable_realtime_steps";
|
||||||
|
|
||||||
String EXTRA_WEATHER_TIMESTAMP = "weather_timestamp";
|
String EXTRA_WEATHER_TIMESTAMP = "weather_timestamp";
|
||||||
|
@ -88,6 +88,14 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default implementation just calls #connect()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean connectFirstTime() {
|
||||||
|
return connect();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
return gbDevice.isConnected();
|
return gbDevice.isConnected();
|
||||||
|
@ -134,7 +134,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOT
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_SUBJECT;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_SUBJECT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TITLE;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TITLE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TYPE;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TYPE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_PERFORM_PAIR;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CONNECT_FIRST_TIME;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_URI;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_URI;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_VIBRATION_INTENSITY;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_VIBRATION_INTENSITY;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_WEATHER_CURRENTCONDITION;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_WEATHER_CURRENTCONDITION;
|
||||||
@ -239,7 +239,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
}
|
}
|
||||||
|
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
boolean pair = intent.getBooleanExtra(EXTRA_PERFORM_PAIR, false);
|
boolean firstTime = intent.getBooleanExtra(EXTRA_CONNECT_FIRST_TIME, false);
|
||||||
|
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
LOG.info("no action");
|
LOG.info("no action");
|
||||||
@ -299,8 +299,8 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
DeviceSupport deviceSupport = mFactory.createDeviceSupport(gbDevice);
|
DeviceSupport deviceSupport = mFactory.createDeviceSupport(gbDevice);
|
||||||
if (deviceSupport != null) {
|
if (deviceSupport != null) {
|
||||||
setDeviceSupport(deviceSupport);
|
setDeviceSupport(deviceSupport);
|
||||||
if (pair) {
|
if (firstTime) {
|
||||||
deviceSupport.pair();
|
deviceSupport.connectFirstTime();
|
||||||
} else {
|
} else {
|
||||||
deviceSupport.setAutoReconnect(autoReconnect);
|
deviceSupport.setAutoReconnect(autoReconnect);
|
||||||
deviceSupport.connect();
|
deviceSupport.connect();
|
||||||
|
@ -52,6 +52,27 @@ public interface DeviceSupport extends EventHandler {
|
|||||||
*/
|
*/
|
||||||
boolean isConnected();
|
boolean isConnected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to establish a connection to the device. Implementations may perform
|
* Attempts to establish a connection to the device. Implementations may perform
|
||||||
* the connection in a synchronous or asynchronous way.
|
* the connection in a synchronous or asynchronous way.
|
||||||
@ -62,6 +83,7 @@ public interface DeviceSupport extends EventHandler {
|
|||||||
* The actual connection state change (successful or not) will be reported via the
|
* The actual connection state change (successful or not) will be reported via the
|
||||||
* #getDevice device as a device change Intent.
|
* #getDevice device as a device change Intent.
|
||||||
*
|
*
|
||||||
|
* @see #connectFirstTime()
|
||||||
* @see GBDevice#ACTION_DEVICE_CHANGED
|
* @see GBDevice#ACTION_DEVICE_CHANGED
|
||||||
*/
|
*/
|
||||||
boolean connect();
|
boolean connect();
|
||||||
@ -92,14 +114,6 @@ public interface DeviceSupport extends EventHandler {
|
|||||||
*/
|
*/
|
||||||
boolean getAutoReconnect();
|
boolean getAutoReconnect();
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to pair and connect this device with the gadget device. Success
|
|
||||||
* will be reported via a device change Intent.
|
|
||||||
*
|
|
||||||
* @see GBDevice#ACTION_DEVICE_CHANGED
|
|
||||||
*/
|
|
||||||
void pair();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the associated device this instance communicates with.
|
* Returns the associated device this instance communicates with.
|
||||||
*/
|
*/
|
||||||
|
@ -72,6 +72,11 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
|||||||
return delegate.isConnected();
|
return delegate.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean connectFirstTime() {
|
||||||
|
return delegate.connectFirstTime();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connect() {
|
public boolean connect() {
|
||||||
return delegate.connect();
|
return delegate.connect();
|
||||||
@ -112,11 +117,6 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
|||||||
return delegate.useAutoConnect();
|
return delegate.useAutoConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pair() {
|
|
||||||
delegate.pair();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkBusy(String notificationKind) {
|
private boolean checkBusy(String notificationKind) {
|
||||||
if (!flags.contains(Flags.BUSY_CHECKING)) {
|
if (!flags.contains(Flags.BUSY_CHECKING)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -417,12 +417,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pair() {
|
|
||||||
|
|
||||||
LOG.debug("Pair");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleDeviceInfo(DeviceInfo info) {
|
private void handleDeviceInfo(DeviceInfo info) {
|
||||||
LOG.warn("Device info: " + info);
|
LOG.warn("Device info: " + info);
|
||||||
}
|
}
|
||||||
|
@ -217,12 +217,13 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pair() {
|
public boolean connectFirstTime() {
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
if (connect()) {
|
if (connect()) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceInfo getDeviceInfo() {
|
public DeviceInfo getDeviceInfo() {
|
||||||
|
@ -267,13 +267,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pair() {
|
public boolean connectFirstTime() {
|
||||||
needsAuth = true;
|
needsAuth = true;
|
||||||
for (int i = 0; i < 5; i++) {
|
return super.connect();
|
||||||
if (connect()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MiBand2Support sendDefaultNotification(TransactionBuilder builder, SimpleNotification simpleNotification, short repeat, BtLEAction extraAction) {
|
private MiBand2Support sendDefaultNotification(TransactionBuilder builder, SimpleNotification simpleNotification, short repeat, BtLEAction extraAction) {
|
||||||
|
@ -124,11 +124,6 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pair() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) {
|
private void handleDeviceInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfo info) {
|
||||||
LOG.warn("Device info: " + info);
|
LOG.warn("Device info: " + info);
|
||||||
versionCmd.hwVersion = info.getHardwareRevision();
|
versionCmd.hwVersion = info.getHardwareRevision();
|
||||||
|
@ -68,12 +68,6 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pair() {
|
|
||||||
// Default implementation does no manual pairing, use the Android
|
|
||||||
// pairing dialog instead.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lazily creates and returns the GBDeviceProtocol instance to be used.
|
* Lazily creates and returns the GBDeviceProtocol instance to be used.
|
||||||
*/
|
*/
|
||||||
|
@ -44,11 +44,6 @@ class TestDeviceSupport extends AbstractDeviceSupport {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pair() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotification(NotificationSpec notificationSpec) {
|
public void onNotification(NotificationSpec notificationSpec) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user