• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "download_config.h"
17 #include "constant.h"
18 #include "log.h"
19 
20 namespace OHOS::Request::Download {
DownloadConfig()21 DownloadConfig::DownloadConfig()
22 {
23 }
24 
SetUrl(const std::string & url)25 void DownloadConfig::SetUrl(const std::string &url)
26 {
27     url_ = url;
28 }
29 
SetHeader(const std::string & key,const std::string & val)30 void DownloadConfig::SetHeader(const std::string &key, const std::string &val)
31 {
32     header_[key] = val;
33 }
34 
SetMetered(bool enableMetered)35 void DownloadConfig::SetMetered(bool enableMetered)
36 {
37     enableMetered_ = enableMetered;
38 }
39 
SetRoaming(bool enableRoaming)40 void DownloadConfig::SetRoaming(bool enableRoaming)
41 {
42     enableRoaming_ = enableRoaming;
43 }
44 
SetDescription(const std::string & description)45 void DownloadConfig::SetDescription(const std::string &description)
46 {
47     description_ = description;
48 }
49 
SetNetworkType(uint32_t type)50 void DownloadConfig::SetNetworkType(uint32_t type)
51 {
52     networkType_ = type;
53 }
54 
SetFilePath(const std::string & filePath)55 void DownloadConfig::SetFilePath(const std::string &filePath)
56 {
57     filePath_ = filePath;
58 }
59 
SetTitle(const std::string & title)60 void DownloadConfig::SetTitle(const std::string &title)
61 {
62     title_ = title;
63 }
64 
SetFD(int32_t fd)65 void DownloadConfig::SetFD(int32_t fd)
66 {
67     fd_ = fd;
68 }
69 
SetFDError(int32_t fdError)70 void DownloadConfig::SetFDError(int32_t fdError)
71 {
72     fdError_ = fdError;
73 }
74 
SetBundleName(const std::string & bundleName)75 void DownloadConfig::SetBundleName(const std::string &bundleName)
76 {
77     bundleName_ = bundleName;
78 }
79 
SetBackground(bool background)80 void DownloadConfig::SetBackground(bool background)
81 {
82     background_ = background;
83 }
84 
SetApplicationInfoUid(const int32_t uid)85 void DownloadConfig::SetApplicationInfoUid(const int32_t uid)
86 {
87     uid_ = uid;
88 }
89 
GetUrl() const90 const std::string &DownloadConfig::GetUrl() const
91 {
92     return url_;
93 }
94 
GetHeader() const95 const std::map<std::string, std::string> &DownloadConfig::GetHeader() const
96 {
97     return header_;
98 }
99 
IsMetered() const100 bool DownloadConfig::IsMetered() const
101 {
102     return enableMetered_;
103 }
104 
IsRoaming() const105 bool DownloadConfig::IsRoaming() const
106 {
107     return enableRoaming_;
108 }
109 
GetDescription() const110 const std::string &DownloadConfig::GetDescription() const
111 {
112     return description_;
113 }
114 
GetNetworkType() const115 uint32_t DownloadConfig::GetNetworkType() const
116 {
117     return networkType_;
118 }
119 
GetFilePath() const120 const std::string &DownloadConfig::GetFilePath() const
121 {
122     return filePath_;
123 }
124 
GetTitle() const125 const std::string &DownloadConfig::GetTitle() const
126 {
127     return title_;
128 }
129 
GetFD() const130 int32_t DownloadConfig::GetFD() const
131 {
132     return fd_;
133 }
134 
GetFDError() const135 int32_t DownloadConfig::GetFDError() const
136 {
137     return fdError_;
138 }
139 
GetBundleName() const140 const std::string &DownloadConfig::GetBundleName() const
141 {
142     return bundleName_;
143 }
144 
IsBackground() const145 bool DownloadConfig::IsBackground() const
146 {
147     return background_;
148 }
149 
GetApplicationInfoUid() const150 int32_t DownloadConfig::GetApplicationInfoUid() const
151 {
152     return uid_;
153 }
154 
Dump(bool isFull) const155 void DownloadConfig::Dump(bool isFull) const
156 {
157     DOWNLOAD_HILOGD("fd: %{public}d", fd_);
158     DOWNLOAD_HILOGD("fd errno: %{public}d", fdError_);
159     DOWNLOAD_HILOGD("URL: %{public}s", url_.c_str());
160     DOWNLOAD_HILOGD("enableMetered: %{public}s", enableMetered_ ? "true" : "false");
161     DOWNLOAD_HILOGD("enableRoaming: %{public}s", enableRoaming_ ? "true" : "false");
162     DOWNLOAD_HILOGD("description: %{public}s", description_.c_str());
163     std::string networkDesc = "WLAN and Mobile";
164     if ((networkType_ & NETWORK_MASK) == NETWORK_MOBILE) {
165         networkDesc = "Mobile";
166     } else if ((networkType_ & NETWORK_MASK) == NETWORK_WIFI) {
167         networkDesc = "WLAN";
168     }
169     DOWNLOAD_HILOGD("networkType: %{public}s", networkDesc.c_str());
170     DOWNLOAD_HILOGD("filePath: %{public}s", filePath_.c_str());
171     DOWNLOAD_HILOGD("title: %{public}s", title_.c_str());
172     if (isFull) {
173         DOWNLOAD_HILOGD("Header Information:");
174         std::for_each(header_.begin(), header_.end(), [](std::pair<std::string, std::string> p) {
175             DOWNLOAD_HILOGD("%{public}s : %{public}s", p.first.c_str(), p.second.c_str());
176         });
177         DOWNLOAD_HILOGD("Header Information -------------- End");
178     }
179     DOWNLOAD_HILOGD("bundleName: %{public}s", bundleName_.c_str());
180     DOWNLOAD_HILOGD("background: %{public}s", background_ ? "true" : "false");
181     DOWNLOAD_HILOGD("uid: %{public}d", uid_);
182 }
183 } // namespace OHOS::Request::Download
184