Merge change I0e09e56f into eclair

* changes:
  Don't callback on NULL client. Bug 2180510.
diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java
index a4c141e..bb0cbe9 100644
--- a/core/java/android/appwidget/AppWidgetHostView.java
+++ b/core/java/android/appwidget/AppWidgetHostView.java
@@ -123,7 +123,8 @@
 
     @Override
     protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
-        final ParcelableSparseArray jail = (ParcelableSparseArray) container.get(generateId());
+        ParcelableSparseArray jail = (ParcelableSparseArray) container.get(generateId());
+        if (jail == null) jail = new ParcelableSparseArray();
         super.dispatchRestoreInstanceState(jail);
     }
 
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index c87a11c..45fcaa59 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -67,7 +67,11 @@
          the slider can be opened (for example, in a pocket or purse). -->
     <bool name="config_bypass_keyguard_if_slider_open">true</bool>
     
-    <!-- Flag indicating whether the device supports automatic brightness mode. -->
+    <!-- Flag indicating whether the device supports automatic brightness mode in hardware. -->
+    <bool name="config_hardware_automatic_brightness_available">false</bool>
+
+    <!-- Flag indicating whether the we should enable the automatic brightness in Settings.
+         Software implementation will be used if config_hardware_auto_brightness_available is not set -->
     <bool name="config_automatic_brightness_available">false</bool>
     
     <!-- XXXXXX END OF RESOURCES USING WRONG NAMING CONVENTION -->
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 195ea6f..cc39dac 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -29,6 +29,8 @@
 using namespace android::renderscript;
 
 pthread_key_t Context::gThreadTLSKey = 0;
+uint32_t Context::gThreadTLSKeyCount = 0;
+pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER;
 
 void Context::initEGL()
 {
@@ -57,6 +59,7 @@
     configAttribsPtr[0] = EGL_NONE;
     rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint))));
 
+    LOGV("initEGL start");
     mEGL.mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     eglInitialize(mEGL.mDisplay, &mEGL.mMajorVersion, &mEGL.mMinorVersion);
 
@@ -144,6 +147,12 @@
     }
     mStateFragmentStore.mLast.clear();
     bool ret = runScript(mRootScript.get(), 0);
+
+    GLenum err = glGetError();
+    if (err != GL_NO_ERROR) {
+        LOGE("Pending GL Error, 0x%x", err);
+    }
+
     return ret;
 }
 
@@ -293,6 +302,8 @@
 
 Context::Context(Device *dev, Surface *sur, bool useDepth)
 {
+    pthread_mutex_lock(&gInitMutex);
+
     dev->addContext(this);
     mDev = dev;
     mRunning = false;
@@ -304,16 +315,18 @@
     int status;
     pthread_attr_t threadAttr;
 
-    if (!gThreadTLSKey) {
+    if (!gThreadTLSKeyCount) {
         status = pthread_key_create(&gThreadTLSKey, NULL);
         if (status) {
             LOGE("Failed to init thread tls key.");
+            pthread_mutex_unlock(&gInitMutex);
             return;
         }
-    } else {
-        // HACK: workaround gl hang on start
-        exit(-1);
     }
+    gThreadTLSKeyCount++;
+    pthread_mutex_unlock(&gInitMutex);
+
+    // Global init done at this point.
 
     status = pthread_attr_init(&threadAttr);
     if (status) {
@@ -355,10 +368,16 @@
     int status = pthread_join(mThreadId, &res);
     objDestroyOOBRun();
 
+    // Global structure cleanup.
+    pthread_mutex_lock(&gInitMutex);
     if (mDev) {
         mDev->removeContext(this);
-        pthread_key_delete(gThreadTLSKey);
+        --gThreadTLSKeyCount;
+        if (!gThreadTLSKeyCount) {
+            pthread_key_delete(gThreadTLSKey);
+        }
     }
+    pthread_mutex_unlock(&gInitMutex);
 
     objDestroyOOBDestroy();
 }
@@ -419,6 +438,7 @@
     } else {
         mVertex.set(pv);
     }
+    mVertex->forceDirty();
 }
 
 void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 3570e10..0dd90ed 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -53,6 +53,9 @@
     ~Context();
 
     static pthread_key_t gThreadTLSKey;
+    static uint32_t gThreadTLSKeyCount;
+    static pthread_mutex_t gInitMutex;
+
     struct ScriptTLSStruct {
         Context * mContext;
         Script * mScript;
diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h
index 26b78dd..57c654f 100644
--- a/libs/rs/rsProgram.h
+++ b/libs/rs/rsProgram.h
@@ -44,6 +44,10 @@
     ObjectBaseRef<Allocation> mConstants;
 
     mutable bool mDirty;
+
+
+public:
+    void forceDirty() {mDirty = true;}
 };
 
 
diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp
index fcf6824..51ae7cf 100644
--- a/libs/rs/rsProgramRaster.cpp
+++ b/libs/rs/rsProgramRaster.cpp
@@ -74,7 +74,7 @@
     if (mLineSmooth) {
         glEnable(GL_LINE_SMOOTH);
     } else {
-        glEnable(GL_LINE_SMOOTH);
+        glDisable(GL_LINE_SMOOTH);
     }
 
     if (rsc->checkVersion1_1()) {
diff --git a/services/java/com/android/server/HardwareService.java b/services/java/com/android/server/HardwareService.java
index 29c13e0..7c56a30 100755
--- a/services/java/com/android/server/HardwareService.java
+++ b/services/java/com/android/server/HardwareService.java
@@ -133,7 +133,7 @@
         context.registerReceiver(mIntentReceiver, filter);
 
         mAutoBrightnessAvailable = context.getResources().getBoolean(
-                com.android.internal.R.bool.config_automatic_brightness_available);
+                com.android.internal.R.bool.config_hardware_automatic_brightness_available);
     }
 
     protected void finalize() throws Throwable {
diff --git a/services/java/com/android/server/status/StatusBarService.java b/services/java/com/android/server/status/StatusBarService.java
index fe761ea..59e9832 100644
--- a/services/java/com/android/server/status/StatusBarService.java
+++ b/services/java/com/android/server/status/StatusBarService.java
@@ -140,7 +140,7 @@
             boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
             switch (event.getKeyCode()) {
             case KeyEvent.KEYCODE_BACK:
-                if (down) {
+                if (!down) {
                     StatusBarService.this.deactivate();
                 }
                 return true;
@@ -973,15 +973,24 @@
     }
     
     void animateCollapse() {
-        if (SPEW) Log.d(TAG, "Animate collapse: expanded=" + mExpanded
-                + " expanded visible=" + mExpandedVisible);
+        if (SPEW) {
+            Log.d(TAG, "animateCollapse(): mExpanded=" + mExpanded
+                    + " mExpandedVisible=" + mExpandedVisible
+                    + " mAnimating=" + mAnimating
+                    + " mAnimVel=" + mAnimVel);
+        }
         
         if (!mExpandedVisible) {
             return;
         }
 
-        prepareTracking(mDisplay.getHeight()-1);
-        performFling(mDisplay.getHeight()-1, -2000.0f, true);
+        if (mAnimating) {
+            return;
+        }
+
+        int y = mDisplay.getHeight()-1;
+        prepareTracking(y);
+        performFling(y, -2000.0f, true);
     }
     
     void performExpand() {
@@ -1096,7 +1105,7 @@
         mTracking = true;
         mVelocityTracker = VelocityTracker.obtain();
         boolean opening = !mExpanded;
-        if (!mExpanded) {
+        if (opening) {
             mAnimAccel = 2000.0f;
             mAnimVel = 200;
             mAnimY = mStatusBarView.getHeight();
@@ -1111,16 +1120,13 @@
             mAnimating = true;
             mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE_REVEAL),
                     mCurAnimationTime);
+            makeExpandedVisible();
         } else {
             // it's open, close it?
             if (mAnimating) {
                 mAnimating = false;
                 mHandler.removeMessages(MSG_ANIMATE);
             }
-        }
-        if (opening) {
-            makeExpandedVisible();
-        } else {
             updateExpandedViewPos(y + mViewDelta);
         }
     }
@@ -1547,7 +1553,7 @@
 
     void updateExpandedViewPos(int expandedPosition) {
         if (SPEW) {
-            Log.d(TAG, "updateExpandedViewPos before pos=" + expandedPosition
+            Log.d(TAG, "updateExpandedViewPos before expandedPosition=" + expandedPosition
                     + " mTrackingParams.y=" + mTrackingParams.y
                     + " mTrackingPosition=" + mTrackingPosition);
         }
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmMmiCode.java b/telephony/java/com/android/internal/telephony/gsm/GsmMmiCode.java
index 18e6375..bcbd127 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmMmiCode.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmMmiCode.java
@@ -595,7 +595,8 @@
                     }
 
                     int isSettingUnconditionalVoice =
-                        ((reason == CommandsInterface.CF_REASON_UNCONDITIONAL) &&
+                        (((reason == CommandsInterface.CF_REASON_UNCONDITIONAL) ||
+                                (reason == CommandsInterface.CF_REASON_ALL)) &&
                                 (((serviceClass & CommandsInterface.SERVICE_CLASS_VOICE) != 0) ||
                                  (serviceClass == CommandsInterface.SERVICE_CLASS_NONE))) ? 1 : 0;