This commit is contained in:
Aleksander Nowakowski
2018-04-25 10:29:43 +02:00
parent 92fe6cb5fb
commit 315cbbbcb8
29 changed files with 136 additions and 118 deletions

View File

@@ -41,7 +41,7 @@ There are 4 different solutions how to use the manager shown in different profil
A better implementation may be found in CSC, RSC, HTM and CGM. The BleManager instance is maintained by the running service. The service is started in order to connect to a device and stopped when user decides to disconnect from it. When an activity is destroyed it unbinds from the service, but the service is still running, so the incoming data may continue to be handled. All device-related data are kept be the service and may be obtained by a new activity when it binds to it in order to be shown to the user. A better implementation may be found in CSC, RSC, HTM and CGM. The BleManager instance is maintained by the running service. The service is started in order to connect to a device and stopped when user decides to disconnect from it. When an activity is destroyed it unbinds from the service, but the service is still running, so the incoming data may continue to be handled. All device-related data are kept be the service and may be obtained by a new activity when it binds to it in order to be shown to the user.
As a third, the Proximity profile allows to connect to multiple sensors at the same time. It uses a different service implementation but still the BleManager is used to manage each connection. If the [shouldAutoConnect()](hhttps://github.com/NordicSemiconductor/Android-BLE-Library/blob/master/ble/src/main/java/no/nordicsemi/android/ble/BleManager.java#L246) method returns true for a connection, the manager will try to reconnect automatically to the device if a link was lost. You will also be notified about a device that got away using ```onLinklossOccur(BluetoothDevice)```. As a third, the Proximity profile allows to connect to multiple sensors at the same time. It uses a different service implementation but still the BleManager is used to manage each connection. If the [shouldAutoConnect()](hhttps://github.com/NordicSemiconductor/Android-BLE-Library/blob/master/ble/src/main/java/no/nordicsemi/android/ble/BleManager.java#L246) method returns true for a connection, the manager will try to reconnect automatically to the device if a link was lost. You will also be notified about a device that got away using ```onLinklossOccurred(BluetoothDevice)```.
The BleMulticonnectProfileService implementation, used by Proximity profile, does not save addresses of connected devices. When the service is killed it will not be able to reconnect to them after it's restarted, so this feature has been disabled. Also, when user removes the nRF Toolbox app from Recents, the service will be killed and all devices will be disconnected automatically. To change this behaviour a service would have to either save the addresses and reconnect to devices after it has restarted (but then removing the app from Recents would cause disconnection and immediate reconnection as the service is then killed and moved to another process), or would have to be implemented in a way that is using another [process](https://developer.android.com/guide/topics/manifest/service-element.html#proc). Then, however, it is not possible to bind to such service and data must be exchanged using a [Messenger](https://developer.android.com/reference/android/app/Service.html#RemoteMessengerServiceSample). Such approach is not demonstrated in nRF Toolbox. The BleMulticonnectProfileService implementation, used by Proximity profile, does not save addresses of connected devices. When the service is killed it will not be able to reconnect to them after it's restarted, so this feature has been disabled. Also, when user removes the nRF Toolbox app from Recents, the service will be killed and all devices will be disconnected automatically. To change this behaviour a service would have to either save the addresses and reconnect to devices after it has restarted (but then removing the app from Recents would cause disconnection and immediate reconnection as the service is then killed and moved to another process), or would have to be implemented in a way that is using another [process](https://developer.android.com/guide/topics/manifest/service-element.html#proc). Then, however, it is not possible to bind to such service and data must be exchanged using a [Messenger](https://developer.android.com/reference/android/app/Service.html#RemoteMessengerServiceSample). Such approach is not demonstrated in nRF Toolbox.
@@ -91,7 +91,7 @@ To open the DFU settings click the *Settings* button in the top toolbar when on
**MBR size** - This value is used only to convert HEX files into BIN files. If your packet is already in the BIN format, this value is ignored. The data from addresses lower then this value are being skipped while converting HEX to BIN. This is to prevent from sending the MBR (Master Boot Record) part from the HEX file that contains the Soft Device. The compiled Soft Device contains data that starts at address 0x0000 and contains the MBR. It is followed by the jump to address 0x1000 (default MBR size) where the Soft Device firmware starts. Only the Soft Device part must be sent over DFU. **MBR size** - This value is used only to convert HEX files into BIN files. If your packet is already in the BIN format, this value is ignored. The data from addresses lower then this value are being skipped while converting HEX to BIN. This is to prevent from sending the MBR (Master Boot Record) part from the HEX file that contains the Soft Device. The compiled Soft Device contains data that starts at address 0x0000 and contains the MBR. It is followed by the jump to address 0x1000 (default MBR size) where the Soft Device firmware starts. Only the Soft Device part must be sent over DFU.
**Keep bond information** - When upgrading the application on a bonded device the DFU bootloader may be configured to preserve some pages of the application's memory intact, so that the new application may read them. The new application must know the old data format in order to read them correctly. Our HRS DFU sample stores the Long Term Key (LTK) and the Service Attributes in two first pages. However, the DFU Bootloader, by default, clears the whole application's memory when the new application upload completes, and the bond information is lost. In order to configure the number of pages to be preserved set the **DFU_APP_DATA_RESERVED** value in the *dfu_types.h* file in the DFU bootloader code (line ~56). To preserve two pages the value should be set to 0x0800. When your DFU bootloader has been modified to keep the bond information after updating the application set the switch to ON. Otherwise the bond information will be removed from the phone. **Keep bond information** - When upgrading the application on a bound device the DFU bootloader may be configured to preserve some pages of the application's memory intact, so that the new application may read them. The new application must know the old data format in order to read them correctly. Our HRS DFU sample stores the Long Term Key (LTK) and the Service Attributes in two first pages. However, the DFU Bootloader, by default, clears the whole application's memory when the new application upload completes, and the bond information is lost. In order to configure the number of pages to be preserved set the **DFU_APP_DATA_RESERVED** value in the *dfu_types.h* file in the DFU bootloader code (line ~56). To preserve two pages the value should be set to 0x0800. When your DFU bootloader has been modified to keep the bond information after updating the application set the switch to ON. Otherwise the bond information will be removed from the phone.
**External MCU DFU** - The DFU service from the library, when connected to a DFU target, will check whether it is in application or in DFU bootloader mode. For DFU implementations from SDK 7.0 or newer this is done by reading the value of DFU Version characteristic. If the returned value is equal to 0x0100 (major = 0, minor = 1) it means that we are in the application mode and jump to the bootloader mode is required. **External MCU DFU** - The DFU service from the library, when connected to a DFU target, will check whether it is in application or in DFU bootloader mode. For DFU implementations from SDK 7.0 or newer this is done by reading the value of DFU Version characteristic. If the returned value is equal to 0x0100 (major = 0, minor = 1) it means that we are in the application mode and jump to the bootloader mode is required.

View File

@@ -115,7 +115,7 @@ public class CGMSActivity extends BleProfileServiceReadyActivity<CGMService.CGMS
} }
@Override @Override
protected void onServiceBinded(final CGMService.CGMSBinder binder) { protected void onServiceBound(final CGMService.CGMSBinder binder) {
mBinder = binder; mBinder = binder;
final SparseArray<CGMSRecord> cgmsRecords = binder.getRecords(); final SparseArray<CGMSRecord> cgmsRecords = binder.getRecords();
if (cgmsRecords != null && cgmsRecords.size() > 0) { if (cgmsRecords != null && cgmsRecords.size() > 0) {
@@ -128,7 +128,7 @@ public class CGMSActivity extends BleProfileServiceReadyActivity<CGMService.CGMS
} }
@Override @Override
protected void onServiceUnbinded() { protected void onServiceUnbound() {
mBinder = null; mBinder = null;
} }

View File

@@ -167,12 +167,12 @@ public class CSCActivity extends BleProfileServiceReadyActivity<CSCService.CSCBi
} }
@Override @Override
protected void onServiceBinded(final CSCService.CSCBinder binder) { protected void onServiceBound(final CSCService.CSCBinder binder) {
// not used // not used
} }
@Override @Override
protected void onServiceUnbinded() { protected void onServiceUnbound() {
// not used // not used
} }

