diff options
Diffstat (limited to 'include/gui')
-rw-r--r-- | include/gui/BufferItem.h | 16 | ||||
-rw-r--r-- | include/gui/BufferItemConsumer.h | 15 | ||||
-rw-r--r-- | include/gui/BufferQueue.h | 7 | ||||
-rw-r--r-- | include/gui/BufferQueueConsumer.h | 2 | ||||
-rw-r--r-- | include/gui/BufferQueueCore.h | 10 | ||||
-rw-r--r-- | include/gui/BufferQueueProducer.h | 6 | ||||
-rw-r--r-- | include/gui/ConsumerBase.h | 43 | ||||
-rw-r--r-- | include/gui/CpuConsumer.h | 17 | ||||
-rw-r--r-- | include/gui/GLConsumer.h | 3 | ||||
-rw-r--r-- | include/gui/IGraphicBufferConsumer.h | 12 | ||||
-rw-r--r-- | include/gui/IGraphicBufferProducer.h | 17 | ||||
-rw-r--r-- | include/gui/ISensorServer.h | 7 | ||||
-rw-r--r-- | include/gui/Sensor.h | 4 | ||||
-rw-r--r-- | include/gui/SensorEventQueue.h | 5 | ||||
-rw-r--r-- | include/gui/SensorManager.h | 68 | ||||
-rw-r--r-- | include/gui/Surface.h | 14 |
16 files changed, 177 insertions, 69 deletions
diff --git a/include/gui/BufferItem.h b/include/gui/BufferItem.h index 000ef0e..145efe6 100644 --- a/include/gui/BufferItem.h +++ b/include/gui/BufferItem.h @@ -72,7 +72,13 @@ class BufferItem : public Flattenable<BufferItem> { // to set by queueBuffer each time this slot is queued. This value // is guaranteed to be monotonically increasing for each newly // acquired buffer. - int64_t mTimestamp; + union { + int64_t mTimestamp; + struct { + uint32_t mTimestampLo; + uint32_t mTimestampHi; + }; + }; // mIsAutoTimestamp indicates whether mTimestamp was generated // automatically when the buffer was queued. @@ -84,7 +90,13 @@ class BufferItem : public Flattenable<BufferItem> { android_dataspace mDataSpace; // mFrameNumber is the number of the queued frame for this slot. - uint64_t mFrameNumber; + union { + uint64_t mFrameNumber; + struct { + uint32_t mFrameNumberLo; + uint32_t mFrameNumberHi; + }; + }; union { // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT). diff --git a/include/gui/BufferItemConsumer.h b/include/gui/BufferItemConsumer.h index 930fabf..56c7a3f 100644 --- a/include/gui/BufferItemConsumer.h +++ b/include/gui/BufferItemConsumer.h @@ -86,21 +86,6 @@ class BufferItemConsumer: public ConsumerBase status_t releaseBuffer(const BufferItem &item, const sp<Fence>& releaseFence = Fence::NO_FENCE); - // setDefaultBufferSize is used to set the size of buffers returned by - // requestBuffers when a with and height of zero is requested. - status_t setDefaultBufferSize(uint32_t w, uint32_t h); - - // setDefaultBufferFormat allows the BufferQueue to create - // GraphicBuffers of a defaultFormat if no format is specified - // in dequeueBuffer - status_t setDefaultBufferFormat(PixelFormat defaultFormat); - - // setDefaultBufferDataSpace allows the BufferQueue to create - // GraphicBuffers of a defaultDataSpace if no data space is specified - // in queueBuffer. - // The initial default is HAL_DATASPACE_UNKNOWN - status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace); - }; } // namespace android diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h index 721b218..09300a2 100644 --- a/include/gui/BufferQueue.h +++ b/include/gui/BufferQueue.h @@ -62,9 +62,10 @@ public: public: ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); virtual ~ProxyConsumerListener(); - virtual void onFrameAvailable(const BufferItem& item); - virtual void onBuffersReleased(); - virtual void onSidebandStreamChanged(); + virtual void onFrameAvailable(const BufferItem& item) override; + virtual void onFrameReplaced(const BufferItem& item) override; + virtual void onBuffersReleased() override; + virtual void onSidebandStreamChanged() override; private: // mConsumerListener is a weak reference to the IConsumerListener. This is // the raison d'etre of ProxyConsumerListener. diff --git a/include/gui/BufferQueueConsumer.h b/include/gui/BufferQueueConsumer.h index 9c91fc7..cde302f 100644 --- a/include/gui/BufferQueueConsumer.h +++ b/include/gui/BufferQueueConsumer.h @@ -47,7 +47,7 @@ public: // returned. The presentation time is in nanoseconds, and the time base // is CLOCK_MONOTONIC. virtual status_t acquireBuffer(BufferItem* outBuffer, - nsecs_t expectedPresent); + nsecs_t expectedPresent, uint64_t maxFrameNumber = 0) override; // See IGraphicBufferConsumer::detachBuffer virtual status_t detachBuffer(int slot); diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h index 9a43516..99134ea 100644 --- a/include/gui/BufferQueueCore.h +++ b/include/gui/BufferQueueCore.h @@ -270,6 +270,16 @@ private: // mAllowAllocation determines whether dequeueBuffer is allowed to allocate // new buffers bool mAllowAllocation; + + // mBufferAge tracks the age of the contents of the most recently dequeued + // buffer as the number of frames that have elapsed since it was last queued + uint64_t mBufferAge; + + // mGenerationNumber stores the current generation number of the attached + // producer. Any attempt to attach a buffer with a different generation + // number will fail. + uint32_t mGenerationNumber; + }; // class BufferQueueCore } // namespace android diff --git a/include/gui/BufferQueueProducer.h b/include/gui/BufferQueueProducer.h index ed660fb..9754a89 100644 --- a/include/gui/BufferQueueProducer.h +++ b/include/gui/BufferQueueProducer.h @@ -175,6 +175,12 @@ public: // See IGraphicBufferProducer::allowAllocation virtual status_t allowAllocation(bool allow); + // See IGraphicBufferProducer::setGenerationNumber + virtual status_t setGenerationNumber(uint32_t generationNumber); + + // See IGraphicBufferProducer::getConsumerName + virtual String8 getConsumerName() const override; + private: // This is required by the IBinder::DeathRecipient interface virtual void binderDied(const wp<IBinder>& who); diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h index d56fa89..9307a26 100644 --- a/include/gui/ConsumerBase.h +++ b/include/gui/ConsumerBase.h @@ -38,15 +38,9 @@ class ConsumerBase : public virtual RefBase, protected ConsumerListener { public: struct FrameAvailableListener : public virtual RefBase { - // onFrameAvailable() is called each time an additional frame becomes - // available for consumption. This means that frames that are queued - // while in asynchronous mode only trigger the callback if no previous - // frames are pending. Frames queued while in synchronous mode always - // trigger the callback. - // - // This is called without any lock held and can be called concurrently - // by multiple threads. + // See IConsumerListener::onFrame{Available,Replaced} virtual void onFrameAvailable(const BufferItem& item) = 0; + virtual void onFrameReplaced(const BufferItem& /* item */) {} }; virtual ~ConsumerBase(); @@ -62,6 +56,9 @@ public: // or by OpenGL ES as a texture) then those buffer will remain allocated. void abandon(); + // Returns true if the ConsumerBase is in the 'abandoned' state + bool isAbandoned(); + // set the name of the ConsumerBase that will be used to identify it in // log messages. void setName(const String8& name); @@ -79,6 +76,15 @@ public: // See IGraphicBufferConsumer::detachBuffer status_t detachBuffer(int slot); + // See IGraphicBufferConsumer::setDefaultBufferSize + status_t setDefaultBufferSize(uint32_t width, uint32_t height); + + // See IGraphicBufferConsumer::setDefaultBufferFormat + status_t setDefaultBufferFormat(PixelFormat defaultFormat); + + // See IGraphicBufferConsumer::setDefaultBufferDataSpace + status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace); + private: ConsumerBase(const ConsumerBase&); void operator=(const ConsumerBase&); @@ -104,14 +110,16 @@ protected: // Implementation of the IConsumerListener interface. These // calls are used to notify the ConsumerBase of asynchronous events in the - // BufferQueue. The onFrameAvailable and onBuffersReleased methods should - // not need to be overridden by derived classes, but if they are overridden - // the ConsumerBase implementation must be called from the derived class. - // The ConsumerBase version of onSidebandStreamChanged does nothing and can - // be overriden by derived classes if they want the notification. - virtual void onFrameAvailable(const BufferItem& item); - virtual void onBuffersReleased(); - virtual void onSidebandStreamChanged(); + // BufferQueue. The onFrameAvailable, onFrameReplaced, and + // onBuffersReleased methods should not need to be overridden by derived + // classes, but if they are overridden the ConsumerBase implementation must + // be called from the derived class. The ConsumerBase version of + // onSidebandStreamChanged does nothing and can be overriden by derived + // classes if they want the notification. + virtual void onFrameAvailable(const BufferItem& item) override; + virtual void onFrameReplaced(const BufferItem& item) override; + virtual void onBuffersReleased() override; + virtual void onSidebandStreamChanged() override; // freeBufferLocked frees up the given buffer slot. If the slot has been // initialized this will release the reference to the GraphicBuffer in that @@ -156,7 +164,8 @@ protected: // initialization that must take place the first time a buffer is assigned // to a slot. If it is overridden the derived class's implementation must // call ConsumerBase::acquireBufferLocked. - virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen); + virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen, + uint64_t maxFrameNumber = 0); // releaseBufferLocked relinquishes control over a buffer, returning that // control to the BufferQueue. diff --git a/include/gui/CpuConsumer.h b/include/gui/CpuConsumer.h index c99ab29..3b07a31 100644 --- a/include/gui/CpuConsumer.h +++ b/include/gui/CpuConsumer.h @@ -80,23 +80,6 @@ class CpuConsumer : public ConsumerBase // log messages. void setName(const String8& name); - // setDefaultBufferSize is used to set the size of buffers returned by - // requestBuffers when a width and height of zero is requested. - // A call to setDefaultBufferSize() may trigger requestBuffers() to - // be called from the client. Default size is 1x1. - status_t setDefaultBufferSize(uint32_t width, uint32_t height); - - // setDefaultBufferFormat allows CpuConsumer's BufferQueue to create buffers - // of a defaultFormat if no format is specified by producer. - // The initial default is PIXEL_FORMAT_RGBA_8888. - status_t setDefaultBufferFormat(PixelFormat defaultFormat); - - // setDefaultBufferDataSpace allows the BufferQueue to create - // GraphicBuffers of a defaultDataSpace if no data space is specified - // in queueBuffer. - // The initial default is HAL_DATASPACE_UNKNOWN - status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace); - // Gets the next graphics buffer from the producer and locks it for CPU use, // filling out the passed-in locked buffer structure with the native pointer // and metadata. Returns BAD_VALUE if no new buffer is available, and diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h index 4912580..c35c7be 100644 --- a/include/gui/GLConsumer.h +++ b/include/gui/GLConsumer.h @@ -241,7 +241,8 @@ protected: // acquireBufferLocked overrides the ConsumerBase method to update the // mEglSlots array in addition to the ConsumerBase behavior. - virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen); + virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen, + uint64_t maxFrameNumber = 0) override; // releaseBufferLocked overrides the ConsumerBase method to update the // mEglSlots array in addition to the ConsumerBase. diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h index 8f31b55..60ec9cc 100644 --- a/include/gui/IGraphicBufferConsumer.h +++ b/include/gui/IGraphicBufferConsumer.h @@ -69,6 +69,12 @@ public: // returned. The presentation time is in nanoseconds, and the time base // is CLOCK_MONOTONIC. // + // If maxFrameNumber is non-zero, it indicates that acquireBuffer should + // only return a buffer with a frame number less than or equal to + // maxFrameNumber. If no such frame is available (such as when a buffer has + // been replaced but the consumer has not received the onFrameReplaced + // callback), then PRESENT_LATER will be returned. + // // Return of NO_ERROR means the operation completed as normal. // // Return of a positive value means the operation could not be completed @@ -78,7 +84,8 @@ public: // // Return of a negative value means an error has occurred: // * INVALID_OPERATION - too many buffers have been acquired - virtual status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen) = 0; + virtual status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen, + uint64_t maxFrameNumber = 0) = 0; // detachBuffer attempts to remove all ownership of the buffer in the given // slot from the buffer queue. If this call succeeds, the slot will be @@ -103,7 +110,8 @@ public: // will be deallocated as stale. // // Return of a value other than NO_ERROR means an error has occurred: - // * BAD_VALUE - outSlot or buffer were NULL + // * BAD_VALUE - outSlot or buffer were NULL, or the generation number of + // the buffer did not match the buffer queue. // * INVALID_OPERATION - cannot attach the buffer because it would cause too // many buffers to be acquired. // * NO_MEMORY - no free slots available diff --git a/include/gui/IGraphicBufferProducer.h b/include/gui/IGraphicBufferProducer.h index 5c50b2b..9530de1 100644 --- a/include/gui/IGraphicBufferProducer.h +++ b/include/gui/IGraphicBufferProducer.h @@ -218,8 +218,9 @@ public: // // Return of a negative value means an error has occurred: // * NO_INIT - the buffer queue has been abandoned. - // * BAD_VALUE - outSlot or buffer were NULL or invalid combination of - // async mode and buffer count override. + // * BAD_VALUE - outSlot or buffer were NULL, invalid combination of + // async mode and buffer count override, or the generation + // number of the buffer did not match the buffer queue. // * INVALID_OPERATION - cannot attach the buffer because it would cause // too many buffers to be dequeued, either because // the producer already has a single buffer dequeued @@ -470,6 +471,18 @@ public: // eligible slot is available, dequeueBuffer will block or return an error // as usual. virtual status_t allowAllocation(bool allow) = 0; + + // Sets the current generation number of the BufferQueue. + // + // This generation number will be inserted into any buffers allocated by the + // BufferQueue, and any attempts to attach a buffer with a different + // generation number will fail. Buffers already in the queue are not + // affected and will retain their current generation number. The generation + // number defaults to 0. + virtual status_t setGenerationNumber(uint32_t generationNumber) = 0; + + // Returns the name of the connected consumer. + virtual String8 getConsumerName() const = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/gui/ISensorServer.h b/include/gui/ISensorServer.h index 9c8afc5..3dca2a3 100644 --- a/include/gui/ISensorServer.h +++ b/include/gui/ISensorServer.h @@ -30,14 +30,17 @@ namespace android { class Sensor; class ISensorEventConnection; +class String8; class ISensorServer : public IInterface { public: DECLARE_META_INTERFACE(SensorServer); - virtual Vector<Sensor> getSensorList() = 0; - virtual sp<ISensorEventConnection> createSensorEventConnection() = 0; + virtual Vector<Sensor> getSensorList(const String16& opPackageName) = 0; + virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName, + int mode, const String16& opPackageName) = 0; + virtual int32_t isDataInjectionEnabled() = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/gui/Sensor.h b/include/gui/Sensor.h index 27a215e..8142be6 100644 --- a/include/gui/Sensor.h +++ b/include/gui/Sensor.h @@ -71,6 +71,8 @@ public: uint32_t getFifoMaxEventCount() const; const String8& getStringType() const; const String8& getRequiredPermission() const; + bool isRequiredPermissionRuntime() const; + int32_t getRequiredAppOp() const; int32_t getMaxDelay() const; uint32_t getFlags() const; bool isWakeUpSensor() const; @@ -97,6 +99,8 @@ private: uint32_t mFifoMaxEventCount; String8 mStringType; String8 mRequiredPermission; + bool mRequiredPermissionRuntime = false; + int32_t mRequiredAppOp; int32_t mMaxDelay; uint32_t mFlags; static void flattenString8(void*& buffer, size_t& size, const String8& string8); diff --git a/include/gui/SensorEventQueue.h b/include/gui/SensorEventQueue.h index 02b3d38..e5b9fc5 100644 --- a/include/gui/SensorEventQueue.h +++ b/include/gui/SensorEventQueue.h @@ -23,6 +23,7 @@ #include <utils/Errors.h> #include <utils/RefBase.h> #include <utils/Timers.h> +#include <utils/String16.h> #include <gui/BitTube.h> @@ -52,7 +53,7 @@ public: enum { MAX_RECEIVE_BUFFER_EVENT_COUNT = 256 }; - SensorEventQueue(const sp<ISensorEventConnection>& connection); + SensorEventQueue(const sp<ISensorEventConnection>& connection); virtual ~SensorEventQueue(); virtual void onFirstRef(); @@ -77,6 +78,8 @@ public: status_t flush() const; // Send an ack for every wake_up sensor event that is set to WAKE_UP_SENSOR_EVENT_NEEDS_ACK. void sendAck(const ASensorEvent* events, int count); + + status_t injectSensorEvent(const ASensorEvent& event); private: sp<Looper> getLooper() const; sp<ISensorEventConnection> mSensorEventConnection; diff --git a/include/gui/SensorManager.h b/include/gui/SensorManager.h index 3176462..3796067 100644 --- a/include/gui/SensorManager.h +++ b/include/gui/SensorManager.h @@ -17,15 +17,20 @@ #ifndef ANDROID_GUI_SENSOR_MANAGER_H #define ANDROID_GUI_SENSOR_MANAGER_H +#include <map> + #include <stdint.h> #include <sys/types.h> #include <binder/IBinder.h> +#include <binder/IPCThreadState.h> +#include <binder/IServiceManager.h> #include <utils/Errors.h> #include <utils/RefBase.h> #include <utils/Singleton.h> #include <utils/Vector.h> +#include <utils/String8.h> #include <gui/SensorEventQueue.h> @@ -40,20 +45,69 @@ namespace android { class ISensorServer; class Sensor; class SensorEventQueue; - // ---------------------------------------------------------------------------- class SensorManager : - public ASensorManager, - public Singleton<SensorManager> + public ASensorManager { public: - SensorManager(); + static SensorManager& getInstanceForPackage(const String16& packageName) { + Mutex::Autolock _l(sLock); + + SensorManager* sensorManager; + std::map<String16, SensorManager*>::iterator iterator = + sPackageInstances.find(packageName); + + if (iterator != sPackageInstances.end()) { + sensorManager = iterator->second; + } else { + String16 opPackageName = packageName; + + // It is possible that the calling code has no access to the package name. + // In this case we will get the packages for the calling UID and pick the + // first one for attributing the app op. This will work correctly for + // runtime permissions as for legacy apps we will toggle the app op for + // all packages in the UID. The caveat is that the operation may be attributed + // to the wrong package and stats based on app ops may be slightly off. + if (opPackageName.size() <= 0) { + sp<IBinder> binder = defaultServiceManager()->getService(String16("permission")); + if (binder != 0) { + const uid_t uid = IPCThreadState::self()->getCallingUid(); + Vector<String16> packages; + interface_cast<IPermissionController>(binder)->getPackagesForUid(uid, packages); + if (!packages.isEmpty()) { + opPackageName = packages[0]; + } else { + ALOGE("No packages for calling UID"); + } + } else { + ALOGE("Cannot get permission service"); + } + } + + sensorManager = new SensorManager(opPackageName); + + // If we had no package name, we looked it up from the UID and the sensor + // manager instance we created should also be mapped to the empty package + // name, to avoid looking up the packages for a UID and get the same result. + if (packageName.size() <= 0) { + sPackageInstances.insert(std::make_pair(String16(), sensorManager)); + } + + // Stash the per package sensor manager. + sPackageInstances.insert(std::make_pair(opPackageName, sensorManager)); + } + + return *sensorManager; + } + + SensorManager(const String16& opPackageName); ~SensorManager(); ssize_t getSensorList(Sensor const* const** list) const; Sensor const* getDefaultSensor(int type); - sp<SensorEventQueue> createEventQueue(); + sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0); + bool isDataInjectionEnabled(); private: // DeathRecipient interface @@ -62,11 +116,15 @@ private: status_t assertStateLocked() const; private: + static Mutex sLock; + static std::map<String16, SensorManager*> sPackageInstances; + mutable Mutex mLock; mutable sp<ISensorServer> mSensorServer; mutable Sensor const** mSensorList; mutable Vector<Sensor> mSensors; mutable sp<IBinder::DeathRecipient> mDeathObserver; + const String16 mOpPackageName; }; // ---------------------------------------------------------------------------- diff --git a/include/gui/Surface.h b/include/gui/Surface.h index a9f78cf..72f1067 100644 --- a/include/gui/Surface.h +++ b/include/gui/Surface.h @@ -101,6 +101,14 @@ public: */ void allocateBuffers(); + /* Sets the generation number on the IGraphicBufferProducer and updates the + * generation number on any buffers attached to the Surface after this call. + * See IGBP::setGenerationNumber for more information. */ + status_t setGenerationNumber(uint32_t generationNumber); + + // See IGraphicBufferProducer::getConsumerName + String8 getConsumerName() const; + protected: virtual ~Surface(); @@ -179,7 +187,7 @@ public: virtual int unlockAndPost(); virtual int connect(int api, const sp<IProducerListener>& listener); - virtual int detachNextBuffer(ANativeWindowBuffer** outBuffer, + virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence); virtual int attachBuffer(ANativeWindowBuffer*); @@ -305,6 +313,10 @@ private: // When a non-CPU producer is attached, this reflects the surface damage // (the change since the previous frame) passed in by the producer. Region mDirtyRegion; + + // Stores the current generation number. See setGenerationNumber and + // IGraphicBufferProducer::setGenerationNumber for more information. + uint32_t mGenerationNumber; }; }; // namespace android |