From 56663ddbe74f8d2c0f6103ffb200a690185740dc Mon Sep 17 00:00:00 2001 From: Lais Andrade Date: Thu, 15 Jul 2021 19:57:10 +0100 Subject: [PATCH] Remove call to set wakeLock WorkSource from VibrationThread constructor A new VibrationThread might be created and dropped if the ongoing thread takes long to be finished and a new vibration arrived to the service. The wakelock is only acquired when a thread starts, so move the calls to configure the worksource to the run() method. Fix: 193742818 Test: manual Change-Id: I7d7953ec9e065bcec78110b44daf3ef57693164d --- .../java/com/android/server/vibrator/VibrationThread.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/vibrator/VibrationThread.java b/services/core/java/com/android/server/vibrator/VibrationThread.java index 0f4f58b32c1b1..630bf0a01a404 100644 --- a/services/core/java/com/android/server/vibrator/VibrationThread.java +++ b/services/core/java/com/android/server/vibrator/VibrationThread.java @@ -98,7 +98,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { } private final Object mLock = new Object(); - private final WorkSource mWorkSource = new WorkSource(); + private final WorkSource mWorkSource; private final PowerManager.WakeLock mWakeLock; private final IBatteryStats mBatteryStatsService; private final VibrationSettings mVibrationSettings; @@ -119,9 +119,8 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { mVibrationSettings = vibrationSettings; mDeviceEffectAdapter = effectAdapter; mCallbacks = callbacks; + mWorkSource = new WorkSource(mVibration.uid); mWakeLock = wakeLock; - mWorkSource.set(vib.uid); - mWakeLock.setWorkSource(mWorkSource); mBatteryStatsService = batteryStatsService; CombinedVibration effect = vib.getEffect(); @@ -152,6 +151,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_DISPLAY); + mWakeLock.setWorkSource(mWorkSource); mWakeLock.acquire(); try { mVibration.token.linkToDeath(this, 0);