Home | History | Annotate | Download | only in binder
      1 /*
      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 
     17 #ifndef ANDROID_BINDER_H
     18 #define ANDROID_BINDER_H
     19 
     20 #include <atomic>
     21 #include <stdint.h>
     22 #include <binder/IBinder.h>
     23 
     24 // ---------------------------------------------------------------------------
     25 namespace android {
     26 
     27 class BBinder : public IBinder
     28 {
     29 public:
     30                         BBinder();
     31 
     32     virtual const String16& getInterfaceDescriptor() const;
     33     virtual bool        isBinderAlive() const;
     34     virtual status_t    pingBinder();
     35     virtual status_t    dump(int fd, const Vector<String16>& args);
     36 
     37     // NOLINTNEXTLINE(google-default-arguments)
     38     virtual status_t    transact(   uint32_t code,
     39                                     const Parcel& data,
     40                                     Parcel* reply,
     41                                     uint32_t flags = 0);
     42 
     43     // NOLINTNEXTLINE(google-default-arguments)
     44     virtual status_t    linkToDeath(const sp<DeathRecipient>& recipient,
     45                                     void* cookie = nullptr,
     46                                     uint32_t flags = 0);
     47 
     48     // NOLINTNEXTLINE(google-default-arguments)
     49     virtual status_t    unlinkToDeath(  const wp<DeathRecipient>& recipient,
     50                                         void* cookie = nullptr,
     51                                         uint32_t flags = 0,
     52                                         wp<DeathRecipient>* outRecipient = nullptr);
     53 
     54     virtual void        attachObject(   const void* objectID,
     55                                         void* object,
     56                                         void* cleanupCookie,
     57                                         object_cleanup_func func);
     58     virtual void*       findObject(const void* objectID) const;
     59     virtual void        detachObject(const void* objectID);
     60 
     61     virtual BBinder*    localBinder();
     62 
     63     bool                isRequestingSid();
     64     // This must be called before the object is sent to another process. Not thread safe.
     65     void                setRequestingSid(bool requestSid);
     66 
     67 protected:
     68     virtual             ~BBinder();
     69 
     70     // NOLINTNEXTLINE(google-default-arguments)
     71     virtual status_t    onTransact( uint32_t code,
     72                                     const Parcel& data,
     73                                     Parcel* reply,
     74                                     uint32_t flags = 0);
     75 
     76 private:
     77                         BBinder(const BBinder& o);
     78             BBinder&    operator=(const BBinder& o);
     79 
     80     class Extras;
     81 
     82     Extras*             getOrCreateExtras();
     83 
     84     std::atomic<Extras*> mExtras;
     85             void*       mReserved0;
     86 };
     87 
     88 // ---------------------------------------------------------------------------
     89 
     90 class BpRefBase : public virtual RefBase
     91 {
     92 protected:
     93     explicit                BpRefBase(const sp<IBinder>& o);
     94     virtual                 ~BpRefBase();
     95     virtual void            onFirstRef();
     96     virtual void            onLastStrongRef(const void* id);
     97     virtual bool            onIncStrongAttempted(uint32_t flags, const void* id);
     98 
     99     inline  IBinder*        remote()                { return mRemote; }
    100     inline  IBinder*        remote() const          { return mRemote; }
    101 
    102 private:
    103                             BpRefBase(const BpRefBase& o);
    104     BpRefBase&              operator=(const BpRefBase& o);
    105 
    106     IBinder* const          mRemote;
    107     RefBase::weakref_type*  mRefs;
    108     std::atomic<int32_t>    mState;
    109 };
    110 
    111 }; // namespace android
    112 
    113 // ---------------------------------------------------------------------------
    114 
    115 #endif // ANDROID_BINDER_H
    116