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 UI_EXTENSION_ABILITY_CONNECTION_H
17 #define UI_EXTENSION_ABILITY_CONNECTION_H
18 
19 #include "ability_connection.h"
20 #include "ability_connect_callback_interface.h"
21 #include "ability_connect_callback_stub.h"
22 #include "iremote_object.h"
23 #include "iremote_proxy.h"
24 #include "message_parcel.h"
25 #include "nocopyable.h"
26 
27 #include "iam_hitrace_helper.h"
28 #include "iam_ptr.h"
29 
30 namespace OHOS {
31 namespace UserIam {
32 namespace UserAuth {
33 class UIExtensionAbilityConnection : public AAFwk::AbilityConnectionStub {
34 public:
UIExtensionAbilityConnection(const std::string commandStr)35     UIExtensionAbilityConnection(const std::string commandStr)
36     {
37         commandStr_ = commandStr;
38         connectAbilityHitrace_ = Common::MakeShared<IamHitraceHelper>("ConnectAbilityStart");
39     }
40 
41     virtual ~UIExtensionAbilityConnection() = default;
42 
43     void OnAbilityConnectDone(const AppExecFwk::ElementName &element,
44         const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override;
45     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override;
46     void ReleaseUIExtensionComponent();
47 
48 private:
49     void ReleaseUIExtensionComponentInner();
50 
51     std::string commandStr_;
52     std::shared_ptr<IamHitraceHelper> connectAbilityHitrace_ {nullptr};
53     sptr<IRemoteObject> extRemoteObject_ {nullptr};
54     std::recursive_mutex mutex_;
55     bool isConnectionRelease_ {true};
56 };
57 } // namespace UserAuth
58 } // namespace UserIam
59 } // namespace OHOS
60 #endif // UI_EXTENSION_ABILITY_CONNECTION_H