• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bool_wrapper.h"
25 #include "extension_manager_client.h"
26 #include "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 "nlohmann/json.hpp"
33 #include "permission_manager.h"
34 #include "raw_address.h"
35 #include "refbase.h"
36 #include "string_wrapper.h"
37 #include "want_params_wrapper.h"
38 
39 namespace OHOS {
40 namespace bluetooth {
41 
RequestBluetoothSwitchDialog(DialogSwitchType type)42 bool DialogSwitch::RequestBluetoothSwitchDialog(DialogSwitchType type)
43 {
44     const std::string abilityName = "bluetooth";
45     const std::string bundleName = "com.ohos.settings";
46     std::string thirdlyBundleName = PermissionManager::GetCallingName();
47     std::string connectStr = DialogSwitch::BuildStartCommand(type, thirdlyBundleName);
48     HILOGI("The bundlename is %{public}s.", thirdlyBundleName.c_str());
49     if (!BluetoothDialog::DialogConnectExtension(connectStr, bundleName, abilityName)) {
50         HILOGE("Failed to build switch dialog.");
51         return false;
52     }
53     return true;
54 }
55 
BuildStartCommand(DialogSwitchType type,std::string thirdlyBundleName)56 std::string DialogSwitch::BuildStartCommand(DialogSwitchType type, std::string thirdlyBundleName)
57 {
58     std::string types;
59     if (type == ENABLE_BLUETOOTH) {
60         types = "enable";
61     } else {
62         types = "disable";
63     }
64     nlohmann::json root;
65     std::string uiType = "sysDialog/common";
66     root["ability.want.params.uiExtensionType"] = uiType;
67     root["bundleName"] = thirdlyBundleName;
68     root["type"] = types;
69     std::string cmdData = root.dump();
70     HILOGI("cmdData is: %{public}s.", cmdData.c_str());
71     return cmdData;
72 }
73 } // namespace bluetooth
74 } // namespace OHOS
75