Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 83c0446f authored by Mathias Agopian's avatar Mathias Agopian
Browse files

some work to try to reduce the code size of some native libraries

- make sure that all binder Bn classes define a ctor and dtor in their respective library.
  This avoids duplication of the ctor/dtor in libraries where these objects are instantiated.
  This is also cleaner, should we want these ctor/dtor to do something one day.

- same change as above for some Bp classes and various other non-binder classes

- moved the definition of CHECK_INTERFACE() in IInterface.h instead of having it everywhere.

- improved the CHECK_INTERFACE() macro so it calls a single method in Parcel, instead of inlining its code everywhere

- IBinder::getInterfaceDescriptor() now returns a "const String16&" instead of String16, which saves calls to String16 and ~String16

- implemented a cache for BpBinder::getInterfaceDescriptor(), since this does an IPC. HOWEVER, this method never seems to be called.
  The cache makes BpBinder bigger, so we need to figure out if we need this method at all.
parent 5f239748
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -1052,12 +1052,6 @@ status_t CameraService::dump(int fd, const Vector<String16>& args)
}


#define CHECK_INTERFACE(interface, data, reply) \
        do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
            LOGW("Call incorrectly routed to " #interface); \
            return PERMISSION_DENIED; \
        } } while (0)

status_t CameraService::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
+2 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class BBinder : public IBinder
public:
                        BBinder();

    virtual String16    getInterfaceDescriptor() const;
    virtual const String16& getInterfaceDescriptor() const;
    virtual bool        isBinderAlive() const;
    virtual status_t    pingBinder();
    virtual status_t    dump(int fd, const Vector<String16>& args);
@@ -71,6 +71,7 @@ private:

            Extras*     mExtras;
            void*       mReserved0;
    static  String16    sEmptyDescriptor;
};

// ---------------------------------------------------------------------------
+3 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ public:

    inline  int32_t     handle() const { return mHandle; }

    virtual String16    getInterfaceDescriptor() const;
    virtual const String16&    getInterfaceDescriptor() const;
    virtual bool        isBinderAlive() const;
    virtual status_t    pingBinder();
    virtual status_t    dump(int fd, const Vector<String16>& args);
@@ -106,6 +106,7 @@ private:
    };

            void                reportOneDeath(const Obituary& obit);
            bool                isDescriptorCached() const;

    mutable Mutex               mLock;
            volatile int32_t    mAlive;
@@ -113,6 +114,7 @@ private:
            Vector<Obituary>*   mObituaries;
            ObjectManager       mObjects;
            Parcel*             mConstantData;
    mutable String16            mDescriptorCache;
};

}; // namespace android
+3 −3
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public:
        FLAG_ONEWAY             = 0x00000001
    };

    inline                  IBinder() { }
                          IBinder();

    /**
     * Check if this IBinder implements the interface named by
@@ -69,7 +69,7 @@ public:
     * Return the canonical name of the interface provided by this IBinder
     * object.
     */
    virtual String16        getInterfaceDescriptor() const = 0;
    virtual const String16& getInterfaceDescriptor() const = 0;

    virtual bool            isBinderAlive() const = 0;
    virtual status_t        pingBinder() = 0;
@@ -147,7 +147,7 @@ public:
    virtual BpBinder*       remoteBinder();

protected:
    inline virtual          ~IBinder() { }
    virtual          ~IBinder();

private:
};
+18 −6
Original line number Diff line number Diff line
@@ -27,10 +27,12 @@ namespace android {
class IInterface : public virtual RefBase
{
public:
            IInterface();
            sp<IBinder>         asBinder();
            sp<const IBinder>   asBinder() const;
            
protected:
    virtual                     ~IInterface();
    virtual IBinder*            onAsBinder() = 0;
};

@@ -49,7 +51,7 @@ class BnInterface : public INTERFACE, public BBinder
{
public:
    virtual sp<IInterface>      queryLocalInterface(const String16& _descriptor);
    virtual String16            getInterfaceDescriptor() const;
    virtual const String16&     getInterfaceDescriptor() const;

protected:
    virtual IBinder*            onAsBinder();
@@ -72,11 +74,14 @@ protected:
#define DECLARE_META_INTERFACE(INTERFACE)                               \
    static const String16 descriptor;                                   \
    static sp<I##INTERFACE> asInterface(const sp<IBinder>& obj);        \
    virtual String16 getInterfaceDescriptor() const;                    \
    virtual const String16& getInterfaceDescriptor() const;             \
    I##INTERFACE();                                                     \
    virtual ~I##INTERFACE();                                            \


#define IMPLEMENT_META_INTERFACE(INTERFACE, NAME)                       \
    const String16 I##INTERFACE::descriptor(NAME);                      \
    String16 I##INTERFACE::getInterfaceDescriptor() const {             \
    const String16& I##INTERFACE::getInterfaceDescriptor() const {      \
        return I##INTERFACE::descriptor;                                \
    }                                                                   \
    sp<I##INTERFACE> I##INTERFACE::asInterface(const sp<IBinder>& obj)  \
@@ -92,9 +97,16 @@ protected:
        }                                                               \
        return intr;                                                    \
    }                                                                   \
    I##INTERFACE::I##INTERFACE() { }                                    \
    I##INTERFACE::~I##INTERFACE() { }                                   \


#define CHECK_INTERFACE(interface, data, reply)                         \
    if (!data.checkInterface(this)) { return PERMISSION_DENIED; }       \


// ----------------------------------------------------------------------
// No user-servicable parts after this...
// No user-serviceable parts after this...

template<typename INTERFACE>
inline sp<IInterface> BnInterface<INTERFACE>::queryLocalInterface(
@@ -105,7 +117,7 @@ inline sp<IInterface> BnInterface<INTERFACE>::queryLocalInterface(
}

template<typename INTERFACE>
inline String16 BnInterface<INTERFACE>::getInterfaceDescriptor() const
inline const String16& BnInterface<INTERFACE>::getInterfaceDescriptor() const
{
    return INTERFACE::getInterfaceDescriptor();
}
Loading