blob: a9168020b87d5a0e7848b28b96b8aebaa47a7f69 [file] [log] [blame]
Mikhail Naganov065985f2024-03-25 10:50:00 -07001/*
2 * Copyright (C) 2024 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 "AidlUtils.h"
18
19#define LOG_TAG "AIDLUtils"
20#include <utils/Log.h>
21
22namespace android {
23
24//static
25HalDeathHandler& HalDeathHandler::getInstance() {
26 // never-delete singleton
27 static HalDeathHandler* instance = new HalDeathHandler;
28 return *instance;
29}
30
31//static
32void HalDeathHandler::OnBinderDied(void*) {
33 ALOGE("HAL instance died, audio server is restarting");
34 _exit(1); // Avoid calling atexit handlers, as this code runs on a thread from RPC threadpool.
35}
36
37HalDeathHandler::HalDeathHandler()
38 : mDeathRecipient(AIBinder_DeathRecipient_new(OnBinderDied)) {}
39
40bool HalDeathHandler::registerHandler(AIBinder* binder) {
41 binder_status_t status = AIBinder_linkToDeath(binder, mDeathRecipient.get(), nullptr);
42 if (status == STATUS_OK) return true;
43 ALOGE("%s: linkToDeath failed: %d", __func__, status);
44 return false;
45}
46
47} // namespace android