Merge change Ibd2197fb into eclair

* changes:
  Add script to script call support.  Add exception to catch out of bound index data when added to TriangleMeshBuilder.
diff --git a/api/current.xml b/api/current.xml
index 0bca84b..f4d81c7 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -25550,6 +25550,17 @@
  visibility="public"
 >
 </method>
+<method name="getDefaultAdapter"
+ return="android.bluetooth.BluetoothAdapter"
+ abstract="false"
+ native="false"
+ synchronized="true"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getName"
  return="java.lang.String"
  abstract="false"
@@ -31505,17 +31516,6 @@
  visibility="public"
 >
 </field>
-<field name="BLUETOOTH_SERVICE"
- type="java.lang.String"
- transient="false"
- volatile="false"
- value="&quot;bluetooth&quot;"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="CLIPBOARD_SERVICE"
  type="java.lang.String"
  transient="false"
diff --git a/core/java/android/app/ApplicationContext.java b/core/java/android/app/ApplicationContext.java
index 8ba7c01..f48f150 100644
--- a/core/java/android/app/ApplicationContext.java
+++ b/core/java/android/app/ApplicationContext.java
@@ -22,8 +22,6 @@
 
 import org.xmlpull.v1.XmlPullParserException;
 
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.IBluetooth;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.ContentResolver;
@@ -182,8 +180,6 @@
     private StatusBarManager mStatusBarManager = null;
     private TelephonyManager mTelephonyManager = null;
     private ClipboardManager mClipboardManager = null;
-    private boolean mIsBluetoothAdapterCached = false;
-    private BluetoothAdapter mBluetoothAdapter;
     private boolean mRestricted;
     private AccountManager mAccountManager; // protected by mSync
 
@@ -883,8 +879,6 @@
             return getSearchManager();
         } else if (SENSOR_SERVICE.equals(name)) {
             return getSensorManager();
-        } else if (BLUETOOTH_SERVICE.equals(name)) {
-            return getBluetoothAdapter();
         } else if (VIBRATOR_SERVICE.equals(name)) {
             return getVibrator();
         } else if (STATUS_BAR_SERVICE.equals(name)) {
@@ -1034,18 +1028,6 @@
         return mSearchManager;
     }
 
