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 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 bool ExecuteCmd(const std::string &cmd, std::string &result); 51 static pid_t GetImsaPid(); 52 static void KillImsaProcess(); 53 static void PushEnableImeValue(const std::string &key, const std::string &value); 54 static void GrantNativePermission(); 55 static int32_t GetEnableData(std::string &value); 56 static void InitWindow(bool isShow); 57 static void DestroyWindow(); 58 static bool GetFocused(); 59 static bool GetUnfocused(); 60 class WindowManager { 61 public: 62 static void CreateWindow(); 63 static void ShowWindow(); 64 static void HideWindow(); 65 static void DestroyWindow(); 66 static void RegisterFocusChangeListener(); 67 static int32_t currentWindowId_; 68 69 private: 70 static sptr<Rosen::Window> window_; 71 }; 72 73 private: 74 static sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr(); 75 static int GetUserIdByBundleName(const std::string &bundleName, const int currentUserId); 76 static uint64_t selfTokenID_; 77 static uint64_t testTokenID_; 78 static int32_t userID_; 79 }; 80 } // namespace MiscServices 81 } // namespace OHOS 82 #endif // INPUTMETHOD_UNITTEST_UTIL_H