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 INPUTMETHOD_UNITTEST_UTIL_H 17 #define INPUTMETHOD_UNITTEST_UTIL_H 18 19 #include <string> 20 21 #include "block_data.h" 22 #include "bundle_mgr_interface.h" 23 #include "window.h" 24 #include "window_manager.h" 25 #include "window_option.h" 26 #include "wm_common.h" 27 28 namespace OHOS { 29 namespace MiscServices { 30 class FocusChangedListenerTestImpl : public Rosen::IFocusChangedListener { 31 public: 32 FocusChangedListenerTestImpl() = default; 33 ~FocusChangedListenerTestImpl() = default; 34 void OnFocused(const sptr<Rosen::FocusChangeInfo> &focusChangeInfo) override; 35 void OnUnfocused(const sptr<Rosen::FocusChangeInfo> &focusChangeInfo) override; 36 bool getFocus_ = false; 37 static std::shared_ptr<BlockData<bool>> isFocused_; 38 static std::shared_ptr<BlockData<bool>> unFocused_; 39 }; 40 class TddUtil { 41 public: 42 static void StorageSelfTokenID(); 43 static uint64_t AllocTestTokenID(bool isSystemApp, bool needPermission, const std::string &bundleName); 44 static uint64_t GetTestTokenID(const std::string &bundleName); 45 static void DeleteTestTokenID(uint64_t tokenId); 46 static void SetTestTokenID(uint64_t tokenId); 47 static void RestoreSelfTokenID(); 48 static bool ExecuteCmd(const std::string &cmd, std::string &result); 49 static pid_t GetImsaPid(); 50 static void KillImsaProcess(); 51 class WindowManager { 52 public: 53 static void CreateWindow(); 54 static void ShowWindow(); 55 static void HideWindow(); 56 static void DestroyWindow(); 57 static void RegisterFocusChangeListener(); 58 static int32_t currentWindowId_; 59 60 private: 61 static sptr<Rosen::Window> window_; 62 }; 63 64 private: 65 static int32_t GetCurrentUserId(); 66 static sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr(); 67 static int GetUserIdByBundleName(const std::string &bundleName, const int currentUserId); 68 static uint64_t selfTokenID_; 69 static uint64_t testTokenID_; 70 static int32_t userID_; 71 }; 72 } // namespace MiscServices 73 } // namespace OHOS 74 #endif // INPUTMETHOD_UNITTEST_UTIL_H