Merge change I91eb0354 into eclair-mr2

* changes:
  Change OMXCodec::Create to return an sp<MediaSource> instead of an sp<OMXCodec>, this is more general and does not sacrifice any functionality as the remaining OMXCodec APIs are not meant to be public anyway.
diff --git a/api/7.xml b/api/7.xml
index f6ccc93..83d2bc7 100644
--- a/api/7.xml
+++ b/api/7.xml
@@ -199633,6 +199633,292 @@
  visibility="public"
 >
 </field>
+<field name="OP_UNUSED_3e"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="62"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_3f"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="63"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_40"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="64"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_41"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="65"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_42"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="66"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_43"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="67"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_73"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="115"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_79"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="121"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_7A"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="122"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_E3"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="227"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_E4"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="228"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_E5"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="229"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_E6"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="230"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_E7"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="231"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_E8"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="232"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_E9"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="233"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_EA"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="234"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_EB"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="235"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_EC"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="236"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_ED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="237"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_EF"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="239"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_F1"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="241"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_FC"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="252"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_FD"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="253"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_FE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="254"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OP_UNUSED_FF"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="255"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="OP_USHR_INT"
  type="int"
  transient="false"
diff --git a/core/java/android/app/ISearchManager.aidl b/core/java/android/app/ISearchManager.aidl
index a7d63789..0920467 100644
--- a/core/java/android/app/ISearchManager.aidl
+++ b/core/java/android/app/ISearchManager.aidl
@@ -16,11 +16,11 @@
 
 package android.app;
 
+import android.app.SearchableInfo;
 import android.app.ISearchManagerCallback;
 import android.content.ComponentName;
 import android.content.res.Configuration;
 import android.os.Bundle;
-import android.server.search.SearchableInfo;
 
 /** @hide */
 interface ISearchManager {
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index 0757cb0..b204c79 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -37,7 +37,6 @@
 import android.os.RemoteException;
 import android.os.SystemClock;
 import android.provider.Browser;
-import android.server.search.SearchableInfo;
 import android.speech.RecognizerIntent;
 import android.text.Editable;
 import android.text.InputType;
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index 2e94a2f..ab5e102 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -26,7 +26,6 @@
 import android.os.Handler;
 import android.os.RemoteException;
 import android.os.ServiceManager;
-import android.server.search.SearchableInfo;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.KeyEvent;
diff --git a/core/java/android/server/search/SearchableInfo.aidl b/core/java/android/app/SearchableInfo.aidl
similarity index 95%
rename from core/java/android/server/search/SearchableInfo.aidl
rename to core/java/android/app/SearchableInfo.aidl
index 9576c2b..146b373 100644
--- a/core/java/android/server/search/SearchableInfo.aidl
+++ b/core/java/android/app/SearchableInfo.aidl
@@ -14,6 +14,6 @@
  * limitations under the License.
  */
 
-package android.server.search;
+package android.app;
 
 parcelable SearchableInfo;
diff --git a/core/java/android/server/search/SearchableInfo.java b/core/java/android/app/SearchableInfo.java
similarity index 99%
rename from core/java/android/server/search/SearchableInfo.java
rename to core/java/android/app/SearchableInfo.java
index 69ef98c..cbf7b3d 100644
--- a/core/java/android/server/search/SearchableInfo.java
+++ b/core/java/android/app/SearchableInfo.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.server.search;
+package android.app;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -37,6 +37,10 @@
 import java.io.IOException;
 import java.util.HashMap;
 
+/**
+ * 
+ * @hide Pending API council approval
+ */
 public final class SearchableInfo implements Parcelable {
 
     // general debugging support
diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java
index 12be97c..173c3e1 100644
--- a/core/java/android/app/SuggestionsAdapter.java
+++ b/core/java/android/app/SuggestionsAdapter.java
@@ -31,7 +31,6 @@
 import android.graphics.drawable.StateListDrawable;
 import android.net.Uri;
 import android.os.Bundle;
-import android.server.search.SearchableInfo;
 import android.text.Html;
 import android.text.TextUtils;
 import android.util.Log;
diff --git a/core/java/android/server/search/SearchManagerService.java b/core/java/android/server/search/SearchManagerService.java
index 78ea2e3..6e8b7ee 100644
--- a/core/java/android/server/search/SearchManagerService.java
+++ b/core/java/android/server/search/SearchManagerService.java
@@ -21,6 +21,7 @@
 import android.app.ISearchManager;
 import android.app.ISearchManagerCallback;
 import android.app.SearchManager;
+import android.app.SearchableInfo;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
diff --git a/core/java/android/server/search/Searchables.java b/core/java/android/server/search/Searchables.java
index c615957..cbb63a5 100644
--- a/core/java/android/server/search/Searchables.java
+++ b/core/java/android/server/search/Searchables.java
@@ -19,6 +19,7 @@
 import com.android.internal.app.ResolverActivity;
 
 import android.app.SearchManager;
+import android.app.SearchableInfo;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
diff --git a/core/java/android/text/method/ArrowKeyMovementMethod.java b/core/java/android/text/method/ArrowKeyMovementMethod.java
index ab33cb3..789172f 100644
--- a/core/java/android/text/method/ArrowKeyMovementMethod.java
+++ b/core/java/android/text/method/ArrowKeyMovementMethod.java
@@ -54,7 +54,7 @@
                 Selection.setSelection(buffer, 0);
                 return true;
             } else {
-                return Selection.moveUp(buffer, layout); 
+                return Selection.moveUp(buffer, layout);
             }
         }
     }
@@ -80,7 +80,7 @@
                 Selection.setSelection(buffer, buffer.length());
                 return true;
             } else {
-                return Selection.moveDown(buffer, layout); 
+                return Selection.moveDown(buffer, layout);
             }
         }
     }
@@ -133,6 +133,35 @@
         }
     }
 
+    private int getOffset(int x, int y, TextView widget){
+      // Converts the absolute X,Y coordinates to the character offset for the
+      // character whose position is closest to the specified
+      // horizontal position.
+      x -= widget.getTotalPaddingLeft();
+      y -= widget.getTotalPaddingTop();
+
+      // Clamp the position to inside of the view.
+      if (x < 0) {
+          x = 0;
+      } else if (x >= (widget.getWidth()-widget.getTotalPaddingRight())) {
+          x = widget.getWidth()-widget.getTotalPaddingRight() - 1;
+      }
+      if (y < 0) {
+          y = 0;
+      } else if (y >= (widget.getHeight()-widget.getTotalPaddingBottom())) {
+          y = widget.getHeight()-widget.getTotalPaddingBottom() - 1;
+      }
+
+      x += widget.getScrollX();
+      y += widget.getScrollY();
+
+      Layout layout = widget.getLayout();
+      int line = layout.getLineForVertical(y);
+
+      int offset = layout.getOffsetForHorizontal(line, x);
+      return offset;
+    }
+
     public boolean onKeyDown(TextView widget, Spannable buffer, int keyCode, KeyEvent event) {
         if (executeDown(widget, buffer, keyCode)) {
             MetaKeyKeyListener.adjustMetaAfterKeypress(buffer);
@@ -196,12 +225,12 @@
         }
         return false;
     }
