From 8a4aca06e605471c97008263f34ab0bc8e1ace51 Mon Sep 17 00:00:00 2001 From: Johannes Krude Date: Fri, 30 Aug 2024 17:13:48 +0200 Subject: [PATCH] DevicePrefs gets the GBDevice since it it device specific --- .../gadgetbridge/GBApplication.java | 4 ++-- .../activities/ConfigureReminders.java | 2 +- .../activities/DevicesFragment.java | 2 +- .../PebbleContentProvider.java | 2 +- .../gadgetbridge/database/DBHelper.java | 2 +- .../GarminRealtimeSettingsFragment.java | 4 ++-- .../devices/hplus/HPlusCoordinator.java | 14 ------------ .../devices/pebble/PebbleCoordinator.java | 4 ++-- .../service/AbstractDeviceSupport.java | 4 ++-- .../gbx100/SetConfigurationOperation.java | 2 +- .../devices/hplus/HPlusHandlerThread.java | 2 +- .../service/devices/hplus/HPlusSupport.java | 22 ++++++++++++++----- .../service/devices/huami/HuamiSupport.java | 6 ++--- .../devices/huawei/HuaweiSupportProvider.java | 4 ++-- .../requests/GetBatteryLevelRequest.java | 2 +- .../makibeshr3/MakibesHR3DeviceSupport.java | 2 +- .../service/devices/miband/MiBandSupport.java | 2 +- .../operations/FetchActivityOperation.java | 2 +- .../devices/pebble/AppMessageHandler.java | 4 ++-- .../pebble/DatalogSessionPebbleHealth.java | 2 +- .../devices/pebble/PebbleIoThread.java | 4 ++-- .../service/devices/pebble/PebbleSupport.java | 4 ++-- .../devices/pebble/ble/PebbleLESupport.java | 9 +++++--- .../services/AbstractXiaomiService.java | 2 +- .../service/serial/GBDeviceProtocol.java | 2 +- .../freeyourgadget/gadgetbridge/util/GB.java | 2 +- .../util/preferences/DevicePrefs.java | 7 ++++-- 27 files changed, 60 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index b825e9ae4..7b04a82d7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -1737,8 +1737,8 @@ public class GBApplication extends Application { return context.getSharedPreferences("devicesettings_" + deviceIdentifier, Context.MODE_PRIVATE); } - public static DevicePrefs getDevicePrefs(final String deviceIdentifier) { - return new DevicePrefs(getDeviceSpecificSharedPrefs(deviceIdentifier)); + public static DevicePrefs getDevicePrefs(GBDevice gbDevice) { + return new DevicePrefs(getDeviceSpecificSharedPrefs(gbDevice.getAddress()), gbDevice); } public static void deleteDeviceSpecificSharedPrefs(String deviceIdentifier) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java index 9edebffb5..40becd646 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java @@ -102,7 +102,7 @@ public class ConfigureReminders extends AbstractGBActivity { public void onClick(View v) { final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); - int deviceSlots = coordinator.getReminderSlotCount(gbDevice) - GBApplication.getDevicePrefs(gbDevice.getAddress()).getReservedReminderCalendarSlots(gbDevice); + int deviceSlots = coordinator.getReminderSlotCount(gbDevice) - GBApplication.getDevicePrefs(gbDevice).getReservedReminderCalendarSlots(); if (mGBReminderListAdapter.getItemCount() >= deviceSlots) { // No more free slots diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java index 72cb87c48..7cf65a11b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DevicesFragment.java @@ -260,7 +260,7 @@ public class DevicesFragment extends Fragment { private void updateDevice(final DBHandler db, final GBDevice gbDevice) { final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); - final boolean showActivityCard = GBApplication.getDevicePrefs(gbDevice.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD, true); + final boolean showActivityCard = GBApplication.getDevicePrefs(gbDevice).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD, true); if (coordinator.supportsActivityTracking() && showActivityCard) { final long[] stepsAndSleepData = getSteps(gbDevice, db); deviceActivityHashMap.put(gbDevice.getAddress(), stepsAndSleepData); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/contentprovider/PebbleContentProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/contentprovider/PebbleContentProvider.java index 84b349c89..4e9756527 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/contentprovider/PebbleContentProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/contentprovider/PebbleContentProvider.java @@ -80,7 +80,7 @@ public class PebbleContentProvider extends ContentProvider { int pebbleKit = 0; String fwString = "unknown"; if (mGBDevice != null && mGBDevice.getType() == DeviceType.PEBBLE && mGBDevice.isInitialized()) { - final DevicePrefs deviceSpecificSharedPrefsrefs = GBApplication.getDevicePrefs(mGBDevice.getAddress()); + final DevicePrefs deviceSpecificSharedPrefsrefs = GBApplication.getDevicePrefs(mGBDevice); if (deviceSpecificSharedPrefsrefs.getBoolean("third_party_apps_set_settings", false)) { pebbleKit = 1; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/DBHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/DBHelper.java index 7542c6307..bba3ac517 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/DBHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/DBHelper.java @@ -639,7 +639,7 @@ public class DBHelper { public static List getReminders(@NonNull GBDevice gbDevice) { final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); - final int reservedSlots = GBApplication.getDevicePrefs(gbDevice.getAddress()).getReservedReminderCalendarSlots(gbDevice); + final int reservedSlots = GBApplication.getDevicePrefs(gbDevice).getReservedReminderCalendarSlots(); final int reminderSlots = coordinator.getReminderSlotCount(gbDevice); try (DBHandler db = GBApplication.acquireDB()) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminRealtimeSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminRealtimeSettingsFragment.java index 1ae635e7b..89b447664 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminRealtimeSettingsFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminRealtimeSettingsFragment.java @@ -232,7 +232,7 @@ public class GarminRealtimeSettingsFragment extends AbstractPreferenceFragment { } void reload() { - final boolean debug = GBApplication.getDevicePrefs(device.getAddress()).getBoolean(PREF_DEBUG, BuildConfig.DEBUG); + final boolean debug = GBApplication.getDevicePrefs(device).getBoolean(PREF_DEBUG, BuildConfig.DEBUG); final FragmentActivity activity = getActivity(); if (activity == null) { @@ -800,7 +800,7 @@ public class GarminRealtimeSettingsFragment extends AbstractPreferenceFragment { } void toggleDebug() { - final Prefs prefs = GBApplication.getDevicePrefs(device.getAddress()); + final Prefs prefs = GBApplication.getDevicePrefs(device); prefs.getPreferences().edit() .putBoolean(PREF_DEBUG, !prefs.getBoolean(PREF_DEBUG, BuildConfig.DEBUG)) .apply(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java index 9b9b03382..5e06514c9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java @@ -181,20 +181,6 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator { return activityUser.getStepsGoal(); } - public static byte getScreenTime(String address) { - return (byte) (GBApplication.getDevicePrefs(address).getInt(HPlusConstants.PREF_HPLUS_SCREENTIME, 5) & 0xFF); - } - - public static byte getAllDayHR(String address) { - boolean value = (GBApplication.getDevicePrefs(address).getBoolean(HPlusConstants.PREF_HPLUS_ALLDAYHR, true)); - - if (value) { - return HPlusConstants.ARG_HEARTRATE_ALLDAY_ON; - } else { - return HPlusConstants.ARG_HEARTRATE_ALLDAY_OFF; - } - } - public static byte getSocial(String address) { //TODO: Figure what this is. Returning the default value diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleCoordinator.java index 6524e9f0b..ac0724926 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleCoordinator.java @@ -89,7 +89,7 @@ public class PebbleCoordinator extends AbstractBLClassicDeviceCoordinator { @Override public SampleProvider getSampleProvider(GBDevice device, DaoSession session) { - DevicePrefs prefs = GBApplication.getDevicePrefs(device.getAddress()); + DevicePrefs prefs = GBApplication.getDevicePrefs(device); int activityTracker = prefs.getInt("pebble_activitytracker", SampleProvider.PROVIDER_PEBBLE_HEALTH); switch (activityTracker) { case SampleProvider.PROVIDER_PEBBLE_HEALTH: @@ -285,7 +285,7 @@ public class PebbleCoordinator extends AbstractBLClassicDeviceCoordinator { } public boolean isBackgroundJsEnabled(final GBDevice device) { - DevicePrefs deviceSpecificPreferences = GBApplication.getDevicePrefs(device.getAddress()); + DevicePrefs deviceSpecificPreferences = GBApplication.getDevicePrefs(device); return deviceSpecificPreferences.getBoolean(BG_JS_ENABLED, BG_JS_ENABLED_DEFAULT); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java index f2bf2c071..0a432a70e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java @@ -540,7 +540,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { gbDevice.setBatteryState(deviceEvent.state); gbDevice.setBatteryVoltage(deviceEvent.voltage, deviceEvent.batteryIndex); - final DevicePrefs devicePrefs = GBApplication.getDevicePrefs(gbDevice.getAddress()); + final DevicePrefs devicePrefs = GBApplication.getDevicePrefs(gbDevice); final BatteryConfig batteryConfig = gbDevice.getDeviceCoordinator().getBatteryConfig(gbDevice)[deviceEvent.batteryIndex]; if (deviceEvent.level == GBDevice.BATTERY_UNKNOWN) { @@ -786,7 +786,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { } public DevicePrefs getDevicePrefs() { - return GBApplication.getDevicePrefs(gbDevice.getAddress()); + return GBApplication.getDevicePrefs(gbDevice); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/SetConfigurationOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/SetConfigurationOperation.java index a675b9c68..3dd4650e8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/SetConfigurationOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/SetConfigurationOperation.java @@ -202,7 +202,7 @@ public class SetConfigurationOperation extends AbstractBTLEOperation reminders) { final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); - int reservedSlots = GBApplication.getDevicePrefs(gbDevice.getAddress()).getReservedReminderCalendarSlots(gbDevice); + int reservedSlots = GBApplication.getDevicePrefs(gbDevice).getReservedReminderCalendarSlots(); LOG.info("On Set Reminders. Reminders: {}, Reserved slots: {}", reminders.size(), reservedSlots); // Send the reminders, skipping the reserved slots for calendar events @@ -2754,7 +2754,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements } final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); - int availableSlots = GBApplication.getDevicePrefs(gbDevice.getAddress()).getReservedReminderCalendarSlots(gbDevice); + int availableSlots = GBApplication.getDevicePrefs(gbDevice).getReservedReminderCalendarSlots(); CalendarManager upcomingEvents = new CalendarManager(getContext(), getDevice().getAddress()); List calendarEvents = upcomingEvents.getCalendarEventList(); @@ -3373,7 +3373,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements } protected HuamiSupport setTimeFormat(TransactionBuilder builder) { - String timeFormat = GBApplication.getDevicePrefs(gbDevice.getAddress()).getTimeFormat(); + String timeFormat = GBApplication.getDevicePrefs(gbDevice).getTimeFormat(); LOG.info("Setting time format to " + timeFormat); if (timeFormat.equals(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java index a2de11da9..b578e9e50 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java @@ -1057,7 +1057,7 @@ public class HuaweiSupportProvider { GB.toast(context, context.getString(R.string.toast_setting_requires_reconnect), Toast.LENGTH_SHORT, GB.INFO); } case DeviceSettingsPreferenceConst.PREF_BATTERY_POLLING_ENABLE: - if (!GBApplication.getDevicePrefs(gbDevice.getAddress()).getBatteryPollingEnabled()) { + if (!GBApplication.getDevicePrefs(gbDevice).getBatteryPollingEnabled()) { stopBatteryRunnerDelayed(); break; } @@ -2118,7 +2118,7 @@ public class HuaweiSupportProvider { } public boolean startBatteryRunnerDelayed() { - int interval_minutes = GBApplication.getDevicePrefs(deviceMac).getBatteryPollingIntervalMinutes(); + int interval_minutes = GBApplication.getDevicePrefs(gbDevice).getBatteryPollingIntervalMinutes(); int interval = interval_minutes * 60 * 1000; LOG.debug("Starting battery runner delayed by {} ({} minutes)", interval, interval_minutes); handler.removeCallbacks(batteryRunner); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetBatteryLevelRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetBatteryLevelRequest.java index 5b22808ad..1d4915e08 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetBatteryLevelRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetBatteryLevelRequest.java @@ -64,7 +64,7 @@ public class GetBatteryLevelRequest extends Request { batteryInfo.level = (int)batteryLevel & 0xff; this.supportProvider.evaluateGBDeviceEvent(batteryInfo); - if (GBApplication.getDevicePrefs(getDevice().getAddress()).getBatteryPollingEnabled()) { + if (GBApplication.getDevicePrefs(getDevice()).getBatteryPollingEnabled()) { if (!this.supportProvider.startBatteryRunnerDelayed()) { GB.toast(getContext(), R.string.battery_polling_failed_start, Toast.LENGTH_SHORT, GB.ERROR); LOG.error("Failed to start the battery polling"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/makibeshr3/MakibesHR3DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/makibeshr3/MakibesHR3DeviceSupport.java index 1f5199d0f..625415977 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/makibeshr3/MakibesHR3DeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/makibeshr3/MakibesHR3DeviceSupport.java @@ -1003,7 +1003,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement } public byte getTimeMode(SharedPreferences sharedPrefs) { - String timeMode = new DevicePrefs(sharedPrefs).getTimeFormat(); + String timeMode = new DevicePrefs(sharedPrefs, gbDevice).getTimeFormat(); if (timeMode.equals(getContext().getString(R.string.p_timeformat_24h))) { return MakibesHR3Constants.ARG_SET_TIMEMODE_24H; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index 661fc23f1..6d05c049f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -366,7 +366,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { // Unfortunately this extra pairing causes problems when bonding is not used/does not work // so we only do this when configured to keep data on the device - Prefs prefs = GBApplication.getDevicePrefs(gbDevice.getAddress()); + Prefs prefs = GBApplication.getDevicePrefs(gbDevice); if (prefs.getBoolean("keep_activity_data_on_device", false)) { LOG.info("Attempting to pair MI device..."); BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_PAIR); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/FetchActivityOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/FetchActivityOperation.java index 9ecce3f54..748615a25 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/FetchActivityOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/FetchActivityOperation.java @@ -410,7 +410,7 @@ public class FetchActivityOperation extends AbstractMiBand1Operation { */ private void sendAckDataTransfer(Calendar time, int bytesTransferred) { byte[] ackTime = MiBandDateConverter.calendarToRawBytes(time, getDevice().getAddress()); - Prefs prefs = GBApplication.getDevicePrefs(getDevice().getAddress()); + Prefs prefs = GBApplication.getDevicePrefs(getDevice()); byte[] ackChecksum = new byte[]{ (byte) (bytesTransferred & 0xff), diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandler.java index 72b436360..9313999ba 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandler.java @@ -48,7 +48,7 @@ class AppMessageHandler { AppMessageHandler(UUID uuid, PebbleProtocol pebbleProtocol) { mUUID = uuid; mPebbleProtocol = pebbleProtocol; - devicePrefs = GBApplication.getDevicePrefs(pebbleProtocol.getDevice().getAddress()); + devicePrefs = GBApplication.getDevicePrefs(pebbleProtocol.getDevice()); } public boolean isEnabled() { @@ -88,4 +88,4 @@ class AppMessageHandler { } throw new IOException(); } -} \ No newline at end of file +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionPebbleHealth.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionPebbleHealth.java index 0133bd42a..be08d935c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionPebbleHealth.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionPebbleHealth.java @@ -31,7 +31,7 @@ abstract class DatalogSessionPebbleHealth extends DatalogSession { DatalogSessionPebbleHealth(byte id, UUID uuid, int timestamp, int tag, byte itemType, short itemSize, GBDevice device) { super(id, uuid, timestamp, tag, itemType, itemSize); mDevice = device; - devicePrefs = GBApplication.getDevicePrefs(mDevice.getAddress()); + devicePrefs = GBApplication.getDevicePrefs(mDevice); } public GBDevice getDevice() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java index e6998c42f..2ea3402e1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java @@ -149,7 +149,7 @@ class PebbleIoThread extends GBDeviceIoThread { PebbleIoThread(PebbleSupport pebbleSupport, GBDevice gbDevice, GBDeviceProtocol gbDeviceProtocol, BluetoothAdapter btAdapter, Context context) { super(gbDevice, context); - devicePrefs = GBApplication.getDevicePrefs(gbDevice.getAddress()); + devicePrefs = GBApplication.getDevicePrefs(gbDevice); mPebbleProtocol = (PebbleProtocol) gbDeviceProtocol; mBtAdapter = btAdapter; mPebbleSupport = pebbleSupport; @@ -193,7 +193,7 @@ class PebbleIoThread extends GBDeviceIoThread { LOG.info("This is a Pebble 2 or Pebble-LE/Pebble Time LE, will use BLE"); mInStream = new PipedInputStream(); mOutStream = new PipedOutputStream(); - mPebbleLESupport = new PebbleLESupport(this.getContext(), btDevice, (PipedInputStream) mInStream, (PipedOutputStream) mOutStream); + mPebbleLESupport = new PebbleLESupport(this.getContext(), gbDevice, btDevice, (PipedInputStream) mInStream, (PipedOutputStream) mOutStream); } else { ParcelUuid[] uuids = btDevice.getUuids(); if (uuids == null) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java index 12bda9777..8e09266f8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java @@ -182,7 +182,7 @@ public class PebbleSupport extends AbstractSerialDeviceSupport { @Override public void onNotification(NotificationSpec notificationSpec) { - String currentPrivacyMode = GBApplication.getDevicePrefs(gbDevice.getAddress()).getString("pebble_pref_privacy_mode", getContext().getString(R.string.p_pebble_privacy_mode_off)); + String currentPrivacyMode = GBApplication.getDevicePrefs(gbDevice).getString("pebble_pref_privacy_mode", getContext().getString(R.string.p_pebble_privacy_mode_off)); if (getContext().getString(R.string.p_pebble_privacy_mode_complete).equals(currentPrivacyMode)) { notificationSpec.body = null; notificationSpec.sender = null; @@ -206,7 +206,7 @@ public class PebbleSupport extends AbstractSerialDeviceSupport { @Override public void onSetCallState(CallSpec callSpec) { if (reconnect()) { - if ((callSpec.command != CallSpec.CALL_OUTGOING) || GBApplication.getDevicePrefs(gbDevice.getAddress()).getBoolean("pebble_enable_outgoing_call", true)) { + if ((callSpec.command != CallSpec.CALL_OUTGOING) || GBApplication.getDevicePrefs(gbDevice).getBoolean("pebble_enable_outgoing_call", true)) { super.onSetCallState(callSpec); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java index 925cf3fe5..cf2636e76 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java @@ -29,9 +29,11 @@ import java.io.PipedInputStream; import java.io.PipedOutputStream; import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; public class PebbleLESupport { private static final Logger LOG = LoggerFactory.getLogger(PebbleLESupport.class); + private final GBDevice mgbDevice; private final BluetoothDevice mBtDevice; private PipeReader mPipeReader; private PebbleGATTServer mPebbleGATTServer; @@ -45,7 +47,8 @@ public class PebbleLESupport { private HandlerThread mWriteHandlerThread; private Handler mWriteHandler; - public PebbleLESupport(Context context, final BluetoothDevice btDevice, PipedInputStream pipedInputStream, PipedOutputStream pipedOutputStream) throws IOException { + public PebbleLESupport(Context context, GBDevice gbDevice, final BluetoothDevice btDevice, PipedInputStream pipedInputStream, PipedOutputStream pipedOutputStream) throws IOException { + mgbDevice = gbDevice; mBtDevice = btDevice; mPipedInputStream = new PipedInputStream(); mPipedOutputStream = new PipedOutputStream(); @@ -60,11 +63,11 @@ public class PebbleLESupport { mWriteHandlerThread.start(); mWriteHandler = new Handler(mWriteHandlerThread.getLooper()); - mMTULimit = GBApplication.getDevicePrefs(mBtDevice.getAddress()).getInt("pebble_mtu_limit", 512); + mMTULimit = GBApplication.getDevicePrefs(mgbDevice).getInt("pebble_mtu_limit", 512); mMTULimit = Math.max(mMTULimit, 20); mMTULimit = Math.min(mMTULimit, 512); - clientOnly = GBApplication.getDevicePrefs(mBtDevice.getAddress()).getBoolean("pebble_gatt_clientonly", false); + clientOnly = GBApplication.getDevicePrefs(mgbDevice).getBoolean("pebble_gatt_clientonly", false); if (!clientOnly) { mPebbleGATTServer = new PebbleGATTServer(this, context, mBtDevice); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/AbstractXiaomiService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/AbstractXiaomiService.java index 56fc5098b..aa800ab77 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/AbstractXiaomiService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/AbstractXiaomiService.java @@ -61,7 +61,7 @@ public abstract class AbstractXiaomiService { } protected DevicePrefs getDevicePrefs() { - return GBApplication.getDevicePrefs(getSupport().getDevice().getAddress()); + return GBApplication.getDevicePrefs(getSupport().getDevice()); } public void onDisconnect() {} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java index e7438c8bd..38f68f4bf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java @@ -182,6 +182,6 @@ public abstract class GBDeviceProtocol { } protected DevicePrefs getDevicePrefs() { - return GBApplication.getDevicePrefs(getDevice().getAddress()); + return GBApplication.getDevicePrefs(getDevice()); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java index 231bf51f4..10f840977 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java @@ -284,7 +284,7 @@ public class GB { } public static String buildDeviceBatteryString(final Context context, final GBDevice device) { - final DevicePrefs devicePrefs = GBApplication.getDevicePrefs(device.getAddress()); + final DevicePrefs devicePrefs = GBApplication.getDevicePrefs(device); final List batteryLevels = new ArrayList<>(); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < 3; i++) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/DevicePrefs.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/DevicePrefs.java index 1cbc5d05f..d9cc1b8fd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/DevicePrefs.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/DevicePrefs.java @@ -32,8 +32,11 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; public class DevicePrefs extends Prefs { - public DevicePrefs(final SharedPreferences preferences) { + private GBDevice gbDevice; + + public DevicePrefs(final SharedPreferences preferences, GBDevice gbDevice) { super(preferences); + this.gbDevice = gbDevice; } public boolean getBatteryShowInNotification(final int batteryIndex) { @@ -104,7 +107,7 @@ public class DevicePrefs extends Prefs { return dateFormat; } - public int getReservedReminderCalendarSlots(GBDevice gbDevice) { + public int getReservedReminderCalendarSlots() { if (!gbDevice.getDeviceCoordinator().getReserveReminderSlotsForCalendar()) return 0; if (!getBoolean(DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR, false))