• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "notification_analytics_util.h"
24 
25 constexpr int32_t SIGNAL_NUM = 3;
26 
27 namespace OHOS {
28 namespace Notification {
29 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)30 void SystemDialogConnectStb::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
31     const sptr<IRemoteObject> &remoteObject, int32_t resultCode)
32 {
33     ANS_LOGI("on ability connected");
34     MessageParcel data;
35     MessageParcel reply;
36     MessageOption option;
37     data.WriteInt32(SIGNAL_NUM);
38     data.WriteString16(u"bundleName");
39     data.WriteString16(u"com.ohos.notificationdialog");
40     data.WriteString16(u"abilityName");
41     data.WriteString16(u"EnableNotificationDialog");
42     data.WriteString16(u"parameters");
43     data.WriteString16(Str8ToStr16(commandStr_));
44 
45     int32_t errCode = remoteObject->SendRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
46     ANS_LOGI("AbilityConnectionWrapperProxy::OnAbilityConnectDone result %{public}d", errCode);
47     if (errCode != ERR_OK) {
48         ANS_LOGE("send Request to SytemDialog fail");
49         RemoveEnableNotificationDialog();
50     }
51 }
52 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)53 void SystemDialogConnectStb::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element,
54     int32_t resultCode)
55 {
56     ANS_LOGI("on ability disconnected");
57     RemoveEnableNotificationDialog();
58 }
59 
RemoveEnableNotificationDialog()60 void SystemDialogConnectStb::RemoveEnableNotificationDialog()
61 {
62     ANS_LOGI("RemoveEnableNotificationDialog called.");
63     HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_23, EventBranchId::BRANCH_0);
64     if (commandStr_.empty() || !nlohmann::json::accept(commandStr_)) {
65         ANS_LOGE("Invalid JSON");
66         NotificationAnalyticsUtil::ReportModifyEvent(message);
67         return;
68     }
69     nlohmann::json root = nlohmann::json::parse(commandStr_);
70     if (root.is_null() or !root.is_object()) {
71         ANS_LOGE("Invalid JSON object");
72         NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_1));
73         return;
74     }
75     if (!root.contains("bundleName") || !root.contains("bundleUid")) {
76         ANS_LOGE("not found jsonKey from");
77         NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_2));
78         return;
79     }
80     if (!root["bundleName"].is_string() || !root["bundleUid"].is_number_integer()) {
81         ANS_LOGE("value type is not right");
82         NotificationAnalyticsUtil::ReportModifyEvent(message.BranchId(BRANCH_3));
83         return;
84     }
85     std::string bundleName = root["bundleName"];
86     int32_t bundleUid = root["bundleUid"];
87     sptr<NotificationBundleOption> bundleOption = new (std::nothrow) NotificationBundleOption(
88         bundleName, bundleUid);
89     if (bundleOption == nullptr) {
90         ANS_LOGE("bundleOption inin fail");
91         return;
92     }
93     AdvancedNotificationService::GetInstance()->RemoveEnableNotificationDialog(bundleOption);
94 }
95 
96 }
97 }