Fix bootloop caused by null mIpClient in ClientModeImpl

Check if mIpClient is null before every access of this member variable.

Bug: 123990895
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: manually test that device does not bootloop.
Change-Id: I5f173981484cc8b47053152a1c5409f167979e29
(cherry picked from commit 6bd79980828fd0a6a58a0675a34c548fd5e15251)
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index 1a47d0b..ae3c125 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -3660,10 +3660,12 @@
                     break;
                 case CMD_READ_PACKET_FILTER:
                     byte[] data = mWifiNative.readPacketFilter(mInterfaceName);
-                    try {
-                        mIpClient.readPacketFilterComplete(data);
-                    } catch (RemoteException e) {
-                        loge("Error notifying IpClient of packet filter read", e);
+                    if (mIpClient != null) {
+                        try {
+                            mIpClient.readPacketFilterComplete(data);
+                        } catch (RemoteException e) {
+                            loge("Error notifying IpClient of packet filter read", e);
+                        }
                     }
                     break;
                 case CMD_SET_FALLBACK_PACKET_FILTERING:
@@ -4016,10 +4018,12 @@
                     // DNAv4/DNAv6 -style probing for on-link neighbors of
                     // interest (e.g. routers); harmless if none are configured.
                     if (state == SupplicantState.COMPLETED) {
-                        try {
-                            mIpClient.confirmConfiguration();
-                        } catch (RemoteException e) {
-                            loge("Error confirming IpClient configuration", e);
+                        if (mIpClient != null) {
+                            try {
+                                mIpClient.confirmConfiguration();
+                            } catch (RemoteException e) {
+                                loge("Error confirming IpClient configuration", e);
+                            }
                         }
                         mWifiScoreReport.noteIpCheck();
                     }
@@ -4303,12 +4307,14 @@
                             startConnectToNetwork(netId, message.sendingUid, SUPPLICANT_BSSID_ANY);
                         } else {
                             if (result.hasProxyChanged()) {
-                                log("Reconfiguring proxy on connection");
-                                try {
-                                    mIpClient.setHttpProxy(toStableParcelable(
-                                            getCurrentWifiConfiguration().getHttpProxy()));
-                                } catch (RemoteException e) {
-                                    loge("Error setting IpClient proxy", e);
+                                if (mIpClient != null) {
+                                    log("Reconfiguring proxy on connection");
+                                    try {
+                                        mIpClient.setHttpProxy(toStableParcelable(
+                                                getCurrentWifiConfiguration().getHttpProxy()));
+                                    } catch (RemoteException e) {
+                                        loge("Error setting IpClient proxy", e);
+                                    }
                                 }
                             }
                             if (result.hasIpChanged()) {
@@ -4847,10 +4853,12 @@
 
         @Override
         public void exit() {
-            try {
-                mIpClient.stop();
-            } catch (RemoteException e) {
-                loge("Error stopping IpClient", e);
+            if (mIpClient != null) {
+                try {
+                    mIpClient.stop();
+                } catch (RemoteException e) {
+                    loge("Error stopping IpClient", e);
+                }
             }
 
             // This is handled by receiving a NETWORK_DISCONNECTION_EVENT in ConnectModeState
@@ -4882,10 +4890,12 @@
                     handlePreDhcpSetup();
                     break;
                 case CMD_PRE_DHCP_ACTION_COMPLETE:
-                    try {
-                        mIpClient.completedPreDhcpAction();
-                    } catch (RemoteException e) {
-                        loge("Error completing PreDhcpAction", e);
+                    if (mIpClient != null) {
+                        try {
+                            mIpClient.completedPreDhcpAction();
+                        } catch (RemoteException e) {
+                            loge("Error completing PreDhcpAction", e);
+                        }
                     }
                     break;
                 case CMD_POST_DHCP_ACTION:
@@ -5002,10 +5012,12 @@
                                 mWifiInfo, mNetworkAgent, mWifiMetrics);
                         mWifiMetrics.updateWifiUsabilityStatsEntries(mWifiInfo, stats);
                         if (mWifiScoreReport.shouldCheckIpLayer()) {
-                            try {
-                                mIpClient.confirmConfiguration();
-                            } catch (RemoteException e) {
-                                loge("Error confirming IpClient configuration", e);
+                            if (mIpClient != null) {
+                                try {
+                                    mIpClient.confirmConfiguration();
+                                } catch (RemoteException e) {
+                                    loge("Error confirming IpClient configuration", e);
+                                }
                             }
                             mWifiScoreReport.noteIpCheck();
                         }
@@ -5161,16 +5173,20 @@
             // CONNECTED.
             stopIpClient();
 
-            try {
-                mIpClient.setHttpProxy(toStableParcelable(currentConfig.getHttpProxy()));
-            } catch (RemoteException e) {
-                loge("Error setting IpClient proxy", e);
+            if (mIpClient != null) {
+                try {
+                    mIpClient.setHttpProxy(toStableParcelable(currentConfig.getHttpProxy()));
+                } catch (RemoteException e) {
+                    loge("Error setting IpClient proxy", e);
+                }
             }
             if (!TextUtils.isEmpty(mTcpBufferSizes)) {
-                try {
-                    mIpClient.setTcpBufferSizes(mTcpBufferSizes);
-                } catch (RemoteException e) {
-                    loge("Error setting IpClient TCP buffer sizes", e);
+                if (mIpClient != null) {
+                    try {
+                        mIpClient.setTcpBufferSizes(mTcpBufferSizes);
+                    } catch (RemoteException e) {
+                        loge("Error setting IpClient TCP buffer sizes", e);
+                    }
                 }
             }
             final ProvisioningConfiguration prov;
@@ -5191,10 +5207,12 @@
                             .withDisplayName(currentConfig.SSID)
                             .build();
             }
-            try {
-                mIpClient.startProvisioning(prov.toStableParcelable());
-            } catch (RemoteException e) {
-                loge("Error starting IpClient provisioning", e);
+            if (mIpClient != null) {
+                try {
+                    mIpClient.startProvisioning(prov.toStableParcelable());
+                } catch (RemoteException e) {
+                    loge("Error starting IpClient provisioning", e);
+                }
             }
             // Get Link layer stats so as we get fresh tx packet counters
             getWifiLinkLayerStats();