1 /*
2 * Copyright (c) 2024 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 #include "screen_session_dumper.h"
16
17 #include <csignal>
18 #include <fstream>
19 #include <transaction/rs_interfaces.h>
20
21 #include "unique_fd.h"
22 #include "screen_session_manager.h"
23 #include "session_permission.h"
24 #include "screen_rotation_property.h"
25 #include "screen_sensor_connector.h"
26 #include "parameters.h"
27
28 namespace OHOS {
29 namespace Rosen {
30 namespace {
31 constexpr int LINE_WIDTH = 30;
32 constexpr int DUMPER_PARAM_INDEX_ONE = 1;
33 constexpr int DUMPER_PARAM_INDEX_TWO = 2;
34 constexpr int DUMPER_PARAM_INDEX_THREE = 3;
35 const std::string ARG_DUMP_HELP = "-h";
36 const std::string ARG_DUMP_ALL = "-a";
37 const std::string ARG_DUMP_FOLD_STATUS = "-f";
38
39 constexpr int MOTION_SENSOR_PARAM_SIZE = 2;
40 const std::string STATUS_FOLD_HALF = "-z";
41 const std::string STATUS_EXPAND = "-y";
42 const std::string STATUS_FOLD = "-p";
43 const std::string ARG_SET_ROTATION_SENSOR = "-motion"; // rotation event inject
44 const std::string ARG_SET_ROTATION_LOCK = "-rotationlock";
45 const std::string ARG_FOLD_DISPLAY_FULL = "-f";
46 const std::string ARG_FOLD_DISPLAY_MAIN = "-m";
47 const std::string ARG_FOLD_DISPLAY_SUB = "-sub";
48 const std::string ARG_FOLD_DISPLAY_COOR = "-coor";
49 const std::vector<std::string> displayModeCommands = {"-f", "-m", "-sub", "-coor"};
50 const std::string ARG_LOCK_FOLD_DISPLAY_STATUS = "-l";
51 const std::string ARG_UNLOCK_FOLD_DISPLAY_STATUS = "-u";
52 const std::string ARG_SET_ON_TENT_MODE = "-ontent";
53 const std::string ARG_SET_OFF_TENT_MODE = "-offtent";
54 const std::string ARG_SET_HOVER_STATUS = "-hoverstatus";
55 const std::string ARG_SET_POSTURE_HALL = "-posture";
56 const std::string ARG_SET_POSTURE_HALL_STATUS = "-registerhall"; // 关闭开合sensor报值
57 }
58
GetProcessNameByPid(int32_t pid)59 static std::string GetProcessNameByPid(int32_t pid)
60 {
61 std::string filePath = "/proc/" + std::to_string(pid) + "/comm";
62 char tmpPath[PATH_MAX] = { 0 };
63 if (!realpath(filePath.c_str(), tmpPath)) {
64 return "UNKNOWN";
65 }
66 std::ifstream infile(filePath);
67 if (!infile.is_open()) {
68 return "UNKNOWN";
69 }
70 std::string processName = "UNKNOWN";
71 std::getline(infile, processName);
72 infile.close();
73 return processName;
74 }
75
ScreenSessionDumper(int fd,const std::vector<std::u16string> & args)76 ScreenSessionDumper::ScreenSessionDumper(int fd, const std::vector<std::u16string>& args)
77 : fd_(fd)
78 {
79 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> cv;
80 std::string info;
81 for (auto& u16str: args) {
82 std::string arg = cv.to_bytes(u16str);
83 params_.emplace_back(arg);
84 info += arg;
85 }
86 TLOGI(WmsLogTag::DMS, "input args: [%{public}s]", info.c_str());
87 }
88
IsNumber(std::string str)89 bool ScreenSessionDumper::IsNumber(std::string str)
90 {
91 if (str.size() == 0) {
92 return false;
93 }
94 for (int32_t i = 0; i < static_cast<int32_t>(str.size()); i++) {
95 if (str.at(i) < '0' || str.at(i) > '9') {
96 return false;
97 }
98 }
99 return true;
100 }
101
OutputDumpInfo()102 void ScreenSessionDumper::OutputDumpInfo()
103 {
104 if (fd_ < 0) {
105 TLOGE(WmsLogTag::DMS, "invalid fd: %{public}d", fd_);
106 return;
107 }
108
109 static_cast<void>(signal(SIGPIPE, SIG_IGN)); // ignore SIGPIPE crash
110 int ret = dprintf(fd_, "%s\n", dumpInfo_.c_str());
111 if (ret < 0) {
112 TLOGE(WmsLogTag::DMS, "dprintf error. ret: %{public}d", ret);
113 return;
114 }
115 dumpInfo_.clear();
116 }
117
118
ExcuteDumpCmd()119 void ScreenSessionDumper::ExcuteDumpCmd()
120 {
121 if (params_.empty() || params_[0] == ARG_DUMP_HELP) { //help command
122 ShowHelpInfo();
123 }
124
125 if (!(SessionPermission::IsSACalling() || SessionPermission::IsStartByHdcd())) {
126 TLOGE(WmsLogTag::DMS, "dump permission denied!");
127 return;
128 }
129 if (!params_.empty() && params_[0] == ARG_DUMP_ALL) { // dump all info command
130 ShowAllScreenInfo();
131 } else if (!params_.empty() && params_[0] == ARG_DUMP_FOLD_STATUS) { // dump fold status command
132 DumpFoldStatus();
133 }
134 ExcuteInjectCmd();
135 OutputDumpInfo();
136 }
137
ExcuteInjectCmd()138 void ScreenSessionDumper::ExcuteInjectCmd()
139 {
140 bool isDeveloperMode = system::GetBoolParameter("const.security.developermode.state", false);
141 if (isDeveloperMode) {
142 if (params_.size() == 1 && IsValidDisplayModeCommand(params_[0])) {
143 int errCode = SetFoldDisplayMode();
144 if (errCode != 0) {
145 ShowIllegalArgsInfo();
146 }
147 return;
148 }
149 }
150
151 bool isDebugMode = system::GetBoolParameter("dms.hidumper.supportdebug", false);
152 if (!isDebugMode) {
153 TLOGI(WmsLogTag::DMS, "Can't use DMS hidumper inject methods.");
154 dumpInfo_.append("dms.hidumper.supportdebug false\n");
155 return;
156 }
157 if (params_[0] == STATUS_FOLD_HALF || params_[0] == STATUS_EXPAND || params_[0] == STATUS_FOLD) {
158 ShowNotifyFoldStatusChangedInfo();
159 return;
160 } else if (params_[0].find(ARG_SET_ROTATION_SENSOR) != std::string::npos) {
161 SetMotionSensorvalue(params_[0]);
162 return;
163 } else if (params_[0].find(ARG_SET_ROTATION_LOCK) != std::string::npos) {
164 SetRotationLockedvalue(params_[0]);
165 return;
166 } else if (params_.size() == 1 && (params_[0] == ARG_LOCK_FOLD_DISPLAY_STATUS
167 || params_[0] == ARG_UNLOCK_FOLD_DISPLAY_STATUS)) {
168 int errCode = SetFoldStatusLocked();
169 if (errCode != 0) {
170 ShowIllegalArgsInfo();
171 }
172 return;
173 }
174 ExcuteInjectCmd2();
175 }
176
ExcuteInjectCmd2()177 void ScreenSessionDumper::ExcuteInjectCmd2()
178 {
179 if (params_[0].find(ARG_SET_ON_TENT_MODE) != std::string::npos ||
180 params_[0].find(ARG_SET_OFF_TENT_MODE) != std::string::npos) {
181 SetEnterOrExitTentMode(params_[0]);
182 } else if (params_[0].find(ARG_SET_HOVER_STATUS) != std::string::npos) {
183 SetHoverStatusChange(params_[0]);
184 } else if (params_[0].find(ARG_SET_POSTURE_HALL) != std::string::npos) {
185 SetHallAndPostureValue(params_[0]);
186 } else if (params_[0].find(ARG_SET_POSTURE_HALL_STATUS) != std::string::npos) {
187 SetHallAndPostureStatus(params_[0]);
188 }
189 }
190
DumpEventTracker(EventTracker & tracker)191 void ScreenSessionDumper::DumpEventTracker(EventTracker& tracker)
192 {
193 std::ostringstream oss;
194 auto recordInfos = tracker.GetRecordInfos();
195 oss << "-------------- DMS KEY EVENTS LIST --------------" << std::endl;
196 for (const auto& info : recordInfos) {
197 oss << std::left << "[" << tracker.formatTimestamp(info.timestamp).c_str()
198 << "]: " << info.info.c_str() << std::endl;
199 }
200 dumpInfo_.append(oss.str());
201 }
202
DumpMultiUserInfo(std::vector<int32_t> oldScbPids,int32_t userId,int32_t ScbPid)203 void ScreenSessionDumper::DumpMultiUserInfo(std::vector<int32_t> oldScbPids, int32_t userId, int32_t ScbPid)
204 {
205 std::ostringstream oss;
206 oss << "-------------- DMS Multi User Info --------------" << std::endl;
207 oss << std::left << "[oldScbPid:] ";
208 for (auto oldScbPid : oldScbPids) {
209 oss << oldScbPid << " ";
210 }
211 oss << std::endl;
212 oss << std::left << "[userId:] " << userId << std::endl;
213 oss << std::left << "[ScbPid:] " << ScbPid << std::endl;
214 dumpInfo_.append(oss.str());
215 }
216
DumpFreezedPidList(std::set<int32_t> pidList)217 void ScreenSessionDumper::DumpFreezedPidList(std::set<int32_t> pidList)
218 {
219 std::ostringstream oss;
220 oss << "-------------- DMS FREEZED PID LIST --------------" << std::endl;
221 for (auto pid : pidList) {
222 oss << std::left << "[PID: " << pid << "]: "
223 << " [" << GetProcessNameByPid(pid) << "]"<< std::endl;
224 }
225 dumpInfo_.append(oss.str());
226 }
227
ShowHelpInfo()228 void ScreenSessionDumper::ShowHelpInfo()
229 {
230 dumpInfo_.append("Usage:\n")
231 .append(" -h ")
232 .append("|help text for the tool\n")
233 .append(" -a ")
234 .append("|dump all screen information in the system\n")
235 .append(" -z ")
236 .append("|switch to fold half status\n")
237 .append(" -y ")
238 .append("|switch to expand status\n")
239 .append(" -p ")
240 .append("|switch to fold status\n")
241 .append(" -f ")
242 .append("|get to fold status\n");
243 }
244
ShowAllScreenInfo()245 void ScreenSessionDumper::ShowAllScreenInfo()
246 {
247 std::vector<ScreenId> screenIds = ScreenSessionManager::GetInstance().GetAllScreenIds();
248 for (auto screenId : screenIds) {
249 std::ostringstream oss;
250 oss << "---------------- Screen ID: " << screenId << " ----------------" << std::endl;
251 dumpInfo_.append(oss.str());
252 DumpFoldStatus();
253 DumpTentMode();
254 DumpScreenSessionById(screenId);
255 DumpRsInfoById(screenId);
256 DumpCutoutInfoById(screenId);
257 DumpScreenInfoById(screenId);
258 DumpScreenPropertyById(screenId);
259 }
260 }
261
DumpFoldStatus()262 void ScreenSessionDumper::DumpFoldStatus()
263 {
264 std::ostringstream oss;
265 auto foldStatus = ScreenSessionManager::GetInstance().GetFoldStatus();
266 std::string status = "";
267 switch (foldStatus) {
268 case FoldStatus::EXPAND: {
269 status = "EXPAND";
270 break;
271 }
272 case FoldStatus::FOLDED: {
273 status = "FOLDED";
274 break;
275 }
276 case FoldStatus::HALF_FOLD: {
277 status = "HALF_FOLD";
278 break;
279 }
280 default: {
281 status = "UNKNOWN";
282 break;
283 }
284 }
285 oss << std::left << std::setw(LINE_WIDTH) << "FoldStatus: "
286 << status << std::endl;
287 dumpInfo_.append(oss.str());
288 }
289
DumpTentMode()290 void ScreenSessionDumper::DumpTentMode()
291 {
292 std::ostringstream oss;
293 bool isTentMode = ScreenSessionManager::GetInstance().GetTentMode();
294 std::string status = "";
295 if (isTentMode) {
296 status = "TRUE";
297 } else {
298 status = "FALSE";
299 }
300 oss << std::left << std::setw(LINE_WIDTH) << "TentMode: "
301 << status << std::endl;
302 dumpInfo_.append(oss.str());
303 }
304
DumpScreenSessionById(ScreenId id)305 void ScreenSessionDumper::DumpScreenSessionById(ScreenId id)
306 {
307 std::ostringstream oss;
308 oss << "[SCREEN SESSION]" << std::endl;
309 auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(id);
310 if (screenSession == nullptr) {
311 TLOGE(WmsLogTag::DMS, "screenSession nullptr. screen id: %{public}" PRIu64"", id);
312 return;
313 }
314 oss << std::left << std::setw(LINE_WIDTH) << "Name: "
315 << screenSession->GetName() << std::endl;
316 oss << std::left << std::setw(LINE_WIDTH) << "RSScreenId: "
317 << screenSession->GetRSScreenId() << std::endl;
318 sptr<SupportedScreenModes> activeModes = screenSession->GetActiveScreenMode();
319 if (activeModes != nullptr) {
320 oss << std::left << std::setw(LINE_WIDTH) << "activeModes<id, W, H, RS>: "
321 << activeModes->id_ << ", " << activeModes->width_ << ", "
322 << activeModes->height_ << ", " << activeModes->refreshRate_ << std::endl;
323 }
324 oss << std::left << std::setw(LINE_WIDTH) << "SourceMode: "
325 << static_cast<int32_t>(screenSession->GetSourceMode()) << std::endl;
326 oss << std::left << std::setw(LINE_WIDTH) << "ScreenCombination: "
327 << static_cast<int32_t>(screenSession->GetScreenCombination()) << std::endl;
328 oss << std::left << std::setw(LINE_WIDTH) << "Orientation: "
329 << static_cast<int32_t>(screenSession->GetOrientation()) << std::endl;
330 oss << std::left << std::setw(LINE_WIDTH) << "Rotation: "
331 << static_cast<int32_t>(screenSession->GetRotation()) << std::endl;
332 oss << std::left << std::setw(LINE_WIDTH) << "ScreenRequestedOrientation: "
333 << static_cast<int32_t>(screenSession->GetScreenRequestedOrientation()) << std::endl;
334 dumpInfo_.append(oss.str());
335 }
336
DumpRsInfoById(ScreenId id)337 void ScreenSessionDumper::DumpRsInfoById(ScreenId id)
338 {
339 std::ostringstream oss;
340 oss << "[RS INFO]" << std::endl;
341 auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(id);
342 if (screenSession == nullptr) {
343 TLOGE(WmsLogTag::DMS, "screenSession nullptr. screen id: %{public}" PRIu64"", id);
344 return;
345 }
346 std::vector<ScreenColorGamut> colorGamuts;
347 DMError ret = screenSession->GetScreenSupportedColorGamuts(colorGamuts);
348 if (ret == DMError::DM_OK && colorGamuts.size() > 0) {
349 oss << std::left << std::setw(LINE_WIDTH) << "SupportedColorGamuts: ";
350 for (uint32_t i = 0; i < colorGamuts.size() - 1; i++) {
351 oss << static_cast<int32_t>(colorGamuts[i]) << ", ";
352 }
353 oss << static_cast<int32_t>(colorGamuts[colorGamuts.size() - 1]) << std::endl;
354 }
355 ScreenColorGamut colorGamut;
356 ret = screenSession->GetScreenColorGamut(colorGamut);
357 if (ret == DMError::DM_OK) {
358 oss << std::left << std::setw(LINE_WIDTH) << "ScreenColorGamut: "
359 << static_cast<int32_t>(colorGamut) << std::endl;
360 }
361 ScreenGamutMap gamutMap;
362 ret = screenSession->GetScreenGamutMap(gamutMap);
363 if (ret == DMError::DM_OK) {
364 oss << std::left << std::setw(LINE_WIDTH) << "ScreenGamutMap: "
365 << static_cast<int32_t>(gamutMap) << std::endl;
366 }
367 GraphicPixelFormat pixelFormat;
368 ret = screenSession->GetPixelFormat(pixelFormat);
369 if (ret == DMError::DM_OK) {
370 oss << std::left << std::setw(LINE_WIDTH) << "GraphicPixelFormat: "
371 << static_cast<int32_t>(pixelFormat) << std::endl;
372 }
373 dumpInfo_.append(oss.str());
374 DumpRsInfoById01(screenSession); // 拆分函数,避免函数过长
375 }
376
DumpRsInfoById01(sptr<ScreenSession> screenSession)377 void ScreenSessionDumper::DumpRsInfoById01(sptr<ScreenSession> screenSession)
378 {
379 std::ostringstream oss;
380 std::vector<ScreenHDRFormat> hdrFormats;
381 DMError ret = screenSession->GetSupportedHDRFormats(hdrFormats);
382 if (ret == DMError::DM_OK && hdrFormats.size() > 0) {
383 oss << std::left << std::setw(LINE_WIDTH) << "SupportedScreenHDRFormat: ";
384 for (uint32_t i = 0; i < hdrFormats.size() - 1; i++) {
385 oss << static_cast<int32_t>(hdrFormats[i]) << ", ";
386 }
387 oss << static_cast<int32_t>(hdrFormats[hdrFormats.size() - 1]) << std::endl;
388 }
389 ScreenHDRFormat hdrFormat;
390 ret = screenSession->GetScreenHDRFormat(hdrFormat);
391 if (ret == DMError::DM_OK) {
392 oss << std::left << std::setw(LINE_WIDTH) << "ScreenHDRFormat: "
393 << static_cast<int32_t>(hdrFormat) << std::endl;
394 }
395 std::vector<GraphicCM_ColorSpaceType> colorSpaces;
396 ret = screenSession->GetSupportedColorSpaces(colorSpaces);
397 if (ret == DMError::DM_OK && colorSpaces.size() > 0) {
398 oss << std::left << std::setw(LINE_WIDTH) << "SupportedColorSpaces: ";
399 for (uint32_t i = 0; i < colorSpaces.size() - 1; i++) {
400 oss << static_cast<int32_t>(colorSpaces[i]) << ", ";
401 }
402 oss << static_cast<int32_t>(colorSpaces[colorSpaces.size() - 1]) << std::endl;
403 }
404 GraphicCM_ColorSpaceType colorSpace;
405 ret = screenSession->GetScreenColorSpace(colorSpace);
406 if (ret == DMError::DM_OK) {
407 oss << std::left << std::setw(LINE_WIDTH) << "ScreenColorSpace: "
408 << static_cast<int32_t>(colorSpace) << std::endl;
409 }
410 dumpInfo_.append(oss.str());
411 }
412
DumpCutoutInfoById(ScreenId id)413 void ScreenSessionDumper::DumpCutoutInfoById(ScreenId id)
414 {
415 std::ostringstream oss;
416 oss << "[CUTOUT INFO]" << std::endl;
417 sptr<CutoutInfo> cutoutInfo = ScreenSessionManager::GetInstance().GetCutoutInfo(id);
418 if (cutoutInfo == nullptr) {
419 TLOGE(WmsLogTag::DMS, "cutoutInfo nullptr. screen id: %{public}" PRIu64"", id);
420 return;
421 }
422 oss << std::left << std::setw(LINE_WIDTH) << "WaterFall_L<X,Y,W,H>: "
423 << cutoutInfo->GetWaterfallDisplayAreaRects().left.posX_ << ", "
424 << cutoutInfo->GetWaterfallDisplayAreaRects().left.posY_ << ", "
425 << cutoutInfo->GetWaterfallDisplayAreaRects().left.width_ << ", "
426 << cutoutInfo->GetWaterfallDisplayAreaRects().left.height_ << std::endl;
427 oss << std::left << std::setw(LINE_WIDTH) << "WaterFall_T<X,Y,W,H>: "
428 << cutoutInfo->GetWaterfallDisplayAreaRects().top.posX_ << ", "
429 << cutoutInfo->GetWaterfallDisplayAreaRects().top.posY_ << ", "
430 << cutoutInfo->GetWaterfallDisplayAreaRects().top.width_ << ", "
431 << cutoutInfo->GetWaterfallDisplayAreaRects().top.height_ << std::endl;
432 oss << std::left << std::setw(LINE_WIDTH) << "WaterFall_R<X,Y,W,H>: "
433 << cutoutInfo->GetWaterfallDisplayAreaRects().right.posX_ << ", "
434 << cutoutInfo->GetWaterfallDisplayAreaRects().right.posY_ << ", "
435 << cutoutInfo->GetWaterfallDisplayAreaRects().right.width_ << ", "
436 << cutoutInfo->GetWaterfallDisplayAreaRects().right.height_ << std::endl;
437 oss << std::left << std::setw(LINE_WIDTH) << "WaterFall_B<X,Y,W,H>: "
438 << cutoutInfo->GetWaterfallDisplayAreaRects().bottom.posX_ << ", "
439 << cutoutInfo->GetWaterfallDisplayAreaRects().bottom.posY_ << ", "
440 << cutoutInfo->GetWaterfallDisplayAreaRects().bottom.width_ << ", "
441 << cutoutInfo->GetWaterfallDisplayAreaRects().bottom.height_ << std::endl;
442
443 std::vector<DMRect> boundingRects = cutoutInfo->GetBoundingRects();
444 oss << std::left << std::setw(LINE_WIDTH) << "BoundingRects<X,Y,W,H>: ";
445 for (auto rect : boundingRects) {
446 oss << "[" << rect.posX_ << ", " << rect.posY_ << ", " << rect.width_ << ", " << rect.height_ << "] ";
447 }
448 oss << std::endl;
449 dumpInfo_.append(oss.str());
450 }
451
DumpScreenInfoById(ScreenId id)452 void ScreenSessionDumper::DumpScreenInfoById(ScreenId id)
453 {
454 std::ostringstream oss;
455 oss << "[SCREEN INFO]" << std::endl;
456 auto screenInfo = ScreenSessionManager::GetInstance().GetScreenInfoById(id);
457 if (screenInfo == nullptr) {
458 TLOGE(WmsLogTag::DMS, "screenInfo nullptr. screen id: %{public}" PRIu64"", id);
459 return;
460 }
461 oss << std::left << std::setw(LINE_WIDTH) << "VirtualWidth: "
462 << screenInfo->GetVirtualWidth() << std::endl;
463 oss << std::left << std::setw(LINE_WIDTH) << "VirtualHeight: "
464 << screenInfo->GetVirtualHeight() << std::endl;
465 oss << std::left << std::setw(LINE_WIDTH) << "LastParentId: "
466 << screenInfo->GetLastParentId() << std::endl;
467 oss << std::left << std::setw(LINE_WIDTH) << "ParentId: "
468 << screenInfo->GetParentId() << std::endl;
469 oss << std::left << std::setw(LINE_WIDTH) << "IsScreenGroup: "
470 << screenInfo->GetIsScreenGroup() << std::endl;
471 oss << std::left << std::setw(LINE_WIDTH) << "VirtualPixelRatio: "
472 << screenInfo->GetVirtualPixelRatio() << std::endl;
473 oss << std::left << std::setw(LINE_WIDTH) << "Rotation: "
474 << static_cast<int32_t>(screenInfo->GetRotation()) << std::endl;
475 oss << std::left << std::setw(LINE_WIDTH) << "Orientation: "
476 << static_cast<int32_t>(screenInfo->GetOrientation()) << std::endl;
477 oss << std::left << std::setw(LINE_WIDTH) << "SourceMode: "
478 << static_cast<int32_t>(screenInfo->GetSourceMode()) << std::endl;
479 oss << std::left << std::setw(LINE_WIDTH) << "ScreenType: "
480 << static_cast<int32_t>(screenInfo->GetType()) << std::endl;
481 dumpInfo_.append(oss.str());
482 }
483
DumpScreenPropertyById(ScreenId id)484 void ScreenSessionDumper::DumpScreenPropertyById(ScreenId id)
485 {
486 std::ostringstream oss;
487 oss << "[SCREEN PROPERTY]" << std::endl;
488 ScreenProperty screenProperty = ScreenSessionManager::GetInstance().GetScreenProperty(id);
489
490 oss << std::left << std::setw(LINE_WIDTH) << "Rotation: " << screenProperty.GetRotation() << std::endl;
491 oss << std::left << std::setw(LINE_WIDTH) << "Density: " << screenProperty.GetDensity() << std::endl;
492 oss << std::left << std::setw(LINE_WIDTH) << "DensityInCurResolution: "
493 << screenProperty.GetDensityInCurResolution() << std::endl;
494 oss << std::left << std::setw(LINE_WIDTH) << "PhyWidth: " << screenProperty.GetPhyWidth() << std::endl;
495 oss << std::left << std::setw(LINE_WIDTH) << "PhyHeight: " << screenProperty.GetPhyHeight() << std::endl;
496 oss << std::left << std::setw(LINE_WIDTH) << "RefreshRate: " << screenProperty.GetRefreshRate() << std::endl;
497 oss << std::left << std::setw(LINE_WIDTH) << "VirtualPixelRatio: "
498 << screenProperty.GetVirtualPixelRatio() << std::endl;
499 oss << std::left << std::setw(LINE_WIDTH) << "ScreenRotation: "
500 << static_cast<int32_t>(screenProperty.GetRotation()) << std::endl;
501 oss << std::left << std::setw(LINE_WIDTH) << "Orientation: "
502 << static_cast<int32_t>(screenProperty.GetOrientation()) << std::endl;
503 oss << std::left << std::setw(LINE_WIDTH) << "DisplayOrientation: "
504 << static_cast<int32_t>(screenProperty.GetDisplayOrientation()) << std::endl;
505 oss << std::left << std::setw(LINE_WIDTH) << "GetScreenType: "
506 << static_cast<int32_t>(screenProperty.GetScreenType()) << std::endl;
507 oss << std::left << std::setw(LINE_WIDTH) << "ReqOrientation: "
508 << static_cast<int32_t>(screenProperty.GetScreenRequestedOrientation()) << std::endl;
509 oss << std::left << std::setw(LINE_WIDTH) << "DPI<X, Y>: " << screenProperty.GetXDpi()
510 << ", " << screenProperty.GetYDpi() << std::endl;
511 oss << std::left << std::setw(LINE_WIDTH) << "Offset<X, Y>: " << screenProperty.GetOffsetX()
512 << ", " << screenProperty.GetOffsetY() << std::endl;
513 oss << std::left << std::setw(LINE_WIDTH) << "Bounds<L,T,W,H>: "
514 << screenProperty.GetBounds().rect_.GetLeft() << ", "
515 << screenProperty.GetBounds().rect_.GetTop() << ", "
516 << screenProperty.GetBounds().rect_.GetWidth() << ", "
517 << screenProperty.GetBounds().rect_.GetHeight() << ", " << std::endl;
518 oss << std::left << std::setw(LINE_WIDTH) << "PhyBounds<L,T,W,H>: "
519 << screenProperty.GetPhyBounds().rect_.GetLeft() << ", "
520 << screenProperty.GetPhyBounds().rect_.GetTop() << ", "
521 << screenProperty.GetPhyBounds().rect_.GetWidth() << ", "
522 << screenProperty.GetPhyBounds().rect_.GetHeight() << ", " << std::endl;
523 oss << std::left << std::setw(LINE_WIDTH) << "AvailableArea<X,Y,W,H> "
524 << screenProperty.GetAvailableArea().posX_ << ", "
525 << screenProperty.GetAvailableArea().posY_ << ", "
526 << screenProperty.GetAvailableArea().width_ << ", "
527 << screenProperty.GetAvailableArea().height_ << ", " << std::endl;
528 oss << std::left << std::setw(LINE_WIDTH) << "DefaultDeviceRotationOffset "
529 << screenProperty.GetDefaultDeviceRotationOffset() << std::endl;
530 dumpInfo_.append(oss.str());
531 }
532
533 /*
534 * hidumper inject methods
535 */
ShowNotifyFoldStatusChangedInfo()536 void ScreenSessionDumper::ShowNotifyFoldStatusChangedInfo()
537 {
538 TLOGI(WmsLogTag::DMS, "params_: [%{public}s]", params_[0].c_str());
539 int errCode = ScreenSessionManager::GetInstance().NotifyFoldStatusChanged(params_[0]);
540 if (errCode != 0) {
541 ShowIllegalArgsInfo();
542 } else {
543 std::ostringstream oss;
544 oss << "currentFoldStatus is: "
545 << static_cast<uint32_t>(ScreenSessionManager::GetInstance().GetFoldStatus())
546 << std::endl;
547 dumpInfo_.append(oss.str());
548 }
549 }
550
ShowIllegalArgsInfo()551 void ScreenSessionDumper::ShowIllegalArgsInfo()
552 {
553 dumpInfo_.append("The arguments are illegal and you can enter '-h' for help.");
554 }
555
SetMotionSensorvalue(std::string input)556 void ScreenSessionDumper::SetMotionSensorvalue(std::string input)
557 {
558 size_t commaPos = input.find_last_of(',');
559 if ((commaPos != std::string::npos) && (input.substr(0, commaPos) == ARG_SET_ROTATION_SENSOR)) {
560 std::string valueStr = input.substr(commaPos + 1, MOTION_SENSOR_PARAM_SIZE);
561 if (valueStr.size() == 1 && !std::isdigit(valueStr[0])) {
562 return;
563 }
564 if (valueStr.size() == MOTION_SENSOR_PARAM_SIZE && valueStr != "-1") {
565 return;
566 }
567 int32_t value = std::stoi(valueStr);
568 if (value < static_cast<int32_t>(DeviceRotation::INVALID) ||
569 value > static_cast<int32_t>(DeviceRotation::ROTATION_LANDSCAPE_INVERTED)) {
570 TLOGE(WmsLogTag::DMS, "params is invalid: %{public}d", value);
571 return;
572 }
573 ScreenRotationProperty::HandleSensorEventInput(static_cast<DeviceRotation>(value));
574 TLOGI(WmsLogTag::DMS, "mock motion sensor: %{public}d", value);
575 }
576 }
577
SetRotationLockedvalue(std::string input)578 void ScreenSessionDumper::SetRotationLockedvalue(std::string input)
579 {
580 size_t commaPos = input.find_last_of(',');
581 if ((commaPos != std::string::npos) && (input.substr(0, commaPos) == ARG_SET_ROTATION_LOCK)) {
582 std::string valueStr = input.substr(commaPos + 1);
583 if (valueStr.size() != 1) {
584 return;
585 }
586 if (!std::isdigit(valueStr[0])) {
587 return;
588 }
589 int32_t value = std::stoi(valueStr);
590 ScreenSessionManager::GetInstance().SetScreenRotationLocked(static_cast<bool>(value));
591 TLOGI(WmsLogTag::DMS, "mock rotation locked: %{public}d", value);
592 }
593 }
594
IsValidDisplayModeCommand(std::string command)595 bool ScreenSessionDumper::IsValidDisplayModeCommand(std::string command)
596 {
597 if (std::find(displayModeCommands.begin(), displayModeCommands.end(), command) != displayModeCommands.end()) {
598 return true;
599 }
600 return false;
601 }
602
SetFoldDisplayMode()603 int ScreenSessionDumper::SetFoldDisplayMode()
604 {
605 std::string modeParam = params_[0];
606 if (modeParam.empty()) {
607 return -1;
608 }
609 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
610 if (modeParam == ARG_FOLD_DISPLAY_FULL) {
611 displayMode = FoldDisplayMode::FULL;
612 } else if (modeParam == ARG_FOLD_DISPLAY_MAIN) {
613 displayMode = FoldDisplayMode::MAIN;
614 } else if (modeParam == ARG_FOLD_DISPLAY_SUB) {
615 displayMode = FoldDisplayMode::SUB;
616 } else if (modeParam == ARG_FOLD_DISPLAY_COOR) {
617 displayMode = FoldDisplayMode::COORDINATION;
618 } else {
619 TLOGW(WmsLogTag::DMS, "SetFoldDisplayMode mode not support");
620 return -1;
621 }
622 ScreenSessionManager::GetInstance().SetFoldDisplayMode(displayMode);
623 return 0;
624 }
625
SetFoldStatusLocked()626 int ScreenSessionDumper::SetFoldStatusLocked()
627 {
628 std::string lockParam = params_[0];
629 if (lockParam.empty()) {
630 return -1;
631 }
632 bool lockDisplayStatus = false;
633 if (lockParam == ARG_LOCK_FOLD_DISPLAY_STATUS) {
634 lockDisplayStatus = true;
635 } else if (lockParam == ARG_UNLOCK_FOLD_DISPLAY_STATUS) {
636 lockDisplayStatus = false;
637 } else {
638 TLOGW(WmsLogTag::DMS, "SetFoldStatusLocked status not support");
639 return -1;
640 }
641 ScreenSessionManager::GetInstance().SetFoldStatusLocked(lockDisplayStatus);
642 return 0;
643 }
644
SetEnterOrExitTentMode(std::string input)645 void ScreenSessionDumper::SetEnterOrExitTentMode(std::string input)
646 {
647 if (input == ARG_SET_ON_TENT_MODE) {
648 ScreenSessionManager::GetInstance().OnTentModeChanged(true);
649 } else if (input == ARG_SET_OFF_TENT_MODE) {
650 ScreenSessionManager::GetInstance().OnTentModeChanged(false);
651 }
652 }
653
SetHoverStatusChange(std::string input)654 void ScreenSessionDumper::SetHoverStatusChange(std::string input)
655 {
656 size_t commaPos = input.find_last_of(',');
657 auto screenSession = ScreenSessionManager::GetInstance().GetDefaultScreenSession();
658 if (screenSession == nullptr) {
659 TLOGE(WmsLogTag::DMS, "screenSession is nullptr");
660 return;
661 }
662 if ((commaPos != std::string::npos) && (input.substr(0, commaPos) == ARG_SET_HOVER_STATUS)) {
663 std::string valueStr = input.substr(commaPos + 1);
664 if (valueStr.size() != 1) {
665 dumpInfo_.append("[error]: the value is too long");
666 return;
667 }
668 if (!std::isdigit(valueStr[0])) {
669 dumpInfo_.append("[error]: value is not a number");
670 return;
671 }
672 int32_t value = std::stoi(valueStr);
673 if ((value < static_cast<int32_t>(DeviceHoverStatus::INVALID)) ||
674 (value > static_cast<int32_t>(DeviceHoverStatus::CAMERA_STATUS_CANCEL))) {
675 TLOGE(WmsLogTag::DMS, "params is invalid: %{public}d", value);
676 return;
677 }
678 screenSession->HoverStatusChange(value);
679 TLOGI(WmsLogTag::DMS, "SetHoverStatusChange: %{public}d", value);
680 }
681 }
682
SetHallAndPostureValue(std::string input)683 void ScreenSessionDumper::SetHallAndPostureValue(std::string input)
684 {
685 std::string token;
686 std::istringstream ss(input);
687 std::vector<std::string> tokens;
688 while (std::getline(ss, token, ',')) {
689 tokens.push_back(token);
690 }
691 if (tokens.size() != DUMPER_PARAM_INDEX_THREE && tokens[0] != ARG_SET_POSTURE_HALL) {
692 TLOGE(WmsLogTag::DMS, "param error: %{public}s", input.c_str());
693 return;
694 }
695 if (!IsNumber(tokens[DUMPER_PARAM_INDEX_ONE]) || !IsNumber(tokens[DUMPER_PARAM_INDEX_TWO])) {
696 TLOGE(WmsLogTag::DMS, "param error: %{public}s", input.c_str());
697 return;
698 }
699 int hallVal = stoi(tokens[DUMPER_PARAM_INDEX_ONE]);
700 int postureVal = stoi(tokens[DUMPER_PARAM_INDEX_TWO]);
701 ExtHallData hallData = {(1 << 1), hallVal};
702 PostureData postureData = {
703 .angle = postureVal,
704 };
705 SensorEvent hallEvent = {
706 .data = reinterpret_cast<uint8_t *>(&hallData),
707 .dataLen = sizeof(ExtHallData),
708 };
709 SensorEvent postureEvent = {
710 .data = reinterpret_cast<uint8_t *>(&postureData),
711 .dataLen = sizeof(PostureData),
712 };
713 OHOS::Rosen::FoldScreenSensorManager::GetInstance().HandleHallData(&hallEvent);
714 OHOS::Rosen::FoldScreenSensorManager::GetInstance().HandlePostureData(&postureEvent);
715 TLOGI(WmsLogTag::DMS, "mock posture: %{public}d, hall: %{public}d ", postureVal, hallVal);
716 }
717
SetHallAndPostureStatus(std::string input)718 void ScreenSessionDumper::SetHallAndPostureStatus(std::string input)
719 {
720 size_t commaPos = input.find_last_of(',');
721 if ((commaPos != std::string::npos) && (input.substr(0, commaPos) == ARG_SET_POSTURE_HALL_STATUS)) {
722 std::string valueStr = input.substr(commaPos + 1, DUMPER_PARAM_INDEX_ONE);
723 if (valueStr.size() != DUMPER_PARAM_INDEX_ONE && !std::isdigit(valueStr[0])) {
724 return;
725 }
726 int32_t value = std::stoi(valueStr);
727 if (value) {
728 OHOS::Rosen::FoldScreenSensorManager::GetInstance().RegisterHallCallback();
729 OHOS::Rosen::FoldScreenSensorManager::GetInstance().RegisterPostureCallback();
730 OHOS::Rosen::ScreenSensorConnector::SubscribeRotationSensor();
731 } else {
732 OHOS::Rosen::FoldScreenSensorManager::GetInstance().UnRegisterHallCallback();
733 OHOS::Rosen::FoldScreenSensorManager::GetInstance().UnRegisterPostureCallback();
734 OHOS::Rosen::ScreenSensorConnector::UnsubscribeRotationSensor();
735 }
736 TLOGI(WmsLogTag::DMS, "hall and posture register status: %{public}d", value);
737 }
738 }
739
740 } // Rosen
741 } // OHOS