xref: /aosp_15_r20/frameworks/av/media/libmediaplayerservice/DeathRecipient.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1*ec779b8eSAndroid Build Coastguard Worker /*
2*ec779b8eSAndroid Build Coastguard Worker  * Copyright 2019 The Android Open Source Project
3*ec779b8eSAndroid Build Coastguard Worker  *
4*ec779b8eSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*ec779b8eSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*ec779b8eSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*ec779b8eSAndroid Build Coastguard Worker  *
8*ec779b8eSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*ec779b8eSAndroid Build Coastguard Worker  *
10*ec779b8eSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*ec779b8eSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*ec779b8eSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*ec779b8eSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*ec779b8eSAndroid Build Coastguard Worker  * limitations under the License.
15*ec779b8eSAndroid Build Coastguard Worker  */
16*ec779b8eSAndroid Build Coastguard Worker 
17*ec779b8eSAndroid Build Coastguard Worker #ifndef ANDROID_MEDIASERVICE_DEATHRECIPIENT_H
18*ec779b8eSAndroid Build Coastguard Worker #define ANDROID_MEDIASERVICE_DEATHRECIPIENT_H
19*ec779b8eSAndroid Build Coastguard Worker 
20*ec779b8eSAndroid Build Coastguard Worker #include <binder/binder.h>
21*ec779b8eSAndroid Build Coastguard Worker #include <hidl/HidlSupport.h>
22*ec779b8eSAndroid Build Coastguard Worker 
23*ec779b8eSAndroid Build Coastguard Worker #include <variant>
24*ec779b8eSAndroid Build Coastguard Worker 
25*ec779b8eSAndroid Build Coastguard Worker class DeathNotifier :
26*ec779b8eSAndroid Build Coastguard Worker         public IBinder::DeathRecipient,
27*ec779b8eSAndroid Build Coastguard Worker         public ::android::hardware::hidl_death_recipient {
28*ec779b8eSAndroid Build Coastguard Worker public:
29*ec779b8eSAndroid Build Coastguard Worker     using Service = std::variant<
30*ec779b8eSAndroid Build Coastguard Worker             sp<IBinder> const&,
31*ec779b8eSAndroid Build Coastguard Worker             sp<android::hidl::base::V1_0::IBase> const&>;
32*ec779b8eSAndroid Build Coastguard Worker 
33*ec779b8eSAndroid Build Coastguard Worker     DeathNotifier(std::variant<sp<IBinder> const&,
34*ec779b8eSAndroid Build Coastguard Worker             const sp<IBinder>& service,
35*ec779b8eSAndroid Build Coastguard Worker             const sp<MediaPlayerBase>& listener,
36*ec779b8eSAndroid Build Coastguard Worker             int which,
37*ec779b8eSAndroid Build Coastguard Worker             const std::string& name);
38*ec779b8eSAndroid Build Coastguard Worker     DeathNotifier(
39*ec779b8eSAndroid Build Coastguard Worker             const sp<android::hidl::base::V1_0::IBase>& hService,
40*ec779b8eSAndroid Build Coastguard Worker             const sp<MediaPlayerBase>& listener,
41*ec779b8eSAndroid Build Coastguard Worker             int which,
42*ec779b8eSAndroid Build Coastguard Worker             const std::string& name);
43*ec779b8eSAndroid Build Coastguard Worker     virtual ~DeathNotifier() = default;
44*ec779b8eSAndroid Build Coastguard Worker     virtual void binderDied(const wp<IBinder>& who);
45*ec779b8eSAndroid Build Coastguard Worker     virtual void serviceDied(
46*ec779b8eSAndroid Build Coastguard Worker             uint64_t cookie,
47*ec779b8eSAndroid Build Coastguard Worker             const wp<::android::hidl::base::V1_0::IBase>& who);
48*ec779b8eSAndroid Build Coastguard Worker     void unlinkToDeath();
49*ec779b8eSAndroid Build Coastguard Worker 
50*ec779b8eSAndroid Build Coastguard Worker private:
51*ec779b8eSAndroid Build Coastguard Worker     sp<IBinder> mService;
52*ec779b8eSAndroid Build Coastguard Worker     sp<android::hidl::base::V1_0::IBase> mHService; // HIDL service
53*ec779b8eSAndroid Build Coastguard Worker     wp<MediaPlayerBase> mListener;
54*ec779b8eSAndroid Build Coastguard Worker     int mWhich;
55*ec779b8eSAndroid Build Coastguard Worker     std::string mName;
56*ec779b8eSAndroid Build Coastguard Worker };
57*ec779b8eSAndroid Build Coastguard Worker 
58*ec779b8eSAndroid Build Coastguard Worker #endif // ANDROID_MEDIASERVICE_DEATHRECIPIENT_H
59*ec779b8eSAndroid Build Coastguard Worker 
60