• 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 #ifndef DOWNLOAD_CONFIG_H
17 #define DOWNLOAD_CONFIG_H
18 
19 #include <map>
20 #include <iosfwd>
21 #include <string>
22 
23 namespace OHOS::Request::Download {
24 class DownloadConfig final {
25 public:
26     DownloadConfig();
27 
28     void SetUrl(const std::string &url);
29 
30     void SetHeader(const std::string &key, const std::string &val);
31 
32     void SetMetered(bool enableMetered);
33 
34     void SetRoaming(bool enableRoaming);
35 
36     void SetDescription(const std::string &description);
37 
38     void SetNetworkType(uint32_t type);
39 
40     void SetFilePath(const std::string &filePath);
41 
42     void SetTitle(const std::string &title);
43 
44     void SetFD(int32_t fd);
45 
46     void SetFDError(int32_t fdError);
47 
48     void SetBundleName(const std::string &bundleName);
49 
50     void SetBackground(bool background);
51 
52     void SetApplicationInfoUid(const int32_t uid);
53 
54     [[nodiscard]] const std::string &GetUrl() const;
55 
56     [[nodiscard]] const std::map<std::string, std::string> &GetHeader() const;
57 
58     [[nodiscard]] bool IsMetered() const;
59 
60     [[nodiscard]] bool IsRoaming() const;
61 
62     [[nodiscard]] const std::string &GetDescription() const;
63 
64     [[nodiscard]] uint32_t GetNetworkType() const;
65 
66     [[nodiscard]] const std::string &GetFilePath() const;
67 
68     [[nodiscard]] const std::string &GetTitle() const;
69 
70     int32_t GetFD() const;
71 
72     int32_t GetFDError() const;
73 
74     [[nodiscard]] const std::string &GetBundleName() const;
75 
76     [[nodiscard]] bool IsBackground() const;
77 
78     int32_t GetApplicationInfoUid() const;
79 
80     void Dump(bool isFull = true) const;
81 
82 private:
83     bool enableMetered_ = false;
84     bool enableRoaming_ = false;
85     bool background_ = false;
86     int32_t fd_ = -1;
87     int32_t fdError_ = 0;
88     int32_t uid_ = -1;
89     uint32_t networkType_ = 0;
90     std::string url_;
91     std::string description_;
92     std::string filePath_;
93     std::string title_;
94     std::string bundleName_;
95     std::map<std::string, std::string> header_;
96 };
97 } // namespace OHOS::Request::Download
98 
99 #endif /* DOWNLOAD_CONFIG_H */
100