Merge "Flush resets the count of played audio frames"
diff --git a/cmds/stagefright/sf2.cpp b/cmds/stagefright/sf2.cpp
index 263ecd1..f547e01 100644
--- a/cmds/stagefright/sf2.cpp
+++ b/cmds/stagefright/sf2.cpp
@@ -46,7 +46,8 @@
           mDecodeAudio(decodeAudio),
           mSurface(surface),
           mRenderToSurface(renderToSurface),
-          mCodec(new ACodec) {
+          mCodec(new ACodec),
+          mIsVorbis(false) {
         CHECK(!mDecodeAudio || mSurface == NULL);
     }
 
@@ -85,6 +86,12 @@
                     if (!strncasecmp(mDecodeAudio ? "audio/" : "video/",
                                      mime, 6)) {
                         mSource = extractor->getTrack(i);
+
+                        if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_VORBIS)) {
+                            mIsVorbis = true;
+                        } else {
+                            mIsVorbis = false;
+                        }
                         break;
                     }
                 }
@@ -227,6 +234,7 @@
     bool mRenderToSurface;
     sp<ACodec> mCodec;
     sp<MediaSource> mSource;
+    bool mIsVorbis;
 
     Vector<sp<ABuffer> > mCSD;
     size_t mCSDIndex;
@@ -369,6 +377,20 @@
 
             buffer->meta()->setInt32("csd", true);
             mCSD.push(buffer);
+        } else if (meta->findData(kKeyVorbisInfo, &type, &data, &size)) {
+            sp<ABuffer> buffer = new ABuffer(size);
+            memcpy(buffer->data(), data, size);
+
+            buffer->meta()->setInt32("csd", true);
+            mCSD.push(buffer);
+
+            CHECK(meta->findData(kKeyVorbisBooks, &type, &data, &size));
+
+            buffer = new ABuffer(size);
+            memcpy(buffer->data(), data, size);
+
+            buffer->meta()->setInt32("csd", true);
+            mCSD.push(buffer);
         }
 
         int32_t maxInputSize;
@@ -423,10 +445,17 @@
                     }
                 }
 
-                if (inBuffer->range_length() > sizeLeft) {
+                size_t sizeNeeded = inBuffer->range_length();
+                if (mIsVorbis) {
+                    // Vorbis data is suffixed with the number of
+                    // valid samples on the page.
+                    sizeNeeded += sizeof(int32_t);
+                }
+
+                if (sizeNeeded > sizeLeft) {
                     if (outBuffer->size() == 0) {
                         LOGE("Unable to fit even a single input buffer of size %d.",
-                             inBuffer->range_length());
+                             sizeNeeded);
                     }
                     CHECK_GT(outBuffer->size(), 0u);
 
@@ -448,10 +477,22 @@
                         + inBuffer->range_offset(),
                        inBuffer->range_length());
 
-                outBuffer->setRange(
-                        0, outBuffer->size() + inBuffer->range_length());
+                if (mIsVorbis) {
+                    int32_t numPageSamples;
+                    if (!inBuffer->meta_data()->findInt32(
+                                kKeyValidSamples, &numPageSamples)) {
+                        numPageSamples = -1;
+                    }
 
-                sizeLeft -= inBuffer->range_length();
+                    memcpy(outBuffer->data()
+                            + outBuffer->size() + inBuffer->range_length(),
+                           &numPageSamples, sizeof(numPageSamples));
+                }
+
+                outBuffer->setRange(
+                        0, outBuffer->size() + sizeNeeded);
+
+                sizeLeft -= sizeNeeded;
 
                 inBuffer->release();
                 inBuffer = NULL;
diff --git a/core/java/android/accounts/ChooseAccountTypeActivity.java b/core/java/android/accounts/ChooseAccountTypeActivity.java
index 5239e8c..448b2c0 100644
--- a/core/java/android/accounts/ChooseAccountTypeActivity.java
+++ b/core/java/android/accounts/ChooseAccountTypeActivity.java
@@ -33,7 +33,6 @@
 import android.widget.TextView;
 import com.android.internal.R;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -43,7 +42,7 @@
 /**
  * @hide
  */
-public class ChooseAccountTypeActivity extends Activity implements AccountManagerCallback<Bundle> {
+public class ChooseAccountTypeActivity extends Activity {
     private static final String TAG = "AccountManager";
 
     private HashMap<String, AuthInfo> mTypeToAuthenticatorInfo = new HashMap<String, AuthInfo>();
@@ -52,7 +51,6 @@
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        setContentView(R.layout.choose_account_type);
 
         // Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
         Set<String> setOfAllowableAccountTypes = null;
@@ -90,10 +88,11 @@
         }
 
         if (mAuthenticatorInfosToDisplay.size() == 1) {
-            runAddAccountForAuthenticator(mAuthenticatorInfosToDisplay.get(0));
+            setResultAndFinish(mAuthenticatorInfosToDisplay.get(0).desc.type);
             return;
         }
 
+        setContentView(R.layout.choose_account_type);
         // Setup the list
         ListView list = (ListView) findViewById(android.R.id.list);
         // Use an existing ListAdapter that will map an array of strings to TextViews
@@ -103,11 +102,20 @@
         list.setTextFilterEnabled(false);
         list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
-                runAddAccountForAuthenticator(mAuthenticatorInfosToDisplay.get(position));
+                setResultAndFinish(mAuthenticatorInfosToDisplay.get(position).desc.type);
             }
         });
     }
 
+    private void setResultAndFinish(final String type) {
+        Bundle bundle = new Bundle();
+        bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, type);
+        setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
+        Log.d(TAG, "ChooseAccountTypeActivity.setResultAndFinish: "
+                + "selected account type " + type);
+        finish();
+    }
+
     private void buildTypeToAuthDescriptionMap() {
         for(AuthenticatorDescription desc : AccountManager.get(this).getAuthenticatorTypes()) {
             String name = null;
@@ -136,42 +144,6 @@
         }
     }
 
