Merge "Sholes mobile iface comes/goes - handle the reset" into froyo
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index a556a32..fd84859 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -150,13 +150,13 @@
 
     public static IPackageManager getPackageManager() {
         if (sPackageManager != null) {
-            //Log.v("PackageManager", "returning cur default = " + sPackageManager);
+            //Slog.v("PackageManager", "returning cur default = " + sPackageManager);
             return sPackageManager;
         }
         IBinder b = ServiceManager.getService("package");
-        //Log.v("PackageManager", "default service binder = " + b);
+        //Slog.v("PackageManager", "default service binder = " + b);
         sPackageManager = IPackageManager.Stub.asInterface(b);
-        //Log.v("PackageManager", "default service = " + sPackageManager);
+        //Slog.v("PackageManager", "default service = " + sPackageManager);
         return sPackageManager;
     }
 
@@ -170,7 +170,7 @@
         }
         DisplayMetrics metrics = mDisplayMetrics = new DisplayMetrics();
         mDisplay.getMetrics(metrics);
-        //Log.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
+        //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
         //        + metrics.heightPixels + " den=" + metrics.density
         //        + " xdpi=" + metrics.xdpi + " ydpi=" + metrics.ydpi);
         return metrics;
@@ -189,14 +189,14 @@
         synchronized (mPackages) {
             // Resources is app scale dependent.
             if (false) {
-                Log.w(TAG, "getTopLevelResources: " + resDir + " / "
+                Slog.w(TAG, "getTopLevelResources: " + resDir + " / "
                         + compInfo.applicationScale);
             }
             WeakReference<Resources> wr = mActiveResources.get(key);
             r = wr != null ? wr.get() : null;
             if (r != null && r.getAssets().isUpToDate()) {
                 if (false) {
-                    Log.w(TAG, "Returning cached resources " + r + " " + resDir
+                    Slog.w(TAG, "Returning cached resources " + r + " " + resDir
                             + ": appScale=" + r.getCompatibilityInfo().applicationScale);
                 }
                 return r;
@@ -204,7 +204,7 @@
         }
 
         //if (r != null) {
-        //    Log.w(TAG, "Throwing away out-of-date resources!!!! "
+        //    Slog.w(TAG, "Throwing away out-of-date resources!!!! "
         //            + r + " " + resDir);
         //}
 
@@ -213,11 +213,11 @@
             return null;
         }
 
-        //Log.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
+        //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
         DisplayMetrics metrics = getDisplayMetricsLocked(false);
         r = new Resources(assets, metrics, getConfiguration(), compInfo);
         if (false) {
-            Log.i(TAG, "Created app resources " + resDir + " " + r + ": "
+            Slog.i(TAG, "Created app resources " + resDir + " " + r + ": "
                     + r.getConfiguration() + " appScale="
                     + r.getCompatibilityInfo().applicationScale);
         }
@@ -306,7 +306,7 @@
                     mSystemContext.getResources().updateConfiguration(
                              mainThread.getConfiguration(),
                              mainThread.getDisplayMetricsLocked(false));
-                    //Log.i(TAG, "Created system resources "
+                    //Slog.i(TAG, "Created system resources "
                     //        + mSystemContext.getResources() + ": "
                     //        + mSystemContext.getResources().getConfiguration());
                 }
@@ -465,7 +465,7 @@
                      * create the class loader.
                      */
 
-                    if (localLOGV) Log.v(TAG, "Class path: " + zip);
+                    if (localLOGV) Slog.v(TAG, "Class path: " + zip);
 
                     mClassLoader =
                         ApplicationLoaders.getDefault().getClassLoader(
@@ -692,7 +692,7 @@
                 }
             }
             mUnregisteredReceivers.remove(context);
-            //Log.i(TAG, "Receiver registrations: " + mReceivers);
+            //Slog.i(TAG, "Receiver registrations: " + mReceivers);
             HashMap<ServiceConnection, ServiceDispatcher> smap =
                 mServices.remove(context);
             if (smap != null) {
@@ -714,7 +714,7 @@
                 }
             }
             mUnboundServices.remove(context);
