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 constexpr const char* ENABLE_APP_GALLERY_SELECTOR_UTIL = "abilitymanagerservice.support.appgallery.selector";
32 
AppFwkBootEventCallback(const char *key, const char *value, void *context)33 [[maybe_unused]] static void AppFwkBootEventCallback(const char *key, const char *value, void *context)
34 {
35     if (strcmp(key, "bootevent.boot.completed") == 0 && strcmp(value, "true") == 0) {
36         Want want;
37         want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
38         EventFwk::CommonEventData commonData {want};
39         TAG_LOGI(AAFwkTag::ABILITYMGR, "init call, AppFwkBootEventCallback");
40         EventFwk::CommonEventManager::PublishCommonEvent(commonData);
41         TAG_LOGI(AAFwkTag::ABILITYMGR, "init call, AppFwkBootEventCallback push BootEvent");
42         return;
43     }
44     TAG_LOGE(AAFwkTag::ABILITYMGR, "init call, AppFwkBootEventCallback key: %{public}s, value: %{public}s", key, value);
45 }
46 
IsBootCompleted()47 inline bool IsBootCompleted()
48 {
49     TAG_LOGD(AAFwkTag::ABILITYMGR, "call");
50     std::string ret = OHOS::system::GetParameter(BOOTEVENT_BOOT_COMPLETED, "false");
51     if (ret == "true") {
52         return true;
53     }
54     return false;
55 }
56 
IsEnableAppGallerySelector()57 inline bool IsEnableAppGallerySelector()
58 {
59     TAG_LOGD(AAFwkTag::ABILITYMGR, "call");
60     std::string ret = OHOS::system::GetParameter(ENABLE_APP_GALLERY_SELECTOR_UTIL, "true");
61     if (ret == "true") {
62         return true;
63     }
64     return false;
65 }
66 }  // namespace ApplicationlUtil
67 }  // namespace AAFwk
68 }  // namespace OHOS
69 #endif  // OHOS_ABILITY_RUNTIME_APPLICATION_UTIL_H
70