-    
+
     public boolean onTrackballEvent(TextView widget, Spannable text,
             MotionEvent event) {
         return false;
     }
-    
+
     public boolean onTouchEvent(TextView widget, Spannable buffer,
                                 MotionEvent event) {
         int initialScrollX = -1, initialScrollY = -1;
@@ -209,11 +238,63 @@
             initialScrollX = Touch.getInitialScrollX(widget, buffer);
             initialScrollY = Touch.getInitialScrollY(widget, buffer);
         }
-        
+
         boolean handled = Touch.onTouchEvent(widget, buffer, event);
 
         if (widget.isFocused() && !widget.didTouchFocusSelect()) {
-            if (event.getAction() == MotionEvent.ACTION_UP) {
+            if (event.getAction() == MotionEvent.ACTION_DOWN) {
+              boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
+                              KeyEvent.META_SHIFT_ON) == 1) ||
+                            (MetaKeyKeyListener.getMetaState(buffer,
+                              MetaKeyKeyListener.META_SELECTING) != 0);
+              if (cap) {
+                  int x = (int) event.getX();
+                  int y = (int) event.getY();
+                  int offset = getOffset(x, y, widget);
+
+                  buffer.setSpan(LAST_TAP_DOWN, offset, offset,
+                                 Spannable.SPAN_POINT_POINT);
+              }
+            } else if (event.getAction() == MotionEvent.ACTION_MOVE ) {
+              boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
+                              KeyEvent.META_SHIFT_ON) == 1) ||
+                            (MetaKeyKeyListener.getMetaState(buffer,
+                              MetaKeyKeyListener.META_SELECTING) != 0);
+
+              if (cap) {
+                // Update selection as we're moving the selection area.
+
+                // Get the current touch position
+                int x = (int) event.getX();
+                int y = (int) event.getY();
+                int offset = getOffset(x, y, widget);
+
+                // Get the last down touch position (the position at which the
+                // user started the selection)
+                int lastDownOffset = buffer.getSpanStart(LAST_TAP_DOWN);
+
+                // Compute the selection boundries
+                int spanstart;
+                int spanend;
+                if (offset >= lastDownOffset) {
+                  // expand to from word start of the original tap to new word
+                  // end, since we are selecting "forwards"
+                  spanstart = findWordStart(buffer, lastDownOffset);
+                  spanend = findWordEnd(buffer, offset);
+                } else {
+                  // Expand to from new word start to word end of the original
+                  // tap since we are selecting "backwards".
+                  // The spanend will always need to be associated with the touch
+                  // up position, so that refining the selection with the
+                  // trackball will work as expected.
+                  spanstart = findWordEnd(buffer, lastDownOffset);
+                  spanend = findWordStart(buffer, offset);
+                }
+
+                Selection.setSelection(buffer, spanstart, spanend);
+                return true;
+              }
+            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                 // If we have scrolled, then the up shouldn't move the cursor,
                 // but we do need to make sure the cursor is still visible at
                 // the current scroll offset to avoid the scroll jumping later
@@ -223,35 +304,13 @@
                     widget.moveCursorToVisibleOffset();
                     return true;
                 }
-                
+
                 int x = (int) event.getX();
                 int y = (int) event.getY();
-
-                x -= widget.getTotalPaddingLeft();
-                y -= widget.getTotalPaddingTop();
-
-                // Clamp the position to inside of the view.
-                if (x < 0) {
-                    x = 0;
-                } else if (x >= (widget.getWidth()-widget.getTotalPaddingRight())) {
-                    x = widget.getWidth()-widget.getTotalPaddingRight() - 1;
-                }
-                if (y < 0) {
-                    y = 0;
-                } else if (y >= (widget.getHeight()-widget.getTotalPaddingBottom())) {
-                    y = widget.getHeight()-widget.getTotalPaddingBottom() - 1;
-                }
-                
-                x += widget.getScrollX();
-                y += widget.getScrollY();
-
-                Layout layout = widget.getLayout();
-                int line = layout.getLineForVertical(y);
-                
-                int off = layout.getOffsetForHorizontal(line, x);
+                int off = getOffset(x, y, widget);
 
                 // XXX should do the same adjust for x as we do for the line.
-                
+
                 boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                                 KeyEvent.META_SHIFT_ON) == 1) ||
                               (MetaKeyKeyListener.getMetaState(buffer,
@@ -278,7 +337,7 @@
                 }
 
                 if (cap) {
-                    Selection.extendSelection(buffer, off);
+                    buffer.removeSpan(LAST_TAP_DOWN);
                 } else if (doubletap) {
                     Selection.setSelection(buffer,
                                            findWordStart(buffer, off),
@@ -395,5 +454,7 @@
         return sInstance;
     }
 
+
+    private static final Object LAST_TAP_DOWN = new Object();
     private static ArrowKeyMovementMethod sInstance;
 }
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index f04b04f..99b3f21 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -338,6 +338,7 @@
             super.onEditorAction(actionCode);
             break;
         case EditorInfo.IME_ACTION_GO:
+        case EditorInfo.IME_ACTION_SEARCH:
             // Send an enter and hide the soft keyboard
             InputMethodManager.getInstance(mContext)
                     .hideSoftInputFromWindow(getWindowToken(), 0);
@@ -827,6 +828,9 @@
             case 2: // DONE
                 setImeOptions(EditorInfo.IME_ACTION_DONE);
                 break;
+            case 3: // SEARCH
+                setImeOptions(EditorInfo.IME_ACTION_SEARCH);
+                break;
             }
         } else {
             inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index e353501..92ff315 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -2109,6 +2109,9 @@
                             }
                             reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
                             mFlingRunnable.start(-initialVelocity);
