系统服务接口权限管控。

Signed-off-by: Hollokin <taoyuxin2@huawei.com>
This commit is contained in:
Hollokin 2023-06-15 14:20:48 +08:00
parent 3ca49d4017
commit ad570de079
6 changed files with 141 additions and 137 deletions

17
CODEOWNERS Normal file
View File

@ -0,0 +1,17 @@
/*
* 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 services/include/inputmethod_service_ipc_interface_code.h needs to be reviewed by @lenochan5
services/include/inputmethod_service_ipc_interface_code.h @leonchan5

View File

@ -16,6 +16,7 @@
#include "input_method_system_ability_proxy.h"
#include "global.h"
#include "inputmethod_service_ipc_interface_code.h"
#include "itypes_util.h"
#include "message_option.h"
@ -31,13 +32,16 @@ InputMethodSystemAbilityProxy::InputMethodSystemAbilityProxy(const sptr<IRemoteO
int32_t InputMethodSystemAbilityProxy::PrepareInput(InputClientInfo &inputClientInfo)
{
return SendRequest(
PREPARE_INPUT, [&inputClientInfo](MessageParcel &data) { return ITypesUtil::Marshal(data, inputClientInfo); });
static_cast<uint32_t>(InputMethodInterfaceCode::PREPARE_INPUT), [&inputClientInfo](MessageParcel &data) {
return ITypesUtil::Marshal(data, inputClientInfo);
});
}
int32_t InputMethodSystemAbilityProxy::StartInput(sptr<IInputClient> client, bool isShowKeyboard)
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(START_INPUT, [isShowKeyboard, client](MessageParcel &data) {
return SendRequest(
static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT), [isShowKeyboard, client](MessageParcel &data) {
return data.WriteRemoteObject(client->AsObject()) && data.WriteBool(isShowKeyboard);
});
}
@ -45,44 +49,47 @@ int32_t InputMethodSystemAbilityProxy::StartInput(sptr<IInputClient> client, boo
int32_t InputMethodSystemAbilityProxy::ShowCurrentInput()
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(SHOW_CURRENT_INPUT);
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT));
}
int32_t InputMethodSystemAbilityProxy::HideCurrentInput()
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(HIDE_CURRENT_INPUT);
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT));
}
int32_t InputMethodSystemAbilityProxy::StopInputSession()
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(STOP_INPUT_SESSION);
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT_SESSION));
}
int32_t InputMethodSystemAbilityProxy::StopInput(sptr<IInputClient> client)
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(
STOP_INPUT, [client](MessageParcel &data) { return data.WriteRemoteObject(client->AsObject()); });
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT), [client](MessageParcel &data) {
return data.WriteRemoteObject(client->AsObject());
});
}
int32_t InputMethodSystemAbilityProxy::ReleaseInput(sptr<IInputClient> client)
{
return SendRequest(
RELEASE_INPUT, [client](MessageParcel &data) { return data.WriteRemoteObject(client->AsObject()); });
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT), [client](MessageParcel &data) {
return data.WriteRemoteObject(client->AsObject());
});
}
int32_t InputMethodSystemAbilityProxy::DisplayOptionalInputMethod()
{
IMSA_HILOGI("%{public}s in", __func__);
return SendRequest(DISPLAY_OPTIONAL_INPUT_METHOD);
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_METHOD));
}
int32_t InputMethodSystemAbilityProxy::SetCoreAndAgent(sptr<IInputMethodCore> core, sptr<IInputMethodAgent> agent)
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(SET_CORE_AND_AGENT, [core, agent](MessageParcel &data) {
return SendRequest(
static_cast<uint32_t>(InputMethodInterfaceCode::SET_CORE_AND_AGENT), [core, agent](MessageParcel &data) {
return data.WriteRemoteObject(core->AsObject()) && data.WriteRemoteObject(agent->AsObject());
});
}
@ -91,7 +98,8 @@ std::shared_ptr<Property> InputMethodSystemAbilityProxy::GetCurrentInputMethod()
{
IMSA_HILOGD("%{public}s in", __func__);
std::shared_ptr<Property> property = nullptr;
int32_t ret = SendRequest(GET_CURRENT_INPUT_METHOD, nullptr, [&property](MessageParcel &reply) {
int32_t ret = SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD), nullptr,
[&property](MessageParcel &reply) {
property = std::make_shared<Property>();
if (property == nullptr) {
IMSA_HILOGE("%{public}s make_shared nullptr", __func__);
@ -106,7 +114,8 @@ std::shared_ptr<SubProperty> InputMethodSystemAbilityProxy::GetCurrentInputMetho
{
IMSA_HILOGD("%{public}s in", __func__);
std::shared_ptr<SubProperty> property = nullptr;
int32_t ret = SendRequest(GET_CURRENT_INPUT_METHOD_SUBTYPE, nullptr, [&property](MessageParcel &reply) {
int32_t ret = SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD_SUBTYPE),
nullptr, [&property](MessageParcel &reply) {
property = std::make_shared<SubProperty>();
if (property == nullptr) {
IMSA_HILOGE("%{public}s make_shared nullptr", __func__);
@ -121,26 +130,31 @@ int32_t InputMethodSystemAbilityProxy::ListInputMethod(InputMethodStatus status,
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(
LIST_INPUT_METHOD, [status](MessageParcel &data) { return ITypesUtil::Marshal(data, uint32_t(status)); },
[&props](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, props); });
static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD),
[status](MessageParcel &data) {
return ITypesUtil::Marshal(data, uint32_t(status));
},
[&props](MessageParcel &reply) {
return ITypesUtil::Unmarshal(reply, props);
});
}
int32_t InputMethodSystemAbilityProxy::ShowCurrentInputDeprecated()
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(SHOW_CURRENT_INPUT_DEPRECATED);
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT_DEPRECATED));
}
int32_t InputMethodSystemAbilityProxy::HideCurrentInputDeprecated()
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(HIDE_CURRENT_INPUT_DEPRECATED);
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT_DEPRECATED));
}
int32_t InputMethodSystemAbilityProxy::DisplayOptionalInputMethodDeprecated()
{
IMSA_HILOGD("%{public}s in", __func__);
return SendRequest(DISPLAY_OPTIONAL_INPUT_DEPRECATED);
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_DEPRECATED));
}
int32_t InputMethodSystemAbilityProxy::ListInputMethodSubtype(
@ -148,29 +162,39 @@ int32_t InputMethodSystemAbilityProxy::ListInputMethodSubtype(
{
IMSA_HILOGD("InputMethodSystemAbilityProxy::ListInputMethodSubtype");
return SendRequest(
LIST_INPUT_METHOD_SUBTYPE, [&name](MessageParcel &data) { return ITypesUtil::Marshal(data, name); },
[&subProps](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, subProps); });
static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD_SUBTYPE),
[&name](MessageParcel &data) {
return ITypesUtil::Marshal(data, name);
},
[&subProps](MessageParcel &reply) {
return ITypesUtil::Unmarshal(reply, subProps);
});
}
int32_t InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype(std::vector<SubProperty> &subProps)
{
IMSA_HILOGD("InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype");
return SendRequest(LIST_CURRENT_INPUT_METHOD_SUBTYPE, nullptr,
[&subProps](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, subProps); });
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::LIST_CURRENT_INPUT_METHOD_SUBTYPE), nullptr,
[&subProps](MessageParcel &reply) {
return ITypesUtil::Unmarshal(reply, subProps);
});
}
int32_t InputMethodSystemAbilityProxy::SwitchInputMethod(const std::string &name, const std::string &subName)
{
IMSA_HILOGD("InputMethodSystemAbilityProxy::SwitchInputMethod");
return SendRequest(SWITCH_INPUT_METHOD,
[&name, &subName](MessageParcel &data) { return ITypesUtil::Marshal(data, name, subName); });
return SendRequest(
static_cast<uint32_t>(InputMethodInterfaceCode::SWITCH_INPUT_METHOD), [&name, &subName](MessageParcel &data) {
return ITypesUtil::Marshal(data, name, subName);
});
}
int32_t InputMethodSystemAbilityProxy::PanelStatusChange(
const InputWindowStatus &status, const InputWindowInfo &windowInfo)
{
IMSA_HILOGD("InputMethodSystemAbilityProxy::PanelStatusChange");
return SendRequest(PANEL_STATUS_CHANGE, [status, windowInfo](MessageParcel &data) {
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::PANEL_STATUS_CHANGE),
[status, windowInfo](MessageParcel &data) {
return ITypesUtil::Marshal(data, static_cast<uint32_t>(status), windowInfo);
});
}
@ -178,8 +202,10 @@ int32_t InputMethodSystemAbilityProxy::PanelStatusChange(
int32_t InputMethodSystemAbilityProxy::UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType)
{
IMSA_HILOGD("InputMethodSystemAbilityProxy::UpdateListenEventFlag");
return SendRequest(UPDATE_LISTEN_EVENT_FLAG,
[&clientInfo, eventType](MessageParcel &data) { return ITypesUtil::Marshal(data, clientInfo, eventType); });
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::UPDATE_LISTEN_EVENT_FLAG),
[&clientInfo, eventType](MessageParcel &data) {
return ITypesUtil::Marshal(data, clientInfo, eventType);
});
}
int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output)

View File

@ -38,30 +38,6 @@ namespace OHOS {
namespace MiscServices {
class IInputMethodSystemAbility : public IRemoteBroker {
public:
enum CommandId : int32_t {
PREPARE_INPUT = 0,
START_INPUT,
SHOW_CURRENT_INPUT,
HIDE_CURRENT_INPUT,
STOP_INPUT,
STOP_INPUT_SESSION,
RELEASE_INPUT,
GET_CURRENT_INPUT_METHOD,
GET_CURRENT_INPUT_METHOD_SUBTYPE,
LIST_INPUT_METHOD,
LIST_INPUT_METHOD_SUBTYPE,
LIST_CURRENT_INPUT_METHOD_SUBTYPE,
SWITCH_INPUT_METHOD,
DISPLAY_OPTIONAL_INPUT_METHOD,
SET_CORE_AND_AGENT,
SHOW_CURRENT_INPUT_DEPRECATED,
HIDE_CURRENT_INPUT_DEPRECATED,
DISPLAY_OPTIONAL_INPUT_DEPRECATED,
PANEL_STATUS_CHANGE,
UPDATE_LISTEN_EVENT_FLAG,
INPUT_SERVICE_CMD_LAST
};
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodSystemAbility");
virtual int32_t PrepareInput(InputClientInfo &clientInfo) = 0;

View File

@ -20,6 +20,7 @@
#include "global.h"
#include "i_input_method_system_ability.h"
#include "inputmethod_service_ipc_interface_code.h"
#include "iremote_stub.h"
#include "message_parcel.h"
#include "refbase.h"
@ -70,6 +71,50 @@ private:
int32_t HideCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply);
int32_t ShowCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply);
using RequestHandler = int32_t (InputMethodSystemAbilityStub::*)(MessageParcel &, MessageParcel &);
static constexpr RequestHandler HANDLERS[static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_LAST)] = {
[static_cast<uint32_t>(InputMethodInterfaceCode::PREPARE_INPUT)] =
&InputMethodSystemAbilityStub::PrepareInputOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT)] =
&InputMethodSystemAbilityStub::StartInputOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT)] =
&InputMethodSystemAbilityStub::ShowCurrentInputOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT)] =
&InputMethodSystemAbilityStub::HideCurrentInputOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT)] =
&InputMethodSystemAbilityStub::StopInputOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT)] =
&InputMethodSystemAbilityStub::ReleaseInputOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD)] =
&InputMethodSystemAbilityStub::GetCurrentInputMethodOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD_SUBTYPE)] =
&InputMethodSystemAbilityStub::GetCurrentInputMethodSubtypeOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD)] =
&InputMethodSystemAbilityStub::ListInputMethodOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD_SUBTYPE)] =
&InputMethodSystemAbilityStub::ListInputMethodSubtypeOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::LIST_CURRENT_INPUT_METHOD_SUBTYPE)] =
&InputMethodSystemAbilityStub::ListCurrentInputMethodSubtypeOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::SWITCH_INPUT_METHOD)] =
&InputMethodSystemAbilityStub::SwitchInputMethodOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_METHOD)] =
&InputMethodSystemAbilityStub::DisplayOptionalInputMethodOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::SET_CORE_AND_AGENT)] =
&InputMethodSystemAbilityStub::SetCoreAndAgentOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT_DEPRECATED)] =
&InputMethodSystemAbilityStub::ShowCurrentInputOnRemoteDeprecated,
[static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT_DEPRECATED)] =
&InputMethodSystemAbilityStub::HideCurrentInputOnRemoteDeprecated,
[static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_DEPRECATED)] =
&InputMethodSystemAbilityStub::DisplayInputOnRemoteDeprecated,
[static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT_SESSION)] =
&InputMethodSystemAbilityStub::StopInputSessionOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::PANEL_STATUS_CHANGE)] =
&InputMethodSystemAbilityStub::PanelStatusChangeOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::UPDATE_LISTEN_EVENT_FLAG)] =
&InputMethodSystemAbilityStub::UpdateListenEventFlagOnRemote,
};
};
} // namespace OHOS::MiscServices

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* 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
@ -40,6 +40,7 @@ enum class InputMethodInterfaceCode {
DISPLAY_OPTIONAL_INPUT_DEPRECATED,
PANEL_STATUS_CHANGE,
UPDATE_LISTEN_EVENT_FLAG,
IMS_CMD_LAST
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -21,7 +21,6 @@
#include "input_data_channel_proxy.h"
#include "input_method_agent_proxy.h"
#include "input_method_core_proxy.h"
#include "inputmethod_service_ipc_interface_code.h"
#include "ipc_skeleton.h"
#include "itypes_util.h"
#include "os_account_manager.h"
@ -38,71 +37,11 @@ int32_t InputMethodSystemAbilityStub::OnRemoteRequest(
IMSA_HILOGE("%{public}s descriptor failed", __func__);
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
}
switch (code) {
case static_cast<uint32_t>(InputMethodInterfaceCode::PREPARE_INPUT):
PrepareInputOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT):
StartInputOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT):
ShowCurrentInputOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT):
HideCurrentInputOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT):
StopInputOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT):
ReleaseInputOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD):
GetCurrentInputMethodOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT_SESSION):
StopInputSessionOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD_SUBTYPE):
GetCurrentInputMethodSubtypeOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD):
ListInputMethodOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD_SUBTYPE):
ListInputMethodSubtypeOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::LIST_CURRENT_INPUT_METHOD_SUBTYPE):
ListCurrentInputMethodSubtypeOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::SWITCH_INPUT_METHOD):
SwitchInputMethodOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_METHOD):
DisplayOptionalInputMethodOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::SET_CORE_AND_AGENT):
SetCoreAndAgentOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT_DEPRECATED):
ShowCurrentInputOnRemoteDeprecated(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT_DEPRECATED):
HideCurrentInputOnRemoteDeprecated(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_DEPRECATED):
DisplayInputOnRemoteDeprecated(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::PANEL_STATUS_CHANGE):
PanelStatusChangeOnRemote(data, reply);
break;
case static_cast<uint32_t>(InputMethodInterfaceCode::UPDATE_LISTEN_EVENT_FLAG):
UpdateListenEventFlagOnRemote(data, reply);
break;
default:
if (code >= 0 && code < static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_LAST)) {
return (this->*HANDLERS[code])(data, reply);
} else {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return ErrorCode::NO_ERROR;
}
int32_t InputMethodSystemAbilityStub::PrepareInputOnRemote(MessageParcel &data, MessageParcel &reply)