View File

@@ -128,12 +128,12 @@ public class HTSActivity extends BleProfileServiceReadyActivity<HTSService.RSCBi
} }
@Override @Override
protected void onServiceBinded(final HTSService.RSCBinder binder) { protected void onServiceBound(final HTSService.RSCBinder binder) {
// not used // not used
} }
@Override @Override
protected void onServiceUnbinded() { protected void onServiceUnbound() {
// not used // not used
} }

View File

@@ -108,7 +108,7 @@ public class HTSService extends BleProfileService implements HTSManagerCallbacks
broadcast.putExtra(EXTRA_TEMPERATURE, value); broadcast.putExtra(EXTRA_TEMPERATURE, value);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
if (!mBinded) { if (!mBound) {
// Here we may update the notification to display the current temperature. // Here we may update the notification to display the current temperature.
// TODO modify the notification here // TODO modify the notification here
} }

View File

@@ -278,7 +278,7 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
mDeviceConnected = false; mDeviceConnected = false;
} }
@@ -298,7 +298,7 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
} }
@Override @Override
public void onBonded(final BluetoothDevice device) { public void onBound(final BluetoothDevice device) {
showToast(R.string.bonded); showToast(R.string.bonded);
} }

View File

@@ -278,7 +278,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
mDeviceConnected = false; mDeviceConnected = false;
} }
@@ -298,7 +298,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
} }
@Override @Override
public void onBonded(final BluetoothDevice device) { public void onBound(final BluetoothDevice device) {
showToast(R.string.bonded); showToast(R.string.bonded);
} }

View File

@@ -81,7 +81,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
private BleManager<BleManagerCallbacks> mBleManager; private BleManager<BleManagerCallbacks> mBleManager;
private Handler mHandler; private Handler mHandler;
protected boolean mBinded; protected boolean mBound;
private boolean mActivityIsChangingConfiguration; private boolean mActivityIsChangingConfiguration;
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
private String mDeviceName; private String mDeviceName;
@@ -234,13 +234,13 @@ public abstract class BleProfileService extends Service implements BleManagerCal
@Override @Override
public IBinder onBind(final Intent intent) { public IBinder onBind(final Intent intent) {
mBinded = true; mBound = true;
return getBinder(); return getBinder();
} }
@Override @Override
public final void onRebind(final Intent intent) { public final void onRebind(final Intent intent) {
mBinded = true; mBound = true;
if (!mActivityIsChangingConfiguration) if (!mActivityIsChangingConfiguration)
onRebind(); onRebind();
@@ -257,7 +257,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
@Override @Override
public final boolean onUnbind(final Intent intent) { public final boolean onUnbind(final Intent intent) {
mBinded = false; mBound = false;
if (!mActivityIsChangingConfiguration) if (!mActivityIsChangingConfiguration)
onUnbind(); onUnbind();
@@ -424,7 +424,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
// Note 2: if BleManager#shouldAutoConnect() for this device returned true, this callback will be // Note 2: if BleManager#shouldAutoConnect() for this device returned true, this callback will be
// invoked ONLY when user requested disconnection (using Disconnect button). If the device // invoked ONLY when user requested disconnection (using Disconnect button). If the device
// disconnects due to a link loss, the onLinklossOccur(BluetoothDevice) method will be called instead. // disconnects due to a link loss, the onLinklossOccurred(BluetoothDevice) method will be called instead.
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE); final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
broadcast.putExtra(EXTRA_DEVICE, mBluetoothDevice); broadcast.putExtra(EXTRA_DEVICE, mBluetoothDevice);
@@ -442,7 +442,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE); final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
broadcast.putExtra(EXTRA_DEVICE, mBluetoothDevice); broadcast.putExtra(EXTRA_DEVICE, mBluetoothDevice);
broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_LINK_LOSS); broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_LINK_LOSS);
@@ -495,7 +495,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
} }
@Override @Override
public void onBonded(final BluetoothDevice device) { public void onBound(final BluetoothDevice device) {
showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonded); showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonded);
final Intent broadcast = new Intent(BROADCAST_BOND_STATE); final Intent broadcast = new Intent(BROADCAST_BOND_STATE);

