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

Android 高通7.1系开机动画自动跟随系统方向旋转

本篇博客是记录自己解决开机动画与系统方向不一致方案代码,思路:在系统参数根目录自定义persist.sys.hwrotationxrd=0来作为动画方向,当修改系统方向时同时修改这个参数,当系统启动加载动画时在根据这个来旋转动画方式以保证动画方式与系统方式一致。

实现步骤如下:

一、在rk3288\device\rockchip\rk3288\system.prop 内创建persist.sys.hwrotationxrd=0 与屏幕主屏默认方式一致

二、在rk3288\frameworks\base\cmds\bootanimation\BootAnimation.cpp 内修改动画方式

status_t BootAnimation::readyToRun() {mAssets.addDefaultAssets();
......DisplayInfo dinfo;status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);if (status)return -1;// create the native surface
//    int curWidth = dinfo.w;
//    int curHeight = dinfo.h;
//    if(mShutdown && mReverseAxis){
//        curWidth = dinfo.h;
//        curHeight = dinfo.w;
//    }//start add superchar hwrotationaa[PROPERTY_VALUE_MAX];property_get("persist.sys.hwrotationxrd",hwrotationaa,"0");ALOGE("hwrotation::%s" , hwrotationaa);int orient = atoi(hwrotationaa)/90;sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),(orient ==1 || orient==3) ?dinfo.h:dinfo.w,(orient ==1 || orient==3) ?dinfo.w:dinfo.h, PIXEL_FORMAT_RGB_565);//    sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
//                                                          dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);if(orient == 1 || orient == 3){Rect destRect(dinfo.h, dinfo.w);mSession->setDisplayProjection(dtoken,orient,destRect,destRect);}ALOGE("eliot BootAnimation::readyToRun22222222 add end\n");//end add super
......

三、在rk3288\frameworks\native\services\surfaceflinger\DisplayDevice.cpp 内初始化动画方向

 // Name the display.  The name will be replaced shortly if the display// was created with createDisplay().switch (mType) {case DISPLAY_PRIMARY:mDisplayName = "Built-in Screen";break;case DISPLAY_EXTERNAL:mDisplayName = "HDMI Screen";break;default:mDisplayName = "Virtual Screen";    // e.g. Overlay #nbreak;}//start add superint defaultOrientation = 0;char property[PROPERTY_VALUE_MAX];property_get("persist.sys.hwrotationxrd", property, "0");defaultOrientation = atoi(property);switch(defaultOrientation) {case 0:defaultOrientation = DisplayState::eOrientationDefault;break;case 90:defaultOrientation = DisplayState::eOrientation90;break;case 180:defaultOrientation = DisplayState::eOrientation180;break;case 270:defaultOrientation = DisplayState::eOrientation270;break;default:defaultOrientation = DisplayState::eOrientationDefault;break;}// initialize the display orientation transform.setProjection(defaultOrientation, mViewport, mFrame);//end add super// initialize the display orientation transform.
//    setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);#ifdef NUM_FRAMEBUFFER_SURFACE_BUFFERSsurface->allocateBuffers();
#endif
}

四、上层修改动画方向

1、rk3288\frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager 修改

