From 26826390d285b57a0af3eed540d6e6a082d3d0e7 Mon Sep 17 00:00:00 2001 From: Dipankar Bhardwaj Date: Tue, 18 Feb 2025 07:11:38 -0800 Subject: Use fixed thread pool for calls to OemMetadataService Instead of creating a new thread everytime we want to fetch OEM metadata, updating code to use a fixed thread pool of 3 threads. We do not expect lot of concurrent requests to this as scanner code is currently serialised, hence keeping thread pool size low. Also guarded oem metadata connection code with try-catch to avoid onCreate() crash. Test: atest OemMetadataServiceTest Bug: 377432406 Change-Id: I70a0b6ca6ae43f7ba7ab086103365cc16b3497fa Flag: EXEMPT minor fix --- .../java/android/provider/OemMetadataServiceWrapper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'apex') diff --git a/apex/framework/java/android/provider/OemMetadataServiceWrapper.java b/apex/framework/java/android/provider/OemMetadataServiceWrapper.java index 278f1b94a..634632589 100644 --- a/apex/framework/java/android/provider/OemMetadataServiceWrapper.java +++ b/apex/framework/java/android/provider/OemMetadataServiceWrapper.java @@ -37,6 +37,7 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -53,6 +54,8 @@ public final class OemMetadataServiceWrapper { private final IOemMetadataService mOemMetadataService; + private final ExecutorService mExecutorService; + private final long mServiceTimeoutInSeconds; public OemMetadataServiceWrapper(@NonNull IOemMetadataService oemMetadataService) { @@ -65,6 +68,7 @@ public final class OemMetadataServiceWrapper { this.mOemMetadataService = oemMetadataService; this.mServiceTimeoutInSeconds = serviceTimeoutInSeconds; + mExecutorService = Executors.newFixedThreadPool(3); } /** @@ -76,7 +80,7 @@ public final class OemMetadataServiceWrapper { return new HashSet<>(); } - return Executors.newSingleThreadExecutor().submit(() -> { + return mExecutorService.submit(() -> { CompletableFuture> future = new CompletableFuture<>(); RemoteCallback callback = new RemoteCallback( result -> setResultForGetSupportedMimeTypes(result, future)); @@ -94,7 +98,7 @@ public final class OemMetadataServiceWrapper { return new HashMap<>(); } - return Executors.newSingleThreadExecutor().submit(() -> { + return mExecutorService.submit(() -> { CompletableFuture> future = new CompletableFuture<>(); RemoteCallback callback = new RemoteCallback( result -> setResultForGetOemCustomData(result, future)); -- cgit v1.2.3-59-g8ed1b