mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 03:07:32 +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:
parent
274e8591dc
commit
c773181da3
@ -1,5 +1,9 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge;
|
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.NotificationManager;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@ -19,11 +23,6 @@ import android.support.v4.content.LocalBroadcastManager;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
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 class BluetoothCommunicationService extends Service {
|
||||||
public static final String ACTION_START
|
public static final String ACTION_START
|
||||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.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 (!action.equals(ACTION_START) && !action.equals(ACTION_CONNECT)) {
|
||||||
if (mDeviceSupport == null || (!isConnected() && !mDeviceSupport.useAutoConnect())) {
|
if (mDeviceSupport == null || (!isConnected() && !mDeviceSupport.useAutoConnect())) {
|
||||||
// trying to send notification without valid Bluetooth connection
|
// 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;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,10 @@ public class ControlCenter extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
refreshPairedDevices();
|
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);
|
Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
|
||||||
startIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT);
|
startIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT);
|
||||||
startIntent.putExtra("device_address", deviceList.get(position).getAddress());
|
startIntent.putExtra("device_address", deviceList.get(position).getAddress());
|
||||||
|
|
||||||
startService(startIntent);
|
startService(startIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,7 +108,17 @@ public class ControlCenter extends Activity {
|
|||||||
startIntent.setAction(BluetoothCommunicationService.ACTION_START);
|
startIntent.setAction(BluetoothCommunicationService.ACTION_START);
|
||||||
startService(startIntent);
|
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);
|
versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
|
||||||
startService(versionInfoIntent);
|
startService(versionInfoIntent);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user