• 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 #ifndef LOCATOR_EVENT_MANAGER_H
17 #define LOCATOR_EVENT_MANAGER_H
18 
19 #include <list>
20 #include <map>
21 #include <singleton.h>
22 #include <string>
23 
24 #include "event_handler.h"
25 #include "event_runner.h"
26 
27 #include "request.h"
28 
29 namespace OHOS {
30 namespace Location {
31 constexpr uint32_t EVENT_SEND_HIVIEW_MESSAGE = 0x0001;
32 constexpr uint32_t EVENT_SEND_DAILY_REPORT = 0x0002;
33 
34 constexpr uint32_t DAILY_INTERVAL = 24 * 60 * 60 * 1000;
35 constexpr uint32_t COUNT_MAX = 500;
36 constexpr uint32_t INVALID_VALUE = 0xFFFFFFFF;
37 constexpr uint32_t DFT_APP_MAX_SIZE = 10;
38 constexpr uint32_t DFT_TOP_REQUEST_UPLOAD_MAX_SIZE = 5;
39 
40 struct AppRequestCount {
41     std::string packageName;
42     std::vector<int> requestType;
43     std::vector<int> count;
44 };
45 
46 class DftEvent {
47 public:
48     void PutInt(const std::string& name, int value);
49     int GetInt(const std::string& name);
50 private:
51     std::map<std::string, int> intValues_;
52 };
53 
54 class DftHandler : public AppExecFwk::EventHandler {
55 public:
56     explicit DftHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner);
57     ~DftHandler() override;
58     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
59 };
60 
61 class LocatorDftManager : DelayedSingleton<LocatorDftManager> {
62 public:
63     LocatorDftManager();
64     ~LocatorDftManager();
65     void Init();
66     void IpcCallingErr(int error);
67     void LocationSessionStart(std::shared_ptr<Request> request);
68     void DistributionSessionStart();
69     void DistributionDisconnect();
70     void SendDistributionDailyCount();
71     void SendRequestDailyCount();
72 private:
73     std::shared_ptr<AppRequestCount> GetTopRequest();
74 
75     std::shared_ptr<DftHandler> handler_;
76     std::list<std::shared_ptr<AppRequestCount>> appRequests_;
77     uint32_t distributeSissionCnt_;
78     uint32_t distributeDisconnectCnt_;
79 };
80 } // namespace Location
81 } // namespace OHOS
82 #endif // LOCATOR_EVENT_MANAGER_H
83