1 /*
2  * Copyright (c) 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 #include "ability_util.h"
17 #include "hilog_tag_wrapper.h"
18 #include "modal_system_dialog/modal_system_dialog_ui_extension.h"
19 #include "parameters.h"
20 #include "utils/modal_system_dialog_util.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
24 namespace {
25 constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state";
26 constexpr const char* RESOURCE_ID_GENERAL_GET_IT = "general_get_it";
27 constexpr const char* RESOURCE_ID_DEVELOPER_DIALOG_TITLE = "lab_developer_mode_tips";
28 constexpr const char* RESOURCE_ID_DEVELOPER_DIALOG_CONTENT = "desc_developer_mode_tips";
29 }
30 
CheckDebugAppNotInDeveloperMode(const AppExecFwk::ApplicationInfo &applicationInfo)31 bool ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(const AppExecFwk::ApplicationInfo &applicationInfo)
32 {
33     if (applicationInfo.appProvisionType == AppExecFwk::Constants::APP_PROVISION_TYPE_DEBUG &&
34         !system::GetBoolParameter(DEVELOPER_MODE_STATE, false)) {
35         TAG_LOGD(AAFwkTag::ABILITYMGR, "not developer mode.");
36         return true;
37     }
38     return false;
39 }
40 
ShowDeveloperModeDialog(const std::string &bundleName, const std::string &abilityName)41 void ModalSystemDialogUtil::ShowDeveloperModeDialog(const std::string &bundleName, const std::string &abilityName)
42 {
43     auto bms = AAFwk::AbilityUtil::GetBundleManagerHelper();
44     CHECK_POINTER(bms);
45     std::string labelString = bms->GetAbilityLabel(bundleName, abilityName);
46 
47     nlohmann::json infoObject;
48     infoObject["appName"] = labelString.c_str();
49     infoObject["title"] = RESOURCE_ID_DEVELOPER_DIALOG_TITLE;
50     infoObject["content"] = RESOURCE_ID_DEVELOPER_DIALOG_CONTENT;
51     infoObject["button"] = RESOURCE_ID_GENERAL_GET_IT;
52 
53     nlohmann::json param;
54     param["extraInfo"] = infoObject;
55 
56     std::string paramStr = param.dump();
57     auto connection = std::make_shared<ModalSystemDialogUIExtension>();
58     if (connection && connection->CreateModalUIExtension(paramStr)) {
59         TAG_LOGE(AAFwkTag::ABILITYMGR, "create modal ui extension failed");
60     }
61 }
62 
63 }  // namespace AbilityRuntime
64 }  // namespace OHOS
65