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 "zidl/mock_session_manager_service_stub.h"
17
18 #include <ipc_skeleton.h>
19 #include "window_manager_hilog.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "MockSessionManagerServiceStub"};
25 constexpr int32_t MAX_USER_SIZE = 1000;
26 }
27
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int32_t MockSessionManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
29 MessageOption& option)
30 {
31 if (data.ReadInterfaceToken() != GetDescriptor()) {
32 TLOGE(WmsLogTag::DEFAULT, "Check failed");
33 return ERR_TRANSACTION_FAILED;
34 }
35 auto msgId = static_cast<MockSessionManagerServiceMessage>(code);
36 switch (msgId) {
37 case MockSessionManagerServiceMessage::TRANS_ID_GET_SESSION_MANAGER_SERVICE: {
38 sptr<IRemoteObject> remoteObject = GetSessionManagerService();
39 reply.WriteRemoteObject(remoteObject);
40 break;
41 }
42 case MockSessionManagerServiceMessage::TRANS_ID_GET_SCREEN_SESSION_MANAGER: {
43 sptr<IRemoteObject> remoteObject = GetScreenSessionManagerLite();
44 reply.WriteRemoteObject(remoteObject);
45 break;
46 }
47 case MockSessionManagerServiceMessage::TRANS_ID_NOTIFY_SCENE_BOARD_AVAILABLE: {
48 NotifySceneBoardAvailable();
49 break;
50 }
51 case MockSessionManagerServiceMessage::TRANS_ID_REGISTER_SMS_RECOVER_LISTENER: {
52 sptr<IRemoteObject> listenerObject = data.ReadRemoteObject();
53 if (listenerObject == nullptr) {
54 TLOGE(WmsLogTag::WMS_RECOVER, "ReadRemoteObject failed");
55 return ERR_INVALID_DATA;
56 }
57 RegisterSMSRecoverListener(listenerObject);
58 break;
59 }
60 case MockSessionManagerServiceMessage::TRANS_ID_UNREGISTER_SMS_RECOVER_LISTENER: {
61 UnregisterSMSRecoverListener();
62 break;
63 }
64 case MockSessionManagerServiceMessage::TRANS_ID_REGISTER_SMS_LITE_RECOVER_LISTENER: {
65 sptr<IRemoteObject> listenerObject = data.ReadRemoteObject();
66 if (listenerObject == nullptr) {
67 TLOGE(WmsLogTag::WMS_RECOVER, "ReadRemoteObject failed");
68 return ERR_INVALID_DATA;
69 }
70 RegisterSMSLiteRecoverListener(listenerObject);
71 break;
72 }
73 case MockSessionManagerServiceMessage::TRANS_ID_UNREGISTER_SMS_LITE_RECOVER_LISTENER: {
74 UnregisterSMSLiteRecoverListener();
75 break;
76 }
77 case MockSessionManagerServiceMessage::TRANS_ID_SET_SNAPSHOT_SKIP_BY_USERID_AND_BUNDLENAMES: {
78 return HandleSetSnapshotSkipByUserIdAndBundleNames(data, reply);
79 }
80 case MockSessionManagerServiceMessage::TRANS_ID_SET_SNAPSHOT_SKIP_BY_MAP: {
81 return HandleSetSnapshotSkipByIdNamesMap(data, reply);
82 }
83 default:
84 WLOGFW("unknown transaction code %{public}d", code);
85 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
86 }
87 return ERR_NONE;
88 }
89
HandleSetSnapshotSkipByUserIdAndBundleNames(MessageParcel & data,MessageParcel & reply)90 int32_t MockSessionManagerServiceStub::HandleSetSnapshotSkipByUserIdAndBundleNames(
91 MessageParcel& data, MessageParcel& reply)
92 {
93 int32_t userId = 0;
94 if (!data.ReadInt32(userId)) {
95 TLOGE(WmsLogTag::WMS_MULTI_USER, "Failed to readInt32 userId");
96 return ERR_INVALID_DATA;
97 }
98 std::vector<std::string> bundleNameList;
99 if (!data.ReadStringVector(&bundleNameList)) {
100 TLOGE(WmsLogTag::WMS_MULTI_USER, "Fail to read bundleNameList");
101 return ERR_INVALID_DATA;
102 }
103 int32_t errCode = SetSnapshotSkipByUserIdAndBundleNames(userId, bundleNameList);
104 reply.WriteInt32(errCode);
105 return ERR_NONE;
106 }
107
HandleSetSnapshotSkipByIdNamesMap(MessageParcel & data,MessageParcel & reply)108 int32_t MockSessionManagerServiceStub::HandleSetSnapshotSkipByIdNamesMap(MessageParcel& data, MessageParcel& reply)
109 {
110 int32_t mapSize = 0;
111 if (!data.ReadInt32(mapSize)) {
112 TLOGE(WmsLogTag::WMS_MULTI_USER, "Fail to read mapSize");
113 return ERR_INVALID_DATA;
114 }
115 if (mapSize > MAX_USER_SIZE) {
116 TLOGE(WmsLogTag::WMS_MULTI_USER, "Too many users!");
117 return ERR_INVALID_DATA;
118 }
119 std::unordered_map<int32_t, std::vector<std::string>> idBundlesMap;
120 for (int i = 0; i < mapSize; i++) {
121 int32_t userId = data.ReadInt32();
122 std::vector<std::string> bundleNameList;
123 if (!data.ReadStringVector(&bundleNameList)) {
124 TLOGE(WmsLogTag::WMS_MULTI_USER, "Fail to read bundleNameList");
125 return ERR_INVALID_DATA;
126 }
127 idBundlesMap[userId] = std::move(bundleNameList);
128 }
129 int32_t errCode = SetSnapshotSkipByIdNamesMap(idBundlesMap);
130 reply.WriteInt32(errCode);
131 return ERR_NONE;
132 }
133 } // namespace Rosen
134 } // namespace OHOS