1 /*
2  * Copyright (c) 2022-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 "dscreen_sink_load_callback.h"
17 
18 #include "dscreen_constants.h"
19 #include "dscreen_errcode.h"
20 #include "dscreen_hisysevent.h"
21 #include "dscreen_log.h"
22 #include "dscreen_sink_handler.h"
23 
24 namespace OHOS { class IRemoteObject; }
25 namespace OHOS {
26 namespace DistributedHardware {
DScreenSinkLoadCallback(const std::string & params)27 DScreenSinkLoadCallback::DScreenSinkLoadCallback(
28     const std::string &params) : params_(params) {}
29 
OnLoadSystemAbilitySuccess(int32_t systemAbilityId,const sptr<IRemoteObject> & remoteObject)30 void DScreenSinkLoadCallback::OnLoadSystemAbilitySuccess(
31     int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject)
32 {
33     DHLOGI("load screen SA success, systemAbilityId:%{public}" PRId32 ", remoteObject result:%{public}s",
34         systemAbilityId, (remoteObject != nullptr) ? "true" : "false");
35     if (systemAbilityId != DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID) {
36         DHLOGE("start systemabilityId is not sinkSAId!");
37         return;
38     }
39     if (remoteObject == nullptr) {
40         DHLOGE("remoteObject is nullptr");
41         return;
42     }
43 
44     DScreenSinkHandler::GetInstance().FinishStartSA(params_, remoteObject);
45 }
46 
OnLoadSystemAbilityFail(int32_t systemAbilityId)47 void DScreenSinkLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
48 {
49     DHLOGE("load screen SA failed, systemAbilityId: %{public}" PRId32, systemAbilityId);
50     ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, systemAbilityId,
51         "dscreen sink OnLoadSystemAbilityFail.");
52 }
53 }  // namespace DistributedHardware
54 }  // namespace OHOS
55