summaryrefslogtreecommitdiff
path: root/apex
diff options
context:
space:
mode:
author Dipankar Bhardwaj <dipankarb@google.com> 2025-02-18 07:11:38 -0800
committer Dipankar Bhardwaj <dipankarb@google.com> 2025-02-18 07:11:38 -0800
commit26826390d285b57a0af3eed540d6e6a082d3d0e7 (patch)
treed665c0d343f8353cd9fc701e362f96b8b67bb52c /apex
parent1f01a45bbf0c7606809df3c2586eaac2084fefa9 (diff)
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
Diffstat (limited to 'apex')
-rw-r--r--apex/framework/java/android/provider/OemMetadataServiceWrapper.java8
1 files changed, 6 insertions, 2 deletions
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<Set<String>> 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<Map<String, String>> future = new CompletableFuture<>();
RemoteCallback callback = new RemoteCallback(
result -> setResultForGetOemCustomData(result, future));