-    protected void runAddAccountForAuthenticator(AuthInfo authInfo) {
-        Log.d(TAG, "selected account type " + authInfo.name);
-        final Bundle options = getIntent().getBundleExtra(
-                ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE);
-        final String[] requiredFeatures = getIntent().getStringArrayExtra(
-                ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY);
-        final String authTokenType = getIntent().getStringExtra(
-                ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING);
-        AccountManager.get(this).addAccount(authInfo.desc.type, authTokenType, requiredFeatures,
-                options, this, this, null /* Handler */);
-    }
-
-    public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {
-        try {
-            Bundle accountManagerResult = accountManagerFuture.getResult();
-            Bundle bundle = new Bundle();
-            bundle.putString(AccountManager.KEY_ACCOUNT_NAME,
-                    accountManagerResult.getString(AccountManager.KEY_ACCOUNT_NAME));
-            bundle.putString(AccountManager.KEY_ACCOUNT_TYPE,
-                    accountManagerResult.getString(AccountManager.KEY_ACCOUNT_TYPE));
-            setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
-            finish();
-            return;
-        } catch (OperationCanceledException e) {
-            setResult(Activity.RESULT_CANCELED);
-            finish();
-            return;
-        } catch (IOException e) {
-        } catch (AuthenticatorException e) {
-        }
-        Bundle bundle = new Bundle();
-        bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server");
-        setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
-        finish();
-    }
-
     private static class AuthInfo {
         final AuthenticatorDescription desc;
         final String name;
diff --git a/core/java/android/accounts/ChooseTypeAndAccountActivity.java b/core/java/android/accounts/ChooseTypeAndAccountActivity.java
index 852c4dd..8cc2002 100644
--- a/core/java/android/accounts/ChooseTypeAndAccountActivity.java
+++ b/core/java/android/accounts/ChooseTypeAndAccountActivity.java
@@ -36,6 +36,7 @@
 import android.widget.TextView;
 import com.android.internal.R;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -44,7 +45,8 @@
 /**
  * @hide
  */
-public class ChooseTypeAndAccountActivity extends Activity {
+public class ChooseTypeAndAccountActivity extends Activity
+        implements AccountManagerCallback<Bundle> {
     private static final String TAG = "AccountManager";
 
     /**
@@ -211,10 +213,9 @@
     protected void onActivityResult(final int requestCode, final int resultCode,
             final Intent data) {
         if (resultCode == RESULT_OK && data != null) {
-            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
             String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
-            if (accountName != null && accountType != null) {
-                setResultAndFinish(accountName, accountType);
+            if (accountType != null) {
+                runAddAccountForAuthenticator(accountType);
                 return;
             }
         }
@@ -223,6 +224,43 @@
         finish();
     }
 
+    protected void runAddAccountForAuthenticator(String type) {
+        Log.d(TAG, "selected account type " + type);
+        final Bundle options = getIntent().getBundleExtra(
+                ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE);
+        final String[] requiredFeatures = getIntent().getStringArrayExtra(
+                ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY);
+        final String authTokenType = getIntent().getStringExtra(
+                ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING);
+        AccountManager.get(this).addAccount(type, authTokenType, requiredFeatures,
+                options, this, this, null /* Handler */);
+    }
+
+    public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {
+        try {
+            final Bundle accountManagerResult = accountManagerFuture.getResult();
+            final String name = accountManagerResult.getString(AccountManager.KEY_ACCOUNT_NAME);
+            final String type = accountManagerResult.getString(AccountManager.KEY_ACCOUNT_TYPE);
+            if (name != null && type != null) {
+                final Bundle bundle = new Bundle();
+                bundle.putString(AccountManager.KEY_ACCOUNT_NAME, name);
+                bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, type);
+                setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
+                finish();
+                return;
+            }
+        } catch (OperationCanceledException e) {
+            setResult(Activity.RESULT_CANCELED);
+            finish();
+            return;
+        } catch (IOException e) {
+        } catch (AuthenticatorException e) {
+        }
+        Bundle bundle = new Bundle();
+        bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server");
+        setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
+        finish();
+    }
 
     private Drawable getDrawableForType(
             final HashMap<String, AuthenticatorDescription> typeToAuthDescription,
@@ -266,6 +304,7 @@
 
     private void startChooseAccountTypeActivity() {
         final Intent intent = new Intent(this, ChooseAccountTypeActivity.class);
+        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
         intent.putExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY,
                 getIntent().getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY));
         intent.putExtra(EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE,
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index d45a71a..7a7e4f4 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -2537,6 +2537,7 @@
      * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
      * application's enabled state is based on the original information in
      * the manifest as found in {@link ComponentInfo}.
+     * @throws IllegalArgumentException if the named package does not exist.
      */
     public abstract int getApplicationEnabledSetting(String packageName);
 
diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java
index c9fcf0c..5ee90a4 100644
--- a/core/java/android/webkit/CallbackProxy.java
+++ b/core/java/android/webkit/CallbackProxy.java
@@ -905,11 +905,9 @@
     */
 
     public void onPageStarted(String url, Bitmap favicon) {
-        // Do an unsynchronized quick check to avoid posting if no callback has
-        // been set.
-        if (mWebViewClient == null) {
-            return;
-        }
+        // We need to send the message even if no WebViewClient is set, because we need to call
+        // WebView.onPageStarted().
+
         // Performance probe
         if (PERF_PROBE) {
             mWebCoreThreadTime = SystemClock.currentThreadTimeMillis();
diff --git a/core/java/android/webkit/SslCertLookupTable.java b/core/java/android/webkit/SslCertLookupTable.java
index 048a3cf..052244f 100644
--- a/core/java/android/webkit/SslCertLookupTable.java
+++ b/core/java/android/webkit/SslCertLookupTable.java
@@ -46,4 +46,8 @@
     public boolean isAllowed(SslError sslError) {
         return table.getBoolean(sslError.toString());
     }
+
+    public void clear() {
+        table.clear();
+    }
 }
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 139f9f3..530b230 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -2392,6 +2392,12 @@
         return mZoomManager.getScale();
     }
 
+    // Called by JNI. Returns the scale to apply to the text selection handles
+    /* package */ float getTextHandleScale() {
+        float density = mContext.getResources().getDisplayMetrics().density;
+        return density / getScale();
+    }
+
     /**
      * Return the reading level scale of the WebView
      * @return The reading level scale.
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 470e843..deaf0f2 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -1349,8 +1349,14 @@
                         }
 
                         case CLEAR_SSL_PREF_TABLE:
-                            Network.getInstance(mContext)
-                                    .clearUserSslPrefTable();
+                            if (JniUtil.useChromiumHttpStack()) {
+                                // FIXME: This will not work for connections currently in use, as
+                                // they cache the certificate responses. See http://b/5324235.
+                                SslCertLookupTable.getInstance().clear();
+                                nativeCloseIdleConnections();
+                            } else {
+                                Network.getInstance(mContext).clearUserSslPrefTable();
+                            }
                             break;
 
                         case TOUCH_UP:
diff --git a/core/java/android/widget/MediaController.java b/core/java/android/widget/MediaController.java
index a63b8c8..90ece5d 100644
--- a/core/java/android/widget/MediaController.java
+++ b/core/java/android/widget/MediaController.java
@@ -75,6 +75,7 @@
     private WindowManager       mWindowManager;
     private Window              mWindow;
     private View                mDecor;
+    private WindowManager.LayoutParams mDecorLayoutParams;
     private ProgressBar         mProgress;
     private TextView            mEndTime, mCurrentTime;
     private boolean             mShowing;
@@ -120,6 +121,7 @@
         mContext = context;
         mUseFastForward = true;
         initFloatingWindow();
+        initFloatingWindowLayout();
     }
 
     private void initFloatingWindow() {
@@ -142,6 +144,48 @@
         requestFocus();
     }
 
+    // Allocate and initialize the static parts of mDecorLayoutParams. Must
+    // also call updateFloatingWindowLayout() to fill in the dynamic parts
+    // (y and width) before mDecorLayoutParams can be used.
+    private void initFloatingWindowLayout() {
+        mDecorLayoutParams = new WindowManager.LayoutParams();
+        WindowManager.LayoutParams p = mDecorLayoutParams;
+        p.gravity = Gravity.TOP;
+        p.height = LayoutParams.WRAP_CONTENT;
+        p.x = 0;
+        p.format = PixelFormat.TRANSLUCENT;
+        p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
+        p.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
+                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
+                | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
+        p.token = null;
+        p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;
+    }
+
+    // Update the dynamic parts of mDecorLayoutParams
+    // Must be called with mAnchor != NULL.
+    private void updateFloatingWindowLayout() {
+        int [] anchorPos = new int[2];
+        mAnchor.getLocationOnScreen(anchorPos);
+
+        WindowManager.LayoutParams p = mDecorLayoutParams;
+        p.width = mAnchor.getWidth();
+        p.y = anchorPos[1] + mAnchor.getHeight();
+    }
+
+    // This is called whenever mAnchor's layout bound changes
+    private OnLayoutChangeListener mLayoutChangeListener =
+            new OnLayoutChangeListener() {
+        public void onLayoutChange(View v, int left, int top, int right,
+                int bottom, int oldLeft, int oldTop, int oldRight,
+                int oldBottom) {
+            updateFloatingWindowLayout();
+            if (mShowing) {
+                mWindowManager.updateViewLayout(mDecor, mDecorLayoutParams);
+            }
+        }
+    };
+
     private OnTouchListener mTouchListener = new OnTouchListener() {
         public boolean onTouch(View v, MotionEvent event) {
             if (event.getAction() == MotionEvent.ACTION_DOWN) {
@@ -164,7 +208,13 @@
      * @param view The view to which to anchor the controller when it is visible.
      */
     public void setAnchorView(View view) {
+        if (mAnchor != null) {
+            mAnchor.removeOnLayoutChangeListener(mLayoutChangeListener);
+        }
         mAnchor = view;
+        if (mAnchor != null) {
+            mAnchor.addOnLayoutChangeListener(mLayoutChangeListener);
+        }
 
         FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(
                 ViewGroup.LayoutParams.MATCH_PARENT,
@@ -279,31 +329,14 @@
      * the controller until hide() is called.
      */
     public void show(int timeout) {
-
         if (!mShowing && mAnchor != null) {
             setProgress();
             if (mPauseButton != null) {
                 mPauseButton.requestFocus();
             }
             disableUnsupportedButtons();
-
-            int [] anchorpos = new int[2];
-            mAnchor.getLocationOnScreen(anchorpos);
-
-            WindowManager.LayoutParams p = new WindowManager.LayoutParams();
-            p.gravity = Gravity.TOP;
-            p.width = mAnchor.getWidth();
-            p.height = LayoutParams.WRAP_CONTENT;
-            p.x = 0;
-            p.y = anchorpos[1] + mAnchor.getHeight() - p.height;
-            p.format = PixelFormat.TRANSLUCENT;
-            p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
-            p.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
-                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
-                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
-            p.token = null;
-            p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;
-            mWindowManager.addView(mDecor, p);
+            updateFloatingWindowLayout();
+            mWindowManager.addView(mDecor, mDecorLayoutParams);
             mShowing = true;
         }
         updatePausePlay();
diff --git a/core/java/android/widget/VideoView.java b/core/java/android/widget/VideoView.java
index 88a0e01..8e438ff 100644
--- a/core/java/android/widget/VideoView.java
+++ b/core/java/android/widget/VideoView.java
@@ -456,13 +456,6 @@
                     seekTo(mSeekWhenPrepared);
                 }
                 start();
-                if (mMediaController != null) {
-                    if (mMediaController.isShowing()) {
-                        // ensure the controller will get repositioned later
-                        mMediaController.hide();
-                    }
-                    mMediaController.show();
-                }
             }
         }
 
diff --git a/core/java/com/android/internal/policy/IFaceLockCallback.aidl b/core/java/com/android/internal/policy/IFaceLockCallback.aidl
index 1eadc41..4f76c71 100644
--- a/core/java/com/android/internal/policy/IFaceLockCallback.aidl
+++ b/core/java/com/android/internal/policy/IFaceLockCallback.aidl
@@ -21,5 +21,4 @@
 oneway interface IFaceLockCallback {
     void unlock();
     void cancel();
-    void sleepDevice();
 }
diff --git a/core/res/res/layout/keyguard_screen_password_landscape.xml b/core/res/res/layout/keyguard_screen_password_landscape.xml
index 3343d8b..8bc5f34 100644
--- a/core/res/res/layout/keyguard_screen_password_landscape.xml
+++ b/core/res/res/layout/keyguard_screen_password_landscape.xml
@@ -191,4 +191,17 @@
         android:layout_height="0dip"
         />
 
+    <!-- Area to overlay FaceLock -->
+    <TextView android:id="@+id/faceLockAreaView"
+        android:visibility="gone"
+        android:layout_row="0"
+        android:layout_column="2"
+        android:layout_rowSpan="8"
+        android:layout_columnSpan="1"
+        android:layout_gravity="fill"
+        android:layout_width="0dip"
+        android:layout_height="0dip"
+        android:background="@color/facelock_color_background"
+    />
+
 </GridLayout>
diff --git a/core/res/res/layout/keyguard_screen_unlock_landscape.xml b/core/res/res/layout/keyguard_screen_unlock_landscape.xml
index d71dbff..2778f4e 100644
--- a/core/res/res/layout/keyguard_screen_unlock_landscape.xml
+++ b/core/res/res/layout/keyguard_screen_unlock_landscape.xml
@@ -160,4 +160,18 @@
         android:layout_height="0dip"
         />
 
+    <!-- Area to overlay FaceLock -->
+    <TextView android:id="@+id/faceLockAreaView"
+        android:visibility="gone"
+        android:layout_row="0"
+        android:layout_column="1"
+        android:layout_rowSpan="7"
+        android:layout_columnSpan="1"
+        android:layout_gravity="fill"
+        android:layout_marginLeft="8dip"
+        android:layout_width="0dip"
+        android:layout_height="0dip"
+        android:background="@color/facelock_color_background"
+    />
+
 </GridLayout>
diff --git a/docs/html/guide/practices/design/jni.jd b/docs/html/guide/practices/design/jni.jd
index 6e984b0..9980efd 100644
--- a/docs/html/guide/practices/design/jni.jd
+++ b/docs/html/guide/practices/design/jni.jd
@@ -26,9 +26,9 @@
 </div>
 </div>
 
-<p>JNI is the Java Native Interface.  It defines a way for code written in the
-Java programming language to interact with native
-code: functions written in C/C++.  It's VM-neutral, has support for loading code from
+<p>JNI is the Java Native Interface.  It defines a way for managed code
+(written in the Java programming language) to interact with native
+code (written in C/C++).  It's vendor-neutral, has support for loading code from
 dynamic shared libraries, and while cumbersome at times is reasonably efficient.</p>
 
 <p>You really should read through the
@@ -46,13 +46,13 @@
 pointers to pointers to function tables.  (In the C++ version, they're classes with a
 pointer to a function table and a member function for each JNI function that indirects through
 the table.)  The JavaVM provides the "invocation interface" functions,
-which allow you to create and destroy the VM.  In theory you can have multiple VMs per process,
-but Android's VM only allows one.</p>
+which allow you to create and destroy a JavaVM.  In theory you can have multiple JavaVMs per process,
+but Android only allows one.</p>
 
 <p>The JNIEnv provides most of the JNI functions.  Your native functions all receive a JNIEnv as
 the first argument.</p>
 
-<p>On some VMs, the JNIEnv is used for thread-local storage.  For this reason, <strong>you cannot share a JNIEnv between threads</strong>.
+<p>The JNIEnv is used for thread-local storage.  For this reason, <strong>you cannot share a JNIEnv between threads</strong>.
 If a piece of code has no other way to get its JNIEnv, you should share
 the JavaVM, and use <code>GetEnv</code> to discover the thread's JNIEnv. (Assuming it has one; see <code>AttachCurrentThread</code> below.)</p>
 
@@ -66,23 +66,22 @@
 <a name="threads" id="threads"></a>
 <h2>Threads</h2>
 
-<p>All VM threads are Linux threads, scheduled by the kernel.  They're usually
-started using Java language features (notably <code>Thread.start</code>),
-but they can also be created elsewhere and then attached to the VM.  For
+<p>All threads are Linux threads, scheduled by the kernel.  They're usually
+started from managed code (using <code>Thread.start</code>),
+but they can also be created elsewhere and then attached to the JavaVM.  For
 example, a thread started with <code>pthread_create</code> can be attached
 with the JNI <code>AttachCurrentThread</code> or
 <code>AttachCurrentThreadAsDaemon</code> functions.  Until a thread is
-attached to the VM, it has no JNIEnv, and
-<strong>cannot make JNI calls</strong>.</p>
+attached, it has no JNIEnv, and <strong>cannot make JNI calls</strong>.</p>
 
-<p>Attaching a natively-created thread causes the VM to allocate and initialize
-a <code>Thread</code> object, add it to the "main" <code>ThreadGroup</code>,
-and add the thread to the set that is visible to the debugger.  Calling
-<code>AttachCurrentThread</code> on an already-attached thread is a no-op.</p>
+<p>Attaching a natively-created thread causes a <code>java.lang.Thread</code>
+object to be constructed and added to the "main" <code>ThreadGroup</code>,
+making it visible to the debugger.  Calling <code>AttachCurrentThread</code>
+on an already-attached thread is a no-op.</p>
 
-<p>The Dalvik VM does not suspend threads executing native code.  If
+<p>Android does not suspend threads executing native code.  If
 garbage collection is in progress, or the debugger has issued a suspend
-request, the VM will pause the thread the next time it makes a JNI call.</p>
+request, Android will pause the thread the next time it makes a JNI call.</p>
 
 <p>Threads attached through JNI <strong>must call
 <code>DetachCurrentThread</code> before they exit</strong>.
@@ -108,12 +107,12 @@
 </ul>
 
 <p>Similarly, to call a method, you'd first get a class object reference and then a method ID.  The IDs are often just
-pointers to internal VM data structures.  Looking them up may require several string
+pointers to internal runtime data structures.  Looking them up may require several string
 comparisons, but once you have them the actual call to get the field or invoke the method
 is very quick.</p>
 
 <p>If performance is important, it's useful to look the values up once and cache the results
-in your native code.  Because there is a limit of one VM per process, it's reasonable
+in your native code.  Because there is a limit of one JavaVM per process, it's reasonable
 to store this data in a static local structure.</p>
 
 <p>The class references, field IDs, and method IDs are guaranteed valid until the class is unloaded.  Classes
@@ -145,13 +144,17 @@
 <a name="local_and_global_references" id="local_and_global_references"></a>
 <h2>Local and Global References</h2>
 
-<p>Every object that JNI returns is a "local reference".  This means that it's valid for the
+<p>Every argument passed to a native method, and almost every object returned
+by a JNI function is a "local reference".  This means that it's valid for the
 duration of the current native method in the current thread.
-<strong>Even if the object itself continues to live on after the native method returns, the reference is not valid.</strong>
-This applies to all sub-classes of <code>jobject</code>, including
+<strong>Even if the object itself continues to live on after the native method
+returns, the reference is not valid.</strong>
+<p>This applies to all sub-classes of <code>jobject</code>, including
 <code>jclass</code>, <code>jstring</code>, and <code>jarray</code>.
-(Dalvik VM will warn you about most reference mis-uses when extended JNI
+(The runtime will warn you about most reference mis-uses when extended JNI
 checks are enabled.)</p>
+<p>The only way to get non-local references is via the functions
+<code>NewGlobalRef</code> and <code>NewWeakGlobalRef</code>.
 
 <p>If you want to hold on to a reference for a longer period, you must use
 a "global" reference.  The <code>NewGlobalRef</code> function takes the
@@ -159,7 +162,7 @@
 The global reference is guaranteed to be valid until you call
 <code>DeleteGlobalRef</code>.</p>
 
-<p>This pattern is commonly used when caching copies of class objects obtained
+<p>This pattern is commonly used when caching a jclass returned
 from <code>FindClass</code>, e.g.:</p>
 <pre>jclass localClass = env-&gt;FindClass("MyClass");
 jclass globalClass = reinterpret_cast&lt;jclass&gt;(env-&gt;NewGlobalRef(localClass));</pre>
@@ -181,22 +184,25 @@
 
 <p>Programmers are required to "not excessively allocate" local references.  In practical terms this means
 that if you're creating large numbers of local references, perhaps while running through an array of
-Objects, you should free them manually with
+objects, you should free them manually with
 <code>DeleteLocalRef</code> instead of letting JNI do it for you.  The
-VM is only required to reserve slots for
+implementation is only required to reserve slots for
 16 local references, so if you need more than that you should either delete as you go or use
-<code>EnsureLocalCapacity</code> to reserve more.</p>
+<code>EnsureLocalCapacity</code>/<code>PushLocalFrame</code> to reserve more.</p>
 
-<p>Note that <code>jfieldID</code>s and <code>jmethodID</code>s are just integers, not object
-references, and should not be passed to <code>NewGlobalRef</code>.  The raw data
+<p>Note that <code>jfieldID</code>s and <code>jmethodID</code>s are opaque
+types, not object references, and should not be passed to
+<code>NewGlobalRef</code>.  The raw data
 pointers returned by functions like <code>GetStringUTFChars</code>
-and <code>GetByteArrayElements</code> are also not objects.</p>
+and <code>GetByteArrayElements</code> are also not objects. (They may be passed
+between threads, and are valid until the matching Release call.)</p>
 
 <p>One unusual case deserves separate mention.  If you attach a native
-thread to the VM with <code>AttachCurrentThread</code>, the code you are running will
-never "return" to the VM until the thread detaches from the VM.  Any local
-references you create will have to be deleted manually unless you're going
-to detach the thread soon.</p>
+thread with <code>AttachCurrentThread</code>, the code you are running will
+never automatically free local references until the thread detaches.  Any local
+references you create will have to be deleted manually. In general, any native
+code that creates local references in a loop probably needs to do some manual
+deletion.</p>
 
 <a name="UTF_8_and_UTF_16_strings" id="UTF_8_and_UTF_16_strings"></a>
 <h2>UTF-8 and UTF-16 Strings</h2>
@@ -205,14 +211,15 @@
 modified encoding is useful for C code because it encodes \u0000 as 0xc0 0x80 instead of 0x00.
 The nice thing about this is that you can count on having C-style zero-terminated strings,
 suitable for use with standard libc string functions.  The down side is that you cannot pass
-arbitrary UTF-8 data into the VM and expect it to work correctly.</p>
+arbitrary UTF-8 data to JNI and expect it to work correctly.</p>
 
-<p>It's usually best to operate with UTF-16 strings.  With Android's current VMs, the
-<code>GetStringChars</code> method
-does not require a copy, whereas <code>GetStringUTFChars</code> requires a malloc and a UTF conversion.  Note that
+<p>If possible, it's usually faster to operate with UTF-16 strings. Android
+currently does not require a copy in <code>GetStringChars</code>, whereas
+<code>GetStringUTFChars</code> requires an allocation and a conversion to
+UTF-8.  Note that
 <strong>UTF-16 strings are not zero-terminated</strong>, and \u0000 is allowed,
 so you need to hang on to the string length as well as
-the string pointer.</p>
+the jchar pointer.</p>
 
 <p><strong>Don't forget to <code>Release</code> the strings you <code>Get</code></strong>.  The
 string functions return <code>jchar*</code> or <code>jbyte*</code>, which
@@ -237,9 +244,8 @@
 primitives can be read and written directly as if they were declared in C.</p>
 
 <p>To make the interface as efficient as possible without constraining
-the VM implementation,
-the <code>Get&lt;PrimitiveType&gt;ArrayElements</code> family of calls
-allows the VM to either return a pointer to the actual elements, or
+the VM implementation, the <code>Get&lt;PrimitiveType&gt;ArrayElements</code>
+family of calls allows the runtime to either return a pointer to the actual elements, or
 allocate some memory and make a copy.  Either way, the raw pointer returned
 is guaranteed to be valid until the corresponding <code>Release</code> call
 is issued (which implies that, if the data wasn't copied, the array object
@@ -253,7 +259,7 @@
 useful.</p>
 
 <p>The <code>Release</code> call takes a <code>mode</code> argument that can
-have one of three values.  The actions performed by the VM depend upon
+have one of three values.  The actions performed by the runtime depend upon
 whether it returned a pointer to the actual data or a copy of it:</p>
 
 <ul>
@@ -312,8 +318,9 @@
     }</pre>
 
 <p>This grabs the array, copies the first <code>len</code> byte
-elements out of it, and then releases the array.  Depending upon the VM
-policies the <code>Get</code> call will either pin or copy the array contents.
+elements out of it, and then releases the array.  Depending upon the
+implementation, the <code>Get</code> call will either pin or copy the array
+contents.
 The code copies the data (for perhaps a second time), then calls <code>Release</code>; in this case
 <code>JNI_ABORT</code> ensures there's no chance of a third copy.</p>
 
@@ -335,7 +342,7 @@
 
 
 <a name="exceptions" id="exceptions"></a>
-<h2>Exception</h2>
+<h2>Exceptions</h2>
 
 <p><strong>You must not call most JNI functions while an exception is pending.</strong>
 Your code is expected to notice the exception (via the function's return value,
@@ -369,11 +376,11 @@
 you must always check for an exception, because the return value is not
 going to be valid if an exception was thrown.</p>
 
-<p>Note that exceptions thrown by interpreted code do not "leap over" native code,
-and C++ exceptions thrown by native code are not handled by Dalvik.
+<p>Note that exceptions thrown by interpreted code do not unwind native stack
+frames, and Android does not yet support C++ exceptions.
 The JNI <code>Throw</code> and <code>ThrowNew</code> instructions just
-set an exception pointer in the current thread.  Upon returning to the VM from
-native code, the exception will be noted and handled appropriately.</p>
+set an exception pointer in the current thread.  Upon returning to managed
+from native code, the exception will be noted and handled appropriately.</p>
 
 <p>Native code can "catch" an exception by calling <code>ExceptionCheck</code> or
 <code>ExceptionOccurred</code>, and clear it with
@@ -476,23 +483,19 @@
 shared library.  For Android apps, you may find it useful to get the full
 path to the application's private data storage area from the context object.</p>
 
-<p>This is the recommended approach, but not the only approach.  The VM does
-not require explicit registration, nor that you provide a
+<p>This is the recommended approach, but not the only approach.  Explicit
+registration is not required, nor is it necessary that you provide a
 <code>JNI_OnLoad</code> function.
 You can instead use "discovery" of native methods that are named in a
-specific way (see <a href="http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp615">
-    the JNI spec</a> for details), though this is less desirable.
-It requires more space in the shared object symbol table,
-loading is slower because it requires string searches through all of the
-loaded shared libraries, and if a method signature is wrong you won't know
+specific way (see <a href="http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp615">the JNI spec</a> for details), though this is less desirable because if a method signature is wrong you won't know
 about it until the first time the method is actually used.</p>
 
 <p>One other note about <code>JNI_OnLoad</code>: any <code>FindClass</code>
 calls you make from there will happen in the context of the class loader
 that was used to load the shared library.  Normally <code>FindClass</code>
 uses the loader associated with the method at the top of the interpreted
-stack, or if there isn't one (because the thread was just attached to
-the VM) it uses the "system" class loader.  This makes
+stack, or if there isn't one (because the thread was just attached) it uses
+the "system" class loader.  This makes
 <code>JNI_OnLoad</code> a convenient place to look up and cache class
 object references.</p>
 
@@ -515,10 +518,9 @@
 
 <p>All JNI 1.6 features are supported, with the following exceptions:</p>
 <ul>
-    <li><code>DefineClass</code> is not implemented.  Dalvik does not use
+    <li><code>DefineClass</code> is not implemented.  Android does not use
     Java bytecodes or class files, so passing in binary class data
-    doesn't work.  Translation facilities may be added in a future
-    version of the VM.</li>
+    doesn't work.</li>
     <li>"Weak global" references are implemented, but may only be passed
     to <code>NewLocalRef</code>, <code>NewGlobalRef</code>, and
     <code>DeleteWeakGlobalRef</code>.  (The spec strongly encourages
@@ -536,12 +538,16 @@
     around this requires using explicit registration or moving the
     native methods out of inner classes.
     <li>Until Android 2.0 (Eclair), it was not possible to use a <code>pthread_key_create</code>
-    destructor function to avoid the VM's "thread must be detached before
-    exit" check.  (The VM also uses a pthread key destructor function,
+    destructor function to avoid the "thread must be detached before
+    exit" check.  (The runtime also uses a pthread key destructor function,
     so it'd be a race to see which gets called first.)
     <li>Until Android 2.2 (Froyo), weak global references were not implemented.
-    Older VMs will vigorously reject attempts to use them.  You can use
+    Older versions will vigorously reject attempts to use them.  You can use
     the Android platform version constants to test for support.
+    <li>Until Android 4.0 (Ice Cream Sandwich), JNI local references were
+    actually direct pointers. Ice Cream Sandwich added the indirection
+    necessary to support better garbage collectors, but this means that lots
+    of JNI bugs are undetectable on older releases.
 </ul>
 
 
@@ -572,8 +578,8 @@
 <p>In logcat, you'll see:</p>
 <pre>W/dalvikvm(  880): No implementation found for native LFoo;.myfunc ()V</pre>
 
-<p>This means that the VM tried to find a matching method but was unsuccessful.
-Some common reasons for this are:</p>
+<p>This means that the runtime tried to find a matching method but was
+unsuccessful.  Some common reasons for this are:</p>
 <ul>
     <li>The library isn't getting loaded.  Check the logcat output for
     messages about library loading.
@@ -581,10 +587,15 @@
     is commonly caused by:
     <ul>
         <li>For lazy method lookup, failing to declare C++ functions
-        with <code>extern "C"</code>.  You can use <code>arm-eabi-nm</code>
+        with <code>extern "C"</code> and appropriate
+        visibility (<code>JNIEXPORT</code>). Note that prior to Ice Cream
+        Sandwich, the JNIEXPORT macro was incorrect, so using a new GCC with
+        an old <code>jni.h</code> won't work.
+        You can use <code>arm-eabi-nm</code>
         to see the symbols as they appear in the library; if they look
         mangled (something like <code>_Z15Java_Foo_myfuncP7_JNIEnvP7_jclass</code>
-        rather than <code>Java_Foo_myfunc</code>) then you need to
+        rather than <code>Java_Foo_myfunc</code>), or if the symbol type is
+        a lowercase 't' rather than an uppercase 'T', then you need to
         adjust the declaration.
         <li>For explicit registration, minor errors when entering the
         method signature.  Make sure that what you're passing to the
@@ -612,7 +623,7 @@
 
 <p>If the class name looks right, you could be running into a class loader
 issue.  <code>FindClass</code> wants to start the class search in the
-class loader associated with your code.  It examines the VM call stack,
+class loader associated with your code.  It examines the call stack,
 which will look something like:
 <pre>    Foo.myfunc(Native Method)
     Foo.main(Foo.java:10)
@@ -623,14 +634,14 @@
 class and uses that.</p>
 
 <p>This usually does what you want.  You can get into trouble if you
-create a thread outside the VM (perhaps by calling <code>pthread_create</code>
-and then attaching it to the VM with <code>AttachCurrentThread</code>).
+create a thread yourself (perhaps by calling <code>pthread_create</code>
+and then attaching it with <code>AttachCurrentThread</code>).
 Now the stack trace looks like this:</p>
 <pre>    dalvik.system.NativeStart.run(Native Method)</pre>
 
 <p>The topmost method is <code>NativeStart.run</code>, which isn't part of
 your application.  If you call <code>FindClass</code> from this thread, the
-VM will start in the "system" class loader instead of the one associated
+JavaVM will start in the "system" class loader instead of the one associated
 with your application, so attempts to find app-specific classes will fail.</p>
 
 <p>There are a few ways to work around this:</p>
@@ -656,12 +667,12 @@
 <h2>FAQ: How do I share raw data with native code?</h2>
 
 <p>You may find yourself in a situation where you need to access a large
-buffer of raw data from code written in Java and C/C++.  Common examples
+buffer of raw data from both managed and native code.  Common examples
 include manipulation of bitmaps or sound samples.  There are two
 basic approaches.</p>
 
 <p>You can store the data in a <code>byte[]</code>.  This allows very fast
-access from code written in Java.  On the native side, however, you're
+access from managed code.  On the native side, however, you're
 not guaranteed to be able to access the data without having to copy it.  In
 some implementations, <code>GetByteArrayElements</code> and
 <code>GetPrimitiveArrayCritical</code> will return actual pointers to the
@@ -674,8 +685,8 @@
 byte buffers, the storage is not allocated on the managed heap, and can
 always be accessed directly from native code (get the address
 with <code>GetDirectBufferAddress</code>).  Depending on how direct
-byte buffer access is implemented in the VM, accessing the data from code
-written in Java can be very slow.</p>
+byte buffer access is implemented, accessing the data from managed code
+can be very slow.</p>
 
 <p>The choice of which to use depends on two factors:</p>
 <ol>
@@ -688,5 +699,4 @@
 </ol>
 
 <p>If there's no clear winner, use a direct byte buffer.  Support for them
-is built directly into JNI, and access to them from code written in
-Java can be made faster with VM improvements.</p>
+is built directly into JNI, and performance should improve in future releases.</p>
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h
index 9da9907..5822877 100644
--- a/include/media/stagefright/ACodec.h
+++ b/include/media/stagefright/ACodec.h
@@ -151,6 +151,12 @@
             OMX_VIDEO_CODINGTYPE compressionFormat);
 
     status_t setupAACDecoder(int32_t numChannels, int32_t sampleRate);
+    status_t setupAMRDecoder(bool isWAMR);
+    status_t setupG711Decoder(int32_t numChannels);
+
+    status_t setupRawAudioFormat(
+            OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels);
+
     status_t setMinBufferSize(OMX_U32 portIndex, size_t size);
 
     status_t initNativeWindow();
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index c270f21..f3174fe 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -651,6 +651,10 @@
 android_media_MediaPlayer_native_finalize(JNIEnv *env, jobject thiz)
 {
     LOGV("native_finalize");
+    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
+    if (mp != NULL) {
+        LOGW("MediaPlayer finalized without being released");
+    }
     android_media_MediaPlayer_release(env, thiz);
 }
 
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index a3746cd..9cb18de 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -687,6 +687,8 @@
             "audio_decoder.amrwb", "audio_encoder.amrwb" },
         { MEDIA_MIMETYPE_AUDIO_AAC,
             "audio_decoder.aac", "audio_encoder.aac" },
