1 /* 2 * Copyright (C) 2021 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 "global.h" 17 #include "platform.h" 18 #include "platform_callback_stub.h" 19 20 namespace OHOS { 21 namespace MiscServices { SetPlatform(const sptr<IPlatformApi> & platformApi)22 void Platform::SetPlatform(const sptr < IPlatformApi >& platformApi) 23 { 24 this->platformApi = platformApi; 25 sptr < IPlatformCallback > cb = new PlatformCallbackStub(); 26 this->platformApi->registerCallback(cb); 27 } 28 29 /*! Constructor 30 */ Platform()31 Platform::Platform() 32 { 33 } 34 35 /*! Destructor 36 */ ~Platform()37 Platform::~Platform() 38 { 39 } 40 41 /*! Single instance exists in the service 42 */ Instance()43 Platform *Platform::Instance() 44 { 45 static Platform *platform = nullptr; 46 if (platform == nullptr) { 47 platform = new Platform(); 48 } 49 return platform; 50 } 51 52 /*! Start an input method service 53 \param userId the id of the given user. 54 \param packageName the packageName of the given input method engine which is going to start 55 \param intention the intention to start the service 56 \return the remote object handler of started input method service. 57 */ BindInputMethodService(int userId,const std::u16string & packageName,const std::u16string & intention)58 sptr<IInputMethodCore> Platform::BindInputMethodService(int userId, const std::u16string& packageName, 59 const std::u16string& intention) 60 { 61 if (platformApi == nullptr) { 62 return nullptr; 63 } 64 return platformApi->bindInputMethodService(packageName, intention, userId); 65 } 66 67 /*! Stop an input method service 68 \param userId the id of the given user. 69 \param packageName the packageName of the given input method engine which is going to stop 70 \return ErrorCode 71 */ UnbindInputMethodService(int userId,const std::u16string & packageName)72 int Platform::UnbindInputMethodService(int userId, const std::u16string& packageName) 73 { 74 if (platformApi == nullptr) { 75 return ErrorCode::ERROR_NULL_POINTER; 76 } 77 return platformApi->unbindInputMethodService(userId, packageName); 78 } 79 80 /*! Create window token 81 \param userId the id of the given user. 82 \param displayId the id of display screen 83 \param packageName the packageName of the given input method engine 84 \return ErrorCode 85 */ CreateWindowToken(int userId,int displayId,const std::u16string & packageName)86 sptr < IRemoteObject > Platform::CreateWindowToken(int userId, int displayId, const std::u16string& packageName) 87 { 88 if (platformApi == nullptr) { 89 return nullptr; 90 } 91 return platformApi->createWindowToken(userId, displayId, packageName); 92 } 93 94 /*! Destroy window token 95 \param userId the id of the given user. 96 \param packageName the packageName of the given input method engine 97 \return ErrorCode 98 */ DestroyWindowToken(int userId,const std::u16string & packageName)99 int Platform::DestroyWindowToken(int userId, const std::u16string& packageName) 100 { 101 if (platformApi == nullptr) { 102 return ErrorCode::ERROR_NULL_POINTER; 103 } 104 return platformApi->destroyWindowToken(userId, packageName); 105 } 106 107 /*! Get all the installed input method engines for the given user 108 \param userId the id of the given user. 109 \param[out] inputMethodProperties the input method engine list installed in the system for the given user 110 \return ErrorCode 111 */ ListInputMethod(int userId,std::vector<InputMethodProperty * > * inputMethodProperties)112 int Platform::ListInputMethod(int userId, std::vector<InputMethodProperty*> *inputMethodProperties) 113 { 114 return 0; 115 } 116 117 /*! Get input method engine information of the given package for the given user 118 \param userId the id of the given user. 119 \param packageName the given package name for which to get input method engine information 120 \param[out] inputMethodProperty the input method engine information for the given package 121 \return ErrorCode 122 */ GetInputMethodProperty(int userId,const std::u16string & packageName,InputMethodProperty * inputMethodProperty)123 int Platform::GetInputMethodProperty(int userId, const std::u16string& packageName, 124 InputMethodProperty *inputMethodProperty) 125 { 126 if (platformApi == nullptr) { 127 return ErrorCode::ERROR_NULL_POINTER; 128 } 129 return platformApi->getInputMethodProperty(userId, packageName, inputMethodProperty); 130 } 131 132 /*! Get the input method setting data for the given user 133 \param userId the id of the given user 134 \param[out] inputMethodSetting the input method setting data for the given user 135 \return ErrorCode 136 */ 137 GetInputMethodSetting(int userId,InputMethodSetting * inputMethodSetting)138 int Platform::GetInputMethodSetting(int userId, InputMethodSetting *inputMethodSetting) 139 { 140 return 0; 141 } 142 143 /*! Set the input method setting data for the given user 144 \param userId the id of the given user 145 \param inputMethodSetting the input method setting data for the given user 146 \return ErrorCode 147 */ SetInputMethodSetting(int userId,const InputMethodSetting & inputMethodSetting)148 int Platform::SetInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting) 149 { 150 if (platformApi == nullptr) { 151 return ErrorCode::ERROR_NULL_POINTER; 152 } 153 return platformApi->setInputMethodSetting(userId, inputMethodSetting); 154 } 155 156 /*! Check if a physical keyboard is connected to the system 157 \return true - a physical keyboard is connected 158 \n false - no physical keyboard 159 */ CheckPhysicalKeyboard()160 bool Platform::CheckPhysicalKeyboard() 161 { 162 return true; 163 } 164 165 /*! Check if the remote caller is from a valid window 166 \return true - the remote caller is from a valid window 167 \n false - the remote caller is not from a valid window 168 */ IsValidWindow(int uid,int pid,int displayId)169 bool Platform::IsValidWindow(int uid, int pid, int displayId) 170 { 171 (void)uid; 172 (void)pid; 173 (void)displayId; 174 return true; 175 } 176 177 /*! Check if the remote caller is from a focused window 178 \return true - the remote caller is from a focused window 179 \n false - the remote caller is not from a focused window 180 */ IsWindowFocused(int uid,int pid,int displayId)181 bool Platform::IsWindowFocused(int uid, int pid, int displayId) 182 { 183 (void)uid; 184 (void)pid; 185 (void)displayId; 186 return true; 187 } 188 } 189 }