Restore early AIDL initialization if the
-B daemonize option is not being used.

AIDL initialization was moved in ag/22511957,
but this causes issues if interfaces are added
before the delayed AIDL initialization.

Bug: 285101633
Test: Manual test - enable and disable the -B
       daemonize option. Check that AIDL is
       initialized at the right time for each case.
Change-Id: I6ba6dc0e6ae3d4ba7b42a0998fe9b0f3f72f82d7
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index 943897d..89a0389 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -37,6 +37,16 @@
 	}
 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
 
+#ifdef CONFIG_AIDL
+	// Initialize AIDL here if daemonize is disabled.
+	// Otherwise initialize it later.
+	if (!global->params.daemonize) {
+		global->aidl = wpas_aidl_init(global);
+		if (!global->aidl)
+			return -1;
+	}
+#endif /* CONFIG_AIDL */
+
 	return 0;
 }
 
@@ -63,13 +73,14 @@
 	}
 
 #ifdef CONFIG_AIDL
-	/* AIDL initialization may not be complete at this point.
+	/*
+	 * AIDL initialization may not be complete here if daemonize is enabled.
 	 * Initialization is done after daemonizing in order to avoid
 	 * issues with the file descriptor.
 	 */
-	if (!wpa_s || !wpa_s->global->aidl)
+	if (!wpa_s->global->aidl)
 		return 0;
-	/* HIDL interface wants to keep track of the P2P mgmt iface. */
+	/* AIDL interface wants to keep track of the P2P mgmt iface. */
 	if (wpas_aidl_register_interface(wpa_s))
 		return -1;
 #endif
@@ -85,7 +96,7 @@
 		wpas_dbus_unregister_interface(wpa_s);
 	}
 
-	/* HIDL interface wants to keep track of the P2P mgmt iface. */
+	/* AIDL interface wants to keep track of the P2P mgmt iface. */
 	wpas_aidl_unregister_interface(wpa_s);
 }