Remove kDefaultHalClientId
Replace kDefaultHalClientId with chre::kHostClientIdUnspecified
to simplify the maintenance.
Test: unit test
Bug: 307749518
Change-Id: I98d70bfcfb280d1970af04792abedae7a2bb36a1
diff --git a/host/hal_generic/common/hal_client_id.h b/host/hal_generic/common/hal_client_id.h
index fb6e2a5..778a59d 100644
--- a/host/hal_generic/common/hal_client_id.h
+++ b/host/hal_generic/common/hal_client_id.h
@@ -17,6 +17,7 @@
#ifndef ANDROID_HARDWARE_CONTEXTHUB_COMMON_HAL_CLIENT_ID_H_
#define ANDROID_HARDWARE_CONTEXTHUB_COMMON_HAL_CLIENT_ID_H_
+#include <cstdint>
#include <limits>
namespace android::hardware::contexthub::common::implementation {
@@ -29,9 +30,6 @@
/** Max number of HAL clients supported. */
constexpr uint16_t kMaxNumOfHalClients = kMaxHalClientId - 1;
-/** The default HAL client id indicating the id is not assigned. */
-constexpr HalClientId kDefaultHalClientId = 0;
-
/**
* The HAL client id indicating the message is actually sent to the HAL itself.
*/
diff --git a/host/hal_generic/common/hal_client_manager.cc b/host/hal_generic/common/hal_client_manager.cc
index 2f0099b..320282f 100644
--- a/host/hal_generic/common/hal_client_manager.cc
+++ b/host/hal_generic/common/hal_client_manager.cc
@@ -98,7 +98,7 @@
const HalClient *client = getClientByProcessIdLocked(pid);
if (client == nullptr) {
LOGE("Failed to find the client id for pid %d", pid);
- return kDefaultHalClientId;
+ return ::chre::kHostClientIdUnspecified;
}
return client->clientId;
}
diff --git a/host/hal_generic/common/hal_client_manager.h b/host/hal_generic/common/hal_client_manager.h
index c16e759..888ce5f 100644
--- a/host/hal_generic/common/hal_client_manager.h
+++ b/host/hal_generic/common/hal_client_manager.h
@@ -16,18 +16,21 @@
#ifndef ANDROID_HARDWARE_CONTEXTHUB_COMMON_HAL_CLIENT_MANAGER_H_
#define ANDROID_HARDWARE_CONTEXTHUB_COMMON_HAL_CLIENT_MANAGER_H_
-#include <aidl/android/hardware/contexthub/ContextHubMessage.h>
-#include <aidl/android/hardware/contexthub/IContextHub.h>
-#include <aidl/android/hardware/contexthub/IContextHubCallback.h>
-#include <chre_host/fragmented_load_transaction.h>
-#include <chre_host/preloaded_nanoapp_loader.h>
+#include "chre/platform/shared/host_protocol_common.h"
+#include "chre_host/fragmented_load_transaction.h"
+#include "chre_host/log.h"
+#include "chre_host/preloaded_nanoapp_loader.h"
+#include "hal_client_id.h"
+
#include <sys/types.h>
#include <cstddef>
#include <unordered_map>
#include <unordered_set>
#include <utility>
-#include "chre_host/log.h"
-#include "hal_client_id.h"
+
+#include <aidl/android/hardware/contexthub/ContextHubMessage.h>
+#include <aidl/android/hardware/contexthub/IContextHub.h>
+#include <aidl/android/hardware/contexthub/IContextHubCallback.h>
using aidl::android::hardware::contexthub::ContextHubMessage;
using aidl::android::hardware::contexthub::HostEndpointInfo;
@@ -85,6 +88,7 @@
public:
struct HalClient {
static constexpr pid_t PID_UNSET = 0;
+
explicit HalClient(const std::string &uuid, const HalClientId clientId)
: HalClient(uuid, clientId, /* pid= */ PID_UNSET,
/* callback= */ nullptr,
@@ -98,6 +102,7 @@
pid{pid},
callback{callback},
deathRecipientCookie{deathRecipientCookie} {}
+
/** Resets the client's fields except uuid and clientId. */
void reset(pid_t processId,
const std::shared_ptr<IContextHubCallback> &contextHubCallback,
@@ -107,6 +112,7 @@
deathRecipientCookie = cookie;
endpointIds.clear();
}
+
const std::string uuid;
const HalClientId clientId;
pid_t pid{};
@@ -136,8 +142,8 @@
*
* @param pid process id of the current client
*
- * @return client id assigned to the calling process, or kDefaultHalClientId
- * if the process id is not found.
+ * @return client id assigned to the calling process, or
+ * ::chre::kHostClientIdUnspecified if the process id is not found.
*/
HalClientId getClientId(pid_t pid);
@@ -432,7 +438,7 @@
std::string mClientMappingFilePath{};
// next available client id
- HalClientId mNextClientId = kDefaultHalClientId + 1;
+ HalClientId mNextClientId = 1;
// The lock guarding the access to clients' states and pending transactions
std::mutex mLock;
diff --git a/host/test/hal_generic/common/hal_client_manager_test.cc b/host/test/hal_generic/common/hal_client_manager_test.cc
index 8dcd59c..73a885f 100644
--- a/host/test/hal_generic/common/hal_client_manager_test.cc
+++ b/host/test/hal_generic/common/hal_client_manager_test.cc
@@ -9,6 +9,7 @@
#include <aidl/android/hardware/contexthub/BnContextHubCallback.h>
#include <aidl/android/hardware/contexthub/IContextHub.h>
#include <aidl/android/hardware/contexthub/NanoappBinary.h>
+#include "chre/platform/shared/host_protocol_common.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "hal_client_manager.h"
@@ -189,7 +190,7 @@
EXPECT_EQ(client.callback, callback);
EXPECT_EQ(client.uuid, kSystemServerUuid);
EXPECT_EQ(client.pid, kSystemServerPid);
- EXPECT_NE(client.clientId, kDefaultHalClientId);
+ EXPECT_NE(client.clientId, ::chre::kHostClientIdUnspecified);
}
TEST_F(HalClientManagerTest, CallbackRegistryTwiceFromSameClient) {
@@ -388,7 +389,7 @@
EXPECT_EQ(client.callback, nullptr);
EXPECT_EQ(client.pid, HalClient::PID_UNSET);
EXPECT_EQ(client.uuid, kSystemServerUuid);
- EXPECT_NE(client.clientId, kDefaultHalClientId);
+ EXPECT_NE(client.clientId, ::chre::kHostClientIdUnspecified);
EXPECT_THAT(client.endpointIds, IsEmpty());
}