USB TP随系统一起旋转
前言:
android12 RK平台,有一个USB接口的TP需要随着系统一起旋转。
参考:
https://blog.csdn.net/SHH_1064994894/article/details/132576404
解决方法:
通过自定义一个系统属性persist.sys.usbtp.rotation 来存储TP旋转方向,修改framework 的input相关文件,补丁如下:
Index: base/services/core/java/com/android/server/wm/DisplayRotation.java
===================================================================
--- base/services/core/java/com/android/server/wm/DisplayRotation.java (revision 2519)
+++ base/services/core/java/com/android/server/wm/DisplayRotation.java (working copy)
@@ -1136,7 +1136,12 @@
if (isFixedToUserRotation()) {
return mUserRotation;
}
-
+
+ // ---add start asw
+ Slog.d(TAG,"ASW rotationForOrientation mUserRotation = " + mUserRotation);
+ SystemProperties.set("persist.sys.usbtp.rotation", ""+mUserRotation);
+ // ---add end asw
+
int sensorRotation = mOrientationListener != null
? mOrientationListener.getProposedRotation() // may be -1
: -1;
Index: native/services/inputflinger/reader/mapper/TouchInputMapper.cpp
===================================================================
--- native/services/inputflinger/reader/mapper/TouchInputMapper.cpp (revision 2519)
+++ native/services/inputflinger/reader/mapper/TouchInputMapper.cpp (working copy)
@@ -25,6 +25,7 @@
#include "CursorScrollAccumulator.h"
#include "TouchButtonAccumulator.h"
#include "TouchCursorInputMapperCommon.h"
+#include <cutils/properties.h>
namespace android {
@@ -674,6 +675,12 @@
// Raw width and height in the natural orientation.
int32_t rawWidth = mRawPointerAxes.getRawWidth();
int32_t rawHeight = mRawPointerAxes.getRawHeight();
+
+ // ---add start asw
+ char rotationvalue[PROPERTY_VALUE_MAX] = "";;
+ property_get("persist.sys.usbtp.rotation", rotationvalue, "0");
+ int rotation = atoi(rotationvalue);
+ // ---add end asw
bool viewportChanged = mViewport != *newViewport;
bool skipViewportUpdate = false;
@@ -691,9 +698,36 @@
// Apply the inverse of the input device orientation so that the surface is configured
// in the same orientation as the device. The input device orientation will be
// re-applied to mSurfaceOrientation.
- const int32_t naturalSurfaceOrientation =
- (mViewport.orientation - static_cast<int32_t>(mParameters.orientation) + 4) % 4;
- switch (naturalSurfaceOrientation) {
+
+ // const int32_t naturalSurfaceOrientation =
+ // (mViewport.orientation - static_cast<int32_t>(mParameters.orientation) + 4) % 4;
+ // switch (naturalSurfaceOrientation) {
+ // ---add start asw
+ int currentrotation = DISPLAY_ORIENTATION_0;
+ switch (rotation) {
+ case 0:
+ currentrotation = DISPLAY_ORIENTATION_0;
+ break;
+ case 90:
+ currentrotation = DISPLAY_ORIENTATION_90;
+ break;
+ case 180:
+ currentrotation = DISPLAY_ORIENTATION_180;
+ break;
+ case 270:
+ currentrotation = DISPLAY_ORIENTATION_270;
+ break;
+ default:
+ break;
+ }
+
+ if(currentrotation == DISPLAY_ORIENTATION_0 && mViewport.orientation != currentrotation){
+ rotation = mViewport.orientation;
+ currentrotation = mViewport.orientation;
+ }
+
+ switch (currentrotation) {
+ // ---add end asw
case DISPLAY_ORIENTATION_90:
naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
@@ -793,7 +827,27 @@
mSurfaceOrientation = DISPLAY_ORIENTATION_0;
}
}
-
+
+ // ---add start asw
+ ALOGI("Primary Display Orientation is set to rotation %2d.", rotation);
+ switch (rotation) {
+ case 0:
+ mSurfaceOrientation = DISPLAY_ORIENTATION_0;
+ break;
+ case 1:
+ mSurfaceOrientation = DISPLAY_ORIENTATION_90;
+ break;
+ case 2:
+ mSurfaceOrientation = DISPLAY_ORIENTATION_180;
+ break;
+ case 3:
+ mSurfaceOrientation = DISPLAY_ORIENTATION_270;
+ break;
+ default:
+ break;
+ }
+ // ---add end asw
+
// If moving between pointer modes, need to reset some state.
bool deviceModeChanged = mDeviceMode != oldDeviceMode;
if (deviceModeChanged) {
Index: native/services/surfaceflinger/SurfaceFlinger.cpp
===================================================================
--- native/services/surfaceflinger/SurfaceFlinger.cpp (revision 2519)
+++ native/services/surfaceflinger/SurfaceFlinger.cpp (working copy)
@@ -2637,7 +2637,30 @@
if (!info) {
continue;
}
-
+
+ // ---add start asw
+ char rotationvalue[PROPERTY_VALUE_MAX] = "";;
+ property_get("persist.sys.usbtp.rotation", rotationvalue, "-1");
+ int rotation = atoi(rotationvalue);
+ ALOGI("Primary Display Orientation is set to rotation %2d.", rotation);
+ switch (rotation) {
+ case 0:
+ internalDisplayOrientation = ui::ROTATION_0;
+ break;
+ case 1:
+ internalDisplayOrientation = ui::ROTATION_90;
+ break;
+ case 2:
+ internalDisplayOrientation = ui::ROTATION_180;
+ break;
+ case 3:
+ internalDisplayOrientation = ui::ROTATION_270;
+ break;
+ default:
+ break;
+ }
+ // ---add end asw
+
const auto displayId = info->id;
const auto it = mPhysicalDisplayTokens.find(displayId);
在device.mk下自定义persist.sys.usbtp.rotation属性。
修改完成之后,TP触摸屏能随着系统一起旋转了,但是TP触摸屏有一部分触摸失效。可能是这个TP固件没有适配,需要找TP原厂适配。
浙公网安备 33010602011771号