1 /* 2 * Copyright (c) 2025 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 #ifndef OHOS_ABILITY_RUNTIME_ETS_FREE_INSTALL_OBSERVER_H 16 #define OHOS_ABILITY_RUNTIME_ETS_FREE_INSTALL_OBSERVER_H 17 18 #include <memory> 19 #include <string> 20 #include <vector> 21 22 #include "ets_error_utils.h" 23 #include "ets_runtime.h" 24 #include "free_install_observer_stub.h" 25 26 namespace OHOS { 27 namespace AbilityRuntime { 28 struct EtsFreeInstallObserverObject { 29 std::string bundleName; 30 std::string abilityName; 31 std::string startTime; 32 std::string url; 33 ani_object callback = nullptr; 34 bool isAbilityResult = false; 35 }; 36 37 class EtsFreeInstallObserver : public FreeInstallObserverStub { 38 public: 39 explicit EtsFreeInstallObserver(ani_vm *etsVm); 40 virtual ~EtsFreeInstallObserver(); 41 42 void OnInstallFinished(const std::string &bundleName, const std::string &abilityName, const std::string &startTime, 43 int32_t resultCode) override; 44 void OnInstallFinished(const std::string &bundleName, const std::string &abilityName, const std::string &startTime, 45 ani_object abilityResult); 46 void OnInstallFinishedByUrl(const std::string &startTime, const std::string &url, int32_t resultCode) override; 47 void AddEtsObserverObject(ani_env *env, const std::string &bundleName, const std::string &abilityName, 48 const std::string &startTime, ani_object callback, bool isAbilityResult = false); 49 void AddEtsObserverObject(ani_env *env, const std::string &startTime, 50 const std::string &url, ani_object callback, bool isAbilityResult = false); 51 52 private: 53 void CallCallback(ani_object callback, int32_t resultCode); 54 void CallCallback(ani_object callback, ani_object abilityResult); 55 void HandleOnInstallFinished(const std::string &bundleName, const std::string &abilityName, 56 const std::string &startTime, int32_t resultCode); 57 void HandleOnInstallFinishedByUrl(const std::string &startTime, const std::string &url, int32_t resultCode); 58 void AddEtsObserverCommon(ani_env *env, EtsFreeInstallObserverObject &object, ani_object callback); 59 60 ani_vm *etsVm_ = nullptr; 61 std::mutex etsObserverObjectListLock_; 62 std::vector<EtsFreeInstallObserverObject> etsObserverObjectList_; 63 }; 64 } // namespace AbilityRuntime 65 } // namespace OHOS 66 67 #endif // OHOS_ABILITY_RUNTIME_ETS_FREE_INSTALL_OBSERVER_H