1 /* 2 * Copyright (c) 2021 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 HIVIEWDFX_FAULTLOGGER_SERVICE_OHOS_H 16 #define HIVIEWDFX_FAULTLOGGER_SERVICE_OHOS_H 17 #include <cstdint> 18 #include <map> 19 #include <mutex> 20 #include <string> 21 #include <vector> 22 23 #include "system_ability.h" 24 25 #include "faultlogger_service_stub.h" 26 #include "faultlog_info_ohos.h" 27 #include "faultlog_query_result_ohos.h" 28 #include "i_faultlog_manager_service.h" 29 30 namespace OHOS { 31 namespace HiviewDFX { 32 class FaultloggerServiceOhos : public SystemAbility, 33 public FaultLoggerServiceStub { 34 DECLARE_SYSTEM_ABILITY(FaultloggerServiceOhos); 35 public: FaultloggerServiceOhos()36 FaultloggerServiceOhos() {}; ~FaultloggerServiceOhos()37 virtual ~FaultloggerServiceOhos() {}; 38 39 static void StartService(std::shared_ptr<IFaultLogManagerService> service); 40 static std::shared_ptr<IFaultLogManagerService> GetOrSetFaultlogger( 41 std::shared_ptr<IFaultLogManagerService> service = nullptr); 42 43 int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override; 44 45 void AddFaultLog(const FaultLogInfoOhos& info) override; 46 sptr<IRemoteObject> QuerySelfFaultLog(int32_t faultType, int32_t maxNum) override; 47 48 bool EnableGwpAsanGrayscale(bool alwaysEnabled, double sampleRate, 49 double maxSimutaneousAllocations, int32_t duration) override; 50 void DisableGwpAsanGrayscale() override; 51 uint32_t GetGwpAsanGrayscaleState() override; 52 53 void Destroy() override; 54 55 private: 56 struct FaultLogQuery { 57 int32_t pid = -1; 58 sptr<FaultLogQueryResultOhos> ptr = nullptr; 59 }; 60 61 private: 62 void ClearQueryStub(int32_t uid); 63 64 std::map<int32_t, std::unique_ptr<FaultLogQuery>> queries_; 65 std::mutex mutex_; 66 }; 67 }; // namespace HiviewDFX 68 }; // namespace OHOS 69 #endif // HIVIEWDFX_FAULTLOGGER_SERVICE_OHOS_H 70