• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "ability_impl_factory.h"
17 #include "data_ability_impl.h"
18 #include "hilog_wrapper.h"
19 #include "new_ability_impl.h"
20 #ifdef SUPPORT_GRAPHICS
21 #include "page_ability_impl.h"
22 #endif
23 #include "service_ability_impl.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
AbilityImplFactory()27 AbilityImplFactory::AbilityImplFactory() {}
28 
~AbilityImplFactory()29 AbilityImplFactory::~AbilityImplFactory() {}
30 
MakeAbilityImplObject(const std::shared_ptr<AbilityInfo> & info)31 std::shared_ptr<AbilityImpl> AbilityImplFactory::MakeAbilityImplObject(const std::shared_ptr<AbilityInfo> &info)
32 {
33     if (info == nullptr) {
34         HILOG_ERROR("AbilityImplFactory::MakeAbilityImplObject is error nullptr == info ");
35         return nullptr;
36     }
37 
38     std::shared_ptr<AbilityImpl> abilityImpl = nullptr;
39     HILOG_DEBUG("AbilityImplFactory::MakeAbilityImplObject type:%{public}d, isStageBasedModel:%{public}d", info->type,
40         info->isStageBasedModel);
41     switch (info->type) {
42 #ifdef SUPPORT_GRAPHICS
43         case AppExecFwk::AbilityType::PAGE:
44             if (info->isStageBasedModel) {
45                 abilityImpl = std::make_shared<NewAbilityImpl>();
46             } else {
47                 abilityImpl = std::make_shared<PageAbilityImpl>();
48             }
49             break;
50 #endif
51         case AppExecFwk::AbilityType::SERVICE:
52             abilityImpl = std::make_shared<ServiceAbilityImpl>();
53             break;
54         case AppExecFwk::AbilityType::DATA:
55             abilityImpl = std::make_shared<DataAbilityImpl>();
56             break;
57         default:
58             HILOG_ERROR("AbilityImplFactory::MakeAbilityImplObject is error");
59             break;
60     }
61 
62     return abilityImpl;
63 }
64 }  // namespace AppExecFwk
65 }  // namespace OHOS
66