• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "distributed_operation_connection.h"
17 
18 #include "ans_log_wrapper.h"
19 #include "ability_manager_helper.h"
20 
21 namespace OHOS {
22 namespace Notification {
23 
24 constexpr int32_t EVENT_CALL_NOTIFY = 1;
25 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)26 void DistributedOperationConnection::OnAbilityConnectDone(
27     const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
28 {
29     ANS_LOGI("Operation on connection %{public}s, %{public}s, %{public}s", element.GetAbilityName().c_str(),
30         element.GetBundleName().c_str(), eventId_.c_str());
31     if (remoteObject == nullptr) {
32         AbilityManagerHelper::GetInstance().DisconnectServiceAbility(eventId_, element);
33         return;
34     }
35     do {
36         MessageParcel data;
37         if (!data.WriteString16(to_utf16("com.ohos.notification_service.sendReply"))) {
38             ANS_LOGE("OnAbilityConnectDone fail:: write inputKey failed");
39             break;
40         }
41         if (!data.WriteString16(to_utf16(inputKey_))) {
42             ANS_LOGE("OnAbilityConnectDone fail:: write inputKey failed");
43             break;
44         }
45         if (!data.WriteString16(to_utf16(userInput_))) {
46             ANS_LOGE("OnAbilityConnectDone fail:: write userInput failed");
47             break;
48         }
49         MessageParcel reply;
50         MessageOption option;
51         int32_t result = remoteObject->SendRequest(EVENT_CALL_NOTIFY, data, reply, option);
52         ANS_LOGI("Send call notify %{public}s %{public}s %{public}d", eventId_.c_str(), inputKey_.c_str(), result);
53     } while (0);
54     AbilityManagerHelper::GetInstance().DisconnectServiceAbility(eventId_, element);
55 }
56 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int resultCode)57 void DistributedOperationConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
58 {
59     ANS_LOGI("Operation disconnection %{public}s, %{public}s, %{public}s", element.GetAbilityName().c_str(),
60         element.GetBundleName().c_str(), eventId_.c_str());
61 }
62 }
63 }
64