• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 "distributed_operation_helper.h"
17 
18 #ifdef SCREENLOCK_MGR_ENABLE
19 #include "screenlock_common.h"
20 #endif
21 #include "in_process_call_wrapper.h"
22 #include "distributed_service.h"
23 #include "analytics_util.h"
24 
25 namespace OHOS {
26 namespace Notification {
27 
28 #ifdef SCREENLOCK_MGR_ENABLE
UnlockScreenCallback(const std::string & eventId)29 UnlockScreenCallback::UnlockScreenCallback(const std::string& eventId) : eventId_(eventId) {}
30 
~UnlockScreenCallback()31 UnlockScreenCallback::~UnlockScreenCallback() {}
32 
OnCallBack(int32_t screenLockResult)33 void UnlockScreenCallback::OnCallBack(int32_t screenLockResult)
34 {
35     ANS_LOGI("Unlock Screen result: %{public}d", screenLockResult);
36     if (screenLockResult == ScreenLock::ScreenChange::SCREEN_SUCC) {
37         OperationService::GetInstance().TriggerOperation(eventId_);
38     } else {
39         AnalyticsUtil::GetInstance().SendEventReport(0, -1, "unlock screen failed");
40         AnalyticsUtil::GetInstance().SendHaReport(MODIFY_ERROR_EVENT_CODE, -1, BRANCH7_ID,
41             "unlock screen failed");
42     }
43 }
44 #endif
45 
GetInstance()46 OperationService& OperationService::GetInstance()
47 {
48     static OperationService operationService;
49     return operationService;
50 }
51 
AddOperation(OperationInfo operationInfo)52 void OperationService::AddOperation(OperationInfo operationInfo)
53 {
54     std::lock_guard<ffrt::mutex> lock(operationMutex_);
55     auto iter = operationInfoMaps_.find(operationInfo.eventId);
56     if (iter != operationInfoMaps_.end()) {
57         ANS_LOGW("OperationService operation exist %{public}s.", operationInfo.eventId.c_str());
58         return;
59     }
60     ANS_LOGI("OperationService add operation %{public}s %{public}d.",
61         operationInfo.eventId.c_str(), operationInfo.type);
62     operationInfoMaps_[operationInfo.eventId] = operationInfo;
63 }
64 
HandleScreenEvent()65 void OperationService::HandleScreenEvent()
66 {
67     std::lock_guard<ffrt::mutex> lock(operationMutex_);
68     for (auto iter = operationInfoMaps_.begin(); iter != operationInfoMaps_.end();) {
69         ANS_LOGI("OperationService erase operation %{public}s %{public}d.",
70             iter->second.eventId.c_str(), iter->second.type);
71         iter = operationInfoMaps_.erase(iter);
72     }
73 }
74 
TriggerOperation(std::string eventId)75 void OperationService::TriggerOperation(std::string eventId)
76 {
77     std::lock_guard<ffrt::mutex> lock(operationMutex_);
78     auto iter = operationInfoMaps_.find(eventId);
79     if (iter == operationInfoMaps_.end()) {
80         ANS_LOGW("Operation not exist %{public}s.", eventId.c_str());
81         return;
82     }
83     if (iter->second.type == OperationType::DISTRIBUTE_OPERATION_JUMP) {
84         auto ret = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->StartAbility(iter->second.want));
85         std::string errorReason = "pull up success";
86         if (ret == ERR_OK) {
87             AnalyticsUtil::GetInstance().OperationalReporting(iter->second.deviceTypeId,
88                 HaOperationType::COLLABORATE_JUMP, NotificationConstant::SlotType::LIVE_VIEW);
89             AnalyticsUtil::GetInstance().SendHaReport(MODIFY_ERROR_EVENT_CODE,
90                 NotificationConstant::SlotType::LIVE_VIEW, BRANCH3_ID, errorReason, ANS_CUSTOMIZE_CODE);
91         } else {
92             AnalyticsUtil::GetInstance().SendEventReport(0, ret, "pull up failed");
93         }
94         AnalyticsUtil::GetInstance().SendHaReport(MODIFY_ERROR_EVENT_CODE, ret, BRANCH8_ID, errorReason);
95         operationInfoMaps_.erase(iter);
96         ANS_LOGI("StartAbility result:%{public}s %{public}d", eventId.c_str(), ret);
97         return;
98     }
99 }
100 
TimeOutOperation(std::string eventId)101 void OperationService::TimeOutOperation(std::string eventId)
102 {
103     std::lock_guard<ffrt::mutex> lock(operationMutex_);
104     auto iter = operationInfoMaps_.find(eventId);
105     if (iter == operationInfoMaps_.end()) {
106         ANS_LOGI("Operation not exist %{public}s.", eventId.c_str());
107         return;
108     }
109     ANS_LOGI("OperationService timeout operation %{public}s %{public}d.",
110         iter->second.eventId.c_str(), iter->second.type);
111     operationInfoMaps_.erase(iter);
112 }
113 }
114 }
115