1 /*
2 * Copyright (c) 2022 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_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 const int32_t BOOT_COMPLETED_SIZE = 6;
30 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 HILOG_INFO("%{public}s %{public}s is true", __func__, key);
36 Want want;
37 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
38 EventFwk::CommonEventData commonData {want};
39 EventFwk::CommonEventManager::PublishCommonEvent(commonData);
40 HILOG_INFO("%{public}s BootEvent completed", __func__);
41 }
42 }
43
IsBootCompleted()44 bool IsBootCompleted()
45 {
46 HILOG_DEBUG("call");
47 std::string ret = OHOS::system::GetParameter(BOOTEVENT_BOOT_COMPLETED, "false");
48 if (ret == "true") {
49 return true;
50 }
51 return false;
52 }
53 } // namespace ApplicationlUtil
54 } // namespace AAFwk
55 } // namespace OHOS
56 #endif // OHOS_ABILITY_RUNTIME_APPLICATION_UTIL_H
57