1. fix sa issue, 2. fix dmsfwk dependency issue, 3. fix gn format issue, 4. fix code check issu, 5. fix data abililty permission issue, 6. add app permission check feature

Signed-off-by: liulinna <liulinna4@huawei.com>
This commit is contained in:
liulinna 2022-03-18 13:40:19 +08:00
parent e9f3f3ac37
commit 7d79361fdd
31 changed files with 326 additions and 131 deletions

View File

@ -11,8 +11,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//build/lite/config/component/lite_component.gni")
import("//build/ohos.gni")
## Build download_dataability.hap
ohos_hap("download_dataability") {
@ -26,26 +26,26 @@ ohos_hap("download_dataability") {
## Build downloaddataability.so {{{
config("downloaddataability_public_config") {
visibility = [ ":*" ]
visibility = [ ":*" ]
include_dirs = [
"//third_party/node/src",
"include",
]
cflags = [ ]
cflags = []
}
ohos_shared_library("downloaddataability") {
sources = [
"src/common_event.cpp",
"src/db_path.cpp",
"src/download_data_ability.cpp",
"src/download_database.cpp",
"src/uri_utils.cpp",
"src/file_utils.cpp",
"src/predicates_convert.cpp",
"src/common_event.cpp",
"src/sql_analyzer.cpp",
"src/db_path.cpp",
]
include_dirs=[
"src/uri_utils.cpp",
]
include_dirs = [
"//utils/native/base/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//third_party/jsoncpp",
@ -60,37 +60,38 @@ include_dirs=[
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include",
"//foundation/aafwk/standard/services/abilitymgr/include",
"//foundation/appexecfwk/standard/common/log/include",
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
"//foundation/aafwk/standard/frameworks/kits/ability/native/include",
"//base/notification/ces_standard/interfaces/innerkits/native/include/",
"//base/miscservices/request/download/utils/include"
]
"//base/miscservices/request/download/utils/include",
"//foundation/aafwk/standard/interfaces/innerkits/uri/include",
]
deps = [
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//utils/native/base:utils",
"//foundation/ace/napi:ace_napi",
"//third_party/jsoncpp:jsoncpp",
deps = [
"//base/notification/ces_standard/frameworks/core:cesfwk_core",
"//base/notification/ces_standard/frameworks/native:cesfwk_innerkits",
"//base/notification/ces_standard/services:cesfwk_services",
"//foundation/aafwk/standard/interfaces/innerkits/want/:want",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes",
"//foundation/aafwk/standard/interfaces/innerkits/uri:zuri",
"//foundation/aafwk/standard/interfaces/innerkits/want/:want",
"//foundation/ace/napi:ace_napi",
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//third_party/jsoncpp:jsoncpp",
"//utils/native/base:utils",
"//utils/native/base:utilsbase",
]
public_configs = [ ":downloaddataability_public_config" ]
external_deps = [
"ability_runtime:ability_manager",
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ces_standard:cesfwk_innerkits",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"ces_standard:cesfwk_innerkits",
"native_appdatamgr:native_appdatafwk",
"native_appdatamgr:native_dataability",
"native_appdatamgr:native_preferences",

View File

@ -26,9 +26,6 @@
},
"abilities": [
{
"permissions": [
"com.ohos.download.DataAbilityShellProvider.PROVIDER"
],
"name": "DownloadDataAbility",
"icon": "$media:icon",
"description": "dataability_description",

View File

@ -35,6 +35,7 @@ public:
virtual bool Resume(uint32_t taskId) = 0;
virtual bool On(uint32_t taskId, const std::string &type, const sptr<DownloadNotifyInterface> &listener) = 0;
virtual bool Off(uint32_t taskId, const std::string &type) = 0;
virtual bool CheckPermission() = 0;
};
enum {
@ -46,6 +47,7 @@ enum {
CMD_RESUME,
CMD_ON,
CMD_OFF,
CMD_CHECKPERMISSION,
};
} // namespace OHOS::Request::Download
#endif // DOWNLOAD_SERVICE_INTERFACE_H

View File

@ -13,9 +13,7 @@
import("//build/ohos.gni")
config("download_interfaces_kits_napi_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
]
include_dirs = [ "include" ]
cflags_cc = [ "-fexceptions" ]
}
@ -42,51 +40,49 @@ ohos_shared_library("downloadsingle") {
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include",
"//foundation/appexecfwk/standard/kits/appkit/native/app",
"//foundation/appexecfwk/standard/common/log/include",
"//foundation/aafwk/standard/interfaces/innerkits/uri/include",
]
public_configs = [
":download_interfaces_kits_napi_config",
]
public_configs = [ ":download_interfaces_kits_napi_config" ]
sources = [
"src/napi_utils.cpp",
"src/async_call.cpp",
"src/download_base_notify.cpp",
"src/download_config.cpp",
"src/download_event.cpp",
"src/download_fail_notify.cpp",
"src/download_info.cpp",
"src/download_manager.cpp",
"src/download_notify_stub.cpp",
"src/download_pause.cpp",
"src/download_progress_notify.cpp",
"src/download_query.cpp",
"src/download_query_mimetype.cpp",
"src/download_remove.cpp",
"src/download_resume.cpp",
"src/download_service_proxy.cpp",
"src/download_manager.cpp",
"src/download_task_napi.cpp",
"src/async_call.cpp",
"src/download_task.cpp",
"src/download_event.cpp",
"src/download_notify_stub.cpp",
"src/download_base_notify.cpp",
"src/download_fail_notify.cpp",
"src/download_progress_notify.cpp",
"src/download_task_napi.cpp",
"src/napi_utils.cpp",
]
deps = [
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes",
"//foundation/aafwk/standard/interfaces/innerkits/uri:zuri",
"//foundation/ace/napi:ace_napi",
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//utils/native/base:utils",
"//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"ability_runtime:ability_manager",
"ability_base:want",
"eventhandler:libeventhandler",
"native_appdatamgr:native_appdatafwk",
"native_appdatamgr:native_dataability",
"native_appdatamgr:native_preferences",

View File

@ -52,6 +52,8 @@ public:
bool On(uint32_t taskId, const std::string &type, const sptr<DownloadNotifyInterface> &listener);
bool Off(uint32_t taskId, const std::string &type);
bool CheckPermission();
void OnRemoteSaDied(const wptr<IRemoteObject> &object);
void SetDataAbilityHelper(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper);

View File

@ -36,6 +36,7 @@ public:
bool On(uint32_t taskId, const std::string &type, const sptr<DownloadNotifyInterface> &listener) override;
bool Off(uint32_t taskId, const std::string &type) override;
bool CheckPermission() override;
private:
static inline BrokerDelegator<DownloadServiceProxy> delegator_;

View File

@ -27,6 +27,10 @@ namespace OHOS::Request::Download {
napi_value DownloadEvent::On(napi_env env, napi_callback_info info)
{
DOWNLOAD_HILOGD("Enter ---->");
if (!DownloadManager::GetInstance()->CheckPermission()) {
DOWNLOAD_HILOGD("no permission to access download service");
return nullptr;
}
napi_value result = nullptr;
size_t argc = NapiUtils::MAX_ARGC;
napi_value argv[NapiUtils::MAX_ARGC] = {nullptr};
@ -73,6 +77,10 @@ napi_value DownloadEvent::On(napi_env env, napi_callback_info info)
napi_value DownloadEvent::Off(napi_env env, napi_callback_info info)
{
DOWNLOAD_HILOGD("Enter ---->");
if (!DownloadManager::GetInstance()->CheckPermission()) {
DOWNLOAD_HILOGD("no permission to access download service");
return nullptr;
}
auto context = std::make_shared<EventOffContext>();
napi_value result = nullptr;
size_t argc = NapiUtils::MAX_ARGC;

View File

@ -31,7 +31,7 @@ DownloadFailNotify::~DownloadFailNotify()
void DownloadFailNotify::OnCallBack(MessageParcel &data)
{
DOWNLOAD_HILOGD("Pause callback in");
DOWNLOAD_HILOGD("Failed callback in");
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(env_, &loop);
if (loop == nullptr) {
@ -51,11 +51,12 @@ void DownloadFailNotify::OnCallBack(MessageParcel &data)
notifyData->task = task_;
notifyData->firstArgv = data.ReadUint32();
DOWNLOAD_HILOGD("recv error code is %{public}d", notifyData->firstArgv);
work->data = this;
work->data = notifyData;
uv_queue_work(
loop, work, [](uv_work_t *work) {},
[](uv_work_t *work, int statusInt) {
DOWNLOAD_HILOGD("this is new fail callback");
NotifyData *notifyData = static_cast<NotifyData*>(work->data);
napi_value undefined = 0;
napi_get_undefined(notifyData->env, &undefined);

View File

@ -64,34 +64,6 @@ DownloadTask* DownloadManager::EnqueueTask(const DownloadConfig &config)
{
DOWNLOAD_HILOGD("DownloadManager EnqueueTask start.");
OHOS::Uri uriDownload("dataability:///com.ohos.download/download/downloadInfo");
OHOS::NativeRdb::ValuesBucket rawContactValues;
rawContactValues.PutString("title", "test1");
int rowId = dataAbilityHelper_->Insert(uriDownload, rawContactValues);
DOWNLOAD_HILOGI("DownloadManager EnqueueTask rowId = %{public}d", rowId);
std::vector<std::string> columns;
columns.push_back("taskid");
columns.push_back("title");
OHOS::NativeRdb::DataAbilityPredicates predicates;
predicates.GreaterThan("taskid", "0");
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet;
resultSet = dataAbilityHelper_->Query(uriDownload, columns, predicates);
int rowCount = 0;
resultSet->GetRowCount(rowCount);
DOWNLOAD_HILOGI("DownloadManager ResultSet rowCount = %{public}d", rowCount);
int resultSetNum = resultSet->GoToFirstRow();
while (resultSetNum == 0) {
int id = 0;
std::string contactIdKey = "taskid";
int contactIndex = 0;
resultSet->GetColumnIndex(contactIdKey, contactIndex);
resultSet->GetInt(contactIndex, id);
DOWNLOAD_HILOGI("DownloadManager query result id = %{public}d", id);
resultSetNum = resultSet->GoToNextRow();
}
resultSet->Close();
if (downloadServiceProxy_ == nullptr) {
DOWNLOAD_HILOGW("Redo GetDownloadServiceProxy");
downloadServiceProxy_ = GetDownloadServiceProxy();
@ -100,8 +72,23 @@ DownloadTask* DownloadManager::EnqueueTask(const DownloadConfig &config)
DOWNLOAD_HILOGE("Pause quit because redoing GetDownloadServiceProxy failed.");
return nullptr;
}
DOWNLOAD_HILOGD("DownloadManager Pause succeeded.");
uint32_t taskId = downloadServiceProxy_->Request(config);
DOWNLOAD_HILOGD("DownloadManager EnqueueTask succeeded.");
DOWNLOAD_HILOGD("DownloadManager EnqueueTask Save Data.");
OHOS::Uri uriDownload("dataability:///com.ohos.download/download/downloadInfo");
OHOS::NativeRdb::ValuesBucket rawContactValues;
rawContactValues.PutInt("taskId", taskId);
rawContactValues.PutString("url", config.GetUrl().c_str());
rawContactValues.PutString("description", config.GetDescription().c_str());
rawContactValues.PutString("title", config.GetTitle().c_str());
rawContactValues.PutString("filePath", config.GetFilePath().c_str());
rawContactValues.PutBool("metered", config.GetMetered());
rawContactValues.PutBool("roaming", config.GetRoaming());
rawContactValues.PutInt("network", config.GetNetworkType());
int rowId = dataAbilityHelper_->Insert(uriDownload, rawContactValues);
DOWNLOAD_HILOGI("DownloadManager EnqueueTask rowId = %{public}d", rowId);
return new DownloadTask(taskId);
}
@ -185,7 +172,7 @@ bool DownloadManager::On(uint32_t taskId, const std::string &type, const sptr<Do
DOWNLOAD_HILOGE("Resume quit because redoing GetDownloadServiceProxy failed.");
return false;
}
DOWNLOAD_HILOGD("DownloadManager Resume succeeded.");
DOWNLOAD_HILOGD("DownloadManager On succeeded.");
return downloadServiceProxy_->On(taskId, type, listener);
}
@ -199,10 +186,25 @@ bool DownloadManager::Off(uint32_t taskId, const std::string &type)
DOWNLOAD_HILOGE("Resume quit because redoing GetDownloadServiceProxy failed.");
return false;
}
DOWNLOAD_HILOGD("DownloadManager Resume succeeded.");
DOWNLOAD_HILOGD("DownloadManager Off succeeded.");
return downloadServiceProxy_->Off(taskId, type);
}
bool DownloadManager::CheckPermission()
{
if (downloadServiceProxy_ == nullptr) {
DOWNLOAD_HILOGW("Redo GetDownloadServiceProxy");
downloadServiceProxy_ = GetDownloadServiceProxy();
}
if (downloadServiceProxy_ == nullptr) {
DOWNLOAD_HILOGE("Resume quit because redoing GetDownloadServiceProxy failed.");
return false;
}
DOWNLOAD_HILOGD("DownloadManager CheckPermission succeeded.");
DOWNLOAD_HILOGD("Check Permission enable");
return downloadServiceProxy_->CheckPermission();
}
sptr<DownloadServiceInterface> DownloadManager::GetDownloadServiceProxy()
{
sptr<ISystemAbilityManager> systemAbilityManager =

View File

@ -22,13 +22,19 @@ namespace OHOS::Request::Download {
napi_value DownloadPause::Exec(napi_env env, napi_callback_info info)
{
DOWNLOAD_HILOGD("Enter ---->");
if (!DownloadManager::GetInstance()->CheckPermission()) {
DOWNLOAD_HILOGD("no permission to access download service");
return nullptr;
}
auto context = std::make_shared<PauseContext>();
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
NAPI_ASSERT_BASE(env, argc == 0, " should 0 parameter!", napi_invalid_arg);
return napi_ok;
};
auto output = [context](napi_env env, napi_value *result) -> napi_status {
return napi_ok;
napi_status status = napi_get_boolean(env, context->result, result);
DOWNLOAD_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
return status;
};
auto exec = [context](AsyncCall::Context *ctx) {
context->result = DownloadManager::GetInstance()->Pause(context->task_->GetId());

View File

@ -34,7 +34,7 @@ DownloadProgressNotify::~DownloadProgressNotify()
void DownloadProgressNotify::OnCallBack(MessageParcel &data)
{
DOWNLOAD_HILOGD("Pause callback in");
DOWNLOAD_HILOGD("Progress callback in");
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(env_, &loop);
if (loop == nullptr) {

View File

@ -22,6 +22,10 @@ namespace OHOS::Request::Download {
napi_value DownloadQuery::Exec(napi_env env, napi_callback_info info)
{
DOWNLOAD_HILOGD("Enter ---->");
if (!DownloadManager::GetInstance()->CheckPermission()) {
DOWNLOAD_HILOGD("no permission to access download service");
return nullptr;
}
auto context = std::make_shared<QueryContext>();
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
NAPI_ASSERT_BASE(env, argc == 0, " should 0 parameter!", napi_invalid_arg);

View File

@ -23,6 +23,10 @@ namespace OHOS::Request::Download {
napi_value DownloadQueryMimeType::Exec(napi_env env, napi_callback_info info)
{
DOWNLOAD_HILOGD("Enter ---->");
if (!DownloadManager::GetInstance()->CheckPermission()) {
DOWNLOAD_HILOGD("no permission to access download service");
return nullptr;
}
auto context = std::make_shared<QueryMimeContext>();
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
NAPI_ASSERT_BASE(env, argc == 0, " should 0 parameter!", napi_invalid_arg);

View File

@ -21,13 +21,19 @@ namespace OHOS::Request::Download {
napi_value DownloadRemove::Exec(napi_env env, napi_callback_info info)
{
DOWNLOAD_HILOGD("Enter ---->");
if (!DownloadManager::GetInstance()->CheckPermission()) {
DOWNLOAD_HILOGD("no permission to access download service");
return nullptr;
}
auto context = std::make_shared<RemoveContext>();
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
NAPI_ASSERT_BASE(env, argc == 0, " should 0 parameter!", napi_invalid_arg);
return napi_ok;
};
auto output = [context](napi_env env, napi_value *result) -> napi_status {
return napi_ok;
napi_status status = napi_get_boolean(env, context->result, result);
DOWNLOAD_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
return status;
};
auto exec = [context](AsyncCall::Context *ctx) {
context->result = DownloadManager::GetInstance()->Remove(context->task_->GetId());

View File

@ -21,13 +21,19 @@ namespace OHOS::Request::Download {
napi_value DownloadResume::Exec(napi_env env, napi_callback_info info)
{
DOWNLOAD_HILOGD("Enter ---->");
if (!DownloadManager::GetInstance()->CheckPermission()) {
DOWNLOAD_HILOGD("no permission to access download service");
return nullptr;
}
auto context = std::make_shared<ResumeContext>();
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
NAPI_ASSERT_BASE(env, argc == 0, " should 0 parameter!", napi_invalid_arg);
return napi_ok;
};
auto output = [context](napi_env env, napi_value *result) -> napi_status {
return napi_ok;
napi_status status = napi_get_boolean(env, context->result, result);
DOWNLOAD_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
return status;
};
auto exec = [context](AsyncCall::Context *ctx) {
context->result = DownloadManager::GetInstance()->Resume(context->task_->GetId());

View File

@ -223,4 +223,24 @@ bool DownloadServiceProxy::Off(uint32_t taskId, const std::string &type)
DOWNLOAD_HILOGD("DownloadServiceProxy::Off out [ret: %{public}d]", ret);
return ret;
}
bool DownloadServiceProxy::CheckPermission()
{
DOWNLOAD_HILOGD("DownloadServiceProxy::CheckPermission in");
MessageParcel data, reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
DOWNLOAD_HILOGE(" Failed to write parcelable ");
return false;
}
int32_t result = Remote()->SendRequest(CMD_CHECKPERMISSION, data, reply, option);
if (result != ERR_NONE) {
DOWNLOAD_HILOGE(" DownloadServiceProxy::CheckPermission fail, ret = %{public}d ", result);
return false;
}
bool ret = reply.ReadBool();
DOWNLOAD_HILOGD("DownloadServiceProxy::CheckPermission out [ret: %{public}d]", ret);
return ret;
}
} // namespace OHOS::Request::Download

View File

@ -51,6 +51,10 @@ __thread napi_ref DownloadTaskNapi::globalCtor = nullptr;
napi_value DownloadTaskNapi::JsMain(napi_env env, napi_callback_info info)
{
DOWNLOAD_HILOGD("Enter download JsMain.");
if (!DownloadManager::GetInstance()->CheckPermission()) {
DOWNLOAD_HILOGD("no permission to access download service");
return nullptr;
}
struct ContextInfo {
napi_ref ref = nullptr;
};
@ -188,9 +192,12 @@ std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> DownloadTaskNapi::GetDataAb
}
std::shared_ptr<OHOS::Uri> uriPtr = std::make_shared<OHOS::Uri>("dataability:///com.ohos.download");
if (dataAbilityHelper_ == nullptr) {
DOWNLOAD_HILOGE("dataAbilityHelper_ is not nullptr!");
DOWNLOAD_HILOGE("Try to get dataAbilityHelper_!");
dataAbilityHelper_ = OHOS::AppExecFwk::DataAbilityHelper::Creator(ability->GetContext(), uriPtr);
}
if (dataAbilityHelper_ != nullptr) {
DOWNLOAD_HILOGE("dataAbilityHelper_ is not nullptr!");
}
return dataAbilityHelper_;
}
} // namespace OHOS::Request::Download

View File

@ -15,7 +15,7 @@
<info>
<process>download_server</process>
<systemability>
<name>3705</name>
<name>3706</name>
<libpath>libdownload_server.z.so</libpath>
<run-on-create>true</run-on-create>
<distributed>false</distributed>

View File

@ -15,30 +15,28 @@ import("//build/ohos.gni")
config("download_service_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
]
include_dirs = [ "include" ]
cflags_cc = [ "-fexceptions" ]
}
ohos_shared_library("download_server") {
sources = [
"src/download_service_ability.cpp",
"src/download_service_stub.cpp",
"src/download_notify_proxy.cpp",
"src/download_service_manager.cpp",
"src/download_service_task.cpp",
"src/download_thread.cpp",
"//base/miscservices/request/download/interfaces/kits/js/napi/download_single/src/download_config.cpp",
"//base/miscservices/request/download/interfaces/kits/js/napi/download_single/src/download_info.cpp",
"//base/miscservices/request/download/interfaces/kits/js/napi/download_single/src/download_config.cpp",
"//base/miscservices/request/download/interfaces/kits/js/napi/download_single/src/download_info.cpp",
"src/download_notify_proxy.cpp",
"src/download_service_ability.cpp",
"src/download_service_manager.cpp",
"src/download_service_stub.cpp",
"src/download_service_task.cpp",
"src/download_thread.cpp",
]
public_configs = [
"//utils/native/base:utils_config",
":download_service_config",
]
include_dirs = [
include_dirs = [
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"//base/miscservices/request/download/interfaces/innerkits/include",
@ -46,29 +44,30 @@ ohos_shared_library("download_server") {
"//third_party/json/include",
"//base/miscservices/request/download/interfaces/kits/js/napi/download_single/include",
"//third_party/curl/include",
"//foundation/aafwk/standard/interfaces/innerkits/uri/include",
]
deps = [
"//utils/native/base:utils",
"//base/telephony/core_service/interfaces/innerkits:tel_core_service_api",
"//foundation/aafwk/standard/interfaces/innerkits/uri:zuri",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//base/telephony/core_service/interfaces/innerkits:tel_core_service_api",
"//third_party/curl:curl",
"//utils/native/base:utils",
]
defines = [ "NO_SSL_CERTIFICATION=1" ]
external_deps = [
"ipc:ipc_core",
"ril_adapter:hril_innerkits",
"hiviewdfx_hilog_native:libhilog",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_core",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"multimedia_image_standard:image_native",
"os_account_standard:os_account_innerkits",
"ril_adapter:hril_innerkits",
]
subsystem_name = "miscservices"
part_name = "request"
}

View File

@ -50,6 +50,8 @@ public:
bool On(uint32_t taskId, const std::string &type, const sptr<DownloadNotifyInterface> &listener) override;
bool Off(uint32_t taskId, const std::string &type) override;
bool CheckPermission() override;
static void NotifyHandler(const std::string& type, uint32_t taskId, uint32_t argv1, uint32_t argv2);
protected:

View File

@ -34,6 +34,7 @@ private:
bool OnResume(MessageParcel &data, MessageParcel &reply);
bool OnEventOn(MessageParcel &data, MessageParcel &reply);
bool OnEventOff(MessageParcel &data, MessageParcel &reply);
bool OnCheckPermission(MessageParcel &data, MessageParcel &reply);
};
} // namespace OHOS::Request::Download
#endif // DOWNLOAD_SERVICE_STUB_H

View File

@ -88,6 +88,7 @@ private:
bool isPartialMode_;
bool forceStop_;
bool isRemoved_;
uint32_t retryTime_;
DownloadTaskCallback eventCb_;

View File

@ -22,6 +22,7 @@
#include "core_service_client.h"
#include "ipc_skeleton.h"
#include "accesstoken_kit.h"
#include "iservice_registry.h"
#include "system_ability.h"
#include "system_ability_definition.h"
@ -33,6 +34,11 @@
namespace OHOS::Request::Download {
using namespace std;
using namespace OHOS::HiviewDFX;
using namespace Security::AccessToken;
static const std::string DOWNLOAD_PERMISSION_NAME_INTERNET = "ohos.permission.INTERNET";
static const std::string DOWNLOAD_PERMISSION_NAME_SESSION = "ohos.permission.DOWNLOAD_SESSION_MANAGER";
REGISTER_SYSTEM_ABILITY_BY_ID(DownloadServiceAbility, DOWNLOAD_SERVICE_ID, true);
const std::int64_t INIT_INTERVAL = 5000L;
@ -219,6 +225,21 @@ bool DownloadServiceAbility::Off(uint32_t taskId, const std::string &type)
return false;
}
bool DownloadServiceAbility::CheckPermission()
{
AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
int result = PERMISSION_DENIED;
if (AccessTokenKit::GetTokenTypeFlag(callerToken) == TOKEN_NATIVE) {
result = AccessTokenKit::VerifyNativeToken(callerToken, DOWNLOAD_PERMISSION_NAME_INTERNET);
} else if (AccessTokenKit::GetTokenTypeFlag(callerToken) == TOKEN_HAP) {
result = AccessTokenKit::VerifyAccessToken(callerToken, DOWNLOAD_PERMISSION_NAME_INTERNET);
} else {
DOWNLOAD_HILOGE("invalid token id %{public}d", callerToken);
}
DOWNLOAD_HILOGI("Current token permission is %{public}d", result);
return result == PERMISSION_GRANTED;
}
void DownloadServiceAbility::NotifyHandler(const std::string& type, uint32_t taskId, uint32_t argv1, uint32_t argv2)
{
std::string combineType = type + "-" + std::to_string(taskId);

View File

@ -52,6 +52,9 @@ int32_t DownloadServiceStub::OnRemoteRequest(
case CMD_OFF:
return OnEventOff(data, reply);
break;
case CMD_CHECKPERMISSION:
return OnCheckPermission(data, reply);
break;
default:
DOWNLOAD_HILOGE("Default value received, check needed.");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
@ -197,4 +200,16 @@ bool DownloadServiceStub::OnEventOff(MessageParcel &data, MessageParcel &reply)
DOWNLOAD_HILOGD("DownloadServiceStub::OnEventOff out");
return true;
}
bool DownloadServiceStub::OnCheckPermission(MessageParcel &data, MessageParcel &reply)
{
DOWNLOAD_HILOGD("DownloadServiceStub::OnCheckPermission in");
bool result = CheckPermission();
if (!reply.WriteBool(result)) {
return false;
}
DOWNLOAD_HILOGD("DownloadServiceStub::OnCheckPermission out");
return true;
}
} // namespace OHOS::Request::Download

View File

@ -23,7 +23,7 @@ namespace OHOS::Request::Download {
DownloadServiceTask::DownloadServiceTask(uint32_t taskId, const DownloadConfig &config)
: taskId_(taskId), config_(config), status_(SESSION_UNKNOWN), code_(ERROR_UNKNOWN), reason_(PAUSED_UNKNOWN),
mimeType_(""), file_(nullptr), totalSize_(0), downloadSize_(0), isPartialMode_(false), forceStop_(false),
retryTime_(10), eventCb_(nullptr) {
isRemoved_(false), retryTime_(10), eventCb_(nullptr) {
}
DownloadServiceTask::~DownloadServiceTask(void)
@ -96,6 +96,7 @@ bool DownloadServiceTask::Resume()
bool DownloadServiceTask::Remove()
{
DOWNLOAD_HILOGD("Remove Task[%{public}d], current status is %{public}d\n", taskId_, status_);
isRemoved_ = true;
ForceStopRunning();
if (eventCb_ != nullptr) {
eventCb_("remove", taskId_, 0, 0);
@ -380,7 +381,10 @@ int DownloadServiceTask::ProgressCallback(void *pParam, double dltotal, double d
{
DownloadServiceTask *this_ = static_cast<DownloadServiceTask *>(pParam);
if (this_ != nullptr) {
if (this_->eventCb_ != nullptr) {
if (this_->isRemoved_) {
DOWNLOAD_HILOGD("download task has been removed\n");
}
if (this_->eventCb_ != nullptr && !this_->isRemoved_) {
this_->eventCb_("progress", this_->taskId_, this_->downloadSize_, this_->totalSize_);
}
if (this_->forceStop_) {
@ -440,6 +444,7 @@ bool DownloadServiceTask::ExecHttp()
}
CURLcode code = curl_easy_perform(handle.get());
if (file_ != nullptr) {
fflush(file_);
fclose(file_);
@ -551,6 +556,9 @@ bool DownloadServiceTask::GetFileSize(uint32_t &result)
if (res == CURLE_OK) {
result = static_cast<long long>(size);
}
if (result == -1) {
result = 0;
}
DOWNLOAD_HILOGD("fetch file size %{public}d", result);
return true;
}
@ -562,6 +570,10 @@ std::string DownloadServiceTask::GetTmpPath()
void DownloadServiceTask::HandleResponseCode(CURLcode code, int32_t httpCode)
{
if (isRemoved_) {
DOWNLOAD_HILOGD("download task has been removed");
return;
}
switch (code) {
case CURLE_OK:
if (httpCode == HTTP_OK || (isPartialMode_ && httpCode == HTTP_PARIAL_FILE)) {

View File

@ -26,10 +26,10 @@ enum NetworkType {
enum ErrorCode {
ERROR_CANNOT_RESUME,
ERROR_DEVICE_NOT_FOUND,
ERROR_INSUFFICIENT_SPACE,
ERROR_FILE_ALREADY_EXISTS,
ERROR_FILE_ERROR,
ERROR_HTTP_DATA_ERROR,
ERROR_INSUFFICIENT_SPACE,
ERROR_TOO_MANY_REDIRECTS,
ERROR_UNHANDLED_HTTP_CODE,
ERROR_UNKNOWN,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -53,12 +53,13 @@ ohos_shared_library("upload_lib") {
deps = [
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/uri:zuri",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//third_party/curl/:curl",
]
external_deps = [
"ability_base:zuri",
"ability_runtime:ability_manager",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",

View File

@ -29,6 +29,7 @@ config("upload_native_public_config") {
"//third_party/libuv/include",
"./",
"//base/miscservices/request/download/interfaces/kits/js/napi/download_single/include",
"//base/miscservices/request/download/utils/include",
]
}

View File

@ -18,14 +18,89 @@
#include "upload_task_napi.h"
#include "js_util.h"
#include "download_task_napi.h"
#include "constant.h"
using namespace OHOS::Request::UploadNapi;
using namespace OHOS::Request::Upload;
using namespace OHOS::Request::Download;
// fix code rule issue
static napi_value network_mobile = nullptr;
static napi_value network_wifi = nullptr;
static napi_value err_cannot_resume = nullptr;
static napi_value err_dev_not_found = nullptr;
static napi_value err_file_exist = nullptr;
static napi_value err_file_error = nullptr;
static napi_value err_http_data = nullptr;
static napi_value err_no_space = nullptr;
static napi_value err_many_redirect = nullptr;
static napi_value err_http_code = nullptr;
static napi_value err_unknown = nullptr;
static napi_value paused_queue_wifi = nullptr;
static napi_value paused_for_network = nullptr;
static napi_value paused_to_retry = nullptr;
static napi_value paused_by_user = nullptr;
static napi_value session_success = nullptr;
static napi_value session_running = nullptr;
static napi_value session_pending = nullptr;
static napi_value session_paused = nullptr;
static napi_value session_failed = nullptr;
static napi_value Init(napi_env env, napi_value exports)
{
/* Create Network Type Const */
napi_create_int32(env, static_cast<int32_t>(NETWORK_MOBILE), &network_mobile);
napi_create_int32(env, static_cast<int32_t>(NETWORK_WIFI), &network_wifi);
/* Create error cause const */
napi_create_int32(env, static_cast<int32_t>(ERROR_CANNOT_RESUME), &err_cannot_resume);
napi_create_int32(env, static_cast<int32_t>(ERROR_DEVICE_NOT_FOUND), &err_dev_not_found);
napi_create_int32(env, static_cast<int32_t>(ERROR_FILE_ALREADY_EXISTS), &err_file_exist);
napi_create_int32(env, static_cast<int32_t>(ERROR_FILE_ERROR), &err_file_error);
napi_create_int32(env, static_cast<int32_t>(ERROR_HTTP_DATA_ERROR), &err_http_data);
napi_create_int32(env, static_cast<int32_t>(ERROR_INSUFFICIENT_SPACE), &err_no_space);
napi_create_int32(env, static_cast<int32_t>(ERROR_TOO_MANY_REDIRECTS), &err_many_redirect);
napi_create_int32(env, static_cast<int32_t>(ERROR_UNHANDLED_HTTP_CODE), &err_http_code);
napi_create_int32(env, static_cast<int32_t>(ERROR_UNKNOWN), &err_unknown);
/* Create paused reason Const */
napi_create_int32(env, static_cast<int32_t>(PAUSED_QUEUED_FOR_WIFI), &paused_queue_wifi);
napi_create_int32(env, static_cast<int32_t>(PAUSED_WAITING_FOR_NETWORK), &paused_for_network);
napi_create_int32(env, static_cast<int32_t>(PAUSED_WAITING_TO_RETRY), &paused_to_retry);
napi_create_int32(env, static_cast<int32_t>(PAUSED_BY_USER), &paused_by_user);
/* Create session status Const */
napi_create_int32(env, static_cast<int32_t>(SESSION_SUCCESS), &session_success);
napi_create_int32(env, static_cast<int32_t>(SESSION_RUNNING), &session_running);
napi_create_int32(env, static_cast<int32_t>(SESSION_PENDING), &session_pending);
napi_create_int32(env, static_cast<int32_t>(SESSION_PAUSED), &session_paused);
napi_create_int32(env, static_cast<int32_t>(SESSION_FAILED), &session_failed);
napi_property_descriptor desc[] = {
DECLARE_NAPI_STATIC_PROPERTY("NETWORK_MOBILE", network_mobile),
DECLARE_NAPI_STATIC_PROPERTY("NETWORK_WIFI", network_wifi),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_CANNOT_RESUME", err_cannot_resume),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_DEVICE_NOT_FOUND", err_dev_not_found),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_FILE_ALREADY_EXISTS", err_file_exist),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_FILE_ERROR", err_file_error),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_HTTP_DATA_ERROR", err_http_data),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_INSUFFICIENT_SPACE", err_no_space),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_TOO_MANY_REDIRECTS", err_many_redirect),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_UNHANDLED_HTTP_CODE", err_http_code),
DECLARE_NAPI_STATIC_PROPERTY("ERROR_UNKNOWN", err_unknown),
DECLARE_NAPI_STATIC_PROPERTY("PAUSED_QUEUED_FOR_WIFI", paused_queue_wifi),
DECLARE_NAPI_STATIC_PROPERTY("PAUSED_WAITING_FOR_NETWORK", paused_for_network),
DECLARE_NAPI_STATIC_PROPERTY("PAUSED_WAITING_TO_RETRY", paused_to_retry),
DECLARE_NAPI_STATIC_PROPERTY("PAUSED_BY_USER", paused_by_user),
DECLARE_NAPI_STATIC_PROPERTY("SESSION_SUCCESS", session_success),
DECLARE_NAPI_STATIC_PROPERTY("SESSION_RUNNING", session_running),
DECLARE_NAPI_STATIC_PROPERTY("SESSION_PENDING", session_pending),
DECLARE_NAPI_STATIC_PROPERTY("SESSION_PAUSED", session_paused),
DECLARE_NAPI_STATIC_PROPERTY("SESSION_FAILED", session_failed),
DECLARE_NAPI_METHOD("download", DownloadTaskNapi::JsMain),
DECLARE_NAPI_METHOD("upload", UploadTaskNapi::JsUpload),
};

View File

@ -33,12 +33,15 @@ ohos_unittest("upload_obtain_file_UT_test") {
deps = [
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/uri:zuri",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
]
external_deps = [ "ability_runtime:ability_manager" ]
external_deps = [
"ability_base:zuri",
"ability_runtime:ability_manager",
]
}
ohos_unittest("upload_UT_test") {
@ -71,13 +74,14 @@ ohos_unittest("upload_UT_test") {
deps = [
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/frameworks/kits/appkit:app_context",
"//foundation/aafwk/standard/interfaces/innerkits/uri:zuri",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//third_party/curl/:curl",
"//utils/native/base:utils",
]
external_deps = [
"ability_base:zuri",
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:napi_base_context",