am ab30f486: am fa8570bc: am 7026617e: am 1fcb6d3a: Merge "Respect style boundaries when measuring text" into mnc-dev

* commit 'ab30f486ba553d547aac0ff48d87cf307de2871d':
  Respect style boundaries when measuring text
diff --git a/Android.mk b/Android.mk
index a7a2ecb..7757d50 100644
--- a/Android.mk
+++ b/Android.mk
@@ -762,7 +762,8 @@
 	$(foreach lib,$(FRAMEWORKS_SUPPORT_JAVA_LIBRARIES),$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib)-res,,COMMON))
 
 framework_docs_LOCAL_ADDITIONAL_DEPENDENCIES := \
-    frameworks/base/docs/knowntags.txt
+    frameworks/base/docs/knowntags.txt \
+    libcore/Docs.mk
 
 samples_dir := development/samples/browseable
 
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 9f4bc52..2df3ed4 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -105,7 +105,7 @@
                 "usage: am [subcommand] [options]\n" +
                 "usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]\n" +
                 "               [--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace]\n" +
-                "               [--user <USER_ID> | current] <INTENT>\n" +
+                "               [--track-allocation] [--user <USER_ID> | current] <INTENT>\n" +
                 "       am startservice [--user <USER_ID> | current] <INTENT>\n" +
                 "       am stopservice [--user <USER_ID> | current] <INTENT>\n" +
                 "       am force-stop [--user <USER_ID> | all | current] <PACKAGE>\n" +
@@ -161,6 +161,7 @@
                 "        the top activity will be finished.\n" +
                 "    -S: force stop the target app before starting the activity\n" +
                 "    --opengl-trace: enable tracing of OpenGL functions\n" +
+                "    --track-allocation: enable tracking of object allocations\n" +
                 "    --user <USER_ID> | current: Specify which user to run as; if not\n" +
                 "        specified then run as the current user.\n" +
                 "\n" +
@@ -689,6 +690,8 @@
                 mStopOption = true;
             } else if (opt.equals("--opengl-trace")) {
                 mStartFlags |= ActivityManager.START_FLAG_OPENGL_TRACES;
+            } else if (opt.equals("--track-allocation")) {
+                mStartFlags |= ActivityManager.START_FLAG_TRACK_ALLOCATION;
             } else if (opt.equals("--user")) {
                 mUserId = parseUserArg(nextArgRequired());
             } else if (opt.equals("--receiver-permission")) {
diff --git a/cmds/app_process/Android.mk b/cmds/app_process/Android.mk
index 7ce0846..51bbb81 100644
--- a/cmds/app_process/Android.mk
+++ b/cmds/app_process/Android.mk
@@ -65,7 +65,7 @@
 LOCAL_MODULE_STEM_32 := app_process32
 LOCAL_MODULE_STEM_64 := app_process64
 
-LOCAL_ADDRESS_SANITIZER := true
+LOCAL_SANITIZE := address
 LOCAL_CLANG := true
 LOCAL_MODULE_PATH := $(TARGET_OUT_EXECUTABLES)/asan
 
diff --git a/cmds/input/src/com/android/commands/input/Input.java b/cmds/input/src/com/android/commands/input/Input.java
index 2a7c79b..754d3f5 100644
--- a/cmds/input/src/com/android/commands/input/Input.java
+++ b/cmds/input/src/com/android/commands/input/Input.java
@@ -234,6 +234,18 @@
                 InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
     }
 
+    private int getInputDeviceId(int inputSource) {
+        final int DEFAULT_DEVICE_ID = 0;
+        int[] devIds = InputDevice.getDeviceIds();
+        for (int devId : devIds) {
+            InputDevice inputDev = InputDevice.getDevice(devId);
+            if (inputDev.supportsSource(inputSource)) {
+                return devId;
+            }
+        }
+        return DEFAULT_DEVICE_ID;
+    }
+
     /**
      * Builds a MotionEvent and injects it into the event stream.
      *
@@ -249,11 +261,10 @@
         final int DEFAULT_META_STATE = 0;
         final float DEFAULT_PRECISION_X = 1.0f;
         final float DEFAULT_PRECISION_Y = 1.0f;
-        final int DEFAULT_DEVICE_ID = 0;
         final int DEFAULT_EDGE_FLAGS = 0;
         MotionEvent event = MotionEvent.obtain(when, when, action, x, y, pressure, DEFAULT_SIZE,
-                DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y, DEFAULT_DEVICE_ID,
-                DEFAULT_EDGE_FLAGS);
+                DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y,
+                getInputDeviceId(inputSource), DEFAULT_EDGE_FLAGS);
         event.setSource(inputSource);
         Log.i(TAG, "injectMotionEvent: " + event);
         InputManager.getInstance().injectInputEvent(event,
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 55b2fd9..44c1554 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -210,6 +210,13 @@
     public static final int START_FLAG_OPENGL_TRACES = 1<<2;
 
     /**
+     * Flag for IActivityManaqer.startActivity: launch the app for
+     * allocation tracking.
+     * @hide
+     */
+    public static final int START_FLAG_TRACK_ALLOCATION = 1<<3;
+
+    /**
      * Result for IActivityManaqer.broadcastIntent: success!
      * @hide
      */
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 2b4d03b..6bb3ff9 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -132,6 +132,7 @@
 import dalvik.system.CloseGuard;
 import dalvik.system.VMDebug;
 import dalvik.system.VMRuntime;