View File

@@ -112,7 +112,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
break; break;
} }
case BleProfileService.STATE_LINK_LOSS: { case BleProfileService.STATE_LINK_LOSS: {
onLinklossOccur(bluetoothDevice); onLinklossOccurred(bluetoothDevice);
break; break;
} }
case BleProfileService.STATE_CONNECTING: { case BleProfileService.STATE_CONNECTING: {
@@ -151,7 +151,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
onBondingRequired(bluetoothDevice); onBondingRequired(bluetoothDevice);
break; break;
case BluetoothDevice.BOND_BONDED: case BluetoothDevice.BOND_BONDED:
onBonded(bluetoothDevice); onBound(bluetoothDevice);
break; break;
} }
break; break;
@@ -180,7 +180,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
mBluetoothDevice = bleService.getBluetoothDevice(); mBluetoothDevice = bleService.getBluetoothDevice();
mLogSession = mService.getLogSession(); mLogSession = mService.getLogSession();
Logger.d(mLogSession, "Activity bound to the service"); Logger.d(mLogSession, "Activity bound to the service");
onServiceBinded(bleService); onServiceBound(bleService);
// Update UI // Update UI
mDeviceName = bleService.getDeviceName(); mDeviceName = bleService.getDeviceName();
@@ -211,7 +211,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
mDeviceName = null; mDeviceName = null;
mBluetoothDevice = null; mBluetoothDevice = null;
mLogSession = null; mLogSession = null;
onServiceUnbinded(); onServiceUnbound();
} }
}; };
@@ -277,7 +277,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
mService = null; mService = null;
Logger.d(mLogSession, "Activity unbound from the service"); Logger.d(mLogSession, "Activity unbound from the service");
onServiceUnbinded(); onServiceUnbound();
mDeviceName = null; mDeviceName = null;
mBluetoothDevice = null; mBluetoothDevice = null;
mLogSession = null; mLogSession = null;
@@ -308,13 +308,13 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
* Called when activity binds to the service. The parameter is the object returned in {@link Service#onBind(Intent)} method in your service. The method is * Called when activity binds to the service. The parameter is the object returned in {@link Service#onBind(Intent)} method in your service. The method is
* called when device gets connected or is created while sensor was connected before. You may use the binder as a sensor interface. * called when device gets connected or is created while sensor was connected before. You may use the binder as a sensor interface.
*/ */
protected abstract void onServiceBinded(E binder); protected abstract void onServiceBound(E binder);
/** /**
* Called when activity unbinds from the service. You may no longer use this binder because the sensor was disconnected. This method is also called when you * Called when activity unbinds from the service. You may no longer use this binder because the sensor was disconnected. This method is also called when you
* leave the activity being connected to the sensor in the background. * leave the activity being connected to the sensor in the background.
*/ */
protected abstract void onServiceUnbinded(); protected abstract void onServiceUnbound();
/** /**
* Returns the service class for sensor communication. The service class must derive from {@link BleProfileService} in order to operate with this class. * Returns the service class for sensor communication. The service class must derive from {@link BleProfileService} in order to operate with this class.
@@ -511,7 +511,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
mService = null; mService = null;
Logger.d(mLogSession, "Activity unbound from the service"); Logger.d(mLogSession, "Activity unbound from the service");
onServiceUnbinded(); onServiceUnbound();
mDeviceName = null; mDeviceName = null;
mBluetoothDevice = null; mBluetoothDevice = null;
mLogSession = null; mLogSession = null;
@@ -521,7 +521,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
// empty default implementation // empty default implementation
} }
@@ -541,7 +541,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
} }
@Override @Override
public void onBonded(final BluetoothDevice device) { public void onBound(final BluetoothDevice device) {
// empty default implementation // empty default implementation
} }

View File

@@ -79,7 +79,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
private List<BluetoothDevice> mManagedDevices; private List<BluetoothDevice> mManagedDevices;
private Handler mHandler; private Handler mHandler;
protected boolean mBinded; protected boolean mBound;
private boolean mActivityIsChangingConfiguration; private boolean mActivityIsChangingConfiguration;
private final BroadcastReceiver mBluetoothStateBroadcastReceiver = new BroadcastReceiver() { private final BroadcastReceiver mBluetoothStateBroadcastReceiver = new BroadcastReceiver() {
@@ -251,13 +251,13 @@ public abstract class BleMulticonnectProfileService extends Service implements B
@Override @Override
public IBinder onBind(final Intent intent) { public IBinder onBind(final Intent intent) {
mBinded = true; mBound = true;
return getBinder(); return getBinder();
} }
@Override @Override
public final void onRebind(final Intent intent) { public final void onRebind(final Intent intent) {
mBinded = true; mBound = true;
if (!mActivityIsChangingConfiguration) { if (!mActivityIsChangingConfiguration) {
onRebind(); onRebind();
@@ -275,7 +275,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
@Override @Override
public final boolean onUnbind(final Intent intent) { public final boolean onUnbind(final Intent intent) {
mBinded = false; mBound = false;
if (!mActivityIsChangingConfiguration) { if (!mActivityIsChangingConfiguration) {
if (!mManagedDevices.isEmpty()) { if (!mManagedDevices.isEmpty()) {
@@ -435,7 +435,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
public void onDeviceDisconnected(final BluetoothDevice device) { public void onDeviceDisconnected(final BluetoothDevice device) {
// Note: if BleManager#shouldAutoConnect() for this device returned true, this callback will be // Note: if BleManager#shouldAutoConnect() for this device returned true, this callback will be
// invoked ONLY when user requested disconnection (using Disconnect button). If the device // invoked ONLY when user requested disconnection (using Disconnect button). If the device
// disconnects due to a link loss, the onLinklossOccur(BluetoothDevice) method will be called instead. // disconnects due to a link loss, the onLinklossOccurred(BluetoothDevice) method will be called instead.
// We no longer want to keep the device in the service // We no longer want to keep the device in the service
mManagedDevices.remove(device); mManagedDevices.remove(device);
@@ -449,13 +449,13 @@ public abstract class BleMulticonnectProfileService extends Service implements B
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
// When user disconnected the last device while the activity was not bound the service can be stopped // When user disconnected the last device while the activity was not bound the service can be stopped
if (!mBinded && mManagedDevices.isEmpty()) { if (!mBound && mManagedDevices.isEmpty()) {
stopSelf(); stopSelf();
} }
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE); final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
broadcast.putExtra(EXTRA_DEVICE, device); broadcast.putExtra(EXTRA_DEVICE, device);
broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_LINK_LOSS); broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_LINK_LOSS);
@@ -512,7 +512,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
} }
@Override @Override
public void onBonded(final BluetoothDevice device) { public void onBound(final BluetoothDevice device) {
showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonded); showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonded);
final Intent broadcast = new Intent(BROADCAST_BOND_STATE); final Intent broadcast = new Intent(BROADCAST_BOND_STATE);

View File

@@ -99,7 +99,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
break; break;
} }
case BleMulticonnectProfileService.STATE_LINK_LOSS: { case BleMulticonnectProfileService.STATE_LINK_LOSS: {
onLinklossOccur(bluetoothDevice); onLinklossOccurred(bluetoothDevice);
break; break;
} }
case BleMulticonnectProfileService.STATE_CONNECTING: { case BleMulticonnectProfileService.STATE_CONNECTING: {
@@ -138,7 +138,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
onBondingRequired(bluetoothDevice); onBondingRequired(bluetoothDevice);
break; break;
case BluetoothDevice.BOND_BONDED: case BluetoothDevice.BOND_BONDED:
onBonded(bluetoothDevice); onBound(bluetoothDevice);
break; break;
} }
break; break;
@@ -166,7 +166,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
final E bleService = mService = (E) service; final E bleService = mService = (E) service;
bleService.log(LogContract.Log.Level.DEBUG, "Activity bound to the service"); bleService.log(LogContract.Log.Level.DEBUG, "Activity bound to the service");
mManagedDevices.addAll(bleService.getManagedDevices()); mManagedDevices.addAll(bleService.getManagedDevices());
onServiceBinded(bleService); onServiceBound(bleService);
// and notify user if device is connected // and notify user if device is connected
for (final BluetoothDevice device : mManagedDevices) { for (final BluetoothDevice device : mManagedDevices) {
@@ -178,7 +178,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
@Override @Override
public void onServiceDisconnected(final ComponentName name) { public void onServiceDisconnected(final ComponentName name) {
mService = null; mService = null;
onServiceUnbinded(); onServiceUnbound();
} }
}; };
@@ -238,7 +238,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
unbindService(mServiceConnection); unbindService(mServiceConnection);
mService = null; mService = null;
onServiceUnbinded(); onServiceUnbound();
} }
@Override @Override
@@ -263,12 +263,12 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
* Called when activity binds to the service. The parameter is the object returned in {@link Service#onBind(Intent)} method in your service. * Called when activity binds to the service. The parameter is the object returned in {@link Service#onBind(Intent)} method in your service.
* It is safe to obtain managed devices now. * It is safe to obtain managed devices now.
*/ */
protected abstract void onServiceBinded(E binder); protected abstract void onServiceBound(E binder);
/** /**
* Called when activity unbinds from the service. You may no longer use this binder methods. * Called when activity unbinds from the service. You may no longer use this binder methods.
*/ */
protected abstract void onServiceUnbinded(); protected abstract void onServiceUnbound();
/** /**
* Returns the service class for sensor communication. The service class must derive from {@link BleMulticonnectProfileService} in order to operate with this class. * Returns the service class for sensor communication. The service class must derive from {@link BleMulticonnectProfileService} in order to operate with this class.
@@ -415,7 +415,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
// empty default implementation // empty default implementation
} }
@@ -435,7 +435,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
} }
@Override @Override
public void onBonded(final BluetoothDevice device) { public void onBound(final BluetoothDevice device) {
// empty default implementation // empty default implementation
} }

View File

@@ -78,12 +78,12 @@ public class ProximityActivity extends BleMulticonnectProfileServiceReadyActivit
} }
@Override @Override
protected void onServiceBinded(final ProximityService.ProximityBinder binder) { protected void onServiceBound(final ProximityService.ProximityBinder binder) {
mDevicesView.setAdapter(mAdapter = new DeviceAdapter(binder)); mDevicesView.setAdapter(mAdapter = new DeviceAdapter(binder));
} }
@Override @Override
protected void onServiceUnbinded() { protected void onServiceUnbound() {
mDevicesView.setAdapter(mAdapter = null); mDevicesView.setAdapter(mAdapter = null);
} }
@@ -140,7 +140,7 @@ public class ProximityActivity extends BleMulticonnectProfileServiceReadyActivit
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
if (mAdapter != null) if (mAdapter != null)
mAdapter.onDeviceStateChanged(device); mAdapter.onDeviceStateChanged(device);

View File

@@ -262,7 +262,7 @@ public class ProximityService extends BleMulticonnectProfileService implements P
public void onDeviceConnected(final BluetoothDevice device) { public void onDeviceConnected(final BluetoothDevice device) {
super.onDeviceConnected(device); super.onDeviceConnected(device);
if (!mBinded) { if (!mBound) {
createBackgroundNotification(); createBackgroundNotification();
} }
} }
@@ -274,12 +274,12 @@ public class ProximityService extends BleMulticonnectProfileService implements P
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
mServerManager.cancelConnection(device); mServerManager.cancelConnection(device);
stopAlarm(device); stopAlarm(device);
super.onLinklossOccur(device); super.onLinklossOccurred(device);
if (!mBinded) { if (!mBound) {
createBackgroundNotification(); createBackgroundNotification();
if (BluetoothAdapter.getDefaultAdapter().isEnabled()) if (BluetoothAdapter.getDefaultAdapter().isEnabled())
createLinklossNotification(device); createLinklossNotification(device);
@@ -294,7 +294,7 @@ public class ProximityService extends BleMulticonnectProfileService implements P
stopAlarm(device); stopAlarm(device);
super.onDeviceDisconnected(device); super.onDeviceDisconnected(device);
if (!mBinded) { if (!mBound) {
cancelNotification(device); cancelNotification(device);
createBackgroundNotification(); createBackgroundNotification();
} }

View File

@@ -167,12 +167,12 @@ public class RSCActivity extends BleProfileServiceReadyActivity<RSCService.RSCBi
} }
@Override @Override
protected void onServiceBinded(final RSCService.RSCBinder binder) { protected void onServiceBound(final RSCService.RSCBinder binder) {
// not used // not used
} }
@Override @Override
protected void onServiceUnbinded() { protected void onServiceUnbound() {
// not used // not used
} }

View File

@@ -76,7 +76,7 @@ public class RSCService extends BleProfileService implements RSCManagerCallbacks
private final LocalBinder mBinder = new RSCBinder(); private final LocalBinder mBinder = new RSCBinder();
/** /**
* This local binder is an interface for the binded activity to operate with the RSC sensor * This local binder is an interface for the bound activity to operate with the RSC sensor
*/ */
public class RSCBinder extends LocalBinder { public class RSCBinder extends LocalBinder {
// empty // empty

View File

@@ -56,8 +56,10 @@ import no.nordicsemi.android.support.v18.scanner.ScanResult;
import no.nordicsemi.android.support.v18.scanner.ScanSettings; import no.nordicsemi.android.support.v18.scanner.ScanSettings;
/** /**
* ScannerFragment class scan required BLE devices and shows them in a list. This class scans and filter devices with standard BLE Service UUID and devices with custom BLE Service UUID. It contains a * ScannerFragment class scan required BLE devices and shows them in a list. This class scans and filter
* list and a button to scan/cancel. There is a interface {@link OnDeviceSelectedListener} which is implemented by activity in order to receive selected device. The scanning will continue to scan * devices with standard BLE Service UUID and devices with custom BLE Service UUID. It contains a
* list and a button to scan/cancel. There is a interface {@link OnDeviceSelectedListener} which is
* implemented by activity in order to receive selected device. The scanning will continue to scan
* for 5 seconds and then stop. * for 5 seconds and then stop.
*/ */
public class ScannerFragment extends DialogFragment { public class ScannerFragment extends DialogFragment {
@@ -100,8 +102,9 @@ public class ScannerFragment extends DialogFragment {
* @param device * @param device
* the device to connect to * the device to connect to
* @param name * @param name
* the device name. Unfortunately on some devices {@link BluetoothDevice#getName()} always returns <code>null</code>, f.e. Sony Xperia Z1 (C6903) with Android 4.3. The name has to * the device name. Unfortunately on some devices {@link BluetoothDevice#getName()}
* be parsed manually form the Advertisement packet. * always returns <code>null</code>, i.e. Sony Xperia Z1 (C6903) with Android 4.3.
* The name has to be parsed manually form the Advertisement packet.
*/ */
void onDeviceSelected(final BluetoothDevice device, final String name); void onDeviceSelected(final BluetoothDevice device, final String name);
@@ -129,12 +132,14 @@ public class ScannerFragment extends DialogFragment {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final Bundle args = getArguments(); final Bundle args = getArguments();
if (args.containsKey(PARAM_UUID)) { if (args != null && args.containsKey(PARAM_UUID)) {
mUuid = args.getParcelable(PARAM_UUID); mUuid = args.getParcelable(PARAM_UUID);
} }
final BluetoothManager manager = (BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothManager manager = (BluetoothManager) requireContext().getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = manager.getAdapter(); if (manager != null) {
mBluetoothAdapter = manager.getAdapter();
}
} }
@Override @Override
@@ -146,7 +151,7 @@ public class ScannerFragment extends DialogFragment {
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(final Bundle savedInstanceState) { public Dialog onCreateDialog(final Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
final View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_device_selection, null); final View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_device_selection, null);
final ListView listview = dialogView.findViewById(android.R.id.list); final ListView listview = dialogView.findViewById(android.R.id.list);
@@ -175,7 +180,7 @@ public class ScannerFragment extends DialogFragment {
} }
}); });
addBondedDevices(); addBoundDevices();
if (savedInstanceState == null) if (savedInstanceState == null)
startScan(); startScan();
return dialog; return dialog;
@@ -205,16 +210,17 @@ public class ScannerFragment extends DialogFragment {
} }
/** /**
* Scan for 5 seconds and then stop scanning when a BluetoothLE device is found then mLEScanCallback is activated This will perform regular scan for custom BLE Service UUID and then filter out. * Scan for 5 seconds and then stop scanning when a BluetoothLE device is found then mLEScanCallback
* is activated This will perform regular scan for custom BLE Service UUID and then filter out.
* using class ScannerServiceParser * using class ScannerServiceParser
*/ */
private void startScan() { private void startScan() {
// Since Android 6.0 we need to obtain either Manifest.permission.ACCESS_COARSE_LOCATION or Manifest.permission.ACCESS_FINE_LOCATION to be able to scan for // Since Android 6.0 we need to obtain either Manifest.permission.ACCESS_COARSE_LOCATION or Manifest.permission.ACCESS_FINE_LOCATION to be able to scan for
// Bluetooth LE devices. This is related to beacons as proximity devices. // Bluetooth LE devices. This is related to beacons as proximity devices.
// On API older than Marshmallow the following code does nothing. // On API older than Marshmallow the following code does nothing.
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// When user pressed Deny and still wants to use this functionality, show the rationale // When user pressed Deny and still wants to use this functionality, show the rationale
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) && mPermissionRationale.getVisibility() == View.GONE) { if (ActivityCompat.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) && mPermissionRationale.getVisibility() == View.GONE) {
mPermissionRationale.setVisibility(View.VISIBLE); mPermissionRationale.setVisibility(View.VISIBLE);
return; return;
} }
@@ -276,7 +282,7 @@ public class ScannerFragment extends DialogFragment {
} }
}; };
private void addBondedDevices() { private void addBoundDevices() {
final Set<BluetoothDevice> devices = mBluetoothAdapter.getBondedDevices(); final Set<BluetoothDevice> devices = mBluetoothAdapter.getBondedDevices();
mAdapter.addBondedDevices(devices); mAdapter.addBondedDevices(devices);
} }

