Merge "Remove MediaVideoItem and AudioTrack playback APIs."
diff --git a/api/current.xml b/api/current.xml
index a866669..b0f0b14 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -20328,7 +20328,7 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="value" type="android.view.animation.Interpolator">
+<parameter name="value" type="android.animation.TimeInterpolator">
 </parameter>
 </method>
 <method name="setStartDelay"
@@ -20678,7 +20678,7 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="interpolator" type="android.view.animation.Interpolator">
+<parameter name="interpolator" type="android.animation.TimeInterpolator">
 </parameter>
 </method>
 <method name="setStartDelay"
@@ -20981,7 +20981,7 @@
 >
 </method>
 <method name="getInterpolator"
- return="android.view.animation.Interpolator"
+ return="android.animation.TimeInterpolator"
  abstract="false"
  native="false"
  synchronized="false"
@@ -21036,7 +21036,7 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="interpolator" type="android.view.animation.Interpolator">
+<parameter name="interpolator" type="android.animation.TimeInterpolator">
 </parameter>
 </method>
 <method name="setValue"
@@ -21124,7 +21124,7 @@
 </parameter>
 </method>
 <method name="getInterpolator"
- return="android.view.animation.Interpolator"
+ return="android.animation.TimeInterpolator"
  abstract="false"
  native="false"
  synchronized="false"
@@ -21271,7 +21271,7 @@
 >
 <parameter name="transitionType" type="int">
 </parameter>
-<parameter name="interpolator" type="android.view.animation.Interpolator">
+<parameter name="interpolator" type="android.animation.TimeInterpolator">
 </parameter>
 </method>
 <method name="setStagger"
@@ -21670,6 +21670,27 @@
 </parameter>
 </method>
 </class>
+<interface name="TimeInterpolator"
+ abstract="true"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="getInterpolation"
+ return="float"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="input" type="float">
+</parameter>
+</method>
+</interface>
 <interface name="TypeEvaluator"
  abstract="true"
  static="false"
@@ -21794,7 +21815,7 @@
 >
 </method>
 <method name="getInterpolator"
- return="android.view.animation.Interpolator"
+ return="android.animation.TimeInterpolator"
  abstract="false"
  native="false"
  synchronized="false"
@@ -21956,7 +21977,7 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="value" type="android.view.animation.Interpolator">
+<parameter name="value" type="android.animation.TimeInterpolator">
 </parameter>
 </method>
 <method name="setRepeatCount"
@@ -212417,19 +212438,8 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<method name="getInterpolation"
- return="float"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="input" type="float">
-</parameter>
-</method>
+<implements name="android.animation.TimeInterpolator">
+</implements>
 </interface>
 <class name="LayoutAnimationController"
  extends="java.lang.Object"
@@ -215713,6 +215723,19 @@
 <parameter name="id" type="java.lang.String">
 </parameter>
 </method>
+<method name="showInputMethodAndSubtypeEnabler"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="topId" type="java.lang.String">
+</parameter>
+</method>
 <method name="showInputMethodPicker"
  return="void"
  abstract="false"
diff --git a/cmds/stagefright/recordvideo.cpp b/cmds/stagefright/recordvideo.cpp
index 330fbc2..f8eb514 100644
--- a/cmds/stagefright/recordvideo.cpp
+++ b/cmds/stagefright/recordvideo.cpp
@@ -18,12 +18,10 @@
 
 #include <binder/ProcessState.h>
 #include <media/stagefright/AudioPlayer.h>
-#include <media/stagefright/FileSource.h>
 #include <media/stagefright/MediaBufferGroup.h>
 #include <media/stagefright/MediaDebug.h>
 #include <media/stagefright/MediaDefs.h>
 #include <media/stagefright/MetaData.h>
-#include <media/stagefright/MediaExtractor.h>
 #include <media/stagefright/MPEG4Writer.h>
 #include <media/stagefright/OMXClient.h>
 #include <media/stagefright/OMXCodec.h>
@@ -31,18 +29,21 @@
 
 using namespace android;
 
-// print usage showing how to use this utility to record videos
+// Print usage showing how to use this utility to record videos
 static void usage(const char *me) {
     fprintf(stderr, "usage: %s\n", me);
     fprintf(stderr, "       -h(elp)\n");
-    fprintf(stderr, "       -b bit rate in bits per second (default 300000)\n");
-    fprintf(stderr, "       -c YUV420 color format: [0] semi planar or [1] planar (default 1)\n");
-    fprintf(stderr, "       -f frame rate in frames per second (default 30)\n");
-    fprintf(stderr, "       -i I frame interval in seconds (default 1)\n");
-    fprintf(stderr, "       -n number of frames to be recorded (default 300)\n");
-    fprintf(stderr, "       -w width in pixels (default 176)\n");
-    fprintf(stderr, "       -t height in pixels (default 144)\n");
-    fprintf(stderr, "       -v video codec: [0] AVC [1] M4V [2] H263 (default 0)\n");
+    fprintf(stderr, "       -b bit rate in bits per second (default: 300000)\n");
+    fprintf(stderr, "       -c YUV420 color format: [0] semi planar or [1] planar (default: 1)\n");
+    fprintf(stderr, "       -f frame rate in frames per second (default: 30)\n");
+    fprintf(stderr, "       -i I frame interval in seconds (default: 1)\n");
+    fprintf(stderr, "       -n number of frames to be recorded (default: 300)\n");
+    fprintf(stderr, "       -w width in pixels (default: 176)\n");
+    fprintf(stderr, "       -t height in pixels (default: 144)\n");
+    fprintf(stderr, "       -l encoder level. see omx il header (default: encoder specific)\n");
+    fprintf(stderr, "       -p encoder profile. see omx il header (default: encoder specific)\n");
+    fprintf(stderr, "       -v video codec: [0] AVC [1] M4V [2] H263 (default: 0)\n");
+    fprintf(stderr, "The output file is /sdcard/output.mp4\n");
     exit(1);
 }
 
@@ -56,6 +57,7 @@
           mFrameRate(fps),
           mColorFormat(colorFormat),
           mSize((width * height * 3) / 2) {
+
         mGroup.add_buffer(new MediaBuffer(mSize));
 
         // Check the color format to make sure
@@ -98,8 +100,11 @@
             return err;
         }
 
-        char x = (char)((double)rand() / RAND_MAX * 255);
-        memset((*buffer)->data(), x, mSize);
+        // We don't care about the contents. we just test video encoder
+        // Also, by skipping the content generation, we can return from
+        // read() much faster.
+        //char x = (char)((double)rand() / RAND_MAX * 255);
+        //memset((*buffer)->data(), x, mSize);
         (*buffer)->set_range(0, mSize);
         (*buffer)->meta_data()->clear();
         (*buffer)->meta_data()->setInt64(
@@ -125,38 +130,6 @@
     DummySource &operator=(const DummySource &);
 };
 
