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 "rpc_callback_imp.h"
17 #include "sam_log.h"
18 #include "system_ability_manager.h"
19 #include "tools.h"
20 
21 namespace OHOS {
GetSystemAbilityFromRemote(int32_t systemAbilityId)22 sptr<IRemoteObject> RpcCallbackImp::GetSystemAbilityFromRemote(int32_t systemAbilityId)
23 {
24     return SystemAbilityManager::GetInstance()->GetSystemAbilityFromRemote(systemAbilityId);
25 }
26 
IsDistributedSystemAbility(int32_t systemAbilityId)27 bool RpcCallbackImp::IsDistributedSystemAbility(int32_t systemAbilityId)
28 {
29     return SystemAbilityManager::GetInstance()->IsDistributedSystemAbility(systemAbilityId);
30 }
31 
LoadSystemAbilityFromRemote(const std::string & srcNetworkId,int32_t systemAbilityId)32 bool RpcCallbackImp::LoadSystemAbilityFromRemote(const std::string& srcNetworkId, int32_t systemAbilityId)
33 {
34     HILOGI("LoadSystemAbilityFromRemote! deviceId : %{public}s, said : %{public}d",
35         AnonymizeDeviceId(srcNetworkId).c_str(), systemAbilityId);
36     sptr<LoadCallbackImp> loadCallback = new LoadCallbackImp(srcNetworkId);
37     return SystemAbilityManager::GetInstance()->LoadSystemAbilityFromRpc(srcNetworkId,
38         systemAbilityId, loadCallback);
39 }
40 
OnLoadSystemAbilitySuccess(int32_t systemAbilityId,const sptr<IRemoteObject> & remoteObject)41 void RpcCallbackImp::LoadCallbackImp::OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
42     const sptr<IRemoteObject>& remoteObject)
43 {
44     HILOGI("LoadCallbackImp OnLoadSystemAbilitySuccess! deviceId : %{public}s, said : %{public}d",
45         AnonymizeDeviceId(srcNetWorkId_).c_str(), systemAbilityId);
46     SystemAbilityManager::GetInstance()->NotifyRpcLoadCompleted(srcNetWorkId_, systemAbilityId, remoteObject);
47 }
48 
OnLoadSystemAbilityFail(int32_t systemAbilityId)49 void RpcCallbackImp::LoadCallbackImp::OnLoadSystemAbilityFail(int32_t systemAbilityId)
50 {
51     HILOGW("LoadCallbackImp OnLoadSystemAbilityFail! deviceId : %{public}s, said : %{public}d",
52         AnonymizeDeviceId(srcNetWorkId_).c_str(), systemAbilityId);
53     SystemAbilityManager::GetInstance()->NotifyRpcLoadCompleted(srcNetWorkId_, systemAbilityId, nullptr);
54 }
55 }
56