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 #include "mock_app_mgr_service.h" 17 #include <gtest/gtest.h> 18 19 namespace OHOS { 20 namespace AppExecFwk { GetForegroundApplications(std::vector<AppStateData> & list)21int32_t MockAppMgrService::GetForegroundApplications(std::vector<AppStateData> &list) 22 { 23 AppStateData data; 24 data.bundleName = "ohos.test.access_token"; 25 data.pid = 0; 26 data.accessTokenId = 0; 27 data.state = 1; 28 list.emplace_back(data); 29 return 0; 30 } 31 RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer,const std::vector<std::string> & bundleNameList)32int32_t MockAppMgrService::RegisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer, 33 const std::vector<std::string>& bundleNameList) 34 { 35 if (observer == nullptr || observer == observer_) { 36 return -1; 37 } 38 GTEST_LOG_(INFO) << "register: " << observer; 39 observer_ = observer; 40 return 0; 41 } 42 UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer)43int32_t MockAppMgrService::UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver>& observer) 44 { 45 if (observer == nullptr || observer != observer_) { 46 return -1; 47 } 48 GTEST_LOG_(INFO) << "unregister: " << observer; 49 observer_ = nullptr; 50 return 0; 51 } 52 SwitchForeOrBackGround(uint32_t tokenId,int32_t flag)53void MockAppMgrService::SwitchForeOrBackGround(uint32_t tokenId, int32_t flag) 54 { 55 if (observer_ == nullptr) { 56 return; 57 } 58 AppStateData data; 59 data.bundleName = "ohos.test.access_token"; 60 data.pid = 0; 61 data.accessTokenId = tokenId; 62 data.state = flag; 63 observer_->OnForegroundApplicationChanged(data); 64 } 65 } 66 }