blob: d05c6ffa98e9d1cae5d3c5ba305021f81bb76335 [file] [log] [blame]
Mathias Agopian16475702009-05-19 19:08:10 -07001/*
2 * Copyright (C) 2008 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
Martijn Coenenf75a23d2016-08-01 11:55:17 +020017#ifndef ANDROID_HARDWARE_BINDER_H
18#define ANDROID_HARDWARE_BINDER_H
Mathias Agopian16475702009-05-19 19:08:10 -070019
Bailey Forreste20d6f42015-08-18 17:15:10 -070020#include <atomic>
Hans Boehm99c620a2014-08-12 22:56:00 +000021#include <stdint.h>
Martijn Coenen4080edc2016-05-04 14:17:02 +020022#include <hwbinder/IBinder.h>
Mathias Agopian16475702009-05-19 19:08:10 -070023
Steven Morelandb5f6e002021-02-26 01:51:20 +000024// WARNING: this code is part of libhwbinder, a fork of libbinder. Generally,
25// this means that it is only relevant to HIDL. Any AIDL- or libbinder-specific
26// code should not try to use these things.
27
Mathias Agopian16475702009-05-19 19:08:10 -070028// ---------------------------------------------------------------------------
29namespace android {
Martijn Coenenf75a23d2016-08-01 11:55:17 +020030namespace hardware {
Mathias Agopian16475702009-05-19 19:08:10 -070031
Yifan Hongdde40f32017-01-12 14:22:45 -080032class BHwBinder : public IBinder
Mathias Agopian16475702009-05-19 19:08:10 -070033{
34public:
Yifan Hongdde40f32017-01-12 14:22:45 -080035 BHwBinder();
Mathias Agopian16475702009-05-19 19:08:10 -070036
Mathias Agopian16475702009-05-19 19:08:10 -070037 virtual status_t transact( uint32_t code,
38 const Parcel& data,
39 Parcel* reply,
Martijn Coenen79c2f4d2016-05-20 10:55:59 +020040 uint32_t flags = 0,
41 TransactCallback callback = nullptr);
Mathias Agopian16475702009-05-19 19:08:10 -070042
43 virtual status_t linkToDeath(const sp<DeathRecipient>& recipient,
Yi Kong55d41072018-07-23 14:55:39 -070044 void* cookie = nullptr,
Mathias Agopian16475702009-05-19 19:08:10 -070045 uint32_t flags = 0);
46
47 virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient,
Yi Kong55d41072018-07-23 14:55:39 -070048 void* cookie = nullptr,
Mathias Agopian16475702009-05-19 19:08:10 -070049 uint32_t flags = 0,
Yi Kong55d41072018-07-23 14:55:39 -070050 wp<DeathRecipient>* outRecipient = nullptr);
Mathias Agopian16475702009-05-19 19:08:10 -070051
52 virtual void attachObject( const void* objectID,
53 void* object,
54 void* cleanupCookie,
55 object_cleanup_func func);
56 virtual void* findObject(const void* objectID) const;
57 virtual void detachObject(const void* objectID);
58
Yifan Hongdde40f32017-01-12 14:22:45 -080059 virtual BHwBinder* localBinder();
Mathias Agopian16475702009-05-19 19:08:10 -070060
Martijn Coenen3f181282017-05-03 13:45:32 -070061 int getMinSchedulingPolicy();
62 int getMinSchedulingPriority();
Steven Moreland7375a872018-12-26 13:59:23 -080063
64 bool isRequestingSid();
65
Mathias Agopian16475702009-05-19 19:08:10 -070066protected:
Yifan Hongdde40f32017-01-12 14:22:45 -080067 virtual ~BHwBinder();
Mathias Agopian16475702009-05-19 19:08:10 -070068
69 virtual status_t onTransact( uint32_t code,
70 const Parcel& data,
71 Parcel* reply,
Martijn Coenen79c2f4d2016-05-20 10:55:59 +020072 uint32_t flags = 0,
73 TransactCallback callback = nullptr);
Steven Moreland7375a872018-12-26 13:59:23 -080074
75 // This must be called before the object is sent to another process. Not thread safe.
Steven Moreland8a3fd5a2020-07-07 23:03:12 +000076 //
77 // If this is called with true, and the kernel supports it,
78 // IPCThreadState::getCallingSid will return values for remote processes.
Steven Moreland7375a872018-12-26 13:59:23 -080079 void setRequestingSid(bool requestSid);
80
Martijn Coenen3f181282017-05-03 13:45:32 -070081 int mSchedPolicy; // policy to run transaction from this node at
82 // priority [-20..19] for SCHED_NORMAL, [1..99] for SCHED_FIFO/RT
83 int mSchedPriority;
Mathias Agopian16475702009-05-19 19:08:10 -070084private:
Yifan Hongdde40f32017-01-12 14:22:45 -080085 BHwBinder(const BHwBinder& o);
86 BHwBinder& operator=(const BHwBinder& o);
Mathias Agopian16475702009-05-19 19:08:10 -070087
88 class Extras;
89
Steven Moreland7375a872018-12-26 13:59:23 -080090 Extras* getOrCreateExtras();
91
Bailey Forreste20d6f42015-08-18 17:15:10 -070092 std::atomic<Extras*> mExtras;
Mathias Agopian16475702009-05-19 19:08:10 -070093 void* mReserved0;
Mathias Agopian16475702009-05-19 19:08:10 -070094};
95
96// ---------------------------------------------------------------------------
97
Yifan Honga2ce3b82017-01-12 14:49:26 -080098class BpHwRefBase : public virtual RefBase
Mathias Agopian16475702009-05-19 19:08:10 -070099{
100protected:
Chih-Hung Hsieh2ecdeaf2016-09-01 11:44:54 -0700101 explicit BpHwRefBase(const sp<IBinder>& o);
Yifan Honga2ce3b82017-01-12 14:49:26 -0800102 virtual ~BpHwRefBase();
Mathias Agopian16475702009-05-19 19:08:10 -0700103 virtual void onFirstRef();
104 virtual void onLastStrongRef(const void* id);
105 virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
106
Steven Moreland81dbdee2018-09-27 10:56:35 -0700107public:
Mathias Agopian16475702009-05-19 19:08:10 -0700108 inline IBinder* remote() const { return mRemote; }
109
110private:
Yifan Honga2ce3b82017-01-12 14:49:26 -0800111 BpHwRefBase(const BpHwRefBase& o);
112 BpHwRefBase& operator=(const BpHwRefBase& o);
Mathias Agopian16475702009-05-19 19:08:10 -0700113
114 IBinder* const mRemote;
115 RefBase::weakref_type* mRefs;
Bailey Forreste20d6f42015-08-18 17:15:10 -0700116 std::atomic<int32_t> mState;
Mathias Agopian16475702009-05-19 19:08:10 -0700117};
118
Steven Moreland7173a4c2019-09-26 15:55:02 -0700119} // namespace hardware
120} // namespace android
Mathias Agopian16475702009-05-19 19:08:10 -0700121
122// ---------------------------------------------------------------------------
123
Martijn Coenenf75a23d2016-08-01 11:55:17 +0200124#endif // ANDROID_HARDWARE_BINDER_H