+        { MEDIA_MIMETYPE_AUDIO_VORBIS,
+            "audio_decoder.vorbis", "audio_encoder.vorbis" },
         { MEDIA_MIMETYPE_VIDEO_AVC,
             "video_decoder.avc", "video_encoder.avc" },
         { MEDIA_MIMETYPE_VIDEO_MPEG4,
@@ -750,9 +752,19 @@
         CHECK(msg->findInt32("sample-rate", &sampleRate));
 
         CHECK_EQ(setupAACDecoder(numChannels, sampleRate), (status_t)OK);
-    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) {
-    } else {
-        TRESPASS();
+    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB)) {
+        CHECK_EQ(setupAMRDecoder(false /* isWAMR */), (status_t)OK);
+    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) {
+        CHECK_EQ(setupAMRDecoder(true /* isWAMR */), (status_t)OK);
+    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_G711_ALAW)
+            || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_G711_MLAW)) {
+        // These are PCM-like formats with a fixed sample rate but
+        // a variable number of channels.
+
+        int32_t numChannels;
+        CHECK(msg->findInt32("channel-count", &numChannels));
+
+        CHECK_EQ(setupG711Decoder(numChannels), (status_t)OK);
     }
 
     int32_t maxInputSize;
@@ -824,6 +836,84 @@
     return err;
 }
 
