Make WakeLock handling thread safe

We have an implementation of a wakelock which reference counts requestors - however, the implementation is not thread safe.

This commit:

1. Makes the implementation thread safe
2. Retroactively flag guards the use of WakeLocks on background thread from previous commit.
3. Slightly improves logging so we don't churn strings if logging is disabled.

Bug:326544949
Bug:316128516

Test: newly added and existing unit tests
Flag: ACONFIG com.android.systemui.flags.DELAYED_WAKELOCK_RELEASE_ON_BACKGROUND_THREAD DISABLED
Change-Id: I9ce86fdd69fdae9f88b5e06f5b85836fb4f9aa5e
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index f5c4843..ba77380 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -542,6 +542,13 @@
     namespace: "systemui"
     description: "Binds Keyguard Media Controller Visibility to MediaContainerView"
     bug: "298213983"
+}
+
+flag {
+    name: "delayed_wakelock_release_on_background_thread"
+    namespace: "systemui"
+    description: "Released delayed wakelocks on background threads to avoid janking screen transitions."
+    bug: "316128516"
     metadata {
         purpose: PURPOSE_BUGFIX
     }