Repository navigation
DEV-1402: ShimmerCapture no longer crashes at launch when Bluetooth is off #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
...shimmerresearch/android/shimmerService/AAPI_00008_ServiceWithoutBluetoothManagerTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.shimmerresearch.android.shimmerService; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import com.shimmerresearch.driver.ShimmerDevice; | ||
|
|
||
| /** | ||
| * DEV-1402: with Bluetooth off, ShimmerService.onCreate() cannot create its | ||
| * BluetoothManager ("Bluetooth not Enabled") and leaves btManager null. The | ||
| * ShimmerCapture options menu then called getListOfConnectedDevices() on it, and | ||
| * the app crashed at launch. Google Play's pre-launch test refused the 1.3.4 | ||
| * release for it. | ||
| * <p> | ||
| * A missing BluetoothManager now means no devices: these calls return empty or | ||
| * null, or do nothing, instead of throwing. | ||
| * <p> | ||
| * No hardware: a service that has not been through onCreate() has no | ||
| * BluetoothManager, which is the state Bluetooth being off leaves it in. | ||
| */ | ||
| public class AAPI_00008_ServiceWithoutBluetoothManagerTest { | ||
|
|
||
| private static final String ADDRESS = "00:06:66:00:00:01"; | ||
|
|
||
| private ShimmerService service; | ||
|
|
||
| @Before | ||
| public void createServiceWithoutBluetoothManager() { | ||
| service = new ShimmerService(); | ||
| assertNull("precondition: no BluetoothManager", service.getBluetoothManager()); | ||
| } | ||
|
|
||
| @Test | ||
| public void listOfConnectedDevicesIsEmpty() { | ||
| List<ShimmerDevice> devices = service.getListOfConnectedDevices(); | ||
| assertNotNull(devices); | ||
| assertTrue(devices.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getShimmerFindsNoDevice() { | ||
| assertNull(service.getShimmer(ADDRESS)); | ||
| } | ||
|
|
||
| @Test | ||
| public void disconnectAllDevicesClearsTheServiceState() { | ||
| service.mMultiShimmer.put(ADDRESS, new Object()); | ||
| service.disconnectAllDevices(); | ||
| assertTrue(service.mMultiShimmer.isEmpty()); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guard covers only some of
btManager's uses. This PR guards about six of the ~60btManager.calls in ShimmerService: the ones the Play crash and the tested menus reached. Still unguarded:onStop()(L307), which callsbtManager.disconnectAllDevices()just asonDestroy()did;getBluetoothManager()(L1328), which returnsnullto callers that dereference it straight away:SignalsToPlotFragment(both copies), bothPlotFragments, andMainActivityL598/923/975;btManager.call:startStreamingAllDevices(),setAllEnabledSensors(), thewrite*/get*methods.ShimmerService is library code, and the PR notes say the other apps using it get the guard too. But an app that reaches any of these with Bluetooth off still gets the same NullPointerException. Guarding it once would cover all of them: route every method through one accessor (
ensureBluetoothManager(), returning early or throwing a clear exception when it's false), or use a null-object manager. If that's too much for this release, a follow-up issue would keep it from being lost.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on the gap. In 247271a I guarded
onStop()likeonDestroy(). I left the rest for a follow-up ticket, for this reason. Within ShimmerCapture, every otherbtManager/getBluetoothManager()call you list runs only for a connected or selected device: configure, the sensor/config lists, plot and signals-to-plot while streaming. A device can't connect until a manager exists, and the manager is only ever missing when Bluetooth was off at start, until Allow creates it. So the app can't reach them withnull. Other apps onShimmerServicecan, so I'll raise a follow-up to route every use through one accessor, with a clear failure instead of an NPE, and link it here.