blob: 9d12ed3ea60a3f7da606d887fb3025e5c5fd9bbb [file] [log] [blame]
Tri Vodf205792019-01-30 09:24:19 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <android-base/unique_fd.h>
18#include <binder/BinderService.h>
19#include <binder/IPCThreadState.h>
20#include <binder/IServiceManager.h>
21#include <binder/ProcessState.h>
22#include <binder/Status.h>
23#include <utils/String16.h>
24
25#include <android/ashmemd/BnAshmemDeviceService.h>
26
27using android::String16;
28using android::base::unique_fd;
29
30namespace android {
31namespace ashmemd {
32
33class AshmemDeviceService : public BnAshmemDeviceService {
34 public:
35 binder::Status open(os::ParcelFileDescriptor* ashmemFd) override {
36 ashmemFd->reset(unique_fd(TEMP_FAILURE_RETRY(::open("/dev/ashmem", O_RDWR | O_CLOEXEC))));
37 return binder::Status::ok();
38 }
39};
40
41void CreateAndRegisterService() {
42 sp<AshmemDeviceService> ashmemService = new AshmemDeviceService();
43 defaultServiceManager()->addService(String16("ashmem_device_service"), ashmemService,
44 true /* allowIsolated */);
45}
46
47void JoinThreadPool() {
48 sp<ProcessState> ps = ProcessState::self();
49 IPCThreadState::self()->joinThreadPool(); // should not return
50}
51
52} // namespace ashmemd
53} // namespace android
54
55int main() {
56 android::ashmemd::CreateAndRegisterService();
57 android::ashmemd::JoinThreadPool();
58 std::abort(); // unreachable
59}