1bc2ed2b3Sopenharmony_ci/*
2bc2ed2b3Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License.
5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at
6bc2ed2b3Sopenharmony_ci *
7bc2ed2b3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bc2ed2b3Sopenharmony_ci *
9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and
13bc2ed2b3Sopenharmony_ci * limitations under the License.
14bc2ed2b3Sopenharmony_ci */
15bc2ed2b3Sopenharmony_ci
16bc2ed2b3Sopenharmony_ci#ifndef OHOS_NFC_APP_STATE_OBSERVER_H
17bc2ed2b3Sopenharmony_ci#define OHOS_NFC_APP_STATE_OBSERVER_H
18bc2ed2b3Sopenharmony_ci
19bc2ed2b3Sopenharmony_ci#include "app_mgr_interface.h"
20bc2ed2b3Sopenharmony_ci#include "application_state_observer_stub.h"
21bc2ed2b3Sopenharmony_ci#include "iremote_object.h"
22bc2ed2b3Sopenharmony_ci#include "infc_app_state_observer.h"
23bc2ed2b3Sopenharmony_ci
24bc2ed2b3Sopenharmony_cinamespace OHOS {
25bc2ed2b3Sopenharmony_cinamespace NFC {
26bc2ed2b3Sopenharmony_ciclass AppMgrDeathRecipient : public IRemoteObject::DeathRecipient {
27bc2ed2b3Sopenharmony_ci    void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject> &remote) override;
28bc2ed2b3Sopenharmony_ci};
29bc2ed2b3Sopenharmony_ci
30bc2ed2b3Sopenharmony_ciclass AppStateObserver {
31bc2ed2b3Sopenharmony_cipublic:
32bc2ed2b3Sopenharmony_ci    explicit AppStateObserver(INfcAppStateObserver *nfcAppStateChangeCallback);
33bc2ed2b3Sopenharmony_ci    ~AppStateObserver();
34bc2ed2b3Sopenharmony_ci    AppStateObserver(const AppStateObserver &) = delete;
35bc2ed2b3Sopenharmony_ci    AppStateObserver &operator=(const AppStateObserver &) = delete;
36bc2ed2b3Sopenharmony_ci    bool SubscribeAppState();
37bc2ed2b3Sopenharmony_ci    bool UnSubscribeAppState();
38bc2ed2b3Sopenharmony_ci    bool IsForegroundApp(const std::string &bundleName);
39bc2ed2b3Sopenharmony_ci
40bc2ed2b3Sopenharmony_ciprivate:
41bc2ed2b3Sopenharmony_ci    class AppStateAwareObserver : public AppExecFwk::ApplicationStateObserverStub {
42bc2ed2b3Sopenharmony_ci    public:
43bc2ed2b3Sopenharmony_ci        void OnProcessDied(const AppExecFwk::ProcessData &processData) override;
44bc2ed2b3Sopenharmony_ci        void OnAbilityStateChanged(const AppExecFwk::AbilityStateData &abilityStateData) override;
45bc2ed2b3Sopenharmony_ci        void OnForegroundApplicationChanged(const AppExecFwk::AppStateData &appStateData) override;
46bc2ed2b3Sopenharmony_ci        bool RegisterAppStateChangeCallback(INfcAppStateObserver *nfcAppStateChangeCallback);
47bc2ed2b3Sopenharmony_ci
48bc2ed2b3Sopenharmony_ci    private:
49bc2ed2b3Sopenharmony_ci        INfcAppStateObserver *nfcAppStateChangeCallback_;
50bc2ed2b3Sopenharmony_ci    };
51bc2ed2b3Sopenharmony_ci    bool Connect();
52bc2ed2b3Sopenharmony_ci    bool RegisterAppStateChangeCallback(INfcAppStateObserver *nfcAppStateChangeCallback);
53bc2ed2b3Sopenharmony_ci
54bc2ed2b3Sopenharmony_ciprivate:
55bc2ed2b3Sopenharmony_ci    sptr<AppStateAwareObserver> appStateAwareObserver_;
56bc2ed2b3Sopenharmony_ci};
57bc2ed2b3Sopenharmony_ci} //namespace NFC
58bc2ed2b3Sopenharmony_ci} // namespace OHOS
59bc2ed2b3Sopenharmony_ci#endif // OHOS_NFC_APP_STATE_OBSERVER_H