/* * 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. */ #define LOG_TAG "TestServer" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "TestServer.h" namespace android { namespace { class TestConsumerListener : public BnConsumerListener { virtual void onFrameAvailable(const BufferItem&) override {} virtual void onBuffersReleased() override {} virtual void onSidebandStreamChanged() override {} }; class TestServiceImpl : public libgui_test_server::BnTestServer { public: TestServiceImpl(const char* name) : mName(name) {} virtual binder::Status createProducer(view::Surface* out) override { std::lock_guard lock(mMutex); BufferQueueHolder bq; BufferQueue::createBufferQueue(&bq.producer, &bq.consumer); sp listener = sp::make(); bq.consumer->consumerConnect(listener, /*controlledByApp*/ true); uint64_t id = 0; bq.producer->getUniqueId(&id); std::string name = base::StringPrintf("%s-%" PRIu64, mName, id); out->name = String16(name.c_str()); out->graphicBufferProducer = bq.producer; mBqs.push_back(std::move(bq)); return binder::Status::ok(); } virtual binder::Status killNow() override { ALOGE("LibGUI Test Service %s dying in response to killNow", mName); _exit(0); // Not reached: return binder::Status::ok(); } private: std::mutex mMutex; const char* mName; struct BufferQueueHolder { sp producer; sp consumer; }; std::vector mBqs; }; } // namespace int TestServerMain(const char* name) { ProcessState::self()->startThreadPool(); sp testService = sp::make(name); ALOGE("service"); sp serviceManager(defaultServiceManager()); LOG_ALWAYS_FATAL_IF(OK != serviceManager->addService(String16(name), testService)); ALOGD("LibGUI Test Service %s STARTED", name); IPCThreadState::self()->joinThreadPool(); ALOGW("LibGUI Test Service %s DIED", name); return 0; } } // namespace android