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 "dialog_switch.h"
17
18 #include <algorithm>
19 #include <string>
20
21 #include "bluetooth_dialog.h"
22 #include "bool_wrapper.h"
23 #include "double_wrapper.h"
24 #include "foundation/ability/ability_base/interfaces/inner_api/base/include/bool_wrapper.h"
25 #include "foundation/ability/ability_runtime/interfaces/inner_api/extension_manager/include/extension_manager_client.h"
26 #include "foundation/ability/ability_runtime/interfaces/kits/native/ability/ability_runtime/ability_connect_callback.h"
27 #include "int_wrapper.h"
28 #include "ipc_skeleton.h"
29 #include "json/json.h"
30 #include "json/writer.h"
31 #include "log.h"
32 #include "permission_manager.h"
33 #include "raw_address.h"
34 #include "refbase.h"
35 #include "string_wrapper.h"
36 #include "want_params_wrapper.h"
37
38 namespace OHOS {
39 namespace bluetooth {
40
RequestBluetoothSwitchDialog(DialogSwitchType type)41 bool DialogSwitch::RequestBluetoothSwitchDialog(DialogSwitchType type)
42 {
43 const std::string abilityName = "bluetooth";
44 const std::string bundleName = "com.ohos.settings";
45 std::string thirdlyBundleName = PermissionManager::GetCallingName();
46 std::string connectStr = DialogSwitch::BuildStartCommand(type, thirdlyBundleName);
47 HILOGI("The bundlename is %{public}s.", thirdlyBundleName.c_str());
48 if (!BluetoothDialog::DialogConnectExtension(connectStr, bundleName, abilityName)) {
49 HILOGE("Failed to build switch dialog.");
50 return false;
51 }
52 return true;
53 }
54
BuildStartCommand(DialogSwitchType type,std::string thirdlyBundleName)55 std::string DialogSwitch::BuildStartCommand(DialogSwitchType type, std::string thirdlyBundleName)
56 {
57 std::string types;
58 if (type == ENABLE_BLUETOOTH) {
59 types = "enable";
60 } else {
61 types = "disable";
62 }
63 nlohmann::json root;
64 std::string uiType = "sysDialog/common";
65 root["ability.want.params.uiExtensionType"] = uiType;
66 root["bundleName"] = thirdlyBundleName;
67 root["type"] = types;
68 std::string cmdData = root.dump();
69 HILOGI("cmdData is: %{public}s.", cmdData.c_str());
70 return cmdData;
71 }
72 } // namespace bluetooth
73 } // namespace OHOS
74