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 & moduleName,uint32_t labelId,int32_t userId)41 void ModalSystemDialogUtil::ShowDeveloperModeDialog(
42 const std::string &bundleName, const std::string &moduleName, uint32_t labelId, int32_t userId)
43 {
44 auto bms = AAFwk::AbilityUtil::GetBundleManagerHelper();
45 CHECK_POINTER(bms);
46 std::string labelString = IN_PROCESS_CALL(bms->GetStringById(bundleName, moduleName, labelId, userId));
47
48 nlohmann::json infoObject;
49 infoObject["appName"] = labelString.c_str();
50 infoObject["title"] = RESOURCE_ID_DEVELOPER_DIALOG_TITLE;
51 infoObject["content"] = RESOURCE_ID_DEVELOPER_DIALOG_CONTENT;
52 infoObject["button"] = RESOURCE_ID_GENERAL_GET_IT;
53
54 nlohmann::json param;
55 param["extraInfo"] = infoObject;
56
57 std::string paramStr = param.dump();
58 auto connection = std::make_shared<ModalSystemDialogUIExtension>();
59 if (connection && connection->CreateModalUIExtension(paramStr)) {
60 TAG_LOGE(AAFwkTag::ABILITYMGR, "create modal ui extension failed");
61 }
62 }
63
64 } // namespace AbilityRuntime
65 } // namespace OHOS
66