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 "ability_slice.h"
17
18 #include <ability_state.h>
19 #include <log.h>
20
21 #include "ability_loader.h"
22 #include "ability_slice_manager.h"
23
24 namespace OHOS {
Init(AbilitySliceManager & abilitySliceManager)25 void AbilitySlice::Init(AbilitySliceManager &abilitySliceManager)
26 {
27 HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice Init");
28 abilitySliceManager_ = &abilitySliceManager;
29 sliceState_ = STATE_INITIAL;
30 AbilityContext::token_ = abilitySliceManager.GetToken();
31 }
32
Present(AbilitySlice & abilitySlice,const Want & want)33 void AbilitySlice::Present(AbilitySlice &abilitySlice, const Want &want)
34 {
35 if (abilitySliceManager_ == nullptr) {
36 HILOG_ERROR(HILOG_MODULE_APP, "AbilitySlice Present failed");
37 return;
38 }
39 abilitySliceManager_->Present(*this, abilitySlice, want);
40 }
41
Terminate()42 void AbilitySlice::Terminate()
43 {
44 if (abilitySliceManager_ == nullptr) {
45 HILOG_ERROR(HILOG_MODULE_APP, "AbilitySlice Terminate failed");
46 return;
47 }
48 abilitySliceManager_->Terminate(*this);
49 }
50
SetUIContent(RootView * rootView)51 void AbilitySlice::SetUIContent(RootView *rootView)
52 {
53 if (abilitySliceManager_ == nullptr) {
54 HILOG_ERROR(HILOG_MODULE_APP, "AbilitySlice SetUIContent failed");
55 return;
56 }
57 curRootView_ = rootView;
58 abilitySliceManager_->SetUIContent(rootView);
59 }
60
OnStart(const Want & want)61 void AbilitySlice::OnStart(const Want &want)
62 {
63 HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnStart");
64 sliceState_ = STATE_INACTIVE;
65 }
66
OnInactive()67 void AbilitySlice::OnInactive()
68 {
69 HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnInactive");
70 sliceState_ = STATE_INACTIVE;
71 }
72
OnActive(const Want & want)73 void AbilitySlice::OnActive(const Want &want)
74 {
75 HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnActive");
76 if ((sliceState_ == STATE_BACKGROUND) && (curRootView_ != nullptr)) {
77 SetUIContent(curRootView_);
78 }
79 sliceState_ = STATE_ACTIVE;
80 }
81
OnBackground()82 void AbilitySlice::OnBackground()
83 {
84 HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnBackground");
85 sliceState_ = STATE_BACKGROUND;
86 }
87
OnStop()88 void AbilitySlice::OnStop()
89 {
90 HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnStop");
91 sliceState_ = STATE_INITIAL;
92 }
93
GetState() const94 int AbilitySlice::GetState() const
95 {
96 return sliceState_;
97 }
98 } // namespace OHOS
99