• 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 WALLPAPER_EXTENSION_CONTEXT_H
17 #define WALLPAPER_EXTENSION_CONTEXT_H
18 
19 #include "extension_context.h"
20 
21 #include "ability_connect_callback.h"
22 #include "connection_manager.h"
23 #include "start_options.h"
24 #include "want.h"
25 
26 namespace OHOS {
27 namespace AbilityRuntime {
28 /**
29  * @brief context supply for wallpaper
30  *
31  */
32 class WallpaperExtensionContext : public ExtensionContext {
33 public:
34     WallpaperExtensionContext() = default;
35     virtual ~WallpaperExtensionContext() = default;
36 
37     /**
38      * @brief Starts a new ability.
39      * An ability using the AbilityInfo.AbilityType.WALLPAPER or AbilityInfo.AbilityType.PAGE template uses this method
40      * to start a specific ability. The system locates the target ability from installed abilities based on the value
41      * of the want parameter and then starts it. You can specify the ability to start using the want parameter.
42      *
43      * @param want Indicates the Want containing information about the target ability to start.
44      *
45      * @return errCode ERR_OK on success, others on failure.
46      */
47     ErrCode StartAbility(const AAFwk::Want &want) const;
48 
49     ErrCode StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const;
50 
51     /**
52      * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.WALLPAPER template.
53      *
54      * @param want Indicates the want containing information about the ability to connect
55      *
56      * @param conn Indicates the callback object when the target ability is connected.
57      *
58      * @return True means success and false means failure
59      */
60     bool ConnectAbility(
61         const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const;
62 
63     /**
64      * @brief Starts a new ability.
65      * An ability using the AbilityInfo.AbilityType.WALLPAPER or AbilityInfo.AbilityType.PAGE template uses this method
66      * to start a specific ability. The system locates the target ability from installed abilities based on the value
67      * of the want parameter and then starts it. You can specify the ability to start using the want parameter.
68      *
69      * @param want Indicates the Want containing information about the target ability to start.
70      * @param accountId caller user.
71      *
72      * @return errCode ERR_OK on success, others on failure.
73      */
74     ErrCode StartAbilityWithAccount(const AAFwk::Want &want, int accountId) const;
75 
76     ErrCode StartAbilityWithAccount(
77         const AAFwk::Want &want, int accountId, const AAFwk::StartOptions &startOptions) const;
78 
79     /**
80      * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.WALLPAPER template.
81      *
82      * @param want Indicates the want containing information about the ability to connect.
83      *
84      * @param accountId caller user.
85      *
86      * @param conn Indicates the callback object when the target ability is connected.
87      *
88      * @return True means success and false means failure.
89      */
90     bool ConnectAbilityWithAccount(
91         const AAFwk::Want &want, int accountId, const sptr<AbilityConnectCallback> &connectCallback) const;
92 
93     /**
94      * @brief Disconnects the current ability from an ability.
95      *
96      * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection
97      * is set up. The IAbilityConnection object uniquely identifies a connection between two abilities.
98      *
99      * @return errCode ERR_OK on success, others on failure.
100      */
101     ErrCode DisconnectAbility(
102         const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const;
103 
104     /**
105      * @brief Destroys the current ability.
106      *
107      * @return errCode ERR_OK on success, others on failure.
108      */
109     ErrCode TerminateAbility();
110 
111     using SelfType = WallpaperExtensionContext;
112     static const size_t CONTEXT_TYPE_ID;
113 
114 protected:
IsContext(size_t contextTypeId)115     bool IsContext(size_t contextTypeId) override
116     {
117         return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId);
118     }
119 
120 private:
121     static int ILLEGAL_REQUEST_CODE;
122 
123     /**
124      * @brief Get Current Ability Type
125      *
126      * @return Current Ability Type
127      */
128     OHOS::AppExecFwk::AbilityType GetAbilityInfoType() const;
129 };
130 }  // namespace AbilityRuntime
131 }  // namespace OHOS
132 #endif  // WALLPAPER_EXTENSION_CONTEXT_H