+import org.apache.harmony.dalvik.ddmc.DdmVmInternal;
 
 final class RemoteServiceException extends AndroidRuntimeException {
     public RemoteServiceException(String msg) {
@@ -445,6 +446,7 @@
         IUiAutomationConnection instrumentationUiAutomationConnection;
         int debugMode;
         boolean enableOpenGlTrace;
+        boolean trackAllocation;
         boolean restrictedBackupMode;
         boolean persistent;
         Configuration config;
@@ -769,9 +771,9 @@
                 ProfilerInfo profilerInfo, Bundle instrumentationArgs,
                 IInstrumentationWatcher instrumentationWatcher,
                 IUiAutomationConnection instrumentationUiConnection, int debugMode,
-                boolean enableOpenGlTrace, boolean isRestrictedBackupMode, boolean persistent,
-                Configuration config, CompatibilityInfo compatInfo, Map<String, IBinder> services,
-                Bundle coreSettings) {
+                boolean enableOpenGlTrace, boolean trackAllocation, boolean isRestrictedBackupMode,
+                boolean persistent, Configuration config, CompatibilityInfo compatInfo,
+                Map<String, IBinder> services, Bundle coreSettings) {
 
             if (services != null) {
                 // Setup the service cache in the ServiceManager
@@ -827,6 +829,7 @@
             data.instrumentationUiAutomationConnection = instrumentationUiConnection;
             data.debugMode = debugMode;
             data.enableOpenGlTrace = enableOpenGlTrace;
+            data.trackAllocation = trackAllocation;
             data.restrictedBackupMode = isRestrictedBackupMode;
             data.persistent = persistent;
             data.config = config;
@@ -988,7 +991,7 @@
             long nativeFree = Debug.getNativeHeapFreeSize() / 1024;
 
             Runtime runtime = Runtime.getRuntime();
-
+            runtime.gc();  // Do GC since countInstancesOfClass counts unreachable objects.
             long dalvikMax = runtime.totalMemory() / 1024;
             long dalvikFree = runtime.freeMemory() / 1024;
             long dalvikAllocated = dalvikMax - dalvikFree;
@@ -4432,6 +4435,10 @@
     }
 
     private void handleBindApplication(AppBindData data) {
+        if (data.trackAllocation) {
+            DdmVmInternal.enableRecentAllocations(true);
+        }
+
         mBoundApplication = data;
         mConfiguration = new Configuration(data.config);
         mCompatConfiguration = new Configuration(data.config);
diff --git a/core/java/android/app/AlarmManager.java b/core/java/android/app/AlarmManager.java
index dc83a01..1de8f98 100644
--- a/core/java/android/app/AlarmManager.java
+++ b/core/java/android/app/AlarmManager.java
@@ -823,7 +823,7 @@
         }
 
         /**
-         * Returns an intent intent that can be used to show or edit details of the alarm clock in
+         * Returns an intent that can be used to show or edit details of the alarm clock in
          * the application that scheduled it.
          *
          * <p class="note">Beware that any application can retrieve and send this intent, 
diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java
index e178087..b9ebd9f 100644
--- a/core/java/android/app/ApplicationThreadNative.java
+++ b/core/java/android/app/ApplicationThreadNative.java
@@ -292,6 +292,7 @@
                     IUiAutomationConnection.Stub.asInterface(binder);
             int testMode = data.readInt();
             boolean openGlTrace = data.readInt() != 0;
+            boolean trackAllocation = data.readInt() != 0;
             boolean restrictedBackupMode = (data.readInt() != 0);
             boolean persistent = (data.readInt() != 0);
             Configuration config = Configuration.CREATOR.createFromParcel(data);
@@ -299,7 +300,7 @@
             HashMap<String, IBinder> services = data.readHashMap(null);
             Bundle coreSettings = data.readBundle();
             bindApplication(packageName, info, providers, testName, profilerInfo, testArgs,
-                    testWatcher, uiAutomationConnection, testMode, openGlTrace,
+                    testWatcher, uiAutomationConnection, testMode, openGlTrace, trackAllocation,
                     restrictedBackupMode, persistent, config, compatInfo, services, coreSettings);
             return true;
         }
@@ -987,13 +988,14 @@
         data.recycle();
     }
 
+    @Override
     public final void bindApplication(String packageName, ApplicationInfo info,
             List<ProviderInfo> providers, ComponentName testName, ProfilerInfo profilerInfo,
             Bundle testArgs, IInstrumentationWatcher testWatcher,
             IUiAutomationConnection uiAutomationConnection, int debugMode,
-            boolean openGlTrace, boolean restrictedBackupMode, boolean persistent,
-            Configuration config, CompatibilityInfo compatInfo, Map<String, IBinder> services,
-            Bundle coreSettings) throws RemoteException {
+            boolean openGlTrace, boolean trackAllocation, boolean restrictedBackupMode,
+            boolean persistent, Configuration config, CompatibilityInfo compatInfo,
+            Map<String, IBinder> services, Bundle coreSettings) throws RemoteException {
         Parcel data = Parcel.obtain();
         data.writeInterfaceToken(IApplicationThread.descriptor);
         data.writeString(packageName);
@@ -1016,6 +1018,7 @@
         data.writeStrongInterface(uiAutomationConnection);
         data.writeInt(debugMode);
         data.writeInt(openGlTrace ? 1 : 0);
+        data.writeInt(trackAllocation ? 1 : 0);
         data.writeInt(restrictedBackupMode ? 1 : 0);
         data.writeInt(persistent ? 1 : 0);
         config.writeToParcel(data, 0);
diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java
index 185578f..e204d50 100644
--- a/core/java/android/app/IApplicationThread.java
+++ b/core/java/android/app/IApplicationThread.java
@@ -95,8 +95,9 @@
     void bindApplication(String packageName, ApplicationInfo info, List<ProviderInfo> providers,
             ComponentName testName, ProfilerInfo profilerInfo, Bundle testArguments,
             IInstrumentationWatcher testWatcher, IUiAutomationConnection uiAutomationConnection,
-            int debugMode, boolean openGlTrace, boolean restrictedBackupMode, boolean persistent,
-            Configuration config, CompatibilityInfo compatInfo, Map<String, IBinder> services,
+            int debugMode, boolean openGlTrace, boolean trackAllocation,
+            boolean restrictedBackupMode, boolean persistent, Configuration config,
+            CompatibilityInfo compatInfo, Map<String, IBinder> services,
             Bundle coreSettings) throws RemoteException;
     void scheduleExit() throws RemoteException;
     void scheduleSuicide() throws RemoteException;
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 731903c..788aee9 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -20,6 +20,7 @@
 import android.annotation.ColorInt;
 import android.annotation.StyleRes;
 import android.annotation.StyleableRes;
+import android.icu.text.PluralRules;
 import com.android.internal.util.GrowingArrayUtils;
 import com.android.internal.util.XmlUtils;
 
@@ -68,8 +69,6 @@
 import java.lang.ref.WeakReference;
 import java.util.Locale;
 
-import libcore.icu.NativePluralRules;
-
 /**
  * Class for accessing an application's resources.  This sits on top of the
  * asset manager of the application (accessible through {@link #getAssets}) and
@@ -154,7 +153,7 @@
     final DisplayMetrics mMetrics = new DisplayMetrics();
 
     private final Configuration mConfiguration = new Configuration();
-    private NativePluralRules mPluralRule;
+    private PluralRules mPluralRule;
 
     private CompatibilityInfo mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
 
@@ -335,9 +334,9 @@
      */
     public CharSequence getQuantityText(@PluralsRes int id, int quantity)
             throws NotFoundException {
-        NativePluralRules rule = getPluralRule();
+        PluralRules rule = getPluralRule();
         CharSequence res = mAssets.getResourceBagText(id,
-                attrForQuantityCode(rule.quantityForInt(quantity)));
+                attrForQuantityCode(rule.select(quantity)));
         if (res != null) {
             return res;
         }
@@ -347,40 +346,29 @@
         }
         throw new NotFoundException("Plural resource ID #0x" + Integer.toHexString(id)
                 + " quantity=" + quantity
-                + " item=" + stringForQuantityCode(rule.quantityForInt(quantity)));
+                + " item=" + rule.select(quantity));
     }
 
