android_external_minigbm/cros_gralloc/gralloc4/CrosGralloc4AllocatorService.cc
Jason Macnak 2e63aaf616 cros_gralloc: Check for init failure in allocator service
Prior to this change, the allocator service could be kept
alive in a bad state if the allocator failed to initialize
the underlying cros_gralloc_driver on the first attempt.

With this change, the allocator service will exit if the
allocator fails to initialize the underlying
cros_gralloc_driver which gives the service a chance to
restart and initialize again.

BUG=b:187802138
TEST=launch Cuttlefish

Change-Id: I2a0fd76cda8492632406597656a581325e69b18a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3015656
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2021-07-13 01:05:29 +00:00

35 lines
1.1 KiB
C++

/*
* Copyright 2020 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#define LOG_TAG "AllocatorService"
#include <hidl/LegacySupport.h>
#include "cros_gralloc/gralloc4/CrosGralloc4Allocator.h"
using android::sp;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::hardware::graphics::mapper::V4_0::Error;
int main(int, char**) {
sp<CrosGralloc4Allocator> allocator = new CrosGralloc4Allocator();
if (allocator->init() != Error::NONE) {
ALOGE("Failed to initialize IAllocator 4.0 service.");
return -EINVAL;
}
configureRpcThreadpool(4, true /* callerWillJoin */);
if (allocator->registerAsService() != android::NO_ERROR) {
ALOGE("Failed to register graphics IAllocator 4.0 service.");
return -EINVAL;
}
ALOGI("IAllocator 4.0 service is initialized.");
android::hardware::joinRpcThreadpool();
ALOGI("IAllocator 4.0 service is terminating.");
return 0;
}