From 6d09ca8663deea6b27917c5bf21223ae41c2b1df Mon Sep 17 00:00:00 2001 From: Dan Stoza Date: Fri, 1 May 2015 16:42:55 -0700 Subject: [PATCH 1/4] libgui: Clear frame number while freeing slot Clears the frame number of a slot when it is freed, since it is used to determine if a released buffer is stale. Bug: 20445852 Change-Id: I02415e7b25a1eafe7414d6eb1cedf62ac5543cd9 --- libs/gui/BufferQueueConsumer.cpp | 4 +++- libs/gui/BufferQueueCore.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp index 2deef0e77..336ddb667 100644 --- a/libs/gui/BufferQueueConsumer.cpp +++ b/libs/gui/BufferQueueConsumer.cpp @@ -306,6 +306,8 @@ status_t BufferQueueConsumer::releaseBuffer(int slot, uint64_t frameNumber, if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS || releaseFence == NULL) { + BQ_LOGE("releaseBuffer: slot %d out of range or fence %p NULL", slot, + releaseFence.get()); return BAD_VALUE; } @@ -344,7 +346,7 @@ status_t BufferQueueConsumer::releaseBuffer(int slot, uint64_t frameNumber, mSlots[slot].mNeedsCleanupOnRelease = false; return STALE_BUFFER_SLOT; } else { - BQ_LOGV("releaseBuffer: attempted to release buffer slot %d " + BQ_LOGE("releaseBuffer: attempted to release buffer slot %d " "but its state was %d", slot, mSlots[slot].mBufferState); return BAD_VALUE; } diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp index d0f7afad4..37171edd1 100644 --- a/libs/gui/BufferQueueCore.cpp +++ b/libs/gui/BufferQueueCore.cpp @@ -214,6 +214,7 @@ void BufferQueueCore::freeBufferLocked(int slot) { } mSlots[slot].mBufferState = BufferSlot::FREE; mSlots[slot].mAcquireCalled = false; + mSlots[slot].mFrameNumber = 0; // Destroy fence as BufferQueue now takes ownership if (mSlots[slot].mEglFence != EGL_NO_SYNC_KHR) { From 37c6aaad742fc893b61b9306cd021b7de3c2bc40 Mon Sep 17 00:00:00 2001 From: Svet Ganov Date: Thu, 7 May 2015 10:50:59 -0700 Subject: [PATCH 2/4] Fix broken NDK sensor manager API. Change-Id: I21bb8b0dcfd3f1c812753a9fd77dea792e7155f2 --- include/android/sensor.h | 24 ++++++++++++++++ include/gui/SensorManager.h | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/include/android/sensor.h b/include/android/sensor.h index 969677f6d..1be623221 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -192,6 +192,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. */ diff --git a/include/gui/SensorManager.h b/include/gui/SensorManager.h index d0c63d4bc..4c34e1247 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 + #include #include #include +#include +#include #include #include @@ -47,6 +51,56 @@ class SensorManager : public ASensorManager { public: + static SensorManager& getInstanceForPackage(const String16& packageName) { + Mutex::Autolock _l(sLock); + + SensorManager* sensorManager; + std::map::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 binder = defaultServiceManager()->getService(String16("permission")); + if (binder != 0) { + const uid_t uid = IPCThreadState::self()->getCallingUid(); + Vector packages; + interface_cast(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 sPackageInstances; + mutable Mutex mLock; mutable sp mSensorServer; mutable Sensor const** mSensorList; From 8a715c64eb0242f22e4ce0135fbf007ffb233971 Mon Sep 17 00:00:00 2001 From: Michael Lentine Date: Thu, 28 May 2015 16:48:08 -0700 Subject: [PATCH 3/4] Revert "Modify EGL to disconnect the window when the surface gets destroyed." This reverts commit 00699fa64197cc72a160d69e1f0003cdd43dc136. --- libs/gui/BufferQueueProducer.cpp | 4 ++-- opengl/libs/EGL/eglApi.cpp | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 2cf7433b4..e318484d4 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -914,8 +914,8 @@ status_t BufferQueueProducer::disconnect(int api) { mCore->mSidebandStream.clear(); mCore->mDequeueCondition.broadcast(); listener = mCore->mConsumerListener; - } else if (mCore->mConnectedApi != BufferQueueCore::NO_CONNECTED_API) { - BQ_LOGE("disconnect(P): still connected to another API " + } else { + BQ_LOGE("disconnect(P): connected to another API " "(cur=%d req=%d)", mCore->mConnectedApi, api); status = BAD_VALUE; } diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index 8dd052cb6..544463133 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -562,15 +562,6 @@ EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) return setError(EGL_BAD_SURFACE, EGL_FALSE); egl_surface_t * const s = get_surface(surface); - ANativeWindow* window = s->win.get(); - if (window) { - int result = native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); - if (result != OK) { - ALOGE("eglDestroySurface: native_window_api_disconnect (win=%p) " - "failed (%#x)", - window, result); - } - } EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); if (result == EGL_TRUE) { _s.terminate(); From 5a373bb9b0ffb9a58686079c971aaa4d8788218f Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Wed, 29 Jul 2015 09:36:05 +0000 Subject: [PATCH 4/4] Revert "Bug fix in SensorManager." This reverts commit 869eb2089ec8a6286b944bfcff57e4cbe0c7e207. Change-Id: I4fb865e3b18bbb011fa4e4b4732336930c3a45ae --- include/gui/SensorManager.h | 4 +--- libs/gui/SensorManager.cpp | 11 +++-------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/include/gui/SensorManager.h b/include/gui/SensorManager.h index 9794d4e08..37960673c 100644 --- a/include/gui/SensorManager.h +++ b/include/gui/SensorManager.h @@ -101,6 +101,7 @@ public: return *sensorManager; } + SensorManager(const String16& opPackageName); ~SensorManager(); ssize_t getSensorList(Sensor const* const** list) const; @@ -112,7 +113,6 @@ private: // DeathRecipient interface void sensorManagerDied(); - SensorManager(const String16& opPackageName); status_t assertStateLocked() const; private: @@ -127,8 +127,6 @@ private: const String16 mOpPackageName; }; -android::Mutex android::SensorManager::sLock; -std::map android::SensorManager::sPackageInstances; // ---------------------------------------------------------------------------- }; // namespace android diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp index ead535e63..dd3778137 100644 --- a/libs/gui/SensorManager.cpp +++ b/libs/gui/SensorManager.cpp @@ -59,13 +59,12 @@ void SensorManager::sensorManagerDied() status_t SensorManager::assertStateLocked() const { if (mSensorServer == NULL) { + // try for one second const String16 name("sensorservice"); - // try 10 times before giving up ... - for (int i = 0; i < 10; ++i) { + for (int i=0 ; i<4 ; i++) { status_t err = getService(name, &mSensorServer); if (err == NAME_NOT_FOUND) { - // Sleep for 1 second before retrying. - sleep(1); + usleep(250000); continue; } if (err != NO_ERROR) { @@ -74,10 +73,6 @@ status_t SensorManager::assertStateLocked() const { break; } - if (mSensorServer == NULL) { - ALOGE("FATAL getsensorservice returned` NULL"); - } - class DeathObserver : public IBinder::DeathRecipient { SensorManager& mSensorManger; virtual void binderDied(const wp& who) {