• 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 #include "screen_session_manager.h"
18 #include "fold_screen_state_internel.h"
19 
20 namespace OHOS {
21 namespace Rosen {
HandleSensorEventInput(DeviceRotation deviceRotation)22 void ScreenRotationProperty::HandleSensorEventInput(DeviceRotation deviceRotation)
23 {
24     static DeviceRotation lastSensorRotationConverted_ = DeviceRotation::INVALID;
25     if (FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice() &&
26         ScreenSessionManager::GetInstance().GetFoldStatus() == FoldStatus::FOLDED) {
27         deviceRotation = ConvertSinglePocketOuterRotation(deviceRotation);
28     }
29     TLOGI(WmsLogTag::DMS, "DeviceRotation: %{public}d, "
30         "lastSensorRotationConverted: %{public}d", deviceRotation, lastSensorRotationConverted_);
31 
32     if (deviceRotation != DeviceRotation::INVALID && lastSensorRotationConverted_ != deviceRotation) {
33         lastSensorRotationConverted_ = deviceRotation;
34     }
35     auto screenSession = ScreenSessionManager::GetInstance().GetDefaultScreenSession();
36     if (!screenSession) {
37         TLOGW(WmsLogTag::DMS, "screenSession is null, sensor rotation status handle failed");
38         return;
39     }
40     screenSession->HandleSensorRotation(ConvertDeviceToFloat(deviceRotation));
41 }
42 
ConvertSinglePocketOuterRotation(DeviceRotation deviceRotation)43 DeviceRotation ScreenRotationProperty::ConvertSinglePocketOuterRotation(DeviceRotation deviceRotation)
44 {
45     DeviceRotation sensorRotation = deviceRotation;
46     switch (deviceRotation) {
47         case DeviceRotation::ROTATION_LANDSCAPE:
48             sensorRotation = DeviceRotation::ROTATION_LANDSCAPE_INVERTED;
49             break;
50         case DeviceRotation::ROTATION_LANDSCAPE_INVERTED:
51             sensorRotation = DeviceRotation::ROTATION_LANDSCAPE;
52             break;
53         default:
54             TLOGW(WmsLogTag::DMS, "no need to covert, rotation: %{public}d", deviceRotation);
55     }
56     return sensorRotation;
57 }
58 
ConvertDeviceToFloat(DeviceRotation deviceRotation)59 float ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation deviceRotation)
60 {
61     float sensorRotation = -1.0f; // -1 mean keep before degree
62     switch (deviceRotation) {
63         case DeviceRotation::ROTATION_PORTRAIT:
64             sensorRotation = 0.0f; // degree 0
65             break;
66         case DeviceRotation::ROTATION_LANDSCAPE:
67             sensorRotation = 90.0f; // degree 90
68             break;
69         case DeviceRotation::ROTATION_PORTRAIT_INVERTED:
70             sensorRotation = 180.0f; // degree 180
71             break;
72         case DeviceRotation::ROTATION_LANDSCAPE_INVERTED:
73             sensorRotation = 270.0f; // degree 270
74             break;
75         case DeviceRotation::INVALID:
76             sensorRotation = -1.0f; // keep before degree
77             break;
78         default:
79             TLOGW(WmsLogTag::DMS, "invalid device rotation: %{public}d", deviceRotation);
80     }
81     return sensorRotation;
82 }
83 } // Rosen
84 } // OHOS