Zygote: Increase wrap-pid timeout to thirty seconds

Some lowend devices under heavy instrumentation may not be able to
send the pid in the current five seconds. Drop the safety and
ignore watchdog debug builds, and move the timeout to thirty seconds.

Make the ZygoteConnection constants sharable in their own @hide class.
Add an assert into the watchdog that the wait time is less than the
watchdog time on non-debug builds.

(cherry picked from commit 27497c6dfc03242abfe7c087fcaf37e684529678)

Bug: 63904739
Bug: 63638768
Test: m
Test: manual test
Test: cts-tradefed run commandAndExit cts-dev -m CtsWrapWrapDebugTestCases
Change-Id: I80abdda54cd94e935de5a52b9f3c9192d0e31060
diff --git a/services/core/java/com/android/server/Watchdog.java b/services/core/java/com/android/server/Watchdog.java
index aceedf1..6a81d32 100644
--- a/services/core/java/com/android/server/Watchdog.java
+++ b/services/core/java/com/android/server/Watchdog.java
@@ -19,6 +19,7 @@
 import android.app.IActivityController;
 import android.os.Binder;
 import android.os.RemoteException;
+import com.android.internal.os.ZygoteConnectionConstants;
 import com.android.server.am.ActivityManagerService;
 
 import android.content.BroadcastReceiver;
@@ -57,6 +58,11 @@
     // Set this to true to have the watchdog record kernel thread stacks when it fires
     static final boolean RECORD_KERNEL_THREADS = true;
 
+    // Note 1: Do not lower this value below thirty seconds without tightening the invoke-with
+    //         timeout in com.android.internal.os.ZygoteConnection, or wrapped applications
+    //         can trigger the watchdog.
+    // Note 2: The debug value is already below the wait time in ZygoteConnection. Wrapped
+    //         applications may not work with a debug build. CTS will fail.
     static final long DEFAULT_TIMEOUT = DB ? 10*1000 : 60*1000;
     static final long CHECK_INTERVAL = DEFAULT_TIMEOUT / 2;
 
@@ -262,6 +268,10 @@
 
         // Initialize monitor for Binder threads.
         addMonitor(new BinderThreadMonitor());
+
+        // See the notes on DEFAULT_TIMEOUT.
+        assert DB ||
+                DEFAULT_TIMEOUT > ZygoteConnectionConstants.WRAPPED_PID_TIMEOUT_MILLIS;
     }
 
     public void init(Context context, ActivityManagerService activity) {