1 /*
2 * Copyright (c) 2022-2024 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_UTIL_H
17 #define OHOS_ABILITY_RUNTIME_APPLICATION_UTIL_H
18
19 #include "common_event_manager.h"
20 #include "common_event_support.h"
21 #include "hilog_tag_wrapper.h"
22 #include "parameters.h"
23 #include "want.h"
24
25 namespace OHOS {
26 namespace AAFwk {
27 namespace ApplicationUtil {
28 using Want = OHOS::AAFwk::Want;
29 constexpr int32_t BOOT_COMPLETED_SIZE = 6;
30 constexpr const char* BOOTEVENT_BOOT_COMPLETED = "bootevent.boot.completed";
31
AppFwkBootEventCallback(const char * key,const char * value,void * context)32 [[maybe_unused]] static void AppFwkBootEventCallback(const char *key, const char *value, void *context)
33 {
34 if (strcmp(key, "bootevent.boot.completed") == 0 && strcmp(value, "true") == 0) {
35 Want want;
36 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
37 EventFwk::CommonEventData commonData {want};
38 TAG_LOGI(AAFwkTag::ABILITYMGR, "init call, AppFwkBootEventCallback");
39 EventFwk::CommonEventManager::PublishCommonEvent(commonData);
40 TAG_LOGI(AAFwkTag::ABILITYMGR, "init call, AppFwkBootEventCallback push BootEvent");
41 return;
42 }
43 TAG_LOGE(AAFwkTag::ABILITYMGR, "init call, AppFwkBootEventCallback key: %{public}s, value: %{public}s", key, value);
44 }
45
IsBootCompleted()46 bool IsBootCompleted()
47 {
48 TAG_LOGD(AAFwkTag::ABILITYMGR, "call");
49 std::string ret = OHOS::system::GetParameter(BOOTEVENT_BOOT_COMPLETED, "false");
50 if (ret == "true") {
51 return true;
52 }
53 return false;
54 }
55 } // namespace ApplicationlUtil
56 } // namespace AAFwk
57 } // namespace OHOS
58 #endif // OHOS_ABILITY_RUNTIME_APPLICATION_UTIL_H
59