Repository navigation
Conversation
btManager is null while Bluetooth was off when the service was created. DEV-1402 guarded the calls ShimmerCapture reaches; the other 49 methods that use btManager still threw NullPointerException, as did the four library fragments that dereference getBluetoothManager(). Rule: no BluetoothManager means no devices. Every method that uses it first returns what ShimmerBluetoothManagerAndroid returns for a device it does not know: commands do nothing, and queries return -1, 0, false, "", null, DISCONNECTED or an empty list, method by method. handleMsgStateChange() skips the manager for its CONNECTED, SDLOGGING and DISCONNECTED cases, and bluetoothAddressComparator() compares the addresses itself. A null-object manager was not an option: the manager's constructor throws when Bluetooth is off, and other apps rely on that. getBluetoothManager() keeps returning null, now documented. The PlotFragment and SignalsToPlotFragment copies check for it, and SignalsToPlotFragment also no longer throws for a device the service does not know. AAPI_00008 covers every guarded method; its four new tests fail on master's ShimmerService. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #150 (DEV-1402), whose review asked for it.
ShimmerService.btManagerisnullwhile Bluetooth was off when the service was created (onCreatelogs "Bluetooth not Enabled"). #150 guarded the calls ShimmerCapture reaches. The other 49 methods that usebtManagerstill threw a NullPointerException, as did the four library fragments that dereferencegetBluetoothManager(). Apps usingShimmerServicefrom source or from the publishedshimmerandroidinstrumentdriverpackage could hit them.Rule: no BluetoothManager means no devices
Every method that uses the manager first returns what
ShimmerBluetoothManagerAndroiditself returns for a device it doesn't know, read from each manager method:start/stopStreaming,start/stopLogging,write*,setAll*,toggle*LED*,configureShimmer(s), …getSamplingRate,getAccelRange,getGSRRange,get5VReg,getpmux,getBattLimitWarning,getPacketReceptionRate-1getEnabledSensors,sensorConflictCheckandCorrection,getShimmerVersion0getShimmerStateDISCONNECTEDisSensing,isDocked,isLowPowerMagEnabled,isUsingLogAndStreamFW,DevicesConnected,DeviceIsLogging,DeviceIsStreamingfalsegetFWVersion""getListofEnabledSensorsnullgetListofEnabledSensorSignalsTwo methods are handled by hand:
handleMsgStateChange()skips the manager in its CONNECTED, SDLOGGING and DISCONNECTED cases.bluetoothAddressComparator()is a string comparison, so it now compares the two addresses itself.The rule is written down on the
btManagerfield.Why not a null-object manager:
ShimmerBluetoothManagerAndroid's constructor throws when Bluetooth is off, and other apps rely on that.getBluetoothManager()It keeps returning
nullwhen there's no manager; that's now documented: "callers must check for null". Its callers in the library:PlotFragment(both copies): read the manager once and treatnullas "no sensor list", which the code already handles.SignalsToPlotFragment(both copies): use the service's null-safegetShimmer(). They also no longer throw for a device the service doesn't know (device != null && device.isStreaming()).shimmerServiceExample'sMainActivitycalls it in six places, all for a device the service already has. SincegetShimmer()returnsnullwithout a manager, a device existing means a manager exists, soMainActivityis unchanged.Tests
AAPI_00008gains four tests:Against master's
ShimmerServiceall four fail; with this change all 7 pass, and so do AAPI_00002–00007.assembleDebugbuilds every example app, and the library's release build passes. Paths that show a Toast (connectShimmer,onStop) are left out:Toast.makeText()returnsnullon the stubandroid.jar.Notes
if (btManager == null).🤖 Generated with Claude Code