-sp<MediaSource> createSource(const char *filename) {
-    sp<MediaSource> source;
-
-    sp<MediaExtractor> extractor =
-        MediaExtractor::Create(new FileSource(filename));
-    if (extractor == NULL) {
-        return NULL;
-    }
-
-    size_t num_tracks = extractor->countTracks();
-
-    sp<MetaData> meta;
-    for (size_t i = 0; i < num_tracks; ++i) {
-        meta = extractor->getTrackMetaData(i);
-        CHECK(meta.get() != NULL);
-
-        const char *mime;
-        if (!meta->findCString(kKeyMIMEType, &mime)) {
-            continue;
-        }
-
-        if (strncasecmp(mime, "video/", 6)) {
-            continue;
-        }
-
-        source = extractor->getTrack(i);
-        break;
-    }
-
-    return source;
-}
-
 enum {
     kYUV420SP = 0,
     kYUV420P  = 1,
@@ -186,12 +159,14 @@
     int iFramesIntervalSeconds = 1;
     int colorFormat = OMX_COLOR_FormatYUV420Planar;
     int nFrames = 300;
+    int level = -1;        // Encoder specific default
+    int profile = -1;      // Encoder specific default
     int codec = 0;
     const char *fileName = "/sdcard/output.mp4";
 
     android::ProcessState::self()->startThreadPool();
     int res;
-    while ((res = getopt(argc, argv, "b:c:f:i:n:w:t:v:o:h")) >= 0) {
+    while ((res = getopt(argc, argv, "b:c:f:i:n:w:t:l:p:v:h")) >= 0) {
         switch (res) {
             case 'b':
             {
@@ -238,6 +213,18 @@
                 break;
             }
 
+            case 'l':
+            {
+                level = atoi(optarg);
+                break;
+            }
+
+            case 'p':
+            {
+                profile = atoi(optarg);
+                break;
+            }
+
             case 'v':
             {
                 codec = atoi(optarg);
@@ -260,7 +247,8 @@
     CHECK_EQ(client.connect(), OK);
 
     status_t err = OK;
-    sp<MediaSource> decoder = new DummySource(width, height, nFrames, frameRateFps, colorFormat);
+    sp<MediaSource> source =
+        new DummySource(width, height, nFrames, frameRateFps, colorFormat);
 
     sp<MetaData> enc_meta = new MetaData;
     switch (codec) {
@@ -282,10 +270,16 @@
     enc_meta->setInt32(kKeySliceHeight, height);
     enc_meta->setInt32(kKeyIFramesInterval, iFramesIntervalSeconds);
     enc_meta->setInt32(kKeyColorFormat, colorFormat);
+    if (level != -1) {
+        enc_meta->setInt32(kKeyVideoLevel, level);
+    }
+    if (profile != -1) {
+        enc_meta->setInt32(kKeyVideoProfile, profile);
+    }
 
     sp<MediaSource> encoder =
         OMXCodec::Create(
-                client.interface(), enc_meta, true /* createEncoder */, decoder);
+                client.interface(), enc_meta, true /* createEncoder */, source);
 
     sp<MPEG4Writer> writer = new MPEG4Writer(fileName);
     writer->addSource(encoder);
@@ -296,7 +290,7 @@
     err = writer->stop();
     int64_t end = systemTime();
 
-    printf("$\n");
+    fprintf(stderr, "$\n");
     client.disconnect();
 
     if (err != OK && err != ERROR_END_OF_STREAM) {
diff --git a/core/java/android/animation/Animator.java b/core/java/android/animation/Animator.java
index 2ada6d6..d3e0797 100644
--- a/core/java/android/animation/Animator.java
+++ b/core/java/android/animation/Animator.java
@@ -16,8 +16,6 @@
 
 package android.animation;
 
-import android.view.animation.Interpolator;
-
 import java.util.ArrayList;
 
 /**
@@ -97,7 +95,7 @@
      *
      * @param value the interpolator to be used by this animation
      */
-    public abstract void setInterpolator(Interpolator value);
+    public abstract void setInterpolator(TimeInterpolator value);
 
     /**
      * Returns whether this Animator is currently running (having been started and not yet ended).
diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java
index a8385e4..5de0293 100644
--- a/core/java/android/animation/AnimatorSet.java
+++ b/core/java/android/animation/AnimatorSet.java
@@ -16,8 +16,6 @@
 
 package android.animation;
 
-import android.view.animation.Interpolator;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -173,13 +171,13 @@
     }
 
     /**
-     * Sets the Interpolator for all current {@link #getChildAnimations() child animations}
+     * Sets the TimeInterpolator for all current {@link #getChildAnimations() child animations}
      * of this AnimatorSet.
      *
      * @param interpolator the interpolator to be used by each child animation of this AnimatorSet
      */
     @Override
-    public void setInterpolator(Interpolator interpolator) {
+    public void setInterpolator(TimeInterpolator interpolator) {
         for (Node node : mNodes) {
             node.animation.setInterpolator(interpolator);
         }
diff --git a/core/java/android/animation/Keyframe.java b/core/java/android/animation/Keyframe.java
index 192ba5c..f9a4f3c 100644
--- a/core/java/android/animation/Keyframe.java
+++ b/core/java/android/animation/Keyframe.java
@@ -16,14 +16,12 @@
 
 package android.animation;
 
-import android.view.animation.Interpolator;
-
 /**
  * This class holds a time/value pair for an animation. The Keyframe class is used
  * by {@link ValueAnimator} to define the values that the animation target will have over the course
  * of the animation. As the time proceeds from one keyframe to the other, the value of the
  * target object will animate between the value at the previous keyframe and the value at the
- * next keyframe. Each keyframe also holds an option {@link android.view.animation.Interpolator}
+ * next keyframe. Each keyframe also holds an optional {@link TimeInterpolator}
  * object, which defines the time interpolation over the intervalue preceding the keyframe.
  */
 public class Keyframe implements Cloneable {
@@ -47,7 +45,7 @@
      * The optional time interpolator for the interval preceding this keyframe. A null interpolator
      * (the default) results in linear interpolation over the interval.
      */
-    private Interpolator mInterpolator = null;
+    private TimeInterpolator mInterpolator = null;
 
     /**
      * Private constructor, called from the public constructors with the additional
@@ -224,7 +222,7 @@
      *
      * @return The optional interpolator for this Keyframe.
      */
-    public Interpolator getInterpolator() {
+    public TimeInterpolator getInterpolator() {
         return mInterpolator;
     }
 
@@ -234,7 +232,7 @@
      *
      * @return The optional interpolator for this Keyframe.
      */
-    public void setInterpolator(Interpolator interpolator) {
+    public void setInterpolator(TimeInterpolator interpolator) {
         mInterpolator = interpolator;
     }
 
diff --git a/core/java/android/animation/KeyframeSet.java b/core/java/android/animation/KeyframeSet.java
index af47a15..a24b1fb 100644
--- a/core/java/android/animation/KeyframeSet.java
+++ b/core/java/android/animation/KeyframeSet.java
@@ -18,8 +18,6 @@
 
 import java.util.ArrayList;
 
-import android.view.animation.Interpolator;
-
 /**
  * This class holds a collection of Keyframe objects and is called by ValueAnimator to calculate
  * values between those keyframes for a given animation. The class internal to the animation
@@ -58,7 +56,7 @@
         if (fraction <= 0f) {
             final Keyframe prevKeyframe = mKeyframes.get(0);
             final Keyframe nextKeyframe = mKeyframes.get(1);
-            final Interpolator interpolator = nextKeyframe.getInterpolator();
+            final TimeInterpolator interpolator = nextKeyframe.getInterpolator();
             if (interpolator != null) {
                 fraction = interpolator.getInterpolation(fraction);
             }
@@ -69,7 +67,7 @@
         } else if (fraction >= 1f) {
             final Keyframe prevKeyframe = mKeyframes.get(mNumKeyframes - 2);
             final Keyframe nextKeyframe = mKeyframes.get(mNumKeyframes - 1);
-            final Interpolator interpolator = nextKeyframe.getInterpolator();
+            final TimeInterpolator interpolator = nextKeyframe.getInterpolator();
             if (interpolator != null) {
                 fraction = interpolator.getInterpolation(fraction);
             }
@@ -82,7 +80,7 @@
         for (int i = 1; i < mNumKeyframes; ++i) {
             Keyframe nextKeyframe = mKeyframes.get(i);
             if (fraction < nextKeyframe.getFraction()) {
-                final Interpolator interpolator = nextKeyframe.getInterpolator();
+                final TimeInterpolator interpolator = nextKeyframe.getInterpolator();
                 if (interpolator != null) {
                     fraction = interpolator.getInterpolation(fraction);
                 }
diff --git a/core/java/android/animation/LayoutTransition.java b/core/java/android/animation/LayoutTransition.java
index 52f0f16..56ad857 100644
--- a/core/java/android/animation/LayoutTransition.java
+++ b/core/java/android/animation/LayoutTransition.java
@@ -21,7 +21,6 @@
 import android.view.ViewTreeObserver;
 import android.view.animation.AccelerateDecelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
-import android.view.animation.Interpolator;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -142,10 +141,10 @@
     /**
      * The default interpolators used for the animations
      */
-    private Interpolator mAppearingInterpolator = new AccelerateDecelerateInterpolator();
-    private Interpolator mDisappearingInterpolator = new AccelerateDecelerateInterpolator();
-    private Interpolator mChangingAppearingInterpolator = new DecelerateInterpolator();
-    private Interpolator mChangingDisappearingInterpolator = new DecelerateInterpolator();
+    private TimeInterpolator mAppearingInterpolator = new AccelerateDecelerateInterpolator();
+    private TimeInterpolator mDisappearingInterpolator = new AccelerateDecelerateInterpolator();
+    private TimeInterpolator mChangingAppearingInterpolator = new DecelerateInterpolator();
+    private TimeInterpolator mChangingDisappearingInterpolator = new DecelerateInterpolator();
 
     /**
      * This hashmap is used to store the animations that are currently running as part of
@@ -387,9 +386,9 @@
      * {@link #APPEARING}, or {@link #DISAPPEARING}, which determines the animation whose
      * duration is being set.
      * @param interpolator The interpolator that the specified animation should use.
-     * @see Animator#setInterpolator(android.view.animation.Interpolator)
+     * @see Animator#setInterpolator(TimeInterpolator)
      */
-    public void setInterpolator(int transitionType, Interpolator interpolator) {
+    public void setInterpolator(int transitionType, TimeInterpolator interpolator) {
         switch (transitionType) {
             case CHANGE_APPEARING:
                 mChangingAppearingInterpolator = interpolator;
@@ -414,10 +413,10 @@
      * @param transitionType one of {@link #CHANGE_APPEARING}, {@link #CHANGE_DISAPPEARING},
      * {@link #APPEARING}, or {@link #DISAPPEARING}, which determines the animation whose
      * duration is being set.
-     * @return Interpolator The interpolator that the specified animation uses.
-     * @see Animator#setInterpolator(android.view.animation.Interpolator)
+     * @return TimeInterpolator The interpolator that the specified animation uses.
+     * @see Animator#setInterpolator(TimeInterpolator)
      */
-    public Interpolator getInterpolator(int transitionType) {
+    public TimeInterpolator getInterpolator(int transitionType) {
         switch (transitionType) {
             case CHANGE_APPEARING:
                 return mChangingAppearingInterpolator;
diff --git a/core/java/android/animation/TimeInterpolator.java b/core/java/android/animation/TimeInterpolator.java
new file mode 100644
index 0000000..8d795a8
--- /dev/null
+++ b/core/java/android/animation/TimeInterpolator.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.animation;
+
+/**
+ * A time interpolator defines the rate of change of an animation. This allows animations
+ * to have non-linear motion, such as acceleration and deceleration.
+ */
+public interface TimeInterpolator {
+
+    /**
+     * Maps a value representing the elapsed fraciton of an animation to a value that represents
+     * the interpolated fraction. This interpolated value is then multiplied by the change in
+     * value of an animation to derive the animated value at the current elapsed animation time.
+     *
+     * @param input A value between 0 and 1.0 indicating our current point
+     *        in the animation where 0 represents the start and 1.0 represents
+     *        the end
+     * @return The interpolation value. This value can be more than 1.0 for
+     *         interpolators which overshoot their targets, or less than 0 for
+     *         interpolators that undershoot their targets.
+     */
+    float getInterpolation(float input);
+}
diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java
index f81b1ea..d2b17f0 100755
--- a/core/java/android/animation/ValueAnimator.java
+++ b/core/java/android/animation/ValueAnimator.java
@@ -21,7 +21,6 @@
 import android.os.Message;
 import android.view.animation.AccelerateDecelerateInterpolator;
 import android.view.animation.AnimationUtils;
-import android.view.animation.Interpolator;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -36,7 +35,7 @@
  * <p>By default, ValueAnimator uses non-linear time interpolation, via the
  * {@link AccelerateDecelerateInterpolator} class, which accelerates into and decelerates
  * out of an animation. This behavior can be changed by calling
- * {@link ValueAnimator#setInterpolator(Interpolator)}.</p>
+ * {@link ValueAnimator#setInterpolator(TimeInterpolator)}.</p>
  */
 public class ValueAnimator<T> extends Animator {
 
@@ -95,7 +94,8 @@
     private static final ArrayList<ValueAnimator> sPendingAnimations = new ArrayList<ValueAnimator>();
 
     // The time interpolator to be used if none is set on the animation
-    private static final Interpolator sDefaultInterpolator = new AccelerateDecelerateInterpolator();
+    private static final TimeInterpolator sDefaultInterpolator =
+            new AccelerateDecelerateInterpolator();
 
     // type evaluators for the three primitive types handled by this implementation
     private static final TypeEvaluator sIntEvaluator = new IntEvaluator();
@@ -178,7 +178,7 @@
      * through this interpolator to calculate the interpolated fraction, which is then used to
      * calculate the animated values.
      */
-    private Interpolator mInterpolator = sDefaultInterpolator;
+    private TimeInterpolator mInterpolator = sDefaultInterpolator;
 
     /**
      * The set of listeners to be sent events through the life of an animation.
@@ -654,7 +654,7 @@
      * @param value the interpolator to be used by this animation
      */
     @Override
-    public void setInterpolator(Interpolator value) {
+    public void setInterpolator(TimeInterpolator value) {
         if (value != null) {
             mInterpolator = value;
         }
@@ -665,7 +665,7 @@
      *
      * @return The timing interpolator for this ValueAnimator.
      */
-    public Interpolator getInterpolator() {
+    public TimeInterpolator getInterpolator() {
         return mInterpolator;
     }
 
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index ba74d9b..643e747 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -399,7 +399,11 @@
         pw.println(prefix + "uid=" + uid + " flags=0x" + Integer.toHexString(flags)
                 + " theme=0x" + Integer.toHexString(theme));
         pw.println(prefix + "sourceDir=" + sourceDir);
-        if (!sourceDir.equals(publicSourceDir)) {
+        if (sourceDir == null) {
+            if (publicSourceDir != null) {
+                pw.println(prefix + "publicSourceDir=" + publicSourceDir);
+            }
+        } else if (!sourceDir.equals(publicSourceDir)) {
             pw.println(prefix + "publicSourceDir=" + publicSourceDir);
         }
         if (resourceDirs != null) {
diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java
index 44b73c5..5fd2246 100644
--- a/core/java/android/os/BatteryManager.java
+++ b/core/java/android/os/BatteryManager.java
@@ -84,7 +84,15 @@
      * String describing the technology of the current battery.
      */
     public static final String EXTRA_TECHNOLOGY = "technology";
-    
+
+    /**
+     * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
+     * Boolean value set to true if an unsupported charger is attached
+     * to the device.
+     * {@hide}
+     */
+    public static final String EXTRA_INVALID_CHARGER = "invalid_charger";
+
     // values for "status" field in the ACTION_BATTERY_CHANGED Intent
     public static final int BATTERY_STATUS_UNKNOWN = 1;
     public static final int BATTERY_STATUS_CHARGING = 2;
diff --git a/core/java/android/view/animation/Interpolator.java b/core/java/android/view/animation/Interpolator.java
index d14c3e33..5d0fe7e 100644
--- a/core/java/android/view/animation/Interpolator.java
+++ b/core/java/android/view/animation/Interpolator.java
@@ -16,24 +16,16 @@
 
 package android.view.animation;
 
+import android.animation.TimeInterpolator;
+
 /**
  * An interpolator defines the rate of change of an animation. This allows
  * the basic animation effects (alpha, scale, translate, rotate) to be 
  * accelerated, decelerated, repeated, etc.
  */
-public interface Interpolator {
-    
-    /**
-     * Maps a point on the timeline to a multiplier to be applied to the
-     * transformations of an animation.
-     * 
-     * @param input A value between 0 and 1.0 indicating our current point
-     *        in the animation where 0 represents the start and 1.0 represents
-     *        the end
-     * @return The interpolation value. This value can be more than 1.0 for
-     *         Interpolators which overshoot their targets, or less than 0 for
-     *         Interpolators that undershoot their targets.
-     */
-    float getInterpolation(float input);
-    
+public interface Interpolator extends TimeInterpolator {
+    // A new interface, TimeInterpolator, was introduced for the new android.animation
+    // package. This older Interpolator interface extends TimeInterpolator so that users of
+    // the new Animator-based animations can use either the old Interpolator implementations or
+    // new classes that implement TimeInterpolator directly.
 }
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 8bd3298..8e355d6 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -1401,6 +1401,16 @@
         }
     }
 
+    public void showInputMethodAndSubtypeEnabler(String topId) {
+        synchronized (mH) {
+            try {
+                mService.showInputMethodAndSubtypeEnablerFromClient(mClient, topId);
+            } catch (RemoteException e) {
+                Log.w(TAG, "IME died: " + mCurId, e);
+            }
+        }
+    }
+
     void doDump(FileDescriptor fd, PrintWriter fout, String[] args) {
         final Printer p = new PrintWriterPrinter(fout);
         p.println("Input method client state for " + this + ":");
diff --git a/core/java/com/android/internal/content/NativeLibraryHelper.java b/core/java/com/android/internal/content/NativeLibraryHelper.java
index 2a8cd94..00c4dbe 100644
--- a/core/java/com/android/internal/content/NativeLibraryHelper.java
+++ b/core/java/com/android/internal/content/NativeLibraryHelper.java
@@ -294,33 +294,44 @@
         }
     }
 
+    // Convenience method to call removeNativeBinariesFromDirLI(File)
+    public static boolean removeNativeBinariesLI(String nativeLibraryPath) {
+        return removeNativeBinariesFromDirLI(new File(nativeLibraryPath));
+    }
+
     // Remove the native binaries of a given package. This simply
     // gets rid of the files in the 'lib' sub-directory.
-    public static void removeNativeBinariesLI(String nativeLibraryPath) {
+    public static boolean removeNativeBinariesFromDirLI(File nativeLibraryDir) {
         if (DEBUG_NATIVE) {
-            Slog.w(TAG, "Deleting native binaries from: " + nativeLibraryPath);
+            Slog.w(TAG, "Deleting native binaries from: " + nativeLibraryDir.getPath());
         }
 
+        boolean deletedFiles = false;
+
         /*
          * Just remove any file in the directory. Since the directory is owned
          * by the 'system' UID, the application is not supposed to have written
          * anything there.
          */
-        File binaryDir = new File(nativeLibraryPath);
-        if (binaryDir.exists()) {
-            File[] binaries = binaryDir.listFiles();
+        if (nativeLibraryDir.exists()) {
+            final File[] binaries = nativeLibraryDir.listFiles();
             if (binaries != null) {
                 for (int nn = 0; nn < binaries.length; nn++) {
                     if (DEBUG_NATIVE) {
                         Slog.d(TAG, "    Deleting " + binaries[nn].getName());
                     }
+
                     if (!binaries[nn].delete()) {
                         Slog.w(TAG, "Could not delete native binary: " + binaries[nn].getPath());
+                    } else {
+                        deletedFiles = true;
                     }
                 }
             }
             // Do not delete 'lib' directory itself, or this will prevent
             // installation of future updates.
         }
+
+        return deletedFiles;
     }
 }
diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl
index d012b0f..bffec1d 100644
--- a/core/java/com/android/internal/view/IInputMethodManager.aidl
+++ b/core/java/com/android/internal/view/IInputMethodManager.aidl
@@ -49,6 +49,7 @@
             
     void showInputMethodPickerFromClient(in IInputMethodClient client);
     void showInputMethodSubtypePickerFromClient(in IInputMethodClient client);
+    void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client, String topId);
     void setInputMethod(in IBinder token, String id);
     void hideMySoftInput(in IBinder token, int flags);
     void showMySoftInput(in IBinder token, int flags);
diff --git a/core/java/com/android/internal/view/InputMethodAndSubtypeEnabler.java b/core/java/com/android/internal/view/InputMethodAndSubtypeEnabler.java
new file mode 100644
index 0000000..200d49f
--- /dev/null
+++ b/core/java/com/android/internal/view/InputMethodAndSubtypeEnabler.java
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.view;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.view.inputmethod.InputMethodSubtype;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+public class InputMethodAndSubtypeEnabler extends PreferenceActivity {
+
+    private boolean mHaveHardKeyboard;
+
+    private List<InputMethodInfo> mInputMethodProperties;
+
+    private final TextUtils.SimpleStringSplitter mStringColonSplitter
+            = new TextUtils.SimpleStringSplitter(':');
+
+    private String mLastInputMethodId;
+    private String mLastTickedInputMethodId;
+
+    private AlertDialog mDialog = null;
+
+    @Override
+    protected void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        Configuration config = getResources().getConfiguration();
+        mHaveHardKeyboard = (config.keyboard == Configuration.KEYBOARD_QWERTY);
+        onCreateIMM();
+        setPreferenceScreen(createPreferenceHierarchy());
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        loadInputMethodSubtypeList();
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        saveInputMethodSubtypeList();
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(
+            PreferenceScreen preferenceScreen, Preference preference) {
+
+        if (preference instanceof CheckBoxPreference) {
+            final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
+            final String id = chkPref.getKey();
+            // TODO: Check subtype or not here
+            if (chkPref.isChecked()) {
+                InputMethodInfo selImi = null;
+                final int N = mInputMethodProperties.size();
+                for (int i = 0; i < N; i++) {
+                    InputMethodInfo imi = mInputMethodProperties.get(i);
+                    if (id.equals(imi.getId())) {
+                        selImi = imi;
+                        if (isSystemIme(imi)) {
+                            setSubtypesPreferenceEnabled(id, true);
+                            // This is a built-in IME, so no need to warn.
+                            mLastTickedInputMethodId = id;
+                            return super.onPreferenceTreeClick(preferenceScreen, preference);
+                        }
+                        break;
+                    }
+                }
+                if (selImi == null) {
+                    return super.onPreferenceTreeClick(preferenceScreen, preference);
+                }
+                chkPref.setChecked(false);
+                if (mDialog == null) {
+                    mDialog = (new AlertDialog.Builder(this))
+                            .setTitle(android.R.string.dialog_alert_title)
+                            .setIcon(android.R.drawable.ic_dialog_alert)
+                            .setCancelable(true)
+                            .setPositiveButton(android.R.string.ok,
+                                    new DialogInterface.OnClickListener() {
+                                        public void onClick(DialogInterface dialog, int which) {
+                                            chkPref.setChecked(true);
+                                            setSubtypesPreferenceEnabled(id, true);
+                                            mLastTickedInputMethodId = id;
+                                        }
+
+                            })
+                            .setNegativeButton(android.R.string.cancel,
+                                    new DialogInterface.OnClickListener() {
+                                        public void onClick(DialogInterface dialog, int which) {
+                                        }
+
+                            })
+                            .create();
+                } else {
+                    if (mDialog.isShowing()) {
+                        mDialog.dismiss();
+                    }
+                }
+                mDialog.setMessage(getResources().getString(
+                        com.android.internal.R.string.ime_enabler_security_warning,
+                        selImi.getServiceInfo().applicationInfo.loadLabel(getPackageManager())));
+                mDialog.show();
+            } else {
+                if (id.equals(mLastTickedInputMethodId)) {
+                    mLastTickedInputMethodId = null;
+                }
+                setSubtypesPreferenceEnabled(id, false);
+            }
+        }
+        return super.onPreferenceTreeClick(preferenceScreen, preference);
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        if (mDialog != null) {
+            mDialog.dismiss();
+            mDialog = null;
+        }
+    }
+
+    private void onCreateIMM() {
+        InputMethodManager imm = (InputMethodManager) getSystemService(
+                Context.INPUT_METHOD_SERVICE);
+
+        // TODO: Change mInputMethodProperties to Map
+        mInputMethodProperties = imm.getInputMethodList();
+
+        mLastInputMethodId = Settings.Secure.getString(getContentResolver(),
+                Settings.Secure.DEFAULT_INPUT_METHOD);
+    }
+
+    private PreferenceScreen createPreferenceHierarchy() {
+        // Root
+        PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
+
+        int N = (mInputMethodProperties == null ? 0 : mInputMethodProperties.size());
+        // TODO: Use iterator.
+        for (int i = 0; i < N; ++i) {
+            PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(this);
+            root.addPreference(keyboardSettingsCategory);
+            InputMethodInfo property = mInputMethodProperties.get(i);
+            String prefKey = property.getId();
+
+            PackageManager pm = getPackageManager();
+            CharSequence label = property.loadLabel(pm);
+            boolean systemIME = isSystemIme(property);
+
+            keyboardSettingsCategory.setTitle(label);
+
+            // Add a check box.
+            // Don't show the toggle if it's the only keyboard in the system, or it's a system IME.
+            if (mHaveHardKeyboard || (N > 1 && !systemIME)) {
+                CheckBoxPreference chkbxPref = new CheckBoxPreference(this);
+                chkbxPref.setKey(prefKey);
+                chkbxPref.setTitle(label);
+                keyboardSettingsCategory.addPreference(chkbxPref);
+            }
+
+            ArrayList<InputMethodSubtype> subtypes = property.getSubtypes();
+            if (subtypes.size() > 0) {
+                PreferenceCategory subtypesCategory = new PreferenceCategory(this);
+                subtypesCategory.setTitle(getResources().getString(
+                        com.android.internal.R.string.ime_enabler_subtype_title, label));
+                root.addPreference(subtypesCategory);
+                for (InputMethodSubtype subtype: subtypes) {
+                    CharSequence subtypeLabel;
+                    int nameResId = subtype.getNameResId();
+                    if (nameResId != 0) {
+                        subtypeLabel = pm.getText(property.getPackageName(), nameResId,
+                                property.getServiceInfo().applicationInfo);
+                    } else {
+                        int modeResId = subtype.getModeResId();
+                        CharSequence language = subtype.getLocale();
+                        CharSequence mode = modeResId == 0 ? null
+                                : pm.getText(property.getPackageName(), modeResId,
+                                        property.getServiceInfo().applicationInfo);
+                        // TODO: Use more friendly Title and UI
+                        subtypeLabel = (mode == null ? "" : mode) + ","
+                                + (language == null ? "" : language);
+                    }
+                    CheckBoxPreference chkbxPref = new CheckBoxPreference(this);
+                    chkbxPref.setKey(prefKey + subtype.hashCode());
+                    chkbxPref.setTitle(subtypeLabel);
+                    chkbxPref.setSummary(label);
+                    subtypesCategory.addPreference(chkbxPref);
+                }
+            }
+        }
+        return root;
+    }
+
+    private void loadInputMethodSubtypeList() {
+        final HashSet<String> enabled = new HashSet<String>();
+        String enabledStr = Settings.Secure.getString(getContentResolver(),
+                Settings.Secure.ENABLED_INPUT_METHODS);
+        if (enabledStr != null) {
+            final TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
+            splitter.setString(enabledStr);
+            while (splitter.hasNext()) {
+                enabled.add(splitter.next());
+            }
+        }
+
+        // Update the statuses of the Check Boxes.
+        int N = mInputMethodProperties.size();
+        // TODO: Use iterator.
+        for (int i = 0; i < N; ++i) {
+            final String id = mInputMethodProperties.get(i).getId();
+            CheckBoxPreference pref = (CheckBoxPreference) findPreference(
+                    mInputMethodProperties.get(i).getId());
+            if (pref != null) {
+                boolean isEnabled = enabled.contains(id);
+                pref.setChecked(isEnabled);
+                setSubtypesPreferenceEnabled(id, isEnabled);
+            }
+        }
+        mLastTickedInputMethodId = null;
+    }
+
+    private void saveInputMethodSubtypeList() {
+        StringBuilder builder = new StringBuilder();
+        StringBuilder disabledSysImes = new StringBuilder();
+
+        int firstEnabled = -1;
+        int N = mInputMethodProperties.size();
+        for (int i = 0; i < N; ++i) {
+            final InputMethodInfo property = mInputMethodProperties.get(i);
+            final String id = property.getId();
+            CheckBoxPreference pref = (CheckBoxPreference) findPreference(id);
+            boolean currentInputMethod = id.equals(mLastInputMethodId);
+            boolean systemIme = isSystemIme(property);
+            // TODO: Append subtypes by using the separator ";"
+            if (((N == 1 || systemIme) && !mHaveHardKeyboard)
+                    || (pref != null && pref.isChecked())) {
+                if (builder.length() > 0) builder.append(':');
+                builder.append(id);
+                if (firstEnabled < 0) {
+                    firstEnabled = i;
+                }
+            } else if (currentInputMethod) {
+                mLastInputMethodId = mLastTickedInputMethodId;
+            }
+            // If it's a disabled system ime, add it to the disabled list so that it
+            // doesn't get enabled automatically on any changes to the package list
+            if (pref != null && !pref.isChecked() && systemIme && mHaveHardKeyboard) {
+                if (disabledSysImes.length() > 0) disabledSysImes.append(":");
+                disabledSysImes.append(id);
+            }
+        }
+
+        // If the last input method is unset, set it as the first enabled one.
+        if (TextUtils.isEmpty(mLastInputMethodId)) {
+            if (firstEnabled >= 0) {
+                mLastInputMethodId = mInputMethodProperties.get(firstEnabled).getId();
+            } else {
+                mLastInputMethodId = null;
+            }
+        }
+
+        Settings.Secure.putString(getContentResolver(),
+                Settings.Secure.ENABLED_INPUT_METHODS, builder.toString());
+        Settings.Secure.putString(getContentResolver(),
+                Settings.Secure.DISABLED_SYSTEM_INPUT_METHODS, disabledSysImes.toString());
+        Settings.Secure.putString(getContentResolver(),
+                Settings.Secure.DEFAULT_INPUT_METHOD,
+                mLastInputMethodId != null ? mLastInputMethodId : "");
+    }
+
+    private void setSubtypesPreferenceEnabled(String id, boolean enabled) {
+        PreferenceScreen preferenceScreen = getPreferenceScreen();
+        final int N = mInputMethodProperties.size();
+        // TODO: Use iterator.
+        for (int i = 0; i < N; i++) {
+            InputMethodInfo imi = mInputMethodProperties.get(i);
+            if (id.equals(imi.getId())) {
+                for (InputMethodSubtype subtype: imi.getSubtypes()) {
+                    preferenceScreen.findPreference(id + subtype.hashCode()).setEnabled(enabled);
+                }
+            }
+        }
+    }
+
+    private boolean isSystemIme(InputMethodInfo property) {
+        return (property.getServiceInfo().applicationInfo.flags
+                & ApplicationInfo.FLAG_SYSTEM) != 0;
+    }
+}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 3a1d76f..f15d0a4 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1373,6 +1373,11 @@
                 android:permission="android.permission.BIND_WALLPAPER">
         </service>
 
+        <activity android:name="com.android.internal.view.InputMethodAndSubtypeEnabler"
+                android:excludeFromRecents="true"
+                android:exported="true">
+        </activity>
+
         <receiver android:name="com.android.server.BootReceiver" >
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 8b4f91f..521a739 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1639,7 +1639,7 @@
 
     <!-- Do not translate.  WebView User Agent string -->
     <string name="web_user_agent" translatable="false">Mozilla/5.0 (Linux; U; <xliff:g id="x">Android %s</xliff:g>)
-        AppleWebKit/534.9 (KHTML, like Gecko) Version/4.0 <xliff:g id="mobile">%s</xliff:g>Safari/534.9</string>
+        AppleWebKit/534.10 (KHTML, like Gecko) Version/4.0 <xliff:g id="mobile">%s</xliff:g>Safari/534.10</string>
     <!-- Do not translate.  WebView User Agent targeted content -->
     <string name="web_user_agent_target_content" translatable="false">"Mobile "</string>
 
@@ -2385,5 +2385,9 @@
         <item quantity="other"><xliff:g id="index" example="2">%d</xliff:g> of <xliff:g id="total" example="137">%d</xliff:g></item>
     </plurals>
 
+    <!-- Warning message about security implications of enabling an input method, displayed as a dialog message when the user selects to enable an IME. -->
+    <string name="ime_enabler_security_warning">This input method may be able to collect all the text you type, including personal data like passwords and credit card numbers. It comes from the application <xliff:g id="ime_application_name">%1$s</xliff:g>. Use this input method?</string>
+    <!-- Label for selecting the input method to use -->
+    <string name="ime_enabler_subtype_title">Select inputmethods in <xliff:g id="ime_application_name">%1$s</xliff:g></string>
 
 </resources>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index 4b5047e..0f653f1 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -1139,13 +1139,13 @@
         <item name="android:textColorLink">?textColorLinkInverse</item>
     </style>
 
-    <style name="TextAppearance.Holo.Light.Large">
+    <style name="TextAppearance.Holo.Light.Large" parent="TextAppearance.Large">
     </style>
 
-    <style name="TextAppearance.Holo.Light.Medium">
+    <style name="TextAppearance.Holo.Light.Medium" parent="TextAppearance.Medium">
     </style>
 
-    <style name="TextAppearance.Holo.Light.Small">
+    <style name="TextAppearance.Holo.Light.Small" parent="TextAppearance.Small">
     </style>
  
    <style name="TextAppearance.Holo.Light.Large.Inverse">
diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
index 1289a9e..276e281 100755
--- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
+++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
@@ -579,7 +579,6 @@
     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;
diff --git a/include/camera/CameraHardwareInterface.h b/include/camera/CameraHardwareInterface.h
index 3a77dd1..561a46d 100644
--- a/include/camera/CameraHardwareInterface.h
+++ b/include/camera/CameraHardwareInterface.h
@@ -21,6 +21,8 @@
 #include <ui/egl/android_natives.h>
 #include <utils/RefBase.h>
 #include <surfaceflinger/ISurface.h>
+#include <ui/android_native_buffer.h>
+#include <ui/GraphicBuffer.h>
 #include <camera/Camera.h>
 #include <camera/CameraParameters.h>
 
@@ -47,6 +49,17 @@
                               const sp<IMemory>& dataPtr,
                               void* user);
 
+#ifdef USE_GRAPHIC_VIDEO_BUFFERS
+/**
+ * Replace data_callback_timestamp. Once we are done, this
+ * should be renamed as data_callback_timestamp, and the existing
+ * data_callback_timestamp should be deleted.
+ */
+typedef void (*videobuffer_callback_timestamp)(nsecs_t timestamp,
+                                        int32_t msgType,
+                                        const sp<android_native_buffer_t>& buf,
+                                        void* user);
+#endif
 typedef void (*data_callback_timestamp)(nsecs_t timestamp,
                                         int32_t msgType,
                                         const sp<IMemory>& dataPtr,
@@ -87,6 +100,46 @@
 public:
     virtual ~CameraHardwareInterface() { }
 
+#ifdef USE_GRAPHIC_VIDEO_BUFFERS
+    /**
+     * Replace existing setCallbacks() method. Once we are done, the
+     * videobuffer_callback_timestamp parameter will be renamed to
+     * data_callback_timestamp, but its signature will be the same
+     * as videobuffer_callback_timestamp, which will be renamed
+     * to data_callback_timestamp and the exiting data_callback_timestamp
+     * will be deleted.
+     */
+    virtual void        setCallbacks(notify_callback notify_cb,
+                                data_callback data_cb,
+                                videobuffer_callback_timestamp data_cb_timestamp,
+                                void* user) = 0;
+
+    /**
+     * Replace releaseRecordingFrame(). releaseRecordingFrame() should be
+     * changed so that it has the same signature of releaseVideoBuffer(),
+     * once we are done, and releaseVideoBuffer() will be deleted.
+     */
+    virtual void        releaseVideoBuffer(const sp<android_native_buffer_t>& buf) = 0;
+
+    /**
+     * This method should be called after startRecording().
+     *
+     * @param nBuffers the total number of video buffers allocated by the camera
+     *  hal
+     * @param buffers an array allocated by the camera hal to hold the pointers
+     *  to the individual video buffers. The video buffers and the buffers array
+     *  should NOT be modified/released by camera hal until stopRecording() is
+     *  called and all outstanding video buffers previously sent out via
+     *  CAMERA_MSG_VIDEO_FRAME have been released via releaseVideoBuffer().
+     *  Camera hal client must not release the individual buffers and the buffers
+     *  array.
+     * @return no error if OK.
+     */
+    virtual status_t    getVideoBufferInfo(
+                            sp<android_native_buffer_t>** buffers,
+                            size_t *nBuffers) = 0;
+#endif
+
     /** Set the ANativeWindow to which preview frames are sent */
     virtual status_t setPreviewWindow(const sp<ANativeWindow>& buf) = 0;
 
diff --git a/include/media/stagefright/AudioPlayer.h b/include/media/stagefright/AudioPlayer.h
index ed2f7d7..37af032 100644
--- a/include/media/stagefright/AudioPlayer.h
+++ b/include/media/stagefright/AudioPlayer.h
@@ -49,11 +49,9 @@
 
     status_t start(bool sourceAlreadyStarted = false);
 
-    void pause();
+    void pause(bool playPendingSamples = false);
     void resume();
 
-    void stop();
-
     // Returns the timestamp of the last buffer played (in us).
     int64_t getMediaTimeUs();
 
@@ -107,6 +105,8 @@
 
     int64_t getRealTimeUsLocked() const;
 
+    void reset();
+
     AudioPlayer(const AudioPlayer &);
     AudioPlayer &operator=(const AudioPlayer &);
 };
diff --git a/include/ui/InputDispatcher.h b/include/ui/InputDispatcher.h
index 8d4654f..246df8f8 100644
--- a/include/ui/InputDispatcher.h
+++ b/include/ui/InputDispatcher.h
@@ -212,8 +212,15 @@
     int32_t ownerPid;
     int32_t ownerUid;
 
-    bool visibleFrameIntersects(const InputWindow* other) const;
     bool touchableAreaContainsPoint(int32_t x, int32_t y) const;
+    bool frameContainsPoint(int32_t x, int32_t y) const;
+
+    /* Returns true if the window is of a trusted type that is allowed to silently
+     * overlay other windows for the purpose of implementing the secure views feature.
+     * Trusted overlays, such as IME windows, can partly obscure other windows without causing
+     * motion events to be delivered to them with AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED.
+     */
+    bool isTrustedOverlay() const;
 };
 
 
@@ -973,7 +980,7 @@
     bool shouldPokeUserActivityForCurrentInputTargetsLocked();
     void pokeUserActivityLocked(nsecs_t eventTime, int32_t eventType);
     bool checkInjectionPermission(const InputWindow* window, const InjectionState* injectionState);
-    bool isWindowObscuredLocked(const InputWindow* window);
+    bool isWindowObscuredAtPointLocked(const InputWindow* window, int32_t x, int32_t y) const;
     bool isWindowFinishedWithPreviousInputLocked(const InputWindow* window);
     String8 getApplicationWindowLabelLocked(const InputApplication* application,
             const InputWindow* window);
diff --git a/libs/rs/java/tests/src/com/android/rs/test/primitives.rs b/libs/rs/java/tests/src/com/android/rs/test/primitives.rs
index 5312bcc..012af9c 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/primitives.rs
+++ b/libs/rs/java/tests/src/com/android/rs/test/primitives.rs
@@ -2,15 +2,21 @@
 
 #pragma rs export_func(primitives_test)
 
+#pragma rs export_var(floatTest, doubleTest, charTest, shortTest, intTest, longTest, longlongTest)
+
 // Testing primitive types
 static float floatTest = 1.99f;
 static double doubleTest = 2.05;
 static char charTest = -8;
 static short shortTest = -16;
 static int intTest = -32;
+static long longTest = 17179869184l; // 1 << 34
+static long long longlongTest = 68719476736l; // 1 << 36
+
 static uchar ucharTest = 8;
 static ushort ushortTest = 16;
 static uint uintTest = 32;
+static int64_t int64_tTest = -17179869184l; // - 1 << 34
 
 static bool test_primitive_types(uint32_t index) {
     bool failed = false;
@@ -21,9 +27,13 @@
     _RS_ASSERT(charTest == -8);
     _RS_ASSERT(shortTest == -16);
     _RS_ASSERT(intTest == -32);
+    _RS_ASSERT(longTest == 17179869184l);
+    _RS_ASSERT(longlongTest == 68719476736l);
+
     _RS_ASSERT(ucharTest == 8);
     _RS_ASSERT(ushortTest == 16);
     _RS_ASSERT(uintTest == 32);
+    _RS_ASSERT(int64_tTest == -17179869184l);
 
     float time = end(index);
 
diff --git a/libs/ui/InputDispatcher.cpp b/libs/ui/InputDispatcher.cpp
index a6f5a1b..75b2294 100644
--- a/libs/ui/InputDispatcher.cpp
+++ b/libs/ui/InputDispatcher.cpp
@@ -134,18 +134,21 @@
 
 // --- InputWindow ---
 
-bool InputWindow::visibleFrameIntersects(const InputWindow* other) const {
-    return visibleFrameRight > other->visibleFrameLeft
-        && visibleFrameLeft < other->visibleFrameRight
-        && visibleFrameBottom > other->visibleFrameTop
-        && visibleFrameTop < other->visibleFrameBottom;
-}
-
 bool InputWindow::touchableAreaContainsPoint(int32_t x, int32_t y) const {
     return x >= touchableAreaLeft && x <= touchableAreaRight
             && y >= touchableAreaTop && y <= touchableAreaBottom;
 }
 
+bool InputWindow::frameContainsPoint(int32_t x, int32_t y) const {
+    return x >= frameLeft && x <= frameRight
+            && y >= frameTop && y <= frameBottom;
+}
+
+bool InputWindow::isTrustedOverlay() const {
+    return layoutParamsType == TYPE_INPUT_METHOD
+            || layoutParamsType == TYPE_INPUT_METHOD_DIALOG;
+}
+
 
 // --- InputDispatcher ---
 
@@ -1053,8 +1056,12 @@
 
                 if (maskedAction == AMOTION_EVENT_ACTION_DOWN
                         && (flags & InputWindow::FLAG_WATCH_OUTSIDE_TOUCH)) {
-                    mTempTouchState.addOrUpdateWindow(window,
-                            InputTarget::FLAG_OUTSIDE, BitSet32(0));
+                    int32_t outsideTargetFlags = InputTarget::FLAG_OUTSIDE;
+                    if (isWindowObscuredAtPointLocked(window, x, y)) {
+                        outsideTargetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
+                    }
+
+                    mTempTouchState.addOrUpdateWindow(window, outsideTargetFlags, BitSet32(0));
                 }
             }
         }
@@ -1083,10 +1090,6 @@
             // (May be NULL which is why we put this code block before the next check.)
             newTouchedWindow = mTempTouchState.getFirstForegroundWindow();
         }
-        int32_t targetFlags = InputTarget::FLAG_FOREGROUND;
-        if (isSplit) {
-            targetFlags |= InputTarget::FLAG_SPLIT;
-        }
 
         // If we did not find a touched window then fail.
         if (! newTouchedWindow) {
@@ -1106,6 +1109,15 @@
             goto Failed;
         }
 
+        // Set target flags.
+        int32_t targetFlags = InputTarget::FLAG_FOREGROUND;
+        if (isSplit) {
+            targetFlags |= InputTarget::FLAG_SPLIT;
+        }
+        if (isWindowObscuredAtPointLocked(newTouchedWindow, x, y)) {
+            targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
+        }
+
         // Update the temporary touch state.
         BitSet32 pointerIds;
         if (isSplit) {
@@ -1186,23 +1198,13 @@
             for (size_t i = 0; i < mWindows.size(); i++) {
                 const InputWindow* window = & mWindows[i];
                 if (window->layoutParamsType == InputWindow::TYPE_WALLPAPER) {
-                    mTempTouchState.addOrUpdateWindow(window, 0, BitSet32(0));
+                    mTempTouchState.addOrUpdateWindow(window,
+                            InputTarget::FLAG_WINDOW_IS_OBSCURED, BitSet32(0));
                 }
             }
         }
     }
 
-    // If a touched window has been obscured at any point during the touch gesture, set
-    // the appropriate flag so we remember it for the entire gesture.
-    for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
-        TouchedWindow& touchedWindow = mTempTouchState.windows.editItemAt(i);
-        if ((touchedWindow.targetFlags & InputTarget::FLAG_WINDOW_IS_OBSCURED) == 0) {
-            if (isWindowObscuredLocked(touchedWindow.window)) {
-                touchedWindow.targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
-            }
-        }
-    }
-
     // Success!  Output targets.
     injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
 
@@ -1326,14 +1328,15 @@
     return true;
 }
 
-bool InputDispatcher::isWindowObscuredLocked(const InputWindow* window) {
+bool InputDispatcher::isWindowObscuredAtPointLocked(
+        const InputWindow* window, int32_t x, int32_t y) const {
     size_t numWindows = mWindows.size();
     for (size_t i = 0; i < numWindows; i++) {
         const InputWindow* other = & mWindows.itemAt(i);
         if (other == window) {
             break;
         }
-        if (other->visible && window->visibleFrameIntersects(other)) {
+        if (other->visible && ! other->isTrustedOverlay() && other->frameContainsPoint(x, y)) {
             return true;
         }
     }
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp
index b314114..5ff934d 100644
--- a/media/libstagefright/AudioPlayer.cpp
+++ b/media/libstagefright/AudioPlayer.cpp
@@ -55,7 +55,7 @@
 
 AudioPlayer::~AudioPlayer() {
     if (mStarted) {
-        stop();
+        reset();
     }
 }
 
@@ -165,13 +165,21 @@
     return OK;
 }
 
-void AudioPlayer::pause() {
+void AudioPlayer::pause(bool playPendingSamples) {
     CHECK(mStarted);
 
-    if (mAudioSink.get() != NULL) {
-        mAudioSink->pause();
+    if (playPendingSamples) {
+        if (mAudioSink.get() != NULL) {
+            mAudioSink->stop();
+        } else {
+            mAudioTrack->stop();
+        }
     } else {
-        mAudioTrack->stop();
+        if (mAudioSink.get() != NULL) {
+            mAudioSink->pause();
+        } else {
+            mAudioTrack->pause();
+        }
     }
 }
 
@@ -185,7 +193,7 @@
     }
 }
 
-void AudioPlayer::stop() {
+void AudioPlayer::reset() {
     CHECK(mStarted);
 
     if (mAudioSink.get() != NULL) {
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 31c03ad..4f5ff75 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -579,7 +579,7 @@
         notifyListener_l(
                 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, mStreamDoneStatus);
 
-        pause_l();
+        pause_l(true /* at eos */);
 
         mFlags |= AT_EOS;
         return;
@@ -603,7 +603,7 @@
         LOGV("MEDIA_PLAYBACK_COMPLETE");
         notifyListener_l(MEDIA_PLAYBACK_COMPLETE);
 
-        pause_l();
+        pause_l(true /* at eos */);
 
         mFlags |= AT_EOS;
     }
@@ -752,7 +752,7 @@
     return pause_l();
 }
 
-status_t AwesomePlayer::pause_l() {
+status_t AwesomePlayer::pause_l(bool at_eos) {
     if (!(mFlags & PLAYING)) {
         return OK;
     }
@@ -760,7 +760,14 @@
     cancelPlayerEvents(true /* keepBufferingGoing */);
 
     if (mAudioPlayer != NULL) {
-        mAudioPlayer->pause();
+        if (at_eos) {
+            // If we played the audio stream to completion we
+            // want to make sure that all samples remaining in the audio
+            // track's queue are played out.
+            mAudioPlayer->pause(true /* playPendingSamples */);
+        } else {
+            mAudioPlayer->pause();
+        }
     }
 
     mFlags &= ~PLAYING;
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 4d69dd3..a5341e3 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -1838,8 +1838,31 @@
 
         case OMX_EventPortSettingsChanged:
         {
+            CODEC_LOGV("OMX_EventPortSettingsChanged(port=%ld, data2=0x%08lx)",
+                       data1, data2);
+
             if (data2 == 0 || data2 == OMX_IndexParamPortDefinition) {
                 onPortSettingsChanged(data1);
+            } else if (data1 == kPortIndexOutput
+                    && data2 == OMX_IndexConfigCommonOutputCrop) {
+
+                OMX_CONFIG_RECTTYPE rect;
+                rect.nPortIndex = kPortIndexOutput;
+                InitOMXParams(&rect);
+
+                status_t err =
+                         mOMX->getConfig(
+                             mNode, OMX_IndexConfigCommonOutputCrop,
+                             &rect, sizeof(rect));
+
+                if (err == OK) {
+                    CODEC_LOGV(
+                            "output crop (%ld, %ld, %ld, %ld)",
+                            rect.nLeft, rect.nTop, rect.nWidth, rect.nHeight);
+                } else {
+                    CODEC_LOGE("getConfig(OMX_IndexConfigCommonOutputCrop) "
+                               "returned error 0x%08x", err);
+                }
             }
             break;
         }
diff --git a/media/libstagefright/colorconversion/SoftwareRenderer.cpp b/media/libstagefright/colorconversion/SoftwareRenderer.cpp
index c204a94..662a84a 100644
--- a/media/libstagefright/colorconversion/SoftwareRenderer.cpp
+++ b/media/libstagefright/colorconversion/SoftwareRenderer.cpp
@@ -48,6 +48,9 @@
     LOGI("display = %d x %d, decoded = %d x %d",
             mDisplayWidth, mDisplayHeight, mDecodedWidth, mDecodedHeight);
 
+    mDecodedWidth = mDisplayWidth;
+    mDecodedHeight = mDisplayHeight;
+
     int halFormat;
     switch (mColorFormat) {
 #if HAS_YCBCR420_SP_ADRENO
diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h
index db98253..e04a24d 100644
--- a/media/libstagefright/include/AwesomePlayer.h
+++ b/media/libstagefright/include/AwesomePlayer.h
@@ -223,7 +223,7 @@
     status_t setDataSource_l(const sp<MediaExtractor> &extractor);
     void reset_l();
     status_t seekTo_l(int64_t timeUs);
-    status_t pause_l();
+    status_t pause_l(bool at_eos = false);
     void initRenderer_l();
     void notifyVideoSize_l();
     void seekAudioIfNecessary_l();
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index c25df1d..24c9443 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -1504,7 +1504,11 @@
         sendCloseSystemWindows();
         Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        getContext().startActivity(intent);
+        try {
+            getContext().startActivity(intent);
+        } catch (ActivityNotFoundException e) {
+            Log.w(TAG, "No activity found for android.intent.action.CALL_BUTTON.");
+        }
     }
 
     @Override
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 8527059..cd9b07e 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1715,7 +1715,7 @@
         // The first time a track is added we wait
         // for all its buffers to be filled before processing it
         mAudioMixer->setActiveTrack(track->name());
-        if (cblk->framesReady() && (track->isReady() || track->isStopped()) &&
+        if (cblk->framesReady() && track->isReady() &&
                 !track->isPaused() && !track->isTerminated())
         {
             //LOGV("track %d u=%08x, s=%08x [OK] on thread %p", track->name(), cblk->user, cblk->server, this);
@@ -2231,7 +2231,7 @@
 
                 // The first time a track is added we wait
                 // for all its buffers to be filled before processing it
-                if (cblk->framesReady() && (track->isReady() || track->isStopped()) &&
+                if (cblk->framesReady() && track->isReady() &&
                         !track->isPaused() && !track->isTerminated())
                 {
                     //LOGV("track %d u=%08x, s=%08x [OK]", track->name(), cblk->user, cblk->server);
@@ -3039,7 +3039,7 @@
 }
 
 bool AudioFlinger::PlaybackThread::Track::isReady() const {
-    if (mFillingUpStatus != FS_FILLING) return true;
+    if (mFillingUpStatus != FS_FILLING || isStopped() || isPausing()) return true;
 
     if (mCblk->framesReady() >= mCblk->frameCount ||
             (mCblk->flags & CBLK_FORCEREADY_MSK)) {
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java
index e6c32d9..a8ccfc0 100644
--- a/services/java/com/android/server/BatteryService.java
+++ b/services/java/com/android/server/BatteryService.java
@@ -99,6 +99,7 @@
     private int mBatteryTemperature;
     private String mBatteryTechnology;
     private boolean mBatteryLevelCritical;
+    private boolean mInvalidCharger;
 
     private int mLastBatteryStatus;
     private int mLastBatteryHealth;
@@ -107,6 +108,7 @@
     private int mLastBatteryVoltage;
     private int mLastBatteryTemperature;
     private boolean mLastBatteryLevelCritical;
+    private boolean mLastInvalidCharger;
 
     private int mLowBatteryWarningLevel;
     private int mLowBatteryCloseWarningLevel;
@@ -128,7 +130,12 @@
         mLowBatteryCloseWarningLevel = mContext.getResources().getInteger(
                 com.android.internal.R.integer.config_lowBatteryCloseWarningLevel);
 
-        mUEventObserver.startObserving("SUBSYSTEM=power_supply");
+        mPowerSupplyObserver.startObserving("SUBSYSTEM=power_supply");
+
+        // watch for invalid charger messages if the invalid_charger switch exists
+        if (new File("/sys/devices/virtual/switch/invalid_charger/state").exists()) {
+            mInvalidChargerObserver.startObserving("DEVPATH=/devices/virtual/switch/invalid_charger");
+        }
 
         // set initial status
         update();
@@ -162,13 +169,24 @@
         return mPlugType;
     }
 
-    private UEventObserver mUEventObserver = new UEventObserver() {
+    private UEventObserver mPowerSupplyObserver = new UEventObserver() {
         @Override
         public void onUEvent(UEventObserver.UEvent event) {
             update();
         }
     };
 
+    private UEventObserver mInvalidChargerObserver = new UEventObserver() {
+        @Override
+        public void onUEvent(UEventObserver.UEvent event) {
+            boolean invalidCharger = "1".equals(event.get("SWITCH_STATE"));
+            if (mInvalidCharger != invalidCharger) {
+                mInvalidCharger = invalidCharger;
+                update();
+            }
+        }
+    };
+
     // returns battery level as a percentage
     final int getBatteryLevel() {
         return mBatteryLevel;
@@ -237,7 +255,8 @@
                 mBatteryLevel != mLastBatteryLevel ||
                 mPlugType != mLastPlugType ||
                 mBatteryVoltage != mLastBatteryVoltage ||
-                mBatteryTemperature != mLastBatteryTemperature) {
+                mBatteryTemperature != mLastBatteryTemperature ||
+                mInvalidCharger != mLastInvalidCharger) {
 
             if (mPlugType != mLastPlugType) {
                 if (mLastPlugType == BATTERY_PLUGGED_NONE) {
@@ -334,6 +353,7 @@
             mLastBatteryVoltage = mBatteryVoltage;
             mLastBatteryTemperature = mBatteryTemperature;
             mLastBatteryLevelCritical = mBatteryLevelCritical;
+            mLastInvalidCharger = mInvalidCharger;
         }
     }
 
@@ -355,6 +375,7 @@
         intent.putExtra(BatteryManager.EXTRA_VOLTAGE, mBatteryVoltage);
         intent.putExtra(BatteryManager.EXTRA_TEMPERATURE, mBatteryTemperature);
         intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mBatteryTechnology);
+        intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger);
 
         if (false) {
             Slog.d(TAG, "updateBattery level:" + mBatteryLevel +
@@ -364,7 +385,7 @@
                     " temperature: " + mBatteryTemperature +
                     " technology: " + mBatteryTechnology +
                     " AC powered:" + mAcOnline + " USB powered:" + mUsbOnline +
-                    " icon:" + icon );
+                    " icon:" + icon  + " invalid charger:" + mInvalidCharger);
         }
 
         ActivityManagerNative.broadcastStickyIntent(intent, null);
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index 9a5423c..dc4194c 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -25,6 +25,7 @@
 import com.android.internal.view.IInputMethodManager;
 import com.android.internal.view.IInputMethodSession;
 import com.android.internal.view.InputBindResult;
+import com.android.internal.view.InputMethodAndSubtypeEnabler;
 
 import com.android.server.StatusBarManagerService;
 
@@ -97,6 +98,7 @@
 
     static final int MSG_SHOW_IM_PICKER = 1;
     static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2;
+    static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3;
 
     static final int MSG_UNBIND_INPUT = 1000;
     static final int MSG_BIND_INPUT = 1010;
@@ -1225,7 +1227,7 @@
         synchronized (mMethodMap) {
             if (mCurClient == null || client == null
                     || mCurClient.client.asBinder() != client.asBinder()) {
-                Slog.w(TAG, "Ignoring showInputMethodDialogFromClient of uid "
+                Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
                         + Binder.getCallingUid() + ": " + client);
             }
 
@@ -1237,13 +1239,26 @@
         synchronized (mMethodMap) {
             if (mCurClient == null || client == null
                     || mCurClient.client.asBinder() != client.asBinder()) {
-                Slog.w(TAG, "Ignoring showInputSubtypeMethodDialogFromClient of: " + client);
+                Slog.w(TAG, "Ignoring showInputMethodSubtypePickerFromClient of: " + client);
             }
 
             mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER);
         }
     }
 
+    public void showInputMethodAndSubtypeEnablerFromClient(
+            IInputMethodClient client, String topId) {
+        // TODO: Handle topId for setting the top position of the list activity
+        synchronized (mMethodMap) {
+            if (mCurClient == null || client == null
+                    || mCurClient.client.asBinder() != client.asBinder()) {
+                Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client);
+            }
+
+            mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_ENABLER);
+        }
+    }
+
     public void setInputMethod(IBinder token, String id) {
         setInputMethodWithSubtype(token, id, NOT_A_SUBTYPE_ID);
     }
@@ -1336,6 +1351,10 @@
                 showInputMethodSubtypeMenu();
                 return true;
 
+            case MSG_SHOW_IM_SUBTYPE_ENABLER:
+                showInputMethodAndSubtypeEnabler();
+                return true;
+
             // ---------------------------------------------------------
 
             case MSG_UNBIND_INPUT:
@@ -1528,6 +1547,14 @@
         showInputMethodMenuInternal(true);
     }
 
+    private void showInputMethodAndSubtypeEnabler() {
+        Intent intent = new Intent();
+        intent.setClassName("android", InputMethodAndSubtypeEnabler.class.getCanonicalName());
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+        mContext.startActivity(intent);
+    }
+
     private void showInputMethodMenuInternal(boolean showSubtypes) {
         if (DEBUG) Slog.v(TAG, "Show switching menu");
 
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index c4d2d4d..bcf1b96 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -140,7 +140,6 @@
     private static final boolean DEBUG_PREFERRED = false;
     private static final boolean DEBUG_UPGRADE = false;
     private static final boolean DEBUG_INSTALL = false;
-    private static final boolean DEBUG_NATIVE = false;
 
     private static final boolean MULTIPLE_APPLICATION_UIDS = true;
     private static final int RADIO_UID = Process.PHONE_UID;
@@ -3241,8 +3240,6 @@
                 }
             }
 
-            pkg.applicationInfo.nativeLibraryDir = pkgSetting.nativeLibraryPathString;
-
             /*
              * Set the data dir to the default "/data/data/<package name>/lib"
              * if we got here without anyone telling us different (e.g., apps
@@ -3252,10 +3249,14 @@
              * This happens during an upgrade from a package settings file that
              * doesn't have a native library path attribute at all.
              */
-            if (pkgSetting.nativeLibraryPathString == null && pkg.applicationInfo.dataDir != null) {
-                final String nativeLibraryPath = new File(dataPath, LIB_DIR_NAME).getPath();
-                pkg.applicationInfo.nativeLibraryDir = nativeLibraryPath;
-                pkgSetting.nativeLibraryPathString = nativeLibraryPath;
+            if (pkg.applicationInfo.nativeLibraryDir == null && pkg.applicationInfo.dataDir != null) {
+                if (pkgSetting.nativeLibraryPathString == null) {
+                    final String nativeLibraryPath = new File(dataPath, LIB_DIR_NAME).getPath();
+                    pkg.applicationInfo.nativeLibraryDir = nativeLibraryPath;
+                    pkgSetting.nativeLibraryPathString = nativeLibraryPath;
+                } else {
+                    pkg.applicationInfo.nativeLibraryDir = pkgSetting.nativeLibraryPathString;
+                }
             }
 
             pkgSetting.uidError = uidError;
@@ -3274,10 +3275,23 @@
              *        In other words, we're going to unpack the binaries
              *        only for non-system apps and system app upgrades.
              */
-            if ((!isSystemApp(pkg) || isUpdatedSystemApp(pkg)) && !isExternal(pkg)) {
-                Log.i(TAG, path + " changed; unpacking");
-                File sharedLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir);
-                NativeLibraryHelper.copyNativeBinariesLI(scanFile, sharedLibraryDir);
+            if (pkg.applicationInfo.nativeLibraryDir != null) {
+                final File sharedLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir);
+                if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) {
+                    /*
+                     * Upgrading from a previous version of the OS sometimes
+                     * leaves native libraries in the /data/data/<app>/lib
+                     * directory for system apps even when they shouldn't be.
+                     * Recent changes in the JNI library search path
+                     * necessitates we remove those to match previous behavior.
+                     */
+                    if (NativeLibraryHelper.removeNativeBinariesFromDirLI(sharedLibraryDir)) {
+                        Log.i(TAG, "removed obsolete native libraries for system package " + path);
+                    }
+                } else if (!isExternal(pkg)) {
+                    Log.i(TAG, path + " changed; unpacking");
+                    NativeLibraryHelper.copyNativeBinariesLI(scanFile, sharedLibraryDir);
+                }
             }
             pkg.mScanPath = path;
 
@@ -8051,7 +8065,7 @@
             if (p != null) {
                 if (!p.codePath.equals(codePath)) {
                     // Check to see if its a disabled system app
-                    if((p != null) && ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0)) {
+                    if ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                         // This is an updated system app with versions in both system
                         // and data partition. Just let the most recent version
                         // take precedence.
@@ -8062,6 +8076,13 @@
                         // let's log a message about it.
                         Slog.i(TAG, "Package " + name + " codePath changed from " + p.codePath
                                 + " to " + codePath + "; Retaining data and using new");
+                        /*
+                         * Since we've changed paths, we need to prefer the new
+                         * native library path over the one stored in the
+                         * package settings since we might have moved from
+                         * internal to external storage or vice versa.
+                         */
+                        p.nativeLibraryPathString = nativeLibraryPathString;
                     }
                 }
                 if (p.sharedUser != sharedUser) {
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 29a9a7e..5386a1a4 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -220,6 +220,7 @@
     private Sensor mLightSensor;
     private boolean mLightSensorEnabled;
     private float mLightSensorValue = -1;
+    private boolean mProxIgnoredBecauseScreenTurnedOff = false;
     private int mHighestLightSensorValue = -1;
     private float mLightSensorPendingValue = -1;
     private int mLightSensorScreenBrightness = -1;
@@ -252,7 +253,7 @@
 
     // could be either static or controllable at runtime
     private static final boolean mSpew = false;
-    private static final boolean mDebugProximitySensor = (true || mSpew);
+    private static final boolean mDebugProximitySensor = (false || mSpew);
     private static final boolean mDebugLightSensor = (false || mSpew);
     
     private native void nativeInit();
@@ -638,7 +639,8 @@
         int n = flags & LOCK_MASK;
         return n == PowerManager.FULL_WAKE_LOCK
                 || n == PowerManager.SCREEN_BRIGHT_WAKE_LOCK
-                || n == PowerManager.SCREEN_DIM_WAKE_LOCK;
+                || n == PowerManager.SCREEN_DIM_WAKE_LOCK
+                || n == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK;
     }
 
     void enforceWakeSourcePermission(int uid, int pid) {
@@ -778,25 +780,33 @@
             // set it to whatever they want.  otherwise, we modulate that
             // by the current state so we never turn it more on than
             // it already is.
-            if ((wl.flags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0) {
-                int oldWakeLockState = mWakeLockState;
-                mWakeLockState = mLocks.reactivateScreenLocksLocked();
-                if (mSpew) {
-                    Slog.d(TAG, "wakeup here mUserState=0x" + Integer.toHexString(mUserState)
-                            + " mWakeLockState=0x"
-                            + Integer.toHexString(mWakeLockState)
-                            + " previous wakeLockState=0x" + Integer.toHexString(oldWakeLockState));
+            if ((flags & LOCK_MASK) == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) {
+                mProximityWakeLockCount++;
+                if (mProximityWakeLockCount == 1) {
+                    enableProximityLockLocked();
                 }
             } else {
-                if (mSpew) {
-                    Slog.d(TAG, "here mUserState=0x" + Integer.toHexString(mUserState)
-                            + " mLocks.gatherState()=0x"
-                            + Integer.toHexString(mLocks.gatherState())
-                            + " mWakeLockState=0x" + Integer.toHexString(mWakeLockState));
+                if ((wl.flags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0) {
+                    int oldWakeLockState = mWakeLockState;
+                    mWakeLockState = mLocks.reactivateScreenLocksLocked();
+                    if (mSpew) {
+                        Slog.d(TAG, "wakeup here mUserState=0x" + Integer.toHexString(mUserState)
+                                + " mWakeLockState=0x"
+                                + Integer.toHexString(mWakeLockState)
+                                + " previous wakeLockState=0x"
+                                + Integer.toHexString(oldWakeLockState));
+                    }
+                } else {
+                    if (mSpew) {
+                        Slog.d(TAG, "here mUserState=0x" + Integer.toHexString(mUserState)
+                                + " mLocks.gatherState()=0x"
+                                + Integer.toHexString(mLocks.gatherState())
+                                + " mWakeLockState=0x" + Integer.toHexString(mWakeLockState));
+                    }
+                    mWakeLockState = (mUserState | mWakeLockState) & mLocks.gatherState();
                 }
-                mWakeLockState = (mUserState | mWakeLockState) & mLocks.gatherState();
+                setPowerState(mWakeLockState | mUserState);
             }
-            setPowerState(mWakeLockState | mUserState);
         }
         else if ((flags & LOCK_MASK) == PowerManager.PARTIAL_WAKE_LOCK) {
             if (newlock) {
@@ -806,11 +816,6 @@
                 }
             }
             Power.acquireWakeLock(Power.PARTIAL_WAKE_LOCK,PARTIAL_NAME);
-        } else if ((flags & LOCK_MASK) == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) {
-            mProximityWakeLockCount++;
-            if (mProximityWakeLockCount == 1) {
-                enableProximityLockLocked();
-            }
         }
 
         if (diffsource) {
@@ -868,12 +873,27 @@
         }
 
         if (isScreenLock(wl.flags)) {
-            mWakeLockState = mLocks.gatherState();
-            // goes in the middle to reduce flicker
-            if ((wl.flags & PowerManager.ON_AFTER_RELEASE) != 0) {
-                userActivity(SystemClock.uptimeMillis(), -1, false, OTHER_EVENT, false);
+            if ((wl.flags & LOCK_MASK) == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) {
+                mProximityWakeLockCount--;
+                if (mProximityWakeLockCount == 0) {
+                    if (mProximitySensorActive &&
+                            ((flags & PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE) != 0)) {
+                        // wait for proximity sensor to go negative before disabling sensor
+                        if (mDebugProximitySensor) {
+                            Slog.d(TAG, "waiting for proximity sensor to go negative");
+                        }
+                    } else {
+                        disableProximityLockLocked();
+                    }
+                }
+            } else {
+                mWakeLockState = mLocks.gatherState();
+                // goes in the middle to reduce flicker
+                if ((wl.flags & PowerManager.ON_AFTER_RELEASE) != 0) {
+                    userActivity(SystemClock.uptimeMillis(), -1, false, OTHER_EVENT, false);
+                }
+                setPowerState(mWakeLockState | mUserState);
             }
-            setPowerState(mWakeLockState | mUserState);
         }
         else if ((wl.flags & LOCK_MASK) == PowerManager.PARTIAL_WAKE_LOCK) {
             mPartialCount--;
@@ -881,19 +901,6 @@
                 if (LOG_PARTIAL_WL) EventLog.writeEvent(EventLogTags.POWER_PARTIAL_WAKE_STATE, 0, wl.tag);
                 Power.releaseWakeLock(PARTIAL_NAME);
             }
-        } else if ((wl.flags & LOCK_MASK) == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) {
-            mProximityWakeLockCount--;
-            if (mProximityWakeLockCount == 0) {
-                if (mProximitySensorActive &&
-                        ((flags & PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE) != 0)) {
-                    // wait for proximity sensor to go negative before disabling sensor
-                    if (mDebugProximitySensor) {
-                        Slog.d(TAG, "waiting for proximity sensor to go negative");
-                    }
-                } else {
-                    disableProximityLockLocked();
-                }
-            }
         }
         // Unlink the lock from the binder.
         wl.binder.unlinkToDeath(wl, 0);
@@ -2433,11 +2440,23 @@
             mWakeLockState = SCREEN_OFF;
             int N = mLocks.size();
             int numCleared = 0;
+            boolean proxLock = false;
             for (int i=0; i<N; i++) {
                 WakeLock wl = mLocks.get(i);
                 if (isScreenLock(wl.flags)) {
-                    mLocks.get(i).activated = false;
-                    numCleared++;
+                    if (((wl.flags & LOCK_MASK) == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)
+                            && reason == WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR) {
+                        proxLock = true;
+                    } else {
+                        mLocks.get(i).activated = false;
+                        numCleared++;
+                    }
+                }
+            }
+            if (!proxLock) {
+                mProxIgnoredBecauseScreenTurnedOff = true;
+                if (mDebugProximitySensor) {
+                    Slog.d(TAG, "setting mProxIgnoredBecauseScreenTurnedOff");
                 }
             }
             EventLog.writeEvent(EventLogTags.POWER_SLEEP_REQUESTED, numCleared);
@@ -2629,6 +2648,11 @@
                     result |= wl.minState;
                 }
             }
+            if (mDebugProximitySensor) {
+                Slog.d(TAG, "reactivateScreenLocksLocked mProxIgnoredBecauseScreenTurnedOff="
+                        + mProxIgnoredBecauseScreenTurnedOff);
+            }
+            mProxIgnoredBecauseScreenTurnedOff = false;
             return result;
         }
     }
@@ -2788,7 +2812,13 @@
             }
             if (mProximitySensorActive) {
                 mProximitySensorActive = false;
-                forceUserActivityLocked();
+                if (mDebugProximitySensor) {
+                    Slog.d(TAG, "disableProximityLockLocked mProxIgnoredBecauseScreenTurnedOff="
+                            + mProxIgnoredBecauseScreenTurnedOff);
+                }
+                if (!mProxIgnoredBecauseScreenTurnedOff) {
+                    forceUserActivityLocked();
+                }
             }
         }
     }
@@ -2802,15 +2832,27 @@
             return;
         }
         if (active) {
-            goToSleepLocked(SystemClock.uptimeMillis(),
-                    WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR);
+            if (mDebugProximitySensor) {
+                Slog.d(TAG, "b mProxIgnoredBecauseScreenTurnedOff="
+                        + mProxIgnoredBecauseScreenTurnedOff);
+            }
+            if (!mProxIgnoredBecauseScreenTurnedOff) {
+                goToSleepLocked(SystemClock.uptimeMillis(),
+                        WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR);
+            }
             mProximitySensorActive = true;
         } else {
             // proximity sensor negative events trigger as user activity.
             // temporarily set mUserActivityAllowed to true so this will work
             // even when the keyguard is on.
             mProximitySensorActive = false;
-            forceUserActivityLocked();
+            if (mDebugProximitySensor) {
+                Slog.d(TAG, "b mProxIgnoredBecauseScreenTurnedOff="
+                        + mProxIgnoredBecauseScreenTurnedOff);
+            }
+            if (!mProxIgnoredBecauseScreenTurnedOff) {
+                forceUserActivityLocked();
+            }
 
             if (mProximityWakeLockCount == 0) {
                 // disable sensor if we have no listeners left after proximity negative
diff --git a/services/java/com/android/server/location/GpsLocationProvider.java b/services/java/com/android/server/location/GpsLocationProvider.java
index 39ce0b6..e9eb4f0 100755
--- a/services/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/java/com/android/server/location/GpsLocationProvider.java
@@ -46,6 +46,10 @@
 import android.os.SystemClock;
 import android.os.WorkSource;
 import android.provider.Settings;
+import android.provider.Telephony.Sms.Intents;
+import android.telephony.TelephonyManager;
+import android.telephony.gsm.GsmCellLocation;
+import android.telephony.SmsMessage;
 import android.util.Log;
 import android.util.SparseIntArray;
 
@@ -53,6 +57,9 @@
 import com.android.internal.telephony.Phone;
 import com.android.internal.location.GpsNetInitiatedHandler;
 import com.android.internal.location.GpsNetInitiatedHandler.GpsNiNotification;
+import com.android.internal.telephony.GsmAlphabet;
+import com.android.internal.telephony.SmsHeader;
+import com.android.internal.util.HexDump;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -153,6 +160,24 @@
     private static final int REMOVE_LISTENER = 9;
     private static final int REQUEST_SINGLE_SHOT = 10;
 
+    // Request setid
+    private static final int AGPS_RIL_REQUEST_SETID_IMSI = 1;
+    private static final int AGPS_RIL_REQUEST_SETID_MSISDN = 2;
+
+    // Request ref location
+    private static final int AGPS_RIL_REQUEST_REFLOC_CELLID = 1;
+    private static final int AGPS_RIL_REQUEST_REFLOC_MAC = 2;
+
+    // ref. location info
+    private static final int AGPS_REF_LOCATION_TYPE_GSM_CELLID = 1;
+    private static final int AGPS_REF_LOCATION_TYPE_UMTS_CELLID = 2;
+    private static final int AGPS_REG_LOCATION_TYPE_MAC        = 3;
+
+    // set id info
+    private static final int AGPS_SETID_TYPE_NONE = 0;
+    private static final int AGPS_SETID_TYPE_IMSI = 1;
+    private static final int AGPS_SETID_TYPE_MSISDN = 2;
+
     private static final String PROPERTIES_FILE = "/etc/gps.conf";
 
     private int mLocationFlags = LOCATION_INVALID;
@@ -328,10 +353,27 @@
             } else if (action.equals(ALARM_TIMEOUT)) {
                 if (DEBUG) Log.d(TAG, "ALARM_TIMEOUT");
                 hibernate();
-            }
+            } else if (action.equals(Intents.DATA_SMS_RECEIVED_ACTION)) {
+                checkSmsSuplInit(intent);
+            } else if (action.equals(Intents.WAP_PUSH_RECEIVED_ACTION)) {
+                checkWapSuplInit(intent);
+             }
         }
     };
 
+    private void checkSmsSuplInit(Intent intent) {
+        SmsMessage[] messages = Intents.getMessagesFromIntent(intent);
+        for (int i=0; i <messages.length; i++) {
+            byte[] supl_init = messages[i].getUserData();
+            native_agps_ni_message(supl_init,supl_init.length);
+        }
+    }
+
+    private void checkWapSuplInit(Intent intent) {
+        byte[] supl_init = (byte[]) intent.getExtra("data");
+        native_agps_ni_message(supl_init,supl_init.length);
+    }
+
     public static boolean isSupported() {
         return native_is_supported();
     }
@@ -352,6 +394,21 @@
         mWakeupIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_WAKEUP), 0);
         mTimeoutIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_TIMEOUT), 0);
 
+        IntentFilter intentFilter = new IntentFilter();
+        intentFilter.addAction(Intents.DATA_SMS_RECEIVED_ACTION);
+        intentFilter.addDataScheme("sms");
+        intentFilter.addDataAuthority("localhost","7275");
+        context.registerReceiver(mBroadcastReciever, intentFilter);
+
+        intentFilter = new IntentFilter();
+        intentFilter.addAction(Intents.WAP_PUSH_RECEIVED_ACTION);
+        try {
+            intentFilter.addDataType("application/vnd.omaloc-supl-init");
+        } catch (IntentFilter.MalformedMimeTypeException e) {
+            Log.w(TAG, "Malformed SUPL init mime type");
+        }
+        context.registerReceiver(mBroadcastReciever, intentFilter);
+
         mConnMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
 
         // Battery statistics service to be notified when GPS turns on or off
@@ -1255,22 +1312,20 @@
 
     //=============================================================
     // NI Client support
-	//=============================================================
+    //=============================================================
     private final INetInitiatedListener mNetInitiatedListener = new INetInitiatedListener.Stub() {
-    	// Sends a response for an NI reqeust to HAL.
-    	public boolean sendNiResponse(int notificationId, int userResponse)
-    	{
-        	// TODO Add Permission check
-    		
-    		StringBuilder extrasBuf = new StringBuilder();
+        // Sends a response for an NI reqeust to HAL.
+        public boolean sendNiResponse(int notificationId, int userResponse)
+        {
+            // TODO Add Permission check
 
-    		if (DEBUG) Log.d(TAG, "sendNiResponse, notifId: " + notificationId +
-    				", response: " + userResponse);
-    		
-    		native_send_ni_response(notificationId, userResponse);
-    		
-    		return true;
-    	}        
+            StringBuilder extrasBuf = new StringBuilder();
+
+            if (DEBUG) Log.d(TAG, "sendNiResponse, notifId: " + notificationId +
+                    ", response: " + userResponse);
+            native_send_ni_response(notificationId, userResponse);
+            return true;
+        }
     };
         
     public INetInitiatedListener getNetInitiatedListener() {
@@ -1278,70 +1333,132 @@
     }
 
     // Called by JNI function to report an NI request.
-	@SuppressWarnings("deprecation")
-	public void reportNiNotification(
-        	int notificationId,
-        	int niType,
-        	int notifyFlags,
-        	int timeout,
-        	int defaultResponse,
-        	String requestorId,
-        	String text,
-        	int requestorIdEncoding,
-        	int textEncoding,
-        	String extras  // Encoded extra data
+    public void reportNiNotification(
+            int notificationId,
+            int niType,
+            int notifyFlags,
+            int timeout,
+            int defaultResponse,
+            String requestorId,
+            String text,
+            int requestorIdEncoding,
+            int textEncoding,
+            String extras  // Encoded extra data
         )
-	{
-		Log.i(TAG, "reportNiNotification: entered");
-		Log.i(TAG, "notificationId: " + notificationId +
-				", niType: " + niType +
-				", notifyFlags: " + notifyFlags +
-				", timeout: " + timeout +
-				", defaultResponse: " + defaultResponse);
-		
-		Log.i(TAG, "requestorId: " + requestorId +
-				", text: " + text +
-				", requestorIdEncoding: " + requestorIdEncoding +
-				", textEncoding: " + textEncoding);
-		
-		GpsNiNotification notification = new GpsNiNotification();
-		
-		notification.notificationId = notificationId;
-		notification.niType = niType;
-		notification.needNotify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_NOTIFY) != 0;
-		notification.needVerify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_VERIFY) != 0;
-		notification.privacyOverride = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_PRIVACY_OVERRIDE) != 0;
-		notification.timeout = timeout;
-		notification.defaultResponse = defaultResponse;
-		notification.requestorId = requestorId;
-		notification.text = text;
-		notification.requestorIdEncoding = requestorIdEncoding;
-		notification.textEncoding = textEncoding;
-		
-		// Process extras, assuming the format is
-		// one of more lines of "key = value"
-		Bundle bundle = new Bundle();
-		
-		if (extras == null) extras = "";
-		Properties extraProp = new Properties();
-		
-		try {
-			extraProp.load(new StringBufferInputStream(extras));
-		}
-		catch (IOException e)
-		{
-			Log.e(TAG, "reportNiNotification cannot parse extras data: " + extras);
-		}
-		
-		for (Entry<Object, Object> ent : extraProp.entrySet())
-		{
-			bundle.putString((String) ent.getKey(), (String) ent.getValue());
-		}		
-		
-		notification.extras = bundle;
-		
-		mNIHandler.handleNiNotification(notification);		
-	}
+    {
+        Log.i(TAG, "reportNiNotification: entered");
+        Log.i(TAG, "notificationId: " + notificationId +
+                ", niType: " + niType +
+                ", notifyFlags: " + notifyFlags +
+                ", timeout: " + timeout +
+                ", defaultResponse: " + defaultResponse);
+
+        Log.i(TAG, "requestorId: " + requestorId +
+                ", text: " + text +
+                ", requestorIdEncoding: " + requestorIdEncoding +
+                ", textEncoding: " + textEncoding);
+
+        GpsNiNotification notification = new GpsNiNotification();
+
+        notification.notificationId = notificationId;
+        notification.niType = niType;
+        notification.needNotify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_NOTIFY) != 0;
+        notification.needVerify = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_NEED_VERIFY) != 0;
+        notification.privacyOverride = (notifyFlags & GpsNetInitiatedHandler.GPS_NI_PRIVACY_OVERRIDE) != 0;
+        notification.timeout = timeout;
+        notification.defaultResponse = defaultResponse;
+        notification.requestorId = requestorId;
+        notification.text = text;
+        notification.requestorIdEncoding = requestorIdEncoding;
+        notification.textEncoding = textEncoding;
+
+        // Process extras, assuming the format is
+        // one of more lines of "key = value"
+        Bundle bundle = new Bundle();
+
+        if (extras == null) extras = "";
+        Properties extraProp = new Properties();
+
+        try {
+            extraProp.load(new StringBufferInputStream(extras));
+        }
+        catch (IOException e)
+        {
+            Log.e(TAG, "reportNiNotification cannot parse extras data: " + extras);
+        }
+
+        for (Entry<Object, Object> ent : extraProp.entrySet())
+        {
+            bundle.putString((String) ent.getKey(), (String) ent.getValue());
+        }
+
+        notification.extras = bundle;
+
+        mNIHandler.handleNiNotification(notification);
+    }
+
+    /**
+     * Called from native code to request set id info.
+     * We should be careful about receiving null string from the TelephonyManager,
+     * because sending null String to JNI function would cause a crash.
+     */
+
+    private void requestSetID(int flags) {
+        TelephonyManager phone = (TelephonyManager)
+                mContext.getSystemService(Context.TELEPHONY_SERVICE);
+        int    type = AGPS_SETID_TYPE_NONE;
+        String data = "";
+
+        if ((flags & AGPS_RIL_REQUEST_SETID_IMSI) == AGPS_RIL_REQUEST_SETID_IMSI) {
+            String data_temp = phone.getSubscriberId();
+            if (data_temp == null) {
+                // This means the framework does not have the SIM card ready.
+            } else {
+                // This means the framework has the SIM card.
+                data = data_temp;
+                type = AGPS_SETID_TYPE_IMSI;
+            }
+        }
+        else if ((flags & AGPS_RIL_REQUEST_SETID_MSISDN) == AGPS_RIL_REQUEST_SETID_MSISDN) {
+            String data_temp = phone.getLine1Number();
+            if (data_temp == null) {
+                // This means the framework does not have the SIM card ready.
+            } else {
+                // This means the framework has the SIM card.
+                data = data_temp;
+                type = AGPS_SETID_TYPE_MSISDN;
+            }
+        }
+        native_agps_set_id(type, data);
+    }
+
+    /**
+     * Called from native code to request reference location info
+     */
+
+    private void requestRefLocation(int flags) {
+        TelephonyManager phone = (TelephonyManager)
+                mContext.getSystemService(Context.TELEPHONY_SERVICE);
+        if (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
+            GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
+            if ((gsm_cell != null) && (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
+                    && (phone.getNetworkOperator().length() > 3)) {
+                int type;
+                int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0,3));
+                int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
+                if (phone.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS)
+                    type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
+                else
+                    type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
+                native_agps_set_ref_location_cellid(type, mcc, mnc,
+                        gsm_cell.getLac(), gsm_cell.getCid());
+            }
+            else
+                Log.e(TAG,"Error getting cell location info.");
+        }
+        else
+            Log.e(TAG,"CDMA not supported.");
+    }
 
     private void sendMessage(int message, int arg, Object obj) {
         // hold a wake lock while messages are pending
@@ -1472,8 +1589,14 @@
     private native void native_agps_data_conn_open(String apn);
     private native void native_agps_data_conn_closed();
     private native void native_agps_data_conn_failed();
+    private native void native_agps_ni_message(byte [] msg, int length);
     private native void native_set_agps_server(int type, String hostname, int port);
 
     // Network-initiated (NI) Support
     private native void native_send_ni_response(int notificationId, int userResponse);
+
+    // AGPS ril suport
+    private native void native_agps_set_ref_location_cellid(int type, int mcc, int mnc,
+            int lac, int cid);
+    private native void native_agps_set_id(int type, String setid);
 }
diff --git a/services/jni/com_android_server_location_GpsLocationProvider.cpp b/services/jni/com_android_server_location_GpsLocationProvider.cpp
index 93068e6..71c7aba 100755
--- a/services/jni/com_android_server_location_GpsLocationProvider.cpp
+++ b/services/jni/com_android_server_location_GpsLocationProvider.cpp
@@ -40,12 +40,15 @@
 static jmethodID method_setEngineCapabilities;
 static jmethodID method_xtraDownloadRequest;
 static jmethodID method_reportNiNotification;
+static jmethodID method_requestRefLocation;
+static jmethodID method_requestSetID;
 
 static const GpsInterface* sGpsInterface = NULL;
 static const GpsXtraInterface* sGpsXtraInterface = NULL;
 static const AGpsInterface* sAGpsInterface = NULL;
 static const GpsNiInterface* sGpsNiInterface = NULL;
 static const GpsDebugInterface* sGpsDebugInterface = NULL;
+static const AGpsRilInterface* sAGpsRilInterface = NULL;
 
 // temporary storage for GPS callbacks
 static GpsSvStatus  sGpsSvStatus;
@@ -193,17 +196,30 @@
     create_thread_callback,
 };
 
-static void android_location_GpsLocationProvider_class_init_native(JNIEnv* env, jclass clazz) {
-    method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V");
-    method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V");
-    method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V");
-    method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(II)V");
-    method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V");
-    method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V");
-    method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V");
-    method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V");
+static void agps_request_set_id(uint32_t flags)
+{
+    LOGD("agps_request_set_id: flags (%d)", flags);
+
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_requestSetID, flags);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
 }
 
+static void agps_request_ref_location(uint32_t flags)
+{
+    LOGD("agps_ref_location: flags (%d)", flags);
+
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_requestRefLocation, flags);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+AGpsRilCallbacks sAGpsRilCallbacks = {
+    agps_request_set_id,
+    agps_request_ref_location,
+    create_thread_callback,
+};
+
 static const GpsInterface* get_gps_interface() {
     int err;
     hw_module_t* module;
@@ -222,6 +238,64 @@
     return interface;
 }
 
+static const AGpsInterface* GetAGpsInterface()
+{
+    if (!sGpsInterface)
+        sGpsInterface = get_gps_interface();
+    if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0)
+        return NULL;
+
+    if (!sAGpsInterface) {
+        sAGpsInterface = (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
+        if (sAGpsInterface)
+            sAGpsInterface->init(&sAGpsCallbacks);
+    }
+    return sAGpsInterface;
+}
+
+static const GpsNiInterface* GetNiInterface()
+{
+    if (!sGpsInterface)
+        sGpsInterface = get_gps_interface();
+    if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0)
+        return NULL;
+
+    if (!sGpsNiInterface) {
+       sGpsNiInterface = (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE);
+        if (sGpsNiInterface)
+           sGpsNiInterface->init(&sGpsNiCallbacks);
+    }
+    return sGpsNiInterface;
+}
+
+static const AGpsRilInterface* GetAGpsRilInterface()
+{
+    if (!sGpsInterface)
+        sGpsInterface = get_gps_interface();
+    if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0)
+        return NULL;
+
+    if (!sAGpsRilInterface) {
+       sAGpsRilInterface = (const AGpsRilInterface*)sGpsInterface->get_extension(AGPS_RIL_INTERFACE);
+        if (sAGpsRilInterface)
+            sAGpsRilInterface->init(&sAGpsRilCallbacks);
+    }
+    return sAGpsRilInterface;
+}
+
+static void android_location_GpsLocationProvider_class_init_native(JNIEnv* env, jclass clazz) {
+    method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V");
+    method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V");
+    method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V");
+    method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(II)V");
+    method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V");
+    method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V");
+    method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V");
+    method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V");
+    method_requestRefLocation = env->GetMethodID(clazz,"requestRefLocation","(I)V");
+    method_requestSetID = env->GetMethodID(clazz,"requestSetID","(I)V");
+}
+
 static jboolean android_location_GpsLocationProvider_is_supported(JNIEnv* env, jclass clazz) {
     if (!sGpsInterface)
         sGpsInterface = get_gps_interface();
@@ -239,16 +313,6 @@
     if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0)
         return false;
 
-    if (!sAGpsInterface)
-        sAGpsInterface = (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
-    if (sAGpsInterface)
-        sAGpsInterface->init(&sAGpsCallbacks);
-
-    if (!sGpsNiInterface)
-        sGpsNiInterface = (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE);
-    if (sGpsNiInterface)
-        sGpsNiInterface->init(&sGpsNiCallbacks);
-
     if (!sGpsDebugInterface)
        sGpsDebugInterface = (const GpsDebugInterface*)sGpsInterface->get_extension(GPS_DEBUG_INTERFACE);
 
@@ -313,6 +377,64 @@
     return num_svs;
 }
 
+static void android_location_GpsLocationProvider_agps_set_reference_location_cellid(JNIEnv* env,
+        jobject obj, jint type, jint mcc, jint mnc, jint lac, jint cid)
+{
+    AGpsRefLocation location;
+    const AGpsRilInterface* interface = GetAGpsRilInterface();
+    if (!interface) {
+        LOGE("no AGPS RIL interface in agps_set_reference_location_cellid");
+        return;
+    }
+
+    switch(type) {
+        case AGPS_REF_LOCATION_TYPE_GSM_CELLID:
+        case AGPS_REF_LOCATION_TYPE_UMTS_CELLID:
+            location.type = type;
+            location.u.cellID.mcc = mcc;
+            location.u.cellID.mnc = mnc;
+            location.u.cellID.lac = lac;
+            location.u.cellID.cid = cid;
+            break;
+        default:
+            LOGE("Neither a GSM nor a UMTS cellid (%s:%d).",__FUNCTION__,__LINE__);
+            return;
+            break;
+    }
+    interface->set_ref_location(&location, sizeof(location));
+}
+
+static void android_location_GpsLocationProvider_agps_send_ni_message(JNIEnv* env,
+        jobject obj, jbyteArray ni_msg, jint size)
+{
+    size_t sz;
+    const AGpsRilInterface* interface = GetAGpsRilInterface();
+    if (!interface) {
+        LOGE("no AGPS RIL interface in send_ni_message");
+        return;
+    }
+    if (size < 0)
+        return;
+    sz = (size_t)size;
+    jbyte* b = env->GetByteArrayElements(ni_msg, 0);
+    interface->ni_message((uint8_t *)b,sz);
+    env->ReleaseByteArrayElements(ni_msg,b,0);
+}
+
+static void android_location_GpsLocationProvider_agps_set_id(JNIEnv *env,
+        jobject obj, jint type, jstring  setid_string)
+{
+    const AGpsRilInterface* interface = GetAGpsRilInterface();
+    if (!interface) {
+        LOGE("no AGPS RIL interface in agps_set_id");
+        return;
+    }
+
+    const char *setid = env->GetStringUTFChars(setid_string, NULL);
+    interface->set_set_id(type, setid);
+    env->ReleaseStringUTFChars(setid_string, setid);
+}
+
 static jint android_location_GpsLocationProvider_read_nmea(JNIEnv* env, jobject obj,
                                             jbyteArray nmeaArray, jint buffer_size)
 {
@@ -363,60 +485,63 @@
 
 static void android_location_GpsLocationProvider_agps_data_conn_open(JNIEnv* env, jobject obj, jstring apn)
 {
-    if (!sAGpsInterface) {
-        sAGpsInterface = (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
+    const AGpsInterface* interface = GetAGpsInterface();
+    if (!interface) {
+        LOGE("no AGPS interface in agps_data_conn_open");
+        return;
     }
-    if (sAGpsInterface) {
-        if (apn == NULL) {
-            jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-            return;
-        }
-        const char *apnStr = env->GetStringUTFChars(apn, NULL);
-        sAGpsInterface->data_conn_open(apnStr);
-        env->ReleaseStringUTFChars(apn, apnStr);
+    if (apn == NULL) {
+        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
+        return;
     }
+    const char *apnStr = env->GetStringUTFChars(apn, NULL);
+    interface->data_conn_open(apnStr);
+    env->ReleaseStringUTFChars(apn, apnStr);
 }
 
 static void android_location_GpsLocationProvider_agps_data_conn_closed(JNIEnv* env, jobject obj)
 {
-    if (!sAGpsInterface) {
-        sAGpsInterface = (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
+    const AGpsInterface* interface = GetAGpsInterface();
+    if (!interface) {
+        LOGE("no AGPS interface in agps_data_conn_open");
+        return;
     }
-    if (sAGpsInterface) {
-        sAGpsInterface->data_conn_closed();
-    }
+    interface->data_conn_closed();
 }
 
 static void android_location_GpsLocationProvider_agps_data_conn_failed(JNIEnv* env, jobject obj)
 {
-    if (!sAGpsInterface) {
-        sAGpsInterface = (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
+    const AGpsInterface* interface = GetAGpsInterface();
+    if (!interface) {
+        LOGE("no AGPS interface in agps_data_conn_open");
+        return;
     }
-    if (sAGpsInterface) {
-        sAGpsInterface->data_conn_failed();
-    }
+    interface->data_conn_failed();
 }
 
 static void android_location_GpsLocationProvider_set_agps_server(JNIEnv* env, jobject obj,
         jint type, jstring hostname, jint port)
 {
-    if (!sAGpsInterface) {
-        sAGpsInterface = (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
+    const AGpsInterface* interface = GetAGpsInterface();
+    if (!interface) {
+        LOGE("no AGPS interface in agps_data_conn_open");
+        return;
     }
-    if (sAGpsInterface) {
-        const char *c_hostname = env->GetStringUTFChars(hostname, NULL);
-        sAGpsInterface->set_server(type, c_hostname, port);
-        env->ReleaseStringUTFChars(hostname, c_hostname);
-    }
+    const char *c_hostname = env->GetStringUTFChars(hostname, NULL);
+    interface->set_server(type, c_hostname, port);
+    env->ReleaseStringUTFChars(hostname, c_hostname);
 }
 
 static void android_location_GpsLocationProvider_send_ni_response(JNIEnv* env, jobject obj,
       jint notifId, jint response)
 {
-    if (!sGpsNiInterface)
-        sGpsNiInterface = (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE);
-    if (sGpsNiInterface)
-        sGpsNiInterface->respond(notifId, response);
+    const GpsNiInterface* interface = GetNiInterface();
+    if (!interface) {
+        LOGE("no NI interface in send_ni_response");
+        return;
+    }
+
+    interface->respond(notifId, response);
 }
 
 static jstring android_location_GpsLocationProvider_get_internal_state(JNIEnv* env, jobject obj)
@@ -452,8 +577,11 @@
     {"native_agps_data_conn_open", "(Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_agps_data_conn_open},
     {"native_agps_data_conn_closed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_closed},
     {"native_agps_data_conn_failed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_failed},
+    {"native_agps_set_id","(ILjava/lang/String;)V",(void*)android_location_GpsLocationProvider_agps_set_id},
+    {"native_agps_set_ref_location_cellid","(IIIII)V",(void*)android_location_GpsLocationProvider_agps_set_reference_location_cellid},
     {"native_set_agps_server", "(ILjava/lang/String;I)V", (void*)android_location_GpsLocationProvider_set_agps_server},
     {"native_send_ni_response", "(II)V", (void*)android_location_GpsLocationProvider_send_ni_response},
+    {"native_agps_ni_message", "([BI)V", (void *)android_location_GpsLocationProvider_agps_send_ni_message},
     {"native_get_internal_state", "()Ljava/lang/String;", (void*)android_location_GpsLocationProvider_get_internal_state},
 };
 
diff --git a/tests/StatusBar/src/com/android/statusbartest/PowerTest.java b/tests/StatusBar/src/com/android/statusbartest/PowerTest.java
index f778cab..178fa92 100644
--- a/tests/StatusBar/src/com/android/statusbartest/PowerTest.java
+++ b/tests/StatusBar/src/com/android/statusbartest/PowerTest.java
@@ -49,6 +49,8 @@
     int mPokeState = 0;
     IBinder mPokeToken = new Binder();
     Handler mHandler = new Handler();
+    PowerManager mPm;
+    PowerManager.WakeLock mProx;
 
     @Override
     protected String tag() {
@@ -58,10 +60,27 @@
     @Override
     protected Test[] tests() {
         mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
+        mPm = (PowerManager)getSystemService("power");
+        mProx = mPm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "PowerTest-prox");
         
         return mTests;
     }
     private Test[] mTests = new Test[] {
+        new Test("Enable proximity") {
+            public void run() {
+                mProx.acquire();
+            }
+        },
+        new Test("Disable proximity") {
+            public void run() {
+                mProx.release();
+            }
+        },
+        new Test("Disable proximity (WAIT_FOR_PROXIMITY_NEGATIVE)") {
+            public void run() {
+                mProx.release(PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE);
+            }
+        },
         new Test("Cheek events don't poke") {
             public void run() {
                 mPokeState |= LocalPowerManager.POKE_LOCK_IGNORE_CHEEK_EVENTS;
@@ -72,6 +91,7 @@
                 }
             }
         },
+
         new Test("Cheek events poke") {
             public void run() {
                 mPokeState &= ~LocalPowerManager.POKE_LOCK_IGNORE_CHEEK_EVENTS;