+                        } else {
+                            mTouchMode = TOUCH_MODE_REST;
+                            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                         }
                     }
                 } else {
diff --git a/core/java/android/widget/ExpandableListView.java b/core/java/android/widget/ExpandableListView.java
index 6abb2ae4..405461a 100644
--- a/core/java/android/widget/ExpandableListView.java
+++ b/core/java/android/widget/ExpandableListView.java
@@ -33,7 +33,6 @@
 import android.view.SoundEffectConstants;
 import android.view.View;
 import android.view.ContextMenu.ContextMenuInfo;
-import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.ExpandableListConnector.PositionMetadata;
 
 /**
@@ -514,37 +513,36 @@
         boolean returnValue;
         if (posMetadata.position.type == ExpandableListPosition.GROUP) {
             /* It's a group, so handle collapsing/expanding */
-            
+
+            /* It's a group click, so pass on event */
+            if (mOnGroupClickListener != null) {
+                if (mOnGroupClickListener.onGroupClick(this, v,
+                        posMetadata.position.groupPos, id)) {
+                    posMetadata.recycle();
+                    return true;
+                }
+            }
+
             if (posMetadata.isExpanded()) {
                 /* Collapse it */
                 mConnector.collapseGroup(posMetadata);
 
                 playSoundEffect(SoundEffectConstants.CLICK);
-                
+
                 if (mOnGroupCollapseListener != null) {
                     mOnGroupCollapseListener.onGroupCollapse(posMetadata.position.groupPos);
                 }
-                
             } else {
-                /* It's a group click, so pass on event */
-                if (mOnGroupClickListener != null) {
-                    if (mOnGroupClickListener.onGroupClick(this, v,
-                            posMetadata.position.groupPos, id)) {
-                        posMetadata.recycle();
-                        return true;
-                    }
-                }
-
                 /* Expand it */
                 mConnector.expandGroup(posMetadata);
 
                 playSoundEffect(SoundEffectConstants.CLICK);
-                
+
                 if (mOnGroupExpandListener != null) {
                     mOnGroupExpandListener.onGroupExpand(posMetadata.position.groupPos);
                 }
             }
-            
+
             returnValue = true;
         } else {
             /* It's a child, so pass on event */
@@ -553,12 +551,12 @@
                 return mOnChildClickListener.onChildClick(this, v, posMetadata.position.groupPos,
                         posMetadata.position.childPos, id);
             }
-            
+
             returnValue = false;
         }
-        
+
         posMetadata.recycle();
-        
+
         return returnValue;
     }
 
diff --git a/libs/surfaceflinger/Android.mk b/libs/surfaceflinger/Android.mk
index eb51c22..b3fed58 100644
--- a/libs/surfaceflinger/Android.mk
+++ b/libs/surfaceflinger/Android.mk
@@ -22,9 +22,6 @@
 ifeq ($(TARGET_BOARD_PLATFORM), msm7k)
 	LOCAL_CFLAGS += -DDIM_WITH_TEXTURE
 endif
-ifeq ($(TARGET_BOARD_PLATFORM), qsd8k)
-	LOCAL_CFLAGS += -DDIM_WITH_TEXTURE
-endif
 
 # need "-lrt" on Linux simulator to pick up clock_gettime
 ifeq ($(TARGET_SIMULATOR),true)
diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java
index 8954ec6..1e3bd72 100644
--- a/opengl/java/android/opengl/GLSurfaceView.java
+++ b/opengl/java/android/opengl/GLSurfaceView.java
@@ -847,7 +847,7 @@
             */
             mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
             if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
-                throw new RuntimeException("createContext failed");
+                throwEglException("createContext");
             }
 
             mEglSurface = null;
diff --git a/opengl/java/com/google/android/gles_jni/EGLImpl.java b/opengl/java/com/google/android/gles_jni/EGLImpl.java
index a667e8d..3e06ded 100644
--- a/opengl/java/com/google/android/gles_jni/EGLImpl.java
+++ b/opengl/java/com/google/android/gles_jni/EGLImpl.java
@@ -2,16 +2,16 @@
 **
 ** Copyright 2006, 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 
+** 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 
+**     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 
+** 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.
 */
 
@@ -30,11 +30,11 @@
     private EGLSurfaceImpl mSurface = new EGLSurfaceImpl(-1);
 
     public native boolean     eglInitialize(EGLDisplay display, int[] major_minor);
-    public native boolean     eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value);    
+    public native boolean     eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value);
     public native boolean     eglQuerySurface(EGLDisplay display, EGLSurface surface, int attribute, int[] value);
     public native boolean     eglChooseConfig(EGLDisplay display, int[] attrib_list, EGLConfig[] configs, int config_size, int[] num_config);
     public native boolean     eglGetConfigAttrib(EGLDisplay display, EGLConfig config, int attribute, int[] value);
-    public native boolean     eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config);    
+    public native boolean     eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config);
     public native int         eglGetError();
     public native boolean     eglDestroyContext(EGLDisplay display, EGLContext context);
     public native boolean     eglDestroySurface(EGLDisplay display, EGLSurface surface);
@@ -47,16 +47,27 @@
     public native boolean     eglWaitNative(int engine, Object bindTarget);
 
     public EGLContext eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list) {
-        return new EGLContextImpl( _eglCreateContext(display, config, share_context, attrib_list) );
+        int eglContextId = _eglCreateContext(display, config, share_context, attrib_list);
+        if (eglContextId == 0) {
+            return EGL10.EGL_NO_CONTEXT;
+        }
+        return new EGLContextImpl( eglContextId );
     }
 
     public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) {
-        return new EGLSurfaceImpl( _eglCreatePbufferSurface(display, config, attrib_list) );
+        int eglSurfaceId = _eglCreatePbufferSurface(display, config, attrib_list);
+        if (eglSurfaceId == 0) {
+            return EGL10.EGL_NO_SURFACE;
+        }
+        return new EGLSurfaceImpl( eglSurfaceId );
     }
-    
+
     public EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list) {
         EGLSurfaceImpl sur = new EGLSurfaceImpl();
         _eglCreatePixmapSurface(sur, display, config, native_pixmap, attrib_list);
+        if (sur.mEGLSurface == 0) {
+            return EGL10.EGL_NO_SURFACE;
+        }
         return sur;
     }
 
@@ -73,11 +84,18 @@
                 "eglCreateWindowSurface() can only be called with an instance of " +
                 "SurfaceView or SurfaceHolder at the moment, this will be fixed later.");
         }
-        return new EGLSurfaceImpl( _eglCreateWindowSurface(display, config, sur, attrib_list) );
+        int eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list);
+        if (eglSurfaceId == 0) {
+            return EGL10.EGL_NO_SURFACE;
+        }
+        return new EGLSurfaceImpl( eglSurfaceId );
     }
