audioflinger: keep wakelock during offload playback

Add a system property ro.audio.offload_wakelock to select
if a wakelock should be kept during offload playback while waiting for
write completion callback.
The default is yes, keep the wakelock.

On some platforms, the cost of entering or exiting suspend is so high
that is it better to not release a wakelock at all rather than releasing
it periodically.

Bug: 26208297
Change-Id: Ib41c7e4ed9c8c0c063363eb9fe99a2ecc81b521b
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index b322a45..68339d0 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -2924,11 +2924,7 @@
                     break;
                 }
                 bool released = false;
-                // The following works around a bug in the offload driver. Ideally we would release
-                // the wake lock every time, but that causes the last offload buffer(s) to be
-                // dropped while the device is on battery, so we need to hold a wake lock during
-                // the drain phase.
-                if (mBytesRemaining && !(mDrainSequence & 1)) {
+                if (!keepWakeLock()) {
                     releaseWakeLock_l();
                     released = true;
                 }
@@ -5165,10 +5161,11 @@
         AudioStreamOut* output, audio_io_handle_t id, uint32_t device, bool systemReady,
         uint32_t bitRate)
     :   DirectOutputThread(audioFlinger, output, id, device, OFFLOAD, systemReady, bitRate),
-        mPausedBytesRemaining(0)
+        mPausedWriteLength(0), mPausedBytesRemaining(0), mKeepWakeLock(true)
 {
     //FIXME: mStandby should be set to true by ThreadBase constructor
     mStandby = true;
+    mKeepWakeLock = property_get_bool("ro.audio.offload_wakelock", true /* default_value */);
 }
 
 void AudioFlinger::OffloadThread::threadLoop_exit()