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 "camera_rotation_api_utils.h" 17 18 #include "bundle_mgr_interface.h" 19 #include "camera_log.h" 20 #include "ipc_skeleton.h" 21 #include "iservice_registry.h" 22 #include "parameters.h" 23 #include "system_ability_definition.h" 24 #include "tokenid_kit.h" 25 26 namespace OHOS { 27 namespace CameraStandard { 28 namespace CameraApiVersion { 29 #define API_DEFAULT_VERSION 1000 30 static uint32_t g_apiCompatibleVersion = API_DEFAULT_VERSION; 31 static std::mutex g_apiCompatibleVersionMutex; 32 GetApiVersion()33uint32_t GetApiVersion() 34 { 35 std::lock_guard<std::mutex> lock(g_apiCompatibleVersionMutex); 36 if (g_apiCompatibleVersion != API_DEFAULT_VERSION) { 37 return g_apiCompatibleVersion; 38 } 39 OHOS::sptr<OHOS::ISystemAbilityManager> systemAbilityManager = 40 OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 41 OHOS::sptr<OHOS::IRemoteObject> remoteObject = 42 systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); 43 sptr<AppExecFwk::IBundleMgr> iBundleMgr = OHOS::iface_cast<AppExecFwk::IBundleMgr>(remoteObject); 44 if (iBundleMgr == nullptr) { 45 MEDIA_ERR_LOG("GetApiCompatibleVersion iBundleMgr is null"); 46 return g_apiCompatibleVersion; 47 } 48 AppExecFwk::BundleInfo bundleInfo; 49 if (iBundleMgr->GetBundleInfoForSelf(0, bundleInfo) == ERR_OK) { 50 g_apiCompatibleVersion = bundleInfo.targetVersion % API_DEFAULT_VERSION; 51 MEDIA_ERR_LOG("targetVersion: [%{public}u], apiCompatibleVersion: [%{public}u]", bundleInfo.targetVersion, 52 g_apiCompatibleVersion); 53 } else { 54 MEDIA_ERR_LOG("Call for GetApiCompatibleVersion failed"); 55 } 56 return g_apiCompatibleVersion; 57 } 58 } // namespace CameraApiVersion 59 } // namespace CameraStandard 60 } // namespace OHOS 61