Merge "Switch to using android.system.Os for more calls"
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 f73c142..6cc2cab 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -1427,20 +1427,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/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/libs/androidfw/ZipFileRO.cpp b/libs/androidfw/ZipFileRO.cpp
index b61d179..bdb659c 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) {}
@@ -79,7 +79,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) {
@@ -128,7 +128,8 @@
 bool ZipFileRO::startIteration(void** cookie)
 {
     _ZipEntryRO* ze = new _ZipEntryRO;
-    int32_t error = StartIteration(mHandle, &(ze->cookie), NULL /* prefix */);
+    int32_t error = StartIteration(mHandle, &(ze->cookie),
+                                   NULL /* prefix */, NULL /* suffix */);
     if (error) {
         ALOGW("Could not start iteration over %s: %s", mFileName, ErrorCodeString(error));
         delete ze;
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index d4c530b..1e047b9 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1567,6 +1567,8 @@
             if (mImmersiveModeConfirmation != null) {
                 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
             }
+        }
+        synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
             PolicyControl.reloadFromSetting(mContext);
         }
         if (updateRotation) {
diff --git a/rs/java/android/renderscript/ScriptGroup.java b/rs/java/android/renderscript/ScriptGroup.java
index 5a0897d..2878356 100644
--- a/rs/java/android/renderscript/ScriptGroup.java
+++ b/rs/java/android/renderscript/ScriptGroup.java
@@ -993,6 +993,8 @@
          *
          * @param name name for the script group. Legal names can only contain letters, digits,
          *        '-', or '_'. The name can be no longer than 100 characters.
+         *        Try to use unique names, to avoid name conflicts and reduce
+         *        the cost of group creation.
          * @param outputs futures intended as outputs of the script group
          * @return a script group
          */
diff --git a/rs/java/android/renderscript/ScriptIntrinsicBLAS.java b/rs/java/android/renderscript/ScriptIntrinsicBLAS.java
index 9acf5ad..8fd56d7 100644
--- a/rs/java/android/renderscript/ScriptIntrinsicBLAS.java
+++ b/rs/java/android/renderscript/ScriptIntrinsicBLAS.java
@@ -1554,14 +1554,29 @@
 
 
     /**
+     * 8-bit GEMM-like operation for neural networks: C = B.transposed() * A
+     * Calculations are done in 1.10.21 fixed-point format for the final output,
+     * just before there's a shift down to drop the fractional parts. The output
+     * values are gated to 0 to 255 to fit in a byte, but the 10-bit format
+     * gives some headroom to avoid wrapping around on small overflows.
      *
-     * 8-bit GEMM-like operation for neural networks
-     *
-     * @hide
+     * @param A The input allocation contains matrix A, supported elements type {@link Element#U8}.
+     * @param a_offset The offset for all values in matrix A, e.g A[i,j] = A[i,j] - a_offset. Value should be from 0 to 255.
+     * @param B The input allocation contains matrix B, supported elements type {@link Element#U8}.
+     * @param b_offset The offset for all values in matrix B, e.g B[i,j] = B[i,j] - b_offset. Value should be from 0 to 255.
+     * @param C The input allocation contains matrix C, supported elements type {@link Element#U8}.
+     * @param c_offset The offset for all values in matrix C.
+     * @param c_mult The multiplier for all values in matrix C, e.g C[i,j] = (C[i,j] + c_offset) * c_mult.
      **/
     public void BNNM(Allocation A, int a_offset, Allocation B, int b_offset, Allocation C, int c_offset, int c_mult) {
         validateL3(Element.U8(mRS), NO_TRANSPOSE, TRANSPOSE, 0, A, B, C);
 
+        if (a_offset < 0 || a_offset > 255) {
+            throw new RSRuntimeException("Invalid a_offset passed to BNNM");
+        }
+        if (b_offset < 0 || b_offset > 255) {
+            throw new RSRuntimeException("Invalid b_offset passed to BNNM");
+        }
         int M = -1, N = -1, K = -1;
         M = A.getType().getY();
         N = B.getType().getY();
diff --git a/rs/java/android/renderscript/ScriptIntrinsicBlend.java b/rs/java/android/renderscript/ScriptIntrinsicBlend.java
index 906e0f6..dc1bec3 100644
--- a/rs/java/android/renderscript/ScriptIntrinsicBlend.java
+++ b/rs/java/android/renderscript/ScriptIntrinsicBlend.java
@@ -402,6 +402,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 ec835b2..aac6c19 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -701,8 +701,8 @@
     call.M = M;
     call.N = N;
     call.K = K;
-    call.a_offset = a_offset;
-    call.b_offset = b_offset;
+    call.a_offset = a_offset & 0xFF;
+    call.b_offset = b_offset & 0xFF;
     call.c_offset = c_offset;
     call.c_mult_int = c_mult_int;
 
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/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 $*