From 6d09ca8663deea6b27917c5bf21223ae41c2b1df Mon Sep 17 00:00:00 2001 From: Dan Stoza Date: Fri, 1 May 2015 16:42:55 -0700 Subject: [PATCH 1/5] 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/5] 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/5] 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 7f620a5a5e9034b519c3e8d160096e3ddae351c2 Mon Sep 17 00:00:00 2001 From: Aravind Akella Date: Wed, 24 Jun 2015 08:31:32 -0700 Subject: [PATCH 4/5] Fix crash in SensorService. Ignore devices with no sensors. Change-Id: I1491740baa6348f97c336b6883b11ad2ab93cf73 --- services/sensorservice/SensorService.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp index 45d467d64..550107c4c 100644 --- a/services/sensorservice/SensorService.cpp +++ b/services/sensorservice/SensorService.cpp @@ -276,6 +276,8 @@ status_t SensorService::dump(int fd, const Vector& args) dev.enableAllSensors(); } return status_t(NO_ERROR); + } else if (mSensorList.size() == 0) { + result.append("No Sensors on the device\n"); } else { // Default dump the sensor list and debugging information. result.append("Sensor List:\n"); From e197d815c4a3dd1e79029d35139273a9c90fa547 Mon Sep 17 00:00:00 2001 From: Daichi Hirono Date: Wed, 24 Jun 2015 15:57:06 +0900 Subject: [PATCH 5/5] Fix directory path of codecache. Previously installd removed the normal cache directory when delete_code_cache is called. It should delete the code cache directory. BUG=21206499 Change-Id: I5774430e389e22805fa7984b4c83420c3677ca75 --- cmds/installd/commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp index faf48efc3..f2c76d548 100644 --- a/cmds/installd/commands.cpp +++ b/cmds/installd/commands.cpp @@ -344,7 +344,7 @@ int delete_cache(const char *uuid, const char *pkgname, userid_t userid) int delete_code_cache(const char *uuid, const char *pkgname, userid_t userid) { std::string _codecachedir( - create_data_user_package_path(uuid, userid, pkgname) + CACHE_DIR_POSTFIX); + create_data_user_package_path(uuid, userid, pkgname) + CODE_CACHE_DIR_POSTFIX); const char* codecachedir = _codecachedir.c_str(); struct stat s;