fix [2168531] have software-only gralloc buffer side-step the HAL
diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp
index 10b1051..57d5fc3 100644
--- a/libs/ui/GraphicBufferAllocator.cpp
+++ b/libs/ui/GraphicBufferAllocator.cpp
@@ -22,6 +22,7 @@
 
 #include <ui/GraphicBufferAllocator.h>
 
+#include <private/ui/sw_gralloc_handle.h>
 
 namespace android {
 // ---------------------------------------------------------------------------
@@ -29,7 +30,8 @@
 ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferAllocator )
 
 Mutex GraphicBufferAllocator::sLock;
-KeyedVector<buffer_handle_t, GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList;
+KeyedVector<buffer_handle_t,
+    GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList;
 
 GraphicBufferAllocator::GraphicBufferAllocator()
     : mAllocDev(0)
@@ -83,8 +85,13 @@
     h = clamp(h);
 
     // we have a h/w allocator and h/w buffer is requested
-    status_t err = mAllocDev->alloc(mAllocDev,
-            w, h, format, usage, handle, stride);
+    status_t err; 
+    
+    if (usage & GRALLOC_USAGE_HW_MASK) {
+        err = mAllocDev->alloc(mAllocDev, w, h, format, usage, handle, stride);
+    } else {
+        err = sw_gralloc_handle_t::alloc(w, h, format, usage, handle, stride);
+    }
 
     LOGW_IF(err, "alloc(%u, %u, %d, %08x, ...) failed %d (%s)",
             w, h, format, usage, err, strerror(-err));
@@ -113,9 +120,14 @@
 {
     Mutex::Autolock _l(mLock);
 
-    status_t err = mAllocDev->free(mAllocDev, handle);
+    status_t err;
+    if (sw_gralloc_handle_t::validate(handle) < 0) {
+        err = mAllocDev->free(mAllocDev, handle);
+    } else {
+        err = sw_gralloc_handle_t::free((sw_gralloc_handle_t*)handle);
+    }
+
     LOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));
-    
     if (err == NO_ERROR) {
         Mutex::Autolock _l(sLock);
         KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);