From 719b6ae422910df0c17ae36deba0acc08d9a8943 Mon Sep 17 00:00:00 2001 From: Zhao Sun Date: Fri, 4 May 2018 20:53:07 +0800 Subject: Add null check on getting p2p iface name Cherry-picked from partners After tearing down client interface, p2p interface will be invalid and null is returned when getting p2p interface name. When Wifi on/off is quickly repeated, a crash happens due to NullPointerException because WifiP2pNative#setupInterface is called and trying to get p2p interface name at that time while p2p iface is marked as invalid (client mode is shutting down). This patch adds null check on getting p2p iface name to avoid crash. Bug: 80095183 Test: manual Change-Id: I8aee5e3ca4d77eae3ed94aa76f6666649424e690 --- service/java/com/android/server/wifi/p2p/WifiP2pNative.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pNative.java b/service/java/com/android/server/wifi/p2p/WifiP2pNative.java index 07ee11e3b..de608b133 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pNative.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pNative.java @@ -24,6 +24,7 @@ import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pGroupList; import android.net.wifi.p2p.nsd.WifiP2pServiceInfo; import android.os.Handler; +import android.text.TextUtils; import android.util.Log; import com.android.server.wifi.HalDeviceManager; @@ -190,7 +191,13 @@ public class WifiP2pNative { teardownInterface(); return null; } - if (!mSupplicantP2pIfaceHal.setupIface(HalDeviceManager.getName(mIWifiP2pIface))) { + String ifaceName = HalDeviceManager.getName(mIWifiP2pIface); + if (TextUtils.isEmpty(ifaceName)) { + Log.e(TAG, "Failed to get p2p iface name"); + teardownInterface(); + return null; + } + if (!mSupplicantP2pIfaceHal.setupIface(ifaceName)) { Log.e(TAG, "Failed to setup P2p iface in supplicant"); teardownInterface(); return null; -- cgit v1.2.3