1 /*
2  * Copyright (c) 2022 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 FOUNDATION_ABILITY_FORM_FWK_SERVICES_INCLUDE_FORM_FREE_INSTALL_OPERATOR_H
17 #define FOUNDATION_ABILITY_FORM_FWK_SERVICES_INCLUDE_FORM_FREE_INSTALL_OPERATOR_H
18 
19 #include "form_event_handler.h"
20 #include "form_serial_queue.h"
21 #include "free_install_status_callback_stub.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 class FreeInstallStatusCallBack;
26 /**
27  * @class FormFreeInstallOperator
28  * Free install operator class.
29  */
30 class FormFreeInstallOperator final : public std::enable_shared_from_this<FormFreeInstallOperator> {
31 public:
32     FormFreeInstallOperator(const std::string &formShareInfoKey,
33         const std::shared_ptr<FormSerialQueue> &serialQueue);
34     ~FormFreeInstallOperator();
35 
36     int32_t StartFreeInstall(
37         const std::string &bundleName, const std::string &moduleName, const std::string &abilityName);
38     void OnInstallFinished(int32_t resultCode);
39 
40 private:
41     std::string formShareInfoKey_;
42     sptr<FreeInstallStatusCallBack> freeInstallStatusCallBack_ = nullptr;
43     std::shared_ptr<FormSerialQueue> serialQueue_ = nullptr;
44 };
45 
46 class FreeInstallStatusCallBack final : public FreeInstallStatusCallBackStub {
47 public:
48     FreeInstallStatusCallBack(const std::weak_ptr<FormFreeInstallOperator> &freeInstallOperator);
49     virtual ~FreeInstallStatusCallBack() = default;
50 
51     /**
52      * Callback triggered by free installation completion.
53      *
54      * @param resultCode, ERR_OK on success, others on failure.
55      * @param want Indicates the ability to free install.
56      * @param userId, user`s id.
57      */
58     void OnInstallFinished(int32_t resultCode, const Want &want, int32_t userId) override;
59 
60 private:
61     std::weak_ptr<FormFreeInstallOperator> formFreeInstallOperator_;
62 };
63 } // namespace AppExecFwk
64 } // namespace OHOS
65 #endif // FOUNDATION_ABILITY_FORM_FWK_SERVICES_INCLUDE_FORM_FREE_INSTALL_OPERATOR_H
66