1 /* 2 * Copyright (c) 2021-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 #ifndef OHOS_ABILITY_RUNTIME_APPLICATION_IMPL_H 17 #define OHOS_ABILITY_RUNTIME_APPLICATION_IMPL_H 18 19 #include <map> 20 #include <string> 21 #include "application_info.h" 22 #include "profile.h" 23 #include "iremote_object.h" 24 #include "ability_local_record.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 class OHOSApplication; 29 class AbilityLocalRecord; 30 class Configuration; 31 class ApplicationImpl { 32 public: 33 ApplicationImpl(); 34 virtual ~ApplicationImpl() = default; 35 36 /** 37 * @brief Set the application to the ApplicationImpl. 38 * 39 * @param application The application which the mainthread launched. 40 * 41 */ 42 void SetApplication(const std::shared_ptr<OHOSApplication> &application); 43 44 /** 45 * @brief Schedule the application to the APP_STATE_READY state. 46 * 47 * @return Returns true if performAppReady is scheduled successfully; 48 * Returns false otherwise. 49 */ 50 bool PerformAppReady(); 51 52 /** 53 * @brief Schedule the application to the APP_STATE_FOREGROUND state. 54 * 55 * @return Returns true if PerformForeground is scheduled successfully; 56 * Returns false otherwise. 57 */ 58 bool PerformForeground(); 59 60 /** 61 * @brief Schedule the application to the APP_STATE_BACKGROUND state. 62 * 63 * @return Returns true if PerformBackground is scheduled successfully; 64 * Returns false otherwise. 65 */ 66 bool PerformBackground(); 67 68 /** 69 * @brief Schedule the application to the APP_STATE_TERMINATED state. 70 * 71 * @param isLastProcess When it is the last application process, pass in true. 72 * 73 * @return Returns true if PerformTerminate is scheduled successfully; 74 * Returns false otherwise. 75 */ 76 bool PerformTerminate(bool isLastProcess = false); 77 78 /** 79 * @brief Schedule the application to the APP_STATE_TERMINATED state. 80 * 81 * @return Returns true if PerformTerminate is scheduled successfully; 82 * Returns false otherwise. 83 */ 84 void PerformTerminateStrong(); 85 86 /** 87 * @brief Set the target state to application. 88 * 89 * @param state The target state of application. 90 * 91 */ 92 int SetState(int state); 93 94 /** 95 * @brief Get the current state of application. 96 * 97 * @return Returns the current state of application. 98 * 99 */ 100 int GetState() const; 101 102 /** 103 * @brief Set the RecordId to application. 104 * 105 * @param id recordId. 106 * 107 */ 108 void SetRecordId(int id); 109 110 /** 111 * @brief Get the recordId of application. 112 * 113 * @return Returns the recordId of application. 114 * 115 */ 116 int GetRecordId() const; 117 118 /** 119 * @brief System determines to trim the memory. 120 * 121 * @param level Indicates the memory trim level, which shows the current memory usage status. 122 * 123 */ 124 void PerformMemoryLevel(int level); 125 126 /** 127 * @brief System determines to send the new config to application. 128 * 129 * @param config Indicates the updated configuration information. 130 * 131 */ 132 void PerformConfigurationUpdated(const Configuration &config); 133 134 enum { 135 APP_STATE_CREATE = 0, 136 APP_STATE_READY = 1, 137 APP_STATE_FOREGROUND = 2, 138 APP_STATE_BACKGROUND = 3, 139 APP_STATE_TERMINATED = 4 140 }; 141 private: 142 int curState_; 143 int recordId_; 144 std::shared_ptr<OHOSApplication> application_ = nullptr; 145 146 DISALLOW_COPY_AND_MOVE(ApplicationImpl); 147 }; 148 } // namespace AppExecFwk 149 } // namespace OHOS 150 #endif // OHOS_ABILITY_RUNTIME_APPLICATION_IMPL_H 151