【需求】系统服务接口管控实现

Signed-off-by: anyueling <anyueling@huawei.com>
This commit is contained in:
anyueling 2023-06-27 16:59:47 +08:00
parent 86671fa955
commit 8acc54545c
10 changed files with 178 additions and 109 deletions

18
CODEOWNERS Normal file
View File

@ -0,0 +1,18 @@
# 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 frameworks/native/include/download_server_ipc_interface_code.h needs to be reviewed by @leonchan5
frameworks/native/include/download_server_ipc_interface_code.h @leonchan5
# any change to services/service/rust/src/download_server_ipc_interface_code.rs needs to be reviewed by @leonchan5
services/service/rust/src/download_server_ipc_interface_code.rs @leonchan5

View File

@ -17,6 +17,7 @@
#include "request_event.h"
#include "log.h"
#include "parcel_helper.h"
#include "download_server_ipc_interface_code.h"
namespace OHOS::Request {
int32_t NotifyStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
@ -25,22 +26,20 @@ int32_t NotifyStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageP
auto descriptorToken = data.ReadInterfaceToken();
if (descriptorToken != GetDescriptor()) {
REQUEST_HILOGE("Remote descriptor not the same as local descriptor.");
return E_SERVICE_ERROR;
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
switch (code) {
case REQUEST_NOTIFY: {
case static_cast<uint32_t>(RequestNotifyInterfaceCode::REQUEST_NOTIFY):
OnCallBack(data);
break;
}
case REQUEST_DONE_NOTIFY: {
case static_cast<uint32_t>(RequestNotifyInterfaceCode::REQUEST_DONE_NOTIFY):
OnDone(data);
break;
default:
REQUEST_HILOGE("Default value received, check needed.");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
default: {
return OHOS::UNKNOWN_TRANSACTION;
}
}
return E_OK;
return ERR_NONE;
}
void NotifyStub::OnCallBack(MessageParcel &data)

View File

@ -0,0 +1,46 @@
/*
* 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 DOWNLOAD_SERVER_IPC_INTERFACE_CODE_H
#define DOWNLOAD_SERVER_IPC_INTERFACE_CODE_H
/* SAID: 3706*/
namespace OHOS {
namespace Request {
enum class RequestInterfaceCode {
CMD_REQUEST = 0,
CMD_PAUSE,
CMD_QUERY,
CMD_QUERYMIMETYPE,
CMD_REMOVE,
CMD_RESUME,
CMD_ON,
CMD_OFF,
CMD_START,
CMD_STOP,
CMD_SHOW,
CMD_TOUCH,
CMD_SEARCH,
CMD_CLEAR,
};
enum class RequestNotifyInterfaceCode {
REQUEST_NOTIFY = 0,
REQUEST_DONE_NOTIFY,
};
} // namespace Request
} // namespace OHOS
#endif //DOWNLOAD_SERVER_IPC_INTERFACE_CODE_H

View File

@ -28,10 +28,5 @@ public:
virtual void CallBack(const Notify &notify) = 0;
virtual void Done(const TaskInfo &taskInfo) = 0;
};
enum {
REQUEST_NOTIFY,
REQUEST_DONE_NOTIFY,
};
} // namespace OHOS::Request
#endif // DOWNLOAD_NOTIFY_INTERFACE_H

View File

