diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/android/sensor.h | 24 | ||||
-rw-r--r-- | include/gui/BufferQueue.h | 7 | ||||
-rw-r--r-- | include/gui/BufferQueueConsumer.h | 5 | ||||
-rw-r--r-- | include/gui/BufferQueueCore.h | 6 | ||||
-rw-r--r-- | include/gui/ConsumerBase.h | 31 | ||||
-rw-r--r-- | include/gui/GLConsumer.h | 3 | ||||
-rw-r--r-- | include/gui/IGraphicBufferConsumer.h | 14 | ||||
-rw-r--r-- | include/gui/SensorManager.h | 57 |
8 files changed, 110 insertions, 37 deletions
diff --git a/include/android/sensor.h b/include/android/sensor.h index 969677f..1be6232 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -193,6 +193,30 @@ typedef ASensorRef const* ASensorList; /*****************************************************************************/ /* + * Get a reference to the sensor manager. ASensorManager is a singleton + * per package as different packages may have access to different sensors. + * + * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead. + * + * Example: + * + * ASensorManager* sensorManager = ASensorManager_getInstance(); + * + */ +__attribute__ ((deprecated)) ASensorManager* ASensorManager_getInstance(); + +/* + * Get a reference to the sensor manager. ASensorManager is a singleton + * per package as different packages may have access to different sensors. + * + * Example: + * + * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz"); + * + */ +ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName); + +/* * Returns the list of available sensors. */ int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); 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 0f42613..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); @@ -148,9 +148,6 @@ public: // Retrieve the sideband buffer stream, if any. virtual sp<NativeHandle> getSidebandStream() const; - // See IGraphicBufferConsumer::setShadowQueueSize - virtual void setShadowQueueSize(size_t size); - // dump our state in a String virtual void dump(String8& result, const char* prefix) const; diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h index a22015c..d7686ec 100644 --- a/include/gui/BufferQueueCore.h +++ b/include/gui/BufferQueueCore.h @@ -275,12 +275,6 @@ private: // buffer as the number of frames that have elapsed since it was last queued uint64_t mBufferAge; - // mConsumerHasShadowQueue determines if acquireBuffer should be more - // cautious about dropping buffers so that it always returns a buffer that - // is represented in the consumer's shadow queue. - bool mConsumerHasShadowQueue; - size_t mConsumerShadowQueueSize; - }; // class BufferQueueCore } // namespace android diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h index d56fa89..f46bf01 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(); @@ -104,14 +98,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 +152,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/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 0be09a2..6363a3a 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 @@ -248,11 +255,6 @@ public: // Retrieve the sideband buffer stream, if any. virtual sp<NativeHandle> getSidebandStream() const = 0; - // setShadowQueueSize notifies the BufferQueue that the consumer is - // shadowing its queue and allows it to limit the number of buffers it is - // permitted to drop during acquire so as to not get out of sync. - virtual void setShadowQueueSize(size_t size) = 0; - // dump state into a string virtual void dump(String8& result, const char* prefix) const = 0; diff --git a/include/gui/SensorManager.h b/include/gui/SensorManager.h index d0c63d4..4c34e12 100644 --- a/include/gui/SensorManager.h +++ b/include/gui/SensorManager.h @@ -17,10 +17,14 @@ #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> @@ -47,6 +51,56 @@ class SensorManager : public ASensorManager { public: + 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(); @@ -62,6 +116,9 @@ 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; |