From c59553c9c9a2c998bc44778c3f0007d15edfd611 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Fri, 26 Aug 2016 20:57:59 +0200 Subject: [PATCH] Rename GBDevice#hardwareVersion to model (e.g. while DeviceType is "PEBBLE" in general, the model might specify a Pebble Time or Time Steel. --- .../activities/ExternalPebbleJSActivity.java | 4 +-- .../AbstractAppManagerFragment.java | 4 +-- .../gadgetbridge/adapter/GBDeviceAdapter.java | 4 +-- .../devices/miband/MiBandCoordinator.java | 2 +- .../devices/pebble/PBWInstallHandler.java | 4 +-- .../gadgetbridge/impl/GBDevice.java | 32 +++++++++++++------ .../service/AbstractDeviceSupport.java | 2 +- .../miband/AbstractMi1SFirmwareInfo.java | 2 +- .../devices/miband/Mi1AFirmwareInfo.java | 2 +- .../devices/miband/Mi1FirmwareInfo.java | 2 +- .../devices/miband/Mi1SFirmwareInfo.java | 2 +- .../devices/pebble/PebbleIoThread.java | 2 +- .../gadgetbridge/database/EntitiesTest.java | 2 +- 13 files changed, 39 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java index 1a68138eb..ed9ed5085 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -211,8 +211,8 @@ public class ExternalPebbleJSActivity extends GBActivity { JSONObject wi = new JSONObject(); try { wi.put("firmware", mGBDevice.getFirmwareVersion()); - wi.put("platform", PebbleUtils.getPlatformName(mGBDevice.getHardwareVersion())); - wi.put("model", PebbleUtils.getModel(mGBDevice.getHardwareVersion())); + wi.put("platform", PebbleUtils.getPlatformName(mGBDevice.getModel())); + wi.put("model", PebbleUtils.getModel(mGBDevice.getModel())); //TODO: use real info wi.put("language", "en"); } catch (JSONException e) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java index 8247dcd3d..6389e5d61 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java @@ -112,7 +112,7 @@ public abstract class AbstractAppManagerFragment extends Fragment { systemApps.add(new GBDeviceApp(UUID.fromString("67a32d95-ef69-46d4-a0b9-854cc62f97f9"), "Alarms (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); systemApps.add(new GBDeviceApp(UUID.fromString("18e443ce-38fd-47c8-84d5-6d0c775fbe55"), "Watchfaces (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getHardwareVersion()))) { + if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getModel()))) { systemApps.add(new GBDeviceApp(UUID.fromString("0863fc6a-66c5-4f62-ab8a-82ed00a98b5d"), "Send Text (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); systemApps.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); } @@ -188,7 +188,7 @@ public abstract class AbstractAppManagerFragment extends Fragment { cachedAppList.add(new GBDeviceApp(UUID.fromString("cf1e816a-9db0-4511-bbb8-f60c48ca8fac"), "Golf (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); } */ - if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getHardwareVersion()))) { + if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getModel()))) { if (baseName.equals(PebbleProtocol.UUID_PEBBLE_HEALTH.toString())) { cachedAppList.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); continue; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapter.java index a9ded1581..3296694a7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapter.java @@ -161,8 +161,8 @@ public class GBDeviceAdapter extends ArrayAdapter { private String getUniqueDeviceName(GBDevice device) { String deviceName = device.getName(); if (!isUniqueDeviceName(device, deviceName)) { - if (device.getHardwareVersion() != null) { - deviceName = deviceName + " " + device.getHardwareVersion(); + if (device.getModel() != null) { + deviceName = deviceName + " " + device.getModel(); if (!isUniqueDeviceName(device, deviceName)) { deviceName = deviceName + " " + device.getShortAddress(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandCoordinator.java index 667807789..549da8574 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandCoordinator.java @@ -180,7 +180,7 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator { @Override public boolean supportsHeartRateMeasurement(GBDevice device) { - String hwVersion = device.getHardwareVersion(); + String hwVersion = device.getModel(); return isMi1S(hwVersion) || isMiPro(hwVersion); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java index a00f49b2d..9670851be 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java @@ -52,7 +52,7 @@ public class PBWInstallHandler implements InstallHandler { return; } - String platformName = PebbleUtils.getPlatformName(device.getHardwareVersion()); + String platformName = PebbleUtils.getPlatformName(device.getModel()); try { mPBWReader = new PBWReader(mUri, mContext, platformName); @@ -75,7 +75,7 @@ public class PBWInstallHandler implements InstallHandler { installItem.setIcon(R.drawable.ic_firmware); String hwRevision = mPBWReader.getHWRevision(); - if (hwRevision != null && hwRevision.equals(device.getHardwareVersion())) { + if (hwRevision != null && hwRevision.equals(device.getModel())) { installItem.setName(mContext.getString(R.string.pbw_installhandler_pebble_firmware, "")); installItem.setDetails(mContext.getString(R.string.pbwinstallhandler_correct_hw_revision)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java index 53b16cbd2..8fb41e1b1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; import org.slf4j.Logger; @@ -48,7 +49,7 @@ public class GBDevice implements Parcelable { private final DeviceType mDeviceType; private String mFirmwareVersion; private String mFirmwareVersion2; - private String mHardwareVersion; + private String mModel; private State mState = State.NOT_CONNECTED; private short mBatteryLevel = BATTERY_UNKNOWN; private short mBatteryThresholdPercent = BATTERY_THRESHOLD_PERCENT; @@ -70,7 +71,7 @@ public class GBDevice implements Parcelable { mDeviceType = DeviceType.values()[in.readInt()]; mFirmwareVersion = in.readString(); mFirmwareVersion2 = in.readString(); - mHardwareVersion = in.readString(); + mModel = in.readString(); mState = State.values()[in.readInt()]; mBatteryLevel = (short) in.readInt(); mBatteryThresholdPercent = (short) in.readInt(); @@ -89,7 +90,7 @@ public class GBDevice implements Parcelable { dest.writeInt(mDeviceType.ordinal()); dest.writeString(mFirmwareVersion); dest.writeString(mFirmwareVersion2); - dest.writeString(mHardwareVersion); + dest.writeString(mModel); dest.writeInt(mState.ordinal()); dest.writeInt(mBatteryLevel); dest.writeInt(mBatteryThresholdPercent); @@ -136,12 +137,19 @@ public class GBDevice implements Parcelable { mFirmwareVersion2 = firmwareVersion2; } - public String getHardwareVersion() { - return mHardwareVersion; + /** + * Returns the specific model/hardware revision of this device. + * This information is not always available, typically only when the device is initialized + * @return the model/hardware revision of this device + * @see #getType() + */ + @Nullable + public String getModel() { + return mModel; } - public void setHardwareVersion(String hardwareVersion) { - mHardwareVersion = hardwareVersion; + public void setModel(String model) { + mModel = model; } public boolean isConnected() { @@ -261,6 +269,12 @@ public class GBDevice implements Parcelable { return GBApplication.getContext().getString(R.string.unknown_state); } + /** + * Returns the general type of this device. For more detailed information, + * soo #getModel() + * @return the general type of this device + */ + @NonNull public DeviceType getType() { return mDeviceType; } @@ -384,8 +398,8 @@ public class GBDevice implements Parcelable { if (mDeviceInfos != null) { result.addAll(mDeviceInfos); } - if (mHardwareVersion != null) { - result.add(new GenericItem(DEVINFO_HW_VER, mHardwareVersion)); + if (mModel != null) { + result.add(new GenericItem(DEVINFO_HW_VER, mModel)); } if (mFirmwareVersion != null) { result.add(new GenericItem(DEVINFO_FW_VER, mFirmwareVersion)); 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 900f8de24..36b12e7c8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java @@ -152,7 +152,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { return; } gbDevice.setFirmwareVersion(infoEvent.fwVersion); - gbDevice.setHardwareVersion(infoEvent.hwVersion); + gbDevice.setModel(infoEvent.hwVersion); gbDevice.sendDeviceUpdateIntent(context); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1SFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1SFirmwareInfo.java index cbe8148c6..cdb1e1b69 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1SFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1SFirmwareInfo.java @@ -13,7 +13,7 @@ public abstract class AbstractMi1SFirmwareInfo extends AbstractMiFirmwareInfo { @Override public boolean isGenerallyCompatibleWith(GBDevice device) { - return MiBandConst.MI_1S.equals(device.getHardwareVersion()); + return MiBandConst.MI_1S.equals(device.getModel()); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1AFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1AFirmwareInfo.java index ce975245c..e8dbf6414 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1AFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1AFirmwareInfo.java @@ -31,7 +31,7 @@ public class Mi1AFirmwareInfo extends AbstractMi1FirmwareInfo { @Override public boolean isGenerallyCompatibleWith(GBDevice device) { - String hwVersion = device.getHardwareVersion(); + String hwVersion = device.getModel(); return MiBandConst.MI_1A.equals(hwVersion); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1FirmwareInfo.java index aa5067813..37fde0629 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1FirmwareInfo.java @@ -31,7 +31,7 @@ public class Mi1FirmwareInfo extends AbstractMi1FirmwareInfo { @Override public boolean isGenerallyCompatibleWith(GBDevice device) { - String hwVersion = device.getHardwareVersion(); + String hwVersion = device.getModel(); return MiBandConst.MI_1.equals(hwVersion); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java index 926afca19..8ef2e65da 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java @@ -30,7 +30,7 @@ public class Mi1SFirmwareInfo extends CompositeMiFirmwareInfo { @Override public boolean isGenerallyCompatibleWith(GBDevice device) { - return MiBandConst.MI_1S.equals(device.getHardwareVersion()); + return MiBandConst.MI_1S.equals(device.getModel()); } @Override 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 a1ac5b330..73f4ae514 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 @@ -591,7 +591,7 @@ public class PebbleIoThread extends GBDeviceIoThread { return; } - String platformName = PebbleUtils.getPlatformName(gbDevice.getHardwareVersion()); + String platformName = PebbleUtils.getPlatformName(gbDevice.getModel()); try { mPBWReader = new PBWReader(uri, getContext(), platformName); diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/EntitiesTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/EntitiesTest.java index 4f13f234c..c4f331d29 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/EntitiesTest.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/EntitiesTest.java @@ -100,7 +100,7 @@ public class EntitiesTest { // DBHelper dbHelper = new DBHelper(RuntimeEnvironment.application); GBDevice dummyGBDevice = new GBDevice("00:00:00:00:00", "Testie", DeviceType.TEST); dummyGBDevice.setFirmwareVersion("1.2.3"); - dummyGBDevice.setHardwareVersion("4.0"); + dummyGBDevice.setModel("4.0"); Device device = DBHelper.getDevice(dummyGBDevice, daoSession); assertNotNull(device); assertEquals("00:00:00:00:00", device.getIdentifier());