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