1 /* 2 * Copyright (c) 2024-2025 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 FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_SIGN_DATA_CACHE_MGR 17 #define FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_SIGN_DATA_CACHE_MGR 18 19 #include <mutex> 20 #include <optional> 21 #include <string> 22 #include <unordered_map> 23 24 #include "aot/aot_args.h" 25 #include "bundle_mgr_service.h" 26 #include "common_event_manager.h" 27 #include "common_event_support.h" 28 #include "inner_bundle_info.h" 29 #include "iservice_registry.h" 30 #include "nocopyable.h" 31 32 namespace OHOS { 33 namespace AppExecFwk { 34 class AOTSignDataCacheMgr final { 35 public: 36 static AOTSignDataCacheMgr& GetInstance(); 37 void RegisterScreenUnlockListener(); 38 void AddSignDataForSysComp(const std::string &anFileName, const std::vector<uint8_t> &signData, 39 const ErrCode ret); 40 void AddSignDataForHap(const AOTArgs &aotArgs, const uint32_t versionCode, 41 const std::vector<uint8_t> &signData, const ErrCode ret); 42 private: 43 AOTSignDataCacheMgr() = default; 44 ~AOTSignDataCacheMgr() = default; 45 DISALLOW_COPY_AND_MOVE(AOTSignDataCacheMgr); 46 47 bool RegisterScreenUnlockEvent(); 48 void UnregisterScreenUnlockEvent(); 49 void HandleUnlockEvent(); 50 bool EnforceCodeSign(); 51 bool EnforceCodeSignForSysComp(); 52 bool EnforceCodeSignForHap(); 53 class UnlockEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber { 54 public: UnlockEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo & info)55 UnlockEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) {} 56 ~UnlockEventSubscriber() override = default; 57 void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &event) override; 58 }; 59 private: 60 struct HapSignData { 61 uint32_t versionCode = 0; 62 std::string bundleName; 63 std::string moduleName; 64 std::vector<uint8_t> signData; 65 }; 66 std::atomic<bool> isLocked_ { true }; 67 mutable std::mutex mutex_; 68 std::shared_ptr<UnlockEventSubscriber> unlockEventSubscriber_; 69 std::vector<HapSignData> hapSignDataVector_; 70 // key: anFileName, value: signData 71 std::unordered_map<std::string, std::vector<uint8_t>> sysCompSignDataMap_; 72 }; 73 } // namespace AppExecFwk 74 } // namespace OHOS 75 #endif // FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_SIGN_DATA_CACHE_MGR 76