1 /*
2  * Copyright (c) 2024 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 #ifndef OHOS_CLOUD_FILE_SERVICE_GALLERY_DOWNLOAD_FILE_STAT_H
16 #define OHOS_CLOUD_FILE_SERVICE_GALLERY_DOWNLOAD_FILE_STAT_H
17 #include <string>
18 #include <vector>
19 
20 #include "nocopyable.h"
21 #include "hisysevent.h"
22 
23 namespace OHOS {
24 namespace FileManagement {
25 namespace CloudFile {
26 #define GALLERY_DOWNLOAD_ERROR_STAT_LEN 10
27 #define GALLERY_DOWNLOAD_IMAGE_SIZE_LEN 6
28 #define GALLERY_DOWNLOAD_IMAGE_SPEED_LEN 16
29 #define GALLERY_DOWNLOAD_VIDEO_SIZE_LEN 7
30 #define GALLERY_DOWNLOAD_VIDEO_SPEED_LEN 16
31 struct DownloadFileStatInfo {
32 public:
DownloadFileStatInfoDownloadFileStatInfo33     DownloadFileStatInfo() : downloadFileError(GALLERY_DOWNLOAD_ERROR_STAT_LEN),
34                              imageSize(GALLERY_DOWNLOAD_IMAGE_SIZE_LEN),
35                              imageDownloadSpeed(GALLERY_DOWNLOAD_IMAGE_SPEED_LEN),
36                              videoSize(GALLERY_DOWNLOAD_VIDEO_SIZE_LEN),
37                              videoDownloadSpeed(GALLERY_DOWNLOAD_VIDEO_SPEED_LEN)
38     {
39     }
40     ~DownloadFileStatInfo() = default;
41 
42     std::string bundleName;
43     std::vector<uint64_t> downloadFileError;
44     std::vector<uint64_t> imageSize;
45     std::vector<uint64_t> imageDownloadSpeed;
46     std::vector<uint64_t> videoSize;
47     std::vector<uint64_t> videoDownloadSpeed;
48 };
49 
50 class GalleryDownloadFileStat : public NoCopyable {
51 public:
52     static GalleryDownloadFileStat &GetInstance();
53     GalleryDownloadFileStat(const GalleryDownloadFileStat&) = delete;
54     GalleryDownloadFileStat& operator=(const GalleryDownloadFileStat&) = delete;
55 
56     void UpdateDownloadStat(uint32_t mediaType, uint64_t size, uint64_t duration);
57     void OutputToFile();
58     void Report();
59 private:
60     GalleryDownloadFileStat();
61     ~GalleryDownloadFileStat() = default;
62     void ClearDownloadFileStat();
63     void UpdateDownloadSpeedStat(uint32_t mediaType, uint64_t size, uint64_t duration);
64     void UpdateDownloadSizeStat(uint32_t mediaType, uint64_t size, uint64_t duration);
65     DownloadFileStatInfo ReadVecFromLocal();
66 
67     DownloadFileStatInfo stat_;
68 };
69 } // CloudFile
70 } // FileManagement
71 } // OHOS
72 #endif // OHOS_CLOUD_FILE_SERVICE_GALLERY_DOWNLOAD_FILE_STAT_H