1 /* 2 * Copyright (c) 2022 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_APP_MANAGER_PRIVACY_PROXY_H 17 #define OHOS_APP_MANAGER_PRIVACY_PROXY_H 18 19 #include <iremote_proxy.h> 20 #include "app_state_data.h" 21 22 namespace OHOS { 23 namespace Security { 24 namespace AccessToken { 25 class IApplicationStateObserver : public IRemoteBroker { 26 public: 27 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IApplicationStateObserver"); 28 29 virtual void OnForegroundApplicationChanged(const AppStateData &appStateData) = 0; 30 31 enum class Message { 32 TRANSACT_ON_FOREGROUND_APPLICATION_CHANGED = 0, 33 }; 34 }; 35 36 class IAppMgr : public IRemoteBroker { 37 public: 38 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.AppMgr"); 39 40 virtual int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer, 41 const std::vector<std::string>& bundleNameList = {}) = 0; 42 virtual int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer) = 0; 43 virtual int32_t GetForegroundApplications(std::vector<AppStateData>& list) = 0; 44 45 enum class Message { 46 REGISTER_APPLICATION_STATE_OBSERVER = 12, 47 UNREGISTER_APPLICATION_STATE_OBSERVER = 13, 48 GET_FOREGROUND_APPLICATIONS = 14, 49 }; 50 }; 51 52 class AppManagerPrivacyProxy : public IRemoteProxy<IAppMgr> { 53 public: AppManagerPrivacyProxy(const sptr<IRemoteObject> & impl)54 explicit AppManagerPrivacyProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IAppMgr>(impl) {}; 55 56 virtual ~AppManagerPrivacyProxy() = default; 57 58 int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer, 59 const std::vector<std::string> &bundleNameList = {}) override; 60 int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer) override; 61 int32_t GetForegroundApplications(std::vector<AppStateData>& list) override; 62 private: 63 static inline BrokerDelegator<AppManagerPrivacyProxy> delegator_; 64 }; 65 } 66 } 67 } 68 #endif // OHOS_APP_MANAGER_PRIVACY_PROXY_H 69