• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef EXTENSION_CONTEXT_H
17 #define EXTENSION_CONTEXT_H
18 
19 #include "ability_info.h"
20 #include "context_impl.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
24 /**
25  * @brief context supply for extension
26  *
27  */
28 class ExtensionContext : public ContextImpl {
29 public:
30     ExtensionContext() = default;
31     virtual ~ExtensionContext() = default;
32 
33     /**
34      * @brief Obtains information about the current ability.
35      * The returned information includes the class name, bundle name, and other information about the current ability.
36      *
37      * @return Returns the AbilityInfo object for the current ability.
38      */
39     std::shared_ptr<OHOS::AppExecFwk::AbilityInfo> GetAbilityInfo() const;
40 
41     /**
42      * @brief Set AbilityInfo when init.
43      *
44      */
45     void SetAbilityInfo(const std::shared_ptr<OHOS::AppExecFwk::AbilityInfo> &abilityInfo);
46 
47     using SelfType = ExtensionContext;
48     static const size_t CONTEXT_TYPE_ID;
49 
50 protected:
IsContext(size_t contextTypeId)51     bool IsContext(size_t contextTypeId) override
52     {
53         return contextTypeId == CONTEXT_TYPE_ID || Context::IsContext(contextTypeId);
54     }
55 
56 private:
57     std::shared_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo_;
58 };
59 }  // namespace AbilityRuntime
60 }  // namespace OHOS
61 #endif  // EXTENSION_CONTEXT_H