From 337f73edc9664c1b7159624dffe72452a1fe8f29 Mon Sep 17 00:00:00 2001 From: Yurii Zubrytskyi Date: Tue, 29 Jun 2021 14:45:48 -0700 Subject: [PATCH] Pause watchdog monitor for incfs native lib extraction Native library extraction potentially takes much longer time for Incremental installations vs the regular ones: each page can wait for up to 10s (adb) or 100ms (non-adb), adding up to the full watchdog timeout of 1 min and triggering a reboot. This CL pauses Watchdog for the thread that's running extraction to make sure we don't try to fix a hanging single installation with killing the OS. Bug: 191166673 Fixes: 191166673 Test: atest package manager and incremental suites Change-Id: I9c4c24f305e079f346a76b64d4841cdbd58734fa --- .../internal/content/NativeLibraryHelper.java | 15 ------------ .../server/pm/PackageManagerService.java | 23 ++++++++++++++++++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/core/java/com/android/internal/content/NativeLibraryHelper.java b/core/java/com/android/internal/content/NativeLibraryHelper.java index c74c39a434fa4..10750b695a396 100644 --- a/core/java/com/android/internal/content/NativeLibraryHelper.java +++ b/core/java/com/android/internal/content/NativeLibraryHelper.java @@ -40,7 +40,6 @@ import android.os.incremental.IncrementalManager; import android.os.incremental.IncrementalStorage; import android.system.ErrnoException; import android.system.Os; -import android.util.ArraySet; import android.util.Slog; import dalvik.system.CloseGuard; @@ -551,18 +550,4 @@ public class NativeLibraryHelper { } return false; } - - /** - * Wait for all native library extraction to complete for the passed storages. - * - * @param incrementalStorages A list of the storages to wait for. - */ - public static void waitForNativeBinariesExtraction( - ArraySet incrementalStorages) { - for (int i = 0; i < incrementalStorages.size(); ++i) { - IncrementalStorage storage = incrementalStorages.valueAtUnchecked(i); - storage.waitForNativeBinariesExtraction(); - } - } - } diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 889785d5f766a..bd9c37bef7efd 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -20111,7 +20111,28 @@ public class PackageManagerService extends IPackageManager.Stub notifyPackageChangeObserversOnUpdate(reconciledPkg); } - NativeLibraryHelper.waitForNativeBinariesExtraction(incrementalStorages); + waitForNativeBinariesExtraction(incrementalStorages); + } + + static void waitForNativeBinariesExtraction( + ArraySet incrementalStorages) { + if (incrementalStorages.isEmpty()) { + return; + } + try { + // Native library extraction may take very long time: each page could potentially + // wait for either 10s or 100ms (adb vs non-adb data loader), and that easily adds + // up to a full watchdog timeout of 1 min, killing the system after that. It doesn't + // make much sense as blocking here doesn't lock up the framework, but only blocks + // the installation session and the following ones. + Watchdog.getInstance().pauseWatchingCurrentThread("native_lib_extract"); + for (int i = 0; i < incrementalStorages.size(); ++i) { + IncrementalStorage storage = incrementalStorages.valueAtUnchecked(i); + storage.waitForNativeBinariesExtraction(); + } + } finally { + Watchdog.getInstance().resumeWatchingCurrentThread("native_lib_extract"); + } } private int[] getInstalledUsers(PackageSetting ps, int userId) {