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_SERVICE_EXTENSION_CONTEXT_H
17 #define OHOS_ABILITY_RUNTIME_SERVICE_EXTENSION_CONTEXT_H
18 
19 #include "extension_context.h"
20 
21 #include "ability_connect_callback.h"
22 #include "connection_manager.h"
23 #include "local_call_container.h"
24 #include "start_options.h"
25 #include "want.h"
26 #include "runtime.h"
27 #include "js_runtime.h"
28 #include "js_runtime_utils.h"
29 
30 namespace OHOS {
31 namespace NetManagerStandard {
32 using namespace AbilityRuntime;
33 /**
34  * @brief context supply for vpn
35  *
36  */
37 class VpnExtensionContext : public ExtensionContext {
38 public:
39     VpnExtensionContext() = default;
40     virtual ~VpnExtensionContext() = default;
41 
42     /**
43      * clear failed call connection by callback object
44      *
45      * @param callback Indicates the callback object.
46      *
47      * @return void.
48      */
49     void ClearFailedCallConnection(const std::shared_ptr<CallerCallBack> &callback) const;
50 
51     /**
52      * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE 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 Returns zero on success, others on failure.
59      */
60     ErrCode ConnectAbility(
61         const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const;
62 
63     ErrCode StartVpnExtensionAbility(const AAFwk::Want &want, int32_t accountId = -1) const;
64 
65     ErrCode StopVpnExtensionAbility(const AAFwk::Want& want, int32_t accountId = -1) const;
66 
67     using SelfType = VpnExtensionContext;
68     static const size_t CONTEXT_TYPE_ID;
69 
70 protected:
IsContext(size_t contextTypeId)71     bool IsContext(size_t contextTypeId) override
72     {
73         return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId);
74     }
75 
76 private:
77     static int ILLEGAL_REQUEST_CODE;
78     std::shared_ptr<LocalCallContainer> localCallContainer_ = nullptr;
79 };
80 }  // namespace NetManagerStandard
81 }  // namespace OHOS
82 #endif  // OHOS_ABILITY_RUNTIME_SERVICE_EXTENSION_CONTEXT_H
83