10826e83eSopenharmony_ci/*
20826e83eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
30826e83eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40826e83eSopenharmony_ci * you may not use this file except in compliance with the License.
50826e83eSopenharmony_ci * You may obtain a copy of the License at
60826e83eSopenharmony_ci *
70826e83eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80826e83eSopenharmony_ci *
90826e83eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100826e83eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110826e83eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120826e83eSopenharmony_ci * See the License for the specific language governing permissions and
130826e83eSopenharmony_ci * limitations under the License.
140826e83eSopenharmony_ci */
150826e83eSopenharmony_ci
160826e83eSopenharmony_ci#ifndef OHOS_NWEB_APP_FWK_UPDATE_CLIENT_H
170826e83eSopenharmony_ci#define OHOS_NWEB_APP_FWK_UPDATE_CLIENT_H
180826e83eSopenharmony_ci
190826e83eSopenharmony_ci#include <condition_variable>
200826e83eSopenharmony_ci#include <functional>
210826e83eSopenharmony_ci#include <mutex>
220826e83eSopenharmony_ci#include <set>
230826e83eSopenharmony_ci#include <string>
240826e83eSopenharmony_ci
250826e83eSopenharmony_ci#include "singleton.h"
260826e83eSopenharmony_ci
270826e83eSopenharmony_ci#include "base/web/webview/sa/iapp_fwk_update_service.h"
280826e83eSopenharmony_ci
290826e83eSopenharmony_cinamespace OHOS::NWeb {
300826e83eSopenharmony_ciclass AppFwkUpdateClient {
310826e83eSopenharmony_cipublic:
320826e83eSopenharmony_ci    AppFwkUpdateClient();
330826e83eSopenharmony_ci    virtual ~AppFwkUpdateClient() = default;
340826e83eSopenharmony_ci    static AppFwkUpdateClient& GetInstance();
350826e83eSopenharmony_ci    int VerifyPackageInstall(const std::string& bundleName, const std::string& hapPath);
360826e83eSopenharmony_ci
370826e83eSopenharmony_ci    void OnLoadSystemAbilitySuccess(const sptr<IRemoteObject>& object);
380826e83eSopenharmony_ci    void OnLoadSystemAbilityFail();
390826e83eSopenharmony_ci    void AppFwkUpdateOnRemoteDied(const wptr<IRemoteObject>& remoteObject);
400826e83eSopenharmony_ci
410826e83eSopenharmony_ciprivate:
420826e83eSopenharmony_ci    bool LoadFwkService();
430826e83eSopenharmony_ci    void SetFwkUpdate(const sptr<IRemoteObject>& remoteObject);
440826e83eSopenharmony_ci    sptr<IAppFwkUpdateService> GetFwkUpdate();
450826e83eSopenharmony_ci    sptr<IAppFwkUpdateService> GetFwkUpdateProxy();
460826e83eSopenharmony_ci    class AppFwkUpdateDiedRecipient : public IRemoteObject::DeathRecipient {
470826e83eSopenharmony_ci    public:
480826e83eSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
490826e83eSopenharmony_ci    };
500826e83eSopenharmony_ci
510826e83eSopenharmony_ciprivate:
520826e83eSopenharmony_ci    std::condition_variable loadSaCondition_;
530826e83eSopenharmony_ci    std::mutex loadSaMutex_;
540826e83eSopenharmony_ci    bool loadSaFinished_ { false };
550826e83eSopenharmony_ci    std::mutex mutex_;
560826e83eSopenharmony_ci    sptr<IAppFwkUpdateService> fwkUpdateProxy_ = nullptr;
570826e83eSopenharmony_ci    sptr<AppFwkUpdateDiedRecipient> appFwkUpdateDiedRecipient_ = nullptr;
580826e83eSopenharmony_ci    DISALLOW_COPY_AND_MOVE(AppFwkUpdateClient);
590826e83eSopenharmony_ci};
600826e83eSopenharmony_ci} // namespace OHOS::NWeb
610826e83eSopenharmony_ci#endif // OHOS_NWEB_APP_FWK_UPDATE_CLIENT_H