• 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_EXTENSION_MANAGER_CLIENT_H
17 #define OHOS_ABILITY_RUNTIME_EXTENSION_MANAGER_CLIENT_H
18 
19 #include <mutex>
20 
21 #include "extension_manager_interface.h"
22 
23 #include "iremote_object.h"
24 
25 namespace OHOS {
26 namespace AAFwk {
27 /**
28  * @class ExtensionManagerClient
29  * ExtensionManagerClient is used to access ability manager services.
30  */
31 class ExtensionManagerClient {
32 public:
33     ExtensionManagerClient() = default;
34     virtual ~ExtensionManagerClient() = default;
35     static ExtensionManagerClient& GetInstance();
36 
37     ErrCode ConnectServiceExtensionAbility(const Want &want, const sptr<IRemoteObject> &connect, int32_t userId);
38 
39     ErrCode ConnectServiceExtensionAbility(const Want &want, const sptr<IRemoteObject> &connect,
40         const sptr<IRemoteObject> &callerToken, int32_t userId);
41 
42     ErrCode ConnectEnterpriseAdminExtensionAbility(const Want &want,
43         const sptr<IRemoteObject> &connect, const sptr<IRemoteObject> &callerToken, int32_t userId);
44 
45     /**
46      * Connect extension ability.
47      *
48      * @param want special want for the extension ability.
49      * @param connect callback used to notify caller the result of connecting.
50      * @param userId the extension runs in.
51      * @return Returns ERR_OK on success, others on failure.
52      */
53     ErrCode ConnectExtensionAbility(const Want &want, const sptr<IRemoteObject> &connect,
54         int32_t userId = DEFAULT_INVALID_USER_ID);
55 
56     /**
57      * Disconnect session with extension ability.
58      *
59      * @param connect Callback used to notify caller the result of disconnecting.
60      * @return Returns ERR_OK on success, others on failure.
61      */
62     ErrCode DisconnectAbility(const sptr<IRemoteObject> &connect);
63 
64     ErrCode Release();
65 
66 private:
67     class ExtensionMgrDeathRecipient : public IRemoteObject::DeathRecipient {
68     public:
69         ExtensionMgrDeathRecipient() = default;
70         ~ExtensionMgrDeathRecipient() = default;
71         void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
72     private:
73         DISALLOW_COPY_AND_MOVE(ExtensionMgrDeathRecipient);
74     };
75 
76     sptr<IExtensionManager> GetExtensionManager();
77     void Connect();
78     void ResetProxy(const wptr<IRemoteObject>& remote);
79     ErrCode RemoveDeathRecipient();
80 
81     std::mutex mutex_;
82     sptr<IExtensionManager> proxy_;
83     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
84 };
85 }  // namespace AAFwk
86 }  // namespace OHOS
87 #endif  // OHOS_ABILITY_RUNTIME_EXTENSION_MANAGER_CLIENT_H
88