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 "fusion_controller.h"
17 #include "system_ability_definition.h"
18 #include "common_utils.h"
19 #include "constant_definition.h"
20 #include "location_log.h"
21 #ifdef FEATURE_NETWORK_SUPPORT
22 #include "network_ability_proxy.h"
23 #endif
24
25 namespace OHOS {
26 namespace Location {
27 const uint32_t FUSION_DEFAULT_FLAG = 0;
28 const uint32_t FUSION_BASE_FLAG = 1;
29 const uint32_t REPORT_FUSED_LOCATION_FLAG = FUSION_BASE_FLAG;
30 const uint32_t QUICK_FIX_FLAG = FUSION_BASE_FLAG << 1;
31 #ifdef FEATURE_NETWORK_SUPPORT
32 const uint32_t NETWORK_SELF_REQUEST = 4;
33 #endif
34
ActiveFusionStrategies(int type)35 void FusionController::ActiveFusionStrategies(int type)
36 {
37 if (needReset_) {
38 fusedFlag_ = FUSION_DEFAULT_FLAG;
39 needReset_ = false;
40 }
41 switch (type) {
42 case SCENE_NAVIGATION:
43 case SCENE_TRAJECTORY_TRACKING:
44 break;
45 case PRIORITY_FAST_FIRST_FIX:
46 fusedFlag_ = fusedFlag_ | REPORT_FUSED_LOCATION_FLAG;
47 LBSLOGI(FUSION_CONTROLLER, "enable basic fused report");
48 break;
49 default:
50 break;
51 }
52 }
53
Process(std::string abilityName)54 void FusionController::Process(std::string abilityName)
55 {
56 needReset_ = true;
57 if (GNSS_ABILITY.compare(abilityName) != 0) {
58 return;
59 }
60 LBSLOGI(FUSION_CONTROLLER, "fused flag:%{public}u", fusedFlag_);
61 #ifdef FEATURE_NETWORK_SUPPORT
62 RequestQuickFix(fusedFlag_ & QUICK_FIX_FLAG);
63 #endif
64 }
65
FuseResult(std::string abilityName,const std::unique_ptr<Location> & location)66 void FusionController::FuseResult(std::string abilityName, const std::unique_ptr<Location>& location)
67 {
68 if (GNSS_ABILITY.compare(abilityName) == 0) {
69 #ifdef FEATURE_NETWORK_SUPPORT
70 RequestQuickFix(false);
71 #endif
72 }
73 }
74
75 #ifdef FEATURE_NETWORK_SUPPORT
RequestQuickFix(bool state)76 void FusionController::RequestQuickFix(bool state)
77 {
78 sptr<IRemoteObject> remoteObject = CommonUtils::GetRemoteObject(LOCATION_NETWORK_LOCATING_SA_ID);
79 if (remoteObject == nullptr) {
80 LBSLOGW(FUSION_CONTROLLER, "can not get network ability remote object");
81 return;
82 }
83 MessageParcel data;
84 MessageParcel reply;
85 MessageOption option;
86 if (!data.WriteInterfaceToken(NetworkAbilityProxy::GetDescriptor())) {
87 return;
88 }
89 data.WriteBool(state);
90 remoteObject->SendRequest(NETWORK_SELF_REQUEST, data, reply, option);
91 }
92 #endif
93 } // namespace Location
94 } // namespace OHOS