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 #ifndef SECURITY_COMPONENT_MOCK_ABILITY_RUNTIME_APPLICATION_STATE_OBSERVER_STUB_H 16 #define SECURITY_COMPONENT_MOCK_ABILITY_RUNTIME_APPLICATION_STATE_OBSERVER_STUB_H 17 18 #include <map> 19 #include <mutex> 20 21 #include "iremote_stub.h" 22 #include "nocopyable.h" 23 #include "string_ex.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 enum class AppProcessState { 28 APP_STATE_BEGIN = 0, 29 APP_STATE_CREATE = APP_STATE_BEGIN, 30 APP_STATE_READY, 31 APP_STATE_FOREGROUND, 32 APP_STATE_FOCUS, 33 APP_STATE_BACKGROUND, 34 APP_STATE_TERMINATED, 35 APP_STATE_END, 36 }; 37 38 struct ProcessData { 39 std::string bundleName; 40 int32_t pid = 0; 41 int32_t uid = 0; 42 AppProcessState state; 43 bool isContinuousTask = false; 44 bool isKeepAlive = false; 45 bool isFocused = false; 46 int32_t requestProcCode = 0; 47 }; 48 49 struct AppStateData { 50 std::string bundleName; 51 int32_t pid = -1; 52 int32_t uid = 0; 53 int32_t state = 0; 54 int32_t accessTokenId = 0; 55 bool isFocused = false; 56 }; 57 58 class IApplicationStateObserver : public IRemoteBroker { 59 public: 60 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IApplicationStateObserver"); OnProcessStateChanged(const ProcessData & processData)61 virtual void OnProcessStateChanged(const ProcessData &processData) {} 62 virtual void OnProcessDied(const ProcessData &processData) = 0; 63 virtual void OnAppCacheStateChanged(const AppStateData &appStateData) = 0; 64 }; 65 66 class ApplicationStateObserverStub : public IRemoteStub<IApplicationStateObserver> { 67 public: 68 ApplicationStateObserverStub() = default; 69 virtual ~ApplicationStateObserverStub() = default; 70 DISALLOW_COPY_AND_MOVE(ApplicationStateObserverStub); 71 }; 72 } // namespace AppExecFwk 73 } // namespace OHOS 74 #endif // SECURITY_COMPONENT_MOCK_ABILITY_RUNTIME_APPLICATION_STATE_OBSERVER_STUB_H 75