-    private synchronized BluetoothAdapter getBluetoothAdapter() {
-        if (!mIsBluetoothAdapterCached) {
-            mIsBluetoothAdapterCached = true;
-            IBinder b = ServiceManager.getService(BLUETOOTH_SERVICE);
-            if (b != null) {
-                IBluetooth service = IBluetooth.Stub.asInterface(b);
-                mBluetoothAdapter = new BluetoothAdapter(service);
-            }
-        }
-        return mBluetoothAdapter;
-    }
-
     private SensorManager getSensorManager() {
         synchronized (mSync) {
             if (mSensorManager == null) {
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index 8ce911d..cc35b7d 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -20,9 +20,11 @@
 import android.annotation.SdkConstant.SdkConstantType;
 import android.os.Binder;
 import android.os.Handler;
+import android.os.IBinder;
 import android.os.Message;
 import android.os.ParcelUuid;
 import android.os.RemoteException;
+import android.os.ServiceManager;
 import android.util.Log;
 
 import java.io.IOException;
@@ -36,10 +38,8 @@
 /**
  * Represents the local Bluetooth adapter.
  *
- * <p>Use {@link android.content.Context#getSystemService} with {@link
- * android.content.Context#BLUETOOTH_SERVICE} to get the default local
- * Bluetooth adapter. On most Android devices there is only one local
- * Bluetotoh adapter.
+ * <p>Use {@link #getDefaultAdapter} to get the default local Bluetooth
+ * adapter.
  *
  * <p>Use the {@link BluetoothDevice} class for operations on remote Bluetooth
  * devices.
@@ -257,12 +257,40 @@
      */
     public static final String EXTRA_LOCAL_NAME = "android.bluetooth.adapter.extra.LOCAL_NAME";
 
+    /** @hide */
+    public static final String BLUETOOTH_SERVICE = "bluetooth";
+
     private static final int ADDRESS_LENGTH = 17;
 
+    /**
+     * Lazyily initialized singleton. Guaranteed final after first object
+     * constructed.
+     */
+    private static BluetoothAdapter sAdapter;
+
     private final IBluetooth mService;
 
     /**
-     * Do not use this constructor. Use Context.getSystemService() instead.
+     * Get a handle to the default local Bluetooth adapter.
+     * <p>Currently Android only supports one Bluetooth adapter, but the API
+     * could be extended to support more. This will always return the default
+     * adapter.
+     * @return the default local adapter, or null if Bluetooth is not supported
+     *         on this hardware platform
+     */
+    public static synchronized BluetoothAdapter getDefaultAdapter() {
+        if (sAdapter == null) {
+            IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
+            if (b != null) {
+                IBluetooth service = IBluetooth.Stub.asInterface(b);
+                sAdapter = new BluetoothAdapter(service);
+            }
+        }
+        return sAdapter;
+    }
+
+    /**
+     * Use {@link #getDefaultAdapter} to get the BluetoothAdapter instance.
      * @hide
      */
     public BluetoothAdapter(IBluetooth service) {
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index ce975c2..9c23746 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -18,7 +18,6 @@
 
 import android.annotation.SdkConstant;
 import android.annotation.SdkConstant.SdkConstantType;
-import android.content.Context;
 import android.os.IBinder;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -328,7 +327,7 @@
     /*package*/ static IBluetooth getService() {
         synchronized (BluetoothDevice.class) {
             if (sService == null) {
-                IBinder b = ServiceManager.getService(Context.BLUETOOTH_SERVICE);
+                IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
                 if (b == null) {
                     throw new RuntimeException("Bluetooth service not available");
                 }
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index fe4665e..8f1c671 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -1218,14 +1218,6 @@
      */
     public static final String SENSOR_SERVICE = "sensor";
     /**
-     * Use with {@link #getSystemService} to retrieve a {@link
-     * android.bluetooth.BluetoothAdapter} for using Bluetooth.
-     *
-     * @see #getSystemService
-     * @see android.bluetooth.BluetoothAdapter
-     */
-    public static final String BLUETOOTH_SERVICE = "bluetooth";
-    /**
      * Use with {@link #getSystemService} to retrieve a
      * com.android.server.WallpaperService for accessing wallpapers.
      *
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index d61b42f..b73e53f 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -137,7 +137,7 @@
             throw new RuntimeException("Could not init BluetoothA2dpService");
         }
 
-        mAdapter = (BluetoothAdapter) context.getSystemService(Context.BLUETOOTH_SERVICE);
+        mAdapter = BluetoothAdapter.getDefaultAdapter();
 
         mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
         mIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index 3fdbb68..6d4d152 100644
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -154,7 +154,7 @@
     }
 
     public synchronized void initAfterRegistration() {
-        mAdapter = (BluetoothAdapter) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
+        mAdapter = BluetoothAdapter.getDefaultAdapter();
         mEventLoop = new BluetoothEventLoop(mContext, mAdapter, this);
     }
 
diff --git a/core/java/com/android/internal/app/ShutdownThread.java b/core/java/com/android/internal/app/ShutdownThread.java
index 9e1f325..2060cf8 100644
--- a/core/java/com/android/internal/app/ShutdownThread.java
+++ b/core/java/com/android/internal/app/ShutdownThread.java
@@ -32,6 +32,7 @@
 import android.os.Power;
 import android.os.ServiceManager;
 import android.os.SystemClock;
+
 import com.android.internal.telephony.ITelephony;
 import android.util.Log;
 import android.view.WindowManager;
@@ -91,7 +92,10 @@
                     .setNegativeButton(com.android.internal.R.string.no, null)
                     .create();
             dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
-            dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
+            if (!context.getResources().getBoolean(
+                    com.android.internal.R.bool.config_sf_slowBlur)) {
+                dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
+            }
             dialog.show();
         } else {
             beginShutdownSequence(context);
@@ -111,7 +115,10 @@
         pd.setIndeterminate(true);
         pd.setCancelable(false);
         pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
-        pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
+        if (!context.getResources().getBoolean(
+                com.android.internal.R.bool.config_sf_slowBlur)) {
+            pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
+        }
 
         pd.show();
 
@@ -181,7 +188,7 @@
                 ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
         final IBluetooth bluetooth =
                 IBluetooth.Stub.asInterface(ServiceManager.checkService(
-                        Context.BLUETOOTH_SERVICE));
+                        BluetoothAdapter.BLUETOOTH_SERVICE));
         
         try {
             bluetoothOff = bluetooth == null ||
diff --git a/core/res/res/values-en-rUS/donottranslate-names.xml b/core/res/res/values-en-rUS/donottranslate-names.xml
index 82ba310..ae38ddf 100644
--- a/core/res/res/values-en-rUS/donottranslate-names.xml
+++ b/core/res/res/values-en-rUS/donottranslate-names.xml
@@ -4,31 +4,39 @@
     
     <!-- various string resources for Contacts -->
     <string-array name="common_nicknames">
+        <item>Abigail, Abbie, Gail, Gayle</item>
+        <item>Abe, Abraham</item>
+        <item>Aggie, Agatha, Agnes</item>
         <item>Albert, Al, Bert, Bertie</item>
-        <item>Alexander, Al, Alex, Lex, Sasha</item>
-        <item>Alexandra, Al, Alex, Allie, Ally, Lex, Lexie, Sandra, Sandy, Sasha</item>
+        <item>Alexander, Al, Alec, Alex, Lex, Sasha</item>
+        <item>Alexandra, Al, Allie, Ally, Lex, Lexie, Sandra, Sandy, Sasha</item>
+        <item>Alf, Alfred, Alfredo, Alfie</item>
         <item>Alice, Allie, Ally</item>
         <item>Alison, Allie, Ally</item>
         <item>Allison, Allie, Ally</item>
         <item>Amanda, Mandi, Mandy</item>
         <item>Andrea, Andie</item>
         <item>Andrew, Andy, Drew</item>
+        <item>Anne, Annie, Annette</item>
         <item>Anthony, Tony, Toni, Tone</item>
         <item>Arthur, Art, Arty</item>
         <item>Barbara, Babs, Barb, Barbie</item>
         <item>Benjamin, Ben, Benji, Benny</item>
-        <item>Bernard, Bern, Bernie</item>
+        <item>Bernard, Bern, Bernie, Barnie</item>
         <item>Bertram, Bert, Bertie</item>
         <item>Bradly, Brad</item>
+        <item>Calvin, Cal</item>
         <item>Catherine, Cat, Cate, Cath, Catie, Cathy, Kat, Kate, Katie, Kathy</item>
+        <item>Carrie, Caroline, Carolyn</item>
         <item>Charles, Chuck, Chaz, Charlie, Buck</item>
-        <item>Christine, Chris, Chrissy, Chrissie</item>
+        <item>Christine, Chrissy, Chrissie</item>
         <item>Christopher, Chris</item>
+        <item>Clinton, Clint</item>
         <item>Cynthia, Cindy, Cynth</item>
         <item>Daniel, Dan, Danny</item>
         <item>David, Dave</item>
         <item>Deborah, Deb, Debbie</item>
-        <item>Dennis, Den, Denny, Dean</item>
+        <item>Dennis, Den, Denny</item>
         <item>Dolores, Dolly</item>
         <item>Donald, Don, Donny</item>
         <item>Donnatella, Donna</item>
@@ -41,22 +49,21 @@
         <item>Elizabeth, Beth, Bess, Bessie, Betsy, Betty, Bette, Eliza, Lisa, Liza, Liz</item>
         <item>Emily, Em, Ems, Emmy</item>
         <item>Emma, Em, Ems, Emmy</item>
-        <item>Erica, Rikki, Rikkie, Ricky</item>
         <item>Eugene, Gene</item>
+        <item>Fannie, Fanny</item>
         <item>Florence, Flo</item>
         <item>Frances, Fran, Francie</item>
-        <item>Francis, Fran, Frank</item>
+        <item>Francis, Fran, Frank, Frankie</item>
         <item>Frederick, Fred, Freddy</item>
         <item>Gabriel, Gabe</item>
-        <item>Geoffrey, Jeff</item>
         <item>Gerald, Gerry</item>
         <item>Gerard, Gerry</item>
-        <item>Gregory, Greg</item>
-        <item>Harold, Hal, Hank, Harry</item>
+        <item>Gregory, Greg, Gregg</item>
+        <item>Harold, Hal, Harry</item>
         <item>Henry, Hal, Hank, Harry</item>
         <item>Herbert, Bert, Bertie</item>
         <item>Irving, Irv</item>
-        <item>Isabella, Isa, Izzy</item>
+        <item>Isabella, Isa, Izzy, Bella</item>
         <item>Jacob, Jake</item>
         <item>Jacqueline, Jackie</item>
         <item>James, Jim, Jimmy, Jamie, Jock</item>
@@ -68,8 +75,9 @@
         <item>Jennifer, Jen, Jenny</item>
         <item>Jerome, Jerry</item>
         <item>Jessica, Jessie</item>
-        <item>John, Jack, Jacky, Johnny, Jon</item>
-        <item>Jonathan, Jon, John</item>
+        <item>John, Johnny, Jon</item>
+        <item>Jack, Jacky</item>
+        <item>Jonathan, Jon</item>
         <item>Joseph, Joe, Joey</item>
         <item>Joshua, Josh</item>
         <item>Kaitlyn, Cat, Cate, Catie, Cath, Cathy, Kat, Kate, Katie, Kathy</item>
@@ -78,17 +86,20 @@
         <item>Katrina, Cat, Cate, Catie, Cath, Cathy, Kat, Kate, Katie, Kathy</item>
         <item>Kenneth, Ken</item>
         <item>Kevin, Kev</item>
+        <item>Kim, Kimberly</item>
         <item>Laura, Lauri, Laurie</item>
         <item>Lauren, Lauri, Laurie</item>
-        <item>Laurence, Larry, Lauri, Laurie</item>
-        <item>Lawrence, Larry, Lauri, Laurie</item>
+        <item>Lawrence, Larry</item>
         <item>Leonard, Leo, Len, Lenny</item>
         <item>Leopold, Leo, Len, Lenny</item>
         <item>Madeline, Maddie, Maddy</item>
-        <item>Margaret, Marge, Marg, Maggie, Mags, Meg, Peggy</item>
+        <item>Margaret, Marge, Marg, Maggie, Mags, Meg, Peggy, Greta, Gretchen</item>
+        <item>Martin, Martie, Marty</item>
         <item>Matthew, Matt, Mattie</item>
         <item>Maureen, Mo</item>
         <item>Maurice, Mo</item>
+        <item>Maxwell, Max</item>
+        <item>Maximilian, Maxim, Max</item>
         <item>Megan, Meg</item>
         <item>Michael, Mickey, Mick, Mike, Mikey</item>
         <item>Morris, Mo</item>
@@ -96,16 +107,17 @@
         <item>Nathan, Nat, Nate</item>
         <item>Nathaniel, Nat, Nate</item>
         <item>Nicholas, Nick</item>
+        <item>Nicole, Nicky, Nickie, Nikky</item>
         <item>Pamela, Pam</item>
         <item>Patricia, Pat, Patsy, Patty, Trish, Tricia</item>
-        <item>Patrick, Paddy, Pat, Patty, Patter, Rick, Ricky</item>
+        <item>Patrick, Pat, Patter</item>
+        <item>Penelope, Penny</item>
         <item>Peter, Pete</item>
         <item>Raymond, Ray</item>
         <item>Philip, Phil</item>
-        <item>Rebecca, Becca</item>
+        <item>Rebecca, Becca, Becky</item>
         <item>Richard, Rick, Rich, Dick</item>
         <item>Robert, Bob, Rob, Robbie, Bobby, Rab</item>
-        <item>Roberta, Bobbie</item>
         <item>Rodney. Rod</item>
         <item>Ronald, Ron, Ronnie</item>
         <item>Rosemary, Rosie, Rose</item>
@@ -120,7 +132,8 @@
         <item>Stuart, Stu</item>
         <item>Susan, Sue, Susie, Suzie</item>
         <item>Suzanne, Sue, Susie, Suzie</item>
-        <item>Teresa, Terrie, Terry</item>
+        <item>Tamara, Tammy</item>
+        <item>Theresa, Teresa</item>
         <item>Theodora, Teddie, Thea, Theo</item>
         <item>Theodore, Ted, Teddy, Theo</item>
         <item>Thomas, Tom, Thom, Tommy</item>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 9f4af83..9040edb 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -26,6 +26,11 @@
          strictly needed. -->
     <bool name="config_sf_limitedAlpha">false</bool>
     
+    <!-- Flag indicating whether the surface flinger is inefficient
+         at performing a blur.  Used by parts of the UI to turn off
+         the blur effect where it isn't worth the performance hit. -->
+    <bool name="config_sf_slowBlur">false</bool>
+    
     <!-- The duration (in milliseconds) of a short animation. -->
     <integer name="config_shortAnimTime">150</integer>
     
diff --git a/include/private/ui/SharedBufferStack.h b/include/private/ui/SharedBufferStack.h
index f6824d9..bbc1822 100644
--- a/include/private/ui/SharedBufferStack.h
+++ b/include/private/ui/SharedBufferStack.h
@@ -289,6 +289,7 @@
     void setStatus(status_t status);
     status_t reallocate();
     status_t assertReallocate(int buffer);
+    int32_t getQueuedCount() const;
     
     Region getDirtyRegion(int buffer) const;
 
diff --git a/include/private/ui/SurfaceFlingerSynchro.h b/include/private/ui/SurfaceFlingerSynchro.h
deleted file mode 100644
index 7386d33..0000000
--- a/include/private/ui/SurfaceFlingerSynchro.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef ANDROID_SURFACE_FLINGER_SYNCHRO_H
-#define ANDROID_SURFACE_FLINGER_SYNCHRO_H
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <utils/Errors.h>
-#include <ui/ISurfaceComposer.h>
-
-namespace android {
-
-class SurfaceFlinger;
-
-class SurfaceFlingerSynchro
-{
-public:
-                // client constructor
-                SurfaceFlingerSynchro(const sp<ISurfaceComposer>& flinger);
-                ~SurfaceFlingerSynchro();
-    
-                // signal surfaceflinger for some work
-    status_t    signal();
-    
-private:
-    friend class SurfaceFlinger;
-    sp<ISurfaceComposer> mSurfaceComposer;
-};
-
-}; // namespace android
-
-#endif // ANDROID_SURFACE_FLINGER_SYNCHRO_H
-
diff --git a/include/ui/SurfaceComposerClient.h b/include/ui/SurfaceComposerClient.h
index 8701928..777b878 100644
--- a/include/ui/SurfaceComposerClient.h
+++ b/include/ui/SurfaceComposerClient.h
@@ -153,7 +153,7 @@
                 SharedClient*               mControl;
                 sp<IMemoryHeap>             mControlMemory;
                 sp<ISurfaceFlingerClient>   mClient;
-                SurfaceFlingerSynchro*      mSignalServer;
+                sp<ISurfaceComposer>        mSignalServer;
 };
 
 }; // namespace android
diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp
index 0258cee..7fd5434d 100644
--- a/libs/surfaceflinger/Layer.cpp
+++ b/libs/surfaceflinger/Layer.cpp
@@ -454,14 +454,16 @@
 
             // recompute visible region
             recomputeVisibleRegions = true;
-
-            // we now have the correct size, unfreeze the screen
-            mFreezeLock.clear();
         }
+
+        // we now have the correct size, unfreeze the screen
+        mFreezeLock.clear();
     }
 
-    // FIXME: signal an event if we have more buffers waiting
-    // mFlinger->signalEvent();
+    if (lcblk->getQueuedCount()) {
+        // signal an event if we have more buffers waiting
+        mFlinger->signalEvent();
+    }
 
     if (!mPostedDirtyRegion.isEmpty()) {
         reloadTexture( mPostedDirtyRegion );
diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk
index 73d86ea..84aec61 100644
--- a/libs/ui/Android.mk
+++ b/libs/ui/Android.mk
@@ -27,8 +27,7 @@
 	Region.cpp \
 	SharedBufferStack.cpp \
 	Surface.cpp \
-	SurfaceComposerClient.cpp \
-	SurfaceFlingerSynchro.cpp 
+	SurfaceComposerClient.cpp
 
 LOCAL_SHARED_LIBRARIES := \
 	libcutils \
diff --git a/libs/ui/SharedBufferStack.cpp b/libs/ui/SharedBufferStack.cpp
index b460757..46b6766 100644
--- a/libs/ui/SharedBufferStack.cpp
+++ b/libs/ui/SharedBufferStack.cpp
@@ -394,6 +394,12 @@
     return NO_ERROR;
 }
 
+int32_t SharedBufferServer::getQueuedCount() const
+{
+    SharedBufferStack& stack( *mSharedStack );
+    return stack.queued;
+}
+
 status_t SharedBufferServer::assertReallocate(int buffer)
 {
     ReallocateCondition condition(this, buffer);
diff --git a/libs/ui/Surface.cpp b/libs/ui/Surface.cpp
index 2d83a8c..f51ca7a 100644
--- a/libs/ui/Surface.cpp
+++ b/libs/ui/Surface.cpp
@@ -746,6 +746,8 @@
                 currentBuffer->setIndex(index);
                 mNeedFullUpdate = true;
             }
+        } else {
+            err = err<0 ? err : NO_MEMORY;
         }
     }
     return err; 
diff --git a/libs/ui/SurfaceComposerClient.cpp b/libs/ui/SurfaceComposerClient.cpp
index 3baa281..eda84ef 100644
--- a/libs/ui/SurfaceComposerClient.cpp
+++ b/libs/ui/SurfaceComposerClient.cpp
@@ -42,7 +42,6 @@
 
 #include <private/ui/LayerState.h>
 #include <private/ui/SharedBufferStack.h>
-#include <private/ui/SurfaceFlingerSynchro.h>
 
 #define VERBOSE(...)	((void)0)
 //#define VERBOSE			LOGD
@@ -155,7 +154,6 @@
 {
     VERBOSE("Creating client %p, conn %p", this, conn.get());
 
-    mSignalServer = 0;
     mPrebuiltLayerState = 0;
     mTransactionOpen = 0;
     mStatus = NO_ERROR;
@@ -168,7 +166,7 @@
     }
 
     mControlMemory = mClient->getControlBlock();
-    mSignalServer = new SurfaceFlingerSynchro(sm);
+    mSignalServer = sm;
     mControl = static_cast<SharedClient *>(mControlMemory->getBase());
 }
 
@@ -225,7 +223,6 @@
         Mutex::Autolock _lg(gLock);
         Mutex::Autolock _lm(mLock);
 
-        delete mSignalServer;
         mSignalServer = 0;
 
         if (mClient != 0) {
diff --git a/libs/ui/SurfaceFlingerSynchro.cpp b/libs/ui/SurfaceFlingerSynchro.cpp
deleted file mode 100644
index c81db71..0000000
--- a/libs/ui/SurfaceFlingerSynchro.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdint.h>
-
-#include <private/ui/SurfaceFlingerSynchro.h>
-
-namespace android {
-
-// ---------------------------------------------------------------------------
-
-SurfaceFlingerSynchro::SurfaceFlingerSynchro(const sp<ISurfaceComposer>& flinger)
-    : mSurfaceComposer(flinger)
-{
-}
-SurfaceFlingerSynchro::~SurfaceFlingerSynchro()
-{
-}
-
-status_t SurfaceFlingerSynchro::signal()
-{
-    mSurfaceComposer->signal();
-    return NO_ERROR;
-}
-
-// ---------------------------------------------------------------------------
-
-}; // namespace android
-
diff --git a/services/java/com/android/server/DeviceStorageMonitorService.java b/services/java/com/android/server/DeviceStorageMonitorService.java
index 52e09ca..57af029 100644
--- a/services/java/com/android/server/DeviceStorageMonitorService.java
+++ b/services/java/com/android/server/DeviceStorageMonitorService.java
@@ -43,8 +43,8 @@
 /**
  * This class implements a service to monitor the amount of disk storage space
  * on the device. If the free storage on device is less than a tunable threshold value
- * (default is 10%. this value is a gservices parameter) a low memory notification is 
- * displayed to alert the user. If the user clicks on the low memory notification the 
+ * (default is 10%. this value is a gservices parameter) a low memory notification is
+ * displayed to alert the user. If the user clicks on the low memory notification the
  * Application Manager application gets launched to let the user free storage space.
  * Event log events:
  * A low memory event with the free storage on device in bytes  is logged to the event log
@@ -68,32 +68,35 @@
     private static final int EVENT_LOG_FREE_STORAGE_LEFT = 2746;
     private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB
     private static final long DEFAULT_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000;
-    private long mFreeMem;
+    private long mFreeMem;  // on /data
     private long mLastReportedFreeMem;
     private long mLastReportedFreeMemTime;
     private boolean mLowMemFlag=false;
     private Context mContext;
     private ContentResolver mContentResolver;
-    long mBlkSize;
-    long mTotalMemory;
-    StatFs mFileStats;
-    private static final String DATA_PATH="/data";
-    long mThreadStartTime = -1;
-    boolean mClearSucceeded = false;
-    boolean mClearingCache;
+    private long mTotalMemory;  // on /data
+    private StatFs mDataFileStats;
+    private StatFs mSystemFileStats;
+    private StatFs mCacheFileStats;
+    private static final String DATA_PATH = "/data";
+    private static final String SYSTEM_PATH = "/system";
+    private static final String CACHE_PATH = "/cache";
+    private long mThreadStartTime = -1;
+    private boolean mClearSucceeded = false;
+    private boolean mClearingCache;
     private Intent mStorageLowIntent;
     private Intent mStorageOkIntent;
     private CachePackageDataObserver mClearCacheObserver;
     private static final int _TRUE = 1;
     private static final int _FALSE = 0;
-    
+
     /**
      * This string is used for ServiceManager access to this class.
      */
     static final String SERVICE = "devicestoragemonitor";
-    
+
     /**
-    * Handler that checks the amount of disk space on the device and sends a 
+    * Handler that checks the amount of disk space on the device and sends a
     * notification if the device runs low on disk space
     */
     Handler mHandler = new Handler() {
@@ -107,7 +110,7 @@
             checkMemory(msg.arg1 == _TRUE);
         }
     };
-    
+
     class CachePackageDataObserver extends IPackageDataObserver.Stub {
         public void onRemoveCompleted(String packageName, boolean succeeded) {
             mClearSucceeded = succeeded;
@@ -115,12 +118,17 @@
             if(localLOGV) Log.i(TAG, " Clear succeeded:"+mClearSucceeded
                     +", mClearingCache:"+mClearingCache+" Forcing memory check");
             postCheckMemoryMsg(false, 0);
-        }        
+        }
     }
-    
+
     private final void restatDataDir() {
-        mFileStats.restat(DATA_PATH);
-        mFreeMem = mFileStats.getAvailableBlocks()*mBlkSize;
+        try {
+            mDataFileStats.restat(DATA_PATH);
+            mFreeMem = (long) mDataFileStats.getAvailableBlocks() *
+                mDataFileStats.getBlockSize();
+        } catch (IllegalArgumentException e) {
+            // use the old value of mFreeMem
+        }
         // Allow freemem to be overridden by debug.freemem for testing
         String debugFreeMem = SystemProperties.get("debug.freemem");
         if (!"".equals(debugFreeMem)) {
@@ -132,10 +140,27 @@
                 DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000;
         //log the amount of free memory in event log
         long currTime = SystemClock.elapsedRealtime();
-        if((mLastReportedFreeMemTime == 0) || 
-                (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) {
+        if((mLastReportedFreeMemTime == 0) ||
+           (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) {
             mLastReportedFreeMemTime = currTime;
-            EventLog.writeEvent(EVENT_LOG_FREE_STORAGE_LEFT, mFreeMem);
+            long mFreeSystem = -1, mFreeCache = -1;
+            try {
+                mSystemFileStats.restat(SYSTEM_PATH);
+                mFreeSystem = (long) mSystemFileStats.getAvailableBlocks() *
+                    mSystemFileStats.getBlockSize();
+            } catch (IllegalArgumentException e) {
+                // ignore; report -1
+            }
+            try {
+                mCacheFileStats.restat(CACHE_PATH);
+                mFreeCache = (long) mCacheFileStats.getAvailableBlocks() *
+                    mCacheFileStats.getBlockSize();
+            } catch (IllegalArgumentException e) {
+                // ignore; report -1
+            }
+            mCacheFileStats.restat(CACHE_PATH);
+            EventLog.writeEvent(EVENT_LOG_FREE_STORAGE_LEFT,
+                                mFreeMem, mFreeSystem, mFreeCache);
         }
         // Read the reporting threshold from Gservices
         long threshold = Gservices.getLong(mContentResolver,
@@ -148,7 +173,7 @@
             EventLog.writeEvent(EVENT_LOG_STORAGE_BELOW_THRESHOLD, mFreeMem);
         }
     }
-    
+
     private final void clearCache() {
         if (mClearCacheObserver == null) {
             // Lazy instantiation
@@ -165,10 +190,10 @@
             mClearSucceeded = false;
         }
     }
-    
+
     private final void checkMemory(boolean checkCache) {
-        //if the thread that was started to clear cache is still running do nothing till its 
-        //finished clearing cache. Ideally this flag could be modified by clearCache 
+        //if the thread that was started to clear cache is still running do nothing till its
+        //finished clearing cache. Ideally this flag could be modified by clearCache
         // and should be accessed via a lock but even if it does this test will fail now and
         //hopefully the next time this flag will be set to the correct value.
         if(mClearingCache) {
@@ -177,11 +202,11 @@
             long diffTime = System.currentTimeMillis() - mThreadStartTime;
             if(diffTime > (10*60*1000)) {
                 Log.w(TAG, "Thread that clears cache file seems to run for ever");
-            } 
+            }
         } else {
             restatDataDir();
             if (localLOGV)  Log.v(TAG, "freeMemory="+mFreeMem);
-            
+
             //post intent to NotificationManager to display icon if necessary
             long memThreshold = getMemThreshold();
             if (mFreeMem < memThreshold) {
@@ -214,7 +239,7 @@
         //keep posting messages to itself periodically
         postCheckMemoryMsg(true, DEFAULT_CHECK_INTERVAL);
     }
-    
+
     private void postCheckMemoryMsg(boolean clearCache, long delay) {
         // Remove queued messages
         mHandler.removeMessages(DEVICE_MEMORY_WHAT);
@@ -222,16 +247,16 @@
                 clearCache ?_TRUE : _FALSE, 0),
                 delay);
     }
-    
+
     /*
-     * just query settings to retrieve the memory threshold. 
+     * just query settings to retrieve the memory threshold.
      * Preferred this over using a ContentObserver since Settings.Gservices caches the value
      * any way
      */
     private long getMemThreshold() {
         int value = Settings.Gservices.getInt(
-                              mContentResolver, 
-                              Settings.Gservices.SYS_STORAGE_THRESHOLD_PERCENTAGE, 
+                              mContentResolver,
+                              Settings.Gservices.SYS_STORAGE_THRESHOLD_PERCENTAGE,
                               DEFAULT_THRESHOLD_PERCENTAGE);
         if(localLOGV) Log.v(TAG, "Threshold Percentage="+value);
         //evaluate threshold value
@@ -247,16 +272,17 @@
         mContext = context;
         mContentResolver = mContext.getContentResolver();
         //create StatFs object
-        mFileStats = new StatFs(DATA_PATH);
-        //initialize block size
-        mBlkSize = mFileStats.getBlockSize();
+        mDataFileStats = new StatFs(DATA_PATH);
+        mSystemFileStats = new StatFs(SYSTEM_PATH);
+        mCacheFileStats = new StatFs(CACHE_PATH);
         //initialize total storage on device
-        mTotalMemory = ((long)mFileStats.getBlockCount()*mBlkSize)/100L;
+        mTotalMemory = ((long)mDataFileStats.getBlockCount() *
+                        mDataFileStats.getBlockSize())/100L;
         mStorageLowIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_LOW);
         mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK);
         checkMemory(true);
     }
-    
+
 
     /**
     * This method sends a notification to NotificationManager to display
@@ -271,7 +297,7 @@
         Intent lowMemIntent = new Intent(Intent.ACTION_MANAGE_PACKAGE_STORAGE);
         lowMemIntent.putExtra("memory", mFreeMem);
         lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        NotificationManager mNotificationMgr = 
+        NotificationManager mNotificationMgr =
                 (NotificationManager)mContext.getSystemService(
                         Context.NOTIFICATION_SERVICE);
         CharSequence title = mContext.getText(
@@ -302,7 +328,7 @@
         mContext.removeStickyBroadcast(mStorageLowIntent);
         mContext.sendBroadcast(mStorageOkIntent);
     }
-    
+
     public void updateMemory() {
         int callingUid = getCallingUid();
         if(callingUid != Process.SYSTEM_UID) {
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index e5c6010..b8cf844 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -23,6 +23,7 @@
 import dalvik.system.VMRuntime;
 
 import android.app.ActivityManagerNative;
+import android.bluetooth.BluetoothAdapter;
 import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.ContentService;
@@ -172,14 +173,14 @@
             // support Bluetooth - see bug 988521
             if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
                 Log.i(TAG, "Registering null Bluetooth Service (emulator)");
-                ServiceManager.addService(Context.BLUETOOTH_SERVICE, null);
+                ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
             } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
                 Log.i(TAG, "Registering null Bluetooth Service (factory test)");
-                ServiceManager.addService(Context.BLUETOOTH_SERVICE, null);
+                ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
             } else {
                 Log.i(TAG, "Bluetooth Service");
                 bluetooth = new BluetoothService(context);
-                ServiceManager.addService(Context.BLUETOOTH_SERVICE, bluetooth);
+                ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
                 bluetooth.initAfterRegistration();
                 bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
                 ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
diff --git a/services/java/com/android/server/status/StatusBarPolicy.java b/services/java/com/android/server/status/StatusBarPolicy.java
index cf63d02..3d1fb83 100644
--- a/services/java/com/android/server/status/StatusBarPolicy.java
+++ b/services/java/com/android/server/status/StatusBarPolicy.java
@@ -448,8 +448,7 @@
         mBluetoothData = IconData.makeIcon("bluetooth",
                 null, com.android.internal.R.drawable.stat_sys_data_bluetooth, 0, 0);
         mBluetoothIcon = service.addIcon(mBluetoothData, null);
-        BluetoothAdapter adapter =
-                (BluetoothAdapter) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
         if (adapter != null) {
             mBluetoothEnabled = adapter.isEnabled();
         } else {
@@ -625,15 +624,20 @@
             pixelFormat = bg.getOpacity();
         }
 
+        int flags =  WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
+                | WindowManager.LayoutParams.FLAG_DIM_BEHIND;
+        
+        if (!mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_sf_slowBlur)) {
+            flags |= WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
+        }
+        
         WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                 ViewGroup.LayoutParams.WRAP_CONTENT,
                 ViewGroup.LayoutParams.WRAP_CONTENT,
                 WindowManager.LayoutParams.TYPE_TOAST,
-                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
-                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
-                    | WindowManager.LayoutParams.FLAG_BLUR_BEHIND
-                    | WindowManager.LayoutParams.FLAG_DIM_BEHIND,
-                pixelFormat);
+                flags, pixelFormat);
 
         // Get the dim amount from the theme
         TypedArray a = mContext.obtainStyledAttributes(