1 /* 2 * Copyright (c) 2020 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 "client/wms_client.h" 17 18 #include "ohos_errno.h" 19 #include "iproxy_client.h" 20 #ifdef ABILITY_WINDOW_SUPPORT 21 #include "lite_wm_type.h" 22 #endif 23 #include "liteipc_adapter.h" 24 #include "samgr_lite.h" 25 #include "util/abilityms_log.h" 26 27 namespace OHOS { 28 #ifdef ABILITY_WINDOW_SUPPORT 29 namespace { 30 const unsigned long RETRY_SLEEP_TIMES = 200000; // sleep 200ms 31 } 32 WaitUntilWmsReady()33void WMSClient::WaitUntilWmsReady() 34 { 35 PRINTI("WMSClient", "wait for window manager service start"); 36 IClientProxy *wmsProxy = nullptr; 37 while (wmsProxy == nullptr) { 38 IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SERVICE_NAME); 39 if (iUnknown == nullptr) { 40 usleep(RETRY_SLEEP_TIMES); 41 continue; 42 } 43 int result = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)(&wmsProxy)); 44 if (result != EC_SUCCESS || wmsProxy == nullptr) { 45 usleep(RETRY_SLEEP_TIMES); 46 continue; 47 } 48 } 49 PRINTI("WMSClient", "get window manager service proxy success"); 50 wmsProxy->Release(reinterpret_cast<IUnknown *>(wmsProxy)); 51 } 52 #endif 53 } // namespace OHOS 54