1 /* 2 * Copyright (c) 2024-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 16 #include "hks_upgrade.h" 17 18 #include "hks_template.h" 19 #include "hks_type_enum.h" 20 #include "hks_upgrade_lock.h" 21 #include "rwlock.h" 22 23 #ifdef HUKS_ENABLE_UPGRADE_KEY_STORAGE_SECURE_LEVEL 24 #include "hks_file_transfer.h" 25 #endif 26 27 namespace OHOS { 28 namespace Security { 29 namespace Hks { HksUpgradeOnPowerOn(void)30void HksUpgradeOnPowerOn(void) 31 { 32 #ifdef HUKS_ENABLE_UPGRADE_KEY_STORAGE_SECURE_LEVEL 33 HKS_IF_NOT_SUCC_LOGE(HksUpgradeFileTransferOnPowerOn(), "HksUpgradeFileTransfer on power on failed!") 34 #endif 35 } 36 HksUpgradeOnUserUnlock(uint32_t userId)37void HksUpgradeOnUserUnlock(uint32_t userId) 38 { 39 HKS_LOG_I("enter HksUpgradeOnUserUnlock."); 40 #ifdef HUKS_ENABLE_UPGRADE_KEY_STORAGE_SECURE_LEVEL 41 g_upgradeOrRequestLock.UnLockRead(); 42 43 // Since current thread have owned read lock, the power on upgrade have ended at earlier time, 44 // waiting for notify is not necessary. 45 { 46 HKS_LOG_I("acquiring for write lock..."); 47 OHOS::Utils::UniqueWriteGuard<OHOS::Utils::RWLock> writeGuard(g_upgradeOrRequestLock); 48 int ret = HksUpgradeFileTransferOnUserUnlock(userId); 49 if (ret != HKS_SUCCESS) { 50 HKS_LOG_E("HksUpgradeFileTransferOnUserUnlock failed! %" LOG_PUBLIC "d", ret); 51 } else { 52 HKS_LOG_I("HksUpgradeFileTransferOnUserUnlock ok!"); 53 } 54 } 55 56 g_upgradeOrRequestLock.LockRead(); 57 #endif 58 HKS_LOG_I("leave HksUpgradeOnUserUnlock."); 59 } 60 } 61 } 62 } 63