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 "foundation/window/window_manager/interfaces/innerkits/wm/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 int32_t GetCurrentUserId(); 43 static void StorageSelfTokenID(); 44 static uint64_t AllocTestTokenID( 45 bool isSystemApp, const std::string &bundleName, const std::vector<std::string> &premission = {}); 46 static uint64_t GetTestTokenID(const std::string &bundleName); 47 static void DeleteTestTokenID(uint64_t tokenId); 48 static void SetTestTokenID(uint64_t tokenId); 49 static void RestoreSelfTokenID(); 50 static uint64_t GetCurrentTokenID(); 51 static int32_t GetUid(const std::string &bundleName); 52 static void SetSelfUid(int32_t uid); 53 static bool ExecuteCmd(const std::string &cmd, std::string &result); 54 static pid_t GetImsaPid(); 55 static bool KillImsaProcess(); 56 static void PushEnableImeValue(const std::string &key, const std::string &value); 57 static void GrantNativePermission(); 58 static int32_t GetEnableData(std::string &value); 59 static void InitWindow(bool isShow); 60 static void DestroyWindow(); 61 static bool GetFocused(); 62 static bool GetUnfocused(); 63 static void InitCurrentImePermissionInfo(); 64 static std::string currentBundleNameMock_; 65 class WindowManager { 66 public: 67 static void CreateWindow(); 68 static void ShowWindow(); 69 static void HideWindow(); 70 static void DestroyWindow(); 71 static void RegisterFocusChangeListener(); 72 static int32_t currentWindowId_; 73 74 private: 75 static sptr<Rosen::Window> window_; 76 static uint64_t windowTokenId_; 77 }; 78 79 private: 80 static sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr(); 81 static int GetUserIdByBundleName(const std::string &bundleName, const int currentUserId); 82 static uint64_t selfTokenID_; 83 static uint64_t testTokenID_; 84 static int32_t userID_; 85 }; 86 } // namespace MiscServices 87 } // namespace OHOS 88 #endif // INPUTMETHOD_UNITTEST_UTIL_H