-    private NativePluralRules getPluralRule() {
+    private PluralRules getPluralRule() {
         synchronized (sSync) {
             if (mPluralRule == null) {
-                mPluralRule = NativePluralRules.forLocale(mConfiguration.locale);
+                mPluralRule = PluralRules.forLocale(mConfiguration.locale);
             }
             return mPluralRule;
         }
     }
 
-    private static int attrForQuantityCode(int quantityCode) {
+    private static int attrForQuantityCode(String quantityCode) {
         switch (quantityCode) {
-            case NativePluralRules.ZERO: return 0x01000005;
-            case NativePluralRules.ONE:  return 0x01000006;
-            case NativePluralRules.TWO:  return 0x01000007;
-            case NativePluralRules.FEW:  return 0x01000008;
-            case NativePluralRules.MANY: return 0x01000009;
+            case PluralRules.KEYWORD_ZERO: return 0x01000005;
+            case PluralRules.KEYWORD_ONE:  return 0x01000006;
+            case PluralRules.KEYWORD_TWO:  return 0x01000007;
+            case PluralRules.KEYWORD_FEW:  return 0x01000008;
+            case PluralRules.KEYWORD_MANY: return 0x01000009;
             default:                     return ID_OTHER;
         }
     }
 
-    private static String stringForQuantityCode(int quantityCode) {
-        switch (quantityCode) {
-            case NativePluralRules.ZERO: return "zero";
-            case NativePluralRules.ONE:  return "one";
-            case NativePluralRules.TWO:  return "two";
-            case NativePluralRules.FEW:  return "few";
-            case NativePluralRules.MANY: return "many";
-            default:                     return "other";
-        }
-    }
-
     /**
      * Return the string value associated with a particular resource ID.  It
      * will be stripped of any styled text information.
@@ -2059,7 +2047,7 @@
         }
         synchronized (sSync) {
             if (mPluralRule != null) {
-                mPluralRule = NativePluralRules.forLocale(config.locale);
+                mPluralRule = PluralRules.forLocale(config.locale);
             }
         }
     }
diff --git a/core/java/android/net/LocalSocketImpl.java b/core/java/android/net/LocalSocketImpl.java
index fa9f479..b83fb26 100644
--- a/core/java/android/net/LocalSocketImpl.java
+++ b/core/java/android/net/LocalSocketImpl.java
@@ -25,6 +25,9 @@
 import android.system.ErrnoException;
 import android.system.Os;
 import android.system.OsConstants;
+import android.system.StructLinger;
+import android.system.StructTimeval;
+import android.util.MutableInt;
 
 /**
  * Socket implementation used for android.net.LocalSocket and
@@ -59,7 +62,13 @@
             FileDescriptor myFd = fd;
             if (myFd == null) throw new IOException("socket closed");
 
-            return available_native(myFd);
+            MutableInt avail = new MutableInt(0);
+            try {
+                Os.ioctlInt(myFd, OsConstants.FIONREAD, avail);
+            } catch (ErrnoException e) {
+                throw e.rethrowAsIOException();
+            }
+            return avail.value;
         }
 
         /** {@inheritDoc} */
@@ -156,18 +165,31 @@
         public void flush() throws IOException {
             FileDescriptor myFd = fd;
             if (myFd == null) throw new IOException("socket closed");
-            while(pending_native(myFd) > 0) {
+
+            // Loop until the output buffer is empty.
+            MutableInt pending = new MutableInt(0);
+            while (true) {
+                try {
+                    // See linux/net/unix/af_unix.c
+                    Os.ioctlInt(myFd, OsConstants.TIOCOUTQ, pending);
+                } catch (ErrnoException e) {
+                    throw e.rethrowAsIOException();
+                }
+
+                if (pending.value <= 0) {
+                    // The output buffer is empty.
+                    break;
+                }
+
                 try {
                     Thread.sleep(10);
                 } catch (InterruptedException ie) {
-                    return;
+                    break;
                 }
             }
         }
     }
 
-    private native int pending_native(FileDescriptor fd) throws IOException;
-    private native int available_native(FileDescriptor fd) throws IOException;
     private native int read_native(FileDescriptor fd) throws IOException;
     private native int readba_native(byte[] b, int off, int len,
             FileDescriptor fd) throws IOException;
@@ -179,28 +201,8 @@
             int namespace) throws IOException;
     private native void bindLocal(FileDescriptor fd, String name, int namespace)
             throws IOException;
-    private native void listen_native(FileDescriptor fd, int backlog)
-            throws IOException;
-    private native void shutdown(FileDescriptor fd, boolean shutdownInput);
     private native Credentials getPeerCredentials_native(
             FileDescriptor fd) throws IOException;
-    private native int getOption_native(FileDescriptor fd, int optID)
-            throws IOException;
-    private native void setOption_native(FileDescriptor fd, int optID,
-            int b, int value) throws IOException;
-
-//    private native LocalSocketAddress getSockName_native
-//            (FileDescriptor fd) throws IOException;
-
-    /**
-     * Accepts a connection on a server socket.
-     *
-     * @param fd file descriptor of server socket
-     * @param s socket implementation that will become the new socket
-     * @return file descriptor of new socket
-     */
-    private native FileDescriptor accept
-            (FileDescriptor fd, LocalSocketImpl s) throws IOException;
 
     /**
      * Create a new instance.
@@ -232,7 +234,7 @@
      * or {@link LocalSocket#SOCKET_SEQPACKET}
      * @throws IOException
      */
-    public void create (int sockType) throws IOException {
+    public void create(int sockType) throws IOException {
         // no error if socket already created
         // need this for LocalServerSocket.accept()
         if (fd == null) {
@@ -311,8 +313,11 @@
         if (fd == null) {
             throw new IOException("socket not created");
         }
-
-        listen_native(fd, backlog);
+        try {
+            Os.listen(fd, backlog);
+        } catch (ErrnoException e) {
+            throw e.rethrowAsIOException();
+        }
     }
 
     /**
@@ -322,14 +327,17 @@
      * @param s a socket that will be used to represent the new connection.
      * @throws IOException
      */
-    protected void accept(LocalSocketImpl s) throws IOException
-    {
+    protected void accept(LocalSocketImpl s) throws IOException {
         if (fd == null) {
             throw new IOException("socket not created");
         }
 
-        s.fd = accept(fd, s);
-        s.mFdCreatedInternally = true;
+        try {
+            s.fd = Os.accept(fd, null /* address */);
+            s.mFdCreatedInternally = true;
+        } catch (ErrnoException e) {
+            throw e.rethrowAsIOException();
+        }
     }
 
     /**
@@ -396,7 +404,11 @@
             throw new IOException("socket not created");
         }
 
-        shutdown(fd, true);
+        try {
+            Os.shutdown(fd, OsConstants.SHUT_RD);
+        } catch (ErrnoException e) {
+            throw e.rethrowAsIOException();
+        }
     }
 
     /**
@@ -410,7 +422,11 @@
             throw new IOException("socket not created");
         }
 
-        shutdown(fd, false);
+        try {
+            Os.shutdown(fd, OsConstants.SHUT_WR);
+        } catch (ErrnoException e) {
+            throw e.rethrowAsIOException();
+        }
     }
 
     protected FileDescriptor getFileDescriptor()
@@ -434,24 +450,49 @@
             throw new IOException("socket not created");
         }
 
-        if (optID == SocketOptions.SO_TIMEOUT) {
-            return 0;
-        }
-        
-        int value = getOption_native(fd, optID);
-        switch (optID)
-        {
-            case SocketOptions.SO_RCVBUF:
-            case SocketOptions.SO_SNDBUF:
-                return value;
-            case SocketOptions.SO_REUSEADDR:
-            default:
-                return value;
+        try {
+            Object toReturn;
+            switch (optID) {
+                case SocketOptions.SO_TIMEOUT:
+                    StructTimeval timeval = Os.getsockoptTimeval(fd, OsConstants.SOL_SOCKET,
+                            OsConstants.SO_SNDTIMEO);
+                    toReturn = (int) timeval.toMillis();
+                    break;
+                case SocketOptions.SO_RCVBUF:
+                case SocketOptions.SO_SNDBUF:
+                case SocketOptions.SO_REUSEADDR:
+                    int osOpt = javaSoToOsOpt(optID);
+                    toReturn = Os.getsockoptInt(fd, OsConstants.SOL_SOCKET, osOpt);
+                    break;
+                case SocketOptions.SO_LINGER:
+                    StructLinger linger=
+                            Os.getsockoptLinger(fd, OsConstants.SOL_SOCKET, OsConstants.SO_LINGER);
+                    if (!linger.isOn()) {
+                        toReturn = -1;
+                    } else {
+                        toReturn = linger.l_linger;
+                    }
+                    break;
+                case SocketOptions.TCP_NODELAY:
+                    toReturn = Os.getsockoptInt(fd, OsConstants.IPPROTO_TCP,
+                            OsConstants.TCP_NODELAY);
+                    break;
+                default:
+                    throw new IOException("Unknown option: " + optID);
+            }
+            return toReturn;
+        } catch (ErrnoException e) {
+            throw e.rethrowAsIOException();
         }
     }
 
     public void setOption(int optID, Object value)
             throws IOException {
+
+        if (fd == null) {
+            throw new IOException("socket not created");
+        }
+
         /*
          * Boolean.FALSE is used to disable some options, so it
          * is important to distinguish between FALSE and unset.
@@ -460,11 +501,6 @@
          */
         int boolValue = -1;
         int intValue = 0;
-
-        if (fd == null) {
-            throw new IOException("socket not created");
-        }
-
         if (value instanceof Integer) {
             intValue = (Integer)value;
         } else if (value instanceof Boolean) {
@@ -473,7 +509,39 @@
             throw new IOException("bad value: " + value);
         }
 
-        setOption_native(fd, optID, boolValue, intValue);
+        try {
+            switch (optID) {
+                case SocketOptions.SO_LINGER:
+                    StructLinger linger = new StructLinger(boolValue, intValue);
+                    Os.setsockoptLinger(fd, OsConstants.SOL_SOCKET, OsConstants.SO_LINGER, linger);
+                    break;
+                case SocketOptions.SO_TIMEOUT:
+                    /*
+                     * SO_TIMEOUT from the core library gets converted to
+                     * SO_SNDTIMEO, but the option is supposed to set both
+                     * send and receive timeouts. Note: The incoming timeout
+                     * value is in milliseconds.
+                     */
+                    StructTimeval timeval = StructTimeval.fromMillis(intValue);
+                    Os.setsockoptTimeval(fd, OsConstants.SOL_SOCKET, OsConstants.SO_SNDTIMEO,
+                            timeval);
+                    break;
+                case SocketOptions.SO_RCVBUF:
+                case SocketOptions.SO_SNDBUF:
+                case SocketOptions.SO_REUSEADDR:
+                    int osOpt = javaSoToOsOpt(optID);
+                    Os.setsockoptInt(fd, OsConstants.SOL_SOCKET, osOpt, intValue);
+                    break;
+                case SocketOptions.TCP_NODELAY:
+                    Os.setsockoptInt(fd, OsConstants.IPPROTO_TCP, OsConstants.TCP_NODELAY,
+                            intValue);
+                    break;
+                default:
+                    throw new IOException("Unknown option: " + optID);
+            }
+        } catch (ErrnoException e) {
+            throw e.rethrowAsIOException();
+        }
     }
 
     /**
@@ -517,8 +585,7 @@
      * @return non-null; peer credentials
      * @throws IOException
      */
-    public Credentials getPeerCredentials() throws IOException
-    {
+    public Credentials getPeerCredentials() throws IOException {
         return getPeerCredentials_native(fd);
     }
 
@@ -528,15 +595,26 @@
      * @return non-null; socket name
      * @throws IOException on failure
      */
-    public LocalSocketAddress getSockAddress() throws IOException
-    {
+    public LocalSocketAddress getSockAddress() throws IOException {
+        // This method has never been implemented.
         return null;
-        //TODO implement this
-        //return getSockName_native(fd);
     }
 
     @Override
     protected void finalize() throws IOException {
         close();
     }
+
+    private static int javaSoToOsOpt(int optID) {
+        switch (optID) {
+            case SocketOptions.SO_SNDBUF:
+                return OsConstants.SO_SNDBUF;
+            case SocketOptions.SO_RCVBUF:
+                return OsConstants.SO_RCVBUF;
+            case SocketOptions.SO_REUSEADDR:
+                return OsConstants.SO_REUSEADDR;
+            default:
+                throw new UnsupportedOperationException("Unknown option: " + optID);
+        }
+    }
 }
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index f10b982..87ce12c 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -1574,7 +1574,8 @@
      */
     public static void conditionallyCheckInstanceCounts() {
         VmPolicy policy = getVmPolicy();
-        if (policy.classInstanceLimit.size() == 0) {
+        int policySize = policy.classInstanceLimit.size();
+        if (policySize == 0) {
             return;
         }
 
@@ -1583,15 +1584,17 @@
         System.gc();
 
         // Note: classInstanceLimit is immutable, so this is lock-free
-        for (Map.Entry<Class, Integer> entry : policy.classInstanceLimit.entrySet()) {
-            Class klass = entry.getKey();
-            int limit = entry.getValue();
-            long instances = VMDebug.countInstancesOfClass(klass, false);
-            if (instances <= limit) {
-                continue;
+        // Create the classes array.
+        Class[] classes = policy.classInstanceLimit.keySet().toArray(new Class[policySize]);
+        long[] instanceCounts = VMDebug.countInstancesOfClasses(classes, false);
+        for (int i = 0; i < classes.length; ++i) {
+            Class klass = classes[i];
+            int limit = policy.classInstanceLimit.get(klass);
+            long instances = instanceCounts[i];
+            if (instances > limit) {
+                Throwable tr = new InstanceCountViolation(klass, instances, limit);
+                onVmPolicyViolation(tr.getMessage(), tr);
             }
-            Throwable tr = new InstanceCountViolation(klass, instances, limit);
-            onVmPolicyViolation(tr.getMessage(), tr);
         }
     }
 
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 9a41b75..8940d86 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -19012,7 +19012,7 @@
 
     /**
      * Returns the suggested minimum width that the view should use. This
-     * returns the maximum of the view's minimum width)
+     * returns the maximum of the view's minimum width
      * and the background's minimum width
      *  ({@link android.graphics.drawable.Drawable#getMinimumWidth()}).
      * <p>
diff --git a/core/java/android/view/accessibility/AccessibilityEvent.java b/core/java/android/view/accessibility/AccessibilityEvent.java
index a04c4f1..2cde03d 100644
--- a/core/java/android/view/accessibility/AccessibilityEvent.java
+++ b/core/java/android/view/accessibility/AccessibilityEvent.java
@@ -372,7 +372,6 @@
  *   <li>{@link #getClassName()} - The class name of the source.</li>
  *   <li>{@link #getPackageName()} - The package name of the source.</li>
  *   <li>{@link #getEventTime()}  - The event time.</li>
- *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
  *   <li>{@link #getParcelableData()} - The posted {@link android.app.Notification}.</li>
  *   <li>{@link #getText()} - Text for providing more context.</li>
  * </ul>
diff --git a/core/java/android/webkit/WebViewClient.java b/core/java/android/webkit/WebViewClient.java
index de8ccc1..f2bb55a 100644
--- a/core/java/android/webkit/WebViewClient.java
+++ b/core/java/android/webkit/WebViewClient.java
@@ -415,7 +415,7 @@
      * Notify the host application that the scale applied to the WebView has
      * changed.
      *
-     * @param view he WebView that is initiating the callback.
+     * @param view The WebView that is initiating the callback.
      * @param oldScale The old scale factor
      * @param newScale The new scale factor
      */
diff --git a/core/java/android/widget/Adapter.java b/core/java/android/widget/Adapter.java
index 88b54bf..518718f 100644
--- a/core/java/android/widget/Adapter.java
+++ b/core/java/android/widget/Adapter.java
@@ -130,8 +130,7 @@
      * type of View for all items, this method should return 1.
      * </p>
      * <p>
-     * This method will only be called when when the adapter is set on the
-     * the {@link AdapterView}.
+     * This method will only be called when the adapter is set on the {@link AdapterView}.
      * </p>
      * 
      * @return The number of types of Views that will be created by this adapter
@@ -148,4 +147,3 @@
       */
      boolean isEmpty();
 }
-
diff --git a/core/java/com/android/internal/app/ProcessStats.java b/core/java/com/android/internal/app/ProcessStats.java
index 27aec4e..17ca904d 100644
--- a/core/java/com/android/internal/app/ProcessStats.java
+++ b/core/java/com/android/internal/app/ProcessStats.java
@@ -3366,10 +3366,11 @@
                             + pkgList.keyAt(index) + "/" + proc.mUid
                             + " for multi-proc " + proc.mName + " version " + proc.mVersion);
                 }
+                String savedName = proc.mName;
                 proc = pkg.mProcesses.get(proc.mName);
                 if (proc == null) {
                     throw new IllegalStateException("Didn't create per-package process "
-                            + proc.mName + " in pkg " + pkg.mPackageName + "/" + pkg.mUid);
+                            + savedName + " in pkg " + pkg.mPackageName + "/" + pkg.mUid);
                 }
                 holder.state = proc;
             }
diff --git a/core/java/com/android/internal/util/WithFramework.java b/core/java/com/android/internal/util/WithFramework.java
deleted file mode 100644
index 7d8596f..0000000
--- a/core/java/com/android/internal/util/WithFramework.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.util;
-
-import java.lang.reflect.Method;
-
-/**
- * Binds native framework methods and then invokes a main class with the
- * remaining arguments.
- */
-class WithFramework {
-
-    /**
-     * Invokes main(String[]) method on class in args[0] with args[1..n].
-     */
-    public static void main(String[] args) throws Exception {
-        if (args.length == 0) {
-            printUsage();
-            return;
-        }
-
-        Class<?> mainClass = Class.forName(args[0]);
-
-        System.loadLibrary("android_runtime");
-        if (registerNatives() < 0) {
-            throw new RuntimeException("Error registering natives.");
-        }
-
-        String[] newArgs = new String[args.length - 1];
-        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
-        Method mainMethod = mainClass.getMethod("main", String[].class);
-        mainMethod.invoke(null, new Object[] { newArgs });
-    }
-
-    private static void printUsage() {
-        System.err.println("Usage: dalvikvm " + WithFramework.class.getName()
-                + " [main class] [args]");
-    }
-
-    /**
-     * Registers native functions. See AndroidRuntime.cpp.
-     */
-    static native int registerNatives();
-}
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index bffbab7..9c235f3 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -1430,20 +1430,10 @@
 }
 
 /**
- * Used by WithFramework to register native functions.
+ * Used by surface flinger's DdmConnection to register native methods from
+ * the framework.
  */
-extern "C"
-jint Java_com_android_internal_util_WithFramework_registerNatives(
-        JNIEnv* env, jclass clazz) {
+extern "C" jint registerFrameworkNatives(JNIEnv* env) {
     return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
 }
-
-/**
- * Used by LoadClass to register native functions.
- */
-extern "C"
-jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) {
-    return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
-}
-
 }   // namespace android
