Merge pi-dev-plus-aosp-without-vendor into stage-aosp-master

Bug: 79597307
Change-Id: I45489eff1527f680a5822b147469c30a409261df
diff --git a/msm8998/hal/src/HAL.cpp b/msm8998/hal/src/HAL.cpp
index e19a149..42fe868 100644
--- a/msm8998/hal/src/HAL.cpp
+++ b/msm8998/hal/src/HAL.cpp
@@ -408,7 +408,7 @@
     fl.addArg("prefixes", prefixesStr);
 
     if (!isInitialized()) {
-        BoolResult res = makeInputCheckFailure("Not initialized");
+        res = makeInputCheckFailure("Not initialized");
     } else if(prefixesStr.size() < 1) {
         res = ipaResultToBoolResult(RET::FAIL_INPUT_CHECK);
     } else if (!parser.add(prefixesStr)) {
@@ -611,9 +611,11 @@
 
 Return<void> HAL::debug
 (
-    const hidl_handle& fd,
+    const hidl_handle& handle,
     const hidl_vec<hidl_string>& /* options */
 ) {
-    mLogs.toFd(fd->data[0]);
+    if (handle != nullptr && handle->numFds >= 1) {
+        mLogs.toFd(handle->data[0]);
+    }
     return Void();
 } /* debug */
diff --git a/msm8998/ipacm/src/IPACM_Main.cpp b/msm8998/ipacm/src/IPACM_Main.cpp
index 13cdb51..62dc596 100644
--- a/msm8998/ipacm/src/IPACM_Main.cpp
+++ b/msm8998/ipacm/src/IPACM_Main.cpp
@@ -694,6 +694,7 @@
 			if (OffloadMng->elrInstance == NULL) {
 				IPACMERR("OffloadMng->elrInstance is NULL, can't forward to framework!\n");
 			} else {
+				IPACMERR("calling OffloadMng->elrInstance->onLimitReached \n");
 				OffloadMng->elrInstance->onLimitReached();
 			}
 			continue;
@@ -703,6 +704,7 @@
 			if (OffloadMng->elrInstance == NULL) {
 				IPACMERR("OffloadMng->elrInstance is NULL, can't forward to framework!\n");
 			} else {
+				IPACMERR("calling OffloadMng->elrInstance->onOffloadStopped \n");
 				OffloadMng->elrInstance->onOffloadStopped(IpaEventRelay::ERROR);
 			}
 			continue;
@@ -712,6 +714,7 @@
 			if (OffloadMng->elrInstance == NULL) {
 				IPACMERR("OffloadMng->elrInstance is NULL, can't forward to framework!\n");
 			} else {
+				IPACMERR("calling OffloadMng->elrInstance->onOffloadSupportAvailable \n");
 				OffloadMng->elrInstance->onOffloadSupportAvailable();
 			}
 			continue;
diff --git a/msm8998/ipacm/src/IPACM_OffloadManager.cpp b/msm8998/ipacm/src/IPACM_OffloadManager.cpp
index 2061fd2..1645e89 100644
--- a/msm8998/ipacm/src/IPACM_OffloadManager.cpp
+++ b/msm8998/ipacm/src/IPACM_OffloadManager.cpp
@@ -59,6 +59,8 @@
 	upstream_v6_up = false;
 	memset(event_cache, 0, MAX_EVENT_CACHE*sizeof(framework_event_cache));
 	latest_cache_index = 0;
+	elrInstance = NULL;
+	touInstance = NULL;
 	return ;
 }
 
@@ -347,7 +349,15 @@
 	if(upstream_name == NULL)
 	{
 		if (default_gw_index == INVALID_IFACE) {
-			IPACMERR("no previous upstream set before\n");
+			for (index = 0; index < MAX_EVENT_CACHE; index++) {
+  				if (event_cache[index].valid == true &&
+      			            event_cache[index].event == IPA_WAN_UPSTREAM_ROUTE_ADD_EVENT) {
+    					event_cache[index].valid = false;
+    					memset(event_cache, 0, MAX_EVENT_CACHE*sizeof(framework_event_cache));
+    					return SUCCESS;
+  				}
+			}
+                        IPACMERR("no previous upstream set before\n");
 			return FAIL_INPUT_CHECK;
 		}
 		if (gw_addr_v4.fam == V4 && upstream_v4_up == true) {