• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "locator_event_manager.h"
17 
18 #include "hisysevent.h"
19 
20 #include "common_utils.h"
21 #include "constant_definition.h"
22 #include "location_log.h"
23 
24 namespace OHOS {
25 namespace Location {
PutInt(const std::string & name,int value)26 void DftEvent::PutInt(const std::string& name, int value)
27 {
28     intValues_.emplace(name, value);
29 }
30 
GetInt(const std::string & name)31 int DftEvent::GetInt(const std::string& name)
32 {
33     auto it = intValues_.find(name);
34     if (it == intValues_.end()) {
35         return 0;
36     }
37     return it->second;
38 }
39 
DftHandler(const std::shared_ptr<AppExecFwk::EventRunner> & runner)40 DftHandler::DftHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner) : EventHandler(runner) {}
41 
~DftHandler()42 DftHandler::~DftHandler() {}
43 
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)44 void DftHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
45 {
46 }
47 
LocatorDftManager()48 LocatorDftManager::LocatorDftManager()
49 {
50     distributeSissionCnt_ = 0;
51     distributeDisconnectCnt_ = 0;
52 
53     handler_ = std::make_shared<DftHandler>(AppExecFwk::EventRunner::Create(true));
54 }
55 
~LocatorDftManager()56 LocatorDftManager::~LocatorDftManager() {}
57 
Init()58 void LocatorDftManager::Init()
59 {
60     if (handler_ != nullptr) {
61         handler_->SendHighPriorityEvent(EVENT_SEND_DAILY_REPORT, 0, DAILY_INTERVAL);
62     }
63 }
64 
IpcCallingErr(int error)65 void LocatorDftManager::IpcCallingErr(int error)
66 {
67 }
68 
LocationSessionStart(std::shared_ptr<Request> request)69 void LocatorDftManager::LocationSessionStart(std::shared_ptr<Request> request)
70 {
71     std::shared_ptr<AppRequestCount> requestCount = nullptr;
72     if (request == nullptr) {
73         return;
74     }
75     for (auto appRequest : appRequests_) {
76         if (appRequest->packageName.compare(request->GetPackageName()) == 0) {
77             requestCount = appRequest;
78             break;
79         }
80     }
81     if (requestCount == nullptr) {
82         requestCount = std::make_shared<AppRequestCount>();
83         requestCount->packageName = request->GetPackageName();
84         requestCount->requestType = std::vector<int>(DFT_APP_MAX_SIZE);
85         requestCount->count = std::vector<int>(DFT_APP_MAX_SIZE);
86         appRequests_.push_back(requestCount);
87     }
88 
89     unsigned index = INVALID_VALUE;
90     if (request->GetRequestConfig() == nullptr) {
91         return;
92     }
93     int scenario = request->GetRequestConfig()->GetScenario();
94     int priority = request->GetRequestConfig()->GetPriority();
95     for (unsigned i = 0; i < requestCount->requestType.size(); i++) {
96         if (requestCount->requestType.at(i) == scenario || requestCount->requestType.at(i) == priority) {
97             index = i;
98             break;
99         }
100     }
101     if (index != INVALID_VALUE) {
102         requestCount->count.at(index)++;
103     } else {
104         if (scenario != SCENE_UNSET) {
105             requestCount->requestType.at(0) = scenario;
106         } else if (priority != PRIORITY_UNSET) {
107             requestCount->requestType.at(0) = priority;
108         } else {
109             return;
110         }
111         requestCount->count.at(0)++;
112     }
113 }
114 
DistributionDisconnect()115 void LocatorDftManager::DistributionDisconnect()
116 {
117     if (distributeDisconnectCnt_ < COUNT_MAX) {
118         distributeDisconnectCnt_++;
119     }
120 }
121 
DistributionSessionStart()122 void LocatorDftManager::DistributionSessionStart()
123 {
124     if (distributeSissionCnt_ < COUNT_MAX) {
125         distributeSissionCnt_++;
126     }
127 }
128 
SendDistributionDailyCount()129 void LocatorDftManager::SendDistributionDailyCount()
130 {
131 }
132 
SendRequestDailyCount()133 void LocatorDftManager::SendRequestDailyCount()
134 {
135 }
136 
GetTopRequest()137 std::shared_ptr<AppRequestCount> LocatorDftManager::GetTopRequest()
138 {
139     std::shared_ptr<AppRequestCount> topRequest;
140     int topSum = 0;
141     for (auto appRequest : appRequests_) {
142         int sum = 0;
143         for (unsigned i = 0; i < appRequest->count.size(); i++) {
144             sum = sum + appRequest->count.at(i);
145         }
146         if (sum > topSum) {
147             topSum = sum;
148             topRequest = appRequest;
149         }
150     }
151     return topRequest;
152 }
153 } // namespace Location
154 } // namespace OHOS