From d7af296049969df9ed3708ab8bdf1ee431c26b8a Mon Sep 17 00:00:00 2001 From: zhaohaoran Date: Mon, 10 Jul 2023 21:49:54 +0800 Subject: [PATCH] IPCfix Signed-off-by: zhaohaoran Change-Id: I08d8408f0052af5b38694b61bb87b7a67918f775 --- CODEOWNERS | 16 ++++++++++ device_info/device_info_proxy.cpp | 5 +-- device_info/device_info_stub.cpp | 5 +-- .../deviceinfoservice_ipc_interface_code.h | 29 +++++++++++++++++ device_info/idevice_info.h | 2 -- .../watcher/agent/watcher_manager_proxy.cpp | 10 +++--- .../param/watcher/include/iwatcher_manager.h | 9 +----- .../param_watcher_ipc_interface_code.h | 32 +++++++++++++++++++ .../watcher/proxy/watcher_manager_stub.cpp | 10 +++--- .../deviceinfo/DeviceInfoUnittest.cpp | 17 +++++----- .../unittest/param/watcher_proxy_unittest.cpp | 14 ++++---- 11 files changed, 110 insertions(+), 39 deletions(-) create mode 100644 CODEOWNERS create mode 100644 device_info/deviceinfoservice_ipc_interface_code.h create mode 100644 services/param/watcher/include/param_watcher_ipc_interface_code.h diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..6f95e9b1 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,16 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# any change to tools/ui_appearance_ipc_interface_code.h needs to be reviewed by @leonchan5 +base/startup/init/device_info/deviceinfoservice_ipc_interface_code.h @leonchan5 +base/startup/init/services/param/watcher/include/param_watcher_ipc_interface_code.h @leonchan5 \ No newline at end of file diff --git a/device_info/device_info_proxy.cpp b/device_info/device_info_proxy.cpp index e3ef437a..07795a0f 100644 --- a/device_info/device_info_proxy.cpp +++ b/device_info/device_info_proxy.cpp @@ -19,6 +19,7 @@ #include "parcel.h" #include "string_ex.h" #include "sysparam_errno.h" +#include "deviceinfoservice_ipc_interface_code.h" namespace OHOS { namespace device_info { @@ -43,7 +44,7 @@ int32_t DeviceInfoProxy::GetUdid(std::string& result) MessageParcel reply; MessageOption option { MessageOption::TF_SYNC }; data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor()); - int32_t ret = DeviceInfoSendRequest(COMMAND_GET_UDID, data, reply, option); + int32_t ret = DeviceInfoSendRequest(static_cast (DeviceInfoInterfaceCode::COMMAND_GET_UDID), data, reply, option); DINFO_LOGI("DeviceInfoProxy::GetUdid: %d", ret); DINFO_CHECK(ret == ERR_NONE, return ret, "getUdid failed, error code is %d", ret); result = Str16ToStr8(reply.ReadString16()); @@ -57,7 +58,7 @@ int32_t DeviceInfoProxy::GetSerialID(std::string& result) MessageOption option { MessageOption::TF_SYNC }; data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor()); - int32_t ret = DeviceInfoSendRequest(COMMAND_GET_SERIAL_ID, data, reply, option); + int32_t ret = DeviceInfoSendRequest(static_cast (DeviceInfoInterfaceCode::COMMAND_GET_SERIAL_ID), data, reply, option); DINFO_LOGI("DeviceInfoProxy::GetSerialID: %d", ret); DINFO_CHECK(ret == ERR_NONE, return ret, "GetSerial failed, error code is %d", ret); result = Str16ToStr8(reply.ReadString16()); diff --git a/device_info/device_info_stub.cpp b/device_info/device_info_stub.cpp index 0f435dd3..ddf1f713 100644 --- a/device_info/device_info_stub.cpp +++ b/device_info/device_info_stub.cpp @@ -31,6 +31,7 @@ #include "parameter.h" #include "sysparam_errno.h" #include "init_utils.h" +#include "deviceinfoservice_ipc_interface_code.h" namespace OHOS { using namespace Security; @@ -80,7 +81,7 @@ int32_t DeviceInfoStub::OnRemoteRequest(uint32_t code, int ret = ERR_FAIL; switch (code) { - case COMMAND_GET_UDID: { + case static_cast (DeviceInfoInterfaceCode::COMMAND_GET_UDID): { if (!CheckPermission(data, "ohos.permission.sec.ACCESS_UDID")) { return SYSPARAM_PERMISSION_DENIED; } @@ -90,7 +91,7 @@ int32_t DeviceInfoStub::OnRemoteRequest(uint32_t code, reply.WriteString16(Str8ToStr16(localDeviceInfo)); break; } - case COMMAND_GET_SERIAL_ID: { + case static_cast (DeviceInfoInterfaceCode::COMMAND_GET_SERIAL_ID): { if (!CheckPermission(data, "ohos.permission.sec.ACCESS_UDID")) { return SYSPARAM_PERMISSION_DENIED; } diff --git a/device_info/deviceinfoservice_ipc_interface_code.h b/device_info/deviceinfoservice_ipc_interface_code.h new file mode 100644 index 00000000..12bb4161 --- /dev/null +++ b/device_info/deviceinfoservice_ipc_interface_code.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVICEINFOSERVICE_IPC_INTERFACE_CODE_H +#define DEVICEINFOSERVICE_IPC_INTERFACE_CODE_H + +/*SAID: 3902 */ +namespace OHOS { +namespace device_info { +enum class DeviceInfoInterfaceCode { + COMMAND_GET_UDID = 1, + COMMAND_GET_SERIAL_ID = 2, +}; +} // namespace device_info +} // namespace OHOS + +#endif // DEVICEINFOSERVICE_IPC_INTERFACE_CODE_H diff --git a/device_info/idevice_info.h b/device_info/idevice_info.h index 1dcbb625..14791c93 100644 --- a/device_info/idevice_info.h +++ b/device_info/idevice_info.h @@ -30,8 +30,6 @@ public: virtual int32_t GetUdid(std::string& result) = 0; virtual int32_t GetSerialID(std::string& result) = 0; - static constexpr int COMMAND_GET_UDID = MIN_TRANSACTION_ID + 0; - static constexpr int COMMAND_GET_SERIAL_ID = MIN_TRANSACTION_ID + 1; static constexpr int ERR_FAIL = -1; }; } // namespace device_info diff --git a/services/param/watcher/agent/watcher_manager_proxy.cpp b/services/param/watcher/agent/watcher_manager_proxy.cpp index 32f7b03d..4f0b9d81 100644 --- a/services/param/watcher/agent/watcher_manager_proxy.cpp +++ b/services/param/watcher/agent/watcher_manager_proxy.cpp @@ -29,7 +29,7 @@ uint32_t WatcherManagerProxy::AddRemoteWatcher(uint32_t id, const sptr MessageParcel reply; MessageOption option { MessageOption::TF_SYNC }; - int32_t res = SendWatcherMsg(ADD_REMOTE_AGENT, data, reply, option); + int32_t res = SendWatcherMsg(static_cast(ParamWatcherInterfaceCode::ADD_REMOTE_AGENT), data, reply, option); WATCHER_CHECK(res == ERR_OK, return 0, "Transact error %d", res); return reply.ReadUint32(); } @@ -41,7 +41,7 @@ int32_t WatcherManagerProxy::DelRemoteWatcher(uint32_t remoteWatcherId) data.WriteUint32(remoteWatcherId); MessageParcel reply; MessageOption option { MessageOption::TF_SYNC }; - int32_t res = SendWatcherMsg(DEL_REMOTE_AGENT, data, reply, option); + int32_t res = SendWatcherMsg(static_cast(ParamWatcherInterfaceCode::DEL_REMOTE_AGENT), data, reply, option); WATCHER_CHECK(res == ERR_OK, return ERR_FLATTEN_OBJECT, "Transact error"); return reply.ReadInt32(); } @@ -61,17 +61,17 @@ int32_t WatcherManagerProxy::SendMsg(int op, const std::string &keyPrefix, uint3 int32_t WatcherManagerProxy::AddWatcher(const std::string &keyPrefix, uint32_t remoteWatcherId) { - return SendMsg(ADD_WATCHER, keyPrefix, remoteWatcherId); + return SendMsg(static_cast(ParamWatcherInterfaceCode::ADD_WATCHER), keyPrefix, remoteWatcherId); } int32_t WatcherManagerProxy::DelWatcher(const std::string &keyPrefix, uint32_t remoteWatcherId) { - return SendMsg(DEL_WATCHER, keyPrefix, remoteWatcherId); + return SendMsg(static_cast(ParamWatcherInterfaceCode::DEL_WATCHER), keyPrefix, remoteWatcherId); } int32_t WatcherManagerProxy::RefreshWatcher(const std::string &keyPrefix, uint32_t remoteWatcherId) { - return SendMsg(REFRESH_WATCHER, keyPrefix, remoteWatcherId); + return SendMsg(static_cast(ParamWatcherInterfaceCode::REFRESH_WATCHER), keyPrefix, remoteWatcherId); } int32_t WatcherManagerProxy::SendWatcherMsg(uint32_t code, diff --git a/services/param/watcher/include/iwatcher_manager.h b/services/param/watcher/include/iwatcher_manager.h index c1e1043d..47453671 100644 --- a/services/param/watcher/include/iwatcher_manager.h +++ b/services/param/watcher/include/iwatcher_manager.h @@ -20,19 +20,12 @@ #include "iremote_broker.h" #include "iremote_proxy.h" #include "iwatcher.h" +#include "param_watcher_ipc_interface_code.h" namespace OHOS { namespace init_param { class IWatcherManager : public OHOS::IRemoteBroker { public: - enum { - ADD_WATCHER, - DEL_WATCHER, - ADD_REMOTE_AGENT, - DEL_REMOTE_AGENT, - REFRESH_WATCHER - }; - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Startup.IWatcherManager"); public: virtual uint32_t AddRemoteWatcher(uint32_t id, const sptr &watcher) = 0; diff --git a/services/param/watcher/include/param_watcher_ipc_interface_code.h b/services/param/watcher/include/param_watcher_ipc_interface_code.h new file mode 100644 index 00000000..db643586 --- /dev/null +++ b/services/param/watcher/include/param_watcher_ipc_interface_code.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PARAM_WATCHER_IPC_INTERFACE_CODE_H +#define PARAM_WATCHER_IPC_INTERFACE_CODE_H + +/*SAID: 3901 */ +namespace OHOS { +namespace init_param { +enum class ParamWatcherInterfaceCode { + ADD_WATCHER = 0, + DEL_WATCHER, + ADD_REMOTE_AGENT, + DEL_REMOTE_AGENT, + REFRESH_WATCHER +}; +} // namespace init_param +} // namespace OHOS + +#endif // PARAM_WATCHER_IPC_INTERFACE_CODE_H diff --git a/services/param/watcher/proxy/watcher_manager_stub.cpp b/services/param/watcher/proxy/watcher_manager_stub.cpp index 7cacbee3..30004577 100644 --- a/services/param/watcher/proxy/watcher_manager_stub.cpp +++ b/services/param/watcher/proxy/watcher_manager_stub.cpp @@ -28,19 +28,19 @@ int32_t WatcherManagerStub::OnRemoteRequest(uint32_t code, WATCHER_LOGV("OnRemoteRequest code %u", code); switch (code) { - case ADD_WATCHER: { + case static_cast(ParamWatcherInterfaceCode::ADD_WATCHER): { std::string key = data.ReadString(); int ret = AddWatcher(key, data.ReadUint32()); reply.WriteInt32(ret); break; } - case DEL_WATCHER: { + case static_cast(ParamWatcherInterfaceCode::DEL_WATCHER): { std::string key = data.ReadString(); int ret = DelWatcher(key, data.ReadUint32()); reply.WriteInt32(ret); break; } - case ADD_REMOTE_AGENT: { + case static_cast(ParamWatcherInterfaceCode::ADD_REMOTE_AGENT): { auto remote = data.ReadRemoteObject(); // 0 is invalid watcherId uint32_t id = data.ReadUint32(); @@ -49,12 +49,12 @@ int32_t WatcherManagerStub::OnRemoteRequest(uint32_t code, reply.WriteUint32(remoteWatcherId); break; } - case DEL_REMOTE_AGENT: { + case static_cast(ParamWatcherInterfaceCode::DEL_REMOTE_AGENT): { int ret = DelRemoteWatcher(data.ReadUint32()); reply.WriteInt32(ret); break; } - case REFRESH_WATCHER: { + case static_cast(ParamWatcherInterfaceCode::REFRESH_WATCHER): { std::string key = data.ReadString(); int ret = RefreshWatcher(key, data.ReadUint32()); reply.WriteInt32(ret); diff --git a/test/unittest/deviceinfo/DeviceInfoUnittest.cpp b/test/unittest/deviceinfo/DeviceInfoUnittest.cpp index 7fe745df..4045ec1d 100644 --- a/test/unittest/deviceinfo/DeviceInfoUnittest.cpp +++ b/test/unittest/deviceinfo/DeviceInfoUnittest.cpp @@ -31,12 +31,13 @@ #include "idevice_info.h" #include "device_info_stub.h" #include "sysparam_errno.h" +#include "deviceinfoservice_ipc_interface_code.h" using namespace testing::ext; using namespace std; using namespace OHOS; -static int g_tokenType = OHOS::Security::AccessToken::TOKEN_HAP; +int g_tokenType = OHOS::Security::AccessToken::TOKEN_HAP; int g_tokenVerifyResult = 0; namespace OHOS { namespace Security { @@ -125,7 +126,7 @@ HWTEST_F(DeviceInfoUnittest, DeviceInfoServiceInvalidTokenTest, TestSize.Level1) MessageOption option; g_tokenType = OHOS::Security::AccessToken::TOKEN_INVALID; data.WriteInterfaceToken(OHOS::device_info::DeviceInfoStub::GetDescriptor()); - deviceInfoService->OnRemoteRequest(OHOS::device_info::IDeviceInfo::COMMAND_GET_UDID, data, reply, option); + deviceInfoService->OnRemoteRequest(static_cast (OHOS::device_info::DeviceInfoInterfaceCode::COMMAND_GET_UDID), data, reply, option); } HWTEST_F(DeviceInfoUnittest, DeviceInfoServiceFailTest, TestSize.Level1) @@ -141,10 +142,10 @@ HWTEST_F(DeviceInfoUnittest, DeviceInfoServiceFailTest, TestSize.Level1) // udid data.WriteInterfaceToken(OHOS::device_info::DeviceInfoStub::GetDescriptor()); - deviceInfoService->OnRemoteRequest(OHOS::device_info::IDeviceInfo::COMMAND_GET_UDID, data, reply, option); + deviceInfoService->OnRemoteRequest(static_cast (OHOS::device_info::DeviceInfoInterfaceCode::COMMAND_GET_UDID), data, reply, option); // serial data.WriteInterfaceToken(OHOS::device_info::DeviceInfoStub::GetDescriptor()); - deviceInfoService->OnRemoteRequest(OHOS::device_info::IDeviceInfo::COMMAND_GET_SERIAL_ID, data, reply, option); + deviceInfoService->OnRemoteRequest(static_cast (OHOS::device_info::DeviceInfoInterfaceCode::COMMAND_GET_SERIAL_ID), data, reply, option); } HWTEST_F(DeviceInfoUnittest, DeviceInfoServiceTest, TestSize.Level1) @@ -158,13 +159,13 @@ HWTEST_F(DeviceInfoUnittest, DeviceInfoServiceTest, TestSize.Level1) g_tokenType = OHOS::Security::AccessToken::TOKEN_HAP; g_tokenVerifyResult = OHOS::Security::AccessToken::TypePermissionState::PERMISSION_GRANTED; data.WriteInterfaceToken(OHOS::device_info::DeviceInfoStub::GetDescriptor()); - deviceInfoService->OnRemoteRequest(OHOS::device_info::IDeviceInfo::COMMAND_GET_UDID, data, reply, option); + deviceInfoService->OnRemoteRequest(static_cast (OHOS::device_info::DeviceInfoInterfaceCode::COMMAND_GET_UDID), data, reply, option); data.WriteInterfaceToken(OHOS::device_info::DeviceInfoStub::GetDescriptor()); - deviceInfoService->OnRemoteRequest(OHOS::device_info::IDeviceInfo::COMMAND_GET_SERIAL_ID, data, reply, option); + deviceInfoService->OnRemoteRequest(static_cast (OHOS::device_info::DeviceInfoInterfaceCode::COMMAND_GET_SERIAL_ID), data, reply, option); data.WriteInterfaceToken(OHOS::device_info::DeviceInfoStub::GetDescriptor()); - deviceInfoService->OnRemoteRequest(OHOS::device_info::IDeviceInfo::COMMAND_GET_SERIAL_ID + 1, data, reply, option); + deviceInfoService->OnRemoteRequest(static_cast (OHOS::device_info::DeviceInfoInterfaceCode::COMMAND_GET_SERIAL_ID) + 1, data, reply, option); - deviceInfoService->OnRemoteRequest(OHOS::device_info::IDeviceInfo::COMMAND_GET_SERIAL_ID + 1, data, reply, option); + deviceInfoService->OnRemoteRequest(static_cast (OHOS::device_info::DeviceInfoInterfaceCode::COMMAND_GET_SERIAL_ID) + 1, data, reply, option); std::this_thread::sleep_for(std::chrono::seconds(3)); // wait sa unload 3s deviceInfoService->GetUdid(result); deviceInfoService->GetSerialID(result); diff --git a/test/unittest/param/watcher_proxy_unittest.cpp b/test/unittest/param/watcher_proxy_unittest.cpp index 2c39b309..ecc82d15 100644 --- a/test/unittest/param/watcher_proxy_unittest.cpp +++ b/test/unittest/param/watcher_proxy_unittest.cpp @@ -78,7 +78,7 @@ public: bool ret = data.WriteRemoteObject(watcher->AsObject()); WATCHER_CHECK(ret, return 0, "Can not get remote"); data.WriteUint32(agentId); - watcherManager->OnRemoteRequest(IWatcherManager::ADD_REMOTE_AGENT, data, reply, option); + watcherManager->OnRemoteRequest(static_cast(ParamWatcherInterfaceCode::ADD_REMOTE_AGENT), data, reply, option); watcherId = reply.ReadUint32(); EXPECT_NE(watcherId, 0); @@ -101,7 +101,7 @@ public: data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); data.WriteUint32(watcherId); - watcherManager->OnRemoteRequest(IWatcherManager::DEL_REMOTE_AGENT, data, reply, option); + watcherManager->OnRemoteRequest(static_cast(ParamWatcherInterfaceCode::DEL_REMOTE_AGENT), data, reply, option); EXPECT_EQ(reply.ReadInt32(), 0); EXPECT_EQ(watcherManager->GetRemoteWatcher(watcherId) == nullptr, 1); return 0; @@ -118,7 +118,7 @@ public: data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); data.WriteString(keyPrefix); data.WriteUint32(watcherId); - watcherManager->OnRemoteRequest(IWatcherManager::ADD_WATCHER, data, reply, option); + watcherManager->OnRemoteRequest(static_cast(ParamWatcherInterfaceCode::ADD_WATCHER), data, reply, option); EXPECT_EQ(reply.ReadInt32(), 0); EXPECT_EQ(watcherManager->GetWatcherGroup(keyPrefix) != nullptr, 1); return 0; @@ -135,7 +135,7 @@ public: data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); data.WriteString(keyPrefix); data.WriteUint32(watcherId); - watcherManager->OnRemoteRequest(IWatcherManager::REFRESH_WATCHER, data, reply, option); + watcherManager->OnRemoteRequest(static_cast(ParamWatcherInterfaceCode::REFRESH_WATCHER), data, reply, option); EXPECT_EQ(reply.ReadInt32(), 0); EXPECT_EQ(watcherManager->GetWatcherGroup(keyPrefix) != nullptr, 1); return 0; @@ -151,7 +151,7 @@ public: data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); data.WriteString(keyPrefix); data.WriteUint32(watcherId); - watcherManager->OnRemoteRequest(IWatcherManager::DEL_WATCHER, data, reply, option); + watcherManager->OnRemoteRequest(static_cast(ParamWatcherInterfaceCode::DEL_WATCHER), data, reply, option); EXPECT_EQ(reply.ReadInt32(), 0); return 0; } @@ -231,11 +231,11 @@ public: data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); data.WriteString(keyPrefix); data.WriteUint32(0); - watcherManager->OnRemoteRequest(IWatcherManager::REFRESH_WATCHER + 1, data, reply, option); + watcherManager->OnRemoteRequest(static_cast(ParamWatcherInterfaceCode::REFRESH_WATCHER) + 1, data, reply, option); data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); data.WriteString(keyPrefix); - watcherManager->OnRemoteRequest(IWatcherManager::REFRESH_WATCHER + 1, data, reply, option); + watcherManager->OnRemoteRequest(static_cast(ParamWatcherInterfaceCode::REFRESH_WATCHER) + 1, data, reply, option); return 0; } -- GitLab