View File

@@ -80,12 +80,12 @@ public class TemplateActivity extends BleProfileServiceReadyActivity<TemplateSer
} }
@Override @Override
protected void onServiceBinded(final TemplateService.TemplateBinder binder) { protected void onServiceBound(final TemplateService.TemplateBinder binder) {
// not used // not used
} }
@Override @Override
protected void onServiceUnbinded() { protected void onServiceUnbound() {
// not used // not used
} }

View File

@@ -114,7 +114,7 @@ public class TemplateService extends BleProfileService implements TemplateManage
broadcast.putExtra(EXTRA_DATA, value); broadcast.putExtra(EXTRA_DATA, value);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
if (!mBinded) { if (!mBound) {
// Here we may update the notification to display the current value. // Here we may update the notification to display the current value.
// TODO modify the notification here // TODO modify the notification here
} }

View File

@@ -160,12 +160,12 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
} }
@Override @Override
protected void onServiceBinded(final UARTService.UARTBinder binder) { protected void onServiceBound(final UARTService.UARTBinder binder) {
mServiceBinder = binder; mServiceBinder = binder;
} }
@Override @Override
protected void onServiceUnbinded() { protected void onServiceUnbound() {
mServiceBinder = null; mServiceBinder = null;
} }

View File

@@ -25,6 +25,7 @@ package no.nordicsemi.android.nrftoolbox.uart;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color; import android.graphics.Color;
import android.support.annotation.NonNull;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -49,7 +50,7 @@ public class UARTLogAdapter extends CursorAdapter {
mColors.put(Level.ERROR, Color.RED); mColors.put(Level.ERROR, Color.RED);
} }
public UARTLogAdapter(Context context) { UARTLogAdapter(@NonNull final Context context) {
super(context, null, 0); super(context, null, 0);
} }

