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 SUBABILITY_COMMON_H 17 #define SUBABILITY_COMMON_H 18 19 #include <vector> 20 21 #include "iremote_broker.h" 22 23 #include "constant_definition.h" 24 #include "i_locator_callback.h" 25 #include "location.h" 26 #include "hilog/log.h" 27 #include "work_record.h" 28 29 namespace OHOS { 30 namespace Location { 31 class ISubAbility : public IRemoteBroker { 32 public: 33 virtual LocationErrCode SendLocationRequest(WorkRecord &workrecord) = 0; 34 virtual LocationErrCode SetEnable(bool state) = 0; 35 virtual LocationErrCode EnableMock() = 0; 36 virtual LocationErrCode DisableMock() = 0; 37 virtual LocationErrCode SetMocked(const int timeInterval, 38 const std::vector<std::shared_ptr<Location>> &location) = 0; 39 }; 40 41 class SubAbility { 42 public: 43 SubAbility(); 44 virtual ~SubAbility(); 45 void SetAbility(std::string name); 46 void LocationRequest(WorkRecord &workrecord); 47 void Enable(bool state, const sptr<IRemoteObject> ability); 48 void HandleSelfRequest(pid_t pid, pid_t uid, bool state); 49 void HandleRefrashRequirements(); 50 int GetRequestNum(); 51 bool EnableLocationMock(); 52 bool DisableLocationMock(); 53 bool SetMockedLocations(const int timeInterval, const std::vector<std::shared_ptr<Location>> &location); 54 55 int GetTimeIntervalMock(); 56 bool IsLocationMocked(); 57 std::vector<std::shared_ptr<Location>> GetLocationMock(); 58 void ClearLocationMock(); 59 void ReportLocationInfo(const std::string& systemAbility, const std::shared_ptr<Location> location); 60 private: 61 void HandleLocalRequest(WorkRecord &record); 62 void HandleRemoveRecord(WorkRecord &newRecord); 63 void HandleAddRecord(WorkRecord &newRecord); 64 void CacheLocationMock(const std::vector<std::shared_ptr<Location>> &location); 65 virtual void RequestRecord(WorkRecord &workRecord, bool isAdded) = 0; 66 virtual void SendReportMockLocationEvent() = 0; 67 68 OHOS::HiviewDFX::HiLogLabel label_; 69 int interval_ = 0; 70 std::string name_ = ""; 71 std::u16string capability_ = u""; 72 std::unique_ptr<WorkRecord> lastRecord_; 73 std::unique_ptr<WorkRecord> newRecord_; 74 int mockTimeInterval_ = 0; 75 bool mockEnabled_ = false; 76 std::vector<std::shared_ptr<Location>> mockLoc_; 77 std::mutex mutex_; 78 }; 79 } // namespace Location 80 } // namespace OHOS 81 #endif // SUBABILITY_COMMON_H 82