-    
+
     public synchronized EGLDisplay eglGetDisplay(Object native_display) {
         int value = _eglGetDisplay(native_display);
+        if (value == 0) {
+            return EGL10.EGL_NO_DISPLAY;
+        }
         if (mDisplay.mEGLDisplay != value)
             mDisplay = new EGLDisplayImpl(value);
         return mDisplay;
@@ -85,13 +103,19 @@
 
     public synchronized EGLContext eglGetCurrentContext() {
         int value = _eglGetCurrentContext();
+        if (value == 0) {
+            return EGL10.EGL_NO_CONTEXT;
+        }
         if (mContext.mEGLContext != value)
             mContext = new EGLContextImpl(value);
         return mContext;
     }
-    
+
     public synchronized EGLDisplay eglGetCurrentDisplay() {
         int value = _eglGetCurrentDisplay();
+        if (value == 0) {
+            return EGL10.EGL_NO_DISPLAY;
+        }
         if (mDisplay.mEGLDisplay != value)
             mDisplay = new EGLDisplayImpl(value);
         return mDisplay;
@@ -99,6 +123,9 @@
 
     public synchronized EGLSurface eglGetCurrentSurface(int readdraw) {
         int value = _eglGetCurrentSurface(readdraw);
+        if (value == 0) {
+            return EGL10.EGL_NO_SURFACE;
+        }
         if (mSurface.mEGLSurface != value)
             mSurface = new EGLSurfaceImpl(value);
         return mSurface;
@@ -107,7 +134,7 @@
     private native int _eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list);
     private native int _eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list);
     private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list);
-    private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list);    
+    private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list);
     private native int _eglGetDisplay(Object native_display);
     private native int _eglGetCurrentContext();
     private native int _eglGetCurrentDisplay();
diff --git a/preloaded-classes b/preloaded-classes
index 73bab87..af74b33 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -81,6 +81,7 @@
 android.app.ResultInfo
 android.app.SearchManager$OnCancelListener
 android.app.SearchManager$SearchManagerCallback
+android.app.SearchableInfo
 android.app.Service
 android.app.TabActivity
 android.app.TimePickerDialog
@@ -649,7 +650,6 @@
 android.server.BluetoothEventLoop
 android.server.BluetoothService
 android.server.data.CrashData
-android.server.search.SearchableInfo
 android.speech.IRecognitionListener$Stub
 android.speech.IRecognitionService$Stub
 android.speech.RecognitionResult
diff --git a/services/java/Android.mk b/services/java/Android.mk
index 5c54e33..934712c 100644
--- a/services/java/Android.mk
+++ b/services/java/Android.mk
@@ -6,7 +6,8 @@
 
 LOCAL_SRC_FILES := \
             $(call all-subdir-java-files) \
-	    com/android/server/EventLogTags.logtags
+	    com/android/server/EventLogTags.logtags \
+	    com/android/server/am/EventLogTags.logtags
 
 LOCAL_MODULE:= services
 
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 3612a9b..65070dd 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -152,44 +152,6 @@
     static final long MONITOR_CPU_MAX_TIME = 0x0fffffff;    // wait possibly forever for next cpu sample.
     static final boolean MONITOR_THREAD_CPU_USAGE = false;
 
-    // Event log tags
-    static final int LOG_CONFIGURATION_CHANGED = 2719;
-    static final int LOG_CPU = 2721;
-    static final int LOG_AM_FINISH_ACTIVITY = 30001;
-    static final int LOG_TASK_TO_FRONT = 30002;
-    static final int LOG_AM_NEW_INTENT = 30003;
-    static final int LOG_AM_CREATE_TASK = 30004;
-    static final int LOG_AM_CREATE_ACTIVITY = 30005;
-    static final int LOG_AM_RESTART_ACTIVITY = 30006;
-    static final int LOG_AM_RESUME_ACTIVITY = 30007;
-    static final int LOG_ANR = 30008;
-    static final int LOG_ACTIVITY_LAUNCH_TIME = 30009;
-    static final int LOG_AM_PROCESS_BOUND = 30010;
-    static final int LOG_AM_PROCESS_DIED = 30011;
-    static final int LOG_AM_FAILED_TO_PAUSE_ACTIVITY = 30012;
-    static final int LOG_AM_PAUSE_ACTIVITY = 30013;
-    static final int LOG_AM_PROCESS_START = 30014;
-    static final int LOG_AM_PROCESS_BAD = 30015;
-    static final int LOG_AM_PROCESS_GOOD = 30016;
-    static final int LOG_AM_LOW_MEMORY = 30017;
-    static final int LOG_AM_DESTROY_ACTIVITY = 30018;
-    static final int LOG_AM_RELAUNCH_RESUME_ACTIVITY = 30019;
-    static final int LOG_AM_RELAUNCH_ACTIVITY = 30020;
-    static final int LOG_AM_KILL_FOR_MEMORY = 30023;
-    static final int LOG_AM_BROADCAST_DISCARD_FILTER = 30024;
-    static final int LOG_AM_BROADCAST_DISCARD_APP = 30025;
-    static final int LOG_AM_CREATE_SERVICE = 30030;
-    static final int LOG_AM_DESTROY_SERVICE = 30031;
-    static final int LOG_AM_PROCESS_CRASHED_TOO_MUCH = 30032;
-    static final int LOG_AM_DROP_PROCESS = 30033;
-    static final int LOG_AM_SERVICE_CRASHED_TOO_MUCH = 30034;
-    static final int LOG_AM_SCHEDULE_SERVICE_RESTART = 30035;
-    static final int LOG_AM_PROVIDER_LOST_PROCESS = 30036;
-    static final int LOG_AM_PROCESS_START_TIMEOUT = 30037;
-    
-    static final int LOG_BOOT_PROGRESS_AMS_READY = 3040;
-    static final int LOG_BOOT_PROGRESS_ENABLE_SCREEN = 3050;
-
     // The flags that are set for all calls we make to the package manager.
     static final int STOCK_PM_FLAGS = PackageManager.GET_SHARED_LIBRARY_FILES;
     
@@ -1582,7 +1544,7 @@
                     int total = user + system + iowait + irq + softIrq + idle;
                     if (total == 0) total = 1;
 
