1 /*
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
22 namespace android {
23
24 //static
getInstance()25 HalDeathHandler& HalDeathHandler::getInstance() {
26 // never-delete singleton
27 static HalDeathHandler* instance = new HalDeathHandler;
28 return *instance;
29 }
30
31 //static
OnBinderDied(void *)32 void 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
HalDeathHandler()37 HalDeathHandler::HalDeathHandler()
38 : mDeathRecipient(AIBinder_DeathRecipient_new(OnBinderDied)) {}
39
registerHandler(AIBinder * binder)40 bool 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
48