Fix PhysicalKeyboardFragment crash bug.
The root cause of crash bug #
27749932 is that the state mismatch between
when a Loader is created and when the Loader object finishes background
task. We can easily reproduce this crash by:
1. Pair two hardware keyboard A and B.
2. Open Physical Keyboard settings.
3. Press the power button to turn off the display.
4. Move keyboard A far away so that it is unpaired.
5. Press the power button to turn on the display.
6. Unlock the device.
One of the reasons PhysicalKeyboardFragment was unstable is that loader
ID reuse. PhysicalKeyboardFragment starts background data loading
because of many events such as #onResume() and #onInputDeviceAdded() but
there are chances that loader ID was reused because we specified
hardware keyboard device index as the loader ID. This was dangerous
also because device index can change when a device is added and removed.
With his CL each loader object has an unique ID and
PhysicalKeyboardFragment keeps tracking the list of active Loader IDs
only from which PhysicalKeyboardFragment should accept data.
Also, this CL removes dependencies on PhysicalKeyboardFragment from each
loader object so that we can have a clear boundary of responsibility
between data loader and data consumer.
Bug:
27749932
Change-Id: I53fcb2426d028a492c775bb2b4ec6a5419e33bb4