First, my apologies if this is not relevant to the platform group. I couldn't decide whether this was more suited to the Development group, or here, as it relates to a platform mechanism. I will move it if needed.
I've run into an unexpected condition that I would like to understand the appropriate response to. The scenario is (source attached, commands to exercise the code are in comments):
- Start service: am startservice -a com.test.bindunbind.START -n com.test.bindunbind/.BindTestService
- Service attempts to bind to a service that does not exist.
- bindService, as expected, returns false.
- Service is stopped using the STOP intent ( am startservice -a com.test.bindunbind.STOP -n com.test.bindunbind/.BindTestService).
- ServiceConnectionLeaked exception is thrown.
My question is: should implementations always call unBind() if bindService returns false?
Note that if the above flow is altered to use the STOP_UNBIND (am startservice -a com.test.bindunbind.STOP_UNBIND -n com.test.bindunbind/.BindTestService), the ServiceConnectionLeaked is not thrown, the message "Unbind failed: could not find connection for android.os.BinderProxy@4071edd8" is logged, same as when using STOP.
Tested on 2.3.3.
Thanks!