From bb80de0b84e607a07be352f0820fdd179432b808 Mon Sep 17 00:00:00 2001 From: Sarp Misoglu Date: Thu, 19 Dec 2024 22:06:38 +0000 Subject: Acquire the backup wakelock with a timeout There have been a few reports of the backup service failing to call release() on the wakelock and draining battery for hours. These are rare failures and hard to debug individually but with the timeout we will limit the worst case significantly. I am setting the default timeout to 30 minutes. This should be more than enough time for a backup or restore operation. If in the future these operation get longer, the timeout is configurable by a setting. Test: atest CtsBackupTestCases Fixes: 364931501 Fixes: 357769443 Fixes: 289789401 Flag: EXEMPT bugfix Change-Id: Iaac0218d5258031b6f67c3c56c776ce098e8a8c4 --- .../server/backup/testing/BackupManagerServiceTestUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'services/robotests/backup') diff --git a/services/robotests/backup/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java b/services/robotests/backup/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java index fc3ec7b44f4f..4d04c8b76fc7 100644 --- a/services/robotests/backup/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java +++ b/services/robotests/backup/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java @@ -37,6 +37,7 @@ import android.os.Process; import android.util.Log; import com.android.server.backup.BackupAgentTimeoutParameters; +import com.android.server.backup.BackupManagerConstants; import com.android.server.backup.BackupManagerService; import com.android.server.backup.TransportManager; import com.android.server.backup.UserBackupManagerService; @@ -162,10 +163,10 @@ public class BackupManagerServiceTestUtils { public static UserBackupManagerService.BackupWakeLock createBackupWakeLock( Application application) { - PowerManager powerManager = - (PowerManager) application.getSystemService(Context.POWER_SERVICE); + PowerManager powerManager = application.getSystemService(PowerManager.class); return new UserBackupManagerService.BackupWakeLock( - powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*backup*"), 0); + powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*backup*"), 0, + new BackupManagerConstants(Handler.getMain(), application.getContentResolver())); } /** -- cgit v1.2.3-59-g8ed1b