Merge "New Japanese Era implementation with actual Reiwa name (part 2)"
diff --git a/JavaLibrary.bp b/JavaLibrary.bp
index 53d0a10..317ef4b 100644
--- a/JavaLibrary.bp
+++ b/JavaLibrary.bp
@@ -255,14 +255,20 @@
         // Device files put in /system.
         "tzdata",
         "tz_version",
-        // Files used to simulate the /system and runtime APEX dir
-        // structure on host.
-        "tzdata_host",
-        "tzdata_host_runtime_apex",
-        "tzlookup.xml_host_runtime_apex",
-        "tz_version_host",
-        "tz_version_host_runtime_apex",
     ],
+    target: {
+        hostdex: {
+            required: [
+                // Files used to simulate the /system and runtime APEX dir
+                // structure on host.
+                "tzdata_host",
+                "tzdata_host_runtime_apex",
+                "tzlookup.xml_host_runtime_apex",
+                "tz_version_host",
+                "tz_version_host_runtime_apex",
+            ],
+        },
+    },
 }
 
 // Provided solely to contribute information about which hidden parts of the
diff --git a/luni/src/main/java/libcore/io/BlockGuardOs.java b/luni/src/main/java/libcore/io/BlockGuardOs.java
index d56e182..bd95a93 100644
--- a/luni/src/main/java/libcore/io/BlockGuardOs.java
+++ b/luni/src/main/java/libcore/io/BlockGuardOs.java
@@ -121,14 +121,29 @@
         return linger.isOn() && linger.l_linger > 0;
     }
 
-    @Override public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException {
-        BlockGuard.getThreadPolicy().onNetwork();
+    private static boolean isUdpSocket(FileDescriptor fd) throws ErrnoException {
+        return Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_PROTOCOL) == IPPROTO_UDP;
+    }
+
+    @Override public void connect(FileDescriptor fd, InetAddress address, int port)
+            throws ErrnoException, SocketException {
+        boolean skipGuard = false;
+        try {
+            skipGuard = isUdpSocket(fd);
+        } catch (ErrnoException ignored) {
+        }
+        if (!skipGuard) BlockGuard.getThreadPolicy().onNetwork();
         super.connect(fd, address, port);
     }
 
     @Override public void connect(FileDescriptor fd, SocketAddress address) throws ErrnoException,
             SocketException {
-        BlockGuard.getThreadPolicy().onNetwork();
+        boolean skipGuard = false;
+        try {
+            skipGuard = isUdpSocket(fd);
+        } catch (ErrnoException ignored) {
+        }
+        if (!skipGuard) BlockGuard.getThreadPolicy().onNetwork();
         super.connect(fd, address);
     }
 
diff --git a/luni/src/test/java/libcore/libcore/io/BlockGuardOsTest.java b/luni/src/test/java/libcore/libcore/io/BlockGuardOsTest.java
index 471906f..0e2c6b5 100644
--- a/luni/src/test/java/libcore/libcore/io/BlockGuardOsTest.java
+++ b/luni/src/test/java/libcore/libcore/io/BlockGuardOsTest.java
@@ -16,6 +16,12 @@
 
 package libcore.libcore.io;
 
+import static android.system.OsConstants.AF_INET6;
+import static android.system.OsConstants.IPPROTO_TCP;
+import static android.system.OsConstants.IPPROTO_UDP;
+import static android.system.OsConstants.SOCK_DGRAM;
+import static android.system.OsConstants.SOCK_STREAM;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -28,6 +34,8 @@
 import android.system.OsConstants;
 import android.system.StructAddrinfo;
 
+import java.io.FileDescriptor;
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.net.InetAddress;
@@ -39,6 +47,8 @@
 import java.util.regex.Pattern;
 
 import libcore.io.BlockGuardOs;
+import libcore.io.IoUtils;
+import libcore.io.Libcore;
 import libcore.io.Os;
 
 import dalvik.system.BlockGuard;
