OSDN Git Service

Properly disconnect after skipping an operation.
authorPhilip P. Moltmann <moltmann@google.com>
Wed, 11 Apr 2018 16:23:19 +0000 (09:23 -0700)
committerPhilip P. Moltmann <moltmann@google.com>
Wed, 11 Apr 2018 16:23:19 +0000 (09:23 -0700)
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

services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java

index 1160943..cd524a5 100644 (file)
@@ -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;
-                    }
-
-                    mNumOps.addOp(currentTime);
+                    } else {
+                        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)