From 09dd8c47d81abc486161194f82fb1d3fafed349a Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Wed, 11 Apr 2018 09:23:19 -0700 Subject: [PATCH] Properly disconnect after skipping an operation. If we skip an operation we used to just return. This lead to the service staying connected, holding the wakelock and consuming power. Hence after we skip an operation we need to check if we can disconnect the service, basically treating skipping an operation similar failing to execute the operation. Fixes: 77766977 Test: Detected music via sound trigger service and triggered dropping of operations Change-Id: Ia837d628193b3a5c2763f4aae666193d624b6d7f --- .../soundtrigger/SoundTriggerService.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java index 11609435205f2..cd524a5173763 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java @@ -926,25 +926,24 @@ public class SoundTriggerService extends SystemService { Slog.w(TAG, mPuuid + ": Dropped operation as too many operations were " + "run in last 24 hours"); } - return; - } + } else { + mNumOps.addOp(currentTime); - mNumOps.addOp(currentTime); + // Find a free opID + int opId = mNumTotalOpsPerformed; + do { + mNumTotalOpsPerformed++; + } while (mRunningOpIds.contains(opId)); - // Find a free opID - int opId = mNumTotalOpsPerformed; - do { - mNumTotalOpsPerformed++; - } while (mRunningOpIds.contains(opId)); + // Run OP + try { + if (DEBUG) Slog.v(TAG, mPuuid + ": runOp " + opId); - // Run OP - try { - if (DEBUG) Slog.v(TAG, mPuuid + ": runOp " + opId); - - op.run(opId, mService); - mRunningOpIds.add(opId); - } catch (Exception e) { - Slog.e(TAG, mPuuid + ": Could not run operation " + opId, e); + op.run(opId, mService); + mRunningOpIds.add(opId); + } catch (Exception e) { + Slog.e(TAG, mPuuid + ": Could not run operation " + opId, e); + } } // Unbind from service if no operations are left (i.e. if the operation failed)