View File

@@ -31,6 +31,7 @@ import android.content.ServiceConnection;
import android.database.Cursor; import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader; import android.support.v4.content.CursorLoader;
@@ -57,19 +58,27 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
private static final int LOG_SCROLLED_TO_BOTTOM = -2; private static final int LOG_SCROLLED_TO_BOTTOM = -2;
private static final int LOG_REQUEST_ID = 1; private static final int LOG_REQUEST_ID = 1;
private static final String[] LOG_PROJECTION = { LogContract.Log._ID, LogContract.Log.TIME, LogContract.Log.LEVEL, LogContract.Log.DATA }; private static final String[] LOG_PROJECTION = {LogContract.Log._ID, LogContract.Log.TIME, LogContract.Log.LEVEL, LogContract.Log.DATA};
/** The service UART interface that may be used to send data to the target. */ /**
* The service UART interface that may be used to send data to the target.
*/
private UARTInterface mUARTInterface; private UARTInterface mUARTInterface;
/** The adapter used to populate the list with log entries. */ /**
* The adapter used to populate the list with log entries.
*/
private CursorAdapter mLogAdapter; private CursorAdapter mLogAdapter;
/** The log session created to log events related with the target device. */ /**
* The log session created to log events related with the target device.
*/
private ILogSession mLogSession; private ILogSession mLogSession;
private EditText mField; private EditText mField;
private Button mSendButton; private Button mSendButton;
/** The last list view position. */ /**
* The last list view position.
*/
private int mLogScrollPosition; private int mLogScrollPosition;
/** /**
@@ -128,7 +137,7 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mCommonBroadcastReceiver, makeIntentFilter()); LocalBroadcastManager.getInstance(requireContext()).registerReceiver(mCommonBroadcastReceiver, makeIntentFilter());
// Load the last log list view scroll position // Load the last log list view scroll position
if (savedInstanceState != null) { if (savedInstanceState != null) {
@@ -141,11 +150,11 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
super.onStart(); super.onStart();
/* /*
* If the service has not been started before the following lines will not start it. However, if it's running, the Activity will be binded to it * If the service has not been started before the following lines will not start it. However, if it's running, the Activity will be bound to it
* and notified via mServiceConnection. * and notified via mServiceConnection.
*/ */
final Intent service = new Intent(getActivity(), UARTService.class); final Intent service = new Intent(getActivity(), UARTService.class);
getActivity().bindService(service, mServiceConnection, 0); // we pass 0 as a flag so the service will not be created if not exists requireActivity().bindService(service, mServiceConnection, 0); // we pass 0 as a flag so the service will not be created if not exists
} }
@Override @Override
@@ -153,7 +162,7 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
super.onStop(); super.onStop();
try { try {
getActivity().unbindService(mServiceConnection); requireActivity().unbindService(mServiceConnection);
mUARTInterface = null; mUARTInterface = null;
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
// do nothing, we were not connected to the sensor // do nothing, we were not connected to the sensor
@@ -161,7 +170,7 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
} }
@Override @Override
public void onSaveInstanceState(final Bundle outState) { public void onSaveInstanceState(@NonNull final Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
// Save the last log list view scroll position // Save the last log list view scroll position
@@ -172,9 +181,8 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
@Override @Override
public void onDestroy() { public void onDestroy() {
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(mCommonBroadcastReceiver);
super.onDestroy(); super.onDestroy();
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mCommonBroadcastReceiver);
} }
@Override @Override
@@ -196,26 +204,27 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
} }
@Override @Override
public void onViewCreated(final View view, final Bundle savedInstanceState) { public void onViewCreated(@NonNull final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
// Create the log adapter, initially with null cursor // Create the log adapter, initially with null cursor
mLogAdapter = new UARTLogAdapter(getActivity()); mLogAdapter = new UARTLogAdapter(requireContext());
setListAdapter(mLogAdapter); setListAdapter(mLogAdapter);
} }
@NonNull
@Override @Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
switch (id) { switch (id) {
case LOG_REQUEST_ID: { case LOG_REQUEST_ID: {
return new CursorLoader(getActivity(), mLogSession.getSessionEntriesUri(), LOG_PROJECTION, null, null, LogContract.Log.TIME); return new CursorLoader(requireContext(), mLogSession.getSessionEntriesUri(), LOG_PROJECTION, null, null, LogContract.Log.TIME);
}
} }
} throw new UnsupportedOperationException("Could not create loader with ID " + id);
return null;
} }
@Override @Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) { public void onLoadFinished(@NonNull final Loader<Cursor> loader, final Cursor data) {
// Here we have to restore the old saved scroll position, or scroll to the bottom if before adding new events it was scrolled to the bottom. // Here we have to restore the old saved scroll position, or scroll to the bottom if before adding new events it was scrolled to the bottom.
final ListView list = getListView(); final ListView list = getListView();
final int position = mLogScrollPosition; final int position = mLogScrollPosition;
@@ -233,7 +242,7 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
} }
@Override @Override
public void onLoaderReset(final Loader<Cursor> loader) { public void onLoaderReset(@NonNull final Loader<Cursor> loader) {
mLogAdapter.swapCursor(null); mLogAdapter.swapCursor(null);
} }
@@ -253,15 +262,17 @@ public class UARTLogFragment extends ListFragment implements LoaderManager.Loade
public void onServiceStarted() { public void onServiceStarted() {
// The service has been started, bind to it // The service has been started, bind to it
final Intent service = new Intent(getActivity(), UARTService.class); final Intent service = new Intent(getActivity(), UARTService.class);
getActivity().bindService(service, mServiceConnection, 0); requireActivity().bindService(service, mServiceConnection, 0);
} }
/** /**
* This method is called when user closes the pane in horizontal orientation. The EditText is no longer visible so we need to close the soft keyboard here. * This method is called when user closes the pane in horizontal orientation. The EditText is no longer visible so we need to close the soft keyboard here.
*/ */
public void onFragmentHidden() { public void onFragmentHidden() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mField.getWindowToken(), 0); if (imm != null) {
imm.hideSoftInputFromWindow(mField.getWindowToken(), 0);
}
} }
/** /**

View File

@@ -156,8 +156,8 @@ public class UARTService extends BleProfileService implements UARTManagerCallbac
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
super.onLinklossOccur(device); super.onLinklossOccurred(device);
sendMessageToWearables(Constants.UART.DEVICE_LINKLOSS, notNull(getDeviceName())); sendMessageToWearables(Constants.UART.DEVICE_LINKLOSS, notNull(getDeviceName()));
} }

View File

@@ -67,7 +67,7 @@ public class DevicesAdapter extends WearableListView.Adapter {
mNotAvailable = context.getString(R.string.not_available); mNotAvailable = context.getString(R.string.not_available);
mConnectingText = context.getString(R.string.state_connecting); mConnectingText = context.getString(R.string.state_connecting);
mAvailableText = context.getString(R.string.devices_list_available); mAvailableText = context.getString(R.string.devices_list_available);
mBondedText = context.getString(R.string.devices_list_bonded); mBondedText = context.getString(R.string.devices_list_bound);
mBondingText = context.getString(R.string.devices_list_bonding); mBondingText = context.getString(R.string.devices_list_bonding);
mListView = listView; mListView = listView;
mHandler = new Handler(); mHandler = new Handler();

View File

@@ -184,7 +184,7 @@ public class BleManager implements BleProfileApi {
* that will be automatically connect as soon as they become available (true). In the latter case, if * that will be automatically connect as soon as they become available (true). In the latter case, if
* Bluetooth adapter is enabled, Android scans periodically for devices from the white list and if a advertising packet * Bluetooth adapter is enabled, Android scans periodically for devices from the white list and if a advertising packet
* is received from such, it tries to connect to it. When the connection is lost, the system will keep trying to reconnect * is received from such, it tries to connect to it. When the connection is lost, the system will keep trying to reconnect
* to it in. If true is returned, and the connection to the device is lost the {@link BleManagerCallbacks#onLinklossOccur(BluetoothDevice)} * to it in. If true is returned, and the connection to the device is lost the {@link BleManagerCallbacks#onLinklossOccurred(BluetoothDevice)}
* callback is called instead of {@link BleManagerCallbacks#onDeviceDisconnected(BluetoothDevice)}. * callback is called instead of {@link BleManagerCallbacks#onDeviceDisconnected(BluetoothDevice)}.
* <p>This feature works much better on newer Android phone models and many not work on older phones.</p> * <p>This feature works much better on newer Android phone models and many not work on older phones.</p>
* <p>This method should only be used with bonded devices, as otherwise the device may change it's address. * <p>This method should only be used with bonded devices, as otherwise the device may change it's address.
@@ -659,7 +659,7 @@ public class BleManager implements BleProfileApi {
mCallbacks.onDeviceDisconnected(device); mCallbacks.onDeviceDisconnected(device);
close(); close();
} else { } else {
mCallbacks.onLinklossOccur(device); mCallbacks.onLinklossOccurred(device);
// We are not closing the connection here as the device should try to reconnect automatically. // We are not closing the connection here as the device should try to reconnect automatically.
// This may be only called when the shouldAutoConnect() method returned true. // This may be only called when the shouldAutoConnect() method returned true.
} }

View File

@@ -72,7 +72,7 @@ public interface BleManagerCallbacks {
* Called when the device has disconnected (when the callback returned * Called when the device has disconnected (when the callback returned
* {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)} with state DISCONNECTED), * {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)} with state DISCONNECTED),
* but ONLY if the {@link BleManager#shouldAutoConnect()} method returned false for this device when it was connecting. * but ONLY if the {@link BleManager#shouldAutoConnect()} method returned false for this device when it was connecting.
* Otherwise the {@link #onLinklossOccur(BluetoothDevice)} method will be called instead. * Otherwise the {@link #onLinklossOccurred(BluetoothDevice)} method will be called instead.
* @param device the device that got disconnected * @param device the device that got disconnected
*/ */
void onDeviceDisconnected(final BluetoothDevice device); void onDeviceDisconnected(final BluetoothDevice device);
@@ -82,7 +82,7 @@ public interface BleManagerCallbacks {
* Otherwise a {@link #onDeviceDisconnected(BluetoothDevice)} method will be called on such event. * Otherwise a {@link #onDeviceDisconnected(BluetoothDevice)} method will be called on such event.
* @param device target device * @param device target device
*/ */
void onLinklossOccur(final BluetoothDevice device); void onLinklossOccurred(final BluetoothDevice device);
/** /**
* Called when an {@link BluetoothGatt#GATT_INSUFFICIENT_AUTHENTICATION} error occurred and the device bond state is NOT_BONDED * Called when an {@link BluetoothGatt#GATT_INSUFFICIENT_AUTHENTICATION} error occurred and the device bond state is NOT_BONDED

View File

@@ -65,7 +65,7 @@ public class BleProfileService extends Service implements BleManagerCallbacks {
private BleManager mBleManager; private BleManager mBleManager;
private Handler mHandler; private Handler mHandler;
protected boolean mBinded; protected boolean mBound;
private boolean mConnected; private boolean mConnected;
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
private String mDeviceName; private String mDeviceName;
@@ -157,18 +157,18 @@ public class BleProfileService extends Service implements BleManagerCallbacks {
@Override @Override
public IBinder onBind(final Intent intent) { public IBinder onBind(final Intent intent) {
mBinded = true; mBound = true;
return getBinder(); return getBinder();
} }
@Override @Override
public final void onRebind(final Intent intent) { public final void onRebind(final Intent intent) {
mBinded = true; mBound = true;
} }
@Override @Override
public final boolean onUnbind(final Intent intent) { public final boolean onUnbind(final Intent intent) {
mBinded = false; mBound = false;
// We want the onRebind method be called if anything else binds to it again // We want the onRebind method be called if anything else binds to it again
return true; return true;
@@ -261,7 +261,7 @@ public class BleProfileService extends Service implements BleManagerCallbacks {
@Override @Override
public boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) { public boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) {
// By default the Battery Level notifications will be enabled only the activity is bound. // By default the Battery Level notifications will be enabled only the activity is bound.
return mBinded; return mBound;
} }
@Override @Override
@@ -304,7 +304,7 @@ public class BleProfileService extends Service implements BleManagerCallbacks {
} }
@Override @Override
public void onLinklossOccur(final BluetoothDevice device) { public void onLinklossOccurred(final BluetoothDevice device) {
mConnected = false; mConnected = false;
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE); final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);

View File

@@ -156,7 +156,7 @@ public class UARTCommandsActivity extends Activity implements UARTCommandsAdapte
mGoogleApiClient.unregisterConnectionFailedListener(this); mGoogleApiClient.unregisterConnectionFailedListener(this);
mGoogleApiClient = null; mGoogleApiClient = null;
// unbind if we were binded to the service. // unbind if we were bound to the service.
unbindService(mServiceConnection); unbindService(mServiceConnection);
LocalBroadcastManager.getInstance(this).unregisterReceiver(mServiceBroadcastReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mServiceBroadcastReceiver);
} }
@@ -219,7 +219,7 @@ public class UARTCommandsActivity extends Activity implements UARTCommandsAdapte
@Override @Override
public void onMessageReceived(final MessageEvent messageEvent) { public void onMessageReceived(final MessageEvent messageEvent) {
// If the activity is binded to service it means that it has connected directly to the device. We ignore messages from the handheld. // If the activity is bound to service it means that it has connected directly to the device. We ignore messages from the handheld.
if (mProfile != null) if (mProfile != null)
return; return;

View File

@@ -135,7 +135,7 @@ public class UARTConfigurationsActivity extends Activity implements GoogleApiCli
mGoogleApiClient.unregisterConnectionFailedListener(this); mGoogleApiClient.unregisterConnectionFailedListener(this);
mGoogleApiClient = null; mGoogleApiClient = null;
// If we were binded to the service, disconnect and unbind. The service will terminate itself when disconnected. // If we were bound to the service, disconnect and unbind. The service will terminate itself when disconnected.
if (mBinder != null) { if (mBinder != null) {
mBinder.disconnect(); mBinder.disconnect();
} }
@@ -182,7 +182,7 @@ public class UARTConfigurationsActivity extends Activity implements GoogleApiCli
@Override @Override
public void onMessageReceived(final MessageEvent messageEvent) { public void onMessageReceived(final MessageEvent messageEvent) {
// If the activity is binded to service it means that it has connected directly to the device. We ignore messages from the handheld. // If the activity is bound to service it means that it has connected directly to the device. We ignore messages from the handheld.
if (mBinder != null) if (mBinder != null)
return; return;

View File

@@ -28,7 +28,7 @@
<string name="devices_list_scanning">Scanning for nearby devices…</string> <string name="devices_list_scanning">Scanning for nearby devices…</string>
<string name="devices_list_start_scan">Scan for nearby devices</string> <string name="devices_list_start_scan">Scan for nearby devices</string>
<string name="devices_list_available">Available</string> <string name="devices_list_available">Available</string>
<string name="devices_list_bonded">Bonded</string> <string name="devices_list_bound">Bound</string>
<string name="devices_list_bonding">Bonding…</string> <string name="devices_list_bonding">Bonding…</string>
<string name="devices_list_device_not_supported">Device not supported.</string> <string name="devices_list_device_not_supported">Device not supported.</string>