1 /* 2 * Copyright (c) 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 SERVICES_SAFWK_INCLUDE_SYSTEM_ABILITY_ONDEMAND_REASON_H 17 #define SERVICES_SAFWK_INCLUDE_SYSTEM_ABILITY_ONDEMAND_REASON_H 18 19 #include <map> 20 #include "parcel.h" 21 22 namespace OHOS { 23 enum class OnDemandReasonId { 24 INTERFACE_CALL = 0, 25 DEVICE_ONLINE = 1, 26 SETTING_SWITCH = 2, 27 PARAM = 3, 28 COMMON_EVENT = 4, 29 TIMED_EVENT = 5, 30 }; 31 32 class OnDemandReasonExtraData : public Parcelable { 33 public: 34 OnDemandReasonExtraData() = default; 35 OnDemandReasonExtraData(int32_t code, const std::string& data, const std::map<std::string, std::string>& want); 36 std::string GetData() const; 37 int32_t GetCode() const; 38 const std::map<std::string, std::string>& GetWant() const; 39 bool Marshalling(Parcel& parcel) const override; 40 static OnDemandReasonExtraData *Unmarshalling(Parcel& parcel); 41 private: 42 int32_t code_ = -1; 43 std::string data_; 44 std::map<std::string, std::string> want_; 45 }; 46 47 class SystemAbilityOnDemandReason { 48 public: 49 SystemAbilityOnDemandReason() = default; 50 SystemAbilityOnDemandReason(OnDemandReasonId reasonId, const std::string& reasonName, 51 const std::string& reasonValue, int64_t extraDataId); 52 OnDemandReasonId GetId() const; 53 void SetId(OnDemandReasonId reasonId); 54 std::string GetName() const; 55 void SetName(const std::string& reasonName); 56 std::string GetValue() const; 57 void SetValue(const std::string& reasonValue); 58 int64_t GetExtraDataId() const; 59 void SetExtraDataId(int64_t extraDataId); 60 bool HasExtraData() const; 61 void SetExtraData(OnDemandReasonExtraData& extraData); 62 const OnDemandReasonExtraData& GetExtraData() const; 63 private: 64 OnDemandReasonId reasonId_; 65 std::string reasonName_; 66 std::string reasonValue_; 67 int64_t extraDataId_ = -1; 68 OnDemandReasonExtraData extraData_; 69 }; 70 } 71 #endif /* SERVICES_SAFWK_INCLUDE_SYSTEM_ABILITY_ONDEMAND_REASON_H */