Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 547c8b7f authored by Oluwarotimi Adesina's avatar Oluwarotimi Adesina
Browse files

Name AppFunction executors

Flag: android.app.appfunctions.flags.enable_app_function_manager
Test: Existing CTS
Bug: 357551503
Change-Id: I2658c49caba39510a340cc8067a5bbd14a6ff280
parent 57ed2386
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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() {}
}
+3 −1
Original line number Diff line number Diff line
@@ -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"));
    }

    /**
+40 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}