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 #ifndef OHOS_ABILITY_RECORD_H 17 #define OHOS_ABILITY_RECORD_H 18 19 #ifdef __LITEOS_M__ 20 #include "cmsis_os.h" 21 #endif 22 #include "ability_info.h" 23 24 namespace OHOS { 25 class JsAppHost; 26 27 constexpr int FAIL_CALLBACK_ERRORCODE = 200; 28 29 /* States-feedback from launcher to AMS */ 30 typedef enum { 31 SCHEDULE_INITED, 32 SCHEDULE_INACTIVE, 33 SCHEDULE_ACTIVE, 34 SCHEDULE_BACKGROUND, 35 SCHEDULE_STOP 36 } AbilityState; 37 38 typedef enum { 39 STATE_JS_RUNNING, 40 STATE_NATIVE_RUNNING, 41 STATE_JS_JUMP_NATIVE, 42 STATE_NATIVE_JUMP_JS, 43 STATE_JS_JUMP_JS, 44 } AppState; 45 46 class AbilityRecord { 47 public: 48 AbilityRecord(); 49 ~AbilityRecord(); 50 51 void SetAppName(const char *appName); GetAppName()52 const char *GetAppName() const 53 { 54 return appName_; 55 } 56 57 void SetAppPath(const char *appPath); GetAppPath()58 const char *GetAppPath() const 59 { 60 return appPath_; 61 } 62 63 void SetAppData(const void *appData, uint16_t dataLength); GetAppData()64 const void *GetAppData() const 65 { 66 return appData_; 67 } 68 SetAbilityInfo(const AbilityInfo abilityInfo)69 void SetAbilityInfo(const AbilityInfo abilityInfo) 70 { 71 abilityInfo_ = abilityInfo; 72 } 73 GetAbilityInfo()74 AbilityInfo GetAbilityInfo() const 75 { 76 return abilityInfo_; 77 } 78 GetDataLength()79 uint16_t GetDataLength() const 80 { 81 return dataLength_; 82 } 83 SetState(const AbilityState state)84 void SetState(const AbilityState state) 85 { 86 state_ = state; 87 } 88 GetState()89 AbilityState GetState() const 90 { 91 return state_; 92 } 93 IsAttached()94 bool IsAttached() const 95 { 96 return state_ != SCHEDULE_STOP; 97 } 98 SetToken(uint16_t token)99 void SetToken(uint16_t token) 100 { 101 token_ = token; 102 } GetToken()103 uint16_t GetToken() const 104 { 105 return token_; 106 } 107 SetTaskId(uint32_t taskId)108 void SetTaskId(uint32_t taskId) 109 { 110 taskId_ = taskId; 111 } 112 GetTaskId()113 uint32_t GetTaskId() const 114 { 115 return taskId_; 116 } 117 SetTerminated(bool isTerminated)118 void SetTerminated(bool isTerminated) 119 { 120 isTerminated_ = isTerminated; 121 } 122 IsTerminated()123 bool IsTerminated() const 124 { 125 return isTerminated_; 126 } 127 SetMessageQueueId(const osMessageQueueId_t jsAppQueueId)128 void SetMessageQueueId(const osMessageQueueId_t jsAppQueueId) 129 { 130 jsAppQueueId_ = jsAppQueueId; 131 } 132 GetMessageQueueId()133 const osMessageQueueId_t& GetMessageQueueId() const 134 { 135 return jsAppQueueId_; 136 } 137 SetJsAppHost(const JsAppHost * jsAppHost)138 void SetJsAppHost(const JsAppHost *jsAppHost) 139 { 140 jsAppHost_ = const_cast<JsAppHost *>(jsAppHost); 141 } 142 GetJsAppHost()143 const JsAppHost *GetJsAppHost() const 144 { 145 return jsAppHost_; 146 } 147 148 static void CopyAbilityRecord(AbilityRecord &abilityRecord, AbilityRecord &newAbilityRecord); 149 150 private: 151 char *appName_ { nullptr }; 152 char *appPath_ { nullptr }; 153 AbilityInfo abilityInfo_; 154 void *appData_ { nullptr }; 155 uint16_t dataLength_ { 0 }; 156 AbilityState state_ { SCHEDULE_STOP }; 157 uint16_t token_ { 0 }; 158 uint32_t taskId_ { 0 }; 159 osMessageQueueId_t jsAppQueueId_ { nullptr }; 160 JsAppHost *jsAppHost_ { nullptr }; 161 bool isTerminated_ = false; 162 }; 163 } // namespace OHOS 164 165 #endif // OHOS_ABILITY_RECORD_H 166