• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_ABILITY_RUNTIME_SIMULATOR_ABILITY_CONTEXT_H
17 #define OHOS_ABILITY_RUNTIME_SIMULATOR_ABILITY_CONTEXT_H
18 
19 #include "ability_stage_context.h"
20 #include "context.h"
21 #include "resource_manager.h"
22 #include "simulator.h"
23 #include "uv.h"
24 
25 namespace OHOS {
26 namespace AbilityRuntime {
27 class AbilityContext : public Context {
28 public:
29     AbilityContext() = default;
30     virtual ~AbilityContext() = default;
31 
32     std::shared_ptr<AppExecFwk::Configuration> GetConfiguration() override;
33     std::shared_ptr<AppExecFwk::ApplicationInfo> GetApplicationInfo() const override;
34     std::shared_ptr<AppExecFwk::HapModuleInfo> GetHapModuleInfo() const override;
35     std::shared_ptr<AppExecFwk::AbilityInfo> GetAbilityInfo() const;
36     void SetAbilityInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &info);
37 
38     std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager() const override;
39     std::shared_ptr<Context> CreateModuleContext(const std::string &moduleName) override;
40     std::shared_ptr<Context> CreateModuleContext(const std::string &bundleName, const std::string &moduleName) override;
41 
42     Options GetOptions() override;
43     void SetOptions(const Options &options) override;
44     std::string GetBundleName() const override;
45     std::string GetBundleCodePath() override;
46     std::string GetBundleCodeDir() override;
47     std::string GetCacheDir() override;
48     std::string GetTempDir() override;
49     std::string GetResourceDir() override;
50     std::string GetFilesDir() override;
51     std::string GetDatabaseDir() override;
52     std::string GetPreferencesDir() override;
53     std::string GetDistributedFilesDir() override;
54     std::string GetCloudFileDir() override;
55     void SwitchArea(int mode) override;
56     int GetArea() override;
57     std::string GetBaseDir() override;
58     void SetResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> &resMgr);
59     void SetAbilityStageContext(const std::shared_ptr<AbilityStageContext> &stageContext);
60     bool IsTerminating();
61     void SetTerminating(const bool &state);
62     int32_t TerminateSelf();
63     void SetSimulator(Simulator *simulator);
64     using SelfType = AbilityContext;
65     static const size_t CONTEXT_TYPE_ID;
66 
67 protected:
IsContext(size_t contextTypeId)68     bool IsContext(size_t contextTypeId) override
69     {
70         return contextTypeId == CONTEXT_TYPE_ID || Context::IsContext(contextTypeId);
71     }
72 
73 private:
74     static const int EL_DEFAULT = 1;
75     Options options_;
76     std::shared_ptr<Global::Resource::ResourceManager> resourceMgr_;
77     std::shared_ptr<AbilityStageContext> stageContext_;
78     bool isTerminating_ = false;
79     Simulator *simulator_;
80     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo_;
81 };
82 } // namespace AbilityRuntime
83 } // namespace OHOS
84 #endif // OHOS_ABILITY_RUNTIME_SIMULATOR_ABILITY_CONTEXT_H
85