Merge "[RenderScript] Add optimized ASIMD and SSE3 instrinsics to support lib."
diff --git a/v17/leanback/src/android/support/v17/leanback/widget/SearchEditText.java b/v17/leanback/src/android/support/v17/leanback/widget/SearchEditText.java
index 5f62638..56c63cf 100644
--- a/v17/leanback/src/android/support/v17/leanback/widget/SearchEditText.java
+++ b/v17/leanback/src/android/support/v17/leanback/widget/SearchEditText.java
@@ -55,7 +55,9 @@
     public boolean onKeyPreIme(int keyCode, KeyEvent event) {
         if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
             if (DEBUG) Log.v(TAG, "Keyboard being dismissed");
-            mKeyboardDismissListener.onKeyboardDismiss();
+            if (mKeyboardDismissListener != null) {
+                mKeyboardDismissListener.onKeyboardDismiss();
+            }
             return false;
         }
         return super.onKeyPreIme(keyCode, event);
diff --git a/v4/java/android/support/v4/widget/SlidingPaneLayout.java b/v4/java/android/support/v4/widget/SlidingPaneLayout.java
index c5db3ef..aff4546 100644
--- a/v4/java/android/support/v4/widget/SlidingPaneLayout.java
+++ b/v4/java/android/support/v4/widget/SlidingPaneLayout.java
@@ -379,6 +379,8 @@
             if (child == panel) {
                 // There are still more children above the panel but they won't be affected.
                 break;
+            } else if (child.getVisibility() == GONE) {
+                continue;
             }
 
             final int clampedChildLeft = Math.max((isLayoutRtl ? endBound :
diff --git a/v7/appcompat/src/android/support/v7/app/ActionBarDrawerToggle.java b/v7/appcompat/src/android/support/v7/app/ActionBarDrawerToggle.java
index c15c531..f10cd18 100644
--- a/v7/appcompat/src/android/support/v7/app/ActionBarDrawerToggle.java
+++ b/v7/appcompat/src/android/support/v7/app/ActionBarDrawerToggle.java
@@ -536,10 +536,13 @@
 
         @Override
         public void setActionBarUpIndicator(Drawable themeImage, int contentDescRes) {
-            mActivity.getActionBar().setDisplayShowHomeEnabled(true);
-            mSetIndicatorInfo = ActionBarDrawerToggleHoneycomb.setActionBarUpIndicator(
-                    mSetIndicatorInfo, mActivity, themeImage, contentDescRes);
-            mActivity.getActionBar().setDisplayShowHomeEnabled(false);
+            final ActionBar actionBar = mActivity.getActionBar();
+            if (actionBar != null) {
+                actionBar.setDisplayShowHomeEnabled(true);
+                mSetIndicatorInfo = ActionBarDrawerToggleHoneycomb.setActionBarUpIndicator(
+                        mSetIndicatorInfo, mActivity, themeImage, contentDescRes);
+                actionBar.setDisplayShowHomeEnabled(false);
+            }
         }
 
         @Override
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java b/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
index 85b6763..88accae 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
@@ -1045,6 +1045,7 @@
     }
 
     long     mContext;
+    private boolean mDestroyed = false;
     //Dummy device & context for Inc Support Lib
     long     mIncCon;
     //indicator of whether inc support lib has been loaded or not.
@@ -1657,6 +1658,54 @@
         nContextFinish();
     }
 
+    private void helpDestroy() {
+        boolean shouldDestroy = false;
+        synchronized(this) {
+            if (!mDestroyed) {
+                shouldDestroy = true;
+                mDestroyed = true;
+            }
+        }
+
+        if (shouldDestroy) {
+            nContextFinish();
+            if (mIncCon != 0) {
+                nIncContextFinish();
+                nIncContextDestroy();
+                mIncCon = 0;
+            }
+            nContextDeinitToClient(mContext);
+            mMessageThread.mRun = false;
+            // Interrupt mMessageThread so it gets to see immediately that mRun is false
+            // and exit rightaway.
+            mMessageThread.interrupt();
+
+            // Wait for mMessageThread to join.  Try in a loop, in case this thread gets interrupted
+            // during the wait.  If interrupted, set the "interrupted" status of the current thread.
+            boolean hasJoined = false, interrupted = false;
+            while (!hasJoined) {
+                try {
+                    mMessageThread.join();
+                    hasJoined = true;
+                } catch (InterruptedException e) {
+                    interrupted = true;
+                }
+            }
+            if (interrupted) {
+                Log.v(LOG_TAG, "Interrupted during wait for MessageThread to join");
+                Thread.currentThread().interrupt();
+            }
+
+            nContextDestroy();
+        }
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        helpDestroy();
+        super.finalize();
+    }
+
     /**
      * Destroys this RenderScript context.  Once this function is called,
      * using this context or any objects belonging to this context is
@@ -1672,32 +1721,7 @@
             return;
         }
         validate();
-        nContextFinish();
-        if (mIncCon != 0) {
-            nIncContextFinish();
-            nIncContextDestroy();
-            mIncCon = 0;
-        }
-        nContextDeinitToClient(mContext);
-        mMessageThread.mRun = false;
-
-        // Wait for mMessageThread to join.  Try in a loop, in case this thread gets interrupted
-        // during the wait.  If interrupted, set the "interrupted" status of the current thread.
-        boolean hasJoined = false, interrupted = false;
-        while (!hasJoined) {
-            try {
-                mMessageThread.join();
-                hasJoined = true;
-            } catch (InterruptedException e) {
-                interrupted = true;
-            }
-        }
-        if (interrupted) {
-            Log.v(LOG_TAG, "Interrupted during wait for MessageThread to join");
-            Thread.currentThread().interrupt();
-        }
-
-        nContextDestroy();
+        helpDestroy();
     }
 
     boolean isAlive() {
diff --git a/v8/renderscript/jni/android_renderscript_RenderScript.cpp b/v8/renderscript/jni/android_renderscript_RenderScript.cpp
index fcb4289..78de8d5 100644
--- a/v8/renderscript/jni/android_renderscript_RenderScript.cpp
+++ b/v8/renderscript/jni/android_renderscript_RenderScript.cpp
@@ -1589,6 +1589,12 @@
     sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
     sc.arrayStart = 0;
     sc.arrayEnd = 0;
+    sc.array2Start = 0;
+    sc.array2End = 0;
+    sc.array3Start = 0;
+    sc.array3End = 0;
+    sc.array4Start = 0;
+    sc.array4End = 0;
     if (mUseInc) {
         dispatchTab.ContextFinish((RsContext)con);
         dispatchTabInc.ScriptForEach((RsContext)incCon, (RsScript)script, slot,
@@ -1620,6 +1626,12 @@
     sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
     sc.arrayStart = 0;
     sc.arrayEnd = 0;
+    sc.array2Start = 0;
+    sc.array2End = 0;
+    sc.array3Start = 0;
+    sc.array3End = 0;
+    sc.array4Start = 0;
+    sc.array4End = 0;
     if (mUseInc) {
         dispatchTab.ContextFinish((RsContext)con);
         dispatchTabInc.ScriptForEach((RsContext)incCon, (RsScript)script, slot,