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 "bundle_user_mgr_host.h"
17
18 #include "ipc_types.h"
19
20 #include "app_log_wrapper.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
BundleUserMgrHost()24 BundleUserMgrHost::BundleUserMgrHost()
25 {
26 APP_LOGD("create BundleUserMgrHost instance");
27 }
28
~BundleUserMgrHost()29 BundleUserMgrHost::~BundleUserMgrHost()
30 {
31 APP_LOGD("destroy BundleUserMgrHost instance");
32 }
33
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int BundleUserMgrHost::OnRemoteRequest(
35 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
36 {
37 APP_LOGD("BundleUserMgrHost onReceived message, the message code is %{public}u", code);
38 std::u16string descripter = BundleUserMgrHost::GetDescriptor();
39 std::u16string remoteDescripter = data.ReadInterfaceToken();
40 if (descripter != remoteDescripter) {
41 APP_LOGE("fail to write reply message in bundle user mgr host due to the reply is nullptr");
42 return OBJECT_NULL;
43 }
44
45 switch (code) {
46 case static_cast<uint32_t>(IBundleUserMgr::Message::CREATE_USER): {
47 HandleCreateNewUser(data, reply);
48 break;
49 }
50 case static_cast<uint32_t>(IBundleUserMgr::Message::REMOVE_USER): {
51 HandleRemoveUser(data, reply);
52 break;
53 }
54 default:
55 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57
58 return NO_ERROR;
59 }
60
HandleCreateNewUser(Parcel & data,Parcel & reply)61 void BundleUserMgrHost::HandleCreateNewUser(Parcel &data, Parcel &reply)
62 {
63 CreateNewUser(data.ReadInt32());
64 }
65
HandleRemoveUser(Parcel & data,Parcel & reply)66 void BundleUserMgrHost::HandleRemoveUser(Parcel &data, Parcel &reply)
67 {
68 RemoveUser(data.ReadInt32());
69 }
70 } // namespace AppExecFwk
71 } // namespace OHOS
72