diff --git a/core/jni/android_net_LocalSocketImpl.cpp b/core/jni/android_net_LocalSocketImpl.cpp
index 97abe6b..c137b17 100644
--- a/core/jni/android_net_LocalSocketImpl.cpp
+++ b/core/jni/android_net_LocalSocketImpl.cpp
@@ -112,317 +112,6 @@
     }
 }
 
-/* private native void listen_native(int fd, int backlog) throws IOException; */
-static void
-socket_listen (JNIEnv *env, jobject object, jobject fileDescriptor, jint backlog)
-{
-    int ret;
-    int fd;
-
-    fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-
-    if (env->ExceptionCheck()) {
-        return;
-    }
-
-    ret = listen(fd, backlog);
-
-    if (ret < 0) {
-        jniThrowIOException(env, errno);
-        return;
-    }
-}
-
-/*    private native FileDescriptor
-**    accept (FileDescriptor fd, LocalSocketImpl s)
-**                                   throws IOException;
-*/
-static jobject
-socket_accept (JNIEnv *env, jobject object, jobject fileDescriptor, jobject s)
-{
-    union {
-        struct sockaddr address;
-        struct sockaddr_un un_address;
-    } sa;
-
-    int ret;
-    int retFD;
-    int fd;
-    socklen_t addrlen;
-
-    if (s == NULL) {
-        jniThrowNullPointerException(env, NULL);
-        return NULL;
-    }
-
-    fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-
-    if (env->ExceptionCheck()) {
-        return NULL;
-    }
-
-    do {
-        addrlen = sizeof(sa);
-        ret = accept(fd, &(sa.address), &addrlen);
-    } while (ret < 0 && errno == EINTR);
-
-    if (ret < 0) {
-        jniThrowIOException(env, errno);
-        return NULL;
-    }
-
-    retFD = ret;
-
-    return jniCreateFileDescriptor(env, retFD);
-}
-
-/* private native void shutdown(FileDescriptor fd, boolean shutdownInput) */
-
-static void
-socket_shutdown (JNIEnv *env, jobject object, jobject fileDescriptor,
-                    jboolean shutdownInput)
-{
-    int ret;
-    int fd;
-
-    fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-
-    if (env->ExceptionCheck()) {
-        return;
-    }
-
-    ret = shutdown(fd, shutdownInput ? SHUT_RD : SHUT_WR);
-
-    if (ret < 0) {
-        jniThrowIOException(env, errno);
-        return;
-    }
-}
-
-static bool
-java_opt_to_real(int optID, int* opt, int* level)
-{
-    switch (optID)
-    {
-        case 4098:
-            *opt = SO_RCVBUF;
-            *level = SOL_SOCKET;
-            return true;
-        case 4097:
-            *opt = SO_SNDBUF;
-            *level = SOL_SOCKET;
-            return true;
-        case 4102:
-            *opt = SO_SNDTIMEO;
-            *level = SOL_SOCKET;
-            return true;
-        case 128:
-            *opt = SO_LINGER;
-            *level = SOL_SOCKET;
-            return true;
-        case 1:
-            *opt = TCP_NODELAY;
-            *level = IPPROTO_TCP;
-            return true;
-        case 4:
-            *opt = SO_REUSEADDR;
-            *level = SOL_SOCKET;
-            return true;
-
-    }
-    return false;
-}
-
-static jint
-socket_getOption(JNIEnv *env, jobject object, jobject fileDescriptor, jint optID)
-{
-    int ret, value;
-    int opt, level;
-    int fd;
-
-    socklen_t size = sizeof(int);
-
-    if (!java_opt_to_real(optID, &opt, &level)) {
-        jniThrowIOException(env, -1);
-        return 0;
-    }
-
-    fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-
-    if (env->ExceptionCheck()) {
-        return 0;
-    }
-
-    switch (opt)
-    {
-        case SO_LINGER:
-        {
-            struct linger lingr;
-            size = sizeof(lingr);
-            ret = getsockopt(fd, level, opt, &lingr, &size);
-            if (!lingr.l_onoff) {
-                value = -1;
-            } else {
-                value = lingr.l_linger;
-            }
-            break;
-        }
-        default:
-            ret = getsockopt(fd, level, opt, &value, &size);
-            break;
-    }
-
-
-    if (ret != 0) {
-        jniThrowIOException(env, errno);
-        return 0;
-    }
-
-    return value;
-}
-
-static void socket_setOption(
-        JNIEnv *env, jobject object, jobject fileDescriptor, jint optID,
-        jint boolValue, jint intValue) {
-    int ret;
-    int optname;
-    int level;
-    int fd;
-
-    if (!java_opt_to_real(optID, &optname, &level)) {
-        jniThrowIOException(env, -1);
-        return;
-    }
-
-    fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-
-    if (env->ExceptionCheck()) {
-        return;
-    }
-
-    switch (optname) {
-        case SO_LINGER: {
-            /*
-             * SO_LINGER is special because it needs to use a special
-             * "linger" struct as well as use the incoming boolean
-             * argument specially.
-             */
-            struct linger lingr;
-            lingr.l_onoff = boolValue ? 1 : 0; // Force it to be 0 or 1.
-            lingr.l_linger = intValue;
-            ret = setsockopt(fd, level, optname, &lingr, sizeof(lingr));
-            break;
-        }
-        case SO_SNDTIMEO: {
-            /*
-             * SO_TIMEOUT from the core library gets converted to
-             * SO_SNDTIMEO, but the option is supposed to set both
-             * send and receive timeouts. Note: The incoming timeout
-             * value is in milliseconds.
-             */
-            struct timeval timeout;
-            timeout.tv_sec = intValue / 1000;
-            timeout.tv_usec = (intValue % 1000) * 1000;
-
-            ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,
-                    (void *)&timeout, sizeof(timeout));
-
-            if (ret == 0) {
-                ret = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO,
-                        (void *)&timeout, sizeof(timeout));
-            }
-
-            break;
-        }
-        default: {
-            /*
-             * In all other cases, the translated option level and
-             * optname may be used directly for a call to setsockopt().
-             */
-            ret = setsockopt(fd, level, optname, &intValue, sizeof(intValue));
-            break;
-        }
-    }
-
-    if (ret != 0) {
-        jniThrowIOException(env, errno);
-        return;
-    }
-}
-static jint socket_pending (JNIEnv *env, jobject object,
-        jobject fileDescriptor)
-{
-    int fd;
-
-    fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-
-    if (env->ExceptionCheck()) {
-        return (jint)-1;
-    }
-
-    int pending;
-    int ret = ioctl(fd, TIOCOUTQ, &pending);
-
-    // If this were a non-socket fd, there would be other cases to worry
-    // about...
-
-    //ALOGD("socket_pending, ioctl ret:%d, pending:%d", ret, pending);
-    if (ret < 0) {
-        jniThrowIOException(env, errno);
-        return (jint) 0;
-    }
-
-    return (jint)pending;
-}
-static jint socket_available (JNIEnv *env, jobject object,
-        jobject fileDescriptor)
-{
-    int fd;
-
-    fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-
-    if (env->ExceptionCheck()) {
-        return (jint)-1;
-    }
-
-#if 1
-    int avail;
-    int ret = ioctl(fd, FIONREAD, &avail);
-
-    // If this were a non-socket fd, there would be other cases to worry
-    // about...
-
-    if (ret < 0) {
-        jniThrowIOException(env, errno);
-        return (jint) 0;
-    }
-
-    return (jint)avail;
-#else
-// there appears to be a bionic bug that prevents this version from working.
-
-    ssize_t ret;
-    struct msghdr msg;
-
-    memset(&msg, 0, sizeof(msg));
-
-    do {
-        ret = recvmsg(fd, &msg, MSG_PEEK | MSG_DONTWAIT | MSG_NOSIGNAL);
-    } while (ret < 0 && errno == EINTR);
-
-
-    // MSG_PEEK returns 0 on EOF and EWOULDBLOCK on none available
-    if (ret < 0 && errno == EWOULDBLOCK) {
-        return 0;
-    } if (ret < 0) {
-        jniThrowIOException(env, errno);
-        return -1;
-    }
-
-    return (jint)ret;
-#endif
-}
-
 /**
  * Processes ancillary data, handling only
  * SCM_RIGHTS. Creates appropriate objects and sets appropriate
@@ -803,72 +492,14 @@
             creds.pid, creds.uid, creds.gid);
 }
 
-#if 0
-//TODO change this to return an instance of LocalSocketAddress
-static jobject socket_getSockName(JNIEnv *env,
-        jobject object, jobject fileDescriptor)
-{
-    int err;
-    int fd;
-
-    if (fileDescriptor == NULL) {
-        jniThrowNullPointerException(env, NULL);
-        return NULL;
-    }
-
-    fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-
-    if (env->ExceptionCheck()) {
-        return NULL;
-    }
-
-    union {
-        struct sockaddr address;
-        struct sockaddr_un un_address;
-    } sa;
-
-    memset(&sa, 0, sizeof(sa));
-
-    socklen_t namelen = sizeof(sa);
-    err = getsockname(fd, &(sa.address), &namelen);
-
-    if (err < 0) {
-        jniThrowIOException(env, errno);
-        return NULL;
-    }
-
-    if (sa.address.sa_family != AF_UNIX) {
-        // We think we're an impl only for AF_UNIX, so this should never happen.
-
-        jniThrowIOException(env, EINVAL);
-        return NULL;
-    }
-
-    if (sa.un_address.sun_path[0] == '\0') {
-    } else {
-    }
-
-
-
-
-}
-#endif
-
 /*
  * JNI registration.
  */
 static JNINativeMethod gMethods[] = {
      /* name, signature, funcPtr */
-    {"getOption_native", "(Ljava/io/FileDescriptor;I)I", (void*)socket_getOption},
-    {"setOption_native", "(Ljava/io/FileDescriptor;III)V", (void*)socket_setOption},
     {"connectLocal", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V",
                                                 (void*)socket_connect_local},
     {"bindLocal", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V", (void*)socket_bind_local},
-    {"listen_native", "(Ljava/io/FileDescriptor;I)V", (void*)socket_listen},
-    {"accept", "(Ljava/io/FileDescriptor;Landroid/net/LocalSocketImpl;)Ljava/io/FileDescriptor;", (void*)socket_accept},
-    {"shutdown", "(Ljava/io/FileDescriptor;Z)V", (void*)socket_shutdown},
-    {"available_native", "(Ljava/io/FileDescriptor;)I", (void*) socket_available},
-    {"pending_native", "(Ljava/io/FileDescriptor;)I", (void*) socket_pending},
     {"read_native", "(Ljava/io/FileDescriptor;)I", (void*) socket_read},
     {"readba_native", "([BIILjava/io/FileDescriptor;)I", (void*) socket_readba},
     {"writeba_native", "([BIILjava/io/FileDescriptor;)V", (void*) socket_writeba},
@@ -876,9 +507,6 @@
     {"getPeerCredentials_native",
             "(Ljava/io/FileDescriptor;)Landroid/net/Credentials;",
             (void*) socket_get_peer_credentials}
-    //,{"getSockName_native", "(Ljava/io/FileDescriptor;)Ljava/lang/String;",
-    //        (void *) socket_getSockName}
-
 };
 
 int register_android_net_LocalSocketImpl(JNIEnv *env)
diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp
index e8acd97..b969477 100644
--- a/core/jni/android_os_Debug.cpp
+++ b/core/jni/android_os_Debug.cpp
@@ -34,10 +34,7 @@
 #include <errno.h>
 #include <assert.h>
 #include <ctype.h>
-
-#ifdef HAVE_MALLOC_H
 #include <malloc.h>
-#endif
 
 namespace android
 {
@@ -128,32 +125,20 @@
 
 static jlong android_os_Debug_getNativeHeapSize(JNIEnv *env, jobject clazz)
 {
-#ifdef HAVE_MALLOC_H
     struct mallinfo info = mallinfo();
     return (jlong) info.usmblks;
-#else
-    return -1;
-#endif
 }
 
 static jlong android_os_Debug_getNativeHeapAllocatedSize(JNIEnv *env, jobject clazz)
 {
-#ifdef HAVE_MALLOC_H
     struct mallinfo info = mallinfo();
     return (jlong) info.uordblks;
-#else
-    return -1;
-#endif
 }
 
 static jlong android_os_Debug_getNativeHeapFreeSize(JNIEnv *env, jobject clazz)
 {
-#ifdef HAVE_MALLOC_H
     struct mallinfo info = mallinfo();
     return (jlong) info.fordblks;
-#else
-    return -1;
-#endif
 }
 
 // Container used to retrieve graphics memory pss
diff --git a/core/jni/android_os_Parcel.cpp b/core/jni/android_os_Parcel.cpp
index 0f5ba83f..a14afa0 100644
--- a/core/jni/android_os_Parcel.cpp
+++ b/core/jni/android_os_Parcel.cpp
@@ -451,15 +451,11 @@
         jniThrowNullPointerException(env, NULL);
         return NULL;
     }
-    const jchar* str = env->GetStringCritical(name, 0);
-    if (str == NULL) {
-        // Whatever, whatever.
-        jniThrowException(env, "java/lang/IllegalStateException", NULL);
+    ScopedUtfChars name8(env, name);
+    if (name8.c_str() == NULL) {
         return NULL;
     }
-    String8 name8(reinterpret_cast<const char16_t*>(str),
-                  env->GetStringLength(name));
-    env->ReleaseStringCritical(name, str);
+
     int flags=0;
     switch (mode&0x30000000) {
         case 0:
@@ -482,7 +478,7 @@
     if (mode&0x00000001) realMode |= S_IROTH;
     if (mode&0x00000002) realMode |= S_IWOTH;
 
-    int fd = open(name8.string(), flags, realMode);
+    int fd = open(name8.c_str(), flags, realMode);
     if (fd < 0) {
         jniThrowException(env, "java/io/FileNotFoundException", strerror(errno));
         return NULL;
diff --git a/core/tests/overlaytests/testrunner.py b/core/tests/overlaytests/testrunner.py
index 3703f4a..2aa25ad 100755
--- a/core/tests/overlaytests/testrunner.py
+++ b/core/tests/overlaytests/testrunner.py
@@ -301,7 +301,7 @@
         return self.path
 
     def execute(self):
-        returncode, stdout, stderr = _adb_shell('md5 %s' % self.path)
+        returncode, stdout, stderr = _adb_shell('md5sum %s' % self.path)
         if returncode != 0:
             return returncode, stdout, stderr
         actual_md5 = stdout.split()[0]
diff --git a/data/keyboards/Android.mk b/data/keyboards/Android.mk
index 898efe8..4616838 100644
--- a/data/keyboards/Android.mk
+++ b/data/keyboards/Android.mk
@@ -32,7 +32,7 @@
 	$(hide) mkdir -p $(dir $@) && touch $@
 
 # Run validatekeymaps uncondionally for platform build.
-droidcore all_modules : $(LOCAL_BUILT_MODULE)
+droidcore : $(LOCAL_BUILT_MODULE)
 
 # Reset temp vars.
 validatekeymaps :=
diff --git a/docs/html/guide/topics/renderscript/reference/overview.jd b/docs/html/guide/topics/renderscript/reference/overview.jd
index f85b843..169b320 100644
--- a/docs/html/guide/topics/renderscript/reference/overview.jd
+++ b/docs/html/guide/topics/renderscript/reference/overview.jd
@@ -43,7 +43,7 @@
 </p>
 
 <p> To create vector literals, use the vector type followed by the values enclosed
-between parentheses, e.g. <code>(float3)(1.0f, 2.0f, 3.0f)</code>.
+between curly braces, e.g. <code>(float3){1.0f, 2.0f, 3.0f}</code>.
 </p>
 
 <p> Entries of a vector can be accessed using different naming styles.
diff --git a/docs/html/tools/debugging/debugging-log.jd b/docs/html/tools/debugging/debugging-log.jd
index d2baaf26..e222b2a 100644
--- a/docs/html/tools/debugging/debugging-log.jd
+++ b/docs/html/tools/debugging/debugging-log.jd
@@ -284,22 +284,8 @@
   <h2 id="viewingStd">Viewing stdout and stderr</h2>
 
   <p>By default, the Android system sends <code>stdout</code> and <code>stderr</code>
-  (<code>System.out</code> and <code>System.err</code>) output to <code>/dev/null</code>. In
-  processes that run the Dalvik VM, you can have the system write a copy of the output to the log
-  file. In this case, the system writes the messages to the log using the log tags
-  <code>stdout</code> and <code>stderr</code>, both with priority <code>I</code>.</p>
-
-  <p>To route the output in this way, you stop a running emulator/device instance and then use the
-  shell command <code>setprop</code> to enable the redirection of output. Here's how you do it:</p>
-  <pre>
-$ adb shell stop
-$ adb shell setprop log.redirect-stdio true
-$ adb shell start
-</pre>
-
-  <p>The system retains this setting until you terminate the emulator/device instance. To use the
-  setting as a default on the emulator/device instance, you can add an entry to
-  <code>/data/local.prop</code> on the device.</p>
+  output to <code>/dev/null</code>. (The Java <code>System.out</code> and <code>System.err</code>
+  streams go to the log.)
 
   <h2 id="DebuggingWebPages">Debugging Web Apps</h2>
   <p>
diff --git a/docs/knowntags.txt b/docs/knowntags.txt
index 5bebabb..3b7c8c7 100644
--- a/docs/knowntags.txt
+++ b/docs/knowntags.txt
@@ -15,7 +15,6 @@
 #
 # The grandfathered list.  We should get rid of these if possible.
 #
-@ToBeFixed
 @stable
 @com.intel.drl.spec_ref
 @ar.org.fitc.spec_ref
diff --git a/libs/androidfw/ZipFileRO.cpp b/libs/androidfw/ZipFileRO.cpp
index a6f6d8c..49fe8a2 100644
--- a/libs/androidfw/ZipFileRO.cpp
+++ b/libs/androidfw/ZipFileRO.cpp
@@ -39,7 +39,7 @@
 class _ZipEntryRO {
 public:
     ZipEntry entry;
-    ZipEntryName name;
+    ZipString name;
     void *cookie;
 
     _ZipEntryRO() : cookie(NULL) {}
@@ -80,7 +80,7 @@
 {
     _ZipEntryRO* data = new _ZipEntryRO;
 
-    data->name = ZipEntryName(entryName);
+    data->name = ZipString(entryName);
 
     const int32_t error = FindEntry(mHandle, data->name, &(data->entry));
     if (error) {
@@ -133,8 +133,8 @@
 bool ZipFileRO::startIteration(void** cookie, const char* prefix, const char* suffix)
 {
     _ZipEntryRO* ze = new _ZipEntryRO;
-    ZipEntryName pe(prefix ? prefix : "");
-    ZipEntryName se(suffix ? suffix : "");
+    ZipString pe(prefix ? prefix : "");
+    ZipString se(suffix ? suffix : "");
     int32_t error = StartIteration(mHandle, &(ze->cookie),
                                    prefix ? &pe : NULL,
                                    suffix ? &se : NULL);
diff --git a/media/java/android/media/MediaMetadataRetriever.java b/media/java/android/media/MediaMetadataRetriever.java
index a3ff080..7dd70d4 100644
--- a/media/java/android/media/MediaMetadataRetriever.java
+++ b/media/java/android/media/MediaMetadataRetriever.java
@@ -64,9 +64,7 @@
             throw new IllegalArgumentException();
         }
 
-        FileInputStream is = null;
-        try {
-            is = new FileInputStream(path);
+        try (FileInputStream is = new FileInputStream(path)) {
             FileDescriptor fd = is.getFD();
             setDataSource(fd, 0, 0x7ffffffffffffffL);
         } catch (FileNotFoundException fileEx) {
@@ -74,12 +72,6 @@
         } catch (IOException ioEx) {
             throw new IllegalArgumentException();
         }
-
-        try {
-            if (is != null) {
-                is.close();
-            }
-        } catch (Exception e) {}
     }
 
     /**
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index a4d3485..1a2512c 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -793,7 +793,7 @@
      * <li> {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING}
      * </ul>
      *
-     * @param mode target video scaling mode. Most be one of the supported
+     * @param mode target video scaling mode. Must be one of the supported
      * video scaling modes; otherwise, IllegalArgumentException will be thrown.
      *
      * @see MediaPlayer#VIDEO_SCALING_MODE_SCALE_TO_FIT
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
index eb1a589..05df014 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
@@ -27,12 +27,9 @@
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
 
-import dalvik.annotation.TestTargetClass;
-
 import org.easymock.EasyMock;
 import org.easymock.IArgumentMatcher;
 
-@TestTargetClass(MediaInserter.class)
 public class MediaInserterTest extends InstrumentationTestCase {
 
     private MediaInserter mMediaInserter;
diff --git a/packages/InputDevices/Android.mk b/packages/InputDevices/Android.mk
index f537022..e7190dc 100644
--- a/packages/InputDevices/Android.mk
+++ b/packages/InputDevices/Android.mk
@@ -42,7 +42,7 @@
 	$(hide) mkdir -p $(dir $@) && touch $@
 
 # Run validatekeymaps unconditionally for platform build.
-droidcore all_modules : $(LOCAL_BUILT_MODULE)
+droidcore : $(LOCAL_BUILT_MODULE)
 
 # Reset temp vars.
 validatekeymaps :=
diff --git a/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
index 8556afc..5a6f3c9 100644
--- a/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
+++ b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
@@ -236,7 +236,9 @@
                     Log.d(TAG, "Visibility changed to visible=" + visible);
                 }
                 mVisible = visible;
-                drawFrame();
+                if (visible) {
+                    drawFrame();
+                }
             }
         }
 
diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java
index 0a50593..a4876b9 100644
--- a/rs/java/android/renderscript/Allocation.java
+++ b/rs/java/android/renderscript/Allocation.java
@@ -1505,7 +1505,7 @@
         }
 
         final byte[] data = fp.getData();
-        int data_length = fp.getPos();
+        int data_length = data.length;
         int eSize = mType.mElement.mElements[component_number].getBytesSize();
         eSize *= mType.mElement.mArraySizes[component_number];
 
diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java
index 8b1a032..fc0cd27 100644
--- a/rs/java/android/renderscript/RenderScript.java
+++ b/rs/java/android/renderscript/RenderScript.java
@@ -88,6 +88,21 @@
     */
     public static final int CREATE_FLAG_LOW_POWER = 0x0004;
 
+    /**
+     * @hide
+     * Context creation flag which instructs the implementation to wait for
+     * a debugger to be attached before continuing execution.
+    */
+    public static final int CREATE_FLAG_WAIT_FOR_ATTACH = 0x0008;
+
+    /**
+     * @hide
+     * Context creation flag which specifies that optimization level 0 is
+     * passed to the device compiler upon execution of the RenderScript kernel.
+     * The default optimization level is 3.
+    */
+    public static final int CREATE_FLAG_OPT_LEVEL_0 = 0x0010;
+
     /*
      * Detect the bitness of the VM to allow FieldPacker to do the right thing.
      */
@@ -1356,7 +1371,8 @@
             return null;
         }
 
-        if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER)) != 0) {
+        if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER |
+                       CREATE_FLAG_WAIT_FOR_ATTACH | CREATE_FLAG_OPT_LEVEL_0)) != 0) {
             throw new RSIllegalArgumentException("Invalid flags passed.");
         }
 
diff --git a/rs/java/android/renderscript/ScriptIntrinsicBlend.java b/rs/java/android/renderscript/ScriptIntrinsicBlend.java
index 6b09bb7..fdcd61b 100644
--- a/rs/java/android/renderscript/ScriptIntrinsicBlend.java
+++ b/rs/java/android/renderscript/ScriptIntrinsicBlend.java
@@ -406,6 +406,8 @@
     /**
      * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
      *
+     * <b>Note:</b> this is NOT the Porter/Duff XOR mode; this is a bitwise xor.
+     *
      * @param ain The source buffer
      * @param aout The destination buffer
      * @param opt LaunchOptions for clipping
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp
index ffc4fd8..6a41699 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -1452,7 +1452,7 @@
     rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
                             xoff, yoff, zoff,
                             lod, ptr, sizeBytes, compIdx);
-    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
+    _env->ReleaseByteArrayElements(data, ptr, 0);
 }
 
 // Copies from the Allocation pointed to by _alloc into the Java object data.
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java
index d58d3721..4288fa2 100644
--- a/services/core/java/com/android/server/AlarmManagerService.java
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -516,10 +516,10 @@
         public int compare(Batch b1, Batch b2) {
             long when1 = b1.start;
             long when2 = b2.start;
-            if (when1 - when2 > 0) {
+            if (when1 > when2) {
                 return 1;
             }
-            if (when1 - when2 < 0) {
+            if (when1 < when2) {
                 return -1;
             }
             return 0;
@@ -1932,10 +1932,10 @@
         public int compare(Alarm a1, Alarm a2) {
             long when1 = a1.whenElapsed;
             long when2 = a2.whenElapsed;
-            if (when1 - when2 > 0) {
+            if (when1 > when2) {
                 return 1;
             }
-            if (when1 - when2 < 0) {
+            if (when1 < when2) {
                 return -1;
             }
             return 0;
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index eb6579c9..b925afa 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1204,6 +1204,7 @@
     String mMemWatchDumpFile;
     int mMemWatchDumpPid;
     int mMemWatchDumpUid;
+    String mTrackAllocationApp = null;
 
     final long[] mTmpLong = new long[1];
 
@@ -6050,6 +6051,11 @@
                 enableOpenGlTrace = true;
                 mOpenGlTraceApp = null;
             }
+            boolean enableTrackAllocation = false;
+            if (mTrackAllocationApp != null && mTrackAllocationApp.equals(processName)) {
+                enableTrackAllocation = true;
+                mTrackAllocationApp = null;
+            }
 
             // If the app is being launched for restore or full backup, set it up specially
             boolean isRestrictedBackupMode = false;
@@ -6078,7 +6084,7 @@
             thread.bindApplication(processName, appInfo, providers, app.instrumentationClass,
                     profilerInfo, app.instrumentationArguments, app.instrumentationWatcher,
                     app.instrumentationUiAutomationConnection, testMode, enableOpenGlTrace,
-                    isRestrictedBackupMode || !normalMode, app.persistent,
+                    enableTrackAllocation, isRestrictedBackupMode || !normalMode, app.persistent,
                     new Configuration(mConfiguration), app.compat,
                     getCommonServicesLocked(app.isolated),
                     mCoreSettingsObserver.getCoreSettingsLocked());
@@ -10512,7 +10518,7 @@
         synchronized (this) {
             boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
             if (!isDebuggable) {
-                if ((app.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
+                if ((app.flags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
                     throw new SecurityException("Process not debuggable: " + app.packageName);
                 }
             }
@@ -10521,11 +10527,24 @@
         }
     }
 
+    void setTrackAllocationApp(ApplicationInfo app, String processName) {
+        synchronized (this) {
+            boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
+            if (!isDebuggable) {
+                if ((app.flags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
+                    throw new SecurityException("Process not debuggable: " + app.packageName);
+                }
+            }
+
+            mTrackAllocationApp = processName;
+        }
+    }
+
     void setProfileApp(ApplicationInfo app, String processName, ProfilerInfo profilerInfo) {
         synchronized (this) {
             boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
             if (!isDebuggable) {
-                if ((app.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
+                if ((app.flags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
                     throw new SecurityException("Process not debuggable: " + app.packageName);
                 }
             }
@@ -13588,6 +13607,15 @@
                 pw.println("  mOpenGlTraceApp=" + mOpenGlTraceApp);
             }
         }
+        if (mTrackAllocationApp != null) {
+            if (dumpPackage == null || dumpPackage.equals(mTrackAllocationApp)) {
+                if (needSep) {
+                    pw.println();
+                    needSep = false;
+                }
+                pw.println("  mTrackAllocationApp=" + mTrackAllocationApp);
+            }
+        }
         if (mProfileApp != null || mProfileProc != null || mProfileFile != null
                 || mProfileFd != null) {
             if (dumpPackage == null || dumpPackage.equals(mProfileApp)) {
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 05c58d7..5eaf85c 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -884,20 +884,20 @@
                     aInfo.applicationInfo.packageName, aInfo.name));
 
             // Don't debug things in the system process
-            if ((startFlags&ActivityManager.START_FLAG_DEBUG) != 0) {
-                if (!aInfo.processName.equals("system")) {
+            if (!aInfo.processName.equals("system")) {
+                if ((startFlags & ActivityManager.START_FLAG_DEBUG) != 0) {
                     mService.setDebugApp(aInfo.processName, true, false);
                 }
-            }
 
-            if ((startFlags&ActivityManager.START_FLAG_OPENGL_TRACES) != 0) {
-                if (!aInfo.processName.equals("system")) {
+                if ((startFlags & ActivityManager.START_FLAG_OPENGL_TRACES) != 0) {
                     mService.setOpenGlTraceApp(aInfo.applicationInfo, aInfo.processName);
                 }
-            }
 
-            if (profilerInfo != null) {
-                if (!aInfo.processName.equals("system")) {
+                if ((startFlags & ActivityManager.START_FLAG_TRACK_ALLOCATION) != 0) {
+                    mService.setTrackAllocationApp(aInfo.applicationInfo, aInfo.processName);
+                }
+
+                if (profilerInfo != null) {
                     mService.setProfileApp(aInfo.applicationInfo, aInfo.processName, profilerInfo);
                 }
             }
diff --git a/services/core/java/com/android/server/am/NativeCrashListener.java b/services/core/java/com/android/server/am/NativeCrashListener.java
index d42d415..d0973d5 100644
--- a/services/core/java/com/android/server/am/NativeCrashListener.java
+++ b/services/core/java/com/android/server/am/NativeCrashListener.java
@@ -21,6 +21,7 @@
 import android.system.Os;
 import android.system.StructTimeval;
 import android.system.StructUcred;
+import android.system.UnixSocketAddress;
 import android.util.Slog;
 
 import static android.system.OsConstants.*;
@@ -30,7 +31,6 @@
 import java.io.FileDescriptor;
 import java.io.InterruptedIOException;
 import java.net.InetSocketAddress;
-import java.net.InetUnixAddress;
 
 /**
  * Set up a Unix domain socket that debuggerd will connect() to in
@@ -117,16 +117,16 @@
 
         try {
             FileDescriptor serverFd = Os.socket(AF_UNIX, SOCK_STREAM, 0);
-            final InetUnixAddress sockAddr = new InetUnixAddress(DEBUGGERD_SOCKET_PATH);
-            Os.bind(serverFd, sockAddr, 0);
+            final UnixSocketAddress sockAddr = UnixSocketAddress.createFileSystem(
+                    DEBUGGERD_SOCKET_PATH);
+            Os.bind(serverFd, sockAddr);
             Os.listen(serverFd, 1);
 
             while (true) {
-                InetSocketAddress peer = new InetSocketAddress();
                 FileDescriptor peerFd = null;
                 try {
                     if (MORE_DEBUG) Slog.v(TAG, "Waiting for debuggerd connection");
-                    peerFd = Os.accept(serverFd, peer);
+                    peerFd = Os.accept(serverFd, null /* peerAddress */);
                     if (MORE_DEBUG) Slog.v(TAG, "Got debuggerd socket " + peerFd);
                     if (peerFd != null) {
                         // Only the superuser is allowed to talk to us over this socket
diff --git a/services/core/java/com/android/server/job/JobServiceContext.java b/services/core/java/com/android/server/job/JobServiceContext.java
index bb4e388..d26319b 100644
--- a/services/core/java/com/android/server/job/JobServiceContext.java
+++ b/services/core/java/com/android/server/job/JobServiceContext.java
@@ -73,7 +73,7 @@
     private static final long OP_TIMEOUT_MILLIS = 8 * 1000;
 
     private static final String[] VERB_STRINGS = {
-            "VERB_BINDING", "VERB_STARTING", "VERB_EXECUTING", "VERB_STOPPING"
+            "VERB_BINDING", "VERB_STARTING", "VERB_EXECUTING", "VERB_STOPPING", "VERB_FINISHED"
     };
 
     // States that a job occupies while interacting with the client.
@@ -81,6 +81,7 @@
     static final int VERB_STARTING = 1;
     static final int VERB_EXECUTING = 2;
     static final int VERB_STOPPING = 3;
+    static final int VERB_FINISHED = 4;
 
     // Messages that result from interactions with the client service.
     /** System timed out waiting for a response. */
@@ -172,6 +173,7 @@
                 mRunningJob = null;
                 mParams = null;
                 mExecutionStartTimeElapsed = 0L;
+                mVerb = VERB_FINISHED;
                 removeOpTimeOut();
                 return false;
             }