.....//add start 2024-8-2private int mDefaultOrientation = Surface.ROTATION_0;@Overridepublic void setInitialDisplaySize(Display display, int width, int height, int density) {// This method might be called before the policy has been fully initialized// or for other displays we don't care about.if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {return;}
....// Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per// http://developer.android.com/guide/practices/screens_support.html#rangemForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&// For debug purposes the next line turns this feature off with:// $ adb shell setprop config.override_forced_orient true// $ adb shell wm size reset!"true".equals(SystemProperties.get("config.override_forced_orient"));//start add superString defaultOrientation = SystemProperties.get("persist.sys.hwrotationxrd", "0");if("0".equals(defaultOrientation)) {mDefaultOrientation = Surface.ROTATION_0;} else if("90".equals(defaultOrientation)) {mDefaultOrientation = Surface.ROTATION_90;} else if("180".equals(defaultOrientation)) {mDefaultOrientation = Surface.ROTATION_180;} else if("270".equals(defaultOrientation)) {mDefaultOrientation = Surface.ROTATION_270;} else {mDefaultOrientation = Surface.ROTATION_0;}//end add super}.....@Overridepublic int rotationForOrientationLw(int orientation, int lastRotation) {switch (orientation) {case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:// Return portrait unless overridden.if (isAnyPortrait(preferredRotation)) {return preferredRotation;}return mPortraitRotation;case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:// Return landscape unless overridden.if (isLandscapeOrSeascape(preferredRotation)) {return preferredRotation;}return mLandscapeRotation;case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:// Return reverse portrait unless overridden.if (isAnyPortrait(preferredRotation)) {return preferredRotation;}return mUpsideDownRotation;case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:// Return seascape unless overridden.if (isLandscapeOrSeascape(preferredRotation)) {return preferredRotation;}return mSeascapeRotation;case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:// Return either landscape rotation.if (isLandscapeOrSeascape(preferredRotation)) {return preferredRotation;}if (isLandscapeOrSeascape(lastRotation)) {return lastRotation;}return mLandscapeRotation;case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:// Return either portrait rotation.if (isAnyPortrait(preferredRotation)) {return preferredRotation;}if (isAnyPortrait(lastRotation)) {return lastRotation;}return mPortraitRotation;default:// For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,// just return the preferred orientation we already calculated.if (preferredRotation >= 0) {return preferredRotation;}//  return Surface.ROTATION_0;return mDefaultOrientation;// add modify 2024-8-2}}}

2、rk3288\frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java 修改

	private WindowManagerService(Context context, InputManagerService inputManager,boolean haveInputMethods, boolean showBootMsgs, boolean onlyCore) {......//add start 2024-8-2String defaultOrientation = SystemProperties.get("persist.sys.hwrotationxrd", "0");if("0".equals(defaultOrientation)) {mRotation = Surface.ROTATION_0;} else if("90".equals(defaultOrientation)) {mRotation = Surface.ROTATION_90;} else if("180".equals(defaultOrientation)) {mRotation = Surface.ROTATION_180;} else if("270".equals(defaultOrientation)) {mRotation = Surface.ROTATION_270;} else {mRotation = Surface.ROTATION_0;}//add end 2024-8-2}

到此修改就完成了,本文是参照Android 高通7.1系统默认横屏显示(无G-sensor)_高通 android7 横竖屏显示-CSDN博客

修改完成,感谢!

http://www.lryc.cn/news/426149.html

相关文章:

  • Sentinel入门与进阶:微服务流量控制的最佳实践 ( 三 )
  • 2021年上半年网络工程师考试上午真题
  • SQL触发器的级联魔力:数据完整性的守护者
  • ARCGIS PRO 要素标注背景色透明度的设置
  • 探讨MySQL中 “约束“ 下的查询
  • Nuxt3【布局】layouts 详解
  • 获取数据源(多种方式爬虫介绍)
  • Linux下FTP服务器搭建配置:vsftpd的安装与配置实验
  • 使用Java调用Apache commons-text求解字符串相似性实战
  • http request-01-XMLHttpRequest XHR 简单介绍
  • 关于tresos Studio(EB)的MCAL配置之DIO
  • 【漫谈C语言和嵌入式003】1394总线
  • python爬虫爬取某图书网页实例
  • Linux 用户管理的基本概念、常用工具及操作流程
  • 手撕C++入门基础
  • NPM版本控制策略:实现版本候选行为的指南
  • 问题集锦6
  • 【研发日记】嵌入式处理器技能解锁(四)——TI C2000 DSP的Memory
  • Ubuntu离线安装docker
  • 【抓耳挠腮,还是升职加薪,一起来画架构图!】
  • 算法的学习笔记—合并两个排序的链表(牛客JZ25)
  • 《虚拟之旅:开启无限可能的机器世界》简介:
  • centos7 服务器搭建
  • 【Godot4自学手册】第四十五节用着色器(shader)制作水中效果
  • VMware Workstation Pro 安装 Ubuntu Server
  • 智能化包括自动化与非自动化
  • 微前端架构的容器化部署:策略、实践与优势
  • 面试题(网络、js、框架)
  • C语言典型例题40
  • 【大模型部署及其应用 】使用 Ollama 和 Ollama WebUI 在本地运行 Llama 3