Android默认开机横屏
16lz
2021-01-26
实际开发中,有时项目需要设备默认开机横屏,这里我们默认第一帧第二帧依旧采用竖屏资源(Android7.0)。
frameworks/base/cmds/bootanimation/BootAnimation.cpp frameworks/base/core/res/res/values/config.xml frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java frameworks/native/services/surfaceflinger/DisplayDevice.cpp
修改分为三部分: 1.上层UI修改 (1) --- frameworks/base/core/res/res/values/config.xml(revision 139) +++ frameworks/base/core/res/res/values/config.xml(working copy)@@ -639,7 +639,7 @@ settings are omitted from the system UI. In certain situations we may still use the accelerometer to determine the orientation, such as when docked if the dock is configured to enable the accelerometer. --> - true + false @@ -694,7 +694,7 @@ - -1 + 90 (2) --- frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java(revision 116) +++ frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java(working copy) @@ -656,7 +656,7 @@ SparseArray mDisplayContents = new SparseArray<>(2); - int mRotation = 0; + int mRotation = Surface.ROTATION_90; int mLastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; boolean mAltOrientation = false; @@ -7109,8 +7109,8 @@ final int oldRotation = mRotation; /// M: [ALPS00502835] add for tablet IPO power-off/on issue in landscape mode - int rotation = (mIsUpdateIpoRotation || mIsUpdateAlarmBootRotation) ? Surface.ROTATION_0 : - mPolicy.rotationForOrientationLw(mLastOrientation, mRotation); + int rotation = Surface.ROTATION_90;//(mIsUpdateIpoRotation || mIsUpdateAlarmBootRotation) ? Surface.ROTATION_0 : + //mPolicy.rotationForOrientationLw(mLastOrientation, mRotation); } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { if (mHasReceiveIPO) {// mRotation = 0; mRotation = 1; //M chongqing 20180307 mPolicy.setRotationLw(mRotation); Slog.v(TAG, "Re-initialize the rotation value to " + mRotation); mHasReceiveIPO = false; } *******************上面的可以保证开机UI是横屏的 ************************** 2: 底层(C++)修改开机动画横屏问题 (3) --- frameworks/native/services/surfaceflinger/DisplayDevice.cpp(revision 116) +++ frameworks/native/services/surfaceflinger/DisplayDevice.cpp(working copy) @@ -211,7 +211,7 @@ } // initialize the display orientation transform. - setProjection(DisplayState::eOrientationDefault, mViewport, mFrame); + setProjection(DisplayState::eOrientation90, mViewport, mFrame); (4) --- frameworks/base/cmds/bootanimation/BootAnimation.cpp(revision 116) +++ frameworks/base/cmds/bootanimation/BootAnimation.cpp(working copy) @@ -417,11 +417,11 @@ if (status) return -1; /// M: The tablet rotation maybe 90/270 degrees, so set the lcm config for tablet - SurfaceComposerClient::setDisplayProjection(dtoken, DisplayState::eOrientationDefault, Rect(dinfo.w, dinfo.h), Rect(dinfo.w, dinfo.h)); + SurfaceComposerClient::setDisplayProjection(dtoken, DisplayState::eOrientation90, Rect(dinfo.h, dinfo.w), Rect(dinfo.h, dinfo.w)); // create the native surface sp control = session()->createSurface(String8("BootAnimation"), - dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565); + dinfo.h, dinfo.w, PIXEL_FORMAT_RGB_565);
部分应用在系统强制横屏显示后,还是会以竖屏UI显示,导致应用不能正常使用。
修改路径:frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
private int getAppSpecifiedOrientation() { //wc 强制设置第三方App横屏显示 if(true){ return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; } //wc 强制设置第三方App横屏显示 int lastOrientation = SCREEN_ORIENTATION_UNSPECIFIED; boolean findingBehind = false; boolean lastFullscreen = false; DisplayContent displayContent = getDefaultDisplayContentLocked(); final ArrayList tasks = displayContent.getTasks(); final boolean inMultiWindow = isStackVisibleLocked(DOCKED_STACK_ID) || isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID); final boolean dockMinimized = getDefaultDisplayContentLocked().mDividerControllerLocked.isMinimizedDock(); ...... // The next app has not been requested to be visible, so we keep the current orientation // to prevent freezing/unfreezing the display too early unless we are in multi-window, in // which we don't let the app customize the orientation unless it was the home task that // is handled above. return inMultiWindow ? SCREEN_ORIENTATION_UNSPECIFIED : mLastOrientation; }
更多相关文章
- Android(安卓)监听开机广播实现应用开机自启动
- android 删除开机动画
- Android(安卓)Device Chooser中显示Target unknown解决方法
- Android——获取系统图片/拍照/获取图片路径并显示的Demo
- Android仿微信朋友圈图片上传选择器布局
- Android(安卓)了解Activity
- 获取或同步MeeGo和Android项目源码的脚本[修改稿]
- Android:seekbar控件在某些背景下不能正常显示
- android软件开发:程序的开机启动