设备开机默认是竖屏的,如果设备有重力感应器,则根据自动旋转和重力感应器,来设置屏幕方向,如果我们需要设备开机就是横屏,或者用户自定义横屏或竖屏切换。需要修改主要包括四大块:
首先增加自定义属性persist.sys.panel.orientation=1,可选值为0,1,2,3 其中0,2是竖屏,1.3是横屏
- 开机动画
//frameworks/base/cmds/bootanimation/BootAnimation.cpp status_t BootAnimation::readyToRun() { resolution = limitSurfaceSize(resolution.width, resolution.height); //phoebe add start char rAngleValue[PROPERTY_VALUE_MAX]; property_get("persist.sys.panel.orientation", rAngleValue, "1"); int rAngle = atoi(rAngleValue); SurfaceComposerClient::Transaction t; int temp = resolution.height; ui::Rotation rota; switch(rAngle){ case 0: rota=ui::ROTATION_0; break; case 1: resolution.height= resolution.width; resolution.width= temp; rota=ui::ROTATION_90; break; case 2: rota=ui::ROTATION_180; break; case 3: resolution.height= resolution.width; resolution.width= temp; rota=ui::ROTATION_270; break; default: rota=ui::ROTATION_90; break; } Rect destRect(resolution.width, resolution.height); ALOGD("BootAnimation default set rotation to be %d...",rAngle); t.setDisplayProjection(mDisplayToken, rota, destRect, destRect); //phoebe add end // create the native surface sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), resolution.getWidth(), resolution.getHeight(), PIXEL_FORMAT_RGB_565); // SurfaceComposerClient::Transaction t; // this guest property specifies multi-display IDs to show the boot animation // multiple ids can be set with comma (,) as separator, for example: // setprop persist.boot.animation.displays 19260422155234049,19261083906282754 Vector<uint64_t> physicalDisplayIds; ... }
- Ui修改
// frameworks/base/core/res/res/values/config.xml 关闭自动旋转 <bool name="config_supportAutoRotation">false</bool> //默认为横屏 <integer name="config_lidOpenRotation">90</integer> //frameworks/base/core/java/android/view/DisplayInfo.java //初始值为设置的属性 public int rotation= SystemProperties.getInt("persist.sys.panel.orien