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