1 /*
2 * Copyright (c) 2023 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 "common.h"
17 #include "connection.h"
18 #include "extension_manager_proxy.h"
19 #include <semaphore.h>
20
21 namespace OHOS {
22 namespace HDC {
23 namespace AUTH {
24
25 using namespace std;
26 using namespace AAFwk;
27
OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode)28 void HdcdConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
29 const sptr<IRemoteObject> &remoteObject, int32_t resultCode)
30 {
31 MessageParcel data;
32 MessageParcel reply;
33 MessageOption option;
34 const int paramNum = 3;
35 string bundleName = "com.ohos.settings";
36 string abilityName = "USBDebugDialog";
37 string parameters = "{\"ability.want.params.uiExtensionType\":\"sysDialog/common\",\"sysDialogZOrder\":1}";
38
39 AUTH_LOGE("connect success");
40
41 data.WriteInt32(paramNum);
42 data.WriteString16(Str8ToStr16("bundleName"));
43 data.WriteString16(Str8ToStr16(bundleName));
44 data.WriteString16(Str8ToStr16("abilityName"));
45 data.WriteString16(Str8ToStr16(abilityName));
46
47 data.WriteString16(Str8ToStr16("parameters"));
48 data.WriteString16(Str8ToStr16(parameters));
49
50 if (!data.WriteParcelable(&element)) {
51 AUTH_LOGE("Connect done element error");
52 return;
53 }
54 if (!data.WriteRemoteObject(remoteObject)) {
55 AUTH_LOGE("Connect done remote object error");
56 return;
57 }
58 if (!data.WriteInt32(resultCode)) {
59 AUTH_LOGE("Connect done result code error");
60 return;
61 }
62
63 int32_t ret = remoteObject->SendRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
64 showDialogResult = (ret == 0);
65 sem_post(&sem);
66 AUTH_LOGE("SendRequest(bundle(%s)ability(%s)parameters(%s)) ret(%d)",
67 bundleName.c_str(), abilityName.c_str(), parameters.c_str(), ret);
68 }
69
GetShowDialogResult(void)70 bool HdcdConnection::GetShowDialogResult(void)
71 {
72 AUTH_LOGE("wait for dialog ability");
73 sem_wait(&sem);
74 sem_destroy(&sem);
75 AUTH_LOGE("wait dialog ability over");
76 return showDialogResult;
77 }
78
OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode)79 void HdcdConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element,
80 int32_t resultCode)
81 {
82 AUTH_LOGE("disconnect success");
83 }
84
85 } // namespace AUTH
86 } // namespace HDC
87 } // namespace OHOS
88
89