1 /* 2 * Copyright (c) 2021 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 FRAMEWORKS_BOOTANIMATION_INCLUDE_UTIL_H 17 #define FRAMEWORKS_BOOTANIMATION_INCLUDE_UTIL_H 18 19 #include "contrib/minizip/unzip.h" 20 #include "contrib/minizip/zip.h" 21 #include "zlib.h" 22 #include "log.h" 23 24 #include <cstdint> 25 #include <dirent.h> 26 #include <functional> 27 #include <unistd.h> 28 #include <sys/stat.h> 29 #include <sys/types.h> 30 31 #include <if_system_ability_manager.h> 32 #include <ipc_skeleton.h> 33 #include <iservice_registry.h> 34 #include <iremote_object.h> 35 #include <include/core/SkImage.h> 36 #include <include/core/SkRefCnt.h> 37 #include <platform/ohos/rs_irender_service.h> 38 #include <system_ability_definition.h> 39 40 namespace OHOS { 41 static const int READ_SIZE = 8192; 42 static const int MAX_FILE_NAME = 512; 43 static const int SLEEP_TIME_US = 30000; 44 static const std::string BOOT_PIC_CONFIGFILE = "config.json"; 45 using MemStruct = struct MemStruct { 46 public: 47 char* memBuffer = nullptr; 48 unsigned long bufsize = 0; 49 sk_sp<SkData> skData_ = nullptr; ~MemStructMemStruct50 ~MemStruct() 51 { 52 if (skData_ != nullptr) { 53 skData_ = nullptr; 54 } else { 55 free(memBuffer); 56 memBuffer = nullptr; 57 } 58 } setOwnerShipMemStruct59 void setOwnerShip(sk_sp<SkData>& skData) 60 { 61 skData_ = skData; 62 } SetBufferSizeMemStruct63 void SetBufferSize(unsigned long ibufsize) 64 { 65 if (ibufsize == 0) { 66 LOGE("MemStruct SetBuffer size is invalid!"); 67 return; 68 } 69 if (memBuffer == nullptr) { 70 bufsize = ibufsize + 1; 71 memBuffer = static_cast<char *>(malloc(bufsize + 1)); 72 } 73 } 74 }; 75 using ImageStruct = struct ImageStruct { 76 public: 77 std::string fileName = {}; 78 sk_sp<SkImage> imageData = nullptr; 79 MemStruct memPtr; ~ImageStructImageStruct80 ~ImageStruct() 81 { 82 imageData = nullptr; 83 } 84 }; 85 using BootAniConfig = struct BootAniConfig { 86 public: 87 int32_t frameRate = 30; 88 }; 89 using BootCustomConfig = struct BootCustomConfig { 90 public: 91 std::string custPicZipPath = {}; 92 std::string custSoundsPath = {}; 93 std::string custVideoPath = {}; 94 std::string custExtraVideoPath = {}; 95 int32_t rotateScreenId = -1; 96 int32_t rotateDegree = 0; 97 }; 98 using ImageStructVec = std::vector<std::shared_ptr<ImageStruct>>; 99 int64_t GetNowTime(); 100 void PostTask(std::function<void()> func, uint32_t delayTime = 0); 101 bool ReadZipFile(const std::string& srcFilePath, ImageStructVec& outBgImgVec, BootAniConfig& aniconfig); 102 void WaitRenderServiceInit(); 103 bool ReadCurrentFile(const unzFile zipfile, const std::string& filename, ImageStructVec& outBgImgVec, 104 BootAniConfig& aniconfig, unsigned long fileSize); 105 bool GenImageData(const std::string& filename, std::shared_ptr<ImageStruct> imagetruct, int32_t bufferlen, 106 ImageStructVec& outBgImgVec); 107 bool ReadJsonConfig(const char* filebuffer, int totalsize, BootAniConfig& aniconfig); 108 void SortZipFile(ImageStructVec& outBgImgVec); 109 bool IsFileExisted(const std::string& filePath); 110 bool ReadCustomBootConfig(const std::string& path, BootCustomConfig& aniconfig); 111 } // namespace OHOS 112 113 #endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_UTIL_H 114