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_NFC_APP_STATE_OBSERVER_H 17 #define OHOS_NFC_APP_STATE_OBSERVER_H 18 19 #include "app_mgr_interface.h" 20 #include "application_state_observer_stub.h" 21 #include "iremote_object.h" 22 #include "infc_app_state_observer.h" 23 24 namespace OHOS { 25 namespace NFC { 26 class AppMgrDeathRecipient : public IRemoteObject::DeathRecipient { 27 void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject> &remote) override; 28 }; 29 30 class AppStateObserver { 31 public: 32 explicit AppStateObserver(INfcAppStateObserver *nfcAppStateChangeCallback); 33 ~AppStateObserver(); 34 AppStateObserver(const AppStateObserver &) = delete; 35 AppStateObserver &operator=(const AppStateObserver &) = delete; 36 bool SubscribeAppState(); 37 bool UnSubscribeAppState(); 38 bool IsForegroundApp(const std::string &bundleName); 39 40 private: 41 class AppStateAwareObserver : public AppExecFwk::ApplicationStateObserverStub { 42 public: 43 void OnProcessDied(const AppExecFwk::ProcessData &processData) override; 44 void OnAbilityStateChanged(const AppExecFwk::AbilityStateData &abilityStateData) override; 45 void OnForegroundApplicationChanged(const AppExecFwk::AppStateData &appStateData) override; 46 bool RegisterAppStateChangeCallback(INfcAppStateObserver *nfcAppStateChangeCallback); 47 48 private: 49 INfcAppStateObserver *nfcAppStateChangeCallback_; 50 }; 51 bool Connect(); 52 bool RegisterAppStateChangeCallback(INfcAppStateObserver *nfcAppStateChangeCallback); 53 54 private: 55 sptr<AppStateAwareObserver> appStateAwareObserver_; 56 }; 57 } //namespace NFC 58 } // namespace OHOS 59 #endif // OHOS_NFC_APP_STATE_OBSERVER_H