particle-iot / spark-setup-android

Former home of the Particle Device Setup library for Android
Apache License 2.0
23 stars 30 forks source link

DeviceSetupCompleteContract type mismatch on EXTRA_CONFIGURED_DEVICE_ID #10

Closed mhespenh closed 8 years ago

mhespenh commented 9 years ago

ETA: Version 0.3.0

In ParticleDeviceSetupLibrary.java:72, the intent extra EXTRA_CONFIGURED_DEVICE_ID is treated as a Long:

long errorValue = 0;
long deviceId = intent.getLongExtra(
                    DeviceSetupCompleteContract.EXTRA_CONFIGURED_DEVICE_ID, errorValue);

if (success && deviceId != errorValue) {
    onSetupSuccess(deviceId);
} else {
    onSetupFailure();
}

According to SuccessActivity.java:114 it is added to the intent as a String.

result.putExtra(ParticleDeviceSetupLibrary.DeviceSetupCompleteContract.EXTRA_CONFIGURED_DEVICE_ID, DeviceSetupState.deviceToBeSetUpId);
//DeviceSetupData.deviceToBeSetUpId is defined elsewhere as static volatile String deviceToBeSetUpId;

This causes a Java type-conversion failure and always returns 0 (the default value of getLongExtra() thanks to errorValue), and hence failure

Easy fix (works fine for me) replace ParticleDeviceSetupLibrary:71-80:

//long errorValue = 0;
String deviceId = intent.getStringExtra(
                    DeviceSetupCompleteContract.EXTRA_CONFIGURED_DEVICE_ID);

if (success && !deviceId.equals(null)) {
    onSetupSuccess(deviceId);
} else {
    onSetupFailure();
}
jensck commented 9 years ago

Well, that's embarrassing. Good catch, I'll post an updated release with a fix for this soon.

mhespenh commented 9 years ago

I should have noted- I'm not sure what intent.getStringExtra() will return if claiming failed, so !deviceId.equals(null) might not actually be the correct check.

idokleinman commented 9 years ago

@mhespenh thank you! btw, pull requests are welcome.