+status_t ACodec::setupAMRDecoder(bool isWAMR) {
+    OMX_AUDIO_PARAM_AMRTYPE def;
+    InitOMXParams(&def);
+    def.nPortIndex = kPortIndexInput;
+
+    status_t err =
+        mOMX->getParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
+
+    if (err != OK) {
+        return err;
+    }
+
+    def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
+
+    def.eAMRBandMode =
+        isWAMR ? OMX_AUDIO_AMRBandModeWB0 : OMX_AUDIO_AMRBandModeNB0;
+
+    return mOMX->setParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
+}
+
+status_t ACodec::setupG711Decoder(int32_t numChannels) {
+    return setupRawAudioFormat(
+            kPortIndexInput, 8000 /* sampleRate */, numChannels);
+}
+
+status_t ACodec::setupRawAudioFormat(
+        OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels) {
+    OMX_PARAM_PORTDEFINITIONTYPE def;
+    InitOMXParams(&def);
+    def.nPortIndex = portIndex;
+
+    status_t err = mOMX->getParameter(
+            mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
+
+    if (err != OK) {
+        return err;
+    }
+
+    def.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
+
+    err = mOMX->setParameter(
+            mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
+
+    if (err != OK) {
+        return err;
+    }
+
+    OMX_AUDIO_PARAM_PCMMODETYPE pcmParams;
+    InitOMXParams(&pcmParams);
+    pcmParams.nPortIndex = portIndex;
+
+    err = mOMX->getParameter(
+            mNode, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));
+
+    if (err != OK) {
+        return err;
+    }
+
+    pcmParams.nChannels = numChannels;
+    pcmParams.eNumData = OMX_NumericalDataSigned;
+    pcmParams.bInterleaved = OMX_TRUE;
+    pcmParams.nBitPerSample = 16;
+    pcmParams.nSamplingRate = sampleRate;
+    pcmParams.ePCMMode = OMX_AUDIO_PCMModeLinear;
+
+    if (numChannels == 1) {
+        pcmParams.eChannelMapping[0] = OMX_AUDIO_ChannelCF;
+    } else {
+        CHECK_EQ(numChannels, 2);
+
+        pcmParams.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
+        pcmParams.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
+    }
+
+    return mOMX->setParameter(
+            mNode, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));
+}
+
 status_t ACodec::setVideoPortFormatType(
         OMX_U32 portIndex,
         OMX_VIDEO_CODINGTYPE compressionFormat,
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 9eb1469..e94a8d7 100755
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -1485,6 +1485,8 @@
             "audio_decoder.amrwb", "audio_encoder.amrwb" },
         { MEDIA_MIMETYPE_AUDIO_AAC,
             "audio_decoder.aac", "audio_encoder.aac" },