@ -45,22 +45,5 @@ public:
const sptr<NotifyInterface> &listener) = 0;
virtual int32_t Off(const std::string &type, const std::string &tid) = 0;
};
enum {
CMD_REQUEST,
CMD_PAUSE,
CMD_QUERY,
CMD_QUERYMIMETYPE,
CMD_REMOVE,
CMD_RESUME,
CMD_ON,
CMD_OFF,
CMD_START,
CMD_STOP,
CMD_SHOW,
CMD_TOUCH,
CMD_SEARCH,
CMD_CLEAR,
};
} // namespace OHOS::Request
#endif // DOWNLOAD_SERVICE_INTERFACE_H

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "request_service_proxy.h"
#include "download_server_ipc_interface_code.h"
#include <fcntl.h>
#include <sys/stat.h>
@ -61,7 +62,7 @@ int32_t RequestServiceProxy::Create(const Config &config, int32_t &tid, sptr<Not
data.WriteString(config.data);
GetVectorData(config, data);
data.WriteRemoteObject(listener->AsObject().GetRefPtr());
int32_t ret = Remote()->SendRequest(CMD_REQUEST, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_REQUEST), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("SendRequest ret : %{public}d", ret);
return E_SERVICE_ERROR;
@ -115,7 +116,7 @@ int32_t RequestServiceProxy::Start(const std::string &tid)
data.WriteInterfaceToken(GetDescriptor());
data.WriteString(tid);
REQUEST_HILOGD("Start.");
int32_t ret = Remote()->SendRequest(CMD_START, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_START), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -130,7 +131,7 @@ int32_t RequestServiceProxy::Stop(const std::string &tid)
data.WriteInterfaceToken(GetDescriptor());
data.WriteString(tid);
REQUEST_HILOGD("Stop");
int32_t ret = Remote()->SendRequest(CMD_STOP, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_STOP), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -146,7 +147,7 @@ int32_t RequestServiceProxy::Show(const std::string &tid, TaskInfo &info)
data.WriteUint32(static_cast<uint32_t>(Version::API10));
data.WriteString(tid);
REQUEST_HILOGD("Show");
int32_t ret = Remote()->SendRequest(CMD_SHOW, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_SHOW), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -166,7 +167,7 @@ int32_t RequestServiceProxy::Touch(const std::string &tid, const std::string &to
data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
data.WriteString(tid);
data.WriteString(token);
int32_t ret = Remote()->SendRequest(CMD_TOUCH, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_TOUCH), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -190,7 +191,7 @@ int32_t RequestServiceProxy::Search(const Filter &filter, std::vector<std::strin
data.WriteUint32(static_cast<uint32_t>(filter.state));
data.WriteUint32(static_cast<uint32_t>(filter.action));
data.WriteUint32(static_cast<uint32_t>(filter.mode));
int32_t ret = Remote()->SendRequest(CMD_TOUCH, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_TOUCH), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -214,7 +215,7 @@ int32_t RequestServiceProxy::Clear(const std::vector<std::string> &tids, std::ve
for (auto tid : tids) {
data.WriteString(tid);
}
int32_t ret = Remote()->SendRequest(CMD_CLEAR, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_CLEAR), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -238,7 +239,7 @@ int32_t RequestServiceProxy::Query(const std::string &tid, TaskInfo &info, Versi
data.WriteUint32(static_cast<uint32_t>(version));
data.WriteString(tid);
REQUEST_HILOGD("RequestServiceProxy Query started.");
int32_t ret = Remote()->SendRequest(CMD_QUERY, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_QUERY), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -260,7 +261,7 @@ int32_t RequestServiceProxy::Pause(const std::string &tid, Version version)
data.WriteUint32(static_cast<uint32_t>(version));
data.WriteString(tid);
REQUEST_HILOGD("RequestServiceProxy Pause started.");
int32_t ret = Remote()->SendRequest(CMD_PAUSE, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_PAUSE), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -275,7 +276,8 @@ int32_t RequestServiceProxy::QueryMimeType(const std::string &tid, std::string &
data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
data.WriteString(tid);
REQUEST_HILOGD("RequestServiceProxy QueryMimeType started.");
int32_t ret = Remote()->SendRequest(CMD_QUERYMIMETYPE, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_QUERYMIMETYPE),
data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -296,7 +298,7 @@ int32_t RequestServiceProxy::Remove(const std::string &tid, Version version)
data.WriteUint32(static_cast<uint32_t>(version));
data.WriteString(tid);
REQUEST_HILOGD("RequestServiceProxy Remove started.");
int32_t ret = Remote()->SendRequest(CMD_REMOVE, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_REMOVE), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -311,7 +313,7 @@ int32_t RequestServiceProxy::Resume(const std::string &tid)
data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
data.WriteString(tid);
REQUEST_HILOGD("RequestServiceProxy Resume started.");
int32_t ret = Remote()->SendRequest(CMD_RESUME, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_RESUME), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -329,7 +331,7 @@ int32_t RequestServiceProxy::On(const std::string &type, const std::string &tid,
data.WriteString(type);
data.WriteString(tid);
data.WriteRemoteObject(listener->AsObject().GetRefPtr());
int32_t ret = Remote()->SendRequest(CMD_ON, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_ON), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;
@ -345,7 +347,7 @@ int32_t RequestServiceProxy::Off(const std::string &type, const std::string &tid
data.WriteInterfaceToken(GetDescriptor());
data.WriteString(type);
data.WriteString(tid);
int32_t ret = Remote()->SendRequest(CMD_OFF, data, reply, option);
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_OFF), data, reply, option);
if (ret != ERR_NONE) {
REQUEST_HILOGE("send request ret code is %{public}d", ret);
return E_SERVICE_ERROR;

View File

@ -53,6 +53,7 @@ ohos_rust_shared_library("download_server") {
ohos_rust_shared_library("request") {
sources = [
"src/download_server_ipc_interface_code.rs",
"src/enumration.rs",
"src/form_item.rs",
"src/lib.rs",

View File

@ -0,0 +1,55 @@
/*
* 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.
*/
/* SAID: 3706*/
/// Function code of RequestInterfaceCode
pub enum RequestInterfaceCode {
/// request construct & api10 create task
Construct = 0,
/// pause task
Pause,
/// query task || system api Queries specified task details
Query,
/// query mime type
QueryMimeType,
/// remove task || removes specifed task belongs to the caller
Remove,
/// resume task
Resume,
/// on task
On,
/// off task
Off,
/// ap10 start task
Start,
/// stop task
Stop,
/// Shows specified task details belongs to the caller
Show,
/// Touches specified task with token
Touch,
/// Searches tasks, for system
Search,
/// system api deletes specifed tasks
Clear,
}
/// Function code of RequestNotifyInterfaceCode
pub enum RequestNotifyInterfaceCode {
/// callback notification
Notify = 0,
/// Cache callback notification
DoneNotify,
}

View File

@ -29,6 +29,7 @@ pub mod form_item;
mod log;
pub mod progress;
mod utils;
mod download_server_ipc_interface_code;
use enumration::ErrorCode;
use hilog_rust::*;
@ -45,57 +46,26 @@ use std::{
option::Option,
};
use task_manager::*;
use download_server_ipc_interface_code::*;
/// Function code of RequestCode
pub enum RequestCode {
/// request construct & api10 create task
Construct = 0,
/// pause task
Pause,
/// query task || system api Queries specified task details
Query,
/// query mime type
QueryMimeType,
/// remove task || removes specifed task belongs to the caller
Remove,
/// resume task
Resume,
/// on task
On,
/// off task
Off,
/// ap10 start task
Start,
/// stop task
Stop,
/// Shows specified task details belongs to the caller
Show,
/// Touches specified task with token.
Touch,
/// Searches tasks, for system.
Search,
/// system api deletes specifed tasks.
Clear,
}
impl TryFrom<u32> for RequestCode {
impl TryFrom<u32> for RequestInterfaceCode {
type Error = IpcStatusCode;
fn try_from(code: u32) -> IpcResult<Self> {
match code {
_ if code == RequestCode::Construct as u32 => Ok(RequestCode::Construct),
_ if code == RequestCode::Pause as u32 => Ok(RequestCode::Pause),
_ if code == RequestCode::Query as u32 => Ok(RequestCode::Query),
_ if code == RequestCode::QueryMimeType as u32 => Ok(RequestCode::QueryMimeType),
_ if code == RequestCode::Remove as u32 => Ok(RequestCode::Remove),
_ if code == RequestCode::Resume as u32 => Ok(RequestCode::Resume),
_ if code == RequestCode::On as u32 => Ok(RequestCode::On),
_ if code == RequestCode::Off as u32 => Ok(RequestCode::Off),
_ if code == RequestCode::Start as u32 => Ok(RequestCode::Start),
_ if code == RequestCode::Stop as u32 => Ok(RequestCode::Stop),
_ if code == RequestCode::Show as u32 => Ok(RequestCode::Show),
_ if code == RequestCode::Touch as u32 => Ok(RequestCode::Touch),
_ if code == RequestCode::Search as u32 => Ok(RequestCode::Search),
_ if code == RequestCode::Clear as u32 => Ok(RequestCode::Clear),
_ if code == RequestInterfaceCode::Construct as u32 => Ok(RequestInterfaceCode::Construct),
_ if code == RequestInterfaceCode::Pause as u32 => Ok(RequestInterfaceCode::Pause),
_ if code == RequestInterfaceCode::Query as u32 => Ok(RequestInterfaceCode::Query),
_ if code == RequestInterfaceCode::QueryMimeType as u32 => Ok(RequestInterfaceCode::QueryMimeType),
_ if code == RequestInterfaceCode::Remove as u32 => Ok(RequestInterfaceCode::Remove),
_ if code == RequestInterfaceCode::Resume as u32 => Ok(RequestInterfaceCode::Resume),
_ if code == RequestInterfaceCode::On as u32 => Ok(RequestInterfaceCode::On),
_ if code == RequestInterfaceCode::Off as u32 => Ok(RequestInterfaceCode::Off),
_ if code == RequestInterfaceCode::Start as u32 => Ok(RequestInterfaceCode::Start),
_ if code == RequestInterfaceCode::Stop as u32 => Ok(RequestInterfaceCode::Stop),
_ if code == RequestInterfaceCode::Show as u32 => Ok(RequestInterfaceCode::Show),
_ if code == RequestInterfaceCode::Touch as u32 => Ok(RequestInterfaceCode::Touch),
_ if code == RequestInterfaceCode::Search as u32 => Ok(RequestInterfaceCode::Search),
_ if code == RequestInterfaceCode::Clear as u32 => Ok(RequestInterfaceCode::Clear),
_ => Err(IpcStatusCode::Failed),
}
}
@ -153,20 +123,20 @@ fn on_remote_request(
return Err(IpcStatusCode::Failed);
}
match code.try_into()? {
RequestCode::Construct => stub.construct(data, reply),
RequestCode::Pause => stub.pause(data, reply),
RequestCode::Query => stub.show(data, reply),
RequestCode::QueryMimeType => stub.query_mime_type(data, reply),
RequestCode::Remove => stub.remove(data, reply),
RequestCode::Resume => stub.resume(data, reply),
RequestCode::On => stub.on(data, reply),
RequestCode::Off => stub.off(data, reply),
RequestCode::Start => stub.start(data, reply),
RequestCode::Stop => stub.stop(data, reply),
RequestCode::Show => stub.show(data, reply),
RequestCode::Touch => stub.touch(data, reply),
RequestCode::Search => stub.search(data, reply),
RequestCode::Clear => stub.clear(data, reply),
RequestInterfaceCode::Construct => stub.construct(data, reply),
RequestInterfaceCode::Pause => stub.pause(data, reply),
RequestInterfaceCode::Query => stub.show(data, reply),
RequestInterfaceCode::QueryMimeType => stub.query_mime_type(data, reply),
RequestInterfaceCode::Remove => stub.remove(data, reply),
RequestInterfaceCode::Resume => stub.resume(data, reply),
RequestInterfaceCode::On => stub.on(data, reply),
RequestInterfaceCode::Off => stub.off(data, reply),
RequestInterfaceCode::Start => stub.start(data, reply),
RequestInterfaceCode::Stop => stub.stop(data, reply),
RequestInterfaceCode::Show => stub.show(data, reply),
RequestInterfaceCode::Touch => stub.touch(data, reply),
RequestInterfaceCode::Search => stub.search(data, reply),
RequestInterfaceCode::Clear => stub.clear(data, reply),
}
}

View File

@ -18,7 +18,7 @@ extern crate ipc_rust;
extern crate system_ability_fwk_rust;
use super::{
enumration::*, log::LOG_LABEL, progress::*, request_binding, task_config::TaskConfig,
task_info::TaskInfo, task_manager::*,
task_info::TaskInfo, task_manager::*, download_server_ipc_interface_code::*,
};
use hilog_rust::*;
use ipc_rust::{
@ -317,7 +317,7 @@ impl RequestAbility {
client_data.write(&(item.2)).ok();
}
debug!(LOG_LABEL, "send_request");
let reply = obj.send_request(0, &client_data, false).ok();
let reply = obj.send_request(RequestNotifyInterfaceCode::Notify as u32, &client_data, false).ok();
return;
}
debug!(LOG_LABEL, "key not find");
@ -400,7 +400,7 @@ impl RequestAbility {
reply.write(&(item.2)).ok();
}
debug!(LOG_LABEL, "send_request");
let reply = obj.send_request(1, &reply, false).ok();
let reply = obj.send_request(RequestNotifyInterfaceCode::DoneNotify as u32, &reply, false).ok();
RequestAbility::get_ability_instance().off(task_info.task_id, String::from("done"));
}