1 /*
2  * Copyright (c) 2023 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 #include "system_dialog_connect_stb.h"
16 #include "ability_connect_callback_interface.h"
17 #include "ability_manager_client.h"
18 #include "ans_log_wrapper.h"
19 #include "ans_inner_errors.h"
20 #include "common_event_manager.h"
21 #include "advanced_notification_service.h"
22 #include "notification_bundle_option.h"
23 
24 constexpr int32_t SIGNAL_NUM = 3;
25 
26 namespace OHOS {
27 namespace Notification {
28 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)29 void SystemDialogConnectStb::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
30     const sptr<IRemoteObject> &remoteObject, int32_t resultCode)
31 {
32     ANS_LOGI("on ability connected");
33     MessageParcel data;
34     MessageParcel reply;
35     MessageOption option;
36     data.WriteInt32(SIGNAL_NUM);
37     data.WriteString16(u"bundleName");
38     data.WriteString16(u"com.ohos.notificationdialog");
39     data.WriteString16(u"abilityName");
40     data.WriteString16(u"EnableNotificationDialog");
41     data.WriteString16(u"parameters");
42     data.WriteString16(Str8ToStr16(commandStr_));
43 
44     int32_t errCode = remoteObject->SendRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
45     ANS_LOGI("AbilityConnectionWrapperProxy::OnAbilityConnectDone result %{public}d", errCode);
46     if (errCode != ERR_OK) {
47         ANS_LOGE("send Request to SytemDialog fail");
48         if (commandStr_.empty() || !nlohmann::json::accept(commandStr_)) {
49             ANS_LOGE("Invalid JSON");
50             return;
51         }
52         nlohmann::json root = nlohmann::json::parse(commandStr_);
53         if (root.is_null() or !root.is_object()) {
54             ANS_LOGE("Invalid JSON object");
55             return;
56         }
57         if (!root.contains("bundleName") || !root.contains("bundleUid")) {
58             ANS_LOGE("not found jsonKey from");
59             return;
60         }
61         if (!root["bundleName"].is_string() || !root["bundleUid"].is_number_integer()) {
62             ANS_LOGE("value type is not right");
63             return;
64         }
65         std::string bundleName = root["bundleName"];
66         int32_t bundleUid = root["bundleUid"];
67         sptr<NotificationBundleOption> bundleOption = new (std::nothrow) NotificationBundleOption(
68             bundleName, bundleUid);
69         if (bundleOption == nullptr) {
70             ANS_LOGE("bundleOption inin fail");
71             return;
72         }
73         AdvancedNotificationService::GetInstance()->RemoveEnableNotificationDialog(bundleOption);
74     }
75 }
76 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)77 void SystemDialogConnectStb::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element,
78     int32_t resultCode)
79 {
80     ANS_LOGI("on ability disconnected");
81 }
82 }
83 }