@@ -48,6 +58,8 @@
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -130,6 +142,31 @@
         }
     }
 
+    @Test
+    public void test_connect_networkPolicy() throws ErrnoException, IOException {
+        BlockGuardOs blockGuardOs = new BlockGuardOs(mockOsDelegate);
+
+        // Test connect with a UDP socket that will not trigger a network policy check.
+        FileDescriptor udpSocket = Libcore.os.socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+        try {
+            blockGuardOs.connect(udpSocket, InetAddress.getLoopbackAddress(), 0);
+            verify(mockThreadPolicy, never()).onNetwork();
+            verify(mockOsDelegate, times(1)).connect(eq(udpSocket), any(), anyInt());
+        } finally {
+            IoUtils.closeQuietly(udpSocket);
+        }
+
+        // Test connect with a TCP socket that will trigger a network policy check.
+        FileDescriptor tcpSocket = Libcore.os.socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
+        try {
+            blockGuardOs.connect(tcpSocket, InetAddress.getLoopbackAddress(), 0);
+            verify(mockThreadPolicy, times(1)).onNetwork();
+            verify(mockOsDelegate, times(1)).connect(eq(tcpSocket), any(), anyInt());
+        } finally {
+            IoUtils.closeQuietly(tcpSocket);
+        }
+    }
+
     /**
      * Checks that BlockGuardOs is updated when the Os interface changes. BlockGuardOs extends
      * ForwardingOs so doing so isn't an obvious step and it can be missed. When adding methods to
diff --git a/luni/src/test/java/libcore/libcore/timezone/ZoneInfoDBTest.java b/luni/src/test/java/libcore/libcore/timezone/ZoneInfoDBTest.java
index 3f4791c..ef70236 100644
--- a/luni/src/test/java/libcore/libcore/timezone/ZoneInfoDBTest.java
+++ b/luni/src/test/java/libcore/libcore/timezone/ZoneInfoDBTest.java
@@ -18,7 +18,6 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.RandomAccessFile;
 
 import libcore.timezone.TimeZoneDataFiles;
diff --git a/ojluni/Android.bp b/ojluni/Android.bp
new file mode 100644
index 0000000..20a5a5a
--- /dev/null
+++ b/ojluni/Android.bp
@@ -0,0 +1,26 @@
+// Copyright (C) 2019 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.
+
+// Phony target that causes the build to check the license file in this
+// directory, detect that it is a GPL license and then copy all the files
+// from this directory and its subdirectories in to the
+// ${OUT}/obj/PACKAGING/gpl_source_intermediates/gpl_source.tgz file.
+phony {
+    name: "ojluni-phony",
+
+    // A phony module must have at least one dependency.
+    required: [
+        "core-oj",
+    ],
+}
diff --git a/ojluni/Android.mk b/ojluni/Android.mk
deleted file mode 100644
index 8eef8b5..0000000
--- a/ojluni/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-# -*- mode: makefile -*-
-# Copyright (C) 2016 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.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := ojluni-phony
-include $(BUILD_PHONY_PACKAGE)
-
diff --git a/ojluni/src/main/java/java/lang/System.java b/ojluni/src/main/java/java/lang/System.java
index 8235bf7..d698446 100644
--- a/ojluni/src/main/java/java/lang/System.java
+++ b/ojluni/src/main/java/java/lang/System.java
@@ -509,13 +509,9 @@
      * The byte[] specialized version of arraycopy().
      * Note: This method is required for runtime ART compiler optimizations.
      * Do not remove or change the signature.
-     * Note: Unlike the others, this variant is public due to a dependency we
-     * are working on removing. b/74103559
-     *
-     * @hide
      */
     @SuppressWarnings("unused")
-    public static void arraycopy(byte[] src, int srcPos, byte[] dst, int dstPos, int length) {
+    private static void arraycopy(byte[] src, int srcPos, byte[] dst, int dstPos, int length) {
         if (src == null) {
             throw new NullPointerException("src == null");
         }