@@ -307,8 +309,8 @@
                     break;
                 case MSG_CALLBACK:
                     if (DEBUG) {
-                        Slog.d(TAG, "MSG_CALLBACK of : " + mRunningJob + " v:" +
-                                (mVerb >= 0 ? VERB_STRINGS[mVerb] : "[invalid]"));
+                        Slog.d(TAG, "MSG_CALLBACK of : " + mRunningJob
+                                + " v:" + VERB_STRINGS[mVerb]);
                     }
                     removeOpTimeOut();
 
@@ -524,8 +526,12 @@
          * we want to clean up internally.
          */
         private void closeAndCleanupJobH(boolean reschedule) {
-            final JobStatus completedJob = mRunningJob;
+            final JobStatus completedJob;
             synchronized (mLock) {
+                if (mVerb == VERB_FINISHED) {
+                    return;
+                }
+                completedJob = mRunningJob;
                 try {
                     mBatteryStats.noteJobFinish(mRunningJob.getName(), mRunningJob.getUid());
                 } catch (RemoteException e) {
@@ -538,7 +544,7 @@
                 mWakeLock = null;
                 mRunningJob = null;
                 mParams = null;
-                mVerb = -1;
+                mVerb = VERB_FINISHED;
                 mCancelled.set(false);
                 service = null;
                 mAvailable = true;
diff --git a/services/core/jni/com_android_server_PersistentDataBlockService.cpp b/services/core/jni/com_android_server_PersistentDataBlockService.cpp
index e842eeb..4ccfa56 100644
--- a/services/core/jni/com_android_server_PersistentDataBlockService.cpp
+++ b/services/core/jni/com_android_server_PersistentDataBlockService.cpp
@@ -17,6 +17,7 @@
 #include <android_runtime/AndroidRuntime.h>
 #include <JNIHelp.h>
 #include <jni.h>
+#include <ScopedUtfChars.h>
 
 #include <utils/misc.h>
 #include <sys/ioctl.h>
@@ -77,8 +78,8 @@
 
     static jlong com_android_server_PersistentDataBlockService_getBlockDeviceSize(JNIEnv *env, jclass, jstring jpath)
     {
-        const char *path = env->GetStringUTFChars(jpath, 0);
-        int fd = open(path, O_RDONLY);
+        ScopedUtfChars path(env, jpath);
+        int fd = open(path.c_str(), O_RDONLY);
 
         if (fd < 0)
             return 0;
@@ -87,8 +88,8 @@
     }
 
     static int com_android_server_PersistentDataBlockService_wipe(JNIEnv *env, jclass, jstring jpath) {
-        const char *path = env->GetStringUTFChars(jpath, 0);
-        int fd = open(path, O_WRONLY);
+        ScopedUtfChars path(env, jpath);
+        int fd = open(path.c_str(), O_WRONLY);
 
         if (fd < 0)
             return 0;
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 014527b..46ace17 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -497,7 +497,7 @@
             // TODO: Use a more reliable check to see if this product should
             // support Bluetooth - see bug 988521
             if (isEmulator) {
-                Slog.i(TAG, "No Bluetooh Service (emulator)");
+                Slog.i(TAG, "No Bluetooth Service (emulator)");
             } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
                 Slog.i(TAG, "No Bluetooth Service (factory test)");
             } else if (!context.getPackageManager().hasSystemFeature
diff --git a/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java
index 6300a9a..965341e 100644
--- a/services/usb/java/com/android/server/usb/UsbHostManager.java
+++ b/services/usb/java/com/android/server/usb/UsbHostManager.java
@@ -231,6 +231,8 @@
             mNewConfigurations = null;
             mNewInterfaces = null;
             mNewEndpoints = null;
+            mNewConfiguration = null;
+            mNewInterface = null;
         }
     }
 
diff --git a/test-runner/src/android/test/InstrumentationCoreTestRunner.java b/test-runner/src/android/test/InstrumentationCoreTestRunner.java
index 036a2275..655a65c 100644
--- a/test-runner/src/android/test/InstrumentationCoreTestRunner.java
+++ b/test-runner/src/android/test/InstrumentationCoreTestRunner.java
@@ -21,12 +21,6 @@
 import java.lang.reflect.Modifier;
 import java.util.List;
 
-import com.android.internal.util.Predicate;
-import com.android.internal.util.Predicates;
-
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.SideEffect;
-
 import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -192,19 +186,4 @@
 
         return runner;
     }
-
-    @Override
-    List<Predicate<TestMethod>> getBuilderRequirements() {
-        List<Predicate<TestMethod>> builderRequirements =
-                super.getBuilderRequirements();
-        Predicate<TestMethod> brokenTestPredicate =
-                Predicates.not(new HasAnnotation(BrokenTest.class));
-        builderRequirements.add(brokenTestPredicate);
-        if (!singleTest) {
-            Predicate<TestMethod> sideEffectPredicate =
-                    Predicates.not(new HasAnnotation(SideEffect.class));
-            builderRequirements.add(sideEffectPredicate);
-        }
-        return builderRequirements;
-    }
 }
diff --git a/tests/CoreTests/run_core_test.sh b/tests/CoreTests/run_core_test.sh
deleted file mode 100755
index ffa31ed..0000000
--- a/tests/CoreTests/run_core_test.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-framework=/system/framework
-bpath=$framework/core.jar:$framework/ext.jar:$framework/framework.jar:$framework/android.test.runner.jar
-adb shell exec dalvikvm -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=3001 \
-      -Xbootclasspath:$bpath -cp /data/app/android.core.apk \
-      -Djava.io.tmpdir=/sdcard/tmp \
-      com.android.internal.util.WithFramework junit.textui.TestRunner $*
diff --git a/tests/CoreTests/run_junit.sh b/tests/CoreTests/run_junit.sh
deleted file mode 100755
index b77794d..0000000
--- a/tests/CoreTests/run_junit.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-# runs unit tests over adb shell using dalvikvm.  The value added is setting the classpath for you
-# and pointing to the junit textui test runner.
-#
-# the normal usage might be:
-# (make MoreJavaTests)
-# $ adb sync
-# $ java/tests/run_junit.sh android.util.MyTest
-
-adb shell exec dalvikvm -cp system/app/MoreTests.apk junit.textui.TestRunner $*