diff options
author | 2024-10-17 13:51:22 +0000 | |
---|---|---|
committer | 2024-10-17 13:51:22 +0000 | |
commit | 547c8b7fc11b00740d39ae65fc86f92ffe7e65ce (patch) | |
tree | 8ddede7efd6bab71a3a2088687b0bd15be919274 | |
parent | 57ed23860a481e5d23ba1b861b0ca80d92628f60 (diff) |
Name AppFunction executors
Flag: android.app.appfunctions.flags.enable_app_function_manager
Test: Existing CTS
Bug: 357551503
Change-Id: I2658c49caba39510a340cc8067a5bbd14a6ff280
3 files changed, 45 insertions, 2 deletions
diff --git a/services/appfunctions/java/com/android/server/appfunctions/AppFunctionExecutors.java b/services/appfunctions/java/com/android/server/appfunctions/AppFunctionExecutors.java index c3b7087a44c3..44ae1d1fbbbf 100644 --- a/services/appfunctions/java/com/android/server/appfunctions/AppFunctionExecutors.java +++ b/services/appfunctions/java/com/android/server/appfunctions/AppFunctionExecutors.java @@ -31,7 +31,8 @@ public final class AppFunctionExecutors { /* maxConcurrency= */ Runtime.getRuntime().availableProcessors(), /* keepAliveTime= */ 0L, /* unit= */ TimeUnit.SECONDS, - /* workQueue= */ new LinkedBlockingQueue<>()); + /* workQueue= */ new LinkedBlockingQueue<>(), + new NamedThreadFactory("AppFunctionExecutors")); private AppFunctionExecutors() {} } diff --git a/services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java b/services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java index 96be76975e9d..cc73288cdbfa 100644 --- a/services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java +++ b/services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java @@ -84,7 +84,9 @@ public class MetadataSyncAdapter { @NonNull PackageManager packageManager, @NonNull AppSearchManager appSearchManager) { mPackageManager = Objects.requireNonNull(packageManager); mAppSearchManager = Objects.requireNonNull(appSearchManager); - mExecutor = Executors.newSingleThreadExecutor(); + mExecutor = + Executors.newSingleThreadExecutor( + new NamedThreadFactory("AppFunctionSyncExecutors")); } /** diff --git a/services/appfunctions/java/com/android/server/appfunctions/NamedThreadFactory.java b/services/appfunctions/java/com/android/server/appfunctions/NamedThreadFactory.java new file mode 100644 index 000000000000..7adcc48a6a35 --- /dev/null +++ b/services/appfunctions/java/com/android/server/appfunctions/NamedThreadFactory.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.appfunctions; + +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +/** A {@link ThreadFactory} that creates threads with a given base name. */ +public class NamedThreadFactory implements ThreadFactory { + private final ThreadFactory mDefaultThreadFactory; + private final String mBaseName; + private final AtomicInteger mCount = new AtomicInteger(0); + + public NamedThreadFactory(final String baseName) { + mDefaultThreadFactory = Executors.defaultThreadFactory(); + mBaseName = baseName; + } + + @Override + public Thread newThread(Runnable runnable) { + final Thread thread = mDefaultThreadFactory.newThread(runnable); + thread.setName(mBaseName + "-" + mCount.getAndIncrement()); + return thread; + } +} |