summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/main/java/java/io/FileDescriptor.java9
-rw-r--r--luni/src/main/java/java/util/concurrent/ForkJoinPool.java12
-rw-r--r--luni/src/main/java/java/util/concurrent/ForkJoinTask.java14
-rw-r--r--luni/src/main/java/libcore/io/BlockGuardOs.java9
-rw-r--r--luni/src/main/java/libcore/net/MimeUtils.java11
-rw-r--r--luni/src/main/native/Register.cpp1
-rw-r--r--luni/src/main/native/java_io_FileDescriptor.cpp35
-rw-r--r--luni/src/main/native/sub.mk1
-rw-r--r--luni/src/test/java/libcore/net/MimeUtilsTest.java8
9 files changed, 77 insertions, 23 deletions
diff --git a/luni/src/main/java/java/io/FileDescriptor.java b/luni/src/main/java/java/io/FileDescriptor.java
index cb38123..eba0e4d 100644
--- a/luni/src/main/java/java/io/FileDescriptor.java
+++ b/luni/src/main/java/java/io/FileDescriptor.java
@@ -105,6 +105,15 @@ public final class FileDescriptor {
this.descriptor = fd;
}
+ /**
+ * @hide internal use only
+ */
+ public boolean isSocket() {
+ return isSocket(descriptor);
+ }
+
+ private static native boolean isSocket(int fd);
+
@Override public String toString() {
return "FileDescriptor[" + descriptor + "]";
}
diff --git a/luni/src/main/java/java/util/concurrent/ForkJoinPool.java b/luni/src/main/java/java/util/concurrent/ForkJoinPool.java
index 5ac01c8..2e7adc1 100644
--- a/luni/src/main/java/java/util/concurrent/ForkJoinPool.java
+++ b/luni/src/main/java/java/util/concurrent/ForkJoinPool.java
@@ -39,7 +39,7 @@ import java.util.concurrent.TimeUnit;
* ForkJoinPool}s may also be appropriate for use with event-style
* tasks that are never joined.
*
- * <p>A static {@link #commonPool()} is available and appropriate for
+ * <p>A static {@code commonPool()} is available and appropriate for
* most applications. The common pool is used by any ForkJoinTask that
* is not explicitly submitted to a specified pool. Using the common
* pool normally reduces resource usage (its threads are slowly
@@ -2907,7 +2907,7 @@ public class ForkJoinPool extends AbstractExecutorService {
* Possibly initiates an orderly shutdown in which previously
* submitted tasks are executed, but no new tasks will be
* accepted. Invocation has no effect on execution state if this
- * is the {@link #commonPool()}, and no additional effect if
+ * is the {@code commonPool()}, and no additional effect if
* already shut down. Tasks that are in the process of being
* submitted concurrently during the course of this method may or
* may not be rejected.
@@ -2920,7 +2920,7 @@ public class ForkJoinPool extends AbstractExecutorService {
/**
* Possibly attempts to cancel and/or stop all tasks, and reject
* all subsequently submitted tasks. Invocation has no effect on
- * execution state if this is the {@link #commonPool()}, and no
+ * execution state if this is the {@code commonPool()}, and no
* additional effect if already shut down. Otherwise, tasks that
* are in the process of being submitted or executed concurrently
* during the course of this method may or may not be
@@ -2979,8 +2979,8 @@ public class ForkJoinPool extends AbstractExecutorService {
/**
* Blocks until all tasks have completed execution after a
* shutdown request, or the timeout occurs, or the current thread
- * is interrupted, whichever happens first. Because the {@link
- * #commonPool()} never terminates until program shutdown, when
+ * is interrupted, whichever happens first. Because the {@code
+ * commonPool()} never terminates until program shutdown, when
* applied to the common pool, this method is equivalent to {@link
* #awaitQuiescence(long, TimeUnit)} but always returns {@code false}.
*
@@ -3064,7 +3064,7 @@ public class ForkJoinPool extends AbstractExecutorService {
/**
* Waits and/or attempts to assist performing tasks indefinitely
- * until the {@link #commonPool()} {@link #isQuiescent}.
+ * until the {@code commonPool()} {@link #isQuiescent}.
*/
static void quiesceCommonPool() {
common.awaitQuiescence(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
diff --git a/luni/src/main/java/java/util/concurrent/ForkJoinTask.java b/luni/src/main/java/java/util/concurrent/ForkJoinTask.java
index 6d25775..b77c167 100644
--- a/luni/src/main/java/java/util/concurrent/ForkJoinTask.java
+++ b/luni/src/main/java/java/util/concurrent/ForkJoinTask.java
@@ -32,8 +32,8 @@ import java.lang.reflect.Constructor;
*
* <p>A "main" {@code ForkJoinTask} begins execution when it is
* explicitly submitted to a {@link ForkJoinPool}, or, if not already
- * engaged in a ForkJoin computation, commenced in the {@link
- * ForkJoinPool#commonPool()} via {@link #fork}, {@link #invoke}, or
+ * engaged in a ForkJoin computation, commenced in the {@code
+ * ForkJoinPool.commonPool()} via {@link #fork}, {@link #invoke}, or
* related methods. Once started, it will usually in turn start other
* subtasks. As indicated by the name of this class, many programs
* using {@code ForkJoinTask} employ only methods {@link #fork} and
@@ -138,9 +138,9 @@ import java.lang.reflect.Constructor;
* may be of use in constructing custom subclasses for problems that
* are not statically structured as DAGs. To support such usages, a
* ForkJoinTask may be atomically <em>tagged</em> with a {@code short}
- * value using {@link #setForkJoinTaskTag} or {@link
- * #compareAndSetForkJoinTaskTag} and checked using {@link
- * #getForkJoinTaskTag}. The ForkJoinTask implementation does not use
+ * value using {@code setForkJoinTaskTag} or {@code
+ * compareAndSetForkJoinTaskTag} and checked using {@code
+ * getForkJoinTaskTag}. The ForkJoinTask implementation does not use
* these {@code protected} methods or tags for any purpose, but they
* may be of use in the construction of specialized subclasses. For
* example, parallel graph traversals can use the supplied methods to
@@ -645,8 +645,8 @@ public abstract class ForkJoinTask<V> implements Future<V>, Serializable {
/**
* Arranges to asynchronously execute this task in the pool the
- * current task is running in, if applicable, or using the {@link
- * ForkJoinPool#commonPool()} if not {@link #inForkJoinPool}. While
+ * current task is running in, if applicable, or using the {@code
+ * ForkJoinPool.commonPool()} if not {@link #inForkJoinPool}. While
* it is not necessarily enforced, it is a usage error to fork a
* task more than once unless it has completed and been
* reinitialized. Subsequent modifications to the state of this
diff --git a/luni/src/main/java/libcore/io/BlockGuardOs.java b/luni/src/main/java/libcore/io/BlockGuardOs.java
index 764e60a..b3dc74b 100644
--- a/luni/src/main/java/libcore/io/BlockGuardOs.java
+++ b/luni/src/main/java/libcore/io/BlockGuardOs.java
@@ -80,17 +80,18 @@ public class BlockGuardOs extends ForwardingOs {
@Override public void close(FileDescriptor fd) throws ErrnoException {
try {
- // The usual case is that this _isn't_ a socket, so getsockopt will throw,
- // and that's really expensive. Try to avoid asking if we don't care.
- if ((BlockGuard.getThreadPolicy().getPolicyMask() & DISALLOW_NETWORK) != 0) {
+ // The usual case is that this _isn't_ a socket, so the getsockopt(2) call in
+ // isLingerSocket will throw, and that's really expensive. Try to avoid asking
+ // if we don't care.
+ if (fd.isSocket()) {
if (isLingerSocket(fd)) {
// If the fd is a socket with SO_LINGER set, we might block indefinitely.
// We allow non-linger sockets so that apps can close their network
// connections in methods like onDestroy which will run on the UI thread.
BlockGuard.getThreadPolicy().onNetwork();
}
+ untagSocket(fd);
}
- untagSocket(fd);
} catch (ErrnoException ignored) {
// We're called via Socket.close (which doesn't ask for us to be called), so we
// must not throw here, because Socket.close must not throw if asked to close an
diff --git a/luni/src/main/java/libcore/net/MimeUtils.java b/luni/src/main/java/libcore/net/MimeUtils.java
index 62ff861..a5a1469 100644
--- a/luni/src/main/java/libcore/net/MimeUtils.java
+++ b/luni/src/main/java/libcore/net/MimeUtils.java
@@ -49,10 +49,8 @@ public final class MimeUtils {
add("application/andrew-inset", "ez");
add("application/dsptype", "tsp");
- add("application/futuresplash", "spl");
add("application/hta", "hta");
add("application/mac-binhex40", "hqx");
- add("application/mac-compactpro", "cpt");
add("application/mathematica", "nb");
add("application/msaccess", "mdb");
add("application/oda", "oda");
@@ -140,7 +138,9 @@ public final class MimeUtils {
add("application/x-font", "pcf");
add("application/x-font", "pcf.Z");
add("application/x-freemind", "mm");
+ // application/futuresplash isn't IANA, so application/x-futuresplash should come first.
add("application/x-futuresplash", "spl");
+ add("application/futuresplash", "spl");
add("application/x-gnumeric", "gnumeric");
add("application/x-go-sgf", "sgf");
add("application/x-graphing-calculator", "gcf");
@@ -250,8 +250,12 @@ public final class MimeUtils {
add("audio/x-scpls", "pls");
add("audio/x-sd2", "sd2");
add("audio/x-wav", "wav");
+ // image/bmp isn't IANA, so image/x-ms-bmp should come first.
+ add("image/x-ms-bmp", "bmp");
add("image/bmp", "bmp");
add("image/gif", "gif");
+ // image/ico isn't IANA, so image/x-icon should come first.
+ add("image/x-icon", "ico");
add("image/ico", "cur");
add("image/ico", "ico");
add("image/ief", "ief");
@@ -273,10 +277,8 @@ public final class MimeUtils {
add("image/x-coreldrawpattern", "pat");
add("image/x-coreldrawtemplate", "cdt");
add("image/x-corelphotopaint", "cpt");
- add("image/x-icon", "ico");
add("image/x-jg", "art");
add("image/x-jng", "jng");
- add("image/x-ms-bmp", "bmp");
add("image/x-photoshop", "psd");
add("image/x-portable-anymap", "pnm");
add("image/x-portable-bitmap", "pbm");
@@ -308,7 +310,6 @@ public final class MimeUtils {
add("text/plain", "po"); // reserve "pot" for vnd.ms-powerpoint
add("text/richtext", "rtx");
add("text/rtf", "rtf");
- add("text/texmacs", "ts");
add("text/text", "phps");
add("text/tab-separated-values", "tsv");
add("text/xml", "xml");
diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp
index 4aaa905..6a2c939 100644
--- a/luni/src/main/native/Register.cpp
+++ b/luni/src/main/native/Register.cpp
@@ -35,6 +35,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
#define REGISTER(FN) extern void FN(JNIEnv*); FN(env)
REGISTER(register_android_system_OsConstants);
REGISTER(register_java_io_File);
+ REGISTER(register_java_io_FileDescriptor);
REGISTER(register_java_io_ObjectStreamClass);
REGISTER(register_java_lang_Character);
REGISTER(register_java_lang_Double);
diff --git a/luni/src/main/native/java_io_FileDescriptor.cpp b/luni/src/main/native/java_io_FileDescriptor.cpp
new file mode 100644
index 0000000..fe7e07e
--- /dev/null
+++ b/luni/src/main/native/java_io_FileDescriptor.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#define LOG_TAG "FileDescriptor"
+
+#include "JniConstants.h"
+
+#include <sys/socket.h>
+#include <sys/types.h>
+
+static jboolean FileDescriptor_isSocket(JNIEnv*, jclass, jint fd) {
+ int error;
+ socklen_t error_length = sizeof(error);
+ return TEMP_FAILURE_RETRY(getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &error_length));
+}
+
+static JNINativeMethod gMethods[] = {
+ NATIVE_METHOD(FileDescriptor, isSocket, "(I)Z"),
+};
+void register_java_io_FileDescriptor(JNIEnv* env) {
+ jniRegisterNativeMethods(env, "java/io/FileDescriptor", gMethods, NELEM(gMethods));
+}
diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk
index 5b581f3..079ecd2 100644
--- a/luni/src/main/native/sub.mk
+++ b/luni/src/main/native/sub.mk
@@ -15,6 +15,7 @@ LOCAL_SRC_FILES := \
canonicalize_path.cpp \
cbigint.cpp \
java_io_File.cpp \
+ java_io_FileDescriptor.cpp \
java_io_ObjectStreamClass.cpp \
java_lang_Character.cpp \
java_lang_Double.cpp \
diff --git a/luni/src/test/java/libcore/net/MimeUtilsTest.java b/luni/src/test/java/libcore/net/MimeUtilsTest.java
index 45b8a79..36476e9 100644
--- a/luni/src/test/java/libcore/net/MimeUtilsTest.java
+++ b/luni/src/test/java/libcore/net/MimeUtilsTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package libcore.java.net;
+package libcore.net;
import junit.framework.TestCase;
@@ -27,6 +27,12 @@ public class MimeUtilsTest extends TestCase {
assertEquals("flac", MimeUtils.guessExtensionFromMimeType("application/x-flac"));
}
+ public void test_16978217() {
+ assertEquals("image/x-ms-bmp", MimeUtils.guessMimeTypeFromExtension("bmp"));
+ assertEquals("image/x-icon", MimeUtils.guessMimeTypeFromExtension("ico"));
+ assertEquals("video/mp2ts", MimeUtils.guessMimeTypeFromExtension("ts"));
+ }
+
public void testCommon() {
assertEquals("audio/mpeg", MimeUtils.guessMimeTypeFromExtension("mp3"));
assertEquals("image/png", MimeUtils.guessMimeTypeFromExtension("png"));