• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "screen_rotation_property.h"
17 
18 #include <chrono>
19 #include <securec.h>
20 
21 #include "screen_session_manager.h"
22 #include "parameters.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenRotationProperty"};
28 }
29 
30 DisplayId ScreenRotationProperty::defaultDisplayId_ = 0;
31 Rotation ScreenRotationProperty::currentDisplayRotation_;
32 bool ScreenRotationProperty::isScreenRotationLocked_ = true;
33 uint32_t ScreenRotationProperty::defaultDeviceRotationOffset_ = 0;
34 Orientation ScreenRotationProperty::lastOrientationType_ = Orientation::UNSPECIFIED;
35 Rotation ScreenRotationProperty::lastSensorDecidedRotation_;
36 Rotation ScreenRotationProperty::rotationLockedRotation_;
37 uint32_t ScreenRotationProperty::defaultDeviceRotation_ = 0;
38 std::map<SensorRotation, DeviceRotation> ScreenRotationProperty::sensorToDeviceRotationMap_;
39 std::map<DeviceRotation, float> ScreenRotationProperty::deviceToFloatMap_;
40 std::map<DeviceRotation, Rotation> ScreenRotationProperty::deviceToDisplayRotationMap_;
41 std::map<Rotation, DisplayOrientation> ScreenRotationProperty::displayToDisplayOrientationMap_;
42 DeviceRotation ScreenRotationProperty::lastSensorRotationConverted_ = DeviceRotation::INVALID;
43 
Init()44 void ScreenRotationProperty::Init()
45 {
46     ProcessRotationMapping();
47     currentDisplayRotation_ = GetCurrentDisplayRotation();
48     defaultDisplayId_ = GetDefaultDisplayId();
49     lastSensorDecidedRotation_ = currentDisplayRotation_;
50     rotationLockedRotation_ = currentDisplayRotation_;
51 }
52 
GetDefaultDisplayId()53 DisplayId ScreenRotationProperty::GetDefaultDisplayId()
54 {
55     sptr<DisplayInfo> defaultDisplayInfo = ScreenSessionManager::GetInstance().GetDefaultDisplayInfo();
56     if (defaultDisplayInfo == nullptr) {
57         WLOGFW("GetDefaultDisplayId, defaultDisplayInfo is nullptr.");
58         return DISPLAY_ID_INVALID;
59     }
60     return defaultDisplayInfo->GetDisplayId();
61 }
62 
IsScreenRotationLocked()63 bool ScreenRotationProperty::IsScreenRotationLocked()
64 {
65     return isScreenRotationLocked_;
66 }
67 
SetScreenRotationLocked(bool isLocked)68 DMError ScreenRotationProperty::SetScreenRotationLocked(bool isLocked)
69 {
70     isScreenRotationLocked_ = isLocked;
71     if (isLocked) {
72         rotationLockedRotation_ = GetCurrentDisplayRotation();
73         return DMError::DM_OK;
74     }
75     if (GetCurrentDisplayRotation() == ConvertDeviceToDisplayRotation(lastSensorRotationConverted_)) {
76         return DMError::DM_OK;
77     }
78     Orientation currentOrientation = GetPreferredOrientation();
79     if (IsSensorRelatedOrientation(currentOrientation)) {
80         ProcessSwitchToSensorRelatedOrientation(currentOrientation, lastSensorRotationConverted_);
81     }
82     return DMError::DM_OK;
83 }
84 
SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset)85 void ScreenRotationProperty::SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset)
86 {
87     // Available options for defaultDeviceRotationOffset: {0, 90, 180, 270}
88     if (defaultDeviceRotationOffset < 0 || defaultDeviceRotationOffset > 270 || defaultDeviceRotationOffset % 90 != 0) {
89         return;
90     }
91     defaultDeviceRotationOffset_ = defaultDeviceRotationOffset;
92 }
93 
HandleSensorEventInput(DeviceRotation deviceRotation)94 void ScreenRotationProperty::HandleSensorEventInput(DeviceRotation deviceRotation)
95 {
96     WLOGFI("ScreenRotationProperty::HandleSensorEventInput deviceRotation: %{public}d", deviceRotation);
97     auto isPhone = system::GetParameter("const.product.devicetype", "unknown") == "phone";
98     auto isPad = system::GetParameter("const.product.devicetype", "unknown") == "tablet";
99     if (!isPhone && !isPad) {
100         WLOGFW("device is not phone or pad, return.");
101         return;
102     }
103     if (deviceRotation != DeviceRotation::INVALID && lastSensorRotationConverted_ != deviceRotation) {
104         lastSensorRotationConverted_ = deviceRotation;
105     }
106     auto screenSession = ScreenSessionManager::GetInstance().GetDefaultScreenSession();
107     if (!screenSession) {
108         WLOGFW("screenSession is null.");
109         return;
110     }
111     screenSession->HandleSensorRotation(ConvertDeviceToFloat(deviceRotation));
112 }
113 
GetCurrentDisplayRotation()114 Rotation ScreenRotationProperty::GetCurrentDisplayRotation()
115 {
116     sptr<DisplayInfo> defaultDisplayInfo = ScreenSessionManager::GetInstance().GetDefaultDisplayInfo();
117     if (defaultDisplayInfo == nullptr) {
118         WLOGFW("Cannot get default display info");
119         return defaultDeviceRotation_ == 0 ? ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT) :
120             ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE);
121     }
122     return defaultDisplayInfo->GetRotation();
123 }
124 
GetPreferredOrientation()125 Orientation ScreenRotationProperty::GetPreferredOrientation()
126 {
127     return Orientation::SENSOR;
128 }
129 
CalcTargetDisplayRotation(Orientation requestedOrientation,DeviceRotation sensorRotationConverted)130 Rotation ScreenRotationProperty::CalcTargetDisplayRotation(
131     Orientation requestedOrientation, DeviceRotation sensorRotationConverted)
132 {
133     switch (requestedOrientation) {
134         case Orientation::SENSOR: {
135             lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted);
136             return lastSensorDecidedRotation_;
137         }
138         case Orientation::SENSOR_VERTICAL: {
139             return ProcessAutoRotationPortraitOrientation(sensorRotationConverted);
140         }
141         case Orientation::SENSOR_HORIZONTAL: {
142             return ProcessAutoRotationLandscapeOrientation(sensorRotationConverted);
143         }
144         case Orientation::AUTO_ROTATION_RESTRICTED: {
145             if (isScreenRotationLocked_) {
146                 return currentDisplayRotation_;
147             }
148             lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted);
149             return lastSensorDecidedRotation_;
150         }
151         case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: {
152             if (isScreenRotationLocked_) {
153                 return currentDisplayRotation_;
154             }
155             return ProcessAutoRotationPortraitOrientation(sensorRotationConverted);
156         }
157         case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: {
158             if (isScreenRotationLocked_) {
159                 return currentDisplayRotation_;
160             }
161             return ProcessAutoRotationLandscapeOrientation(sensorRotationConverted);
162         }
163         default: {
164             return currentDisplayRotation_;
165         }
166     }
167 }
168 
ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConverted)169 Rotation ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConverted)
170 {
171     if (IsDeviceRotationHorizontal(sensorRotationConverted)) {
172         return currentDisplayRotation_;
173     }
174     lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted);
175     return lastSensorDecidedRotation_;
176 }
177 
ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConverted)178 Rotation ScreenRotationProperty::ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConverted)
179 {
180     if (IsDeviceRotationVertical(sensorRotationConverted)) {
181         return currentDisplayRotation_;
182     }
183     lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted);
184     return lastSensorDecidedRotation_;
185 }
186 
SetScreenRotation(Rotation targetRotation)187 void ScreenRotationProperty::SetScreenRotation(Rotation targetRotation)
188 {
189     if (targetRotation == GetCurrentDisplayRotation()) {
190         return;
191     }
192     ScreenSessionManager::GetInstance().SetRotationFromWindow(targetRotation);
193     WLOGFI("dms: Set screen rotation: %{public}u", targetRotation);
194 }
195 
CalcDeviceRotation(SensorRotation sensorRotation)196 DeviceRotation ScreenRotationProperty::CalcDeviceRotation(SensorRotation sensorRotation)
197 {
198     if (sensorRotation == SensorRotation::INVALID) {
199         return DeviceRotation::INVALID;
200     }
201     // offset(in degree) divided by 90 to get rotation bias
202     int32_t bias = static_cast<int32_t>(defaultDeviceRotationOffset_ / 90);
203     int32_t deviceRotationValue = static_cast<int32_t>(sensorRotation) - bias;
204     while (deviceRotationValue < 0) {
205         // +4 is used to normalize the values into the range 0~3, corresponding to the four rotations.
206         deviceRotationValue += 4;
207     }
208     if (defaultDeviceRotation_ == 1) {
209         deviceRotationValue += static_cast<int32_t>(defaultDeviceRotation_);
210         // %2 to determine whether the rotation is horizontal or vertical.
211         if (deviceRotationValue % 2 == 0) {
212             // if device's default rotation is landscape, use -2 to swap 0 and 90, 180 and 270.
213             deviceRotationValue -= 2;
214         }
215     }
216     return static_cast<DeviceRotation>(deviceRotationValue);
217 }
218 
IsSensorRelatedOrientation(Orientation orientation)219 bool ScreenRotationProperty::IsSensorRelatedOrientation(Orientation orientation)
220 {
221     if ((orientation >= Orientation::UNSPECIFIED && orientation <= Orientation::REVERSE_HORIZONTAL) ||
222         orientation == Orientation::LOCKED) {
223         return false;
224     }
225     return true;
226 }
227 
ProcessSwitchToSensorRelatedOrientation(Orientation orientation,DeviceRotation sensorRotationConverted)228 void ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(
229     Orientation orientation, DeviceRotation sensorRotationConverted)
230 {
231     lastOrientationType_ = orientation;
232     switch (orientation) {
233         case Orientation::AUTO_ROTATION_RESTRICTED: {
234             if (isScreenRotationLocked_) {
235                 SetScreenRotation(rotationLockedRotation_);
236                 return;
237             }
238             [[fallthrough]];
239         }
240         case Orientation::SENSOR: {
241             ProcessSwitchToAutoRotation(sensorRotationConverted);
242             return;
243         }
244         case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: {
245             if (isScreenRotationLocked_) {
246                 ProcessSwitchToAutoRotationPortraitRestricted();
247                 return;
248             }
249             [[fallthrough]];
250         }
251         case Orientation::SENSOR_VERTICAL: {
252             ProcessSwitchToAutoRotationPortrait(sensorRotationConverted);
253             return;
254         }
255         case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: {
256             if (isScreenRotationLocked_) {
257                 ProcessSwitchToAutoRotationLandscapeRestricted();
258                 return;
259             }
260             [[fallthrough]];
261         }
262         case Orientation::SENSOR_HORIZONTAL: {
263             ProcessSwitchToAutoRotationLandscape(sensorRotationConverted);
264             return;
265         }
266         default: {
267             return;
268         }
269     }
270 }
271 
ProcessSwitchToAutoRotation(DeviceRotation rotation)272 void ScreenRotationProperty::ProcessSwitchToAutoRotation(DeviceRotation rotation)
273 {
274     if (rotation != DeviceRotation::INVALID) {
275         SetScreenRotation(ConvertDeviceToDisplayRotation(rotation));
276     }
277 }
278 
ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation)279 void ScreenRotationProperty::ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation)
280 {
281     if (IsDeviceRotationVertical(rotation)) {
282         SetScreenRotation(ConvertDeviceToDisplayRotation(rotation));
283         return;
284     }
285     SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT));
286 }
287 
ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation)288 void ScreenRotationProperty::ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation)
289 {
290     if (IsDeviceRotationHorizontal(rotation)) {
291         SetScreenRotation(ConvertDeviceToDisplayRotation(rotation));
292         return;
293     }
294     SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE));
295 }
296 
ProcessSwitchToAutoRotationPortraitRestricted()297 void ScreenRotationProperty::ProcessSwitchToAutoRotationPortraitRestricted()
298 {
299     if (IsCurrentDisplayVertical()) {
300         return;
301     }
302     if (IsDisplayRotationVertical(rotationLockedRotation_)) {
303         SetScreenRotation(rotationLockedRotation_);
304         return;
305     }
306     SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT));
307 }
308 
ProcessSwitchToAutoRotationLandscapeRestricted()309 void ScreenRotationProperty::ProcessSwitchToAutoRotationLandscapeRestricted()
310 {
311     if (IsCurrentDisplayHorizontal()) {
312         return;
313     }
314     if (IsDisplayRotationHorizontal(rotationLockedRotation_)) {
315         SetScreenRotation(rotationLockedRotation_);
316         return;
317     }
318     SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE));
319 }
320 
ConvertSensorToDeviceRotation(SensorRotation sensorRotation)321 DeviceRotation ScreenRotationProperty::ConvertSensorToDeviceRotation(SensorRotation sensorRotation)
322 {
323     if (sensorToDeviceRotationMap_.empty()) {
324         ProcessRotationMapping();
325     }
326     return sensorToDeviceRotationMap_.at(sensorRotation);
327 }
328 
ConvertRotationToDisplayOrientation(Rotation rotation)329 DisplayOrientation ScreenRotationProperty::ConvertRotationToDisplayOrientation(Rotation rotation)
330 {
331     if (displayToDisplayOrientationMap_.empty()) {
332         ProcessRotationMapping();
333     }
334     return displayToDisplayOrientationMap_.at(rotation);
335 }
336 
ConvertDeviceToDisplayRotation(DeviceRotation deviceRotation)337 Rotation ScreenRotationProperty::ConvertDeviceToDisplayRotation(DeviceRotation deviceRotation)
338 {
339     if (deviceRotation == DeviceRotation::INVALID) {
340         return GetCurrentDisplayRotation();
341     }
342     if (deviceToDisplayRotationMap_.empty()) {
343         ProcessRotationMapping();
344     }
345     return deviceToDisplayRotationMap_.at(deviceRotation);
346 }
347 
ConvertDeviceToFloat(DeviceRotation deviceRotation)348 float ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation deviceRotation)
349 {
350     if (deviceToFloatMap_.empty()) {
351         ProcessRotationMapping();
352     }
353     return deviceToFloatMap_.at(deviceRotation);
354 }
355 
UpdateDefaultDeviceRotation()356 void ScreenRotationProperty::UpdateDefaultDeviceRotation()
357 {
358     sptr<SupportedScreenModes> modes =
359         ScreenSessionManager::GetInstance().GetScreenModesByDisplayId(defaultDisplayId_);
360 
361     // 0 means PORTRAIT, 1 means LANDSCAPE.
362     if (modes == nullptr) {
363         defaultDeviceRotation_ = 0;
364         WLOGFE("Get screen modes is nullptr.");
365     } else {
366         defaultDeviceRotation_ = (modes->width_ < modes->height_) ? 0 : 1;
367         WLOGFI("Get screen modes width: %{public}d, height: %{public}d", modes->width_, modes->height_);
368     }
369     if (OHOS::system::GetParameter("const.product.devicetype", "unknown") == "phone") {
370         WLOGFI("Current device type is phone, set defaultDeviceRotation is portrait");
371         defaultDeviceRotation_ = 0;
372     }
373     WLOGFI("defaultDeviceRotation: %{public}u, defaultDisplayId: %{public}u",
374         defaultDeviceRotation_, static_cast<uint32_t>(defaultDisplayId_));
375 }
376 
ProcessRotationMapping()377 void ScreenRotationProperty::ProcessRotationMapping()
378 {
379     UpdateDefaultDeviceRotation();
380     if (deviceToDisplayRotationMap_.empty()) {
381         deviceToDisplayRotationMap_ = {
382             {DeviceRotation::ROTATION_PORTRAIT,
383                 defaultDeviceRotation_ == 0 ? Rotation::ROTATION_0 : Rotation::ROTATION_90},
384             {DeviceRotation::ROTATION_LANDSCAPE,
385                 defaultDeviceRotation_ == 1 ? Rotation::ROTATION_0 : Rotation::ROTATION_90},
386             {DeviceRotation::ROTATION_PORTRAIT_INVERTED,
387                 defaultDeviceRotation_ == 0 ? Rotation::ROTATION_180 : Rotation::ROTATION_270},
388             {DeviceRotation::ROTATION_LANDSCAPE_INVERTED,
389                 defaultDeviceRotation_ == 1 ? Rotation::ROTATION_180 : Rotation::ROTATION_270},
390         };
391     }
392     if (deviceToFloatMap_.empty()) {
393         deviceToFloatMap_ = {
394             {DeviceRotation::ROTATION_PORTRAIT, defaultDeviceRotation_ == 0 ? 0.0f : 90.0f}, // degree 0 or 90
395             {DeviceRotation::ROTATION_LANDSCAPE, defaultDeviceRotation_ == 1 ? 0.0f : 90.0f}, // degree 0 or 90
396             {DeviceRotation::ROTATION_PORTRAIT_INVERTED,
397                 defaultDeviceRotation_ == 0 ? 180.0f : 270.0f}, // degree 180 or 270
398             {DeviceRotation::ROTATION_LANDSCAPE_INVERTED,
399                 defaultDeviceRotation_ == 1 ? 180.0f : 270.0f}, // degree 180 or 270
400             {DeviceRotation::INVALID, -1.0f}, // keep degree
401         };
402     }
403     if (displayToDisplayOrientationMap_.empty()) {
404         displayToDisplayOrientationMap_ = {
405             {defaultDeviceRotation_ == 0 ? Rotation::ROTATION_0 : Rotation::ROTATION_90,
406                 DisplayOrientation::PORTRAIT},
407             {defaultDeviceRotation_ == 1 ? Rotation::ROTATION_0 : Rotation::ROTATION_90,
408                 DisplayOrientation::LANDSCAPE},
409             {defaultDeviceRotation_ == 0 ? Rotation::ROTATION_180 : Rotation::ROTATION_270,
410                 DisplayOrientation::PORTRAIT_INVERTED},
411             {defaultDeviceRotation_ == 1 ? Rotation::ROTATION_180 : Rotation::ROTATION_270,
412                 DisplayOrientation::LANDSCAPE_INVERTED},
413         };
414     }
415     if (sensorToDeviceRotationMap_.empty()) {
416         sensorToDeviceRotationMap_ = {
417             {SensorRotation::ROTATION_0, CalcDeviceRotation(SensorRotation::ROTATION_0)},
418             {SensorRotation::ROTATION_90, CalcDeviceRotation(SensorRotation::ROTATION_90)},
419             {SensorRotation::ROTATION_180, CalcDeviceRotation(SensorRotation::ROTATION_180)},
420             {SensorRotation::ROTATION_270, CalcDeviceRotation(SensorRotation::ROTATION_270)},
421             {SensorRotation::INVALID, DeviceRotation::INVALID},
422         };
423     }
424 }
425 
IsDeviceRotationVertical(DeviceRotation deviceRotation)426 bool ScreenRotationProperty::IsDeviceRotationVertical(DeviceRotation deviceRotation)
427 {
428     return (deviceRotation == DeviceRotation::ROTATION_PORTRAIT) ||
429         (deviceRotation == DeviceRotation::ROTATION_PORTRAIT_INVERTED);
430 }
431 
IsDeviceRotationHorizontal(DeviceRotation deviceRotation)432 bool ScreenRotationProperty::IsDeviceRotationHorizontal(DeviceRotation deviceRotation)
433 {
434     return (deviceRotation == DeviceRotation::ROTATION_LANDSCAPE) ||
435         (deviceRotation == DeviceRotation::ROTATION_LANDSCAPE_INVERTED);
436 }
437 
IsCurrentDisplayVertical()438 bool ScreenRotationProperty::IsCurrentDisplayVertical()
439 {
440     return IsDisplayRotationVertical(GetCurrentDisplayRotation());
441 }
442 
IsCurrentDisplayHorizontal()443 bool ScreenRotationProperty::IsCurrentDisplayHorizontal()
444 {
445     return IsDisplayRotationHorizontal(GetCurrentDisplayRotation());
446 }
447 
IsDefaultDisplayRotationPortrait()448 bool ScreenRotationProperty::IsDefaultDisplayRotationPortrait()
449 {
450     return Rotation::ROTATION_0 == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT);
451 }
452 
IsDisplayRotationVertical(Rotation rotation)453 bool ScreenRotationProperty::IsDisplayRotationVertical(Rotation rotation)
454 {
455     return (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)) ||
456         (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED));
457 }
458 
IsDisplayRotationHorizontal(Rotation rotation)459 bool ScreenRotationProperty::IsDisplayRotationHorizontal(Rotation rotation)
460 {
461     return (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)) ||
462         (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED));
463 }
464 
ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation)465 void ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation)
466 {
467     if (lastOrientationType_ == orientation) {
468         return;
469     }
470     lastOrientationType_ = orientation;
471     switch (orientation) {
472         case Orientation::UNSPECIFIED: {
473             SetScreenRotation(Rotation::ROTATION_0);
474             break;
475         }
476         case Orientation::VERTICAL: {
477             SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT));
478             break;
479         }
480         case Orientation::REVERSE_VERTICAL: {
481             SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED));
482             break;
483         }
484         case Orientation::HORIZONTAL: {
485             SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE));
486             break;
487         }
488         case Orientation::REVERSE_HORIZONTAL: {
489             SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED));
490             break;
491         }
492         default: {
493             return;
494         }
495     }
496 }
497 
ProcessOrientationSwitch(Orientation orientation)498 void ScreenRotationProperty::ProcessOrientationSwitch(Orientation orientation)
499 {
500     if (!IsSensorRelatedOrientation(orientation)) {
501         ProcessSwitchToSensorUnrelatedOrientation(orientation);
502     } else {
503         ProcessSwitchToSensorRelatedOrientation(orientation, lastSensorRotationConverted_);
504     }
505 }
506 } // Rosen
507 } // OHOS