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 <ianimation_service.h> 17 18 #include <gslogger.h> 19 #include <iservice_registry.h> 20 #include <system_ability_definition.h> 21 22 namespace OHOS { 23 namespace { 24 DEFINE_HILOG_LABEL("IAnimationService"); 25 } // namespace 26 Init(bool reinit)27GSError IAnimationService::Init(bool reinit) 28 { 29 if (animationService != nullptr && reinit == false) { 30 return GSERROR_OK; 31 } 32 33 auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 34 if (sam == nullptr) { 35 GSLOG2HI(ERROR) << "SystemAbilityManager is nullptr"; 36 return GSERROR_CONNOT_CONNECT_SAMGR; 37 } 38 39 auto robj = sam->GetSystemAbility(ANIMATION_SERVER_SA_ID); 40 if (robj == nullptr) { 41 GSLOG2HI(ERROR) << "Remote Object is nullptr"; 42 return GSERROR_CONNOT_CONNECT_SERVER; 43 } 44 45 animationService = iface_cast<IAnimationService>(robj); 46 if (animationService == nullptr) { 47 GSLOG2HI(ERROR) << "Cannot find proxy"; 48 return GSERROR_PROXY_NOT_INCLUDE; 49 } 50 51 return GSERROR_OK; 52 } 53 Get()54sptr<IAnimationService> IAnimationService::Get() 55 { 56 return animationService; 57 } 58 } // namespace OHOS 59