1 /*
2 * Copyright (c) 2022-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 "enterprise_admin_proxy.h"
17 #include "edm_log.h"
18
19 namespace OHOS {
20 namespace EDM {
OnAdminEnabled()21 void EnterpriseAdminProxy::OnAdminEnabled()
22 {
23 MessageParcel data;
24 if (!data.WriteInterfaceToken(GetDescriptor())) {
25 EDMLOGE("EnterpriseAdminProxy::%{public}s write descriptor failed!", __func__);
26 return;
27 }
28 EDMLOGI("EnterpriseAdminProxy proxy OnAdminEnabled");
29 SendRequest(COMMAND_ON_ADMIN_ENABLED, data);
30 }
31
OnAdminDisabled()32 void EnterpriseAdminProxy::OnAdminDisabled()
33 {
34 MessageParcel data;
35 if (!data.WriteInterfaceToken(GetDescriptor())) {
36 EDMLOGE("EnterpriseAdminProxy::%{public}s write descriptor failed!", __func__);
37 return;
38 }
39 EDMLOGI("EnterpriseAdminProxy proxy OnAdminDisabled");
40 SendRequest(COMMAND_ON_ADMIN_DISABLED, data);
41 }
42
OnBundleAdded(const std::string & bundleName)43 void EnterpriseAdminProxy::OnBundleAdded(const std::string &bundleName)
44 {
45 MessageParcel data;
46 if (!data.WriteInterfaceToken(GetDescriptor())) {
47 EDMLOGE("EnterpriseAdminProxy::%{public}s write descriptor failed!", __func__);
48 return;
49 }
50 data.WriteString(bundleName);
51 EDMLOGI("EnterpriseAdminProxy proxy OnBundleAdded");
52 SendRequest(COMMAND_ON_BUNDLE_ADDED, data);
53 }
54
OnBundleRemoved(const std::string & bundleName)55 void EnterpriseAdminProxy::OnBundleRemoved(const std::string &bundleName)
56 {
57 MessageParcel data;
58 if (!data.WriteInterfaceToken(GetDescriptor())) {
59 EDMLOGE("EnterpriseAdminProxy::%{public}s write descriptor failed!", __func__);
60 return;
61 }
62 data.WriteString(bundleName);
63 EDMLOGI("EnterpriseAdminProxy proxy OnBundleRemoved");
64 SendRequest(COMMAND_ON_BUNDLE_REMOVED, data);
65 }
66
OnAppStart(const std::string & bundleName)67 void EnterpriseAdminProxy::OnAppStart(const std::string &bundleName)
68 {
69 MessageParcel data;
70 if (!data.WriteInterfaceToken(GetDescriptor())) {
71 EDMLOGE("EnterpriseAdminProxy::%{public}s write descriptor failed!", __func__);
72 return;
73 }
74 data.WriteString(bundleName);
75 EDMLOGI("EnterpriseAdminProxy proxy OnAppStart");
76 SendRequest(COMMAND_ON_APP_START, data);
77 }
78
OnAppStop(const std::string & bundleName)79 void EnterpriseAdminProxy::OnAppStop(const std::string &bundleName)
80 {
81 MessageParcel data;
82 if (!data.WriteInterfaceToken(GetDescriptor())) {
83 EDMLOGE("EnterpriseAdminProxy::%{public}s write descriptor failed!", __func__);
84 return;
85 }
86 data.WriteString(bundleName);
87 EDMLOGI("EnterpriseAdminProxy proxy OnAppStop");
88 SendRequest(COMMAND_ON_APP_STOP, data);
89 }
90
OnSystemUpdate(const UpdateInfo & updateInfo)91 void EnterpriseAdminProxy::OnSystemUpdate(const UpdateInfo &updateInfo)
92 {
93 MessageParcel data;
94 if (!data.WriteInterfaceToken(GetDescriptor())) {
95 EDMLOGE("EnterpriseAdminProxy::%{public}s write descriptor failed!", __func__);
96 return;
97 }
98 data.WriteString(updateInfo.version);
99 data.WriteInt64(updateInfo.firstReceivedTime);
100 data.WriteString(updateInfo.packageType);
101 EDMLOGI("EnterpriseAdminProxy proxy OnSystemUpdate");
102 SendRequest(COMMAND_ON_SYSTEM_UPDATE, data);
103 }
104
SendRequest(uint32_t code,MessageParcel & data)105 void EnterpriseAdminProxy::SendRequest(uint32_t code, MessageParcel &data)
106 {
107 MessageParcel reply;
108 MessageOption option(MessageOption::TF_SYNC);
109 Remote()->SendRequest(code, data, reply, option);
110 }
111 } // namespace EDM
112 } // namespace OHOS
113