• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "device_security_level_loader.h"
17 
18 #include <future>
19 #include <type_traits>
20 
21 #include "hilog/log_cpp.h"
22 #include "if_system_ability_manager.h"
23 #include "isystem_ability_load_callback.h"
24 #include "iservice_registry.h"
25 
26 #include "device_security_level_defines.h"
27 #include "idevice_security_level.h"
28 
29 namespace OHOS {
30 namespace Security {
31 namespace DeviceSecurityLevel {
32 using namespace OHOS::HiviewDFX;
33 
LoadDslmService()34 sptr<IRemoteObject> DeviceSecurityLevelLoader::LoadDslmService()
35 {
36     auto registry = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
37     if (registry == nullptr) {
38         HiLog::Error(LABEL, "GetDeviceSecurityInfo get registry error.");
39         return {};
40     }
41     auto object = registry->GetSystemAbility(DEVICE_SECURITY_LEVEL_MANAGER_SA_ID);
42     if (object != nullptr) {
43         return object;
44     }
45 
46     sptr<LoadCallback> callback = new (std::nothrow) LoadCallback();
47     int32_t result = registry->LoadSystemAbility(DEVICE_SECURITY_LEVEL_MANAGER_SA_ID, callback);
48     if (result != ERR_OK) {
49         HiLog::Error(LABEL, "GetDeviceSecurityInfo LoadSystemAbility error.");
50         return {};
51     }
52     return callback->Promise();
53 }
54 
OnLoadSystemAbilitySuccess(int32_t sid,const sptr<IRemoteObject> & object)55 void DeviceSecurityLevelLoader::LoadCallback::OnLoadSystemAbilitySuccess(int32_t sid, const sptr<IRemoteObject> &object)
56 {
57     HiLog::Info(LABEL, "OnLoadSystemAbilitySuccess = %{public}d.", sid);
58     promise_.set_value(object);
59 }
60 
OnLoadSystemAbilityFail(int32_t sid)61 void DeviceSecurityLevelLoader::LoadCallback::OnLoadSystemAbilityFail(int32_t sid)
62 {
63     HiLog::Error(LABEL, "OnLoadSystemAbilityFail = %{public}d.", sid);
64 }
65 
Promise()66 sptr<IRemoteObject> DeviceSecurityLevelLoader::LoadCallback::Promise()
67 {
68     return promise_.get_future().get();
69 }
70 } // namespace DeviceSecurityLevel
71 } // namespace Security
72 } // namespace OHOS
73