Merge "Update cpu_usage to collect thread and mem info" into main
diff --git a/cmake/netsim_dependencies.cmake b/cmake/netsim_dependencies.cmake
index 38290c1..72f814e 100644
--- a/cmake/netsim_dependencies.cmake
+++ b/cmake/netsim_dependencies.cmake
@@ -122,13 +122,6 @@
 
 prebuilt(Threads)
 
-# We need the auto generated header for some components, so let's set the
-# ANDROID_HW_CONFIG_H variable to point to the generated header. Those that need
-# it can add it to their sources list, and it will be there.
-set(HW_PROPERTIES_INI
-    ${EXTERNAL_QEMU}/android/emu/avd/src/android/avd/hardware-properties.ini)
-android_generate_hw_config()
-
 if(DARWIN_AARCH64 AND NOT Rust_COMPILER)
   message(
     STATUS
@@ -200,21 +193,13 @@
 add_subdirectory(${EXTERNAL_QEMU}/android/third_party/googletest/ gtest)
 add_subdirectory(${EXTERNAL_QEMU}/android/third_party/lz4 lz4)
 add_subdirectory(${EXTERNAL_QEMU}/android/third_party/re2 re2)
-add_subdirectory(${EXTERNAL_QEMU}/android/third_party/libselinux libselinux)
-add_subdirectory(${EXTERNAL_QEMU}/android/third_party/libsparse libsparse)
-add_subdirectory(${EXTERNAL_QEMU}/android/third_party/ext4_utils ext4_utils)
 add_subdirectory(${EXTERNAL}/cares cares)
 add_subdirectory(${EXTERNAL}/glib/glib glib2)
 add_subdirectory(${EXTERNAL}/grpc/emulator grpc)
 add_subdirectory(${EXTERNAL}/qemu/android/android-emu-base android-emu-base)
 add_subdirectory(${EXTERNAL}/qemu/android/android-net/android android-emu-net)
-add_subdirectory(${EXTERNAL}/qemu/android-qemu2-glue/netsim
-                 android-wifi-service)
 add_subdirectory(${EXTERNAL}/qemu/android/emu/base emu-base)
 add_subdirectory(${EXTERNAL}/qemu/android/emu/utils android-emu-utils)
-add_subdirectory(${EXTERNAL}/qemu/android/emu/files android-emu-files)
-add_subdirectory(${EXTERNAL}/qemu/android/emu/agents android-emu-agents)
-add_subdirectory(${EXTERNAL}/qemu/android/emu/proxy android-emu-proxy)
 add_subdirectory(${EXTERNAL}/webrtc/third_party/jsoncpp jsoncpp)
 
 # Short term fix for missing glib2 dll for Windows build
diff --git a/dummy.c b/dummy.c
deleted file mode 100644
index e69de29..0000000
--- a/dummy.c
+++ /dev/null
diff --git a/rust/cli/Cargo.toml b/rust/cli/Cargo.toml
index 0a3dcf2..eaff581 100644
--- a/rust/cli/Cargo.toml
+++ b/rust/cli/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "netsim-cli"
-version = "0.3.43"
+version = "0.3.45"
 edition = "2021"
 
 [lib]
diff --git a/rust/common/Cargo.toml b/rust/common/Cargo.toml
index bb96d4e..9c8a0f5 100644
--- a/rust/common/Cargo.toml
+++ b/rust/common/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "netsim-common"
-version = "0.3.43"
+version = "0.3.45"
 edition = "2021"
 
 [lib]
diff --git a/rust/daemon/Cargo.toml b/rust/daemon/Cargo.toml
index 7463acd..fd88b53 100644
--- a/rust/daemon/Cargo.toml
+++ b/rust/daemon/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "netsim-daemon"
-version = "0.3.43"
+version = "0.3.45"
 edition = "2021"
 build = "build.rs"
 
diff --git a/rust/daemon/src/grpc_server/server.rs b/rust/daemon/src/grpc_server/server.rs
index b94e261..7d81164 100644
--- a/rust/daemon/src/grpc_server/server.rs
+++ b/rust/daemon/src/grpc_server/server.rs
@@ -27,7 +27,7 @@
     let backend_service = create_packet_streamer(PacketStreamerService);
     let frontend_service = create_frontend_service(FrontendClient);
     let quota = ResourceQuota::new(Some("NetsimGrpcServerQuota")).resize_memory(1024 * 1024);
-    let ch_builder = ChannelBuilder::new(env.clone()).set_resource_quota(quota);
+    let ch_builder = ChannelBuilder::new(env.clone()).set_resource_quota(quota).reuse_port(false);
     let mut server_builder = ServerBuilder::new(env);
     if !no_cli_ui {
         server_builder = server_builder.register_service(frontend_service);
diff --git a/rust/daemon/src/rust_main.rs b/rust/daemon/src/rust_main.rs
index e3af7d1..bc71b28 100644
--- a/rust/daemon/src/rust_main.rs
+++ b/rust/daemon/src/rust_main.rs
@@ -286,34 +286,40 @@
     let mut service = unsafe { Service::new(service_params) };
 
     // Run all netsimd services (grpc, socket, web)
-    if let Ok((grpc_port, web_port)) = service.run() {
-        // If create_ini fails, check if there is another netsimd instance.
-        // If there isn't another netsimd instance, remove_ini and create_ini once more.
-        for _ in 0..2 {
-            if let Err(e) = create_ini(instance_num, grpc_port, web_port) {
-                warn!("create_ini error with {e:?}");
-                // Continue if the address overlaps to support Oxygen CF Boot.
-                // The pre-warmed device may leave stale netsim ini with the same grpc port.
-                if let Some(address) = get_server_address(instance_num) {
-                    // If the address matches, break the loop and continue running netsimd.
-                    if address == format!("localhost:{grpc_port}") {
-                        info!("Reusing existing netsim ini with grpc_port: {grpc_port}");
-                        break;
+    match service.run() {
+        Err(e) => {
+            error!("service.run() -> Err({e:?})");
+            return;
+        }
+        Ok((grpc_port, web_port)) => {
+            // If create_ini fails, check if there is another netsimd instance.
+            // If there isn't another netsimd instance, remove_ini and create_ini once more.
+            for _ in 0..2 {
+                if let Err(e) = create_ini(instance_num, grpc_port, web_port) {
+                    warn!("create_ini error with {e:?}");
+                    // Continue if the address overlaps to support Oxygen CF Boot.
+                    // The pre-warmed device may leave stale netsim ini with the same grpc port.
+                    if let Some(address) = get_server_address(instance_num) {
+                        // If the address matches, break the loop and continue running netsimd.
+                        if address == format!("localhost:{grpc_port}") {
+                            info!("Reusing existing netsim ini with grpc_port: {grpc_port}");
+                            break;
+                        }
                     }
-                }
-                // Checkes if a different netsimd instance exists
-                if is_netsimd_alive(instance_num) {
-                    warn!("netsimd already running, exiting...");
-                    service.shut_down();
-                    return;
+                    // Checkes if a different netsimd instance exists
+                    if is_netsimd_alive(instance_num) {
+                        warn!("netsimd already running, exiting...");
+                        service.shut_down();
+                        return;
+                    } else {
+                        info!("Removing stale netsim ini");
+                        if let Err(e) = remove_ini(instance_num) {
+                            error!("{e:?}");
+                        }
+                    }
                 } else {
-                    info!("Removing stale netsim ini");
-                    if let Err(e) = remove_ini(instance_num) {
-                        error!("{e:?}");
-                    }
+                    break;
                 }
-            } else {
-                break;
             }
         }
     }
diff --git a/rust/daemon/src/version.rs b/rust/daemon/src/version.rs
index f018873..f63856c 100644
--- a/rust/daemon/src/version.rs
+++ b/rust/daemon/src/version.rs
@@ -16,7 +16,7 @@
 
 /// Version library.
 
-pub const VERSION: &str = "0.3.43";
+pub const VERSION: &str = "0.3.45";
 
 pub fn get_version() -> String {
     VERSION.to_owned()