[NS05.1] Fix WifiNetworkFactoryTest for network offer architecture

By the new design, NetworkFactory will no longer see
CMD_REQUEST_NETWORK sent from ConnectivityService. Instead,
ConnectivityService will send NetworkOfferCallback#onNetworkNeeded
when an network is needed. Current test method is no longer
a valid way.

Thus, sync current implementation from internal branch with some
modifications to reflect the current behavior.

Note that the Merged-In tag points to a random CL in the same git
and only presents in internal branches to prevent this CL from
getting merged to internal branches that do not need this solution.

Test: atest com.android.server.wifi.WifiNetworkFactoryTest#testFullHandleNetworkRequestWithSpecifierWhenWifiOff
Bug: 167544279

Merged-In: I17e7a595d048aa428fb944de39c1f1f82217f2a9
Change-Id: I44926a01d4f7c1106833237bd30af7d8755eda4b
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
index 18ddfdb..516dd32 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
@@ -19,7 +19,6 @@
 import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
 import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE;
 import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_GONE;
-import static android.net.NetworkFactory.CMD_REQUEST_NETWORK;
 
 import static com.android.server.wifi.WifiNetworkFactory.PERIODIC_SCAN_INTERVAL_MS;
 import static com.android.server.wifi.util.NativeUtil.addEnclosingQuotes;
@@ -55,7 +54,6 @@
 import android.net.wifi.WifiSsid;
 import android.os.Binder;
 import android.os.IBinder;
-import android.os.Message;
 import android.os.PatternMatcher;
 import android.os.Process;
 import android.os.RemoteException;
@@ -2228,30 +2226,21 @@
     }
 
     /**
-     * Verify handling of new network request with network specifier when wifi is off & then on.
-     * Note: Unlike the other unit tests, this test invokes the top level
-     * {@link NetworkFactory#CMD_REQUEST_NETWORK} to simulate the full flow.
+     * Verify handling of new network request with network specifier when wifi is off.
+     * The request should be rejected immediately.
      */
     @Test
     public void testFullHandleNetworkRequestWithSpecifierWhenWifiOff() {
         attachDefaultWifiNetworkSpecifierAndAppInfo(TEST_UID_1, false);
 
-        // set wifi off
+        // wifi off
         mWifiNetworkFactory.setWifiState(false);
         // Add the request, should do nothing.
-        Message message = Message.obtain();
-        message.what = CMD_REQUEST_NETWORK;
-        message.obj = mNetworkRequest;
-        mWifiNetworkFactory.sendMessage(message);
+        mWifiNetworkFactory.needNetworkFor(mNetworkRequest);
         mLooper.dispatchAll();
         verify(mWifiScanner, never()).startScan(any(), any(), any(), any());
-
-        // set wifi on
-        mWifiNetworkFactory.setWifiState(true);
-        mLooper.dispatchAll();
-        // Should trigger a re-evaluation of existing requests and the pending request will be
-        // processed now.
-        verify(mWifiScanner).startScan(any(), any(), any(), any());
+        // TODO: Send an immediate failure when wifi is off.
+        // verify(mConnectivityManager).declareNetworkRequestUnfulfillable(eq(mNetworkRequest));
     }
 
     /**