• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_stub.h"
17 #include "edm_log.h"
18 
19 namespace OHOS {
20 namespace EDM {
EnterpriseAdminStub()21 EnterpriseAdminStub::EnterpriseAdminStub()
22 {
23     AddCallFuncMap();
24     EDMLOGD("EnterpriseAdminStub()");
25 }
26 
~EnterpriseAdminStub()27 EnterpriseAdminStub::~EnterpriseAdminStub()
28 {
29     EDMLOGD("~EnterpriseAdminStub()");
30 }
31 
AddCallFuncMap()32 void EnterpriseAdminStub::AddCallFuncMap()
33 {
34     memberFuncMap_[COMMAND_ON_ADMIN_ENABLED] = &EnterpriseAdminStub::OnAdminEnabledInner;
35     memberFuncMap_[COMMAND_ON_ADMIN_DISABLED] = &EnterpriseAdminStub::OnAdminDisabledInner;
36     memberFuncMap_[COMMAND_ON_BUNDLE_ADDED] = &EnterpriseAdminStub::OnBundleAddedInner;
37     memberFuncMap_[COMMAND_ON_BUNDLE_REMOVED] = &EnterpriseAdminStub::OnBundleRemovedInner;
38 }
39 
OnAdminEnabledInner(MessageParcel & data,MessageParcel & reply)40 void EnterpriseAdminStub::OnAdminEnabledInner(MessageParcel& data, MessageParcel& reply)
41 {
42     EDMLOGI("EnterpriseAdminStub::OnAdminEnabled");
43     OnAdminEnabled();
44 }
45 
OnAdminDisabledInner(MessageParcel & data,MessageParcel & reply)46 void EnterpriseAdminStub::OnAdminDisabledInner(MessageParcel& data, MessageParcel& reply)
47 {
48     EDMLOGI("EnterpriseAdminStub::OnAdminDisabled");
49     OnAdminDisabled();
50 }
51 
OnBundleAddedInner(MessageParcel & data,MessageParcel & reply)52 void EnterpriseAdminStub::OnBundleAddedInner(MessageParcel& data, MessageParcel& reply)
53 {
54     EDMLOGI("EnterpriseAdminStub::OnBundleAdded");
55     std::string bundleName = data.ReadString();
56     OnBundleAdded(bundleName);
57 }
58 
OnBundleRemovedInner(MessageParcel & data,MessageParcel & reply)59 void EnterpriseAdminStub::OnBundleRemovedInner(MessageParcel& data, MessageParcel& reply)
60 {
61     EDMLOGI("EnterpriseAdminStub::OnBundleRemoved");
62     std::string bundleName = data.ReadString();
63     OnBundleRemoved(bundleName);
64 }
65 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)66 int32_t EnterpriseAdminStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
67     MessageOption &option)
68 {
69     auto remoteDescriptor = data.ReadInterfaceToken();
70     EDMLOGI("EnterpriseAdminStub code %{public}u", code);
71     if (GetDescriptor() != remoteDescriptor) {
72         EDMLOGE("EnterpriseAdminStub::OnRemoteRequest failed, descriptor is not matched!");
73         return ERR_INVALID_STATE;
74     }
75     auto func = memberFuncMap_.find(code);
76     if (func != memberFuncMap_.end()) {
77         auto memberFunc = func->second;
78         if (memberFunc != nullptr) {
79             (this->*memberFunc)(data, reply);
80             return ERR_NONE;
81         }
82         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
83     }
84 
85     return ERR_TRANSACTION_FAILED;
86 }
87 } // namespace EDM
88 } // namespace OHOS
89