1 /* 2 * Copyright (c) 2023 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 "slite_ace_ability.h" 17 #include "js_async_work.h" 18 19 namespace OHOS { 20 namespace ACELite { SliteAceAbility(const char * bundleName)21SliteAceAbility::SliteAceAbility(const char *bundleName) : SliteAbility(bundleName) 22 { 23 } 24 OnCreate(const Want & want)25void SliteAceAbility::OnCreate(const Want &want) 26 { 27 jsAbility_.Launch(want.appPath, want.element->bundleName, token_); 28 SliteAbility::OnCreate(want); 29 } 30 31 #ifdef _MINI_MULTI_TASKS_ OnRestoreData(AbilitySlite::AbilitySavedData * data)32void SliteAceAbility::OnRestoreData(AbilitySlite::AbilitySavedData *data) 33 { 34 jsAbility_.OnRestoreData(data); 35 SliteAbility::OnRestoreData(data); 36 } 37 #endif 38 OnForeground(const Want & want)39void SliteAceAbility::OnForeground(const Want &want) 40 { 41 jsAbility_.Show(); 42 isBackground_ = false; 43 SliteAbility::OnForeground(want); 44 } 45 OnBackground()46void SliteAceAbility::OnBackground() 47 { 48 isBackground_ = true; 49 jsAbility_.Hide(); 50 SliteAbility::OnBackground(); 51 } 52 53 #ifdef _MINI_MULTI_TASKS_ OnSaveData(AbilitySlite::AbilitySavedData * data)54void SliteAceAbility::OnSaveData(AbilitySlite::AbilitySavedData *data) 55 { 56 jsAbility_.OnSaveData(data); 57 SliteAbility::OnSaveData(data); 58 } 59 #endif 60 OnDestroy()61void SliteAceAbility::OnDestroy() 62 { 63 JsAsyncWork::SetAppQueueHandler(nullptr); 64 // the TE owner will be JS application after JS application start up except for it's lying in background, 65 // call render once to make sure the last TE message is processed properly 66 if (!isBackground_) { 67 jsAbility_.HandleRenderTick(); 68 } 69 jsAbility_.TransferToDestroy(); 70 SliteAbility::OnDestroy(); 71 } 72 HandleExtraMessage(const AbilitySlite::SliteAbilityInnerMsg & innerMsg)73void SliteAceAbility::HandleExtraMessage(const AbilitySlite::SliteAbilityInnerMsg &innerMsg) 74 { 75 switch (innerMsg.msgId) { 76 case AbilitySlite::SliteAbilityMsgId::BACKPRESSED: 77 jsAbility_.BackPressed(); 78 break; 79 case AbilitySlite::SliteAbilityMsgId::ASYNCWORK: { 80 auto* work = reinterpret_cast<AsyncWork *>(innerMsg.data); 81 JsAsyncWork::ExecuteAsyncWork(work); 82 break; 83 } 84 case AbilitySlite::SliteAbilityMsgId::TE_EVENT: 85 jsAbility_.HandleRenderTick(); 86 break; 87 default: 88 break; 89 } 90 } 91 } // namespace ACELite 92 } // namespace OHOS