• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "iservice_registry.h"
21 #include "system_ability_definition.h"
22 
23 namespace OHOS {
24 namespace CameraStandard {
25 namespace CameraApiVersion {
26 #define API_DEFAULT_VERSION 1000
27 static uint32_t g_apiCompatibleVersion = API_DEFAULT_VERSION;
28 static std::mutex g_apiCompatibleVersionMutex;
29 
GetApiVersion()30 uint32_t GetApiVersion()
31 {
32     std::lock_guard<std::mutex> lock(g_apiCompatibleVersionMutex);
33     CHECK_ERROR_RETURN_RET(g_apiCompatibleVersion != API_DEFAULT_VERSION, g_apiCompatibleVersion);
34     OHOS::sptr<OHOS::ISystemAbilityManager> systemAbilityManager =
35         OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
36     OHOS::sptr<OHOS::IRemoteObject> remoteObject =
37         systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
38     sptr<AppExecFwk::IBundleMgr> iBundleMgr = OHOS::iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
39     CHECK_ERROR_RETURN_RET_LOG(iBundleMgr == nullptr, g_apiCompatibleVersion,
40         "GetApiCompatibleVersion iBundleMgr is null");
41     AppExecFwk::BundleInfo bundleInfo;
42     if (iBundleMgr->GetBundleInfoForSelf(0, bundleInfo) == ERR_OK) {
43         g_apiCompatibleVersion = bundleInfo.targetVersion % API_DEFAULT_VERSION;
44         MEDIA_INFO_LOG("targetVersion: [%{public}u], apiCompatibleVersion: [%{public}u]", bundleInfo.targetVersion,
45             g_apiCompatibleVersion);
46     }
47     return g_apiCompatibleVersion;
48 }
49 } // namespace CameraApiVersion
50 } // namespace CameraStandard
51 } // namespace OHOS
52