Duplicate the fd instead of reference

The mFd member was assigned with the original fd. When the auto
Keepalive was closed as system tried to create another auto
Keepalive, the real fd would be closed unexpected. The fd
assignment should come from a duplicate as what the code does
for auto keepalvie.

Bug: 290094178
Test: atest FrameworksNetTests
Test: atest android.net.cts.ConnectivityManagerTest
Change-Id: Ibc153c3f37f9e755446179d3b67178335bc2633d
diff --git a/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java b/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
index 368860e..d03cac6 100644
--- a/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
+++ b/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
@@ -495,8 +495,11 @@
         final AutomaticOnOffKeepalive autoKi;
         try {
             autoKi = target.withKeepaliveInfo(res.second);
-            // Close the duplicated fd.
-            target.close();
+            // Only automatic keepalives duplicate the fd.
+            if (target.mAutomaticOnOffState != STATE_ALWAYS_ON) {
+                // Close the duplicated fd.
+                target.close();
+            }
         } catch (InvalidSocketException e) {
             Log.wtf(TAG, "Fail to create AutomaticOnOffKeepalive", e);
             return;