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