• 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_JS_FREE_INSTALL_OBSERVER_H
17 #define OHOS_ABILITY_RUNTIME_JS_FREE_INSTALL_OBSERVER_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "native_engine/native_engine.h"
24 #include "free_install_observer_stub.h"
25 
26 namespace OHOS {
27 namespace AbilityRuntime {
28 struct JsFreeInstallObserverObject {
29     std::string bundleName;
30     std::string abilityName;
31     std::string startTime;
32     std::shared_ptr<NativeReference> callback;
33     bool isAbilityResult = false;
34 };
35 
36 class JsFreeInstallObserver : public FreeInstallObserverStub {
37 public:
38     explicit JsFreeInstallObserver(NativeEngine& engine);
39     ~JsFreeInstallObserver();
40 
41     /**
42      * OnInstallFinished, return free install result.
43      *
44      * @param bundleName Free install bundleName.
45      * @param abilityName Free install abilityName.
46      * @param startTime Free install start request time.
47      * @param resultCode The result of this free install.
48      */
49     void OnInstallFinished(const std::string &bundleName, const std::string &abilityName,
50         const std::string &startTime, const int &resultCode) override;
51 
52     /**
53      * @brief Use for context to add an callback into the observer.
54      *
55      * @param bundleName The bundleName of want.
56      * @param abilityName The abilityName of want.
57      * @param startTime The startTime that want requested.
58      * @param jsObserverObject The js object instance.
59      */
60     void AddJsObserverObject(const std::string &bundleName, const std::string &abilityName,
61         const std::string &startTime, NativeValue* jsObserverObject, bool isAbilityResult = false);
62 private:
63     void CallJsFunction(NativeValue* value, NativeValue* const *argv, size_t argc);
64     void HandleOnInstallFinished(const std::string &bundleName, const std::string &abilityName,
65         const std::string &startTime, const int &resultCode);
66     NativeEngine& engine_;
67     std::vector<JsFreeInstallObserverObject> jsObserverObjectList_;
68 };
69 } // namespace AbilityRuntime
70 } // namespace OHOS
71 
72 #endif // OHOS_ABILITY_RUNTIME_JS_FREE_INSTALL_OBSERVER_H