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 #ifndef LOCATOR_IMPL_H 16 #define LOCATOR_IMPL_H 17 18 #include <vector> 19 20 #include "iremote_object.h" 21 22 #include "constant_definition.h" 23 #include "country_code.h" 24 #include "country_code_manager.h" 25 #include "geo_address.h" 26 #include "geo_coding_mock_info.h" 27 #include "i_cached_locations_callback.h" 28 #include "locator_proxy.h" 29 #include "i_locating_required_data_callback.h" 30 #include "locating_required_data_config.h" 31 #include "location_data_manager.h" 32 #include "system_ability_status_change_stub.h" 33 #include "locationhub_ipc_interface_code.h" 34 #include "i_bluetooth_scan_result_callback.h" 35 36 namespace OHOS { 37 namespace Location { 38 class ICallbackResumeManager { 39 public: 40 virtual ~ICallbackResumeManager() = default; 41 virtual void ResumeCallback() = 0; 42 }; 43 44 class LocatorSystemAbilityListener : public SystemAbilityStatusChangeStub { 45 public: 46 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 47 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 48 private: 49 bool needResume_ = false; 50 std::mutex mutex_; 51 }; 52 53 class LocatorImpl { 54 public: 55 static std::shared_ptr<LocatorImpl> GetInstance(); 56 explicit LocatorImpl(); 57 ~LocatorImpl(); 58 59 /** 60 * @brief Obtain current location switch status. 61 * 62 * @return Returns true if the location switch on, returns false otherwise. 63 */ 64 bool IsLocationEnabled(); 65 void ShowNotification(); 66 void RequestPermission(); 67 void RequestEnableLocation(); 68 69 /** 70 * @brief Enable location switch. 71 * 72 * @param enable Status of the location switch to be set. 73 */ 74 void EnableAbility(bool enable); 75 76 /** 77 * @brief Subscribe location changed. 78 * 79 * @param requestConfig Indicates the location request parameters. 80 * @param callback Indicates the callback for reporting the location result. 81 */ 82 void StartLocating(std::unique_ptr<RequestConfig>& requestConfig, 83 sptr<ILocatorCallback>& callback); 84 85 /** 86 * @brief Unsubscribe location changed. 87 * 88 * @param callback Indicates the callback for reporting the location result. 89 */ 90 void StopLocating(sptr<ILocatorCallback>& callback); 91 92 /** 93 * @brief Obtain last known location. 94 * 95 * @return The last known location information. 96 */ 97 std::unique_ptr<Location> GetCachedLocation(); 98 99 /** 100 * @brief Subscribe location switch changed. 101 * 102 * @param callback Indicates the callback for reporting the location switch status. 103 * @param uid Indicates the calling uid 104 * @return Return whether the registration is successful. 105 */ 106 bool RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid); 107 108 /** 109 * @brief Unsubscribe location switch changed. 110 * 111 * @param callback Indicates the callback for reporting the location switch status. 112 * @return Return whether the deregistration is successful. 113 */ 114 bool UnregisterSwitchCallback(const sptr<IRemoteObject>& callback); 115 116 /** 117 * @brief Subscribe satellite status changed. 118 * 119 * @param callback Indicates the callback for reporting the satellite status. 120 * @param uid Indicates the calling uid 121 * @return Return whether the registration is successful. 122 */ 123 bool RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid); 124 125 /** 126 * @brief Unsubscribe satellite status changed. 127 * 128 * @param callback Indicates the callback for reporting the satellite status. 129 * @return Return whether the deregistration is successful. 130 */ 131 bool UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback); 132 133 /** 134 * @brief Subscribe nmea message changed. 135 * 136 * @param callback Indicates the callback for reporting the nmea message. 137 * @param uid Indicates the calling uid 138 * @return Return whether the registration is successful. 139 */ 140 bool RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid); 141 142 /** 143 * @brief Unsubscribe nmea message changed. 144 * 145 * @param callback Indicates the callback for reporting the nmea message. 146 * @return Return whether the deregistration is successful. 147 */ 148 bool UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback); 149 150 /** 151 * @brief Registering the callback function for listening to country code changes. 152 * 153 * @param callback Indicates the callback for reporting country code changes. 154 * @param uid Indicates the calling uid 155 * @return Return whether the registration is successful. 156 */ 157 bool RegisterCountryCodeCallback(const sptr<IRemoteObject>& callback, pid_t uid); 158 159 /** 160 * @brief Unregistering the callback function for listening to country code changes. 161 * 162 * @param callback Indicates the callback for reporting country code changes. 163 * @return Return whether the deregistration is successful. 164 */ 165 bool UnregisterCountryCodeCallback(const sptr<IRemoteObject>& callback); 166 167 /** 168 * @brief Subscribe to cache GNSS locations update messages. 169 * 170 * @param request Indicates the cached GNSS locations request parameters. 171 * @param callback Indicates the callback for reporting the cached GNSS locations. 172 * @return Return whether the registration is successful. 173 */ 174 void RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest>& request, 175 sptr<ICachedLocationsCallback>& callback); 176 177 /** 178 * @brief Unsubscribe to cache GNSS locations update messages. 179 * 180 * @param callback Indicates the callback for reporting the cached gnss locations. 181 * @return Return whether the deregistration is successful. 182 */ 183 void UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback); 184 185 /** 186 * @brief Obtain geocoding service status. 187 * 188 * @return Returns true if geocoding service is available, returns false otherwise. 189 */ 190 bool IsGeoServiceAvailable(); 191 192 /** 193 * @brief Obtain address info from location. 194 * 195 * @param data Indicates the reverse geocode query parameters. 196 * @param replyList Indicates the result of the address info. 197 */ 198 void GetAddressByCoordinate(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList); 199 200 /** 201 * @brief Obtain latitude and longitude info from location address. 202 * 203 * @param data Indicates the geocode query parameters. 204 * @param replyList Indicates the result of the address info. 205 */ 206 void GetAddressByLocationName(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList); 207 208 /** 209 * @brief Querying location privacy protocol confirmation status. 210 * 211 * @param type Indicates location privacy protocol type. 212 * @return Returns true if the location privacy protocol has been confirmed, returns false otherwise. 213 */ 214 bool IsLocationPrivacyConfirmed(const int type); 215 216 /** 217 * @brief Set location privacy protocol confirmation status. 218 * 219 * @param type Indicates location privacy protocol type. 220 * @param isConfirmed Indicates whether the location privacy protocol should be confirmed. 221 * @return Returns 1 if the location privacy protocol has been set, returns 0 otherwise. 222 */ 223 int SetLocationPrivacyConfirmStatus(const int type, bool isConfirmed); 224 225 /** 226 * @brief Obtain the number of cached GNSS locations. 227 * 228 * @return Returns the result of the cached GNSS locations size. 229 */ 230 int GetCachedGnssLocationsSize(); 231 232 /** 233 * @brief All prepared GNSS locations are returned to the application through the callback function, 234 * and the bottom-layer buffer is cleared. 235 * 236 * @return Returns 1 if the cached gnss location has been flushed, returns 0 otherwise. 237 */ 238 int FlushCachedGnssLocations(); 239 240 /** 241 * @brief Send extended commands to location subsystem. 242 * 243 * @param commands Indicates the extended command message body. 244 * @return Returns true if the command has been sent successfully, returns false otherwise. 245 */ 246 bool SendCommand(std::unique_ptr<LocationCommand>& commands); 247 248 /** 249 * @brief Obtain the current country code. 250 * 251 * @return Returns the result of the country code. 252 */ 253 std::shared_ptr<CountryCode> GetIsoCountryCode(); 254 255 /** 256 * @brief Enable the geographical location simulation function. 257 * 258 * @return Returns true if the mock location function has been enabled successfully, returns false otherwise. 259 */ 260 bool EnableLocationMock(); 261 262 /** 263 * @brief Disable the geographical location simulation function. 264 * 265 * @return Returns true if the mock location function has been disabled successfully, returns false otherwise. 266 */ 267 bool DisableLocationMock(); 268 269 /** 270 * @brief Set the configuration parameters for location simulation. 271 * 272 * @param timeInterval Indicates how often the simulated location is reported. 273 * @param location Indicates the simulated location to be reported. 274 * @return Returns true if the mock location config has been set successfully, returns false otherwise. 275 */ 276 bool SetMockedLocations( 277 const int timeInterval, const std::vector<std::shared_ptr<Location>> &location); 278 279 /** 280 * @brief Enable the reverse geocoding simulation function. 281 * 282 * @return Returns true if the mock reverse geocoding function has been enabled successfully, 283 * returns false otherwise. 284 */ 285 bool EnableReverseGeocodingMock(); 286 287 /** 288 * @brief Disable the reverse geocoding simulation function. 289 * 290 * @return Returns true if the mock reverse geocoding function has been disabled successfully, 291 * returns false otherwise. 292 */ 293 bool DisableReverseGeocodingMock(); 294 295 /** 296 * @brief Set the configuration parameters for simulating reverse geocoding. 297 * 298 * @param mockInfo Indicates the set of locations and place names to be simulated. 299 * @return Returns true if the mock reverse geocoding config has been set successfully, returns false otherwise. 300 */ 301 bool SetReverseGeocodingMockInfo(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo); 302 303 /** 304 * @brief Obtain current location switch status. 305 * 306 * @param isEnabled Indicates if the location switch on. 307 * @return Returns ERRCODE_SUCCESS if obtain current location switch status succeed. 308 */ 309 LocationErrCode IsLocationEnabledV9(bool &isEnabled); 310 311 /** 312 * @brief Obtain current location switch status. 313 * 314 * @param isEnabled Indicates if the location switch on. 315 * @return Returns ERRCODE_SUCCESS if obtain current location switch status succeed. 316 */ 317 LocationErrCode IsLocationEnabledForUser(bool &isEnabled, int32_t userId); 318 319 /** 320 * @brief Enable location switch. 321 * 322 * @param enable Status of the location switch to be set. 323 * @return Returns ERRCODE_SUCCESS if enable location switch succeed. 324 */ 325 LocationErrCode EnableAbilityV9(bool enable); 326 327 /** 328 * @brief Enable location switch. 329 * 330 * @param enable Status of the location switch to be set. 331 * @param userId userId of the user. 332 * @return Returns ERRCODE_SUCCESS if enable location switch succeed. 333 */ 334 LocationErrCode EnableAbilityForUser(bool enable, int32_t userId); 335 336 /** 337 * @brief Subscribe location changed. 338 * 339 * @param requestConfig Indicates the location request parameters. 340 * @param callback Indicates the callback for reporting the location result. 341 * @return Returns ERRCODE_SUCCESS if subscribe location changed succeed. 342 */ 343 LocationErrCode StartLocatingV9(std::unique_ptr<RequestConfig>& requestConfig, 344 sptr<ILocatorCallback>& callback); 345 346 /** 347 * @brief Unsubscribe location changed. 348 * 349 * @param callback Indicates the callback for reporting the location result. 350 * @return Returns ERRCODE_SUCCESS if Unsubscribe location changed succeed. 351 */ 352 LocationErrCode StopLocatingV9(sptr<ILocatorCallback>& callback); 353 354 /** 355 * @brief Obtain last known location. 356 * 357 * @param loc Indicates the last known location information. 358 * @return Returns ERRCODE_SUCCESS if obtain last known location succeed. 359 */ 360 LocationErrCode GetCachedLocationV9(std::unique_ptr<Location> &loc); 361 362 /** 363 * @brief Subscribe location switch changed. 364 * 365 * @param callback Indicates the callback for reporting the location switch status. 366 * @return Return ERRCODE_SUCCESS if the registration is successful. 367 */ 368 LocationErrCode RegisterSwitchCallbackV9(const sptr<IRemoteObject>& callback); 369 370 /** 371 * @brief Unsubscribe location switch changed. 372 * 373 * @param callback Indicates the callback for reporting the location switch status. 374 * @return Return ERRCODE_SUCCESS if the deregistration is successful. 375 */ 376 LocationErrCode UnregisterSwitchCallbackV9(const sptr<IRemoteObject>& callback); 377 378 /** 379 * @brief Subscribe satellite status changed. 380 * 381 * @param callback Indicates the callback for reporting the satellite status. 382 * @return Return ERRCODE_SUCCESS if the registration is successful. 383 */ 384 LocationErrCode RegisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback); 385 386 /** 387 * @brief Unsubscribe satellite status changed. 388 * 389 * @param callback Indicates the callback for reporting the satellite status. 390 * @return Return ERRCODE_SUCCESS if the deregistration is successful. 391 */ 392 LocationErrCode UnregisterGnssStatusCallbackV9(const sptr<IRemoteObject>& callback); 393 394 /** 395 * @brief Subscribe nmea message changed. 396 * 397 * @param callback Indicates the callback for reporting the nmea message. 398 * @return Return ERRCODE_SUCCESS if the registration is successful. 399 */ 400 LocationErrCode RegisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback); 401 402 /** 403 * @brief Unsubscribe nmea message changed. 404 * 405 * @param callback Indicates the callback for reporting the nmea message. 406 * @return Return ERRCODE_SUCCESS if the deregistration is successful. 407 */ 408 LocationErrCode UnregisterNmeaMessageCallbackV9(const sptr<IRemoteObject>& callback); 409 410 /** 411 * @brief Registering the callback function for listening to country code changes. 412 * 413 * @param callback Indicates the callback for reporting country code changes. 414 * @return Return ERRCODE_SUCCESS if the registration is successful. 415 */ 416 LocationErrCode RegisterCountryCodeCallbackV9(const sptr<IRemoteObject>& callback); 417 418 /** 419 * @brief Unregistering the callback function for listening to country code changes. 420 * 421 * @param callback Indicates the callback for reporting country code changes. 422 * @return Return ERRCODE_SUCCESS if the deregistration is successful. 423 */ 424 LocationErrCode UnregisterCountryCodeCallbackV9(const sptr<IRemoteObject>& callback); 425 426 /** 427 * @brief Subscribe to cache GNSS locations update messages. 428 * 429 * @param request Indicates the cached GNSS locations request parameters. 430 * @param callback Indicates the callback for reporting the cached GNSS locations. 431 * @return Return ERRCODE_SUCCESS if the registration is successful. 432 */ 433 LocationErrCode RegisterCachedLocationCallbackV9(std::unique_ptr<CachedGnssLocationsRequest>& request, 434 sptr<ICachedLocationsCallback>& callback); 435 436 /** 437 * @brief Unsubscribe to cache GNSS locations update messages. 438 * 439 * @param callback Indicates the callback for reporting the cached gnss locations. 440 * @return Return ERRCODE_SUCCESS if the deregistration is successful. 441 */ 442 LocationErrCode UnregisterCachedLocationCallbackV9(sptr<ICachedLocationsCallback>& callback); 443 444 /** 445 * @brief Obtain geocoding service status. 446 * 447 * @param isAvailable Indicates if geocoding service is available 448 * @return Return ERRCODE_SUCCESS if obtain geocoding service status is successful. 449 */ 450 LocationErrCode IsGeoServiceAvailableV9(bool &isAvailable); 451 452 /** 453 * @brief Obtain address info from location. 454 * 455 * @param data Indicates the reverse geocode query parameters. 456 * @param replyList Indicates the result of the address info. 457 * @return Return ERRCODE_SUCCESS if obtain address info from location is successful. 458 */ 459 LocationErrCode GetAddressByCoordinateV9(MessageParcel &data, 460 std::list<std::shared_ptr<GeoAddress>>& replyList); 461 462 /** 463 * @brief Obtain latitude and longitude info from location address. 464 * 465 * @param data Indicates the geocode query parameters. 466 * @param replyList Indicates the result of the address info. 467 * @return Return ERRCODE_SUCCESS if obtain latitude and longitude info from location address is successful. 468 */ 469 LocationErrCode GetAddressByLocationNameV9(MessageParcel &data, 470 std::list<std::shared_ptr<GeoAddress>>& replyList); 471 472 /** 473 * @brief Querying location privacy protocol confirmation status. 474 * 475 * @param type Indicates location privacy protocol type. 476 * @param isConfirmed Indicates if the location privacy protocol has been confirmed 477 * @return Return ERRCODE_SUCCESS if querying location privacy protocol confirmation status is successful. 478 */ 479 LocationErrCode IsLocationPrivacyConfirmedV9(const int type, bool &isConfirmed); 480 481 /** 482 * @brief Set location privacy protocol confirmation status. 483 * 484 * @param type Indicates location privacy protocol type. 485 * @param isConfirmed Indicates whether the location privacy protocol should be confirmed. 486 * @return Return ERRCODE_SUCCESS if set location privacy protocol confirmation status is successful. 487 */ 488 LocationErrCode SetLocationPrivacyConfirmStatusV9(const int type, bool isConfirmed); 489 490 /** 491 * @brief Obtain the number of cached GNSS locations. 492 * 493 * @param size Indicates the cached GNSS locations size 494 * @return Return ERRCODE_SUCCESS if obtain the number of cached GNSS locations is successful. 495 */ 496 LocationErrCode GetCachedGnssLocationsSizeV9(int &size); 497 498 /** 499 * @brief All prepared GNSS locations are returned to the application through the callback function, 500 * and the bottom-layer buffer is cleared. 501 * 502 * @return Return ERRCODE_SUCCESS if flush cached gnss locations is successful. 503 */ 504 LocationErrCode FlushCachedGnssLocationsV9(); 505 506 /** 507 * @brief Send extended commands to location subsystem. 508 * 509 * @param commands Indicates the extended command message body. 510 * @return Returns ERRCODE_SUCCESS if the command has been sent successfully. 511 */ 512 LocationErrCode SendCommandV9(std::unique_ptr<LocationCommand>& commands); 513 514 /** 515 * @brief Obtain the current country code. 516 * 517 * @param countryCode the result of the country code 518 * @return Returns ERRCODE_SUCCESS if obtain the current country code successfully. 519 */ 520 LocationErrCode GetIsoCountryCodeV9(std::shared_ptr<CountryCode>& countryCode); 521 522 /** 523 * @brief Enable the geographical location simulation function. 524 * 525 * @return Returns ERRCODE_SUCCESS if the mock location function has been enabled successfully. 526 */ 527 LocationErrCode EnableLocationMockV9(); 528 529 /** 530 * @brief Disable the geographical location simulation function. 531 * 532 * @return Returns ERRCODE_SUCCESS if the mock location function has been disabled successfully. 533 */ 534 LocationErrCode DisableLocationMockV9(); 535 536 /** 537 * @brief Set the configuration parameters for location simulation. 538 * 539 * @param timeInterval Indicates how often the simulated location is reported. 540 * @param location Indicates the simulated location to be reported. 541 * @return Returns ERRCODE_SUCCESS if the mock location config has been set successfully. 542 */ 543 LocationErrCode SetMockedLocationsV9( 544 const int timeInterval, const std::vector<std::shared_ptr<Location>> &location); 545 546 /** 547 * @brief Enable the reverse geocoding simulation function. 548 * 549 * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding function has been enabled successfully. 550 */ 551 LocationErrCode EnableReverseGeocodingMockV9(); 552 553 /** 554 * @brief Disable the reverse geocoding simulation function. 555 * 556 * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding function has been disabled successfully. 557 */ 558 LocationErrCode DisableReverseGeocodingMockV9(); 559 560 /** 561 * @brief Set the configuration parameters for simulating reverse geocoding. 562 * 563 * @param mockInfo Indicates the set of locations and place names to be simulated. 564 * @return Returns ERRCODE_SUCCESS if the mock reverse geocoding config has been set successfully. 565 */ 566 LocationErrCode SetReverseGeocodingMockInfoV9(std::vector<std::shared_ptr<GeocodingMockInfo>>& mockInfo); 567 568 /** 569 * @brief Used to freeze locating process with specified uid. 570 * 571 * @param pidList Indicates the calling pid. 572 * @param isProxy Indicates if the locating process should be freezed. 573 * @return Returns ERRCODE_SUCCESS if the process has been frozen successfully. 574 */ 575 LocationErrCode ProxyForFreeze(std::set<int> pidList, bool isProxy); 576 577 /** 578 * @brief Used to reset the frozen status of all location processes. 579 * 580 * @return Returns ERRCODE_SUCCESS if the frozen status of process has been reset successfully. 581 */ 582 LocationErrCode ResetAllProxy(); 583 584 /** 585 * @brief Subscribe to changes in WiFi/BT scanning information. 586 * 587 * @param dataConfig Indicates the locating required data configuration parameters. 588 * @param callback Indicates the callback for reporting WiFi/BT scan info. 589 * @return Returns ERRCODE_SUCCESS if subscribe to changes in WiFi/BT scanning information successfully. 590 */ 591 LocationErrCode RegisterLocatingRequiredDataCallback(std::unique_ptr<LocatingRequiredDataConfig>& dataConfig, 592 sptr<ILocatingRequiredDataCallback>& callback); 593 594 /** 595 * @brief Unsubscribe to changes in WiFi/BT scanning information. 596 * 597 * @param callback Indicates the callback for reporting WiFi/BT scan info. 598 * @return Returns ERRCODE_SUCCESS if Unsubscribe to changes in WiFi/BT scanning information successfully. 599 */ 600 LocationErrCode UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback>& callback); 601 602 /** 603 * @brief Subscribe location error changed. 604 * 605 * @param callback Indicates the callback for reporting the location error result. 606 * @return Returns ERRCODE_SUCCESS if subscribe error changed succeed. 607 */ 608 LocationErrCode SubscribeLocationError(sptr<ILocatorCallback>& callback); 609 610 /** 611 * @brief Subscribe bluetooth scan result change. 612 * 613 * @param callback Indicates the callback for reporting the location error result. 614 * @return Returns ERRCODE_SUCCESS if subscribe error changed succeed. 615 */ 616 LocationErrCode SubscribeBluetoothScanResultChange(sptr<IBluetoohScanResultCallback>& callback); 617 618 /** 619 * @brief Unsubscribe bluetooth scan result change. 620 * 621 * @param callback Indicates the callback for reporting the bluetooth scan result. 622 * @return Returns ERRCODE_SUCCESS if subscribe error changed succeed. 623 */ 624 LocationErrCode UnSubscribeBluetoothScanResultChange(sptr<IBluetoohScanResultCallback>& callback); 625 626 /** 627 * @brief Unsubscribe location errorcode changed. 628 * 629 * @param callback Indicates the callback for reporting the location error result. 630 * @return Returns ERRCODE_SUCCESS if Unsubscribe error changed succeed. 631 */ 632 LocationErrCode UnSubscribeLocationError(sptr<ILocatorCallback>& callback); 633 634 /** 635 * @brief Obtain last known location. 636 * 637 * @param loc Indicates the last known location information. 638 * @return Returns ERRCODE_SUCCESS if obtain last known location succeed. 639 */ 640 LocationErrCode GetCurrentWifiBssidForLocating(std::string& bssid); 641 642 /** 643 * Obtaining the location switch status of a specified user. 644 * 645 * @param userId - Indicates the ID of a specified user. 646 * @returns Returns {@code true} if the location switch on, returns {@code false} otherwise. 647 */ 648 LocationErrCode SetLocationSwitchIgnored(bool enable); 649 650 void ResetLocatorProxy(const wptr<IRemoteObject> &remote); 651 sptr<LocatorProxy> GetProxy(); 652 bool IsLocationCallbackRegistered(const sptr<ILocatorCallback>& callback); 653 bool IsSatelliteStatusChangeCallbackRegistered(const sptr<IRemoteObject>& callback); 654 bool IsNmeaCallbackRegistered(const sptr<IRemoteObject>& callback); 655 bool HasGnssNetworkRequest(); 656 void AddLocationCallBack(std::unique_ptr<RequestConfig>& requestConfig, sptr<ILocatorCallback>& callback); 657 void RemoveLocationCallBack(sptr<ILocatorCallback>& callback); 658 void AddSatelliteStatusChangeCallBack(const sptr<IRemoteObject>& callback); 659 void RemoveSatelliteStatusChangeCallBack(const sptr<IRemoteObject>& callback); 660 void AddNmeaCallBack(const sptr<IRemoteObject>& callback); 661 void RemoveNmeaCallBack(const sptr<IRemoteObject>& callback); 662 void SetIsServerExist(bool isServerExist); 663 664 private: 665 LocationErrCode CheckEdmPolicy(bool enable); 666 667 private: 668 class LocatorDeathRecipient : public IRemoteObject::DeathRecipient { 669 public: LocatorDeathRecipient(LocatorImpl & impl)670 explicit LocatorDeathRecipient(LocatorImpl &impl) : impl_(impl) {} 671 ~LocatorDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)672 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 673 { 674 impl_.ResetLocatorProxy(remote); 675 } 676 private: 677 LocatorImpl &impl_; 678 }; 679 680 private: 681 bool IsCallbackResuming(); 682 void UpdateCallbackResumingState(bool state); 683 684 sptr<LocatorProxy> client_ { nullptr }; 685 sptr<IRemoteObject::DeathRecipient> recipient_ { nullptr }; 686 LocationDataManager* locationDataManager_ { nullptr }; 687 bool isServerExist_ = false; 688 bool isCallbackResuming_ = false; 689 std::mutex mutex_; 690 std::mutex resumeMutex_; 691 static std::mutex locatorMutex_; 692 static std::shared_ptr<LocatorImpl> instance_; 693 sptr<ISystemAbilityStatusChange> saStatusListener_ = 694 sptr<LocatorSystemAbilityListener>(new LocatorSystemAbilityListener()); 695 }; 696 697 class CallbackResumeManager : public ICallbackResumeManager { 698 public: 699 CallbackResumeManager() = default; 700 ~CallbackResumeManager() = default; 701 void ResumeCallback() override; 702 private: 703 void InitResumeCallbackFuncMap(); 704 void ResumeGnssStatusCallback(); 705 void ResumeNmeaMessageCallback(); 706 void ResumeLocating(); 707 }; 708 } // namespace Location 709 } // namespace OHOS 710 #endif // LOCATOR_IMPL_H 711