+        { MEDIA_MIMETYPE_AUDIO_VORBIS,
+            "audio_decoder.vorbis", "audio_encoder.vorbis" },
         { MEDIA_MIMETYPE_VIDEO_AVC,
             "video_decoder.avc", "video_encoder.avc" },
         { MEDIA_MIMETYPE_VIDEO_MPEG4,
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
index f3cf0f7..3fb2da0 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java
@@ -17,27 +17,26 @@
 package com.android.mediaframeworktest;
 
 import com.android.mediaframeworktest.functional.CameraTest;
-import com.android.mediaframeworktest.functional.MediaAudioTrackTest;
 import com.android.mediaframeworktest.functional.MediaMetadataTest;
 import com.android.mediaframeworktest.functional.MediaMimeTest;
-import com.android.mediaframeworktest.functional.MediaPlayerApiTest;
-import com.android.mediaframeworktest.functional.MediaRecorderTest;
-import com.android.mediaframeworktest.functional.SimTonesTest;
 import com.android.mediaframeworktest.functional.MediaPlayerInvokeTest;
-import com.android.mediaframeworktest.functional.MediaAudioManagerTest;
-import com.android.mediaframeworktest.functional.MediaAudioEffectTest;
-import com.android.mediaframeworktest.functional.MediaBassBoostTest;
-import com.android.mediaframeworktest.functional.MediaEnvReverbTest;
-import com.android.mediaframeworktest.functional.MediaEqualizerTest;
-import com.android.mediaframeworktest.functional.MediaPresetReverbTest;
-import com.android.mediaframeworktest.functional.MediaVirtualizerTest;
-import com.android.mediaframeworktest.functional.MediaVisualizerTest;
-/*import for VideoEditor Test cases*/
-import com.android.mediaframeworktest.functional.MediaItemThumbnailTest;
-import com.android.mediaframeworktest.functional.MediaPropertiesTest;
-import com.android.mediaframeworktest.functional.VideoEditorAPITest;
-import com.android.mediaframeworktest.functional.VideoEditorExportTest;
-import com.android.mediaframeworktest.functional.VideoEditorPreviewTest;
+import com.android.mediaframeworktest.functional.mediaplayback.MediaPlayerApiTest;
+import com.android.mediaframeworktest.functional.mediarecorder.MediaRecorderTest;
+import com.android.mediaframeworktest.functional.audio.SimTonesTest;
+import com.android.mediaframeworktest.functional.audio.MediaAudioTrackTest;
+import com.android.mediaframeworktest.functional.audio.MediaAudioManagerTest;
+import com.android.mediaframeworktest.functional.audio.MediaAudioEffectTest;
+import com.android.mediaframeworktest.functional.audio.MediaBassBoostTest;
+import com.android.mediaframeworktest.functional.audio.MediaEnvReverbTest;
+import com.android.mediaframeworktest.functional.audio.MediaEqualizerTest;
+import com.android.mediaframeworktest.functional.audio.MediaPresetReverbTest;
+import com.android.mediaframeworktest.functional.audio.MediaVirtualizerTest;
+import com.android.mediaframeworktest.functional.audio.MediaVisualizerTest;
+import com.android.mediaframeworktest.functional.videoeditor.MediaItemThumbnailTest;
+import com.android.mediaframeworktest.functional.videoeditor.MediaPropertiesTest;
+import com.android.mediaframeworktest.functional.videoeditor.VideoEditorAPITest;
+import com.android.mediaframeworktest.functional.videoeditor.VideoEditorExportTest;
+import com.android.mediaframeworktest.functional.videoeditor.VideoEditorPreviewTest;
 import junit.framework.TestSuite;
 
 import android.test.InstrumentationTestRunner;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioEffectTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioEffectTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioEffectTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioEffectTest.java
index 1511cd7..ab78714 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioEffectTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioEffectTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
@@ -1529,4 +1529,3 @@
     }
 
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioManagerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioManagerTest.java
similarity index 97%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioManagerTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioManagerTest.java
index 644444a..c9087d1 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioManagerTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioManagerTest.java
@@ -14,7 +14,7 @@
   * the License.
   */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import android.content.Context;
