Merge "Fix "Bluetooh" logging typo."
diff --git a/core/java/android/net/LocalSocketImpl.java b/core/java/android/net/LocalSocketImpl.java
index fa9f479..8823ab1 100644
--- a/core/java/android/net/LocalSocketImpl.java
+++ b/core/java/android/net/LocalSocketImpl.java
@@ -25,6 +25,8 @@
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
+import android.system.StructLinger;
+import android.system.StructTimeval;
/**
* Socket implementation used for android.net.LocalSocket and
@@ -184,13 +186,6 @@
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.
@@ -232,7 +227,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) {
@@ -434,24 +429,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 +480,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 +488,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 +564,7 @@
* @return non-null; peer credentials
* @throws IOException
*/
- public Credentials getPeerCredentials() throws IOException
- {
+ public Credentials getPeerCredentials() throws IOException {
return getPeerCredentials_native(fd);
}
@@ -528,15 +574,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/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/core/jni/android_net_LocalSocketImpl.cpp b/core/jni/android_net_LocalSocketImpl.cpp
index 97abe6b..ee6997d 100644
--- a/core/jni/android_net_LocalSocketImpl.cpp
+++ b/core/jni/android_net_LocalSocketImpl.cpp
@@ -199,156 +199,6 @@
}
}
-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)
{
@@ -803,64 +653,11 @@
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},
@@ -876,9 +673,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/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/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/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java
index e769bda..4451d7d 100644
--- a/services/usb/java/com/android/server/usb/UsbHostManager.java
+++ b/services/usb/java/com/android/server/usb/UsbHostManager.java
@@ -230,6 +230,8 @@
mNewConfigurations = null;
mNewInterfaces = null;
mNewEndpoints = null;
+ mNewConfiguration = null;
+ mNewInterface = null;
}
}
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 $*