1 /* 2 * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_APPLICATION_IMPL_H 17 #define FOUNDATION_APPEXECFWK_OHOS_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 * @return Returns true if PerformTerminate is scheduled successfully; 72 * Returns false otherwise. 73 */ 74 bool PerformTerminate(); 75 76 /** 77 * @brief Schedule the application to the APP_STATE_TERMINATED state. 78 * 79 * @return Returns true if PerformTerminate is scheduled successfully; 80 * Returns false otherwise. 81 */ 82 void PerformTerminateStrong(); 83 84 /** 85 * @brief Set the target state to application. 86 * 87 * @param state The target state of application. 88 * 89 */ 90 int SetState(int state); 91 92 /** 93 * @brief Get the current state of application. 94 * 95 * @return Returns the current state of application. 96 * 97 */ 98 int GetState() const; 99 100 /** 101 * @brief Set the RecordId to application. 102 * 103 * @param id recordId. 104 * 105 */ 106 void SetRecordId(int id); 107 108 /** 109 * @brief Get the recordId of application. 110 * 111 * @return Returns the recordId of application. 112 * 113 */ 114 int GetRecordId() const; 115 116 /** 117 * @brief System determines to trim the memory. 118 * 119 * @param level Indicates the memory trim level, which shows the current memory usage status. 120 * 121 */ 122 void PerformMemoryLevel(int level); 123 124 /** 125 * @brief System determines to send the new config to application. 126 * 127 * @param config Indicates the updated configuration information. 128 * 129 */ 130 void PerformConfigurationUpdated(const Configuration &config); 131 132 private: 133 enum { 134 APP_STATE_CREATE = 0, 135 APP_STATE_READY = 1, 136 APP_STATE_FOREGROUND = 2, 137 APP_STATE_BACKGROUND = 3, 138 APP_STATE_TERMINATED = 4 139 }; 140 int curState_; 141 int recordId_; 142 std::shared_ptr<OHOSApplication> application_ = nullptr; 143 144 DISALLOW_COPY_AND_MOVE(ApplicationImpl); 145 }; 146 } // namespace AppExecFwk 147 } // namespace OHOS 148 #endif // FOUNDATION_APPEXECFWK_OHOS_APPLICATION_IMPL_H 149