@@ -67,4 +67,4 @@
              assertTrue("SetRingtoneMode : " + ringtoneMode[i], result);
          }
      }
- }
\ No newline at end of file
+ }
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioTrackTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioTrackTest.java
index cea3a5a..e884aba 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioTrackTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
@@ -1250,4 +1250,3 @@
     }    
    
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaBassBoostTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java
similarity index 98%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaBassBoostTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java
index edc3e07..e3aa8cf 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaBassBoostTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
+import com.android.mediaframeworktest.functional.EnergyProbe;
 import android.content.Context;
 import android.content.res.AssetFileDescriptor;
 import android.media.audiofx.AudioEffect;
@@ -291,4 +292,3 @@
    }
 
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEnvReverbTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEnvReverbTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEnvReverbTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEnvReverbTest.java
index 79b90d0..3c8d05a 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEnvReverbTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEnvReverbTest.java
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
+import com.android.mediaframeworktest.functional.EnergyProbe;
 import android.content.Context;
 import android.content.res.AssetFileDescriptor;
 import android.media.audiofx.AudioEffect;
@@ -528,4 +529,3 @@
    }
 
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEqualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java
similarity index 98%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEqualizerTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java
index 459f551..ee91bbb 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEqualizerTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
+import com.android.mediaframeworktest.functional.EnergyProbe;
 import android.content.Context;
 import android.content.res.AssetFileDescriptor;
 import android.media.audiofx.AudioEffect;
