1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 18:15:49 +01:00

Request and display device info (connection state and firmware version)

- request device info initially (connection state)
- request device info (firmware) when connected

This also fixes the wrong connection state being displayed on
orientation change.
This commit is contained in:
cpfeiffer 2015-04-24 23:08:47 +02:00
parent 274e8591dc
commit c773181da3
2 changed files with 23 additions and 7 deletions

View File

@ -1,5 +1,9 @@
package nodomain.freeyourgadget.gadgetbridge;
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport;
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread;
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleSupport;
import android.app.NotificationManager;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
@ -19,11 +23,6 @@ import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.widget.Toast;
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport;
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread;
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleSupport;
public class BluetoothCommunicationService extends Service {
public static final String ACTION_START
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.start";
@ -110,6 +109,10 @@ public class BluetoothCommunicationService extends Service {
if (!action.equals(ACTION_START) && !action.equals(ACTION_CONNECT)) {
if (mDeviceSupport == null || (!isConnected() && !mDeviceSupport.useAutoConnect())) {
// trying to send notification without valid Bluetooth connection
if (mGBDevice != null) {
// at least send back the current device state
mGBDevice.sendDeviceUpdateIntent(this);
}
return START_STICKY;
}
}

View File

@ -57,6 +57,10 @@ public class ControlCenter extends Activity {
}
}
refreshPairedDevices();
if (dev.isConnected() && dev.getFirmwareVersion() == null) {
requestDeviceInfo();
}
}
}
};
@ -79,7 +83,6 @@ public class ControlCenter extends Activity {
Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT);
startIntent.putExtra("device_address", deviceList.get(position).getAddress());
startService(startIntent);
}
}
@ -105,7 +108,17 @@ public class ControlCenter extends Activity {
startIntent.setAction(BluetoothCommunicationService.ACTION_START);
startService(startIntent);
Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class);
requestDeviceInfo();
}
/**
* Requests information from the {@link BluetoothCommunicationService} about the connection state,
* firmware info, etc.
*
* Note that this method may cause an implicit device connection (for auto-connectable devices).
*/
private void requestDeviceInfo() {
Intent versionInfoIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
startService(versionInfoIntent);
}