• 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     /**
43      * Connect extension ability.
44      *
45      * @param want special want for the extension ability.
46      * @param connect callback used to notify caller the result of connecting.
47      * @param userId the extension runs in.
48      * @return Returns ERR_OK on success, others on failure.
49      */
50     ErrCode ConnectExtensionAbility(const Want &want, const sptr<IRemoteObject> &connect,
51         int32_t userId = DEFAULT_INVALID_USER_ID);
52 
53     /**
54      * Disconnect session with extension ability.
55      *
56      * @param connect Callback used to notify caller the result of disconnecting.
57      * @return Returns ERR_OK on success, others on failure.
58      */
59     ErrCode DisconnectAbility(const sptr<IRemoteObject> &connect);
60 
61 private:
62     class ExtensionMgrDeathRecipient : public IRemoteObject::DeathRecipient {
63     public:
64         ExtensionMgrDeathRecipient() = default;
65         ~ExtensionMgrDeathRecipient() = default;
66         void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
67     private:
68         DISALLOW_COPY_AND_MOVE(ExtensionMgrDeathRecipient);
69     };
70 
71     sptr<IExtensionManager> GetExtensionManager();
72     void Connect();
73     void ResetProxy(const wptr<IRemoteObject>& remote);
74 
75     std::mutex mutex_;
76     sptr<IExtensionManager> proxy_;
77     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
78 };
79 }  // namespace AAFwk
80 }  // namespace OHOS
81 #endif  // OHOS_ABILITY_RUNTIME_EXTENSION_MANAGER_CLIENT_H
82