This can be solved if we write the pref to disk before calling the
hardware, and revert it if the hardware fail to fulfill the request.
The behavior can be kept internally to API implementations.
> A slightly more complex scenario is if I turn on wifi, but for some
> reason wifi fails to turn on, do I really want the phone to give up
> rather than try again? Especially after a reboot which might actually
> fix some broken state in the wifi driver? This scenario is a more
> complex though since I don't know under what circumstances wifi would
> actually fail to turn on?
This proposal is deliberately flawed to work with broken hardware.
Instead of quietly trying to call the hardware for the user (before
and after the reboot), the proposal is trying to be explicit to user
when hardware fail to fulfill the request(s).
> One possible solution is to separate "desired state" from "hardware
> state". So when setFooEnabled(true) is called, we'd immediately save
> the new value in prefs, and then reflect "enabled" in a "desired
> state" property. But the "hardware state" property would behave as you
> describe above and would switch to "enabling". If turning the hardware
> on fails, the "hardware state" would switch back to "disabled".
> However the "desired state" would still reflect "enabled". The API
> could then retry to turn on the hardware if that's appropriate.
>
> If we did this we could technically still use mozSettings to track the
> "desired state", and the individual API to track the "hardware state".
> But that might just make for a more complex API. But might mean
> smaller changes compared to what we have now.
>
The proposal is designed such that "desired state" and "hardware
state" is kept in sync as closely as possible, streamlining the
interfaces between three. What you are describing is what we are doing
right now -- keeping the desired state in mozSettings and have the API
to track the changes and try to achieve the described hardware state.
It's proven to be complex for both Gecko and Gaia, when the user
attempt to toggle many times in a short interval -- something fairly
common being tried by QA forks.
I) For Gecko, since there is no way to deny changes in desired state,
it would always have to "catch up" with the changes, presumably by
queue the state change and send the requests to hardware one-by-one.
II) For Gaia, we would have hard time to find the right timing for
disabling/re-enabling the UI (to express the "working" state and
provide a "cool down" period). Oh, and doing that on all toggles of
the same setting on different apps.
> I do agree that this is a more complex system though. And one that
> requires UI authors to deal with more state and more complexity.
>
Exactly.
There is one even simpler alternative: We drop the UI requirement of
(II) and ensure every Gecko API have (I) properly implemented. But
then we will get bugs like "I am able to toggle 'airplane mode' 5
times in 1 sec but the icon only shows up after 1 minute." and we
would have to argue that it's not a bug :)