-            //Log.i(TAG, "Service registrations: " + mServices);
+            //Slog.i(TAG, "Service registrations: " + mServices);
         }
 
         public IIntentReceiver getReceiverDispatcher(BroadcastReceiver r,
@@ -810,8 +810,8 @@
                     ReceiverDispatcher rd = mDispatcher.get();
                     if (DEBUG_BROADCAST) {
                         int seq = intent.getIntExtra("seq", -1);
-                        Log.i(TAG, "Receiving broadcast " + intent.getAction() + " seq=" + seq
-                                + " to " + rd);
+                        Slog.i(TAG, "Receiving broadcast " + intent.getAction() + " seq=" + seq
+                                + " to " + (rd != null ? rd.mReceiver : null));
                     }
                     if (rd != null) {
                         rd.performReceive(intent, resultCode, data, extras,
@@ -821,9 +821,8 @@
                         // receiver in this process, but before it could be delivered the
                         // receiver was unregistered.  Acknowledge the broadcast on its
                         // behalf so that the system's broadcast sequence can continue.
-                        if (DEBUG_BROADCAST) {
-                            Log.i(TAG, "Broadcast to unregistered receiver");
-                        }
+                        if (DEBUG_BROADCAST) Slog.i(TAG,
+                                "Finishing broadcast to unregistered receiver");
                         IActivityManager mgr = ActivityManagerNative.getDefault();
                         try {
                             mgr.finishReceiver(this, resultCode, data, extras, false);
@@ -855,16 +854,29 @@
                     BroadcastReceiver receiver = mReceiver;
                     if (DEBUG_BROADCAST) {
                         int seq = mCurIntent.getIntExtra("seq", -1);
-                        Log.i(TAG, "Dispatching broadcast " + mCurIntent.getAction()
+                        Slog.i(TAG, "Dispatching broadcast " + mCurIntent.getAction()
                                 + " seq=" + seq + " to " + mReceiver);
+                        Slog.i(TAG, "  mRegistered=" + mRegistered
+                                + " mCurOrdered=" + mCurOrdered);
                     }
-                    if (receiver == null) {
-                        return;
-                    }
-
+                    
                     IActivityManager mgr = ActivityManagerNative.getDefault();
                     Intent intent = mCurIntent;
                     mCurIntent = null;
+                    
+                    if (receiver == null) {
+                        if (mRegistered && mCurOrdered) {
+                            try {
+                                if (DEBUG_BROADCAST) Slog.i(TAG,
+                                        "Finishing null broadcast to " + mReceiver);
+                                mgr.finishReceiver(mIIntentReceiver,
+                                        mCurCode, mCurData, mCurMap, false);
+                            } catch (RemoteException ex) {
+                            }
+                        }
+                        return;
+                    }
+
                     try {
                         ClassLoader cl =  mReceiver.getClass().getClassLoader();
                         intent.setExtrasClassLoader(cl);
@@ -880,6 +892,8 @@
                     } catch (Exception e) {
                         if (mRegistered && mCurOrdered) {
                             try {
+                                if (DEBUG_BROADCAST) Slog.i(TAG,
+                                        "Finishing failed broadcast to " + mReceiver);
                                 mgr.finishReceiver(mIIntentReceiver,
                                         mCurCode, mCurData, mCurMap, false);
                             } catch (RemoteException ex) {
@@ -894,6 +908,8 @@
                     }
                     if (mRegistered && mCurOrdered) {
                         try {
+                            if (DEBUG_BROADCAST) Slog.i(TAG,
+                                    "Finishing broadcast to " + mReceiver);
                             mgr.finishReceiver(mIIntentReceiver,
                                     receiver.getResultCode(),
                                     receiver.getResultData(),
@@ -961,7 +977,7 @@
                     String data, Bundle extras, boolean ordered, boolean sticky) {
                 if (DEBUG_BROADCAST) {
                     int seq = intent.getIntExtra("seq", -1);
-                    Log.i(TAG, "Enqueueing broadcast " + intent.getAction() + " seq=" + seq
+                    Slog.i(TAG, "Enqueueing broadcast " + intent.getAction() + " seq=" + seq
                             + " to " + mReceiver);
                 }
                 Args args = new Args();
@@ -972,9 +988,11 @@
                 args.mCurOrdered = ordered;
                 args.mCurSticky = sticky;
                 if (!mActivityThread.post(args)) {
-                    if (mRegistered) {
+                    if (mRegistered && ordered) {
                         IActivityManager mgr = ActivityManagerNative.getDefault();
                         try {
+                            if (DEBUG_BROADCAST) Slog.i(TAG,
+                                    "Finishing sync broadcast to " + mReceiver);
                             mgr.finishReceiver(mIIntentReceiver, args.mCurCode,
                                     args.mCurData, args.mCurMap, false);
                         } catch (RemoteException ex) {
@@ -2133,7 +2151,7 @@
                 IActivityManager am = ActivityManagerNative.getDefault();
                 ActivityRecord prev;
                 do {
-                    if (localLOGV) Log.v(
+                    if (localLOGV) Slog.v(
                         TAG, "Reporting idle of " + a +
                         " finished=" +
                         (a.activity != null ? a.activity.mFinished : false));
@@ -2252,7 +2270,7 @@
                 ref = mResourcePackages.get(packageName);
             }
             PackageInfo packageInfo = ref != null ? ref.get() : null;
-            //Log.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo);
+            //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo);
             if (packageInfo != null && (packageInfo.mResources == null
                     || packageInfo.mResources.getAssets().isUpToDate())) {
                 if (packageInfo.isSecurityViolation()
@@ -2319,7 +2337,7 @@
             PackageInfo packageInfo = ref != null ? ref.get() : null;
             if (packageInfo == null || (packageInfo.mResources != null
                     && !packageInfo.mResources.getAssets().isUpToDate())) {
-                if (localLOGV) Log.v(TAG, (includeCode ? "Loading code package "
+                if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package "
                         : "Loading resource-only package ") + aInfo.packageName
                         + " (in " + (mBoundApplication != null
                                 ? mBoundApplication.processName : null)
@@ -2402,7 +2420,7 @@
                 context.getResources().updateConfiguration(
                         getConfiguration(), getDisplayMetricsLocked(false));
                 mSystemContext = context;
-                //Log.i(TAG, "Created system resources " + context.getResources()
+                //Slog.i(TAG, "Created system resources " + context.getResources()
                 //        + ": " + context.getResources().getConfiguration());
             }
         }
@@ -2442,10 +2460,10 @@
     void doGcIfNeeded() {
         mGcIdlerScheduled = false;
         final long now = SystemClock.uptimeMillis();
-        //Log.i(TAG, "**** WE MIGHT WANT TO GC: then=" + Binder.getLastGcTime()
+        //Slog.i(TAG, "**** WE MIGHT WANT TO GC: then=" + Binder.getLastGcTime()
         //        + "m now=" + now);
         if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) {
-            //Log.i(TAG, "**** WE DO, WE DO WANT TO GC!");
+            //Slog.i(TAG, "**** WE DO, WE DO WANT TO GC!");
             BinderInternal.forceGc("bg");
         }
     }
@@ -2481,7 +2499,7 @@
             } else {
                 name = "(Intent " + intent + ").getComponent() returned null";
             }
-            Log.v(TAG, "Performing launch: action=" + intent.getAction()
+            Slog.v(TAG, "Performing launch: action=" + intent.getAction()
                     + ", comp=" + name
                     + ", token=" + token);
         }
@@ -2495,7 +2513,7 @@
     public final void sendActivityResult(
             IBinder token, String id, int requestCode,
             int resultCode, Intent data) {
-        if (DEBUG_RESULTS) Log.v(TAG, "sendActivityResult: id=" + id
+        if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id
                 + " req=" + requestCode + " res=" + resultCode + " data=" + data);
         ArrayList<ResultInfo> list = new ArrayList<ResultInfo>();
         list.add(new ResultInfo(id, requestCode, resultCode, data));
@@ -2514,7 +2532,7 @@
 
     private final void queueOrSendMessage(int what, Object obj, int arg1, int arg2) {
         synchronized (this) {
-            if (localLOGV) Log.v(
+            if (localLOGV) Slog.v(
                 TAG, "SCHEDULE " + what + " " + mH.codeToString(what)
                 + ": " + arg1 + " / " + obj);
             Message msg = Message.obtain();
@@ -2576,8 +2594,8 @@
         try {
             Application app = r.packageInfo.makeApplication(false, mInstrumentation);
 
-            if (localLOGV) Log.v(TAG, "Performing launch of " + r);
-            if (localLOGV) Log.v(
+            if (localLOGV) Slog.v(TAG, "Performing launch of " + r);
+            if (localLOGV) Slog.v(
                     TAG, r + ": app=" + app
                     + ", appName=" + app.getPackageName()
                     + ", pkg=" + r.packageInfo.getPackageName()
@@ -2590,7 +2608,7 @@
                 appContext.setOuterContext(activity);
                 CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
                 Configuration config = new Configuration(mConfiguration);
-                if (DEBUG_CONFIGURATION) Log.v(TAG, "Launching activity "
+                if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity "
                         + r.activityInfo.name + " with config " + config);
                 activity.attach(appContext, this, getInstrumentation(), r.token,
                         r.ident, app, r.intent, r.activityInfo, title, r.parent,
@@ -2659,7 +2677,7 @@
         // we are back active so skip it.
         unscheduleGcIdler();
 
-        if (localLOGV) Log.v(
+        if (localLOGV) Slog.v(
             TAG, "Handling launch of " + r);
         Activity a = performLaunchActivity(r, customIntent);
 
@@ -2765,6 +2783,8 @@
             receiver = (BroadcastReceiver)cl.loadClass(component).newInstance();
         } catch (Exception e) {
             try {
+                if (DEBUG_BROADCAST) Slog.i(TAG,
+                        "Finishing failed broadcast to " + data.intent.getComponent());
                 mgr.finishReceiver(mAppThread.asBinder(), data.resultCode,
                                    data.resultData, data.resultExtras, data.resultAbort);
             } catch (RemoteException ex) {
@@ -2777,7 +2797,7 @@
         try {
             Application app = packageInfo.makeApplication(false, mInstrumentation);
 
-            if (localLOGV) Log.v(
+            if (localLOGV) Slog.v(
                 TAG, "Performing receive of " + data.intent
                 + ": app=" + app
                 + ", appName=" + app.getPackageName()
@@ -2794,6 +2814,8 @@
                     data.intent);
         } catch (Exception e) {
             try {
+                if (DEBUG_BROADCAST) Slog.i(TAG,
+                        "Finishing failed broadcast to " + data.intent.getComponent());
                 mgr.finishReceiver(mAppThread.asBinder(), data.resultCode,
                     data.resultData, data.resultExtras, data.resultAbort);
             } catch (RemoteException ex) {
@@ -2807,11 +2829,15 @@
 
         try {
             if (data.sync) {
+                if (DEBUG_BROADCAST) Slog.i(TAG,
+                        "Finishing ordered broadcast to " + data.intent.getComponent());
                 mgr.finishReceiver(
                     mAppThread.asBinder(), receiver.getResultCode(),
                     receiver.getResultData(), receiver.getResultExtras(false),
                         receiver.getAbortBroadcast());
             } else {
+                if (DEBUG_BROADCAST) Slog.i(TAG,
+                        "Finishing broadcast to " + data.intent.getComponent());
                 mgr.finishReceiver(mAppThread.asBinder(), 0, null, null, false);
             }
         } catch (RemoteException ex) {
@@ -2820,7 +2846,7 @@
 
     // Instantiate a BackupAgent and tell it that it's alive
     private final void handleCreateBackupAgent(CreateBackupAgentData data) {
-        if (DEBUG_BACKUP) Log.v(TAG, "handleCreateBackupAgent: " + data);
+        if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data);
 
         // no longer idle; we have backup work to do
         unscheduleGcIdler();
@@ -2829,7 +2855,7 @@
         PackageInfo packageInfo = getPackageInfoNoCheck(data.appInfo);
         String packageName = packageInfo.mPackageName;
         if (mBackupAgents.get(packageName) != null) {
-            Log.d(TAG, "BackupAgent " + "  for " + packageName
+            Slog.d(TAG, "BackupAgent " + "  for " + packageName
                     + " already exists");
             return;
         }
@@ -2851,7 +2877,7 @@
                 agent = (BackupAgent) cl.loadClass(data.appInfo.backupAgentName).newInstance();
 
                 // set up the agent's context
-                if (DEBUG_BACKUP) Log.v(TAG, "Initializing BackupAgent "
+                if (DEBUG_BACKUP) Slog.v(TAG, "Initializing BackupAgent "
                         + data.appInfo.backupAgentName);
 
                 ContextImpl context = new ContextImpl();
@@ -2886,7 +2912,7 @@
 
     // Tear down a BackupAgent
     private final void handleDestroyBackupAgent(CreateBackupAgentData data) {
-        if (DEBUG_BACKUP) Log.v(TAG, "handleDestroyBackupAgent: " + data);
+        if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data);
 
         PackageInfo packageInfo = getPackageInfoNoCheck(data.appInfo);
         String packageName = packageInfo.mPackageName;
@@ -2924,7 +2950,7 @@
         }
 
         try {
-            if (localLOGV) Log.v(TAG, "Creating service " + data.info.name);
+            if (localLOGV) Slog.v(TAG, "Creating service " + data.info.name);
 
             ContextImpl context = new ContextImpl();
             context.init(packageInfo, null, this);
@@ -3049,7 +3075,7 @@
         Service s = mServices.remove(token);
         if (s != null) {
             try {
-                if (localLOGV) Log.v(TAG, "Destroying service " + s);
+                if (localLOGV) Slog.v(TAG, "Destroying service " + s);
                 s.onDestroy();
                 Context context = s.getBaseContext();
                 if (context instanceof ContextImpl) {
@@ -3070,13 +3096,13 @@
                 }
             }
         }
-        //Log.i(TAG, "Running services: " + mServices);
+        //Slog.i(TAG, "Running services: " + mServices);
     }
 
     public final ActivityRecord performResumeActivity(IBinder token,
             boolean clearHide) {
         ActivityRecord r = mActivities.get(token);
-        if (localLOGV) Log.v(TAG, "Performing resume of " + r
+        if (localLOGV) Slog.v(TAG, "Performing resume of " + r
                 + " finished=" + r.activity.mFinished);
         if (r != null && !r.activity.mFinished) {
             if (clearHide) {
@@ -3122,7 +3148,7 @@
         if (r != null) {
             final Activity a = r.activity;
 
-            if (localLOGV) Log.v(
+            if (localLOGV) Slog.v(
                 TAG, "Resume " + r + " started activity: " +
                 a.mStartedActivity + ", hideForNow: " + r.hideForNow
                 + ", finished: " + a.mFinished);
@@ -3159,7 +3185,7 @@
             // we started another activity, then don't yet make the
             // window visible.
             } else if (!willBeVisible) {
-                if (localLOGV) Log.v(
+                if (localLOGV) Slog.v(
                     TAG, "Launch " + r + " mStartedActivity set");
                 r.hideForNow = true;
             }
@@ -3169,12 +3195,12 @@
             if (!r.activity.mFinished && willBeVisible
                     && r.activity.mDecor != null && !r.hideForNow) {
                 if (r.newConfig != null) {
-                    if (DEBUG_CONFIGURATION) Log.v(TAG, "Resuming activity "
+                    if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity "
                             + r.activityInfo.name + " with newConfig " + r.newConfig);
                     performConfigurationChanged(r.activity, r.newConfig);
                     r.newConfig = null;
                 }
-                if (localLOGV) Log.v(TAG, "Resuming " + r + " with isForward="
+                if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward="
                         + isForward);
                 WindowManager.LayoutParams l = r.window.getAttributes();
                 if ((l.softInputMode
@@ -3198,7 +3224,7 @@
 
             r.nextIdle = mNewActivities;
             mNewActivities = r;
-            if (localLOGV) Log.v(
+            if (localLOGV) Slog.v(
                 TAG, "Scheduling idle handler for " + r);
             Looper.myQueue().addIdleHandler(new Idler());
 
@@ -3256,7 +3282,7 @@
             boolean userLeaving, int configChanges) {
         ActivityRecord r = mActivities.get(token);
         if (r != null) {
-            //Log.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r);
+            //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r);
             if (userLeaving) {
                 performUserLeavingActivity(r);
             }
@@ -3351,7 +3377,7 @@
 
     private final void performStopActivityInner(ActivityRecord r,
             StopInfo info, boolean keepShown) {
-        if (localLOGV) Log.v(TAG, "Performing stop of " + r);
+        if (localLOGV) Slog.v(TAG, "Performing stop of " + r);
         if (r != null) {
             if (!keepShown && r.stopped) {
                 if (r.activity.mFinished) {
@@ -3412,7 +3438,7 @@
                     }
                 }
                 if (r.newConfig != null) {
-                    if (DEBUG_CONFIGURATION) Log.v(TAG, "Updating activity vis "
+                    if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis "
                             + r.activityInfo.name + " with new config " + r.newConfig);
                     performConfigurationChanged(r.activity, r.newConfig);
                     r.newConfig = null;
@@ -3434,7 +3460,7 @@
         StopInfo info = new StopInfo();
         performStopActivityInner(r, info, show);
 
-        if (localLOGV) Log.v(
+        if (localLOGV) Slog.v(
             TAG, "Finishing stop of " + r + ": show=" + show
             + " win=" + r.window);
 
@@ -3469,7 +3495,7 @@
             r.stopped = false;
         }
         if (r.activity.mDecor != null) {
-            if (Config.LOGV) Log.v(
+            if (Config.LOGV) Slog.v(
                 TAG, "Handle window " + r + " visibility: " + show);
             updateVisibility(r, show);
         }
@@ -3483,7 +3509,7 @@
                 if (ri.mData != null) {
                     ri.mData.setExtrasClassLoader(r.activity.getClassLoader());
                 }
-                if (DEBUG_RESULTS) Log.v(TAG,
+                if (DEBUG_RESULTS) Slog.v(TAG,
                         "Delivering result to activity " + r + " : " + ri);
                 r.activity.dispatchActivityResult(ri.mResultWho,
                         ri.mRequestCode, ri.mResultCode, ri.mData);
@@ -3500,7 +3526,7 @@
 
     private final void handleSendResult(ResultData res) {
         ActivityRecord r = mActivities.get(res.token);
-        if (DEBUG_RESULTS) Log.v(TAG, "Handling send result to " + r);
+        if (DEBUG_RESULTS) Slog.v(TAG, "Handling send result to " + r);
         if (r != null) {
             final boolean resumed = !r.paused;
             if (!r.activity.mFinished && r.activity.mDecor != null
@@ -3545,7 +3571,7 @@
     private final ActivityRecord performDestroyActivity(IBinder token, boolean finishing,
             int configChanges, boolean getNonConfigInstance) {
         ActivityRecord r = mActivities.get(token);
-        if (localLOGV) Log.v(TAG, "Performing finish of " + r);
+        if (localLOGV) Slog.v(TAG, "Performing finish of " + r);
         if (r != null) {
             r.activity.mConfigChangeFlags |= configChanges;
             if (finishing) {
@@ -3695,7 +3721,7 @@
 
         Configuration changedConfig = null;
 
-        if (DEBUG_CONFIGURATION) Log.v(TAG, "Relaunching activity "
+        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity "
                 + tmp.token + " with configChanges=0x"
                 + Integer.toHexString(configChanges));
         
@@ -3717,7 +3743,7 @@
             }
 
             if (tmp == null) {
-                if (DEBUG_CONFIGURATION) Log.v(TAG, "Abort, activity not relaunching!");
+                if (DEBUG_CONFIGURATION) Slog.v(TAG, "Abort, activity not relaunching!");
                 return;
             }
 
@@ -3741,7 +3767,7 @@
             }
         }
         
-        if (DEBUG_CONFIGURATION) Log.v(TAG, "Relaunching activity "
+        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity "
                 + tmp.token + ": changedConfig=" + changedConfig);
         
         // If there was a pending configuration change, execute it first.
@@ -3750,7 +3776,7 @@
         }
 
         ActivityRecord r = mActivities.get(tmp.token);
-        if (DEBUG_CONFIGURATION) Log.v(TAG, "Handling relaunch of " + r);
+        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handling relaunch of " + r);
         if (r == null) {
             return;
         }
@@ -3836,7 +3862,7 @@
                         // the activity manager may, before then, decide the
                         // activity needs to be destroyed to handle its new
                         // configuration.
-                        if (DEBUG_CONFIGURATION) Log.v(TAG, "Setting activity "
+                        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Setting activity "
                                 + ar.activityInfo.name + " newConfig=" + newConfig);
                         ar.newConfig = newConfig;
                     }
@@ -3895,7 +3921,7 @@
             }
         }
 
-        if (DEBUG_CONFIGURATION) Log.v(TAG, "Config callback " + cb
+        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Config callback " + cb
                 + ": shouldChangeConfig=" + shouldChangeConfig);
         if (shouldChangeConfig) {
             cb.onConfigurationChanged(config);
@@ -3917,7 +3943,7 @@
             mResConfiguration = new Configuration();
         }
         if (!mResConfiguration.isOtherSeqNewer(config)) {
-            if (DEBUG_CONFIGURATION) Log.v(TAG, "Skipping new config: curSeq="
+            if (DEBUG_CONFIGURATION) Slog.v(TAG, "Skipping new config: curSeq="
                     + mResConfiguration.seq + ", newSeq=" + config.seq);
             return false;
         }
@@ -3932,7 +3958,7 @@
         Resources.updateSystemConfiguration(config, dm);
 
         ContextImpl.ApplicationPackageManager.configurationChanged();
-        //Log.i(TAG, "Configuration changed in " + currentPackageName());
+        //Slog.i(TAG, "Configuration changed in " + currentPackageName());
         
         Iterator<WeakReference<Resources>> it =
             mActiveResources.values().iterator();
@@ -3942,13 +3968,13 @@
             WeakReference<Resources> v = it.next();
             Resources r = v.get();
             if (r != null) {
-                if (DEBUG_CONFIGURATION) Log.v(TAG, "Changing resources "
+                if (DEBUG_CONFIGURATION) Slog.v(TAG, "Changing resources "
                         + r + " config to: " + config);
                 r.updateConfiguration(config, dm);
-                //Log.i(TAG, "Updated app resources " + v.getKey()
+                //Slog.i(TAG, "Updated app resources " + v.getKey()
                 //        + " " + r + ": " + r.getConfiguration());
             } else {
-                //Log.i(TAG, "Removing old resources " + v.getKey());
+                //Slog.i(TAG, "Removing old resources " + v.getKey());
                 it.remove();
             }
         }
@@ -3972,7 +3998,7 @@
                 return;
             }
             
-            if (DEBUG_CONFIGURATION) Log.v(TAG, "Handle configuration changed: "
+            if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: "
                     + config);
         
             applyConfigurationToResourcesLocked(config);
@@ -4002,7 +4028,7 @@
             return;
         }
 
-        if (DEBUG_CONFIGURATION) Log.v(TAG, "Handle activity config changed: "
+        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: "
                 + r.activityInfo.name);
         
         performConfigurationChanged(r.activity, mConfiguration);
@@ -4095,7 +4121,7 @@
             // XXX should have option to change the port.
             Debug.changeDebugPort(8100);
             if (data.debugMode == IApplicationThread.DEBUG_WAIT) {
-                Log.w(TAG, "Application " + data.info.getPackageName()
+                Slog.w(TAG, "Application " + data.info.getPackageName()
                       + " is waiting for the debugger on port 8100...");
 
                 IActivityManager mgr = ActivityManagerNative.getDefault();
@@ -4112,7 +4138,7 @@
                 }
 
             } else {
-                Log.w(TAG, "Application " + data.info.getPackageName()
+                Slog.w(TAG, "Application " + data.info.getPackageName()
                       + " can be debugged on port 8100...");
             }
         }
@@ -4208,7 +4234,7 @@
         if (mBoundApplication.profileFile != null && mBoundApplication.handlingProfiling) {
             Debug.stopMethodTracing();
         }
-        //Log.i(TAG, "am: " + ActivityManagerNative.getDefault()
+        //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault()
         //      + ", app thr: " + mAppThread);
         try {
             am.finishInstrumentation(mAppThread, resultCode, results);
@@ -4275,12 +4301,12 @@
 
         IContentProvider prov = installProvider(context, holder.provider,
                 holder.info, true);
-        //Log.i(TAG, "noReleaseNeeded=" + holder.noReleaseNeeded);
+        //Slog.i(TAG, "noReleaseNeeded=" + holder.noReleaseNeeded);
         if (holder.noReleaseNeeded || holder.provider == null) {
             // We are not going to release the provider if it is an external
             // provider that doesn't care about being released, or if it is
             // a local provider running in this process.
-            //Log.i(TAG, "*** NO RELEASE NEEDED");
+            //Slog.i(TAG, "*** NO RELEASE NEEDED");
             synchronized(mProviderMap) {
                 mProviderRefCountMap.put(prov.asBinder(), new ProviderRefCount(10000));
             }
@@ -4312,7 +4338,7 @@
         synchronized(mProviderMap) {
             ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
             if(prc == null) {
-                if(localLOGV) Log.v(TAG, "releaseProvider::Weird shouldnt be here");
+                if(localLOGV) Slog.v(TAG, "releaseProvider::Weird shouldnt be here");
                 return false;
             } else {
                 prc.count--;
@@ -4344,7 +4370,7 @@
         
         if (name != null) {
             try {
-                if(localLOGV) Log.v(TAG, "removeProvider::Invoking " +
+                if(localLOGV) Slog.v(TAG, "removeProvider::Invoking " +
                         "ActivityManagerNative.removeContentProvider(" + name);
                 ActivityManagerNative.getDefault().removeContentProvider(
                         getApplicationThread(), name);
@@ -4370,10 +4396,10 @@
             if (myBinder == providerBinder) {
                 //find if its published by this process itself
                 if(pr.mLocalProvider != null) {
-                    if(localLOGV) Log.i(TAG, "removeProvider::found local provider returning");
+                    if(localLOGV) Slog.i(TAG, "removeProvider::found local provider returning");
                     return name;
                 }
-                if(localLOGV) Log.v(TAG, "removeProvider::Not local provider Unlinking " +
+                if(localLOGV) Slog.v(TAG, "removeProvider::Not local provider Unlinking " +
                         "death recipient");
                 //content provider is in another process
                 myBinder.unlinkToDeath(pr, 0);
@@ -4392,7 +4418,7 @@
         synchronized(mProviderMap) {
             ProviderRecord pr = mProviderMap.get(name);
             if (pr.mProvider.asBinder() == provider.asBinder()) {
-                Log.i(TAG, "Removing dead content provider: " + name);
+                Slog.i(TAG, "Removing dead content provider: " + name);
                 ProviderRecord removed = mProviderMap.remove(name);
                 if (removed != null) {
                     removed.mProvider.asBinder().unlinkToDeath(removed, 0);
@@ -4404,7 +4430,7 @@
     final void removeDeadProviderLocked(String name, IContentProvider provider) {
         ProviderRecord pr = mProviderMap.get(name);
         if (pr.mProvider.asBinder() == provider.asBinder()) {
-            Log.i(TAG, "Removing dead content provider: " + name);
+            Slog.i(TAG, "Removing dead content provider: " + name);
             ProviderRecord removed = mProviderMap.remove(name);
             if (removed != null) {
                 removed.mProvider.asBinder().unlinkToDeath(removed, 0);
@@ -4417,7 +4443,7 @@
         ContentProvider localProvider = null;
         if (provider == null) {
             if (noisy) {
-                Log.d(TAG, "Loading provider " + info.authority + ": "
+                Slog.d(TAG, "Loading provider " + info.authority + ": "
                         + info.name);
             }
             Context c = null;
@@ -4452,7 +4478,7 @@
                           info.applicationInfo.sourceDir);
                     return null;
                 }
-                if (Config.LOGV) Log.v(
+                if (Config.LOGV) Slog.v(
                     TAG, "Instantiating local provider " + info.name);
                 // XXX Need to create the correct context for this provider.
                 localProvider.attachInfo(c, info);
@@ -4465,7 +4491,7 @@
                 return null;
             }
         } else if (localLOGV) {
-            Log.v(TAG, "Installing external provider " + info.authority + ": "
+            Slog.v(TAG, "Installing external provider " + info.authority + ": "
                     + info.name);
         }
 
@@ -4586,6 +4612,6 @@
         String name = (thread.mInitialApplication != null)
             ? thread.mInitialApplication.getPackageName()
             : "<unknown>";
-        Log.i(TAG, "Main thread of " + name + " is now exiting");
+        Slog.i(TAG, "Main thread of " + name + " is now exiting");
     }
 }
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 9019af6..fd0edaa 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -796,7 +796,7 @@
                     scheduler = mMainThread.getHandler();
                 }
                 rd = new ActivityThread.PackageInfo.ReceiverDispatcher(
-                        receiver, context, scheduler, null, false).getIIntentReceiver();
+                        receiver, context, scheduler, null, true).getIIntentReceiver();
             }
         }
         try {
diff --git a/core/java/android/database/sqlite/SQLiteCompiledSql.java b/core/java/android/database/sqlite/SQLiteCompiledSql.java
index 72ceb9b..047e176 100644
--- a/core/java/android/database/sqlite/SQLiteCompiledSql.java
+++ b/core/java/android/database/sqlite/SQLiteCompiledSql.java
@@ -54,6 +54,9 @@
     private boolean mInUse = false;
 
     /* package */ SQLiteCompiledSql(SQLiteDatabase db, String sql) {
+        if (!db.isOpen()) {
+            throw new IllegalStateException("database " + db.getPath() + " already closed");
+        }
         mDatabase = db;
         mSqlStmt = sql;
         mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
@@ -75,6 +78,9 @@
      *  existing compiled SQL program already around
      */
     private void compile(String sql, boolean forceCompilation) {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         // Only compile if we don't have a valid statement already or the caller has
         // explicitly requested a recompile.
         if (forceCompilation) {
@@ -90,6 +96,9 @@
     }
 
     /* package */ void releaseSqlStatement() {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         // Note that native_finalize() checks to make sure that nStatement is
         // non-null before destroying it.
         if (nStatement != 0) {
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index 3b7416e..70f681f 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -500,10 +500,10 @@
      * {@link #yieldIfContendedSafely}.
      */
     public void beginTransactionWithListener(SQLiteTransactionListener transactionListener) {
+        lockForced();
         if (!isOpen()) {
             throw new IllegalStateException("database not open");
         }
-        lockForced();
         boolean ok = false;
         try {
             // If this thread already had the lock then get out
@@ -915,11 +915,11 @@
      * @return the database version
      */
     public int getVersion() {
+        SQLiteStatement prog = null;
+        lock();
         if (!isOpen()) {
             throw new IllegalStateException("database not open");
         }
-        SQLiteStatement prog = null;
-        lock();
         try {
             prog = new SQLiteStatement(this, "PRAGMA user_version;");
             long version = prog.simpleQueryForLong();
@@ -936,9 +936,6 @@
      * @param version the new database version
      */
     public void setVersion(int version) {
-        if (!isOpen()) {
-            throw new IllegalStateException("database not open");
-        }
         execSQL("PRAGMA user_version = " + version);
     }
 
@@ -948,11 +945,11 @@
      * @return the new maximum database size
      */
     public long getMaximumSize() {
+        SQLiteStatement prog = null;
+        lock();
         if (!isOpen()) {
             throw new IllegalStateException("database not open");
         }
-        SQLiteStatement prog = null;
-        lock();
         try {
             prog = new SQLiteStatement(this,
                     "PRAGMA max_page_count;");
@@ -972,11 +969,11 @@
      * @return the new maximum database size
      */
     public long setMaximumSize(long numBytes) {
+        SQLiteStatement prog = null;
+        lock();
         if (!isOpen()) {
             throw new IllegalStateException("database not open");
         }
-        SQLiteStatement prog = null;
-        lock();
         try {
             long pageSize = getPageSize();
             long numPages = numBytes / pageSize;
@@ -1000,11 +997,11 @@
      * @return the database page size, in bytes
      */
     public long getPageSize() {
+        SQLiteStatement prog = null;
+        lock();
         if (!isOpen()) {
             throw new IllegalStateException("database not open");
         }
-        SQLiteStatement prog = null;
-        lock();
         try {
             prog = new SQLiteStatement(this,
                     "PRAGMA page_size;");
@@ -1024,9 +1021,6 @@
      * @param numBytes the database page size, in bytes
      */
     public void setPageSize(long numBytes) {
-        if (!isOpen()) {
-            throw new IllegalStateException("database not open");
-        }
         execSQL("PRAGMA page_size = " + numBytes);
     }
 
@@ -1143,10 +1137,10 @@
      * @return a pre-compiled statement object.
      */
     public SQLiteStatement compileStatement(String sql) throws SQLException {
+        lock();
         if (!isOpen()) {
             throw new IllegalStateException("database not open");
         }
-        lock();
         try {
             return new SQLiteStatement(this, sql);
         } finally {
@@ -1586,10 +1580,10 @@
      *         whereClause.
      */
     public int delete(String table, String whereClause, String[] whereArgs) {
+        lock();
         if (!isOpen()) {
             throw new IllegalStateException("database not open");
         }
-        lock();
         SQLiteStatement statement = null;
         try {
             statement = compileStatement("DELETE FROM " + table
@@ -1641,10 +1635,6 @@
      */
     public int updateWithOnConflict(String table, ContentValues values,
             String whereClause, String[] whereArgs, int conflictAlgorithm) {
-        if (!isOpen()) {
-            throw new IllegalStateException("database not open");
-        }
-
         if (values == null || values.size() == 0) {
             throw new IllegalArgumentException("Empty values");
         }
@@ -1673,6 +1663,9 @@
         }
 
         lock();
+        if (!isOpen()) {
+            throw new IllegalStateException("database not open");
+        }
         SQLiteStatement statement = null;
         try {
             statement = compileStatement(sql.toString());
@@ -1724,11 +1717,11 @@
      * @throws SQLException If the SQL string is invalid for some reason
      */
     public void execSQL(String sql) throws SQLException {
+        long timeStart = SystemClock.uptimeMillis();
+        lock();
         if (!isOpen()) {
             throw new IllegalStateException("database not open");
         }
-        long timeStart = SystemClock.uptimeMillis();
-        lock();
         logTimeStat(mLastSqlStatement, timeStart, GET_LOCK_LOG_PREFIX);
         try {
             native_execSQL(sql);
@@ -1759,14 +1752,14 @@
      * @throws SQLException If the SQL string is invalid for some reason
      */
     public void execSQL(String sql, Object[] bindArgs) throws SQLException {
-        if (!isOpen()) {
-            throw new IllegalStateException("database not open");
-        }
         if (bindArgs == null) {
             throw new IllegalArgumentException("Empty bindArgs");
         }
         long timeStart = SystemClock.uptimeMillis();
         lock();
+        if (!isOpen()) {
+            throw new IllegalStateException("database not open");
+        }
         SQLiteStatement statement = null;
         try {
             statement = compileStatement(sql);
diff --git a/core/java/android/database/sqlite/SQLiteProgram.java b/core/java/android/database/sqlite/SQLiteProgram.java
index 66ce3b0..5f13eb1 100644
--- a/core/java/android/database/sqlite/SQLiteProgram.java
+++ b/core/java/android/database/sqlite/SQLiteProgram.java
@@ -173,6 +173,9 @@
      * @param index The 1-based index to the parameter to bind null to
      */
     public void bindNull(int index) {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         acquireReference();
         try {
             native_bind_null(index);
@@ -189,6 +192,9 @@
      * @param value The value to bind
      */
     public void bindLong(int index, long value) {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         acquireReference();
         try {
             native_bind_long(index, value);
@@ -205,6 +211,9 @@
      * @param value The value to bind
      */
     public void bindDouble(int index, double value) {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         acquireReference();
         try {
             native_bind_double(index, value);
@@ -224,6 +233,9 @@
         if (value == null) {
             throw new IllegalArgumentException("the bind value at index " + index + " is null");
         }
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         acquireReference();
         try {
             native_bind_string(index, value);
@@ -243,6 +255,9 @@
         if (value == null) {
             throw new IllegalArgumentException("the bind value at index " + index + " is null");
         }
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         acquireReference();
         try {
             native_bind_blob(index, value);
@@ -255,6 +270,9 @@
      * Clears all existing bindings. Unset bindings are treated as NULL.
      */
     public void clearBindings() {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         acquireReference();
         try {
             native_clear_bindings();
@@ -267,6 +285,9 @@
      * Release this program's resources, making it invalid.
      */
     public void close() {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         mDatabase.lock();
         try {
             releaseReference();
diff --git a/core/java/android/database/sqlite/SQLiteQueryBuilder.java b/core/java/android/database/sqlite/SQLiteQueryBuilder.java
index 1d154ce..610bf70 100644
--- a/core/java/android/database/sqlite/SQLiteQueryBuilder.java
+++ b/core/java/android/database/sqlite/SQLiteQueryBuilder.java
@@ -43,6 +43,7 @@
     private StringBuilder mWhereClause = null;  // lazily created
     private boolean mDistinct;
     private SQLiteDatabase.CursorFactory mFactory;
+    private boolean mStrictProjectionMap;
 
     public SQLiteQueryBuilder() {
         mDistinct = false;
@@ -144,6 +145,13 @@
     }
 
     /**
+     * @hide
+     */
+    public void setStrictProjectionMap(boolean flag) {
+        mStrictProjectionMap = flag;
+    }
+
+    /**
      * Build an SQL query string from the given clauses.
      *
      * @param distinct true if you want each row to be unique, false otherwise.
@@ -505,8 +513,8 @@
                         continue;
                     }
 
-                    if (userColumn.contains(" AS ")
-                            || userColumn.contains(" as ")) {
+                    if (!mStrictProjectionMap &&
+                            ( userColumn.contains(" AS ") || userColumn.contains(" as "))) {
                         /* A column alias already exist */
                         projection[i] = userColumn;
                         continue;
diff --git a/core/java/android/database/sqlite/SQLiteStatement.java b/core/java/android/database/sqlite/SQLiteStatement.java
index 7f484ff..98da414 100644
--- a/core/java/android/database/sqlite/SQLiteStatement.java
+++ b/core/java/android/database/sqlite/SQLiteStatement.java
@@ -44,6 +44,9 @@
      *         some reason
      */
     public void execute() {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         long timeStart = SystemClock.uptimeMillis();
         mDatabase.lock();
 
@@ -67,6 +70,9 @@
      *         some reason
      */
     public long executeInsert() {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         long timeStart = SystemClock.uptimeMillis();
         mDatabase.lock();
 
@@ -90,6 +96,9 @@
      * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows
      */
     public long simpleQueryForLong() {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         long timeStart = SystemClock.uptimeMillis();
         mDatabase.lock();
 
@@ -113,6 +122,9 @@
      * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows
      */
     public String simpleQueryForString() {
+        if (!mDatabase.isOpen()) {
+            throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+        }
         long timeStart = SystemClock.uptimeMillis();
         mDatabase.lock();
 
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index eee8025..eda2e72 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -132,6 +132,7 @@
                     if (mVideoView.isPlaying()) {
                         mVideoView.stopPlayback();
                     }
+                    mCurrentProxy.dispatchOnEnded();
                     mCurrentProxy = null;
                     mLayout.removeView(mVideoView);
                     mVideoView = null;
@@ -154,7 +155,7 @@
 
             if (mCurrentProxy != null) {
                 // Some other video is already playing. Notify the caller that its playback ended.
-                proxy.playbackEnded();
+                proxy.dispatchOnEnded();
                 return;
             }
 
@@ -245,7 +246,10 @@
 
     // MediaPlayer.OnCompletionListener;
     public void onCompletion(MediaPlayer mp) {
-        playbackEnded();
+        // The video ended by itself, so we need to
+        // send a message to the UI thread to dismiss
+        // the video view and to return to the WebView.
+        sendMessage(obtainMessage(ENDED));
     }
 
     // MediaPlayer.OnErrorListener
@@ -254,11 +258,9 @@
         return false;
     }
 
-    public void playbackEnded() {
+    public void dispatchOnEnded() {
         Message msg = Message.obtain(mWebCoreHandler, ENDED);
         mWebCoreHandler.sendMessage(msg);
-        // also send a message to ourselves to return to the WebView
-        sendMessage(obtainMessage(ENDED));
     }
 
     public void onTimeupdate() {
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 7bd83e7..602eedf 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -540,10 +540,10 @@
     static final int FIND_AGAIN                         = 126;
     static final int CENTER_FIT_RECT                    = 127;
     static final int REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID = 128;
+    static final int SET_SCROLLBAR_MODES                = 129;
 
     private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID;
-    private static final int LAST_PACKAGE_MSG_ID
-            = REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID;
+    private static final int LAST_PACKAGE_MSG_ID = SET_SCROLLBAR_MODES;
 
     static final String[] HandlerPrivateDebugString = {
         "REMEMBER_PASSWORD", //              = 1;
@@ -586,7 +586,8 @@
         "RETURN_LABEL", //                   = 125;
         "FIND_AGAIN", //                     = 126;
         "CENTER_FIT_RECT", //                = 127;
-        "REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID" // = 128;
+        "REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID", // = 128;
+        "SET_SCROLLBAR_MODES" //             = 129;
     };
 
     // If the site doesn't use the viewport meta tag to specify the viewport,
@@ -657,6 +658,14 @@
     private static final int DRAW_EXTRAS_SELECTION = 2;
     private static final int DRAW_EXTRAS_CURSOR_RING = 3;
 
+    // keep this in sync with WebCore:ScrollbarMode in WebKit
+    private static final int SCROLLBAR_AUTO = 0;
+    private static final int SCROLLBAR_ALWAYSOFF = 1;
+    // as we auto fade scrollbar, this is ignored.
+    private static final int SCROLLBAR_ALWAYSON = 2;
+    private int mHorizontalScrollBarMode = SCROLLBAR_AUTO;
+    private int mVerticalScrollBarMode = SCROLLBAR_AUTO;
+
     // Used to match key downs and key ups
     private boolean mGotKeyDown;
 
@@ -2277,6 +2286,8 @@
     protected int computeHorizontalScrollRange() {
         if (mDrawHistory) {
             return mHistoryWidth;
+        } else if (mHorizontalScrollBarMode == SCROLLBAR_ALWAYSOFF) {
+            return computeHorizontalScrollExtent();
         } else {
             // to avoid rounding error caused unnecessary scrollbar, use floor
             return (int) Math.floor(mContentWidth * mActualScale);
@@ -2287,6 +2298,8 @@
     protected int computeVerticalScrollRange() {
         if (mDrawHistory) {
             return mHistoryHeight;
+        } else if (mVerticalScrollBarMode == SCROLLBAR_ALWAYSOFF) {
+            return computeVerticalScrollExtent();
         } else {
             // to avoid rounding error caused unnecessary scrollbar, use floor
             return (int) Math.floor(mContentHeight * mActualScale);
@@ -5024,7 +5037,9 @@
         if (settings.supportZoom()
                 && settings.getBuiltInZoomControls()
                 && !getZoomButtonsController().isVisible()
-                && mMinZoomScale < mMaxZoomScale) {
+                && mMinZoomScale < mMaxZoomScale
+                && (mHorizontalScrollBarMode != SCROLLBAR_ALWAYSOFF
+                        || mVerticalScrollBarMode != SCROLLBAR_ALWAYSOFF)) {
             mZoomButtonsController.setVisible(true);
             int count = settings.getDoubleTapToastCount();
             if (mInZoomOverview && count > 0) {
@@ -6641,6 +6656,11 @@
                     centerFitRect(r.left, r.top, r.width(), r.height());
                     break;
 
+                case SET_SCROLLBAR_MODES:
+                    mHorizontalScrollBarMode = msg.arg1;
+                    mVerticalScrollBarMode = msg.arg2;
+                    break;
+
                 default:
                     super.handleMessage(msg);
                     break;
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 0175aed..4118119 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -2453,6 +2453,15 @@
                 new Rect(x, y, x + width, y + height)).sendToTarget();
     }
 
+    // called by JNI
+    private void setScrollbarModes(int hMode, int vMode) {
+        if (mWebView == null) {
+            return;
+        }
+        mWebView.mPrivateHandler.obtainMessage(WebView.SET_SCROLLBAR_MODES,
+                hMode, vMode).sendToTarget();
+    }
+
     private native void nativePause();
     private native void nativeResume();
     private native void nativeFreeMemory();
diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
index 7fa64ca..7ced94f 100755
--- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
+++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
@@ -165,12 +165,18 @@
         }
     }
 
-    PackageManager getPm() {
+    private PackageManager getPm() {
         return mContext.getPackageManager();
     }
 
+    private IPackageManager getIPm() {
+        IPackageManager ipm  = IPackageManager.Stub.asInterface(
+                ServiceManager.getService("package"));
+        return ipm;
+    }
+
     public boolean invokeInstallPackage(Uri packageURI, int flags,
-            final String pkgName, GenericReceiver receiver) throws Exception {
+            GenericReceiver receiver) throws Exception {
         PackageInstallObserver observer = new PackageInstallObserver();
         final boolean received = false;
         mContext.registerReceiver(receiver, receiver.filter);
@@ -209,8 +215,7 @@
         }
     }
 
-    public boolean invokeInstallPackageFail(Uri packageURI, int flags,
-            final String pkgName, int result) throws Exception {
+    public void invokeInstallPackageFail(Uri packageURI, int flags, int result) throws Exception {
         PackageInstallObserver observer = new PackageInstallObserver();
         try {
             // Wait on observer
@@ -224,7 +229,7 @@
                 if(!observer.isDone()) {
                     throw new Exception("Timed out waiting for packageInstalled callback");
                 }
-                return (observer.returnCode == result);
+                assertEquals(observer.returnCode, result);
             }
         } finally {
         }
@@ -284,17 +289,6 @@
     private static final int INSTALL_LOC_INT = 1;
     private static final int INSTALL_LOC_SD = 2;
     private static final int INSTALL_LOC_ERR = -1;
-    private int checkDefaultPolicy(long pkgLen) {
-        // Check for free memory internally
-        if (checkInt(pkgLen)) {
-            return INSTALL_LOC_INT;
-        }
-        // Check for free memory externally
-        if (checkSd(pkgLen)) {
-            return INSTALL_LOC_SD;
-        }
-        return INSTALL_LOC_ERR;
-    }
     private int getInstallLoc(int flags, int expInstallLocation, long pkgLen) {
         // Flags explicitly over ride everything else.
         if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0 ) {
@@ -306,7 +300,6 @@
         }
         // Manifest option takes precedence next
         if (expInstallLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) {
-            // TODO fitsonSd check
             if (checkSd(pkgLen)) {
                return INSTALL_LOC_SD;
             }
@@ -322,36 +315,36 @@
             return INSTALL_LOC_ERR;
         }
         if (expInstallLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
-            return checkDefaultPolicy(pkgLen);
+            // Check for free memory internally
+            if (checkInt(pkgLen)) {
+                return INSTALL_LOC_INT;
+            }
+            // Check for free memory externally
+            if (checkSd(pkgLen)) {
+                return INSTALL_LOC_SD;
+            }
+            return INSTALL_LOC_ERR;
         }
         // Check for settings preference.
         boolean checkSd = false;
-        int setLoc = 0;
-        try {
-            setLoc = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.SET_INSTALL_LOCATION);
-        } catch (SettingNotFoundException e) {
-            failStr(e);
-        }
-        if (setLoc == 1) {
-            int userPref = APP_INSTALL_AUTO;
-            try {
-                userPref = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.DEFAULT_INSTALL_LOCATION);
-            } catch (SettingNotFoundException e) {
-                failStr(e);
+        int userPref = getDefaultInstallLoc();
+        if (userPref == APP_INSTALL_DEVICE) {
+            if (checkInt(pkgLen)) {
+                return INSTALL_LOC_INT;
             }
-            if (userPref == APP_INSTALL_DEVICE) {
-                if (checkInt(pkgLen)) {
-                    return INSTALL_LOC_INT;
-                }
-                return INSTALL_LOC_ERR;
-            } else if (userPref == APP_INSTALL_SDCARD) {
-                if (checkSd(pkgLen)) {
-                    return INSTALL_LOC_SD;
-                }
-                return INSTALL_LOC_ERR;
+            return INSTALL_LOC_ERR;
+        } else if (userPref == APP_INSTALL_SDCARD) {
+            if (checkSd(pkgLen)) {
+                return INSTALL_LOC_SD;
             }
+            return INSTALL_LOC_ERR;
         }
-        return checkDefaultPolicy(pkgLen);
+        // Default system policy for apps with no manifest option specified.
+        // Check for free memory internally
+        if (checkInt(pkgLen)) {
+            return INSTALL_LOC_INT;
+        }
+        return INSTALL_LOC_ERR;
     }
     
     private void assertInstall(PackageParser.Package pkg, int flags, int expInstallLocation) {
@@ -402,14 +395,20 @@
     }
 
     class InstallParams {
-        String outFileName;
         Uri packageURI;
         PackageParser.Package pkg;
-        InstallParams(PackageParser.Package pkg, String outFileName, Uri packageURI) {
-            this.outFileName = outFileName;
-            this.packageURI = packageURI;
+        InstallParams(String outFileName, int rawResId) {
+            this.pkg = getParsedPackage(outFileName, rawResId);
+            this.packageURI = Uri.fromFile(new File(pkg.mScanPath));
+        }
+        InstallParams(PackageParser.Package pkg) {
+            this.packageURI = Uri.fromFile(new File(pkg.mScanPath));
             this.pkg = pkg;
         }
+        long getApkSize() {
+            File file = new File(pkg.mScanPath);
+            return file.length();
+        }
     }
 
     private InstallParams sampleInstallFromRawResource(int flags, boolean cleanUp) {
@@ -520,45 +519,36 @@
      * copies it into own data directory and invokes
      * PackageManager api to install it.
      */
-    private InstallParams installFromRawResource(String outFileName,
-            int rawResId, int flags, boolean cleanUp, boolean fail, int result,
+    private void installFromRawResource(InstallParams ip,
+            int flags, boolean cleanUp, boolean fail, int result,
             int expInstallLocation) {
         PackageManager pm = mContext.getPackageManager();
-        File filesDir = mContext.getFilesDir();
-        File outFile = new File(filesDir, outFileName);
-        Uri packageURI = getInstallablePackage(rawResId, outFile);
-        PackageParser.Package pkg = parsePackage(packageURI);
-        assertNotNull(pkg);
+        PackageParser.Package pkg = ip.pkg;
+        Uri packageURI = ip.packageURI;
         if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) == 0) {
             // Make sure the package doesn't exist
             try {
                 ApplicationInfo appInfo = pm.getApplicationInfo(pkg.packageName,
                         PackageManager.GET_UNINSTALLED_PACKAGES);
                 GenericReceiver receiver = new DeleteReceiver(pkg.packageName);
-                invokeDeletePackage(packageURI, 0,
-                        pkg.packageName, receiver);
+                invokeDeletePackage(pkg.packageName, 0, receiver);
             } catch (NameNotFoundException e1) {
             } catch (Exception e) {
                 failStr(e);
             }
         }
-        InstallParams ip = null;
         try {
             if (fail) {
-                assertTrue(invokeInstallPackageFail(packageURI, flags,
-                        pkg.packageName, result));
+                invokeInstallPackageFail(packageURI, flags, result);
                 if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) == 0) {
                     assertNotInstalled(pkg.packageName);
                 }
             } else {
                 InstallReceiver receiver = new InstallReceiver(pkg.packageName);
-                assertTrue(invokeInstallPackage(packageURI, flags,
-                        pkg.packageName, receiver));
+                assertTrue(invokeInstallPackage(packageURI, flags, receiver));
                 // Verify installed information
                 assertInstall(pkg, flags, expInstallLocation);
-                ip = new InstallParams(pkg, outFileName, packageURI);
             }
-            return ip;
         } catch (Exception e) {
             failStr("Failed with exception : " + e);
         } finally {
@@ -566,6 +556,19 @@
                 cleanUpInstall(ip);
             }
         }
+    }
+
+    /*
+     * Utility function that reads a apk bundled as a raw resource
+     * copies it into own data directory and invokes
+     * PackageManager api to install it.
+     */
+    private InstallParams installFromRawResource(String outFileName,
+            int rawResId, int flags, boolean cleanUp, boolean fail, int result,
+            int expInstallLocation) {
+        PackageManager pm = mContext.getPackageManager();
+        InstallParams ip = new InstallParams(outFileName, rawResId);
+        installFromRawResource(ip, flags, cleanUp, fail, result, expInstallLocation);
         return ip;
     }
 
@@ -654,8 +657,7 @@
         }
         try {
             try {
-                assertEquals(invokeInstallPackage(ip.packageURI, flags,
-                        ip.pkg.packageName, receiver), replace);
+                assertEquals(invokeInstallPackage(ip.packageURI, flags, receiver), replace);
                 if (replace) {
                     assertInstall(ip.pkg, flags, ip.pkg.installLocation);
                 }
@@ -736,8 +738,8 @@
         }
     }
 
-    public boolean invokeDeletePackage(Uri packageURI, int flags,
-            final String pkgName, GenericReceiver receiver) throws Exception {
+    public boolean invokeDeletePackage(final String pkgName, int flags,
+            GenericReceiver receiver) throws Exception {
         DeleteObserver observer = new DeleteObserver();
         final boolean received = false;
         mContext.registerReceiver(receiver, receiver.filter);
@@ -777,8 +779,7 @@
         GenericReceiver receiver = new DeleteReceiver(ip.pkg.packageName);
         DeleteObserver observer = new DeleteObserver();
         try {
-            assertTrue(invokeDeletePackage(ip.packageURI, dFlags,
-                    ip.pkg.packageName, receiver));
+            assertTrue(invokeDeletePackage(ip.pkg.packageName, dFlags, receiver));
             ApplicationInfo info = null;
             Log.i(TAG, "okay4");
             try {
@@ -907,7 +908,7 @@
 
     boolean getMediaState() {
         try {
-        String mPath = Environment.getExternalStorageDirectory().toString();
+        String mPath = Environment.getExternalStorageDirectory().getPath();
         String state = getMs().getVolumeState(mPath);
         return Environment.MEDIA_MOUNTED.equals(state);
         } catch (RemoteException e) {
@@ -928,13 +929,17 @@
         }
     }
 
-
-
     private boolean unmountMedia() {
-        if (!getMediaState()) {
-            return true;
+        String path = Environment.getExternalStorageDirectory().getPath();
+        try {
+            String state = getMs().getVolumeState(path);
+            if (Environment.MEDIA_UNMOUNTED.equals(state)) {
+                return true;
+            }
+        } catch (RemoteException e) {
+            failStr(e);
         }
-        String path = Environment.getExternalStorageDirectory().toString();
+        
         StorageListener observer = new StorageListener();
         StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
         sm.registerListener(observer);
@@ -948,11 +953,12 @@
                     waitTime += WAIT_TIME_INCR;
                 }
                 if(!observer.isDone()) {
-                    throw new Exception("Timed out waiting for packageInstalled callback");
+                    throw new Exception("Timed out waiting for unmount media notification");
                 }
                 return true;
             }
         } catch (Exception e) {
+            Log.e(TAG, "Exception : " + e);
             return false;
         } finally {
             sm.unregisterListener(observer);
@@ -1029,7 +1035,7 @@
         Runtime.getRuntime().gc();
         Log.i(TAG, "Deleting package : " + ip.pkg.packageName);
         getPm().deletePackage(ip.pkg.packageName, null, 0);
-        File outFile = new File(ip.outFileName);
+        File outFile = new File(ip.pkg.mScanPath);
         if (outFile != null && outFile.exists()) {
             outFile.delete();
         }
@@ -1095,8 +1101,7 @@
         GenericReceiver receiver = new ReplaceReceiver(ip.pkg.packageName);
         int replaceFlags = rFlags | PackageManager.INSTALL_REPLACE_EXISTING;
         try {
-            assertEquals(invokeInstallPackage(ip.packageURI, replaceFlags,
-                    ip.pkg.packageName, receiver), true);
+            assertEquals(invokeInstallPackage(ip.packageURI, replaceFlags, receiver), true);
             assertInstall(ip.pkg, rFlags, ip.pkg.installLocation);
         } catch (Exception e) {
             failStr("Failed with exception : " + e);
@@ -1117,8 +1122,7 @@
         GenericReceiver receiver = new ReplaceReceiver(ip.pkg.packageName);
         int replaceFlags = rFlags | PackageManager.INSTALL_REPLACE_EXISTING;
         try {
-            assertEquals(invokeInstallPackage(ip.packageURI, replaceFlags,
-                    ip.pkg.packageName, receiver), true);
+            assertEquals(invokeInstallPackage(ip.packageURI, replaceFlags, receiver), true);
             assertInstall(ip.pkg, iFlags, ip.pkg.installLocation);
         } catch (Exception e) {
             failStr("Failed with exception : " + e);
@@ -1298,11 +1302,9 @@
         return true;
     }
 
-    private int getInstallLoc() {
-        boolean userSetting = false;
+    private int getDefaultInstallLoc() {
         int origDefaultLoc = PackageInfo.INSTALL_LOCATION_AUTO;
         try {
-            userSetting = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.SET_INSTALL_LOCATION) != 0;
             origDefaultLoc = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.DEFAULT_INSTALL_LOCATION);
         } catch (SettingNotFoundException e1) {
         }
@@ -1326,7 +1328,7 @@
     private void moveFromRawResource(String outFileName,
             int rawResId, int installFlags, int moveFlags, boolean cleanUp,
             boolean fail, int result) {
-        int origDefaultLoc = getInstallLoc();
+        int origDefaultLoc = getDefaultInstallLoc();
         InstallParams ip = null;
         try {
             setInstallLoc(PackageHelper.APP_INSTALL_AUTO);
@@ -1416,7 +1418,7 @@
         final int result = PackageManager.MOVE_FAILED_DOESNT_EXIST;
         
         int rawResId = R.raw.install;
-        int origDefaultLoc = getInstallLoc();
+        int origDefaultLoc = getDefaultInstallLoc();
         InstallParams ip = null;
         try {
             PackageManager pm = getPm();
@@ -1447,10 +1449,10 @@
             // Unmount sdcard
             assertTrue(unmountMedia());
             // Try to install and make sure an error code is returned.
-            assertNull(installFromRawResource("install.apk", R.raw.install,
+            installFromRawResource("install.apk", R.raw.install,
                     PackageManager.INSTALL_EXTERNAL, false,
                     true, PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE,
-                    PackageInfo.INSTALL_LOCATION_AUTO));
+                    PackageInfo.INSTALL_LOCATION_AUTO);
         } finally {
             // Restore original media state
             if (origState) {
@@ -1470,11 +1472,9 @@
        try {
            // Unmount sdcard
            assertTrue(unmountMedia());
-           // Try to install and make sure an error code is returned.
-           assertNotNull(installFromRawResource("install.apk", R.raw.install_loc_sdcard,
-                   0, false,
-                   false, -1,
-                   PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY));
+           InstallParams ip = new InstallParams("install.apk", R.raw.install_loc_sdcard);
+           installFromRawResource(ip, 0, true, false, -1,
+                   PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
        } finally {
            // Restore original media state
            if (origState) {
@@ -1912,7 +1912,7 @@
                false,
                false, -1,
                PackageInfo.INSTALL_LOCATION_UNSPECIFIED);
-       int origSetting = getInstallLoc();
+       int origSetting = getDefaultInstallLoc();
        try {
            // Set user setting
            setInstallLoc(userSetting);
@@ -1976,7 +1976,7 @@
    }
    private void setUserX(boolean enable, int userSetting, int iloc) {
        boolean origUserSetting = getUserSettingSetInstallLocation();
-       int origSetting = getInstallLoc();
+       int origSetting = getDefaultInstallLoc();
        try {
            setUserSettingSetInstallLocation(enable);
            // Set user setting
@@ -2101,8 +2101,7 @@
             GenericReceiver receiver = new DeleteReceiver(ip.pkg.packageName);
            
             try {
-                invokeDeletePackage(ip.packageURI, PackageManager.DONT_DELETE_DATA,
-                        ip.pkg.packageName, receiver);
+                invokeDeletePackage(ip.pkg.packageName, PackageManager.DONT_DELETE_DATA, receiver);
             } catch (Exception e) {
                 failStr(e);
             }
@@ -2121,8 +2120,7 @@
             // **: Upon deleting package, are all permissions removed?
            
             try {
-                invokeDeletePackage(ip.packageURI, 0,
-                        ip.pkg.packageName, receiver);
+                invokeDeletePackage(ip.pkg.packageName, 0, receiver);
                 ip = null;
             } catch (Exception e) {
                 failStr(e);
@@ -2134,8 +2132,7 @@
            
             GenericReceiver receiver2 = new DeleteReceiver(ip2.pkg.packageName);
             try {
-                invokeDeletePackage(ip2.packageURI, 0,
-                        ip2.pkg.packageName, receiver);
+                invokeDeletePackage(ip2.pkg.packageName, 0, receiver);
                 ip2 = null;
             } catch (Exception e) {
                 failStr(e);
@@ -2170,8 +2167,7 @@
             // **: Upon deleting package, are all permissions removed?
             
             try {
-                invokeDeletePackage(ip.packageURI, 0,
-                        ip.pkg.packageName, receiver);
+                invokeDeletePackage(ip.pkg.packageName, 0, receiver);
                 ip = null;
             } catch (Exception e) {
                 failStr(e);
@@ -2182,8 +2178,7 @@
             // **: Delete package using permissions; nothing to check here.
             
             try {
-                invokeDeletePackage(ip2.packageURI, 0,
-                        ip2.pkg.packageName, receiver);
+                invokeDeletePackage(ip2.pkg.packageName, 0, receiver);
                 ip2 = null;
             } catch (Exception e) {
                 failStr(e);
@@ -2252,7 +2247,7 @@
             unmountMedia();
             // Delete the app on sdcard to leave a stale container on sdcard.
             GenericReceiver receiver = new DeleteReceiver(pkg.packageName);
-            assertTrue(invokeDeletePackage(packageURI, 0, pkg.packageName, receiver));
+            assertTrue(invokeDeletePackage(pkg.packageName, 0, receiver));
             mountMedia();
             // Reinstall the app and make sure it gets installed.
             installFromRawResource(outFileName, rawResId,
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
index 5969617..ea68352 100644
--- a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
+++ b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
@@ -90,6 +90,8 @@
 int DisplayHardware::getWidth() const           { return mWidth; }
 int DisplayHardware::getHeight() const          { return mHeight; }
 PixelFormat DisplayHardware::getFormat() const  { return mFormat; }
+uint32_t DisplayHardware::getMaxTextureSize() const { return mMaxTextureSize; }
+uint32_t DisplayHardware::getMaxViewportDims() const { return mMaxViewportDims; }
 
 void DisplayHardware::init(uint32_t dpy)
 {
@@ -246,6 +248,11 @@
     LOGI("version   : %s", glGetString(GL_VERSION));
     LOGI("extensions: %s", gl_extensions);
 
+    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
+    glGetIntegerv(GL_MAX_VIEWPORT_DIMS, &mMaxViewportDims);
+    LOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
+    LOGI("GL_MAX_VIEWPORT_DIMS = %d", mMaxViewportDims);
+
 #if 0
     // for drivers that don't have proper support for flushing cached buffers
     // on gralloc unlock, uncomment this block and test for the specific
@@ -273,6 +280,7 @@
 #warning "EGL_ANDROID_image_native_buffer not supported"
 #endif
 
+
     // Unbind the context from this thread
     eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.h b/libs/surfaceflinger/DisplayHardware/DisplayHardware.h
index 6914d0c..df046af 100644
--- a/libs/surfaceflinger/DisplayHardware/DisplayHardware.h
+++ b/libs/surfaceflinger/DisplayHardware/DisplayHardware.h
@@ -76,6 +76,8 @@
     PixelFormat getFormat() const;
     uint32_t    getFlags() const;
     void        makeCurrent() const;
+    uint32_t    getMaxTextureSize() const;
+    uint32_t    getMaxViewportDims() const;
 
     uint32_t getPageFlipCount() const;
     EGLDisplay getEGLDisplay() const { return mDisplay; }
@@ -104,6 +106,8 @@
     PixelFormat     mFormat;
     uint32_t        mFlags;
     mutable uint32_t mPageFlipCount;
+    GLint           mMaxViewportDims;
+    GLint           mMaxTextureSize;
     
     sp<FramebufferNativeWindow> mNativeWindow;
     overlay_control_device_t* mOverlayEngine;
diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp
index 4dc4a15..0a3254d 100644
--- a/libs/surfaceflinger/Layer.cpp
+++ b/libs/surfaceflinger/Layer.cpp
@@ -41,6 +41,10 @@
 
 namespace android {
 
+template <typename T> inline T min(T a, T b) {
+    return a<b ? a : b;
+}
+
 // ---------------------------------------------------------------------------
 
 const uint32_t Layer::typeInfo = LayerBaseClient::typeInfo | 4;
@@ -109,17 +113,26 @@
 
     // the display's pixel format
     const DisplayHardware& hw(graphicPlane(0).displayHardware());
+    uint32_t const maxSurfaceDims = min(
+            hw.getMaxTextureSize(), hw.getMaxViewportDims());
+
+    // never allow a surface larger than what our underlying GL implementation
+    // can handle.
+    if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
+        return BAD_VALUE;
+    }
+
     PixelFormatInfo displayInfo;
     getPixelFormatInfo(hw.getFormat(), &displayInfo);
     const uint32_t hwFlags = hw.getFlags();
     
     mFormat = format;
-    mWidth = w;
+    mWidth  = w;
     mHeight = h;
     mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
     mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
     mNoEGLImageForSwBuffers = !(hwFlags & DisplayHardware::CACHED_BUFFERS);
-    
+
     // we use the red index
     int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
     int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 9ab02f0..a38be48 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -492,27 +492,19 @@
 
         // If stream is muted, set last audible index only
         if (streamState.muteCount() != 0) {
-            streamState.setLastAudibleIndex(index);
-            // Post a persist volume msg
-            sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, streamType,
-                    SENDMSG_REPLACE, 0, 1, streamState, PERSIST_DELAY);
+            // Do not allow last audible index to be 0
+            if (index != 0) {
+                streamState.setLastAudibleIndex(index);
+                // Post a persist volume msg
+                sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, streamType,
+                        SENDMSG_REPLACE, 0, 1, streamState, PERSIST_DELAY);
+            }
         } else {
             if (streamState.setIndex(index, lastAudible) || force) {
                 // Post message to set system volume (it in turn will post a message
                 // to persist).
-                // If we are in silent mode and stream is affected by ringer mode
-                // and the new volume is not 0, just persist the new volume but do not change
-                // current value
-                if (mRingerMode == AudioManager.RINGER_MODE_NORMAL ||
-                    !isStreamAffectedByRingerMode(streamType) ||
-                    index == 0) {
-                    sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, streamType, SENDMSG_NOOP, 0, 0,
-                            streamState, 0);
-                } else {
-                    // Post a persist volume msg
-                    sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, streamType,
-                            SENDMSG_REPLACE, 0, 1, streamState, PERSIST_DELAY);
-                }
+                sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, streamType, SENDMSG_NOOP, 0, 0,
+                        streamState, 0);
             }
         }
     }
@@ -1128,6 +1120,9 @@
             if (direction == AudioManager.ADJUST_RAISE) {
                 // exiting silent mode
                 newRingerMode = AudioManager.RINGER_MODE_NORMAL;
+            } else {
+                // prevent last audible index to reach 0
+                adjustVolumeIndex = false;
             }
         }
 
diff --git a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
index 57f9ce7..79c8f9a 100644
--- a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
+++ b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
@@ -346,16 +346,13 @@
                     PackageHelper.APP_INSTALL_AUTO);
             if (installPreference == PackageHelper.APP_INSTALL_INTERNAL) {
                 checkInt = true;
-                checkBoth = true;
                 break check_inner;
             } else if (installPreference == PackageHelper.APP_INSTALL_EXTERNAL) {
                 checkExt = true;
-                checkBoth = true;
                 break check_inner;
             }
             // Fall back to default policy if nothing else is specified.
             checkInt = true;
-            checkBoth = true;
         }
 
         // Package size = code size + cache size + data size
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 78f7b33..e5b870b 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -179,6 +179,8 @@
     static final int SCAN_NEW_INSTALL = 1<<4;
     static final int SCAN_NO_PATHS = 1<<5;
 
+    static final int REMOVE_CHATTY = 1<<16;
+    
     static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName(
             "com.android.defcontainer",
             "com.android.defcontainer.DefaultContainerService");
@@ -6068,7 +6070,8 @@
         }
         
         synchronized (mInstallLock) {
-            res = deletePackageLI(packageName, deleteCodeAndResources, flags, info);
+            res = deletePackageLI(packageName, deleteCodeAndResources,
+                    flags | REMOVE_CHATTY, info);
         }
 
         if(res && sendBroadCast) {
@@ -6134,7 +6137,7 @@
         if (outInfo != null) {
             outInfo.removedPackage = packageName;
         }
-        removePackageLI(p, true);
+        removePackageLI(p, (flags&REMOVE_CHATTY) != 0);
         // Retrieve object to delete permissions for shared user later on
         PackageSetting deletedPs;
         synchronized (mPackages) {
@@ -9589,8 +9592,7 @@
                    continue;
                }
                // Parse package
-               int parseFlags = PackageParser.PARSE_CHATTY |
-                       PackageParser.PARSE_ON_SDCARD | mDefParseFlags;
+               int parseFlags = PackageParser.PARSE_ON_SDCARD | mDefParseFlags;
                doGc = true;
                synchronized (mInstallLock) {
                    final PackageParser.Package pkg =  scanPackageLI(new File(codePath),
@@ -9756,7 +9758,7 @@
                }
            }
            if (returnCode != PackageManager.MOVE_SUCCEEDED) {
-               processPendingMove(new MoveParams(null, observer, 0, null), returnCode);
+               processPendingMove(new MoveParams(null, observer, 0, packageName), returnCode);
            } else {
                Message msg = mHandler.obtainMessage(INIT_COPY);
                InstallArgs srcArgs = createInstallArgs(currFlags, pkg.applicationInfo.sourceDir,
@@ -9847,9 +9849,9 @@
                                    }
                                }
                            }
-                           // Send resources available broadcast
-                           sendResourcesChangedBroadcast(true, pkgList, uidArr, null);
                        }
+                       // Send resources available broadcast
+                       sendResourcesChangedBroadcast(true, pkgList, uidArr, null);
                    }
                }
                if (returnCode != PackageManager.MOVE_SUCCEEDED){
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index b6f323d..13690bc 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -4078,10 +4078,19 @@
                 System.identityHashCode(r),
                 r.task.taskId, r.shortComponentName, reason);
         r.task.numActivities--;
-        if (r.frontOfTask && index < (mHistory.size()-1)) {
+        if (index < (mHistory.size()-1)) {
             HistoryRecord next = (HistoryRecord)mHistory.get(index+1);
             if (next.task == r.task) {
-                next.frontOfTask = true;
+                if (r.frontOfTask) {
+                    // The next activity is now the front of the task.
+                    next.frontOfTask = true;
+                }
+                if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
+                    // If the caller asked that this activity (and all above it)
+                    // be cleared when the task is reset, don't lose that information,
+                    // but propagate it up to the next activity.
+                    next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+                }
             }
         }
 
@@ -9905,7 +9914,7 @@
             }
             if (mOrderedBroadcasts.size() > 0) {
                 pw.println(" ");
-                pw.println("  Active serialized broadcasts:");
+                pw.println("  Active ordered broadcasts:");
             }
             for (int i=mOrderedBroadcasts.size()-1; i>=0; i--) {
                 pw.println("  Serialized Broadcast #" + i + ":");
@@ -12919,7 +12928,7 @@
             try {
                 if (DEBUG_BROADCAST_LIGHT) {
                     int seq = r.intent.getIntExtra("seq", -1);
-                    Slog.i(TAG, "Delivering to " + filter.receiverList.app
+                    Slog.i(TAG, "Delivering to " + filter
                             + " (seq=" + seq + "): " + r);
                 }
                 performReceive(filter.receiverList.app, filter.receiverList.receiver,
@@ -12959,7 +12968,7 @@
 
             if (DEBUG_BROADCAST) Slog.v(TAG, "processNextBroadcast: "
                     + mParallelBroadcasts.size() + " broadcasts, "
-                    + mOrderedBroadcasts.size() + " serialized broadcasts");
+                    + mOrderedBroadcasts.size() + " ordered broadcasts");
 
             updateCpuStats();
             
@@ -12977,7 +12986,7 @@
                 for (int i=0; i<N; i++) {
                     Object target = r.receivers.get(i);
                     if (DEBUG_BROADCAST)  Slog.v(TAG,
-                            "Delivering non-serialized to registered "
+                            "Delivering non-ordered to registered "
                             + target + ": " + r);
                     deliverToRegisteredReceiver(r, (BroadcastFilter)target, false);
                 }
@@ -13115,12 +13124,14 @@
                 // a direct call.
                 BroadcastFilter filter = (BroadcastFilter)nextReceiver;
                 if (DEBUG_BROADCAST)  Slog.v(TAG,
-                        "Delivering serialized to registered "
+                        "Delivering ordered to registered "
                         + filter + ": " + r);
                 deliverToRegisteredReceiver(r, filter, r.ordered);
                 if (r.receiver == null || !r.ordered) {
                     // The receiver has already finished, so schedule to
                     // process the next one.
+                    if (DEBUG_BROADCAST) Slog.v(TAG, "Quick finishing: ordered="
+                            + r.ordered + " receiver=" + r.receiver);
                     r.state = BroadcastRecord.IDLE;
                     scheduleBroadcastsLocked();
                 }
diff --git a/services/java/com/android/server/am/BroadcastRecord.java b/services/java/com/android/server/am/BroadcastRecord.java
index 75c9600..c3f0b3e 100644
--- a/services/java/com/android/server/am/BroadcastRecord.java
+++ b/services/java/com/android/server/am/BroadcastRecord.java
@@ -126,7 +126,9 @@
             pw.println(prefix + "curApp=" + curApp);
             pw.println(prefix + "curComponent="
                     + (curComponent != null ? curComponent.toShortString() : "--"));
-            pw.println(prefix + "curSourceDir=" + curReceiver.applicationInfo.sourceDir);
+            if (curReceiver != null && curReceiver.applicationInfo != null) {
+                pw.println(prefix + "curSourceDir=" + curReceiver.applicationInfo.sourceDir);
+            }
         }
         String stateStr = " (?)";
         switch (state) {