From 723ad53588d0f8fea5f8da92cab063c06f6e542e Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sun, 27 Nov 2016 10:32:56 +0100 Subject: [PATCH] Call getDevice always when connected This fixes a longstanding bug where device attributes where ONLY updated when fetching activity data or when pairing a new device --- .../service/DeviceCommunicationService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index 7473ec79..24388615 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -169,12 +169,13 @@ public class DeviceCommunicationService extends Service implements SharedPrefere boolean enableReceivers = mDeviceSupport != null && (mDeviceSupport.useAutoConnect() || mGBDevice.isInitialized()); setReceiversEnableState(enableReceivers); GB.updateNotification(mGBDevice.getName() + " " + mGBDevice.getStateString(), mGBDevice.isInitialized(), context); - if (device.isInitialized() && (device.getType() != DeviceType.VIBRATISSIMO)) { + + if (device.isInitialized()) { try (DBHandler dbHandler = GBApplication.acquireDB()) { DaoSession session = dbHandler.getDaoSession(); - if (DBHelper.findDevice(device, session) == null) { - DBHelper dbHelper = new DBHelper(context); - DBHelper.getDevice(device, session); // implicitly creates it :P + DBHelper dbHelper = new DBHelper(context); + DBHelper.getDevice(device, session); // implicitly creates it :P + if (DBHelper.findDevice(device, session) == null && (device.getType() != DeviceType.VIBRATISSIMO)) { if (dbHelper.getOldActivityDatabaseHandler() != null) { Intent startIntent = new Intent(context, OnboardingActivity.class); startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -182,7 +183,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere startActivity(startIntent); } } - } catch (Exception _ignore) { + } catch (Exception ignore) { } } } else { @@ -426,11 +427,11 @@ public class DeviceCommunicationService extends Service implements SharedPrefere break; case ACTION_SETMUSICSTATE: MusicStateSpec stateSpec = new MusicStateSpec(); - stateSpec.shuffle = intent.getByteExtra(EXTRA_MUSIC_SHUFFLE, (byte)0); - stateSpec.repeat = intent.getByteExtra(EXTRA_MUSIC_REPEAT, (byte)0); + stateSpec.shuffle = intent.getByteExtra(EXTRA_MUSIC_SHUFFLE, (byte) 0); + stateSpec.repeat = intent.getByteExtra(EXTRA_MUSIC_REPEAT, (byte) 0); stateSpec.position = intent.getIntExtra(EXTRA_MUSIC_POSITION, 0); stateSpec.playRate = intent.getIntExtra(EXTRA_MUSIC_RATE, 0); - stateSpec.state = intent.getByteExtra(EXTRA_MUSIC_STATE, (byte)0); + stateSpec.state = intent.getByteExtra(EXTRA_MUSIC_STATE, (byte) 0); mDeviceSupport.onSetMusicState(stateSpec); break; case ACTION_REQUEST_APPINFO: