当前位置: 首页 > news >正文

Android12 添加屏幕方向旋转方案

添加屏幕方向属性值

  • device/qcom/qssi/system.prop
persist.panel.orientation=0

修改开机动画方向

  • frameworks/base/cmds/bootanimation/BootAnimation.cpp
status_t BootAnimation::readyToRun() {mAssets.addDefaultAssets();mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();if (mDisplayToken == nullptr)return NAME_NOT_FOUND;DisplayMode displayMode;const status_t error =SurfaceComposerClient::getActiveDisplayMode(mDisplayToken, &displayMode);if (error != NO_ERROR)return error;mMaxWidth = android::base::GetIntProperty("ro.surface_flinger.max_graphics_width", 0);mMaxHeight = android::base::GetIntProperty("ro.surface_flinger.max_graphics_height", 0);ui::Size resolution = displayMode.resolution;resolution = limitSurfaceSize(resolution.width, resolution.height);// add startchar rAngleValue[PROPERTY_VALUE_MAX];property_get("persist.panel.orientation", rAngleValue, "0");int rAngle = atoi(rAngleValue);SurfaceComposerClient::Transaction t;int d_width = resolution.getWidth(),d_height = resolution.getHeight();if (rAngle == 90) {d_width = resolution.getHeight();d_height = resolution.getWidth();Rect destRect(d_width, d_height);t.setDisplayProjection(mDisplayToken, ui::ROTATION_90, destRect, destRect);ALOGD("BootAnimation default set rotation to be 90...");} else if (rAngle == 180) {Rect destRect(d_width, d_height);t.setDisplayProjection(mDisplayToken, ui::ROTATION_180, destRect, destRect);ALOGD("BootAnimation default set rotation to be 180...");} else if (rAngle == 270) {d_width = resolution.getHeight();d_height = resolution.getWidth();Rect destRect(d_width, d_height);t.setDisplayProjection(mDisplayToken, ui::ROTATION_270, destRect, destRect);ALOGD("BootAnimation default set rotation to be 270...");}// create the native surfacesp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),d_width/*resolution.getWidth()*/, d_height/*resolution.getHeight()*/, PIXEL_FORMAT_RGB_565);//SurfaceComposerClient::Transaction t;// add end

修改导航栏位置

  • frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java
@NavigationBarPosition
int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) {// add start/*if (navigationBarCanMove() && displayWidth > displayHeight) {if (displayRotation == Surface.ROTATION_270) {return NAV_BAR_LEFT;} else if (displayRotation == Surface.ROTATION_90) {return NAV_BAR_RIGHT;}}*/// add endreturn NAV_BAR_BOTTOM;
}

应用界面横竖屏修改

  • frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
private int mDefaultOrientation = Surface.ROTATION_0;
DisplayRotation(WindowManagerService service, DisplayContent displayContent,DisplayPolicy displayPolicy, DisplayWindowSettings displayWindowSettings,Context context, Object lock) {...if (isDefaultDisplay) {...t.start();// add startString orientation = SystemProperties.get("persist.panel.orientation");if (orientation.startsWith("0")){mDefaultOrientation = Surface.ROTATION_0;} else if(orientation.startsWith("90")){mDefaultOrientation = Surface.ROTATION_90;} else if(orientation.startsWith("180")){mDefaultOrientation = Surface.ROTATION_180;} else if(orientation.startsWith("270")){mDefaultOrientation = Surface.ROTATION_270;}mRotation = mDefaultOrientation;// add end}
}
...
boolean updateRotationUnchecked(boolean forceUpdate) {...final int oldRotation = mRotation;final int lastOrientation = mLastOrientation;// add startfinal int rotation = mDefaultOrientation/*rotationForOrientation(lastOrientation, oldRotation)*/;// add end...
}
...
@VisibleForTesting
@Surface.Rotation
int rotationForOrientation(@ScreenOrientation int orientation,@Surface.Rotation int lastRotation) {ProtoLog.v(WM_DEBUG_ORIENTATION,"rotationForOrientation(orient=%s (%d), last=%s (%d)); user=%s (%d) %s",ActivityInfo.screenOrientationToString(orientation), orientation,Surface.rotationToString(lastRotation), lastRotation,Surface.rotationToString(mUserRotation), mUserRotation,mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED? "USER_ROTATION_LOCKED" : "");if (isFixedToUserRotation()) {return mUserRotation;}...default:// For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,// just return the preferred orientation we already calculated.if (preferredRotation >= 0) {return preferredRotation;}// add start//return Surface.ROTATION_0;return mDefaultOrientation;// add end}
}
  • frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
@ScreenOrientation
@Override
int getOrientation() {// add startint mDefaultOrientation = 0;String persistOrientation = SystemProperties.get("persist.panel.orientation");if (!persistOrientation.isEmpty()){if (persistOrientation.startsWith("0")){mDefaultOrientation = Surface.ROTATION_0;} else if(persistOrientation.startsWith("90")){mDefaultOrientation = Surface.ROTATION_90;} else if(persistOrientation.startsWith("180")){mDefaultOrientation = Surface.ROTATION_180;} else if(persistOrientation.startsWith("270")){mDefaultOrientation = Surface.ROTATION_270;}return mDefaultOrientation;}// add endmLastOrientationSource = null;
http://www.lryc.cn/news/409283.html

相关文章:

  • Harmony-(1)-TypeScript-ArkTs
  • TC8:SOMEIP_ETS_007-008
  • [网络编程】网络编程的基础使用
  • Postman中的Cookie和会话管理:掌握API测试的关键环节
  • python脚本,识别pdf数据,转换成表格形式
  • Linux环境安装KubeSphere容器云平台并实现远程访问Web UI 界面
  • jumpserver web资源--远程应用发布机
  • Linux环境docker部署Firefox结合内网穿透远程使用浏览器测试
  • 人工智能与机器学习原理精解【8】
  • 关于Protobuf 输入输出中文到文件中的一系列问题
  • 后端笔记(1)--javaweb简介
  • 便携式气象监测系统的优势:精准高效,随行监测
  • uniapp App判断是否安装某个app
  • C/C++大雪纷飞代码
  • 【linux】【设备树】具有 GPIO 控制器和连接器的硬件配置的备树(Device Tree)代码讲解
  • 【2025留学】德国留学真的很难毕业吗?为什么大家不来德国留学?
  • Apache Solr 最常用的命令
  • 经济下行,企业还在“裁员至上”?
  • 学习笔记之Java篇(0729)
  • 吃肉的刷题记录4-基础知识-字符串
  • 人工智能与机器学习原理精解【7】
  • ResNet学习笔记
  • 使用chainlit快速构建类似OPEN AI一样的对话网页
  • 【根据字符出现频率排序】python刷题记录
  • 活动报名小程序
  • unity基础问题
  • RedHat Enterprise Linux 7 YUM源(本地/网络源)配置详解
  • 关于顺序表数组下标的一些关系梳理
  • VS C++ Project(项目)的工作目录设置
  • STM32自定义协议串口接收解析指令程序