-                    EventLog.writeEvent(LOG_CPU,
+                    EventLog.writeEvent(EventLogTags.CPU,
                             ((user+system+iowait+irq+softIrq) * 100) / total,
                             (user * 100) / total,
                             (system * 100) / total,
@@ -1793,7 +1755,7 @@
                     + " with results=" + results + " newIntents=" + newIntents
                     + " andResume=" + andResume);
             if (andResume) {
-                EventLog.writeEvent(LOG_AM_RESTART_ACTIVITY,
+                EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY,
                         System.identityHashCode(r),
                         r.task.taskId, r.shortComponentName);
             }
@@ -1926,7 +1888,7 @@
             // if it had been bad.
             mProcessCrashTimes.remove(info.processName, info.uid);
             if (mBadProcesses.get(info.processName, info.uid) != null) {
-                EventLog.writeEvent(LOG_AM_PROCESS_GOOD, info.uid,
+                EventLog.writeEvent(EventLogTags.AM_PROC_GOOD, info.uid,
                         info.processName);
                 mBadProcesses.remove(info.processName, info.uid);
                 if (app != null) {
@@ -2019,7 +1981,7 @@
                 }
             }
             
-            EventLog.writeEvent(LOG_AM_PROCESS_START, pid, uid,
+            EventLog.writeEvent(EventLogTags.AM_PROC_START, pid, uid,
                     app.processName, hostingType,
                     hostingNameStr != null ? hostingNameStr : "");
             
@@ -2104,7 +2066,7 @@
         if (prev.app != null && prev.app.thread != null) {
             if (DEBUG_PAUSE) Log.v(TAG, "Enqueueing pending pause: " + prev);
             try {
-                EventLog.writeEvent(LOG_AM_PAUSE_ACTIVITY,
+                EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY,
                         System.identityHashCode(prev),
                         prev.shortComponentName);
                 prev.app.thread.schedulePauseActivity(prev, prev.finishing, userLeaving,
@@ -2775,7 +2737,7 @@
                     next.app.thread.scheduleNewIntent(next.newIntents, next);
                 }
 
-                EventLog.writeEvent(LOG_AM_RESUME_ACTIVITY,
+                EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY,
                         System.identityHashCode(next),
                         next.task.taskId, next.shortComponentName);
                 
@@ -3436,7 +3398,7 @@
                                 // intent.
                                 top.task.setIntent(r.intent, r.info);
                             }
-                            logStartActivity(LOG_AM_NEW_INTENT, r, top.task);
+                            logStartActivity(EventLogTags.AM_NEW_INTENT, r, top.task);
                             deliverNewIntentLocked(top, r.intent);
                         } else {
                             // A special case: we need to
@@ -3458,7 +3420,7 @@
                         // desires.
                         if ((launchFlags&Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0
                                 && taskTop.realActivity.equals(r.realActivity)) {
-                            logStartActivity(LOG_AM_NEW_INTENT, r, taskTop.task);
+                            logStartActivity(EventLogTags.AM_NEW_INTENT, r, taskTop.task);
                             if (taskTop.frontOfTask) {
                                 taskTop.task.setIntent(r.intent, r.info);
                             }
@@ -3518,7 +3480,7 @@
                         if ((launchFlags&Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0
                             || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP
                             || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
-                            logStartActivity(LOG_AM_NEW_INTENT, top, top.task);
+                            logStartActivity(EventLogTags.AM_NEW_INTENT, top, top.task);
                             // For paranoia, make sure we have correctly
                             // resumed the top activity.
                             if (doResume) {
@@ -3572,7 +3534,7 @@
                 HistoryRecord top = performClearTaskLocked(
                         sourceRecord.task.taskId, r, launchFlags, true);
                 if (top != null) {
-                    logStartActivity(LOG_AM_NEW_INTENT, r, top.task);
+                    logStartActivity(EventLogTags.AM_NEW_INTENT, r, top.task);
                     deliverNewIntentLocked(top, r.intent);
                     // For paranoia, make sure we have correctly
                     // resumed the top activity.
@@ -3589,7 +3551,7 @@
                 int where = findActivityInHistoryLocked(r, sourceRecord.task.taskId);
                 if (where >= 0) {
                     HistoryRecord top = moveActivityToFrontLocked(where);
-                    logStartActivity(LOG_AM_NEW_INTENT, r, top.task);
+                    logStartActivity(EventLogTags.AM_NEW_INTENT, r, top.task);
                     deliverNewIntentLocked(top, r.intent);
                     if (doResume) {
                         resumeTopActivityLocked(null);
@@ -3619,9 +3581,9 @@
                     + " in new guessed " + r.task);
         }
         if (newTask) {
-            EventLog.writeEvent(LOG_AM_CREATE_TASK, r.task.taskId);
+            EventLog.writeEvent(EventLogTags.AM_CREATE_TASK, r.task.taskId);
         }
-        logStartActivity(LOG_AM_CREATE_ACTIVITY, r, r.task);
+        logStartActivity(EventLogTags.AM_CREATE_ACTIVITY, r, r.task);
         startActivityLocked(r, newTask, doResume);
         return START_SUCCESS;
     }
@@ -3994,7 +3956,7 @@
         }
 
         r.finishing = true;
-        EventLog.writeEvent(LOG_AM_FINISH_ACTIVITY,
+        EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY,
                 System.identityHashCode(r),
                 r.task.taskId, r.shortComponentName, reason);
         r.task.numActivities--;
@@ -4339,7 +4301,7 @@
         if (DEBUG_SWITCH) Log.v(
             TAG, "Removing activity: token=" + r
               + ", app=" + (r.app != null ? r.app.processName : "(null)"));
-        EventLog.writeEvent(LOG_AM_DESTROY_ACTIVITY,
+        EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY,
                 System.identityHashCode(r),
                 r.task.taskId, r.shortComponentName);
 
@@ -4556,7 +4518,7 @@
         if (app.thread != null && app.thread.asBinder() == thread.asBinder()) {
             Log.i(TAG, "Process " + app.processName + " (pid " + pid
                     + ") has died.");
-            EventLog.writeEvent(LOG_AM_PROCESS_DIED, app.pid, app.processName);
+            EventLog.writeEvent(EventLogTags.AM_PROC_DIED, app.pid, app.processName);
             if (localLOGV) Log.v(
                 TAG, "Dying app: " + app + ", pid: " + pid
                 + ", thread: " + thread.asBinder());
@@ -4580,7 +4542,7 @@
                 
                 if (!haveBg) {
                     Log.i(TAG, "Low Memory: No more background processes.");
-                    EventLog.writeEvent(LOG_AM_LOW_MEMORY, mLRUProcesses.size());
+                    EventLog.writeEvent(EventLogTags.AM_LOW_MEMORY, mLRUProcesses.size());
                     long now = SystemClock.uptimeMillis();
                     for (i=0; i<count; i++) {
                         ProcessRecord rec = mLRUProcesses.get(i);
@@ -4628,7 +4590,7 @@
         }
         
         // Log the ANR to the event log.
-        EventLog.writeEvent(LOG_ANR, app.pid, app.processName, annotation);
+        EventLog.writeEvent(EventLogTags.ANR, app.pid, app.processName, annotation);
         
         // If we are on a secure build and the application is not interesting to the user (it is
         // not visible or in the background), just kill it instead of displaying a dialog.
@@ -5200,7 +5162,7 @@
         
         if (gone) {
             Log.w(TAG, "Process " + app + " failed to attach");
-            EventLog.writeEvent(LOG_AM_PROCESS_START_TIMEOUT, pid, app.info.uid,
+            EventLog.writeEvent(EventLogTags.AM_PROCESS_START_TIMEOUT, pid, app.info.uid,
                     app.processName);
             mProcessNames.remove(app.processName, app.info.uid);
             // Take care of any launching providers waiting for this process.
@@ -5258,7 +5220,7 @@
         if (app == null) {
             Log.w(TAG, "No pending application record for pid " + pid
                     + " (IApplicationThread " + thread + "); dropping process");
-            EventLog.writeEvent(LOG_AM_DROP_PROCESS, pid);
+            EventLog.writeEvent(EventLogTags.AM_DROP_PROCESS, pid);
             if (pid > 0 && pid != MY_PID) {
                 Process.killProcess(pid);
             } else {
@@ -5292,7 +5254,7 @@
             return false;
         }
 
-        EventLog.writeEvent(LOG_AM_PROCESS_BOUND, app.pid, app.processName);
+        EventLog.writeEvent(EventLogTags.AM_PROC_BOUND, app.pid, app.processName);
         
         app.thread = thread;
         app.curAdj = app.setAdj = -100;
@@ -5512,7 +5474,7 @@
     }
 
     void enableScreenAfterBoot() {
-        EventLog.writeEvent(LOG_BOOT_PROGRESS_ENABLE_SCREEN,
+        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN,
                 SystemClock.uptimeMillis());
         mWindowManager.enableScreenAfterBoot();
     }
@@ -5719,7 +5681,7 @@
                     r.state = ActivityState.PAUSED;
                     completePauseLocked();
                 } else {
-                	EventLog.writeEvent(LOG_AM_FAILED_TO_PAUSE_ACTIVITY,
+                	EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE,
                 	        System.identityHashCode(r), r.shortComponentName, 
                 			mPausingActivity != null
                 			    ? mPausingActivity.shortComponentName : "(none)");
@@ -7120,7 +7082,7 @@
         }
 
         finishTaskMove(task);
-        EventLog.writeEvent(LOG_TASK_TO_FRONT, task);
+        EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, task);
     }
 
     private final void finishTaskMove(int task) {
@@ -7717,7 +7679,7 @@
                             + cpi.applicationInfo.packageName + "/"
                             + cpi.applicationInfo.uid + " for provider "
                             + name + ": launching app became null");
-                    EventLog.writeEvent(LOG_AM_PROVIDER_LOST_PROCESS,
+                    EventLog.writeEvent(EventLogTags.AM_PROVIDER_LOST_PROCESS,
                             cpi.applicationInfo.packageName,
                             cpi.applicationInfo.uid, name);
                     return null;
@@ -8230,7 +8192,7 @@
                 if (adj >= worstType) {
                     Log.w(TAG, "Killing for memory: " + proc + " (adj "
                             + adj + ")");
-                    EventLog.writeEvent(LOG_AM_KILL_FOR_MEMORY, proc.pid,
+                    EventLog.writeEvent(EventLogTags.AM_KILL_FOR_MEMORY, proc.pid,
                             proc.processName, adj);
                     killed = true;
                     Process.killProcess(pids[i]);
@@ -8500,7 +8462,7 @@
         }
         
         Log.i(TAG, "System now ready");
-        EventLog.writeEvent(LOG_BOOT_PROGRESS_AMS_READY,
+        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_AMS_READY,
             SystemClock.uptimeMillis());
 
         synchronized(this) {
@@ -8732,7 +8694,7 @@
             // This process loses!
             Log.w(TAG, "Process " + app.info.processName
                     + " has crashed too many times: killing!");
-            EventLog.writeEvent(LOG_AM_PROCESS_CRASHED_TOO_MUCH,
+            EventLog.writeEvent(EventLogTags.AM_PROCESS_CRASHED_TOO_MUCH,
                     app.info.processName, app.info.uid);
             killServicesLocked(app, false);
             for (int i=mHistory.size()-1; i>=0; i--) {
@@ -8749,7 +8711,7 @@
                 // explicitly does so...  but for persistent process, we really
                 // need to keep it running.  If a persistent process is actually
                 // repeatedly crashing, then badness for everyone.
-                EventLog.writeEvent(LOG_AM_PROCESS_BAD, app.info.uid,
+                EventLog.writeEvent(EventLogTags.AM_PROC_BAD, app.info.uid,
                         app.info.processName);
                 mBadProcesses.put(app.info.processName, app.info.uid, now);
                 app.bad = true;
@@ -9823,7 +9785,7 @@
                 if (sr.crashCount >= 2) {
                     Log.w(TAG, "Service crashed " + sr.crashCount
                             + " times, stopping: " + sr);
-                    EventLog.writeEvent(LOG_AM_SERVICE_CRASHED_TOO_MUCH,
+                    EventLog.writeEvent(EventLogTags.AM_SERVICE_CRASHED_TOO_MUCH,
                             sr.crashCount, sr.shortName, app.pid);
                     bringDownServiceLocked(sr, true);
                 } else if (!allowRestart) {
@@ -10433,7 +10395,7 @@
                     + r.name + " " + r.intent);
             mStringBuilder.setLength(0);
             r.intent.getIntent().toShortString(mStringBuilder, false, true);
-            EventLog.writeEvent(LOG_AM_CREATE_SERVICE,
+            EventLog.writeEvent(EventLogTags.AM_CREATE_SERVICE,
                     System.identityHashCode(r), r.shortName,
                     mStringBuilder.toString(), r.app.pid);
             synchronized (r.stats.getBatteryStats()) {
@@ -10551,7 +10513,7 @@
         r.nextRestartTime = SystemClock.uptimeMillis() + r.restartDelay;
         Log.w(TAG, "Scheduling restart of crashed service "
                 + r.shortName + " in " + r.restartDelay + "ms");
-        EventLog.writeEvent(LOG_AM_SCHEDULE_SERVICE_RESTART,
+        EventLog.writeEvent(EventLogTags.AM_SCHEDULE_SERVICE_RESTART,
                 r.shortName, r.restartDelay);
 
         Message msg = Message.obtain();
@@ -10696,7 +10658,7 @@
 
         if (DEBUG_SERVICE) Log.v(TAG, "Bringing down service " + r.name
                  + " " + r.intent);
-        EventLog.writeEvent(LOG_AM_DESTROY_SERVICE,
+        EventLog.writeEvent(EventLogTags.AM_DESTROY_SERVICE,
                 System.identityHashCode(r), r.shortName,
                 (r.app != null) ? r.app.pid : -1);
 
@@ -12147,13 +12109,13 @@
             Object curReceiver = r.receivers.get(r.nextReceiver-1);
             if (curReceiver instanceof BroadcastFilter) {
                 BroadcastFilter bf = (BroadcastFilter) curReceiver;
-                EventLog.writeEvent(LOG_AM_BROADCAST_DISCARD_FILTER,
+                EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_FILTER,
                         System.identityHashCode(r),
                         r.intent.getAction(),
                         r.nextReceiver - 1,
                         System.identityHashCode(bf));
             } else {
-                EventLog.writeEvent(LOG_AM_BROADCAST_DISCARD_APP,
+                EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP,
                         System.identityHashCode(r),
                         r.intent.getAction(),
                         r.nextReceiver - 1,
@@ -12162,7 +12124,7 @@
         } else {
             Log.w(TAG, "Discarding broadcast before first receiver is invoked: "
                     + r);
-            EventLog.writeEvent(LOG_AM_BROADCAST_DISCARD_APP,
+            EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP,
                     System.identityHashCode(r),
                     r.intent.getAction(),
                     r.nextReceiver,
@@ -12832,7 +12794,7 @@
                     Log.i(TAG, "Updating configuration to: " + values);
                 }
                 
-                EventLog.writeEvent(LOG_CONFIGURATION_CHANGED, changes);
+                EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes);
 
                 if (values.locale != null) {
                     saveLocaleLocked(values.locale, 
@@ -12910,8 +12872,8 @@
         if (DEBUG_SWITCH) Log.v(TAG, "Relaunching: " + r
                 + " with results=" + results + " newIntents=" + newIntents
                 + " andResume=" + andResume);
-        EventLog.writeEvent(andResume ? LOG_AM_RELAUNCH_RESUME_ACTIVITY
-                : LOG_AM_RELAUNCH_ACTIVITY, System.identityHashCode(r),
+        EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY
+                : EventLogTags.AM_RELAUNCH_ACTIVITY, System.identityHashCode(r),
                 r.task.taskId, r.shortComponentName);
         
         r.startFreezingScreenLocked(r.app, 0);
diff --git a/services/java/com/android/server/am/EventLogTags.logtags b/services/java/com/android/server/am/EventLogTags.logtags
new file mode 100644
index 0000000..7e4ea35
--- /dev/null
+++ b/services/java/com/android/server/am/EventLogTags.logtags
@@ -0,0 +1,82 @@
+# See system/core/logcat/event.logtags for a description of the format of this file.
+
+option java_package com.android.server.am
+
+2719 configuration_changed (config mask|1|5)
+2721 cpu (total|1|6),(user|1|6),(system|1|6),(iowait|1|6),(irq|1|6),(softirq|1|6)
+
+# ActivityManagerService.systemReady() starts:
+3040 boot_progress_ams_ready (time|2|3)
+# ActivityManagerService calls enableScreenAfterBoot():
+3050 boot_progress_enable_screen (time|2|3)
+
+# Do not change these names without updating the checkin_events setting in
+# google3/googledata/wireless/android/provisioning/gservices.config !!
+#
+# An activity is being finished:
+30001 am_finish_activity (Token|1|5),(Task ID|1|5),(Component Name|3),(Reason|3)
+# A task is being brought to the front of the screen:
+30002 am_task_to_front (Task|1|5)
+# An existing activity is being given a new intent:
+30003 am_new_intent (Token|1|5),(Task ID|1|5),(Component Name|3),(Action|3),(MIME Type|3),(URI|3),(Flags|1|5)
+# A new task is being created:
+30004 am_create_task (Task ID|1|5)
+# A new activity is being created in an existing task:
+30005 am_create_activity (Token|1|5),(Task ID|1|5),(Component Name|3),(Action|3),(MIME Type|3),(URI|3),(Flags|1|5)
+# An activity has been resumed into the foreground but was not already running:
+30006 am_restart_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
+# An activity has been resumed and is now in the foreground:
+30007 am_resume_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
+# Application Not Responding
+30008 anr (pid|1|5),(Package Name|3),(reason|3)
+# Activity launch time
+30009 activity_launch_time (Token|1|5),(Component Name|3),(time|2|3)
+# Application process bound to work
+30010 am_proc_bound (PID|1|5),(Process Name|3)
+# Application process died
+30011 am_proc_died (PID|1|5),(Process Name|3)
+# The Activity Manager failed to pause the given activity.
+30012 am_failed_to_pause (Token|1|5),(Wanting to pause|3),(Currently pausing|3)
+# Attempting to pause the current activity
+30013 am_pause_activity (Token|1|5),(Component Name|3)
+# Application process has been started
+30014 am_proc_start (PID|1|5),(UID|1|5),(Process Name|3),(Type|3),(Component|3)
+# An application process has been marked as bad
+30015 am_proc_bad (UID|1|5),(Process Name|3)
+# An application process that was bad is now marked as good
+30016 am_proc_good (UID|1|5),(Process Name|3)
+# Reporting to applications that memory is low
+30017 am_low_memory (Num Processes|1|1)
+# An activity is being destroyed:
+30018 am_destroy_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
+# An activity has been relaunched, resumed, and is now in the foreground:
+30019 am_relaunch_resume_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
+# An activity has been relaunched:
+30020 am_relaunch_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
+# The activity's onPause has been called.
+30021 am_on_paused_called (Component Name|3)
+# The activity's onResume has been called.
+30022 am_on_resume_called (Component Name|3)
+# Kill a process to reclaim memory.
+30023 am_kill_for_memory (PID|1|5),(Process Name|3),(OomAdj|1|5)
+# Discard an undelivered serialized broadcast (timeout/ANR/crash)
+30024 am_broadcast_discard_filter (Broadcast|1|5),(Action|3),(Receiver Number|1|1),(BroadcastFilter|1|5)
+30025 am_broadcast_discard_app (Broadcast|1|5),(Action|3),(Receiver Number|1|1),(App|3)
+# A service is being created
+30030 am_create_service (Service Record|1|5),(Name|3),(Intent|3),(PID|1|5)
+# A service is being destroyed
+30031 am_destroy_service (Service Record|1|5),(Name|3),(PID|1|5)
+# A process has crashed too many times, it is being cleared
+30032 am_process_crashed_too_much (Name|3),(PID|1|5)
+# An unknown process is trying to attach to the activity manager
+30033 am_drop_process (PID|1|5)
+# A service has crashed too many times, it is being stopped
+30034 am_service_crashed_too_much (Crash Count|1|1),(Component Name|3),(PID|1|5)
+# A service is going to be restarted after its process went away
+30035 am_schedule_service_restart (Component Name|3),(Time|2|3)
+# A client was waiting for a content provider, but its process was lost
+30036 am_provider_lost_process (Package Name|3),(UID|1|5),(Name|3)
+# The activity manager gave up on a new process taking too long to start
+30037 am_process_start_timeout (PID|1|5),(UID|1|5),(Process Name|3)
+
+
diff --git a/services/java/com/android/server/am/HistoryRecord.java b/services/java/com/android/server/am/HistoryRecord.java
index 84ded22..0b34f7c 100644
--- a/services/java/com/android/server/am/HistoryRecord.java
+++ b/services/java/com/android/server/am/HistoryRecord.java
@@ -373,7 +373,7 @@
                 final long totalTime = service.mInitialStartTime != 0
                         ? (curTime - service.mInitialStartTime) : thisTime;
                 if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
-                    EventLog.writeEvent(ActivityManagerService.LOG_ACTIVITY_LAUNCH_TIME,
+                    EventLog.writeEvent(EventLogTags.ACTIVITY_LAUNCH_TIME,
                             System.identityHashCode(this), shortComponentName,
                             thisTime, totalTime);
                     StringBuilder sb = service.mStringBuilder;
diff --git a/services/java/com/android/server/am/UsageStatsService.java b/services/java/com/android/server/am/UsageStatsService.java
index 373b44e..f99ca96 100644
--- a/services/java/com/android/server/am/UsageStatsService.java
+++ b/services/java/com/android/server/am/UsageStatsService.java
@@ -380,11 +380,15 @@
             // Get the most recent file
             mFileLeaf = getCurrentDateStr(FILE_PREFIX);
             // Copy current file to back up
-            File backupFile =  new File(mFile.getPath() + ".bak");
-            if (!mFile.renameTo(backupFile)) {
-                Log.w(TAG, "Failed to persist new stats");
-                return;
+            File backupFile = null;
+            if (mFile != null && mFile.exists()) {
+                backupFile = new File(mFile.getPath() + ".bak");
+                if (!mFile.renameTo(backupFile)) {
+                    Log.w(TAG, "Failed to persist new stats");
+                    return;
+                }
             }
+
             try {
                 // Write mStats to file
                 writeStatsFLOCK();
@@ -468,16 +472,10 @@
             
             final boolean samePackage = pkgName.equals(mLastResumedPkg);
             if (mIsResumed) {
-                if (samePackage) {
-                    Log.w(TAG, "Something wrong here, didn't expect "
-                            + pkgName + " to be resumed");
-                    return;
-                }
-                
                 if (mLastResumedPkg != null) {
                     // We last resumed some other package...  just pause it now
                     // to recover.
-                    Log.w(TAG, "Unexpected resume of " + pkgName
+                    Log.i(TAG, "Unexpected resume of " + pkgName
                             + " while already resumed in " + mLastResumedPkg);
                     PkgUsageStatsExtended pus = mStats.get(mLastResumedPkg);
                     if (pus != null) {
@@ -516,7 +514,7 @@
                 return;
             }
             if (!mIsResumed) {
-                Log.w(TAG, "Something wrong here, didn't expect "
+                Log.i(TAG, "Something wrong here, didn't expect "
                         + pkgName + " to be paused");
                 return;
             }
@@ -527,7 +525,7 @@
             PkgUsageStatsExtended pus = mStats.get(pkgName);
             if (pus == null) {
                 // Weird some error here
-                Log.w(TAG, "No package stats for pkg:"+pkgName);
+                Log.i(TAG, "No package stats for pkg:"+pkgName);
                 return;
             }
             pus.updatePause();
diff --git a/tests/AndroidTests/src/com/android/unit_tests/SearchManagerTest.java b/tests/AndroidTests/src/com/android/unit_tests/SearchManagerTest.java
index e48a57b..6f6f55d 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/SearchManagerTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/SearchManagerTest.java
@@ -21,10 +21,10 @@
 import android.app.Activity;
 import android.app.ISearchManager;
 import android.app.SearchManager;
+import android.app.SearchableInfo;
 import android.content.ComponentName;
 import android.content.Context;
 import android.os.ServiceManager;
-import android.server.search.SearchableInfo;
 import android.test.ActivityInstrumentationTestCase2;
 import android.test.suitebuilder.annotation.LargeTest;
 import android.test.suitebuilder.annotation.MediumTest;
diff --git a/tests/AndroidTests/src/com/android/unit_tests/SearchablesTest.java b/tests/AndroidTests/src/com/android/unit_tests/SearchablesTest.java
index 4e5f7a9..972559d 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/SearchablesTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/SearchablesTest.java
@@ -17,6 +17,8 @@
 package com.android.unit_tests;
 
 import android.app.SearchManager;
+import android.app.SearchableInfo;
+import android.app.SearchableInfo.ActionKeyInfo;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -28,9 +30,7 @@
 import android.content.res.Resources;
 import android.content.res.XmlResourceParser;
 import android.os.RemoteException;
-import android.server.search.SearchableInfo;
 import android.server.search.Searchables;
-import android.server.search.SearchableInfo.ActionKeyInfo;
 import android.test.AndroidTestCase;
 import android.test.MoreAsserts;
 import android.test.mock.MockContext;
diff --git a/tools/aapt/StringPool.cpp b/tools/aapt/StringPool.cpp
index 878d3b1..715170a 100644
--- a/tools/aapt/StringPool.cpp
+++ b/tools/aapt/StringPool.cpp
@@ -228,7 +228,7 @@
         }
         dat += (preSize+strPos)/sizeof(uint16_t);
         if (lenSize > sizeof(uint16_t)) {
-            *dat = htods(0x8000 | ((strSize>>16)&0x7ffff));
+            *dat = htods(0x8000 | ((strSize>>16)&0x7fff));
             dat++;
         }
         *dat++ = htods(strSize);