1 /* 2 * Copyright (c) 2021-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 OHOS_ABILITY_RUNTIME_ABILITY_STAGE_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_STAGE_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 23 #include "ability_local_record.h" 24 #include "configuration.h" 25 #include "hap_module_info.h" 26 #include "want.h" 27 28 namespace OHOS { 29 namespace AbilityRuntime { 30 class Context; 31 class Runtime; 32 /** 33 * @brief the hap level entity 34 * 35 * To share the data among the abilities of a hap, 36 * and supply lifecycle func for the developers. 37 */ 38 class AbilityStage { 39 public: 40 static std::shared_ptr<AbilityStage> Create( 41 const std::unique_ptr<Runtime>& runtime, const AppExecFwk::HapModuleInfo& hapModuleInfo); 42 43 AbilityStage() = default; 44 virtual ~AbilityStage() = default; 45 virtual void OnCreate(const AAFwk::Want &want) const; 46 virtual void OnDestroy() const; 47 virtual std::string OnAcceptWant(const AAFwk::Want &want); 48 virtual void Init(const std::shared_ptr<Context> &context); 49 std::shared_ptr<Context> GetContext() const; 50 void AddAbility(const sptr<IRemoteObject> &token, 51 const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &abilityRecord); 52 void RemoveAbility(const sptr<IRemoteObject> &token); 53 bool ContainsAbility() const; 54 virtual void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration); 55 virtual void OnMemoryLevel(int level); 56 57 private: 58 std::shared_ptr<Context> context_; 59 std::map<sptr<IRemoteObject>, std::shared_ptr<AppExecFwk::AbilityLocalRecord>> abilityRecords_; 60 }; 61 } // namespace AbilityRuntime 62 } // namespace OHOS 63 #endif // OHOS_ABILITY_RUNTIME_ABILITY_STAGE_H 64