@@ -354,4 +355,3 @@
    }
 
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPresetReverbTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaPresetReverbTest.java
similarity index 98%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPresetReverbTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaPresetReverbTest.java
index 8cc070e..757bbc5 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPresetReverbTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaPresetReverbTest.java
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
+import com.android.mediaframeworktest.functional.EnergyProbe;
 import android.content.Context;
 import android.content.res.AssetFileDescriptor;
 import android.media.audiofx.AudioEffect;
@@ -369,4 +370,3 @@
    }
 
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVirtualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java
similarity index 98%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVirtualizerTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java
index 3d3c011..b74e525 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVirtualizerTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
+import com.android.mediaframeworktest.functional.EnergyProbe;
 import android.content.Context;
 import android.content.res.AssetFileDescriptor;
 import android.media.audiofx.AudioEffect;
@@ -296,4 +297,3 @@
    }
 
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVisualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVisualizerTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java
index 0d5c6b4..e0cf51d 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVisualizerTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
@@ -506,4 +506,3 @@
     }
 
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/SimTonesTest.java
similarity index 94%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/SimTonesTest.java
index 241f8d6..aaf992c 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/SimTonesTest.java
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.audio;
 
 // import android.content.Resources;
 import com.android.mediaframeworktest.MediaFrameworkTest;
+import com.android.mediaframeworktest.functional.TonesAutoTest;
 
 import android.content.Context;
 import android.test.ActivityInstrumentationTestCase;
@@ -70,4 +71,3 @@
      assertTrue("Stress Tones", result);  
    }
 }
-
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediaplayback/MediaPlayerApiTest.java
similarity index 98%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediaplayback/MediaPlayerApiTest.java
index 57d5368..c501d3f 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediaplayback/MediaPlayerApiTest.java
@@ -14,11 +14,12 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.mediaplayback;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
 import com.android.mediaframeworktest.MediaProfileReader;
+import com.android.mediaframeworktest.functional.CodecTest;
 
 import android.content.Context;
 import android.test.ActivityInstrumentationTestCase;
@@ -31,16 +32,15 @@
 
 /**
  * Junit / Instrumentation test case for the media player api
- 
- */  
-public class MediaPlayerApiTest extends ActivityInstrumentationTestCase<MediaFrameworkTest> {    
+ */
+public class MediaPlayerApiTest extends ActivityInstrumentationTestCase<MediaFrameworkTest> {
    private boolean duratoinWithinTolerence = false;
    private String TAG = "MediaPlayerApiTest";
    private boolean isWMAEnable = false;
    private boolean isWMVEnable = false;
-   
+
    Context mContext;
-  
+
    public MediaPlayerApiTest() {
      super("com.android.mediaframeworktest", MediaFrameworkTest.class);
      isWMAEnable = MediaProfileReader.getWMAEnable();
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediarecorder/MediaRecorderTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediarecorder/MediaRecorderTest.java
index 796b52c..b5c8c8c 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediarecorder/MediaRecorderTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.mediarecorder;
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 import com.android.mediaframeworktest.MediaNames;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaItemThumbnailTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaItemThumbnailTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaItemThumbnailTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaItemThumbnailTest.java
index d5b67aa..80a3bcd 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaItemThumbnailTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaItemThumbnailTest.java
@@ -15,7 +15,7 @@
  */
 
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.videoeditor;
 
 import java.io.File;
 import java.io.IOException;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPropertiesTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaPropertiesTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPropertiesTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaPropertiesTest.java
index 0ad6760..e2f6863 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPropertiesTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaPropertiesTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.videoeditor;
 
 import java.io.File;
 import java.io.IOException;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorAPITest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorAPITest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorAPITest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorAPITest.java
index 2a02b58..b32d865 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorAPITest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorAPITest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.videoeditor;
 
 import java.io.File;
 import java.util.List;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorExportTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorExportTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorExportTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorExportTest.java
index e1b337d..57a1c75 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorExportTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorExportTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.videoeditor;
 
 import java.io.File;
 
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorPreviewTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorPreviewTest.java
similarity index 99%
rename from media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorPreviewTest.java
rename to media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorPreviewTest.java
index 9a7f4f2..e848f5f 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorPreviewTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorPreviewTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.mediaframeworktest.functional;
+package com.android.mediaframeworktest.functional.videoeditor;
 
 import java.io.File;
 import java.io.IOException;
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java b/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
index ec24f97..10cf3aa 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
@@ -593,4 +593,7 @@
         return mClockVisible;
     }
 
+    public int getPhoneState() {
+        return mPhoneState;
+    }
 }
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java b/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
index 2fcf1dc3..74dde9c 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
@@ -127,15 +127,6 @@
      */
     abstract public void cleanUp();
 
-    /**
-     * These were added to support FaceLock because the KeyguardViewManager needs to tell the 
-     * LockPatternKeyguardView when to bind and and unbind with FaceLock service.  Although
-     * implemented in LockPatternKeyguardView, these are not implemented in anything else
-     * derived from KeyguardViewBase
-     */
-    abstract public void bindToFaceLock();
-    abstract public void stopAndUnbindFromFaceLock();
-
     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
         if (shouldEventKeepScreenOnWhileKeyguardShowing(event)) {
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java b/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
index 91f1527..f15812b 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
@@ -205,9 +205,6 @@
         mScreenOn = false;
         if (mKeyguardView != null) {
             mKeyguardView.onScreenTurnedOff();
-
-            // When screen is turned off, need to unbind from FaceLock service if using FaceLock
-            mKeyguardView.stopAndUnbindFromFaceLock();
         }
     }
 
@@ -218,9 +215,6 @@
         if (mKeyguardView != null) {
             mKeyguardView.onScreenTurnedOn();
 
-            // When screen is turned on, need to bind to FaceLock service if we are using FaceLock
-            mKeyguardView.bindToFaceLock();
-
             // Caller should wait for this window to be shown before turning
             // on the screen.
             if (mKeyguardHost.getVisibility() == View.VISIBLE) {
@@ -277,12 +271,6 @@
     public synchronized void hide() {
         if (DEBUG) Log.d(TAG, "hide()");
 
-        if (mKeyguardView != null) {
-            // When view is hidden, need to unbind from FaceLock service if we are using FaceLock
-            // e.g., when device becomes unlocked
-            mKeyguardView.stopAndUnbindFromFaceLock();
-        }
-
         if (mKeyguardHost != null) {
             mKeyguardHost.setVisibility(View.GONE);
             // Don't do this right away, so we can let the view continue to animate
diff --git a/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
index ffb4838..f24991c 100644
--- a/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
+++ b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
@@ -504,6 +504,9 @@
         } else {
             ((KeyguardScreen) mUnlockScreen).onPause();
         }
+
+        // When screen is turned off, need to unbind from FaceLock service if using FaceLock
+        stopAndUnbindFromFaceLock();
     }
 
     @Override
@@ -514,6 +517,14 @@
         } else {
             ((KeyguardScreen) mUnlockScreen).onResume();
         }
+
+        // When screen is turned on, need to bind to FaceLock service if we are using FaceLock
+        // But only if not dealing with a call
+        if (mUpdateMonitor.getPhoneState() == TelephonyManager.CALL_STATE_IDLE) {
+            bindToFaceLock();
+        } else {
+            mHandler.sendEmptyMessage(MSG_HIDE_FACELOCK_AREA_VIEW);
+        }
     }
 
     private void recreateLockScreen() {
@@ -543,6 +554,11 @@
     @Override
     protected void onDetachedFromWindow() {
         removeCallbacks(mRecreateRunnable);
+
+        // When view is hidden, need to unbind from FaceLock service if we are using FaceLock
+        // e.g., when device becomes unlocked
+        stopAndUnbindFromFaceLock();
+
         super.onDetachedFromWindow();
     }
 
@@ -952,8 +968,9 @@
     // Everything below pertains to FaceLock - might want to separate this out
 
     // Only pattern and pin unlock screens actually have a view for the FaceLock area, so it's not
-    // uncommon for it to not exist.  But if it does exist, we need to make sure it's showing if
-    // FaceLock is enabled, and make sure it's not showing if FaceLock is disabled
+    // uncommon for it to not exist.  But if it does exist, we need to make sure it's shown (hiding
+    // the fallback) if FaceLock is enabled, and make sure it's hidden (showing the unlock) if
+    // FaceLock is disabled
     private void initializeFaceLockAreaView(View view) {
         mFaceLockAreaView = view.findViewById(R.id.faceLockAreaView);
         if (mFaceLockAreaView == null) {
@@ -997,9 +1014,7 @@
                 if (DEBUG) Log.d(TAG, "after bind to FaceLock service");
                 mBoundToFaceLockService = true;
             } else {
-                // On startup I've seen onScreenTurnedOn() get called twice without
-                // onScreenTurnedOff() being called in between, which can cause this (bcolonna)
-                if (DEBUG) Log.w(TAG, "Attempt to bind to FaceLock when already bound");
+                Log.w(TAG, "Attempt to bind to FaceLock when already bound");
             }
         }
     }
@@ -1017,7 +1032,7 @@
             } else {
                 // This could probably happen after the session when someone activates FaceLock
                 // because it wasn't active when the phone was turned on
-                if (DEBUG) Log.w(TAG, "Attempt to unbind from FaceLock when not bound");
+                Log.w(TAG, "Attempt to unbind from FaceLock when not bound");
             }
         }
     }
