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
20 #include "unique_fd.h"
21 #include "screen_session_manager.h"
22 #include "session_permission.h"
23 #include "parameters.h"
24
25 namespace OHOS {
26 namespace Rosen {
27 namespace {
28 constexpr int LINE_WIDTH = 30;
29 const std::string ARG_DUMP_HELP = "-h";
30 const std::string ARG_DUMP_ALL = "-a";
31 const std::string ARG_DUMP_FOLD_STATUS = "-f";
32
33 const std::string STATUS_FOLD_HALF = "-z";
34 const std::string STATUS_EXPAND = "-y";
35 const std::string STATUS_FOLD = "-p";
36 const std::string ARG_FOLD_DISPLAY_FULL = "-f";
37 const std::string ARG_FOLD_DISPLAY_MAIN = "-m";
38 const std::string ARG_FOLD_DISPLAY_SUB = "-sub";
39 const std::string ARG_FOLD_DISPLAY_COOR = "-coor";
40 const std::vector<std::string> displayModeCommands = {"-f", "-m", "-sub", "-coor"};
41 const std::string ARG_LOCK_FOLD_DISPLAY_STATUS = "-l";
42 const std::string ARG_UNLOCK_FOLD_DISPLAY_STATUS = "-u";
43 }
44
GetProcessNameByPid(int32_t pid)45 static std::string GetProcessNameByPid(int32_t pid)
46 {
47 std::string filePath = "/proc/" + std::to_string(pid) + "/comm";
48 char tmpPath[PATH_MAX] = { 0 };
49 if (!realpath(filePath.c_str(), tmpPath)) {
50 return "UNKNOWN";
51 }
52 std::ifstream infile(filePath);
53 if (!infile.is_open()) {
54 return "UNKNOWN";
55 }
56 std::string processName = "UNKNOWN";
57 std::getline(infile, processName);
58 infile.close();
59 return processName;
60 }
61
ScreenSessionDumper(int fd,const std::vector<std::u16string> & args)62 ScreenSessionDumper::ScreenSessionDumper(int fd, const std::vector<std::u16string>& args)
63 : fd_(fd)
64 {
65 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> cv;
66 std::string info;
67 for (auto& u16str: args) {
68 std::string arg = cv.to_bytes(u16str);
69 params_.emplace_back(arg);
70 info += arg;
71 }
72 TLOGI(WmsLogTag::DMS, "input args: [%{public}s]", info.c_str());
73 }
74
OutputDumpInfo()75 void ScreenSessionDumper::OutputDumpInfo()
76 {
77 if (fd_ < 0) {
78 TLOGE(WmsLogTag::DMS, "invalid fd: %{public}d", fd_);
79 return;
80 }
81
82 static_cast<void>(signal(SIGPIPE, SIG_IGN)); // ignore SIGPIPE crash
83 int ret = dprintf(fd_, "%s\n", dumpInfo_.c_str());
84 if (ret < 0) {
85 TLOGE(WmsLogTag::DMS, "dprintf error. ret: %{public}d", ret);
86 return;
87 }
88 dumpInfo_.clear();
89 }
90
91
ExcuteDumpCmd()92 void ScreenSessionDumper::ExcuteDumpCmd()
93 {
94 if (params_.empty() || params_[0] == ARG_DUMP_HELP) { //help command
95 ShowHelpInfo();
96 }
97
98 if (!(SessionPermission::IsSACalling() || SessionPermission::IsStartByHdcd())) {
99 TLOGE(WmsLogTag::DMS, "dump permission denied!");
100 return;
101 }
102 if (!params_.empty() && params_[0] == ARG_DUMP_ALL) { // dump all info command
103 ShowAllScreenInfo();
104 } else if (!params_.empty() && params_[0] == ARG_DUMP_FOLD_STATUS) { // dump fold status command
105 DumpFoldStatus();
106 }
107 ExcuteInjectCmd();
108 OutputDumpInfo();
109 }
110
ExcuteInjectCmd()111 void ScreenSessionDumper::ExcuteInjectCmd()
112 {
113 bool isDebugMode = system::GetBoolParameter("dms.hidumper.supportdebug", false);
114 if (!isDebugMode) {
115 TLOGI(WmsLogTag::DMS, "Can't use DMS hidumper inject methods.");
116 dumpInfo_.append("dms.hidumper.supportdebug false\n");
117 return;
118 }
119 if (params_[0] == STATUS_FOLD_HALF || params_[0] == STATUS_EXPAND || params_[0] == STATUS_FOLD) {
120 ShowNotifyFoldStatusChangedInfo();
121 } else if (params_.size() == 1 && IsValidDisplayModeCommand(params_[0])) {
122 int errCode = SetFoldDisplayMode();
123 if (errCode != 0) {
124 ShowIllegalArgsInfo();
125 }
126 } else if (params_.size() == 1 && (params_[0] == ARG_LOCK_FOLD_DISPLAY_STATUS
127 || params_[0] == ARG_UNLOCK_FOLD_DISPLAY_STATUS)) {
128 int errCode = SetFoldStatusLocked();
129 if (errCode != 0) {
130 ShowIllegalArgsInfo();
131 }
132 }
133 }
134
DumpEventTracker(EventTracker & tracker)135 void ScreenSessionDumper::DumpEventTracker(EventTracker& tracker)
136 {
137 std::ostringstream oss;
138 auto recordInfos = tracker.GetRecordInfos();
139 oss << "-------------- DMS KEY EVENTS LIST --------------" << std::endl;
140 for (const auto& info : recordInfos) {
141 oss << std::left << "[" << tracker.formatTimestamp(info.timestamp).c_str()
142 << "]: " << info.info.c_str() << std::endl;
143 }
144 dumpInfo_.append(oss.str());
145 }
146
DumpMultiUserInfo(std::vector<int32_t> oldScbPids,int32_t userId,int32_t ScbPid)147 void ScreenSessionDumper::DumpMultiUserInfo(std::vector<int32_t> oldScbPids, int32_t userId, int32_t ScbPid)
148 {
149 std::ostringstream oss;
150 oss << "-------------- DMS Multi User Info --------------" << std::endl;
151 oss << std::left << "[oldScbPid:] ";
152 for (auto oldScbPid : oldScbPids) {
153 oss << oldScbPid << " ";
154 }
155 oss << std::endl;
156 oss << std::left << "[userId:] " << userId << std::endl;
157 oss << std::left << "[ScbPid:] " << ScbPid << std::endl;
158 dumpInfo_.append(oss.str());
159 }
160
DumpFreezedPidList(std::set<int32_t> pidList)161 void ScreenSessionDumper::DumpFreezedPidList(std::set<int32_t> pidList)
162 {
163 std::ostringstream oss;
164 oss << "-------------- DMS FREEZED PID LIST --------------" << std::endl;
165 for (auto pid : pidList) {
166 oss << std::left << "[PID: " << pid << "]: "
167 << " [" << GetProcessNameByPid(pid) << "]"<< std::endl;
168 }
169 dumpInfo_.append(oss.str());
170 }
171
ShowHelpInfo()172 void ScreenSessionDumper::ShowHelpInfo()
173 {
174 dumpInfo_.append("Usage:\n")
175 .append(" -h ")
176 .append("|help text for the tool\n")
177 .append(" -a ")
178 .append("|dump all screen information in the system\n")
179 .append(" -z ")
180 .append("|switch to fold half status\n")
181 .append(" -y ")
182 .append("|switch to expand status\n")
183 .append(" -p ")
184 .append("|switch to fold status\n")
185 .append(" -f ")
186 .append("|get to fold status\n");
187 }
188
ShowAllScreenInfo()189 void ScreenSessionDumper::ShowAllScreenInfo()
190 {
191 std::vector<ScreenId> screenIds = ScreenSessionManager::GetInstance().GetAllScreenIds();
192 for (auto screenId : screenIds) {
193 std::ostringstream oss;
194 oss << "---------------- Screen ID: " << screenId << " ----------------" << std::endl;
195 dumpInfo_.append(oss.str());
196 DumpFoldStatus();
197 DumpScreenSessionById(screenId);
198 DumpRsInfoById(screenId);
199 DumpCutoutInfoById(screenId);
200 DumpScreenInfoById(screenId);
201 DumpScreenPropertyById(screenId);
202 }
203 }
204
DumpFoldStatus()205 void ScreenSessionDumper::DumpFoldStatus()
206 {
207 std::ostringstream oss;
208 auto foldStatus = ScreenSessionManager::GetInstance().GetFoldStatus();
209 std::string status = "";
210 switch (foldStatus) {
211 case FoldStatus::EXPAND: {
212 status = "EXPAND";
213 break;
214 }
215 case FoldStatus::FOLDED: {
216 status = "FOLDED";
217 break;
218 }
219 case FoldStatus::HALF_FOLD: {
220 status = "HALF_FOLD";
221 break;
222 }
223 default: {
224 status = "UNKNOWN";
225 break;
226 }
227 }
228 oss << std::left << std::setw(LINE_WIDTH) << "FoldStatus: "
229 << status << std::endl;
230 dumpInfo_.append(oss.str());
231 }
232
DumpScreenSessionById(ScreenId id)233 void ScreenSessionDumper::DumpScreenSessionById(ScreenId id)
234 {
235 std::ostringstream oss;
236 oss << "[SCREEN SESSION]" << std::endl;
237 auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(id);
238 if (screenSession == nullptr) {
239 TLOGE(WmsLogTag::DMS, "screenSession nullptr. screen id: %{public}" PRIu64"", id);
240 return;
241 }
242 oss << std::left << std::setw(LINE_WIDTH) << "Name: "
243 << screenSession->GetName() << std::endl;
244 oss << std::left << std::setw(LINE_WIDTH) << "RSScreenId: "
245 << screenSession->GetRSScreenId() << std::endl;
246 sptr<SupportedScreenModes> activeModes = screenSession->GetActiveScreenMode();
247 if (activeModes != nullptr) {
248 oss << std::left << std::setw(LINE_WIDTH) << "activeModes<id, W, H, RS>: "
249 << activeModes->id_ << ", " << activeModes->width_ << ", "
250 << activeModes->height_ << ", " << activeModes->refreshRate_ << std::endl;
251 }
252 oss << std::left << std::setw(LINE_WIDTH) << "SourceMode: "
253 << static_cast<int32_t>(screenSession->GetSourceMode()) << std::endl;
254 oss << std::left << std::setw(LINE_WIDTH) << "ScreenCombination: "
255 << static_cast<int32_t>(screenSession->GetScreenCombination()) << std::endl;
256 oss << std::left << std::setw(LINE_WIDTH) << "Orientation: "
257 << static_cast<int32_t>(screenSession->GetOrientation()) << std::endl;
258 oss << std::left << std::setw(LINE_WIDTH) << "Rotation: "
259 << static_cast<int32_t>(screenSession->GetRotation()) << std::endl;
260 oss << std::left << std::setw(LINE_WIDTH) << "ScreenRequestedOrientation: "
261 << static_cast<int32_t>(screenSession->GetScreenRequestedOrientation()) << std::endl;
262 dumpInfo_.append(oss.str());
263 }
264
DumpRsInfoById(ScreenId id)265 void ScreenSessionDumper::DumpRsInfoById(ScreenId id)
266 {
267 std::ostringstream oss;
268 oss << "[RS INFO]" << std::endl;
269 auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(id);
270 if (screenSession == nullptr) {
271 TLOGE(WmsLogTag::DMS, "screenSession nullptr. screen id: %{public}" PRIu64"", id);
272 return;
273 }
274 std::vector<ScreenColorGamut> colorGamuts;
275 DMError ret = screenSession->GetScreenSupportedColorGamuts(colorGamuts);
276 if (ret == DMError::DM_OK && colorGamuts.size() > 0) {
277 oss << std::left << std::setw(LINE_WIDTH) << "SupportedColorGamuts: ";
278 for (uint32_t i = 0; i < colorGamuts.size() - 1; i++) {
279 oss << static_cast<int32_t>(colorGamuts[i]) << ", ";
280 }
281 oss << static_cast<int32_t>(colorGamuts[colorGamuts.size() - 1]) << std::endl;
282 }
283 ScreenColorGamut colorGamut;
284 ret = screenSession->GetScreenColorGamut(colorGamut);
285 if (ret == DMError::DM_OK) {
286 oss << std::left << std::setw(LINE_WIDTH) << "ScreenColorGamut: "
287 << static_cast<int32_t>(colorGamut) << std::endl;
288 }
289 ScreenGamutMap gamutMap;
290 ret = screenSession->GetScreenGamutMap(gamutMap);
291 if (ret == DMError::DM_OK) {
292 oss << std::left << std::setw(LINE_WIDTH) << "ScreenGamutMap: "
293 << static_cast<int32_t>(gamutMap) << std::endl;
294 }
295 GraphicPixelFormat pixelFormat;
296 ret = screenSession->GetPixelFormat(pixelFormat);
297 if (ret == DMError::DM_OK) {
298 oss << std::left << std::setw(LINE_WIDTH) << "GraphicPixelFormat: "
299 << static_cast<int32_t>(pixelFormat) << std::endl;
300 }
301 dumpInfo_.append(oss.str());
302 DumpRsInfoById01(screenSession); // 拆分函数,避免函数过长
303 }
304
DumpRsInfoById01(sptr<ScreenSession> screenSession)305 void ScreenSessionDumper::DumpRsInfoById01(sptr<ScreenSession> screenSession)
306 {
307 std::ostringstream oss;
308 std::vector<ScreenHDRFormat> hdrFormats;
309 DMError ret = screenSession->GetSupportedHDRFormats(hdrFormats);
310 if (ret == DMError::DM_OK && hdrFormats.size() > 0) {
311 oss << std::left << std::setw(LINE_WIDTH) << "SupportedScreenHDRFormat: ";
312 for (uint32_t i = 0; i < hdrFormats.size() - 1; i++) {
313 oss << static_cast<int32_t>(hdrFormats[i]) << ", ";
314 }
315 oss << static_cast<int32_t>(hdrFormats[hdrFormats.size() - 1]) << std::endl;
316 }
317 ScreenHDRFormat hdrFormat;
318 ret = screenSession->GetScreenHDRFormat(hdrFormat);
319 if (ret == DMError::DM_OK) {
320 oss << std::left << std::setw(LINE_WIDTH) << "ScreenHDRFormat: "
321 << static_cast<int32_t>(hdrFormat) << std::endl;
322 }
323 std::vector<GraphicCM_ColorSpaceType> colorSpaces;
324 ret = screenSession->GetSupportedColorSpaces(colorSpaces);
325 if (ret == DMError::DM_OK && colorSpaces.size() > 0) {
326 oss << std::left << std::setw(LINE_WIDTH) << "SupportedColorSpaces: ";
327 for (uint32_t i = 0; i < colorSpaces.size() - 1; i++) {
328 oss << static_cast<int32_t>(colorSpaces[i]) << ", ";
329 }
330 oss << static_cast<int32_t>(colorSpaces[colorSpaces.size() - 1]) << std::endl;
331 }
332 GraphicCM_ColorSpaceType colorSpace;
333 ret = screenSession->GetScreenColorSpace(colorSpace);
334 if (ret == DMError::DM_OK) {
335 oss << std::left << std::setw(LINE_WIDTH) << "ScreenColorSpace: "
336 << static_cast<int32_t>(colorSpace) << std::endl;
337 }
338 dumpInfo_.append(oss.str());
339 }
340
DumpCutoutInfoById(ScreenId id)341 void ScreenSessionDumper::DumpCutoutInfoById(ScreenId id)
342 {
343 std::ostringstream oss;
344 oss << "[CUTOUT INFO]" << std::endl;
345 sptr<CutoutInfo> cutoutInfo = ScreenSessionManager::GetInstance().GetCutoutInfo(id);
346 if (cutoutInfo == nullptr) {
347 TLOGE(WmsLogTag::DMS, "cutoutInfo nullptr. screen id: %{public}" PRIu64"", id);
348 return;
349 }
350 oss << std::left << std::setw(LINE_WIDTH) << "WaterFall_L<X,Y,W,H>: "
351 << cutoutInfo->GetWaterfallDisplayAreaRects().left.posX_ << ", "
352 << cutoutInfo->GetWaterfallDisplayAreaRects().left.posY_ << ", "
353 << cutoutInfo->GetWaterfallDisplayAreaRects().left.width_ << ", "
354 << cutoutInfo->GetWaterfallDisplayAreaRects().left.height_ << std::endl;
355 oss << std::left << std::setw(LINE_WIDTH) << "WaterFall_T<X,Y,W,H>: "
356 << cutoutInfo->GetWaterfallDisplayAreaRects().top.posX_ << ", "
357 << cutoutInfo->GetWaterfallDisplayAreaRects().top.posY_ << ", "
358 << cutoutInfo->GetWaterfallDisplayAreaRects().top.width_ << ", "
359 << cutoutInfo->GetWaterfallDisplayAreaRects().top.height_ << std::endl;
360 oss << std::left << std::setw(LINE_WIDTH) << "WaterFall_R<X,Y,W,H>: "
361 << cutoutInfo->GetWaterfallDisplayAreaRects().right.posX_ << ", "
362 << cutoutInfo->GetWaterfallDisplayAreaRects().right.posY_ << ", "
363 << cutoutInfo->GetWaterfallDisplayAreaRects().right.width_ << ", "
364 << cutoutInfo->GetWaterfallDisplayAreaRects().right.height_ << std::endl;
365 oss << std::left << std::setw(LINE_WIDTH) << "WaterFall_B<X,Y,W,H>: "
366 << cutoutInfo->GetWaterfallDisplayAreaRects().bottom.posX_ << ", "
367 << cutoutInfo->GetWaterfallDisplayAreaRects().bottom.posY_ << ", "
368 << cutoutInfo->GetWaterfallDisplayAreaRects().bottom.width_ << ", "
369 << cutoutInfo->GetWaterfallDisplayAreaRects().bottom.height_ << std::endl;
370
371 std::vector<DMRect> boundingRects = cutoutInfo->GetBoundingRects();
372 oss << std::left << std::setw(LINE_WIDTH) << "BoundingRects<X,Y,W,H>: ";
373 for (auto rect : boundingRects) {
374 oss << "[" << rect.posX_ << ", " << rect.posY_ << ", " << rect.width_ << ", " << rect.height_ << "] ";
375 }
376 oss << std::endl;
377 dumpInfo_.append(oss.str());
378 }
379
DumpScreenInfoById(ScreenId id)380 void ScreenSessionDumper::DumpScreenInfoById(ScreenId id)
381 {
382 std::ostringstream oss;
383 oss << "[SCREEN INFO]" << std::endl;
384 auto screenInfo = ScreenSessionManager::GetInstance().GetScreenInfoById(id);
385 if (screenInfo == nullptr) {
386 TLOGE(WmsLogTag::DMS, "screenInfo nullptr. screen id: %{public}" PRIu64"", id);
387 return;
388 }
389 oss << std::left << std::setw(LINE_WIDTH) << "VirtualWidth: "
390 << screenInfo->GetVirtualWidth() << std::endl;
391 oss << std::left << std::setw(LINE_WIDTH) << "VirtualHeight: "
392 << screenInfo->GetVirtualHeight() << std::endl;
393 oss << std::left << std::setw(LINE_WIDTH) << "LastParentId: "
394 << screenInfo->GetLastParentId() << std::endl;
395 oss << std::left << std::setw(LINE_WIDTH) << "ParentId: "
396 << screenInfo->GetParentId() << std::endl;
397 oss << std::left << std::setw(LINE_WIDTH) << "IsScreenGroup: "
398 << screenInfo->GetIsScreenGroup() << std::endl;
399 oss << std::left << std::setw(LINE_WIDTH) << "VirtualPixelRatio: "
400 << screenInfo->GetVirtualPixelRatio() << std::endl;
401 oss << std::left << std::setw(LINE_WIDTH) << "Rotation: "
402 << static_cast<int32_t>(screenInfo->GetRotation()) << std::endl;
403 oss << std::left << std::setw(LINE_WIDTH) << "Orientation: "
404 << static_cast<int32_t>(screenInfo->GetOrientation()) << std::endl;
405 oss << std::left << std::setw(LINE_WIDTH) << "SourceMode: "
406 << static_cast<int32_t>(screenInfo->GetSourceMode()) << std::endl;
407 oss << std::left << std::setw(LINE_WIDTH) << "ScreenType: "
408 << static_cast<int32_t>(screenInfo->GetType()) << std::endl;
409 dumpInfo_.append(oss.str());
410 }
411
DumpScreenPropertyById(ScreenId id)412 void ScreenSessionDumper::DumpScreenPropertyById(ScreenId id)
413 {
414 std::ostringstream oss;
415 oss << "[SCREEN PROPERTY]" << std::endl;
416 ScreenProperty screenProperty = ScreenSessionManager::GetInstance().GetScreenProperty(id);
417
418 oss << std::left << std::setw(LINE_WIDTH) << "Rotation: " << screenProperty.GetRotation() << std::endl;
419 oss << std::left << std::setw(LINE_WIDTH) << "Density: " << screenProperty.GetDensity() << std::endl;
420 oss << std::left << std::setw(LINE_WIDTH) << "DensityInCurResolution: "
421 << screenProperty.GetDensityInCurResolution() << std::endl;
422 oss << std::left << std::setw(LINE_WIDTH) << "PhyWidth: " << screenProperty.GetPhyWidth() << std::endl;
423 oss << std::left << std::setw(LINE_WIDTH) << "PhyHeight: " << screenProperty.GetPhyHeight() << std::endl;
424 oss << std::left << std::setw(LINE_WIDTH) << "RefreshRate: " << screenProperty.GetRefreshRate() << std::endl;
425 oss << std::left << std::setw(LINE_WIDTH) << "VirtualPixelRatio: "
426 << screenProperty.GetVirtualPixelRatio() << std::endl;
427 oss << std::left << std::setw(LINE_WIDTH) << "ScreenRotation: "
428 << static_cast<int32_t>(screenProperty.GetRotation()) << std::endl;
429 oss << std::left << std::setw(LINE_WIDTH) << "Orientation: "
430 << static_cast<int32_t>(screenProperty.GetOrientation()) << std::endl;
431 oss << std::left << std::setw(LINE_WIDTH) << "DisplayOrientation: "
432 << static_cast<int32_t>(screenProperty.GetDisplayOrientation()) << std::endl;
433 oss << std::left << std::setw(LINE_WIDTH) << "GetScreenType: "
434 << static_cast<int32_t>(screenProperty.GetScreenType()) << std::endl;
435 oss << std::left << std::setw(LINE_WIDTH) << "ReqOrientation: "
436 << static_cast<int32_t>(screenProperty.GetScreenRequestedOrientation()) << std::endl;
437 oss << std::left << std::setw(LINE_WIDTH) << "DPI<X, Y>: " << screenProperty.GetXDpi()
438 << ", " << screenProperty.GetYDpi() << std::endl;
439 oss << std::left << std::setw(LINE_WIDTH) << "Offset<X, Y>: " << screenProperty.GetOffsetX()
440 << ", " << screenProperty.GetOffsetY() << std::endl;
441 oss << std::left << std::setw(LINE_WIDTH) << "Bounds<L,T,W,H>: "
442 << screenProperty.GetBounds().rect_.GetLeft() << ", "
443 << screenProperty.GetBounds().rect_.GetTop() << ", "
444 << screenProperty.GetBounds().rect_.GetWidth() << ", "
445 << screenProperty.GetBounds().rect_.GetHeight() << ", " << std::endl;
446 oss << std::left << std::setw(LINE_WIDTH) << "PhyBounds<L,T,W,H>: "
447 << screenProperty.GetPhyBounds().rect_.GetLeft() << ", "
448 << screenProperty.GetPhyBounds().rect_.GetTop() << ", "
449 << screenProperty.GetPhyBounds().rect_.GetWidth() << ", "
450 << screenProperty.GetPhyBounds().rect_.GetHeight() << ", " << std::endl;
451 oss << std::left << std::setw(LINE_WIDTH) << "AvailableArea<X,Y,W,H> "
452 << screenProperty.GetAvailableArea().posX_ << ", "
453 << screenProperty.GetAvailableArea().posY_ << ", "
454 << screenProperty.GetAvailableArea().width_ << ", "
455 << screenProperty.GetAvailableArea().height_ << ", " << std::endl;
456 oss << std::left << std::setw(LINE_WIDTH) << "DefaultDeviceRotationOffset "
457 << screenProperty.GetDefaultDeviceRotationOffset() << std::endl;
458 dumpInfo_.append(oss.str());
459 }
460
461 /*
462 * hidumper inject methods
463 */
ShowNotifyFoldStatusChangedInfo()464 void ScreenSessionDumper::ShowNotifyFoldStatusChangedInfo()
465 {
466 TLOGI(WmsLogTag::DMS, "params_: [%{public}s]", params_[0].c_str());
467 int errCode = ScreenSessionManager::GetInstance().NotifyFoldStatusChanged(params_[0]);
468 if (errCode != 0) {
469 ShowIllegalArgsInfo();
470 } else {
471 std::ostringstream oss;
472 oss << "currentFoldStatus is: "
473 << static_cast<uint32_t>(ScreenSessionManager::GetInstance().GetFoldStatus())
474 << std::endl;
475 dumpInfo_.append(oss.str());
476 }
477 }
478
ShowIllegalArgsInfo()479 void ScreenSessionDumper::ShowIllegalArgsInfo()
480 {
481 dumpInfo_.append("The arguments are illegal and you can enter '-h' for help.");
482 }
483
IsValidDisplayModeCommand(std::string command)484 bool ScreenSessionDumper::IsValidDisplayModeCommand(std::string command)
485 {
486 if (std::find(displayModeCommands.begin(), displayModeCommands.end(), command) != displayModeCommands.end()) {
487 return true;
488 }
489 return false;
490 }
491
SetFoldDisplayMode()492 int ScreenSessionDumper::SetFoldDisplayMode()
493 {
494 std::string modeParam = params_[0];
495 if (modeParam.empty()) {
496 return -1;
497 }
498 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
499 if (modeParam == ARG_FOLD_DISPLAY_FULL) {
500 displayMode = FoldDisplayMode::FULL;
501 } else if (modeParam == ARG_FOLD_DISPLAY_MAIN) {
502 displayMode = FoldDisplayMode::MAIN;
503 } else if (modeParam == ARG_FOLD_DISPLAY_SUB) {
504 displayMode = FoldDisplayMode::SUB;
505 } else if (modeParam == ARG_FOLD_DISPLAY_COOR) {
506 displayMode = FoldDisplayMode::COORDINATION;
507 } else {
508 TLOGW(WmsLogTag::DMS, "SetFoldDisplayMode mode not support");
509 return -1;
510 }
511 ScreenSessionManager::GetInstance().SetFoldDisplayMode(displayMode);
512 return 0;
513 }
514
SetFoldStatusLocked()515 int ScreenSessionDumper::SetFoldStatusLocked()
516 {
517 std::string lockParam = params_[0];
518 if (lockParam.empty()) {
519 return -1;
520 }
521 bool lockDisplayStatus = false;
522 if (lockParam == ARG_LOCK_FOLD_DISPLAY_STATUS) {
523 lockDisplayStatus = true;
524 } else if (lockParam == ARG_UNLOCK_FOLD_DISPLAY_STATUS) {
525 lockDisplayStatus = false;
526 } else {
527 TLOGW(WmsLogTag::DMS, "SetFoldStatusLocked status not support");
528 return -1;
529 }
530 ScreenSessionManager::GetInstance().SetFoldStatusLocked(lockDisplayStatus);
531 return 0;
532 }
533 } // Rosen
534 } // OHOS