Implement data push from scripts.  Fixes the problem where apps would have to poll to monitor a scripts state.
Fix bug in StoreState where state could be overridden by the default unless the script used more than one state.

Change only impacts renderscript and renderscript apps.
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 169d5d4..a1e9e45 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -142,6 +142,7 @@
     if (this->props.mLogTimes) {
         timerSet(RS_TIMER_SCRIPT);
     }
+    mStateFragmentStore.mLast.clear();
     bool ret = runScript(mRootScript.get(), 0);
     return ret;
 }
@@ -529,6 +530,64 @@
     }
 }
 
+uint32_t Context::getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait)
+{
+    //LOGE("getMessageToClient %i %i", bufferLen, wait);
+    if (!wait) {
+        if (mIO.mToClient.isEmpty()) {
+            // No message to get and not going to wait for one.
+            receiveLen = 0;
+            return 0;
+        }
+    }
+
+    //LOGE("getMessageToClient 2 con=%p", this);
+    uint32_t bytesData = 0;
+    uint32_t commandID = 0;
+    const void *d = mIO.mToClient.get(&commandID, &bytesData);
+    //LOGE("getMessageToClient 3    %i  %i", commandID, bytesData);
+
+    *receiveLen = bytesData;
+    if (bufferLen >= bytesData) {
+        memcpy(data, d, bytesData);
+        mIO.mToClient.next();
+        return commandID;
+    }
+    return 0;
+}
+
+bool Context::sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace)
+{
+    //LOGE("sendMessageToClient %i %i %i", cmdID, len, waitForSpace);
+    if (cmdID == 0) {
+        LOGE("Attempting to send invalid command 0 to client.");
+        return false;
+    }
+    if (!waitForSpace) {
+        if (mIO.mToClient.getFreeSpace() < len) {
+            // Not enough room, and not waiting.
+            return false;
+        }
+    }
+    //LOGE("sendMessageToClient 2");
+    void *p = mIO.mToClient.reserve(len);
+    memcpy(p, data, len);
+    mIO.mToClient.commit(cmdID, len);
+    //LOGE("sendMessageToClient 3");
+    return true;
+}
+
+void Context::initToClient()
+{
+    while(!mRunning) {
+        usleep(100);
+    }
+}
+
+void Context::deinitToClient()
+{
+    mIO.mToClient.shutdown();
+}
 
 
 ///////////////////////////////////////////////////////////////////////////////////////////
@@ -636,3 +695,21 @@
     rsc->objDestroyAdd(static_cast<ObjectBase *>(obj));
 }
 
+uint32_t rsContextGetMessage(RsContext vrsc, void *data, size_t *receiveLen, size_t bufferLen, bool wait)
+{
+    Context * rsc = static_cast<Context *>(vrsc);
+    return rsc->getMessageToClient(data, receiveLen, bufferLen, wait);
+}
+
+void rsContextInitToClient(RsContext vrsc)
+{
+    Context * rsc = static_cast<Context *>(vrsc);
+    rsc->initToClient();
+}
+
+void rsContextDeinitToClient(RsContext vrsc)
+{
+    Context * rsc = static_cast<Context *>(vrsc);
+    rsc->deinitToClient();
+}
+