@@ -1048,7 +1063,7 @@
                 mFaceLockService = null;
                 mFaceLockServiceRunning = false;
             }
-            if (DEBUG) Log.w(TAG, "Unexpected disconnect from FaceLock service");
+            Log.w(TAG, "Unexpected disconnect from FaceLock service");
         }
     };
 
@@ -1099,36 +1114,21 @@
         // Stops the FaceLock UI and indicates that the phone should be unlocked
         @Override
         public void unlock() {
-            if (DEBUG) Log.d(TAG, "FaceLock unlock");
-            // Note that we don't hide the client FaceLockAreaView because we want to keep the
-            // lock screen covered while the phone is unlocked
-
+            if (DEBUG) Log.d(TAG, "FaceLock unlock()");
+            mHandler.sendEmptyMessage(MSG_SHOW_FACELOCK_AREA_VIEW); // Keep fallback covered
             stopFaceLock();
+
             mKeyguardScreenCallback.keyguardDone(true);
             mKeyguardScreenCallback.reportSuccessfulUnlockAttempt();
         }
 
         // Stops the FaceLock UI and exposes the backup method without unlocking
+        // This means either the user has cancelled out or FaceLock failed to recognize them
         @Override
         public void cancel() {
-            // In this case, either the user has cancelled out, or FaceLock failed to recognize them
-            if (DEBUG) Log.d(TAG, "FaceLock cancel");
-            // Here we hide the client FaceLockViewArea to expose the underlying backup method
-            mHandler.sendEmptyMessage(MSG_HIDE_FACELOCK_AREA_VIEW);
+            if (DEBUG) Log.d(TAG, "FaceLock cancel()");
+            mHandler.sendEmptyMessage(MSG_HIDE_FACELOCK_AREA_VIEW); // Expose fallback
             stopFaceLock();
         }
-
-        // Stops the FaceLock UI and puts the phone to sleep
-        @Override
-        public void sleepDevice() {
-            // In this case, it appears the phone has been turned on accidentally
-            if (DEBUG) Log.d(TAG, "FaceLock accidental turn on");
-            // Here we hide the client FaceLockViewArea to expose the underlying backup method
-            mHandler.sendEmptyMessage(MSG_HIDE_FACELOCK_AREA_VIEW);
-            stopFaceLock();
-            // TODO(bcolonna): how do we put the phone back to sleep (i.e., turn off the screen)
-            // TODO(bcolonna): this should be removed once the service is no longer calling it
-            // because we are just going to let the lockscreen timeout
-        }
     };
 }
diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java
index ea349bf..34f8848 100644
--- a/telephony/java/android/telephony/PhoneNumberUtils.java
+++ b/telephony/java/android/telephony/PhoneNumberUtils.java
@@ -1409,6 +1409,11 @@
      * @hide
      */
     public static String formatNumber(String phoneNumber, String defaultCountryIso) {
+        // Do not attempt to format numbers that start with a hash or star symbol.
+        if (phoneNumber.startsWith("#") || phoneNumber.startsWith("*")) {
+            return phoneNumber;
+        }
+
         PhoneNumberUtil util = PhoneNumberUtil.getInstance();
         String result = null;
         try {
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
index 849ff48..e2349af 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
@@ -513,7 +513,19 @@
         assertEquals("(650) 291-0000", PhoneNumberUtils.formatNumber("650 2910000", "US"));
         assertEquals("123-4567", PhoneNumberUtils.formatNumber("1234567", "US"));
         assertEquals("(800) 466-4114", PhoneNumberUtils.formatNumber("800-GOOG-114", "US"));
+    }
 
+    @SmallTest
+    public void testFormatNumber_LeadingStarAndHash() {
+        // Numbers with a leading '*' or '#' should be left unchanged.
+        assertEquals("*650 2910000", PhoneNumberUtils.formatNumber("*650 2910000", "US"));
+        assertEquals("#650 2910000", PhoneNumberUtils.formatNumber("#650 2910000", "US"));
+        assertEquals("*#650 2910000", PhoneNumberUtils.formatNumber("*#650 2910000", "US"));
+        assertEquals("#*650 2910000", PhoneNumberUtils.formatNumber("#*650 2910000", "US"));
+        assertEquals("#650*2910000", PhoneNumberUtils.formatNumber("#650*2910000", "US"));
+        assertEquals("#650*2910000", PhoneNumberUtils.formatNumber("#650*2910000", "US"));
+        assertEquals("##650 2910000", PhoneNumberUtils.formatNumber("##650 2910000", "US"));
+        assertEquals("**650 2910000", PhoneNumberUtils.formatNumber("**650 2910000", "US"));
     }
 
     @SmallTest