From c5b2c0bf8007562536b822eb060fc54a01f8e08b Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 19 May 2009 19:08:10 -0700 Subject: move libbinder's header files under includes/binder --- camera/libcameraservice/CameraHardwareStub.h | 4 +- camera/libcameraservice/CameraService.cpp | 8 +- cmds/runtime/ServiceManager.cpp | 4 +- cmds/runtime/main_runtime.cpp | 4 +- cmds/surfaceflinger/main_surfaceflinger.cpp | 6 +- include/binder/Binder.h | 103 ++++++++++ include/binder/BpBinder.h | 122 ++++++++++++ include/binder/IBinder.h | 159 +++++++++++++++ include/binder/IInterface.h | 135 +++++++++++++ include/binder/IMemory.h | 94 +++++++++ include/binder/IPCThreadState.h | 110 +++++++++++ include/binder/IPermissionController.h | 56 ++++++ include/binder/IServiceManager.h | 98 ++++++++++ include/binder/MemoryBase.h | 51 +++++ include/binder/MemoryDealer.h | 238 +++++++++++++++++++++++ include/binder/MemoryHeapBase.h | 98 ++++++++++ include/binder/MemoryHeapPmem.h | 80 ++++++++ include/binder/Parcel.h | 209 ++++++++++++++++++++ include/binder/ProcessState.h | 117 +++++++++++ include/private/binder/Static.h | 10 +- include/private/utils/Static.h | 26 --- include/ui/CameraHardwareInterface.h | 2 +- include/ui/ICamera.h | 6 +- include/ui/ICameraClient.h | 6 +- include/ui/ICameraService.h | 4 +- include/ui/IOverlay.h | 2 +- include/ui/ISurface.h | 2 +- include/ui/ISurfaceComposer.h | 2 +- include/ui/ISurfaceFlingerClient.h | 2 +- include/ui/Overlay.h | 2 +- include/ui/Region.h | 2 +- include/utils/Binder.h | 103 ---------- include/utils/BpBinder.h | 122 ------------ include/utils/IBinder.h | 159 --------------- include/utils/IInterface.h | 135 ------------- include/utils/IMemory.h | 94 --------- include/utils/IPCThreadState.h | 110 ----------- include/utils/IPermissionController.h | 56 ------ include/utils/IServiceManager.h | 98 ---------- include/utils/MemoryBase.h | 51 ----- include/utils/MemoryDealer.h | 238 ----------------------- include/utils/MemoryHeapBase.h | 98 ---------- include/utils/MemoryHeapPmem.h | 80 -------- include/utils/Parcel.h | 209 -------------------- include/utils/ProcessState.h | 117 ----------- libs/audioflinger/AudioFlinger.cpp | 6 +- libs/audioflinger/AudioFlinger.h | 2 +- libs/binder/Binder.cpp | 8 +- libs/binder/BpBinder.cpp | 4 +- libs/binder/IDataConnection.cpp | 89 --------- libs/binder/IInterface.cpp | 2 +- libs/binder/IMemory.cpp | 4 +- libs/binder/IPCThreadState.cpp | 6 +- libs/binder/IPermissionController.cpp | 4 +- libs/binder/IServiceManager.cpp | 6 +- libs/binder/MemoryBase.cpp | 2 +- libs/binder/MemoryDealer.cpp | 6 +- libs/binder/MemoryHeapBase.cpp | 2 +- libs/binder/MemoryHeapPmem.cpp | 4 +- libs/binder/Parcel.cpp | 8 +- libs/binder/ProcessState.cpp | 8 +- libs/binder/Static.cpp | 2 +- libs/surfaceflinger/GPUHardware/GPUHardware.cpp | 12 +- libs/surfaceflinger/LayerBitmap.cpp | 4 +- libs/surfaceflinger/LayerBuffer.cpp | 4 +- libs/surfaceflinger/LayerBuffer.h | 2 +- libs/surfaceflinger/LayerOrientationAnim.h | 2 +- libs/surfaceflinger/LayerOrientationAnimRotate.h | 2 +- libs/surfaceflinger/SurfaceFlinger.cpp | 8 +- libs/surfaceflinger/SurfaceFlinger.h | 2 +- libs/surfaceflinger/VRamHeap.cpp | 8 +- libs/surfaceflinger/VRamHeap.h | 2 +- libs/surfaceflinger/tests/overlays/overlays.cpp | 6 +- libs/ui/Camera.cpp | 4 +- libs/ui/EventHub.cpp | 1 - libs/ui/ICamera.cpp | 2 +- libs/ui/ICameraService.cpp | 6 +- libs/ui/IOverlay.cpp | 4 +- libs/ui/ISurface.cpp | 4 +- libs/ui/ISurfaceComposer.cpp | 8 +- libs/ui/ISurfaceFlingerClient.cpp | 8 +- libs/ui/LayerState.cpp | 2 +- libs/ui/Overlay.cpp | 6 +- libs/ui/Surface.cpp | 4 +- libs/ui/SurfaceComposerClient.cpp | 8 +- libs/ui/SurfaceFlingerSynchro.cpp | 2 +- opengl/libs/EGL/gpu.cpp | 8 +- 87 files changed, 1799 insertions(+), 1915 deletions(-) create mode 100644 include/binder/Binder.h create mode 100644 include/binder/BpBinder.h create mode 100644 include/binder/IBinder.h create mode 100644 include/binder/IInterface.h create mode 100644 include/binder/IMemory.h create mode 100644 include/binder/IPCThreadState.h create mode 100644 include/binder/IPermissionController.h create mode 100644 include/binder/IServiceManager.h create mode 100644 include/binder/MemoryBase.h create mode 100644 include/binder/MemoryDealer.h create mode 100644 include/binder/MemoryHeapBase.h create mode 100644 include/binder/MemoryHeapPmem.h create mode 100644 include/binder/Parcel.h create mode 100644 include/binder/ProcessState.h delete mode 100644 include/utils/Binder.h delete mode 100644 include/utils/BpBinder.h delete mode 100644 include/utils/IBinder.h delete mode 100644 include/utils/IInterface.h delete mode 100644 include/utils/IMemory.h delete mode 100644 include/utils/IPCThreadState.h delete mode 100644 include/utils/IPermissionController.h delete mode 100644 include/utils/IServiceManager.h delete mode 100644 include/utils/MemoryBase.h delete mode 100644 include/utils/MemoryDealer.h delete mode 100644 include/utils/MemoryHeapBase.h delete mode 100644 include/utils/MemoryHeapPmem.h delete mode 100644 include/utils/Parcel.h delete mode 100644 include/utils/ProcessState.h delete mode 100644 libs/binder/IDataConnection.cpp diff --git a/camera/libcameraservice/CameraHardwareStub.h b/camera/libcameraservice/CameraHardwareStub.h index 0d26d47..efae935 100644 --- a/camera/libcameraservice/CameraHardwareStub.h +++ b/camera/libcameraservice/CameraHardwareStub.h @@ -21,8 +21,8 @@ #include "FakeCamera.h" #include #include -#include -#include +#include +#include #include namespace android { diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index f85ea9f..4f0fe21 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -20,12 +20,12 @@ #define LOG_TAG "CameraService" #include -#include -#include +#include +#include #include #include -#include -#include +#include +#include #include #include diff --git a/cmds/runtime/ServiceManager.cpp b/cmds/runtime/ServiceManager.cpp index 758a95c..b2bef07 100644 --- a/cmds/runtime/ServiceManager.cpp +++ b/cmds/runtime/ServiceManager.cpp @@ -9,9 +9,9 @@ #include #include -#include +#include #include -#include +#include #include diff --git a/cmds/runtime/main_runtime.cpp b/cmds/runtime/main_runtime.cpp index 1531a9e..718ea67 100644 --- a/cmds/runtime/main_runtime.cpp +++ b/cmds/runtime/main_runtime.cpp @@ -8,8 +8,8 @@ #include "SignalHandler.h" #include -#include -#include +#include +#include #include #include diff --git a/cmds/surfaceflinger/main_surfaceflinger.cpp b/cmds/surfaceflinger/main_surfaceflinger.cpp index 7c89578..d650721 100644 --- a/cmds/surfaceflinger/main_surfaceflinger.cpp +++ b/cmds/surfaceflinger/main_surfaceflinger.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include #include diff --git a/include/binder/Binder.h b/include/binder/Binder.h new file mode 100644 index 0000000..c9b71fd --- /dev/null +++ b/include/binder/Binder.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_BINDER_H +#define ANDROID_BINDER_H + +#include + +// --------------------------------------------------------------------------- +namespace android { + +class BBinder : public IBinder +{ +public: + BBinder(); + + virtual String16 getInterfaceDescriptor() const; + virtual bool isBinderAlive() const; + virtual status_t pingBinder(); + virtual status_t dump(int fd, const Vector& args); + + virtual status_t transact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); + + virtual status_t linkToDeath(const sp& recipient, + void* cookie = NULL, + uint32_t flags = 0); + + virtual status_t unlinkToDeath( const wp& recipient, + void* cookie = NULL, + uint32_t flags = 0, + wp* outRecipient = NULL); + + virtual void attachObject( const void* objectID, + void* object, + void* cleanupCookie, + object_cleanup_func func); + virtual void* findObject(const void* objectID) const; + virtual void detachObject(const void* objectID); + + virtual BBinder* localBinder(); + +protected: + virtual ~BBinder(); + + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); + +private: + BBinder(const BBinder& o); + BBinder& operator=(const BBinder& o); + + class Extras; + + Extras* mExtras; + void* mReserved0; +}; + +// --------------------------------------------------------------------------- + +class BpRefBase : public virtual RefBase +{ +protected: + BpRefBase(const sp& o); + virtual ~BpRefBase(); + virtual void onFirstRef(); + virtual void onLastStrongRef(const void* id); + virtual bool onIncStrongAttempted(uint32_t flags, const void* id); + + inline IBinder* remote() { return mRemote; } + inline IBinder* remote() const { return mRemote; } + +private: + BpRefBase(const BpRefBase& o); + BpRefBase& operator=(const BpRefBase& o); + + IBinder* const mRemote; + RefBase::weakref_type* mRefs; + volatile int32_t mState; +}; + +}; // namespace android + +// --------------------------------------------------------------------------- + +#endif // ANDROID_BINDER_H diff --git a/include/binder/BpBinder.h b/include/binder/BpBinder.h new file mode 100644 index 0000000..067637e --- /dev/null +++ b/include/binder/BpBinder.h @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_BPBINDER_H +#define ANDROID_BPBINDER_H + +#include +#include +#include + +// --------------------------------------------------------------------------- +namespace android { + +class BpBinder : public IBinder +{ +public: + BpBinder(int32_t handle); + + inline int32_t handle() const { return mHandle; } + + virtual String16 getInterfaceDescriptor() const; + virtual bool isBinderAlive() const; + virtual status_t pingBinder(); + virtual status_t dump(int fd, const Vector& args); + + virtual status_t transact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); + + virtual status_t linkToDeath(const sp& recipient, + void* cookie = NULL, + uint32_t flags = 0); + virtual status_t unlinkToDeath( const wp& recipient, + void* cookie = NULL, + uint32_t flags = 0, + wp* outRecipient = NULL); + + virtual void attachObject( const void* objectID, + void* object, + void* cleanupCookie, + object_cleanup_func func); + virtual void* findObject(const void* objectID) const; + virtual void detachObject(const void* objectID); + + virtual BpBinder* remoteBinder(); + + status_t setConstantData(const void* data, size_t size); + void sendObituary(); + + class ObjectManager + { + public: + ObjectManager(); + ~ObjectManager(); + + void attach( const void* objectID, + void* object, + void* cleanupCookie, + IBinder::object_cleanup_func func); + void* find(const void* objectID) const; + void detach(const void* objectID); + + void kill(); + + private: + ObjectManager(const ObjectManager&); + ObjectManager& operator=(const ObjectManager&); + + struct entry_t + { + void* object; + void* cleanupCookie; + IBinder::object_cleanup_func func; + }; + + KeyedVector mObjects; + }; + +protected: + virtual ~BpBinder(); + virtual void onFirstRef(); + virtual void onLastStrongRef(const void* id); + virtual bool onIncStrongAttempted(uint32_t flags, const void* id); + +private: + const int32_t mHandle; + + struct Obituary { + wp recipient; + void* cookie; + uint32_t flags; + }; + + void reportOneDeath(const Obituary& obit); + + mutable Mutex mLock; + volatile int32_t mAlive; + volatile int32_t mObitsSent; + Vector* mObituaries; + ObjectManager mObjects; + Parcel* mConstantData; +}; + +}; // namespace android + +// --------------------------------------------------------------------------- + +#endif // ANDROID_BPBINDER_H diff --git a/include/binder/IBinder.h b/include/binder/IBinder.h new file mode 100644 index 0000000..7370330 --- /dev/null +++ b/include/binder/IBinder.h @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_IBINDER_H +#define ANDROID_IBINDER_H + +#include +#include +#include +#include + + +#define B_PACK_CHARS(c1, c2, c3, c4) \ + ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4)) + +// --------------------------------------------------------------------------- +namespace android { + +class BBinder; +class BpBinder; +class IInterface; +class Parcel; + +/** + * Base class and low-level protocol for a remotable object. + * You can derive from this class to create an object for which other + * processes can hold references to it. Communication between processes + * (method calls, property get and set) is down through a low-level + * protocol implemented on top of the transact() API. + */ +class IBinder : public virtual RefBase +{ +public: + enum { + FIRST_CALL_TRANSACTION = 0x00000001, + LAST_CALL_TRANSACTION = 0x00ffffff, + + PING_TRANSACTION = B_PACK_CHARS('_','P','N','G'), + DUMP_TRANSACTION = B_PACK_CHARS('_','D','M','P'), + INTERFACE_TRANSACTION = B_PACK_CHARS('_', 'N', 'T', 'F'), + + // Corresponds to tfOneWay -- an asynchronous call. + FLAG_ONEWAY = 0x00000001 + }; + + inline IBinder() { } + + /** + * Check if this IBinder implements the interface named by + * @a descriptor. If it does, the base pointer to it is returned, + * which you can safely static_cast<> to the concrete C++ interface. + */ + virtual sp queryLocalInterface(const String16& descriptor); + + /** + * Return the canonical name of the interface provided by this IBinder + * object. + */ + virtual String16 getInterfaceDescriptor() const = 0; + + virtual bool isBinderAlive() const = 0; + virtual status_t pingBinder() = 0; + virtual status_t dump(int fd, const Vector& args) = 0; + + virtual status_t transact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0) = 0; + + /** + * This method allows you to add data that is transported through + * IPC along with your IBinder pointer. When implementing a Binder + * object, override it to write your desired data in to @a outData. + * You can then call getConstantData() on your IBinder to retrieve + * that data, from any process. You MUST return the number of bytes + * written in to the parcel (including padding). + */ + class DeathRecipient : public virtual RefBase + { + public: + virtual void binderDied(const wp& who) = 0; + }; + + /** + * Register the @a recipient for a notification if this binder + * goes away. If this binder object unexpectedly goes away + * (typically because its hosting process has been killed), + * then DeathRecipient::binderDied() will be called with a referene + * to this. + * + * The @a cookie is optional -- if non-NULL, it should be a + * memory address that you own (that is, you know it is unique). + * + * @note You will only receive death notifications for remote binders, + * as local binders by definition can't die without you dying as well. + * Trying to use this function on a local binder will result in an + * INVALID_OPERATION code being returned and nothing happening. + * + * @note This link always holds a weak reference to its recipient. + * + * @note You will only receive a weak reference to the dead + * binder. You should not try to promote this to a strong reference. + * (Nor should you need to, as there is nothing useful you can + * directly do with it now that it has passed on.) + */ + virtual status_t linkToDeath(const sp& recipient, + void* cookie = NULL, + uint32_t flags = 0) = 0; + + /** + * Remove a previously registered death notification. + * The @a recipient will no longer be called if this object + * dies. The @a cookie is optional. If non-NULL, you can + * supply a NULL @a recipient, and the recipient previously + * added with that cookie will be unlinked. + */ + virtual status_t unlinkToDeath( const wp& recipient, + void* cookie = NULL, + uint32_t flags = 0, + wp* outRecipient = NULL) = 0; + + virtual bool checkSubclass(const void* subclassID) const; + + typedef void (*object_cleanup_func)(const void* id, void* obj, void* cleanupCookie); + + virtual void attachObject( const void* objectID, + void* object, + void* cleanupCookie, + object_cleanup_func func) = 0; + virtual void* findObject(const void* objectID) const = 0; + virtual void detachObject(const void* objectID) = 0; + + virtual BBinder* localBinder(); + virtual BpBinder* remoteBinder(); + +protected: + inline virtual ~IBinder() { } + +private: +}; + +}; // namespace android + +// --------------------------------------------------------------------------- + +#endif // ANDROID_IBINDER_H diff --git a/include/binder/IInterface.h b/include/binder/IInterface.h new file mode 100644 index 0000000..3b1e33b --- /dev/null +++ b/include/binder/IInterface.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +#ifndef ANDROID_IINTERFACE_H +#define ANDROID_IINTERFACE_H + +#include + +namespace android { + +// ---------------------------------------------------------------------- + +class IInterface : public virtual RefBase +{ +public: + sp asBinder(); + sp asBinder() const; + +protected: + virtual IBinder* onAsBinder() = 0; +}; + +// ---------------------------------------------------------------------- + +template +inline sp interface_cast(const sp& obj) +{ + return INTERFACE::asInterface(obj); +} + +// ---------------------------------------------------------------------- + +template +class BnInterface : public INTERFACE, public BBinder +{ +public: + virtual sp queryLocalInterface(const String16& _descriptor); + virtual String16 getInterfaceDescriptor() const; + +protected: + virtual IBinder* onAsBinder(); +}; + +// ---------------------------------------------------------------------- + +template +class BpInterface : public INTERFACE, public BpRefBase +{ +public: + BpInterface(const sp& remote); + +protected: + virtual IBinder* onAsBinder(); +}; + +// ---------------------------------------------------------------------- + +#define DECLARE_META_INTERFACE(INTERFACE) \ + static const String16 descriptor; \ + static sp asInterface(const sp& obj); \ + virtual String16 getInterfaceDescriptor() const; \ + +#define IMPLEMENT_META_INTERFACE(INTERFACE, NAME) \ + const String16 I##INTERFACE::descriptor(NAME); \ + String16 I##INTERFACE::getInterfaceDescriptor() const { \ + return I##INTERFACE::descriptor; \ + } \ + sp I##INTERFACE::asInterface(const sp& obj) \ + { \ + sp intr; \ + if (obj != NULL) { \ + intr = static_cast( \ + obj->queryLocalInterface( \ + I##INTERFACE::descriptor).get()); \ + if (intr == NULL) { \ + intr = new Bp##INTERFACE(obj); \ + } \ + } \ + return intr; \ + } \ + +// ---------------------------------------------------------------------- +// No user-servicable parts after this... + +template +inline sp BnInterface::queryLocalInterface( + const String16& _descriptor) +{ + if (_descriptor == INTERFACE::descriptor) return this; + return NULL; +} + +template +inline String16 BnInterface::getInterfaceDescriptor() const +{ + return INTERFACE::getInterfaceDescriptor(); +} + +template +IBinder* BnInterface::onAsBinder() +{ + return this; +} + +template +inline BpInterface::BpInterface(const sp& remote) + : BpRefBase(remote) +{ +} + +template +inline IBinder* BpInterface::onAsBinder() +{ + return remote(); +} + +// ---------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_IINTERFACE_H diff --git a/include/binder/IMemory.h b/include/binder/IMemory.h new file mode 100644 index 0000000..182792c --- /dev/null +++ b/include/binder/IMemory.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_IMEMORY_H +#define ANDROID_IMEMORY_H + +#include +#include +#include + +#include +#include +#include + +namespace android { + +// ---------------------------------------------------------------------------- + +class IMemoryHeap : public IInterface +{ +public: + DECLARE_META_INTERFACE(MemoryHeap); + + // flags returned by getFlags() + enum { + READ_ONLY = 0x00000001, + MAP_ONCE = 0x00000002 + }; + + virtual int getHeapID() const = 0; + virtual void* getBase() const = 0; + virtual size_t getSize() const = 0; + virtual uint32_t getFlags() const = 0; + + // these are there just for backward source compatibility + int32_t heapID() const { return getHeapID(); } + void* base() const { return getBase(); } + size_t virtualSize() const { return getSize(); } +}; + +class BnMemoryHeap : public BnInterface +{ +public: + virtual status_t onTransact( + uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- + +class IMemory : public IInterface +{ +public: + DECLARE_META_INTERFACE(Memory); + + virtual sp getMemory(ssize_t* offset=0, size_t* size=0) const = 0; + + // helpers + void* fastPointer(const sp& heap, ssize_t offset) const; + void* pointer() const; + size_t size() const; + ssize_t offset() const; +}; + +class BnMemory : public BnInterface +{ +public: + virtual status_t onTransact( + uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_IMEMORY_H diff --git a/include/binder/IPCThreadState.h b/include/binder/IPCThreadState.h new file mode 100644 index 0000000..78306b2 --- /dev/null +++ b/include/binder/IPCThreadState.h @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_IPC_THREAD_STATE_H +#define ANDROID_IPC_THREAD_STATE_H + +#include +#include +#include +#include + +#ifdef HAVE_WIN32_PROC +typedef int uid_t; +#endif + +// --------------------------------------------------------------------------- +namespace android { + +class IPCThreadState +{ +public: + static IPCThreadState* self(); + + sp process(); + + status_t clearLastError(); + + int getCallingPid(); + int getCallingUid(); + + int64_t clearCallingIdentity(); + void restoreCallingIdentity(int64_t token); + + void flushCommands(); + + void joinThreadPool(bool isMain = true); + + // Stop the local process. + void stopProcess(bool immediate = true); + + status_t transact(int32_t handle, + uint32_t code, const Parcel& data, + Parcel* reply, uint32_t flags); + + void incStrongHandle(int32_t handle); + void decStrongHandle(int32_t handle); + void incWeakHandle(int32_t handle); + void decWeakHandle(int32_t handle); + status_t attemptIncStrongHandle(int32_t handle); + static void expungeHandle(int32_t handle, IBinder* binder); + status_t requestDeathNotification( int32_t handle, + BpBinder* proxy); + status_t clearDeathNotification( int32_t handle, + BpBinder* proxy); + + static void shutdown(); + +private: + IPCThreadState(); + ~IPCThreadState(); + + status_t sendReply(const Parcel& reply, uint32_t flags); + status_t waitForResponse(Parcel *reply, + status_t *acquireResult=NULL); + status_t talkWithDriver(bool doReceive=true); + status_t writeTransactionData(int32_t cmd, + uint32_t binderFlags, + int32_t handle, + uint32_t code, + const Parcel& data, + status_t* statusBuffer); + status_t executeCommand(int32_t command); + + void clearCaller(); + + static void threadDestructor(void *st); + static void freeBuffer(Parcel* parcel, + const uint8_t* data, size_t dataSize, + const size_t* objects, size_t objectsSize, + void* cookie); + + const sp mProcess; + Vector mPendingStrongDerefs; + Vector mPendingWeakDerefs; + + Parcel mIn; + Parcel mOut; + status_t mLastError; + pid_t mCallingPid; + uid_t mCallingUid; +}; + +}; // namespace android + +// --------------------------------------------------------------------------- + +#endif // ANDROID_IPC_THREAD_STATE_H diff --git a/include/binder/IPermissionController.h b/include/binder/IPermissionController.h new file mode 100644 index 0000000..f9d371b --- /dev/null +++ b/include/binder/IPermissionController.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +#ifndef ANDROID_IPERMISSION_CONTROLLER_H +#define ANDROID_IPERMISSION_CONTROLLER_H + +#include + +namespace android { + +// ---------------------------------------------------------------------- + +class IPermissionController : public IInterface +{ +public: + DECLARE_META_INTERFACE(PermissionController); + + virtual bool checkPermission(const String16& permission, + int32_t pid, int32_t uid) = 0; + + enum { + CHECK_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + }; +}; + +// ---------------------------------------------------------------------- + +class BnPermissionController : public BnInterface +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_IPERMISSION_CONTROLLER_H + diff --git a/include/binder/IServiceManager.h b/include/binder/IServiceManager.h new file mode 100644 index 0000000..ea149dd --- /dev/null +++ b/include/binder/IServiceManager.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +#ifndef ANDROID_ISERVICE_MANAGER_H +#define ANDROID_ISERVICE_MANAGER_H + +#include +#include +#include +#include + +namespace android { + +// ---------------------------------------------------------------------- + +class IServiceManager : public IInterface +{ +public: + DECLARE_META_INTERFACE(ServiceManager); + + /** + * Retrieve an existing service, blocking for a few seconds + * if it doesn't yet exist. + */ + virtual sp getService( const String16& name) const = 0; + + /** + * Retrieve an existing service, non-blocking. + */ + virtual sp checkService( const String16& name) const = 0; + + /** + * Register a service. + */ + virtual status_t addService( const String16& name, + const sp& service) = 0; + + /** + * Return list of all existing services. + */ + virtual Vector listServices() = 0; + + enum { + GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, + CHECK_SERVICE_TRANSACTION, + ADD_SERVICE_TRANSACTION, + LIST_SERVICES_TRANSACTION, + }; +}; + +sp defaultServiceManager(); + +template +status_t getService(const String16& name, sp* outService) +{ + const sp sm = defaultServiceManager(); + if (sm != NULL) { + *outService = interface_cast(sm->getService(name)); + if ((*outService) != NULL) return NO_ERROR; + } + return NAME_NOT_FOUND; +} + +bool checkCallingPermission(const String16& permission); +bool checkCallingPermission(const String16& permission, + int32_t* outPid, int32_t* outUid); + +// ---------------------------------------------------------------------- + +class BnServiceManager : public BnInterface +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_ISERVICE_MANAGER_H + diff --git a/include/binder/MemoryBase.h b/include/binder/MemoryBase.h new file mode 100644 index 0000000..463e26d --- /dev/null +++ b/include/binder/MemoryBase.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_MEMORY_BASE_H +#define ANDROID_MEMORY_BASE_H + +#include +#include + +#include + + +namespace android { + +// --------------------------------------------------------------------------- + +class MemoryBase : public BnMemory +{ +public: + MemoryBase(const sp& heap, ssize_t offset, size_t size); + virtual ~MemoryBase(); + virtual sp getMemory(ssize_t* offset, size_t* size) const; + +protected: + size_t getSize() const { return mSize; } + ssize_t getOffset() const { return mOffset; } + const sp& getHeap() const { return mHeap; } + +private: + size_t mSize; + ssize_t mOffset; + sp mHeap; +}; + +// --------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_MEMORY_BASE_H diff --git a/include/binder/MemoryDealer.h b/include/binder/MemoryDealer.h new file mode 100644 index 0000000..097767f --- /dev/null +++ b/include/binder/MemoryDealer.h @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_MEMORY_DEALER_H +#define ANDROID_MEMORY_DEALER_H + + +#include +#include + +#include +#include +#include + +namespace android { +// ---------------------------------------------------------------------------- +class String8; + +/* + * interface for implementing a "heap". A heap basically provides + * the IMemoryHeap interface for cross-process sharing and the + * ability to map/unmap pages within the heap. + */ +class HeapInterface : public virtual BnMemoryHeap +{ +public: + // all values must be page-aligned + virtual sp mapMemory(size_t offset, size_t size) = 0; +}; + +// ---------------------------------------------------------------------------- + +/* + * interface for implementing an allocator. An allocator provides + * methods for allocating and freeing memory blocks and dumping + * its state. + */ +class AllocatorInterface : public RefBase +{ +public: + enum { + PAGE_ALIGNED = 0x00000001 + }; + + virtual size_t allocate(size_t size, uint32_t flags = 0) = 0; + virtual status_t deallocate(size_t offset) = 0; + virtual size_t size() const = 0; + virtual void dump(const char* what, uint32_t flags = 0) const = 0; + virtual void dump(String8& res, + const char* what, uint32_t flags = 0) const = 0; +}; + +// ---------------------------------------------------------------------------- + +/* + * concrete implementation of HeapInterface on top of mmap() + */ +class SharedHeap : public HeapInterface, public MemoryHeapBase +{ +public: + SharedHeap(size_t size, uint32_t flags = 0, char const * name = NULL); + virtual ~SharedHeap(); + virtual sp mapMemory(size_t offset, size_t size); +}; + +// ---------------------------------------------------------------------------- + +/* + * A simple templatized doubly linked-list implementation + */ + +template +class LinkedList +{ + NODE* mFirst; + NODE* mLast; + +public: + LinkedList() : mFirst(0), mLast(0) { } + bool isEmpty() const { return mFirst == 0; } + NODE const* head() const { return mFirst; } + NODE* head() { return mFirst; } + NODE const* tail() const { return mLast; } + NODE* tail() { return mLast; } + + void insertAfter(NODE* node, NODE* newNode) { + newNode->prev = node; + newNode->next = node->next; + if (node->next == 0) mLast = newNode; + else node->next->prev = newNode; + node->next = newNode; + } + + void insertBefore(NODE* node, NODE* newNode) { + newNode->prev = node->prev; + newNode->next = node; + if (node->prev == 0) mFirst = newNode; + else node->prev->next = newNode; + node->prev = newNode; + } + + void insertHead(NODE* newNode) { + if (mFirst == 0) { + mFirst = mLast = newNode; + newNode->prev = newNode->next = 0; + } else { + insertBefore(mFirst, newNode); + } + } + + void insertTail(NODE* newNode) { + if (mLast == 0) insertBeginning(newNode); + else insertAfter(mLast, newNode); + } + + NODE* remove(NODE* node) { + if (node->prev == 0) mFirst = node->next; + else node->prev->next = node->next; + if (node->next == 0) mLast = node->prev; + else node->next->prev = node->prev; + return node; + } +}; + + +/* + * concrete implementation of AllocatorInterface using a simple + * best-fit allocation scheme + */ +class SimpleBestFitAllocator : public AllocatorInterface +{ +public: + + SimpleBestFitAllocator(size_t size); + virtual ~SimpleBestFitAllocator(); + + virtual size_t allocate(size_t size, uint32_t flags = 0); + virtual status_t deallocate(size_t offset); + virtual size_t size() const; + virtual void dump(const char* what, uint32_t flags = 0) const; + virtual void dump(String8& res, + const char* what, uint32_t flags = 0) const; + +private: + + struct chunk_t { + chunk_t(size_t start, size_t size) + : start(start), size(size), free(1), prev(0), next(0) { + } + size_t start; + size_t size : 28; + int free : 4; + mutable chunk_t* prev; + mutable chunk_t* next; + }; + + ssize_t alloc(size_t size, uint32_t flags); + chunk_t* dealloc(size_t start); + void dump_l(const char* what, uint32_t flags = 0) const; + void dump_l(String8& res, const char* what, uint32_t flags = 0) const; + + static const int kMemoryAlign; + mutable Mutex mLock; + LinkedList mList; + size_t mHeapSize; +}; + +// ---------------------------------------------------------------------------- + +class MemoryDealer : public RefBase +{ +public: + + enum { + READ_ONLY = MemoryHeapBase::READ_ONLY, + PAGE_ALIGNED = AllocatorInterface::PAGE_ALIGNED + }; + + // creates a memory dealer with the SharedHeap and SimpleBestFitAllocator + MemoryDealer(size_t size, uint32_t flags = 0, const char* name = 0); + + // provide a custom heap but use the SimpleBestFitAllocator + MemoryDealer(const sp& heap); + + // provide both custom heap and allocotar + MemoryDealer( + const sp& heap, + const sp& allocator); + + virtual ~MemoryDealer(); + + virtual sp allocate(size_t size, uint32_t flags = 0); + virtual void deallocate(size_t offset); + virtual void dump(const char* what, uint32_t flags = 0) const; + + + sp getMemoryHeap() const { return heap(); } + sp getAllocator() const { return allocator(); } + +private: + const sp& heap() const; + const sp& allocator() const; + + class Allocation : public BnMemory { + public: + Allocation(const sp& dealer, + ssize_t offset, size_t size, const sp& memory); + virtual ~Allocation(); + virtual sp getMemory(ssize_t* offset, size_t* size) const; + private: + sp mDealer; + ssize_t mOffset; + size_t mSize; + sp mMemory; + }; + + sp mHeap; + sp mAllocator; +}; + + +// ---------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_MEMORY_DEALER_H diff --git a/include/binder/MemoryHeapBase.h b/include/binder/MemoryHeapBase.h new file mode 100644 index 0000000..83c7283 --- /dev/null +++ b/include/binder/MemoryHeapBase.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_MEMORY_HEAP_BASE_H +#define ANDROID_MEMORY_HEAP_BASE_H + +#include +#include + +#include + + +namespace android { + +// --------------------------------------------------------------------------- + +class MemoryHeapBase : public virtual BnMemoryHeap +{ +public: + enum { + READ_ONLY = IMemoryHeap::READ_ONLY, + MAP_ONCE = IMemoryHeap::MAP_ONCE, + // memory won't be mapped locally, but will be mapped in the remote + // process. + DONT_MAP_LOCALLY = 0x00000100 + }; + + /* + * maps the memory referenced by fd. but DOESN'T take ownership + * of the filedescriptor (it makes a copy with dup() + */ + MemoryHeapBase(int fd, size_t size, uint32_t flags = 0); + + /* + * maps memory from the given device + */ + MemoryHeapBase(const char* device, size_t size = 0, uint32_t flags = 0); + + /* + * maps memory from ashmem, with the given name for debugging + */ + MemoryHeapBase(size_t size, uint32_t flags = 0, char const* name = NULL); + + virtual ~MemoryHeapBase(); + + /* implement IMemoryHeap interface */ + virtual int getHeapID() const; + virtual void* getBase() const; + virtual size_t getSize() const; + virtual uint32_t getFlags() const; + + const char* getDevice() const; + + /* this closes this heap -- use carefully */ + void dispose(); + + /* this is only needed as a workaround, use only if you know + * what you are doing */ + status_t setDevice(const char* device) { + if (mDevice == 0) + mDevice = device; + return mDevice ? NO_ERROR : ALREADY_EXISTS; + } + +protected: + MemoryHeapBase(); + // init() takes ownership of fd + status_t init(int fd, void *base, int size, + int flags = 0, const char* device = NULL); + +private: + status_t mapfd(int fd, size_t size); + + int mFD; + size_t mSize; + void* mBase; + uint32_t mFlags; + const char* mDevice; + bool mNeedUnmap; +}; + +// --------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_MEMORY_HEAP_BASE_H diff --git a/include/binder/MemoryHeapPmem.h b/include/binder/MemoryHeapPmem.h new file mode 100644 index 0000000..dbf26ff --- /dev/null +++ b/include/binder/MemoryHeapPmem.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_MEMORY_HEAP_PMEM_H +#define ANDROID_MEMORY_HEAP_PMEM_H + +#include +#include + +#include +#include +#include +#include + +namespace android { + +class MemoryHeapBase; + +// --------------------------------------------------------------------------- + +class MemoryHeapPmem : public HeapInterface, public MemoryHeapBase +{ +public: + class MemoryPmem : public BnMemory { + public: + MemoryPmem(const sp& heap); + ~MemoryPmem(); + protected: + const sp& getHeap() const { return mClientHeap; } + private: + friend class MemoryHeapPmem; + virtual void revoke() = 0; + sp mClientHeap; + }; + + MemoryHeapPmem(const sp& pmemHeap, + uint32_t flags = IMemoryHeap::MAP_ONCE); + ~MemoryHeapPmem(); + + /* HeapInterface additions */ + virtual sp mapMemory(size_t offset, size_t size); + + /* make the whole heap visible (you know who you are) */ + virtual status_t slap(); + + /* hide (revoke) the whole heap (the client will see the garbage page) */ + virtual status_t unslap(); + + /* revoke all allocations made by this heap */ + virtual void revoke(); + +private: + /* use this to create your own IMemory for mapMemory */ + virtual sp createMemory(size_t offset, size_t size); + void remove(const wp& memory); + +private: + sp mParentHeap; + mutable Mutex mLock; + SortedVector< wp > mAllocations; +}; + + +// --------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_MEMORY_HEAP_PMEM_H diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h new file mode 100644 index 0000000..9087c44 --- /dev/null +++ b/include/binder/Parcel.h @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_PARCEL_H +#define ANDROID_PARCEL_H + +#include +#include +#include +#include +#include + +// --------------------------------------------------------------------------- +namespace android { + +class IBinder; +class ProcessState; +class String8; +class TextOutput; + +struct flat_binder_object; // defined in support_p/binder_module.h + +class Parcel +{ +public: + Parcel(); + ~Parcel(); + + const uint8_t* data() const; + size_t dataSize() const; + size_t dataAvail() const; + size_t dataPosition() const; + size_t dataCapacity() const; + + status_t setDataSize(size_t size); + void setDataPosition(size_t pos) const; + status_t setDataCapacity(size_t size); + + status_t setData(const uint8_t* buffer, size_t len); + + status_t appendFrom(Parcel *parcel, size_t start, size_t len); + + bool hasFileDescriptors() const; + + status_t writeInterfaceToken(const String16& interface); + bool enforceInterface(const String16& interface) const; + + void freeData(); + + const size_t* objects() const; + size_t objectsCount() const; + + status_t errorCheck() const; + void setError(status_t err); + + status_t write(const void* data, size_t len); + void* writeInplace(size_t len); + status_t writeUnpadded(const void* data, size_t len); + status_t writeInt32(int32_t val); + status_t writeInt64(int64_t val); + status_t writeFloat(float val); + status_t writeDouble(double val); + status_t writeCString(const char* str); + status_t writeString8(const String8& str); + status_t writeString16(const String16& str); + status_t writeString16(const char16_t* str, size_t len); + status_t writeStrongBinder(const sp& val); + status_t writeWeakBinder(const wp& val); + + // doesn't take ownership of the native_handle + status_t writeNativeHandle(const native_handle& handle); + + // Place a file descriptor into the parcel. The given fd must remain + // valid for the lifetime of the parcel. + status_t writeFileDescriptor(int fd); + + // Place a file descriptor into the parcel. A dup of the fd is made, which + // will be closed once the parcel is destroyed. + status_t writeDupFileDescriptor(int fd); + + status_t writeObject(const flat_binder_object& val, bool nullMetaData); + + void remove(size_t start, size_t amt); + + status_t read(void* outData, size_t len) const; + const void* readInplace(size_t len) const; + int32_t readInt32() const; + status_t readInt32(int32_t *pArg) const; + int64_t readInt64() const; + status_t readInt64(int64_t *pArg) const; + float readFloat() const; + status_t readFloat(float *pArg) const; + double readDouble() const; + status_t readDouble(double *pArg) const; + + const char* readCString() const; + String8 readString8() const; + String16 readString16() const; + const char16_t* readString16Inplace(size_t* outLen) const; + sp readStrongBinder() const; + wp readWeakBinder() const; + + + // if alloc is NULL, native_handle is allocated with malloc(), otherwise + // alloc is used. If the function fails, the effects of alloc() must be + // reverted by the caller. + native_handle* readNativeHandle( + native_handle* (*alloc)(void* cookie, int numFds, int ints), + void* cookie) const; + + + // Retrieve a file descriptor from the parcel. This returns the raw fd + // in the parcel, which you do not own -- use dup() to get your own copy. + int readFileDescriptor() const; + + const flat_binder_object* readObject(bool nullMetaData) const; + + // Explicitly close all file descriptors in the parcel. + void closeFileDescriptors(); + + typedef void (*release_func)(Parcel* parcel, + const uint8_t* data, size_t dataSize, + const size_t* objects, size_t objectsSize, + void* cookie); + + const uint8_t* ipcData() const; + size_t ipcDataSize() const; + const size_t* ipcObjects() const; + size_t ipcObjectsCount() const; + void ipcSetDataReference(const uint8_t* data, size_t dataSize, + const size_t* objects, size_t objectsCount, + release_func relFunc, void* relCookie); + + void print(TextOutput& to, uint32_t flags = 0) const; + +private: + Parcel(const Parcel& o); + Parcel& operator=(const Parcel& o); + + status_t finishWrite(size_t len); + void releaseObjects(); + void acquireObjects(); + status_t growData(size_t len); + status_t restartWrite(size_t desired); + status_t continueWrite(size_t desired); + void freeDataNoInit(); + void initState(); + void scanForFds() const; + + status_t mError; + uint8_t* mData; + size_t mDataSize; + size_t mDataCapacity; + mutable size_t mDataPos; + size_t* mObjects; + size_t mObjectsSize; + size_t mObjectsCapacity; + mutable size_t mNextObjectHint; + + mutable bool mFdsKnown; + mutable bool mHasFds; + + release_func mOwner; + void* mOwnerCookie; +}; + +// --------------------------------------------------------------------------- + +inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel) +{ + parcel.print(to); + return to; +} + +// --------------------------------------------------------------------------- + +// Generic acquire and release of objects. +void acquire_object(const sp& proc, + const flat_binder_object& obj, const void* who); +void release_object(const sp& proc, + const flat_binder_object& obj, const void* who); + +void flatten_binder(const sp& proc, + const sp& binder, flat_binder_object* out); +void flatten_binder(const sp& proc, + const wp& binder, flat_binder_object* out); +status_t unflatten_binder(const sp& proc, + const flat_binder_object& flat, sp* out); +status_t unflatten_binder(const sp& proc, + const flat_binder_object& flat, wp* out); + +}; // namespace android + +// --------------------------------------------------------------------------- + +#endif // ANDROID_PARCEL_H diff --git a/include/binder/ProcessState.h b/include/binder/ProcessState.h new file mode 100644 index 0000000..feeb3c3 --- /dev/null +++ b/include/binder/ProcessState.h @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2005 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_PROCESS_STATE_H +#define ANDROID_PROCESS_STATE_H + +#include +#include +#include +#include + +#include + +// --------------------------------------------------------------------------- +namespace android { + +// Global variables +extern int mArgC; +extern const char* const* mArgV; +extern int mArgLen; + +class IPCThreadState; + +class ProcessState : public virtual RefBase +{ +public: + static sp self(); + + static void setSingleProcess(bool singleProcess); + + void setContextObject(const sp& object); + sp getContextObject(const sp& caller); + + void setContextObject(const sp& object, + const String16& name); + sp getContextObject(const String16& name, + const sp& caller); + + bool supportsProcesses() const; + + void startThreadPool(); + + typedef bool (*context_check_func)(const String16& name, + const sp& caller, + void* userData); + + bool isContextManager(void) const; + bool becomeContextManager( + context_check_func checkFunc, + void* userData); + + sp getStrongProxyForHandle(int32_t handle); + wp getWeakProxyForHandle(int32_t handle); + void expungeHandle(int32_t handle, IBinder* binder); + + void setArgs(int argc, const char* const argv[]); + int getArgC() const; + const char* const* getArgV() const; + + void setArgV0(const char* txt); + + void spawnPooledThread(bool isMain); + +private: + friend class IPCThreadState; + + ProcessState(); + ~ProcessState(); + + ProcessState(const ProcessState& o); + ProcessState& operator=(const ProcessState& o); + + struct handle_entry { + IBinder* binder; + RefBase::weakref_type* refs; + }; + + handle_entry* lookupHandleLocked(int32_t handle); + + int mDriverFD; + void* mVMStart; + + mutable Mutex mLock; // protects everything below. + + VectormHandleToObject; + + bool mManagesContexts; + context_check_func mBinderContextCheckFunc; + void* mBinderContextUserData; + + KeyedVector > + mContexts; + + + String8 mRootDir; + bool mThreadPoolStarted; + volatile int32_t mThreadPoolSeq; +}; + +}; // namespace android + +// --------------------------------------------------------------------------- + +#endif // ANDROID_PROCESS_STATE_H diff --git a/include/private/binder/Static.h b/include/private/binder/Static.h index cbdf292..5b0f9fc 100644 --- a/include/private/binder/Static.h +++ b/include/private/binder/Static.h @@ -19,11 +19,11 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace android { diff --git a/include/private/utils/Static.h b/include/private/utils/Static.h index bd591b5..d95ae0d 100644 --- a/include/private/utils/Static.h +++ b/include/private/utils/Static.h @@ -20,16 +20,6 @@ #include #include -/* -#ifndef LIBUTILS_NATIVE -#include -#include -#include -#include -#include -#endif -*/ - namespace android { // For TextStream.cpp extern Vector gTextBuffers; @@ -42,20 +32,4 @@ extern void terminate_string8(); extern void initialize_string16(); extern void terminate_string16(); - -/* -#ifndef LIBUTILS_NATIVE - -// For ProcessState.cpp -extern Mutex gProcessMutex; -extern sp gProcess; - -// For ServiceManager.cpp -extern Mutex gDefaultServiceManagerLock; -extern sp gDefaultServiceManager; -extern sp gPermissionController; - -#endif -*/ - } // namespace android diff --git a/include/ui/CameraHardwareInterface.h b/include/ui/CameraHardwareInterface.h index 73036f0..2cdcc06 100644 --- a/include/ui/CameraHardwareInterface.h +++ b/include/ui/CameraHardwareInterface.h @@ -17,7 +17,7 @@ #ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H #define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H -#include +#include #include #include #include diff --git a/include/ui/ICamera.h b/include/ui/ICamera.h index 241fb63..1df7914 100644 --- a/include/ui/ICamera.h +++ b/include/ui/ICamera.h @@ -18,10 +18,10 @@ #define ANDROID_HARDWARE_ICAMERA_H #include -#include -#include +#include +#include #include -#include +#include #include #include diff --git a/include/ui/ICameraClient.h b/include/ui/ICameraClient.h index c4bdd07..f38a6aa 100644 --- a/include/ui/ICameraClient.h +++ b/include/ui/ICameraClient.h @@ -18,9 +18,9 @@ #define ANDROID_HARDWARE_ICAMERA_APP_H #include -#include -#include -#include +#include +#include +#include namespace android { diff --git a/include/ui/ICameraService.h b/include/ui/ICameraService.h index c652c51..061681a 100644 --- a/include/ui/ICameraService.h +++ b/include/ui/ICameraService.h @@ -18,8 +18,8 @@ #define ANDROID_HARDWARE_ICAMERASERVICE_H #include -#include -#include +#include +#include #include #include diff --git a/include/ui/IOverlay.h b/include/ui/IOverlay.h index 699b1b0..af3add1 100644 --- a/include/ui/IOverlay.h +++ b/include/ui/IOverlay.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include diff --git a/include/ui/ISurface.h b/include/ui/ISurface.h index 87b320f..136e801 100644 --- a/include/ui/ISurface.h +++ b/include/ui/ISurface.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include diff --git a/include/ui/ISurfaceComposer.h b/include/ui/ISurfaceComposer.h index 5c64b22..5b062a8 100644 --- a/include/ui/ISurfaceComposer.h +++ b/include/ui/ISurfaceComposer.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/include/ui/ISurfaceFlingerClient.h b/include/ui/ISurfaceFlingerClient.h index 5b9361d..b6cbb0b 100644 --- a/include/ui/ISurfaceFlingerClient.h +++ b/include/ui/ISurfaceFlingerClient.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include diff --git a/include/ui/Overlay.h b/include/ui/Overlay.h index 66514b4..9ba2f7b 100644 --- a/include/ui/Overlay.h +++ b/include/ui/Overlay.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include diff --git a/include/ui/Region.h b/include/ui/Region.h index 7689673..68cb52e 100644 --- a/include/ui/Region.h +++ b/include/ui/Region.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include diff --git a/include/utils/Binder.h b/include/utils/Binder.h deleted file mode 100644 index b5b8d98..0000000 --- a/include/utils/Binder.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_BINDER_H -#define ANDROID_BINDER_H - -#include - -// --------------------------------------------------------------------------- -namespace android { - -class BBinder : public IBinder -{ -public: - BBinder(); - - virtual String16 getInterfaceDescriptor() const; - virtual bool isBinderAlive() const; - virtual status_t pingBinder(); - virtual status_t dump(int fd, const Vector& args); - - virtual status_t transact( uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); - - virtual status_t linkToDeath(const sp& recipient, - void* cookie = NULL, - uint32_t flags = 0); - - virtual status_t unlinkToDeath( const wp& recipient, - void* cookie = NULL, - uint32_t flags = 0, - wp* outRecipient = NULL); - - virtual void attachObject( const void* objectID, - void* object, - void* cleanupCookie, - object_cleanup_func func); - virtual void* findObject(const void* objectID) const; - virtual void detachObject(const void* objectID); - - virtual BBinder* localBinder(); - -protected: - virtual ~BBinder(); - - virtual status_t onTransact( uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); - -private: - BBinder(const BBinder& o); - BBinder& operator=(const BBinder& o); - - class Extras; - - Extras* mExtras; - void* mReserved0; -}; - -// --------------------------------------------------------------------------- - -class BpRefBase : public virtual RefBase -{ -protected: - BpRefBase(const sp& o); - virtual ~BpRefBase(); - virtual void onFirstRef(); - virtual void onLastStrongRef(const void* id); - virtual bool onIncStrongAttempted(uint32_t flags, const void* id); - - inline IBinder* remote() { return mRemote; } - inline IBinder* remote() const { return mRemote; } - -private: - BpRefBase(const BpRefBase& o); - BpRefBase& operator=(const BpRefBase& o); - - IBinder* const mRemote; - RefBase::weakref_type* mRefs; - volatile int32_t mState; -}; - -}; // namespace android - -// --------------------------------------------------------------------------- - -#endif // ANDROID_BINDER_H diff --git a/include/utils/BpBinder.h b/include/utils/BpBinder.h deleted file mode 100644 index 7b96e29..0000000 --- a/include/utils/BpBinder.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2005 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_BPBINDER_H -#define ANDROID_BPBINDER_H - -#include -#include -#include - -// --------------------------------------------------------------------------- -namespace android { - -class BpBinder : public IBinder -{ -public: - BpBinder(int32_t handle); - - inline int32_t handle() const { return mHandle; } - - virtual String16 getInterfaceDescriptor() const; - virtual bool isBinderAlive() const; - virtual status_t pingBinder(); - virtual status_t dump(int fd, const Vector& args); - - virtual status_t transact( uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); - - virtual status_t linkToDeath(const sp& recipient, - void* cookie = NULL, - uint32_t flags = 0); - virtual status_t unlinkToDeath( const wp& recipient, - void* cookie = NULL, - uint32_t flags = 0, - wp* outRecipient = NULL); - - virtual void attachObject( const void* objectID, - void* object, - void* cleanupCookie, - object_cleanup_func func); - virtual void* findObject(const void* objectID) const; - virtual void detachObject(const void* objectID); - - virtual BpBinder* remoteBinder(); - - status_t setConstantData(const void* data, size_t size); - void sendObituary(); - - class ObjectManager - { - public: - ObjectManager(); - ~ObjectManager(); - - void attach( const void* objectID, - void* object, - void* cleanupCookie, - IBinder::object_cleanup_func func); - void* find(const void* objectID) const; - void detach(const void* objectID); - - void kill(); - - private: - ObjectManager(const ObjectManager&); - ObjectManager& operator=(const ObjectManager&); - - struct entry_t - { - void* object; - void* cleanupCookie; - IBinder::object_cleanup_func func; - }; - - KeyedVector mObjects; - }; - -protected: - virtual ~BpBinder(); - virtual void onFirstRef(); - virtual void onLastStrongRef(const void* id); - virtual bool onIncStrongAttempted(uint32_t flags, const void* id); - -private: - const int32_t mHandle; - - struct Obituary { - wp recipient; - void* cookie; - uint32_t flags; - }; - - void reportOneDeath(const Obituary& obit); - - mutable Mutex mLock; - volatile int32_t mAlive; - volatile int32_t mObitsSent; - Vector* mObituaries; - ObjectManager mObjects; - Parcel* mConstantData; -}; - -}; // namespace android - -// --------------------------------------------------------------------------- - -#endif // ANDROID_BPBINDER_H diff --git a/include/utils/IBinder.h b/include/utils/IBinder.h deleted file mode 100644 index 7370330..0000000 --- a/include/utils/IBinder.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_IBINDER_H -#define ANDROID_IBINDER_H - -#include -#include -#include -#include - - -#define B_PACK_CHARS(c1, c2, c3, c4) \ - ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4)) - -// --------------------------------------------------------------------------- -namespace android { - -class BBinder; -class BpBinder; -class IInterface; -class Parcel; - -/** - * Base class and low-level protocol for a remotable object. - * You can derive from this class to create an object for which other - * processes can hold references to it. Communication between processes - * (method calls, property get and set) is down through a low-level - * protocol implemented on top of the transact() API. - */ -class IBinder : public virtual RefBase -{ -public: - enum { - FIRST_CALL_TRANSACTION = 0x00000001, - LAST_CALL_TRANSACTION = 0x00ffffff, - - PING_TRANSACTION = B_PACK_CHARS('_','P','N','G'), - DUMP_TRANSACTION = B_PACK_CHARS('_','D','M','P'), - INTERFACE_TRANSACTION = B_PACK_CHARS('_', 'N', 'T', 'F'), - - // Corresponds to tfOneWay -- an asynchronous call. - FLAG_ONEWAY = 0x00000001 - }; - - inline IBinder() { } - - /** - * Check if this IBinder implements the interface named by - * @a descriptor. If it does, the base pointer to it is returned, - * which you can safely static_cast<> to the concrete C++ interface. - */ - virtual sp queryLocalInterface(const String16& descriptor); - - /** - * Return the canonical name of the interface provided by this IBinder - * object. - */ - virtual String16 getInterfaceDescriptor() const = 0; - - virtual bool isBinderAlive() const = 0; - virtual status_t pingBinder() = 0; - virtual status_t dump(int fd, const Vector& args) = 0; - - virtual status_t transact( uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0) = 0; - - /** - * This method allows you to add data that is transported through - * IPC along with your IBinder pointer. When implementing a Binder - * object, override it to write your desired data in to @a outData. - * You can then call getConstantData() on your IBinder to retrieve - * that data, from any process. You MUST return the number of bytes - * written in to the parcel (including padding). - */ - class DeathRecipient : public virtual RefBase - { - public: - virtual void binderDied(const wp& who) = 0; - }; - - /** - * Register the @a recipient for a notification if this binder - * goes away. If this binder object unexpectedly goes away - * (typically because its hosting process has been killed), - * then DeathRecipient::binderDied() will be called with a referene - * to this. - * - * The @a cookie is optional -- if non-NULL, it should be a - * memory address that you own (that is, you know it is unique). - * - * @note You will only receive death notifications for remote binders, - * as local binders by definition can't die without you dying as well. - * Trying to use this function on a local binder will result in an - * INVALID_OPERATION code being returned and nothing happening. - * - * @note This link always holds a weak reference to its recipient. - * - * @note You will only receive a weak reference to the dead - * binder. You should not try to promote this to a strong reference. - * (Nor should you need to, as there is nothing useful you can - * directly do with it now that it has passed on.) - */ - virtual status_t linkToDeath(const sp& recipient, - void* cookie = NULL, - uint32_t flags = 0) = 0; - - /** - * Remove a previously registered death notification. - * The @a recipient will no longer be called if this object - * dies. The @a cookie is optional. If non-NULL, you can - * supply a NULL @a recipient, and the recipient previously - * added with that cookie will be unlinked. - */ - virtual status_t unlinkToDeath( const wp& recipient, - void* cookie = NULL, - uint32_t flags = 0, - wp* outRecipient = NULL) = 0; - - virtual bool checkSubclass(const void* subclassID) const; - - typedef void (*object_cleanup_func)(const void* id, void* obj, void* cleanupCookie); - - virtual void attachObject( const void* objectID, - void* object, - void* cleanupCookie, - object_cleanup_func func) = 0; - virtual void* findObject(const void* objectID) const = 0; - virtual void detachObject(const void* objectID) = 0; - - virtual BBinder* localBinder(); - virtual BpBinder* remoteBinder(); - -protected: - inline virtual ~IBinder() { } - -private: -}; - -}; // namespace android - -// --------------------------------------------------------------------------- - -#endif // ANDROID_IBINDER_H diff --git a/include/utils/IInterface.h b/include/utils/IInterface.h deleted file mode 100644 index 959722a..0000000 --- a/include/utils/IInterface.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2005 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// -#ifndef ANDROID_IINTERFACE_H -#define ANDROID_IINTERFACE_H - -#include - -namespace android { - -// ---------------------------------------------------------------------- - -class IInterface : public virtual RefBase -{ -public: - sp asBinder(); - sp asBinder() const; - -protected: - virtual IBinder* onAsBinder() = 0; -}; - -// ---------------------------------------------------------------------- - -template -inline sp interface_cast(const sp& obj) -{ - return INTERFACE::asInterface(obj); -} - -// ---------------------------------------------------------------------- - -template -class BnInterface : public INTERFACE, public BBinder -{ -public: - virtual sp queryLocalInterface(const String16& _descriptor); - virtual String16 getInterfaceDescriptor() const; - -protected: - virtual IBinder* onAsBinder(); -}; - -// ---------------------------------------------------------------------- - -template -class BpInterface : public INTERFACE, public BpRefBase -{ -public: - BpInterface(const sp& remote); - -protected: - virtual IBinder* onAsBinder(); -}; - -// ---------------------------------------------------------------------- - -#define DECLARE_META_INTERFACE(INTERFACE) \ - static const String16 descriptor; \ - static sp asInterface(const sp& obj); \ - virtual String16 getInterfaceDescriptor() const; \ - -#define IMPLEMENT_META_INTERFACE(INTERFACE, NAME) \ - const String16 I##INTERFACE::descriptor(NAME); \ - String16 I##INTERFACE::getInterfaceDescriptor() const { \ - return I##INTERFACE::descriptor; \ - } \ - sp I##INTERFACE::asInterface(const sp& obj) \ - { \ - sp intr; \ - if (obj != NULL) { \ - intr = static_cast( \ - obj->queryLocalInterface( \ - I##INTERFACE::descriptor).get()); \ - if (intr == NULL) { \ - intr = new Bp##INTERFACE(obj); \ - } \ - } \ - return intr; \ - } \ - -// ---------------------------------------------------------------------- -// No user-servicable parts after this... - -template -inline sp BnInterface::queryLocalInterface( - const String16& _descriptor) -{ - if (_descriptor == INTERFACE::descriptor) return this; - return NULL; -} - -template -inline String16 BnInterface::getInterfaceDescriptor() const -{ - return INTERFACE::getInterfaceDescriptor(); -} - -template -IBinder* BnInterface::onAsBinder() -{ - return this; -} - -template -inline BpInterface::BpInterface(const sp& remote) - : BpRefBase(remote) -{ -} - -template -inline IBinder* BpInterface::onAsBinder() -{ - return remote(); -} - -// ---------------------------------------------------------------------- - -}; // namespace android - -#endif // ANDROID_IINTERFACE_H diff --git a/include/utils/IMemory.h b/include/utils/IMemory.h deleted file mode 100644 index 35a3fd7..0000000 --- a/include/utils/IMemory.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_IMEMORY_H -#define ANDROID_IMEMORY_H - -#include -#include -#include - -#include -#include -#include - -namespace android { - -// ---------------------------------------------------------------------------- - -class IMemoryHeap : public IInterface -{ -public: - DECLARE_META_INTERFACE(MemoryHeap); - - // flags returned by getFlags() - enum { - READ_ONLY = 0x00000001, - MAP_ONCE = 0x00000002 - }; - - virtual int getHeapID() const = 0; - virtual void* getBase() const = 0; - virtual size_t getSize() const = 0; - virtual uint32_t getFlags() const = 0; - - // these are there just for backward source compatibility - int32_t heapID() const { return getHeapID(); } - void* base() const { return getBase(); } - size_t virtualSize() const { return getSize(); } -}; - -class BnMemoryHeap : public BnInterface -{ -public: - virtual status_t onTransact( - uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); -}; - -// ---------------------------------------------------------------------------- - -class IMemory : public IInterface -{ -public: - DECLARE_META_INTERFACE(Memory); - - virtual sp getMemory(ssize_t* offset=0, size_t* size=0) const = 0; - - // helpers - void* fastPointer(const sp& heap, ssize_t offset) const; - void* pointer() const; - size_t size() const; - ssize_t offset() const; -}; - -class BnMemory : public BnInterface -{ -public: - virtual status_t onTransact( - uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); -}; - -// ---------------------------------------------------------------------------- - -}; // namespace android - -#endif // ANDROID_IMEMORY_H diff --git a/include/utils/IPCThreadState.h b/include/utils/IPCThreadState.h deleted file mode 100644 index 0490fd3..0000000 --- a/include/utils/IPCThreadState.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2005 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_IPC_THREAD_STATE_H -#define ANDROID_IPC_THREAD_STATE_H - -#include -#include -#include -#include - -#ifdef HAVE_WIN32_PROC -typedef int uid_t; -#endif - -// --------------------------------------------------------------------------- -namespace android { - -class IPCThreadState -{ -public: - static IPCThreadState* self(); - - sp process(); - - status_t clearLastError(); - - int getCallingPid(); - int getCallingUid(); - - int64_t clearCallingIdentity(); - void restoreCallingIdentity(int64_t token); - - void flushCommands(); - - void joinThreadPool(bool isMain = true); - - // Stop the local process. - void stopProcess(bool immediate = true); - - status_t transact(int32_t handle, - uint32_t code, const Parcel& data, - Parcel* reply, uint32_t flags); - - void incStrongHandle(int32_t handle); - void decStrongHandle(int32_t handle); - void incWeakHandle(int32_t handle); - void decWeakHandle(int32_t handle); - status_t attemptIncStrongHandle(int32_t handle); - static void expungeHandle(int32_t handle, IBinder* binder); - status_t requestDeathNotification( int32_t handle, - BpBinder* proxy); - status_t clearDeathNotification( int32_t handle, - BpBinder* proxy); - - static void shutdown(); - -private: - IPCThreadState(); - ~IPCThreadState(); - - status_t sendReply(const Parcel& reply, uint32_t flags); - status_t waitForResponse(Parcel *reply, - status_t *acquireResult=NULL); - status_t talkWithDriver(bool doReceive=true); - status_t writeTransactionData(int32_t cmd, - uint32_t binderFlags, - int32_t handle, - uint32_t code, - const Parcel& data, - status_t* statusBuffer); - status_t executeCommand(int32_t command); - - void clearCaller(); - - static void threadDestructor(void *st); - static void freeBuffer(Parcel* parcel, - const uint8_t* data, size_t dataSize, - const size_t* objects, size_t objectsSize, - void* cookie); - - const sp mProcess; - Vector mPendingStrongDerefs; - Vector mPendingWeakDerefs; - - Parcel mIn; - Parcel mOut; - status_t mLastError; - pid_t mCallingPid; - uid_t mCallingUid; -}; - -}; // namespace android - -// --------------------------------------------------------------------------- - -#endif // ANDROID_IPC_THREAD_STATE_H diff --git a/include/utils/IPermissionController.h b/include/utils/IPermissionController.h deleted file mode 100644 index cb1dd34..0000000 --- a/include/utils/IPermissionController.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2005 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// -#ifndef ANDROID_IPERMISSION_CONTROLLER_H -#define ANDROID_IPERMISSION_CONTROLLER_H - -#include - -namespace android { - -// ---------------------------------------------------------------------- - -class IPermissionController : public IInterface -{ -public: - DECLARE_META_INTERFACE(PermissionController); - - virtual bool checkPermission(const String16& permission, - int32_t pid, int32_t uid) = 0; - - enum { - CHECK_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION - }; -}; - -// ---------------------------------------------------------------------- - -class BnPermissionController : public BnInterface -{ -public: - virtual status_t onTransact( uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); -}; - -// ---------------------------------------------------------------------- - -}; // namespace android - -#endif // ANDROID_IPERMISSION_CONTROLLER_H - diff --git a/include/utils/IServiceManager.h b/include/utils/IServiceManager.h deleted file mode 100644 index e3d99fe..0000000 --- a/include/utils/IServiceManager.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2005 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// -#ifndef ANDROID_ISERVICE_MANAGER_H -#define ANDROID_ISERVICE_MANAGER_H - -#include -#include -#include -#include - -namespace android { - -// ---------------------------------------------------------------------- - -class IServiceManager : public IInterface -{ -public: - DECLARE_META_INTERFACE(ServiceManager); - - /** - * Retrieve an existing service, blocking for a few seconds - * if it doesn't yet exist. - */ - virtual sp getService( const String16& name) const = 0; - - /** - * Retrieve an existing service, non-blocking. - */ - virtual sp checkService( const String16& name) const = 0; - - /** - * Register a service. - */ - virtual status_t addService( const String16& name, - const sp& service) = 0; - - /** - * Return list of all existing services. - */ - virtual Vector listServices() = 0; - - enum { - GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, - CHECK_SERVICE_TRANSACTION, - ADD_SERVICE_TRANSACTION, - LIST_SERVICES_TRANSACTION, - }; -}; - -sp defaultServiceManager(); - -template -status_t getService(const String16& name, sp* outService) -{ - const sp sm = defaultServiceManager(); - if (sm != NULL) { - *outService = interface_cast(sm->getService(name)); - if ((*outService) != NULL) return NO_ERROR; - } - return NAME_NOT_FOUND; -} - -bool checkCallingPermission(const String16& permission); -bool checkCallingPermission(const String16& permission, - int32_t* outPid, int32_t* outUid); - -// ---------------------------------------------------------------------- - -class BnServiceManager : public BnInterface -{ -public: - virtual status_t onTransact( uint32_t code, - const Parcel& data, - Parcel* reply, - uint32_t flags = 0); -}; - -// ---------------------------------------------------------------------- - -}; // namespace android - -#endif // ANDROID_ISERVICE_MANAGER_H - diff --git a/include/utils/MemoryBase.h b/include/utils/MemoryBase.h deleted file mode 100644 index eb5a9d2..0000000 --- a/include/utils/MemoryBase.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_MEMORY_BASE_H -#define ANDROID_MEMORY_BASE_H - -#include -#include - -#include - - -namespace android { - -// --------------------------------------------------------------------------- - -class MemoryBase : public BnMemory -{ -public: - MemoryBase(const sp& heap, ssize_t offset, size_t size); - virtual ~MemoryBase(); - virtual sp getMemory(ssize_t* offset, size_t* size) const; - -protected: - size_t getSize() const { return mSize; } - ssize_t getOffset() const { return mOffset; } - const sp& getHeap() const { return mHeap; } - -private: - size_t mSize; - ssize_t mOffset; - sp mHeap; -}; - -// --------------------------------------------------------------------------- -}; // namespace android - -#endif // ANDROID_MEMORY_BASE_H diff --git a/include/utils/MemoryDealer.h b/include/utils/MemoryDealer.h deleted file mode 100644 index 454b627..0000000 --- a/include/utils/MemoryDealer.h +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_MEMORY_DEALER_H -#define ANDROID_MEMORY_DEALER_H - - -#include -#include - -#include -#include -#include - -namespace android { -// ---------------------------------------------------------------------------- -class String8; - -/* - * interface for implementing a "heap". A heap basically provides - * the IMemoryHeap interface for cross-process sharing and the - * ability to map/unmap pages within the heap. - */ -class HeapInterface : public virtual BnMemoryHeap -{ -public: - // all values must be page-aligned - virtual sp mapMemory(size_t offset, size_t size) = 0; -}; - -// ---------------------------------------------------------------------------- - -/* - * interface for implementing an allocator. An allocator provides - * methods for allocating and freeing memory blocks and dumping - * its state. - */ -class AllocatorInterface : public RefBase -{ -public: - enum { - PAGE_ALIGNED = 0x00000001 - }; - - virtual size_t allocate(size_t size, uint32_t flags = 0) = 0; - virtual status_t deallocate(size_t offset) = 0; - virtual size_t size() const = 0; - virtual void dump(const char* what, uint32_t flags = 0) const = 0; - virtual void dump(String8& res, - const char* what, uint32_t flags = 0) const = 0; -}; - -// ---------------------------------------------------------------------------- - -/* - * concrete implementation of HeapInterface on top of mmap() - */ -class SharedHeap : public HeapInterface, public MemoryHeapBase -{ -public: - SharedHeap(size_t size, uint32_t flags = 0, char const * name = NULL); - virtual ~SharedHeap(); - virtual sp mapMemory(size_t offset, size_t size); -}; - -// ---------------------------------------------------------------------------- - -/* - * A simple templatized doubly linked-list implementation - */ - -template -class LinkedList -{ - NODE* mFirst; - NODE* mLast; - -public: - LinkedList() : mFirst(0), mLast(0) { } - bool isEmpty() const { return mFirst == 0; } - NODE const* head() const { return mFirst; } - NODE* head() { return mFirst; } - NODE const* tail() const { return mLast; } - NODE* tail() { return mLast; } - - void insertAfter(NODE* node, NODE* newNode) { - newNode->prev = node; - newNode->next = node->next; - if (node->next == 0) mLast = newNode; - else node->next->prev = newNode; - node->next = newNode; - } - - void insertBefore(NODE* node, NODE* newNode) { - newNode->prev = node->prev; - newNode->next = node; - if (node->prev == 0) mFirst = newNode; - else node->prev->next = newNode; - node->prev = newNode; - } - - void insertHead(NODE* newNode) { - if (mFirst == 0) { - mFirst = mLast = newNode; - newNode->prev = newNode->next = 0; - } else { - insertBefore(mFirst, newNode); - } - } - - void insertTail(NODE* newNode) { - if (mLast == 0) insertBeginning(newNode); - else insertAfter(mLast, newNode); - } - - NODE* remove(NODE* node) { - if (node->prev == 0) mFirst = node->next; - else node->prev->next = node->next; - if (node->next == 0) mLast = node->prev; - else node->next->prev = node->prev; - return node; - } -}; - - -/* - * concrete implementation of AllocatorInterface using a simple - * best-fit allocation scheme - */ -class SimpleBestFitAllocator : public AllocatorInterface -{ -public: - - SimpleBestFitAllocator(size_t size); - virtual ~SimpleBestFitAllocator(); - - virtual size_t allocate(size_t size, uint32_t flags = 0); - virtual status_t deallocate(size_t offset); - virtual size_t size() const; - virtual void dump(const char* what, uint32_t flags = 0) const; - virtual void dump(String8& res, - const char* what, uint32_t flags = 0) const; - -private: - - struct chunk_t { - chunk_t(size_t start, size_t size) - : start(start), size(size), free(1), prev(0), next(0) { - } - size_t start; - size_t size : 28; - int free : 4; - mutable chunk_t* prev; - mutable chunk_t* next; - }; - - ssize_t alloc(size_t size, uint32_t flags); - chunk_t* dealloc(size_t start); - void dump_l(const char* what, uint32_t flags = 0) const; - void dump_l(String8& res, const char* what, uint32_t flags = 0) const; - - static const int kMemoryAlign; - mutable Mutex mLock; - LinkedList mList; - size_t mHeapSize; -}; - -// ---------------------------------------------------------------------------- - -class MemoryDealer : public RefBase -{ -public: - - enum { - READ_ONLY = MemoryHeapBase::READ_ONLY, - PAGE_ALIGNED = AllocatorInterface::PAGE_ALIGNED - }; - - // creates a memory dealer with the SharedHeap and SimpleBestFitAllocator - MemoryDealer(size_t size, uint32_t flags = 0, const char* name = 0); - - // provide a custom heap but use the SimpleBestFitAllocator - MemoryDealer(const sp& heap); - - // provide both custom heap and allocotar - MemoryDealer( - const sp& heap, - const sp& allocator); - - virtual ~MemoryDealer(); - - virtual sp allocate(size_t size, uint32_t flags = 0); - virtual void deallocate(size_t offset); - virtual void dump(const char* what, uint32_t flags = 0) const; - - - sp getMemoryHeap() const { return heap(); } - sp getAllocator() const { return allocator(); } - -private: - const sp& heap() const; - const sp& allocator() const; - - class Allocation : public BnMemory { - public: - Allocation(const sp& dealer, - ssize_t offset, size_t size, const sp& memory); - virtual ~Allocation(); - virtual sp getMemory(ssize_t* offset, size_t* size) const; - private: - sp mDealer; - ssize_t mOffset; - size_t mSize; - sp mMemory; - }; - - sp mHeap; - sp mAllocator; -}; - - -// ---------------------------------------------------------------------------- -}; // namespace android - -#endif // ANDROID_MEMORY_DEALER_H diff --git a/include/utils/MemoryHeapBase.h b/include/utils/MemoryHeapBase.h deleted file mode 100644 index 574acf4..0000000 --- a/include/utils/MemoryHeapBase.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_MEMORY_HEAP_BASE_H -#define ANDROID_MEMORY_HEAP_BASE_H - -#include -#include - -#include - - -namespace android { - -// --------------------------------------------------------------------------- - -class MemoryHeapBase : public virtual BnMemoryHeap -{ -public: - enum { - READ_ONLY = IMemoryHeap::READ_ONLY, - MAP_ONCE = IMemoryHeap::MAP_ONCE, - // memory won't be mapped locally, but will be mapped in the remote - // process. - DONT_MAP_LOCALLY = 0x00000100 - }; - - /* - * maps the memory referenced by fd. but DOESN'T take ownership - * of the filedescriptor (it makes a copy with dup() - */ - MemoryHeapBase(int fd, size_t size, uint32_t flags = 0); - - /* - * maps memory from the given device - */ - MemoryHeapBase(const char* device, size_t size = 0, uint32_t flags = 0); - - /* - * maps memory from ashmem, with the given name for debugging - */ - MemoryHeapBase(size_t size, uint32_t flags = 0, char const* name = NULL); - - virtual ~MemoryHeapBase(); - - /* implement IMemoryHeap interface */ - virtual int getHeapID() const; - virtual void* getBase() const; - virtual size_t getSize() const; - virtual uint32_t getFlags() const; - - const char* getDevice() const; - - /* this closes this heap -- use carefully */ - void dispose(); - - /* this is only needed as a workaround, use only if you know - * what you are doing */ - status_t setDevice(const char* device) { - if (mDevice == 0) - mDevice = device; - return mDevice ? NO_ERROR : ALREADY_EXISTS; - } - -protected: - MemoryHeapBase(); - // init() takes ownership of fd - status_t init(int fd, void *base, int size, - int flags = 0, const char* device = NULL); - -private: - status_t mapfd(int fd, size_t size); - - int mFD; - size_t mSize; - void* mBase; - uint32_t mFlags; - const char* mDevice; - bool mNeedUnmap; -}; - -// --------------------------------------------------------------------------- -}; // namespace android - -#endif // ANDROID_MEMORY_HEAP_BASE_H diff --git a/include/utils/MemoryHeapPmem.h b/include/utils/MemoryHeapPmem.h deleted file mode 100644 index 60335ad..0000000 --- a/include/utils/MemoryHeapPmem.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_MEMORY_HEAP_PMEM_H -#define ANDROID_MEMORY_HEAP_PMEM_H - -#include -#include - -#include -#include -#include -#include - -namespace android { - -class MemoryHeapBase; - -// --------------------------------------------------------------------------- - -class MemoryHeapPmem : public HeapInterface, public MemoryHeapBase -{ -public: - class MemoryPmem : public BnMemory { - public: - MemoryPmem(const sp& heap); - ~MemoryPmem(); - protected: - const sp& getHeap() const { return mClientHeap; } - private: - friend class MemoryHeapPmem; - virtual void revoke() = 0; - sp mClientHeap; - }; - - MemoryHeapPmem(const sp& pmemHeap, - uint32_t flags = IMemoryHeap::MAP_ONCE); - ~MemoryHeapPmem(); - - /* HeapInterface additions */ - virtual sp mapMemory(size_t offset, size_t size); - - /* make the whole heap visible (you know who you are) */ - virtual status_t slap(); - - /* hide (revoke) the whole heap (the client will see the garbage page) */ - virtual status_t unslap(); - - /* revoke all allocations made by this heap */ - virtual void revoke(); - -private: - /* use this to create your own IMemory for mapMemory */ - virtual sp createMemory(size_t offset, size_t size); - void remove(const wp& memory); - -private: - sp mParentHeap; - mutable Mutex mLock; - SortedVector< wp > mAllocations; -}; - - -// --------------------------------------------------------------------------- -}; // namespace android - -#endif // ANDROID_MEMORY_HEAP_PMEM_H diff --git a/include/utils/Parcel.h b/include/utils/Parcel.h deleted file mode 100644 index 9087c44..0000000 --- a/include/utils/Parcel.h +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (C) 2005 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_PARCEL_H -#define ANDROID_PARCEL_H - -#include -#include -#include -#include -#include - -// --------------------------------------------------------------------------- -namespace android { - -class IBinder; -class ProcessState; -class String8; -class TextOutput; - -struct flat_binder_object; // defined in support_p/binder_module.h - -class Parcel -{ -public: - Parcel(); - ~Parcel(); - - const uint8_t* data() const; - size_t dataSize() const; - size_t dataAvail() const; - size_t dataPosition() const; - size_t dataCapacity() const; - - status_t setDataSize(size_t size); - void setDataPosition(size_t pos) const; - status_t setDataCapacity(size_t size); - - status_t setData(const uint8_t* buffer, size_t len); - - status_t appendFrom(Parcel *parcel, size_t start, size_t len); - - bool hasFileDescriptors() const; - - status_t writeInterfaceToken(const String16& interface); - bool enforceInterface(const String16& interface) const; - - void freeData(); - - const size_t* objects() const; - size_t objectsCount() const; - - status_t errorCheck() const; - void setError(status_t err); - - status_t write(const void* data, size_t len); - void* writeInplace(size_t len); - status_t writeUnpadded(const void* data, size_t len); - status_t writeInt32(int32_t val); - status_t writeInt64(int64_t val); - status_t writeFloat(float val); - status_t writeDouble(double val); - status_t writeCString(const char* str); - status_t writeString8(const String8& str); - status_t writeString16(const String16& str); - status_t writeString16(const char16_t* str, size_t len); - status_t writeStrongBinder(const sp& val); - status_t writeWeakBinder(const wp& val); - - // doesn't take ownership of the native_handle - status_t writeNativeHandle(const native_handle& handle); - - // Place a file descriptor into the parcel. The given fd must remain - // valid for the lifetime of the parcel. - status_t writeFileDescriptor(int fd); - - // Place a file descriptor into the parcel. A dup of the fd is made, which - // will be closed once the parcel is destroyed. - status_t writeDupFileDescriptor(int fd); - - status_t writeObject(const flat_binder_object& val, bool nullMetaData); - - void remove(size_t start, size_t amt); - - status_t read(void* outData, size_t len) const; - const void* readInplace(size_t len) const; - int32_t readInt32() const; - status_t readInt32(int32_t *pArg) const; - int64_t readInt64() const; - status_t readInt64(int64_t *pArg) const; - float readFloat() const; - status_t readFloat(float *pArg) const; - double readDouble() const; - status_t readDouble(double *pArg) const; - - const char* readCString() const; - String8 readString8() const; - String16 readString16() const; - const char16_t* readString16Inplace(size_t* outLen) const; - sp readStrongBinder() const; - wp readWeakBinder() const; - - - // if alloc is NULL, native_handle is allocated with malloc(), otherwise - // alloc is used. If the function fails, the effects of alloc() must be - // reverted by the caller. - native_handle* readNativeHandle( - native_handle* (*alloc)(void* cookie, int numFds, int ints), - void* cookie) const; - - - // Retrieve a file descriptor from the parcel. This returns the raw fd - // in the parcel, which you do not own -- use dup() to get your own copy. - int readFileDescriptor() const; - - const flat_binder_object* readObject(bool nullMetaData) const; - - // Explicitly close all file descriptors in the parcel. - void closeFileDescriptors(); - - typedef void (*release_func)(Parcel* parcel, - const uint8_t* data, size_t dataSize, - const size_t* objects, size_t objectsSize, - void* cookie); - - const uint8_t* ipcData() const; - size_t ipcDataSize() const; - const size_t* ipcObjects() const; - size_t ipcObjectsCount() const; - void ipcSetDataReference(const uint8_t* data, size_t dataSize, - const size_t* objects, size_t objectsCount, - release_func relFunc, void* relCookie); - - void print(TextOutput& to, uint32_t flags = 0) const; - -private: - Parcel(const Parcel& o); - Parcel& operator=(const Parcel& o); - - status_t finishWrite(size_t len); - void releaseObjects(); - void acquireObjects(); - status_t growData(size_t len); - status_t restartWrite(size_t desired); - status_t continueWrite(size_t desired); - void freeDataNoInit(); - void initState(); - void scanForFds() const; - - status_t mError; - uint8_t* mData; - size_t mDataSize; - size_t mDataCapacity; - mutable size_t mDataPos; - size_t* mObjects; - size_t mObjectsSize; - size_t mObjectsCapacity; - mutable size_t mNextObjectHint; - - mutable bool mFdsKnown; - mutable bool mHasFds; - - release_func mOwner; - void* mOwnerCookie; -}; - -// --------------------------------------------------------------------------- - -inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel) -{ - parcel.print(to); - return to; -} - -// --------------------------------------------------------------------------- - -// Generic acquire and release of objects. -void acquire_object(const sp& proc, - const flat_binder_object& obj, const void* who); -void release_object(const sp& proc, - const flat_binder_object& obj, const void* who); - -void flatten_binder(const sp& proc, - const sp& binder, flat_binder_object* out); -void flatten_binder(const sp& proc, - const wp& binder, flat_binder_object* out); -status_t unflatten_binder(const sp& proc, - const flat_binder_object& flat, sp* out); -status_t unflatten_binder(const sp& proc, - const flat_binder_object& flat, wp* out); - -}; // namespace android - -// --------------------------------------------------------------------------- - -#endif // ANDROID_PARCEL_H diff --git a/include/utils/ProcessState.h b/include/utils/ProcessState.h deleted file mode 100644 index 39584f4..0000000 --- a/include/utils/ProcessState.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2005 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_PROCESS_STATE_H -#define ANDROID_PROCESS_STATE_H - -#include -#include -#include -#include - -#include - -// --------------------------------------------------------------------------- -namespace android { - -// Global variables -extern int mArgC; -extern const char* const* mArgV; -extern int mArgLen; - -class IPCThreadState; - -class ProcessState : public virtual RefBase -{ -public: - static sp self(); - - static void setSingleProcess(bool singleProcess); - - void setContextObject(const sp& object); - sp getContextObject(const sp& caller); - - void setContextObject(const sp& object, - const String16& name); - sp getContextObject(const String16& name, - const sp& caller); - - bool supportsProcesses() const; - - void startThreadPool(); - - typedef bool (*context_check_func)(const String16& name, - const sp& caller, - void* userData); - - bool isContextManager(void) const; - bool becomeContextManager( - context_check_func checkFunc, - void* userData); - - sp getStrongProxyForHandle(int32_t handle); - wp getWeakProxyForHandle(int32_t handle); - void expungeHandle(int32_t handle, IBinder* binder); - - void setArgs(int argc, const char* const argv[]); - int getArgC() const; - const char* const* getArgV() const; - - void setArgV0(const char* txt); - - void spawnPooledThread(bool isMain); - -private: - friend class IPCThreadState; - - ProcessState(); - ~ProcessState(); - - ProcessState(const ProcessState& o); - ProcessState& operator=(const ProcessState& o); - - struct handle_entry { - IBinder* binder; - RefBase::weakref_type* refs; - }; - - handle_entry* lookupHandleLocked(int32_t handle); - - int mDriverFD; - void* mVMStart; - - mutable Mutex mLock; // protects everything below. - - VectormHandleToObject; - - bool mManagesContexts; - context_check_func mBinderContextCheckFunc; - void* mBinderContextUserData; - - KeyedVector > - mContexts; - - - String8 mRootDir; - bool mThreadPoolStarted; - volatile int32_t mThreadPoolSeq; -}; - -}; // namespace android - -// --------------------------------------------------------------------------- - -#endif // ANDROID_PROCESS_STATE_H diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp index efcf2b0..4b4fa5e 100644 --- a/libs/audioflinger/AudioFlinger.cpp +++ b/libs/audioflinger/AudioFlinger.cpp @@ -24,10 +24,10 @@ #include #include -#include +#include #include -#include -#include +#include +#include #include #include diff --git a/libs/audioflinger/AudioFlinger.h b/libs/audioflinger/AudioFlinger.h index c7ca9ec..f3e6dc1 100644 --- a/libs/audioflinger/AudioFlinger.h +++ b/libs/audioflinger/AudioFlinger.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp index 37e4685..26f29f8 100644 --- a/libs/binder/Binder.cpp +++ b/libs/binder/Binder.cpp @@ -14,12 +14,12 @@ * limitations under the License. */ -#include +#include #include -#include -#include -#include +#include +#include +#include #include diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp index 69ab195..56bf413 100644 --- a/libs/binder/BpBinder.cpp +++ b/libs/binder/BpBinder.cpp @@ -17,9 +17,9 @@ #define LOG_TAG "BpBinder" //#define LOG_NDEBUG 0 -#include +#include -#include +#include #include #include diff --git a/libs/binder/IDataConnection.cpp b/libs/binder/IDataConnection.cpp deleted file mode 100644 index c6d49aa..0000000 --- a/libs/binder/IDataConnection.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include - -#include - -namespace android { - -// --------------------------------------------------------------------------- - -enum -{ - CONNECT_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, - DISCONNECT_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 1 -}; - -class BpDataConnection : public BpInterface -{ -public: - BpDataConnection::BpDataConnection(const sp& impl) - : BpInterface(impl) - { - } - - virtual void connect() - { - Parcel data, reply; - data.writeInterfaceToken(IDataConnection::descriptor()); - remote()->transact(CONNECT_TRANSACTION, data, &reply); - } - - virtual void disconnect() - { - Parcel data, reply; - remote()->transact(DISCONNECT_TRANSACTION, data, &reply); - } -}; - -IMPLEMENT_META_INTERFACE(DataConnection, "android.utils.IDataConnection"); - -#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 BnDataConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) -{ - switch(code) - { - case CONNECT_TRANSACTION: - { - CHECK_INTERFACE(IDataConnection, data, reply); - connect(); - return NO_ERROR; - } - - case DISCONNECT_TRANSACTION: - { - CHECK_INTERFACE(IDataConnection, data, reply); - disconnect(); - return NO_ERROR; - } - - default: - return BBinder::onTransact(code, data, reply, flags); - } -} - -// ---------------------------------------------------------------------------- - -}; // namespace android diff --git a/libs/binder/IInterface.cpp b/libs/binder/IInterface.cpp index 6ea8178..9f1192f 100644 --- a/libs/binder/IInterface.cpp +++ b/libs/binder/IInterface.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include namespace android { diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp index 429bc2b..13d67c0 100644 --- a/libs/binder/IMemory.cpp +++ b/libs/binder/IMemory.cpp @@ -25,11 +25,11 @@ #include #include -#include +#include #include #include #include -#include +#include #include #define VERBOSE 0 diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 704a481..c3889e9 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -14,10 +14,10 @@ * limitations under the License. */ -#include +#include -#include -#include +#include +#include #include #include #include diff --git a/libs/binder/IPermissionController.cpp b/libs/binder/IPermissionController.cpp index 6b5dd8e..a61debf 100644 --- a/libs/binder/IPermissionController.cpp +++ b/libs/binder/IPermissionController.cpp @@ -16,11 +16,11 @@ #define LOG_TAG "PermissionController" -#include +#include #include #include -#include +#include #include #include diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index f2d0c27..2f265b8 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -16,12 +16,12 @@ #define LOG_TAG "ServiceManager" -#include +#include #include -#include +#include #include -#include +#include #include #include diff --git a/libs/binder/MemoryBase.cpp b/libs/binder/MemoryBase.cpp index f25e11c..033066b 100644 --- a/libs/binder/MemoryBase.cpp +++ b/libs/binder/MemoryBase.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include namespace android { diff --git a/libs/binder/MemoryDealer.cpp b/libs/binder/MemoryDealer.cpp index cf8201b..fd6ab7a 100644 --- a/libs/binder/MemoryDealer.cpp +++ b/libs/binder/MemoryDealer.cpp @@ -16,13 +16,13 @@ #define LOG_TAG "MemoryDealer" -#include +#include #include -#include +#include #include #include -#include +#include #include #include diff --git a/libs/binder/MemoryHeapBase.cpp b/libs/binder/MemoryHeapBase.cpp index 8251728..ac38f51 100644 --- a/libs/binder/MemoryHeapBase.cpp +++ b/libs/binder/MemoryHeapBase.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #if HAVE_ANDROID_OS #include diff --git a/libs/binder/MemoryHeapPmem.cpp b/libs/binder/MemoryHeapPmem.cpp index eba2b30..599c9ae 100644 --- a/libs/binder/MemoryHeapPmem.cpp +++ b/libs/binder/MemoryHeapPmem.cpp @@ -27,8 +27,8 @@ #include -#include -#include +#include +#include #if HAVE_ANDROID_OS #include diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index cea5277..d29ec8c 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -17,12 +17,12 @@ #define LOG_TAG "Parcel" //#define LOG_NDEBUG 0 -#include +#include -#include -#include +#include +#include #include -#include +#include #include #include #include diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index 3a99e24..d7daf73 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -18,14 +18,14 @@ #include -#include +#include #include -#include -#include +#include +#include #include #include -#include +#include #include #include diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp index ff2a046..12b0308 100644 --- a/libs/binder/Static.cpp +++ b/libs/binder/Static.cpp @@ -19,7 +19,7 @@ #include -#include +#include #include namespace android { diff --git a/libs/surfaceflinger/GPUHardware/GPUHardware.cpp b/libs/surfaceflinger/GPUHardware/GPUHardware.cpp index 7168bf2..2de628b 100644 --- a/libs/surfaceflinger/GPUHardware/GPUHardware.cpp +++ b/libs/surfaceflinger/GPUHardware/GPUHardware.cpp @@ -30,12 +30,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/libs/surfaceflinger/LayerBitmap.cpp b/libs/surfaceflinger/LayerBitmap.cpp index e844350..e3d0f77 100644 --- a/libs/surfaceflinger/LayerBitmap.cpp +++ b/libs/surfaceflinger/LayerBitmap.cpp @@ -23,8 +23,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/libs/surfaceflinger/LayerBuffer.cpp b/libs/surfaceflinger/LayerBuffer.cpp index 00fab70..bac544a 100644 --- a/libs/surfaceflinger/LayerBuffer.cpp +++ b/libs/surfaceflinger/LayerBuffer.cpp @@ -25,8 +25,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/libs/surfaceflinger/LayerBuffer.h b/libs/surfaceflinger/LayerBuffer.h index 2dc77f1..f74d6a1 100644 --- a/libs/surfaceflinger/LayerBuffer.h +++ b/libs/surfaceflinger/LayerBuffer.h @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include diff --git a/libs/surfaceflinger/LayerOrientationAnim.h b/libs/surfaceflinger/LayerOrientationAnim.h index 365c6ae..e86156d 100644 --- a/libs/surfaceflinger/LayerOrientationAnim.h +++ b/libs/surfaceflinger/LayerOrientationAnim.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "LayerBase.h" #include "LayerBitmap.h" diff --git a/libs/surfaceflinger/LayerOrientationAnimRotate.h b/libs/surfaceflinger/LayerOrientationAnimRotate.h index 5fbbd42..3296f45 100644 --- a/libs/surfaceflinger/LayerOrientationAnimRotate.h +++ b/libs/surfaceflinger/LayerOrientationAnimRotate.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "LayerBase.h" #include "LayerBitmap.h" diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp index 54b33ce..37d1ded 100644 --- a/libs/surfaceflinger/SurfaceFlinger.cpp +++ b/libs/surfaceflinger/SurfaceFlinger.cpp @@ -31,10 +31,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h index e023182..927908d 100644 --- a/libs/surfaceflinger/SurfaceFlinger.h +++ b/libs/surfaceflinger/SurfaceFlinger.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include diff --git a/libs/surfaceflinger/VRamHeap.cpp b/libs/surfaceflinger/VRamHeap.cpp index 238c602..7132d0d 100644 --- a/libs/surfaceflinger/VRamHeap.cpp +++ b/libs/surfaceflinger/VRamHeap.cpp @@ -30,10 +30,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "GPUHardware/GPUHardware.h" #include "SurfaceFlinger.h" diff --git a/libs/surfaceflinger/VRamHeap.h b/libs/surfaceflinger/VRamHeap.h index 9140167..780a1bc 100644 --- a/libs/surfaceflinger/VRamHeap.h +++ b/libs/surfaceflinger/VRamHeap.h @@ -19,7 +19,7 @@ #include #include -#include +#include namespace android { diff --git a/libs/surfaceflinger/tests/overlays/overlays.cpp b/libs/surfaceflinger/tests/overlays/overlays.cpp index f3c046f..0b9322e 100644 --- a/libs/surfaceflinger/tests/overlays/overlays.cpp +++ b/libs/surfaceflinger/tests/overlays/overlays.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include #include diff --git a/libs/ui/Camera.cpp b/libs/ui/Camera.cpp index 6613700..4228300 100644 --- a/libs/ui/Camera.cpp +++ b/libs/ui/Camera.cpp @@ -19,9 +19,9 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "Camera" #include -#include +#include #include -#include +#include #include #include #include diff --git a/libs/ui/EventHub.cpp b/libs/ui/EventHub.cpp index 7c2fc8e..52aa0c0 100644 --- a/libs/ui/EventHub.cpp +++ b/libs/ui/EventHub.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/libs/ui/ICamera.cpp b/libs/ui/ICamera.cpp index ab0fef1..cbe8798 100644 --- a/libs/ui/ICamera.cpp +++ b/libs/ui/ICamera.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include namespace android { diff --git a/libs/ui/ICameraService.cpp b/libs/ui/ICameraService.cpp index e5687fe..1adb4aa 100644 --- a/libs/ui/ICameraService.cpp +++ b/libs/ui/ICameraService.cpp @@ -18,9 +18,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include diff --git a/libs/ui/IOverlay.cpp b/libs/ui/IOverlay.cpp index fed47c2..a20b36c 100644 --- a/libs/ui/IOverlay.cpp +++ b/libs/ui/IOverlay.cpp @@ -18,8 +18,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/libs/ui/ISurface.cpp b/libs/ui/ISurface.cpp index d5e9f81..a71cf20 100644 --- a/libs/ui/ISurface.cpp +++ b/libs/ui/ISurface.cpp @@ -18,8 +18,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/libs/ui/ISurfaceComposer.cpp b/libs/ui/ISurfaceComposer.cpp index 76597e1..4b7f3a2 100644 --- a/libs/ui/ISurfaceComposer.cpp +++ b/libs/ui/ISurfaceComposer.cpp @@ -20,10 +20,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/libs/ui/ISurfaceFlingerClient.cpp b/libs/ui/ISurfaceFlingerClient.cpp index dd6a798..69731ab 100644 --- a/libs/ui/ISurfaceFlingerClient.cpp +++ b/libs/ui/ISurfaceFlingerClient.cpp @@ -21,10 +21,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/libs/ui/LayerState.cpp b/libs/ui/LayerState.cpp index 0b6374b..a53ffb7 100644 --- a/libs/ui/LayerState.cpp +++ b/libs/ui/LayerState.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include namespace android { diff --git a/libs/ui/Overlay.cpp b/libs/ui/Overlay.cpp index b236edc..9fae416 100644 --- a/libs/ui/Overlay.cpp +++ b/libs/ui/Overlay.cpp @@ -14,10 +14,10 @@ * limitations under the License. */ -#include -#include +#include +#include #include -#include +#include #include #include diff --git a/libs/ui/Surface.cpp b/libs/ui/Surface.cpp index 4ea9ae2..05cc529 100644 --- a/libs/ui/Surface.cpp +++ b/libs/ui/Surface.cpp @@ -26,8 +26,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/libs/ui/SurfaceComposerClient.cpp b/libs/ui/SurfaceComposerClient.cpp index fe803ff..8acd2ee 100644 --- a/libs/ui/SurfaceComposerClient.cpp +++ b/libs/ui/SurfaceComposerClient.cpp @@ -29,9 +29,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -48,7 +48,7 @@ #include -#include +#include #define VERBOSE(...) ((void)0) //#define VERBOSE LOGD diff --git a/libs/ui/SurfaceFlingerSynchro.cpp b/libs/ui/SurfaceFlingerSynchro.cpp index 5cd9755..2e8fa12 100644 --- a/libs/ui/SurfaceFlingerSynchro.cpp +++ b/libs/ui/SurfaceFlingerSynchro.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/opengl/libs/EGL/gpu.cpp b/opengl/libs/EGL/gpu.cpp index f9dc5f1..20d76bc 100644 --- a/opengl/libs/EGL/gpu.cpp +++ b/opengl/libs/EGL/gpu.cpp @@ -29,11 +29,11 @@ #include #include -#include +#include #include -#include -#include -#include +#include +#include +#include #include #include -- cgit v1.1