Fix PowerManagerService handling of work chains.

When a wakelock with specific set of flags is requested
PowerManagerService crashes with NPE because
applyWakeLockFlagsOnAcquireLocked does not handle work chains and
requires UID set directly on the work source instead of the work chain.

This fixes the behavior by handling the work chains as well as
introducing additional emptiness checks.

There may be multiple work chains in a work source, and only the first
one is used. I don't know the details of this method, but it looks like
it's a reasonable decision.

Bug: 113868145
Test: atest FrameworksCoreTests:PowerManagerTest

Change-Id: Idbfa1d0cd32ddc021caf6443138688d3f8b7c946
3 files changed