1 /* 2 * Copyright (c) 2021-2023 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 HIVIEW_SERVICE_ABILITY_H 17 #define HIVIEW_SERVICE_ABILITY_H 18 19 #include <string> 20 #include <memory> 21 22 #include "hiview_file_info.h" 23 #include "hiview_service.h" 24 #include "hiview_service_ability_stub.h" 25 #include "ihiview_service_ability.h" 26 #include "logger.h" 27 #include "singleton.h" 28 #include "system_ability.h" 29 30 namespace OHOS { 31 namespace HiviewDFX { 32 class HiviewServiceAbility : public SystemAbility, 33 public HiviewServiceAbilityStub { 34 DECLARE_SYSTEM_ABILITY(HiviewServiceAbility); 35 36 public: 37 HiviewServiceAbility(); 38 ~HiviewServiceAbility(); 39 int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override; 40 static void StartService(HiviewService *service); 41 static void StartServiceAbility(int sleepS); 42 static HiviewService* GetOrSetHiviewService(HiviewService *service = nullptr); 43 44 int32_t List(const std::string& logType, std::vector<HiviewFileInfo>& fileInfos) override; 45 int32_t Copy(const std::string& logType, const std::string& logName, const std::string& dest) override; 46 int32_t Move(const std::string& logType, const std::string& logName, const std::string& dest) override; 47 int32_t Remove(const std::string& logType, const std::string& logName) override; 48 protected: 49 void OnDump() override; 50 void OnStart() override; 51 void OnStop() override; 52 private: 53 void GetFileInfoUnderDir(const std::string& dirPath, std::vector<HiviewFileInfo>& fileInfos); 54 int32_t CopyOrMoveFile( 55 const std::string& logType, const std::string& logName, const std::string& dest, bool isMove); 56 }; 57 58 class HiviewServiceAbilityDeathRecipient : public IRemoteObject::DeathRecipient { 59 public: 60 HiviewServiceAbilityDeathRecipient(); 61 ~HiviewServiceAbilityDeathRecipient(); 62 void OnRemoteDied(const wptr<IRemoteObject> &object) override; 63 }; 64 } // namespace HiviewDFX 65 } // namespace OHOS 66 #endif // IHIVIEW_SERVICE_H