1 /*
2 * Copyright (c) 2021-2024 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_tag_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 TAG_LOGE(AAFwkTag::ABILITY, "null info");
35 return nullptr;
36 }
37
38 std::shared_ptr<AbilityImpl> abilityImpl = nullptr;
39 TAG_LOGD(AAFwkTag::ABILITY,
40 "type:%{public}d, isStageBasedModel:%{public}d", info->type,
41 info->isStageBasedModel);
42 switch (info->type) {
43 #ifdef SUPPORT_GRAPHICS
44 case AppExecFwk::AbilityType::PAGE:
45 if (info->isStageBasedModel) {
46 abilityImpl = std::make_shared<NewAbilityImpl>();
47 } else {
48 abilityImpl = std::make_shared<PageAbilityImpl>();
49 }
50 break;
51 #endif
52 case AppExecFwk::AbilityType::SERVICE:
53 abilityImpl = std::make_shared<ServiceAbilityImpl>();
54 break;
55 case AppExecFwk::AbilityType::DATA:
56 abilityImpl = std::make_shared<DataAbilityImpl>();
57 break;
58 default:
59 TAG_LOGE(AAFwkTag::ABILITY, "error");
60 break;
61 }
62
63 return abilityImpl;
64 }
65 } // namespace AppExecFwk
66 } // namespace OHOS
67