未验证 提交 3f35b011 编写于 作者: O openharmony_ci 提交者: Gitee

!2111 启动恢复子系统IPC接口管控

Merge pull request !2111 from zhaohaoran09/master
# 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
......@@ -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<uint32_t> (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<uint32_t> (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());
......
......@@ -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<uint32_t> (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<uint32_t> (DeviceInfoInterfaceCode::COMMAND_GET_SERIAL_ID): {
if (!CheckPermission(data, "ohos.permission.sec.ACCESS_UDID")) {
return SYSPARAM_PERMISSION_DENIED;
}
......
/*
* 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
......@@ -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
......
......@@ -29,7 +29,7 @@ uint32_t WatcherManagerProxy::AddRemoteWatcher(uint32_t id, const sptr<IWatcher>
MessageParcel reply;
MessageOption option { MessageOption::TF_SYNC };
int32_t res = SendWatcherMsg(ADD_REMOTE_AGENT, data, reply, option);
int32_t res = SendWatcherMsg(static_cast<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(ParamWatcherInterfaceCode::REFRESH_WATCHER), keyPrefix, remoteWatcherId);
}
int32_t WatcherManagerProxy::SendWatcherMsg(uint32_t code,
......
......@@ -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<IWatcher> &watcher) = 0;
......
/*
* 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
......@@ -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<uint32_t>(ParamWatcherInterfaceCode::ADD_WATCHER): {
std::string key = data.ReadString();
int ret = AddWatcher(key, data.ReadUint32());
reply.WriteInt32(ret);
break;
}
case DEL_WATCHER: {
case static_cast<uint32_t>(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<uint32_t>(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<uint32_t>(ParamWatcherInterfaceCode::DEL_REMOTE_AGENT): {
int ret = DelRemoteWatcher(data.ReadUint32());
reply.WriteInt32(ret);
break;
}
case REFRESH_WATCHER: {
case static_cast<uint32_t>(ParamWatcherInterfaceCode::REFRESH_WATCHER): {
std::string key = data.ReadString();
int ret = RefreshWatcher(key, data.ReadUint32());
reply.WriteInt32(ret);
......
......@@ -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<uint32_t> (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<uint32_t> (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<uint32_t> (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<uint32_t> (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<uint32_t> (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<uint32_t> (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<uint32_t> (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);
......
......@@ -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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(ParamWatcherInterfaceCode::REFRESH_WATCHER) + 1, data, reply, option);
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册