Android10.0 MTK 平板横屏方案修改(强制app横屏 + 开机logo/动画+关机充电横屏 + RecoveryUI 横屏)

简介: Android10.0 MTK 平板横屏方案修改(强制app横屏 + 开机logo/动画+关机充电横屏 + RecoveryUI 横屏)

拆解步骤


1、app 强制横屏显示,无视 android:screenOrientation=“portrait” 属性

2、开机动画横屏

3、开机logo、关机充电动画横屏

4、RecoveryUI 横屏


上代码


1、app 强制横屏显示


DisPlayContent 显示 mRotation 默认改为 3 (270)

frameworks\base\services\core\java\com\android\server\wm\DisplayContent.java


/**
     * Current rotation of the display.
     * Constants as per {@link android.view.Surface.Rotation}.
     *
     * @see #updateRotationUnchecked()
     */
    // private int mRotation = 0;
    private int mRotation = 3;//cczheng add for land scap
 boolean updateRotationUnchecked(boolean forceUpdate) {
        cczheng add for app force landscape
        if (true) {
            return true;
        }
        20200325 add for app force landscape
        ScreenRotationAnimation screenRotationAnimation;
        if (!forceUpdate) {
            if (mDeferredRotationPauseCount > 0) {
                // Rotation updates have been paused temporarily.  Defer the update until
                // updates have been resumed.
                if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
                return false;
            }
    ......

系统导航栏位置调整,横屏后 navigationBarPosition 默认在左边


作为平板项目,需要将位置改为底部,直接修改 navigationBarPosition() 返回 NAV_BAR_BOTTOM


frameworks\base\services\core\java\com\android\server\wm\DisplayPolicy.java

@NavigationBarPosition
    private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) {
      //cchzneg annotaion for land scape
        /*if (mNavigationBarCanMove && displayWidth > displayHeight) {
            if (displayRotation == Surface.ROTATION_270) {
                return NAV_BAR_LEFT;
            } else {
                return NAV_BAR_RIGHT;
            }
        }*/
        return NAV_BAR_BOTTOM;
    }

2、开机动画横屏


DisplayState::eOrientationDefault 修改为 3

frameworks\base\cmds\bootanimation\BootAnimation.cpp


status_t BootAnimation::readyToRun() {
    mAssets.addDefaultAssets();
    sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
            ISurfaceComposer::eDisplayIdMain));
    DisplayInfo dinfo;
    status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
    if (status)
        return -1;
    //cczheng add for land scap  [S]
    if (2 > 1) {
        int temp = dinfo.h;
        dinfo.h = dinfo.w;
        dinfo.w = temp;
    }
    Rect destRect(dinfo.w, dinfo.h);
    //270
    t.setDisplayProjection(mDisplayToken, 3, destRect, destRect);
    t.apply();
    //cczheng add for land scap  [E]
    /// M: The tablet rotation maybe 90/270 degrees, so set the lcm config for tablet
    /*t.setDisplayProjection(mDisplayToken, DisplayState::eOrientationDefault,
        Rect(dinfo.w, dinfo.h), Rect(dinfo.w, dinfo.h));
    t.apply();*/
    // create the native surface
    sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
            dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
    t.setLayer(control, 0x40000000)
        .apply();
  .....
}


3、开机logo、关机充电动画横屏


开机logo定义屏幕分辨率以对应资源文件夹的位置为

vendor\mediatek\proprietary\bootable\bootloader\lk\project\xxxx.mk 没有则看下面的

device\mediateksample\xxxx\ProjectConfig.mk


mk 中的 BOOT_LOGO = hdplus


对应的资源文件位置在 vendor/mediatek/proprietary/bootable/bootloader/lk/dev/logo/hdplus


可以看到 hdplus 中都是竖屏的图片,而 wxganl 中已经是横屏的图片


aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzEwLzExL3ViV2tOdC5wbmc.png

则我们将 BOOT_LOGO 修改为 wxganl 即可


接下来还需要继续修改显示的角度,依旧改成 270,不然会出现花屏的现象


开机第一张图片 uboot 对应显示 phical_screen.rotation = 270


vendor\mediatek\proprietary\bootable\bootloader\lk\platform\mt6765\mt_logo.c

void init_fb_screen()
{
  .....
  // in JB2.MP need to allign width and height to 32 ,but jb5.mp needn't
  phical_screen.needAllign = 1;
  phical_screen.allignWidth = ALIGN_TO(CFG_DISPLAY_WIDTH, MTK_FB_ALIGNMENT);
  /* In GB, no need to adjust 180 showing logo ,for fb driver dealing the change */
  /* but in JB, need adjust it for screen 180 roration           */
  phical_screen.need180Adjust = 0;   // need sync with chip driver
  dprintf(INFO, "[lk logo: %s %d]MTK_LCM_PHYSICAL_ROTATION = %s\n",__FUNCTION__,__LINE__, MTK_LCM_PHYSICAL_ROTATION);
  if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "270", 3)) {
    phical_screen.rotation = 270;
  } else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "90", 2)) {
    phical_screen.rotation = 90;
  } else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "180", 3) && (phical_screen.need180Adjust == 1)) {
    phical_screen.rotation = 180;
  } else {
    phical_screen.rotation = 270;//cczheng add for land scap
  }
  ....

开机第二张图片 kernel 对应显示 phical_screen.rotation = 270

vendor\mediatek\proprietary\external\libshowlogo\charging_animation.cpp

int anim_fb_init(void)
{
     .....
    phical_screen.needAllign = 1;
    phical_screen.need180Adjust = 1;
    phical_screen.fb_size = fb_size;
    if (MTK_LOG_ENABLE == 1) {
        SLOGD("[libshowlogo: %s %d]MTK_LCM_PHYSICAL_ROTATION = %s\n",__FUNCTION__,__LINE__, MTK_LCM_PHYSICAL_ROTATION);
    }
    if(0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "270", 3))
    {
        phical_screen.rotation = 270;
    } else if(0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "90", 2)){
        phical_screen.rotation = 90;
    } else if(0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "180", 3) && (phical_screen.need180Adjust == 1)){
        phical_screen.rotation = 180;
    } else {
        phical_screen.rotation = 270;//cczheng add for land scap
    }
    if (MTK_LOG_ENABLE == 1) {
        SLOGD("[libshowlogo]phical_screen: width= %d,height= %d,bits_per_pixel =%d,needAllign = %d,allignWidth=%d rotation =%d ,need180Adjust = %d\n",
                phical_screen.width, phical_screen.height,
                phical_screen.bits_per_pixel, phical_screen.needAllign,
                phical_screen.allignWidth, phical_screen.rotation, phical_screen.need180Adjust);
        SLOGD("[libshowlogo: %s %d]show old animtion= 1, running show_animationm_ver %d\n",__FUNCTION__,__LINE__, show_animationm_ver);
        SLOGD("[libshowlogo: %s %d]draw_anim_mode = 1, running mode %d\n",__FUNCTION__,__LINE__, draw_anim_mode);
    }
    return 0;
}


关机充电动画错位问题


如果出现充电动画图片错位的现象,多数都是因为图形绘制点和屏幕尺寸不匹配导致的。可通过调整 cust_display.h 中位置参数


/vendor/mediatek/proprietary/external/libshowlogo/cust_display.h


之前都是通过修改 cust_display.h 文件夹中预置宏定义,10.0 中代码结构做了调整,宏定义都没了,初始化写在了 show_animation_common.c 中,修改 rotation = 3 对调 lcm_width 和 lcm_height,当 lcm_width1280 && lcm_height800 时动画就不错位了,这里根据你自己的分辨率情况自行微调,不过一般系统默认的配置值都是对了


vendor/mediatek/proprietary/external/libshowlogo/show_animation_common.c

/*
 * Fill resolution structure based on lcd size
 *
 */
void init_charging_animation_ui_dimension() {
    int lcm_width, lcm_height;
    struct fb_var_screeninfo vinfo;
    display_fd = open("/dev/graphics/fb0", O_RDONLY);
    if (display_fd < 0) {
      SLOGD("[show_animation_common: %s %d]open mtkfb fail...\n",__FUNCTION__,__LINE__);
    }
    if (ioctl(display_fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
      close(display_fd);
      SLOGD("[show_animation_common: %s %d]ioctl FBIOGET_VSCREENINFO failed\n",__FUNCTION__,__LINE__);
    }
    close(display_fd);
    lcm_width = vinfo.xres;
    lcm_height = vinfo.yres;
    int rotation = getValue(MTK_LCM_PHYSICAL_ROTATION_PROP, "0");
    rotation = 3;
    // cczheng add rotation = 3 for charging landscape
    if (MTK_LOG_ENABLE == 1) {
        SLOGD("[libshowlogo: %s %d]rotation = %d\n",__FUNCTION__,__LINE__, rotation);
    }
    if ((3 == rotation)|| (1 == rotation)){
        lcm_width = vinfo.yres;
        lcm_height = vinfo.xres;
    }
    SLOGD("[show_animation_common: %s %d] lcm_width and lcm_height= %d , %d \n",__FUNCTION__,__LINE__,lcm_width,lcm_height);
    if(lcm_width==1080) {
      charg_anim_ui_dimen.cap_left =387;
      charg_anim_ui_dimen.cap_right= 691;
      charg_anim_ui_dimen.num_left=351+84;
      charg_anim_ui_dimen.num_right=435+84;


4、RecoveryUI 横屏


RecoveryUI 在9.0 之前安卓源码并没有为我们适配好旋转配置,之前都是通过自己新增 mt_graphic_rotate.cpp 和 mt_graphic_rotate.h 文件来实现旋转。10.0 中代码也进行了较大重构相比之前,只需修改简单配置 rotation 就能旋转为横屏。


rotation = GRRotation::LEFT; 270


rotation = GRRotation::DOWN; 180


rotation = GRRotation::RIGHT; 90


bootable\recovery\minui\graphics.cpp

int gr_init() {
  .....
  gr_backend = backend.release();
  int overscan_percent = android::base::GetIntProperty("ro.minui.overscan_percent", 0);
  overscan_offset_x = gr_draw->width * overscan_percent / 100;
  overscan_offset_y = gr_draw->height * overscan_percent / 100;
  gr_flip();
  gr_flip();
  if (!gr_draw) {
    printf("gr_init: gr_draw becomes nullptr after gr_flip\n");
    return -1;
  }
  std::string rotation_str =
      android::base::GetProperty("ro.minui.default_rotation", "ROTATION_NONE");
  if (rotation_str == "ROTATION_RIGHT") {
    gr_rotate(GRRotation::RIGHT);
  } else if (rotation_str == "ROTATION_DOWN") {
    gr_rotate(GRRotation::DOWN);
  } else if (rotation_str == "ROTATION_LEFT") {
    gr_rotate(GRRotation::LEFT);
  } else {  // "ROTATION_NONE" or unknown string
    gr_rotate(GRRotation::NONE);
  }
  rotation = GRRotation::LEFT;
  //cczheng add rotation = 3 for recoveryUI landscape


ok,这样就大功告成了,完美的横屏适配

目录
相关文章
|
Android开发 数据安全/隐私保护 开发者
Android自定义view之模仿登录界面文本输入框(华为云APP)
本文介绍了一款自定义输入框的实现,包含静态效果、hint值浮动动画及功能扩展。通过组合多个控件完成界面布局,使用TranslateAnimation与AlphaAnimation实现hint文字上下浮动效果,支持密码加密解密显示、去除键盘回车空格输入、光标定位等功能。代码基于Android平台,提供完整源码与attrs配置,方便复用与定制。希望对开发者有所帮助。
401 0
|
存储 前端开发 安全
实现“永久登录”:针对蜻蜓Q系统的用户体验优化方案(前端uni-app+后端Laravel详解)-优雅草卓伊凡
实现“永久登录”:针对蜻蜓Q系统的用户体验优化方案(前端uni-app+后端Laravel详解)-优雅草卓伊凡
553 5
|
数据采集 JSON 网络安全
移动端数据抓取:Android App的TLS流量解密方案
本文介绍了一种通过TLS流量解密技术抓取知乎App热榜数据的方法。利用Charles Proxy解密HTTPS流量,分析App与服务器通信内容;结合Python Requests库模拟请求,配置特定请求头以绕过反爬机制。同时使用代理IP隐藏真实IP地址,确保抓取稳定。最终成功提取热榜标题、内容简介、链接等信息,为分析热点话题和用户趋势提供数据支持。此方法也可应用于其他Android App的数据采集,但需注意选择可靠的代理服务。
840 11
移动端数据抓取:Android App的TLS流量解密方案
|
存储 Android开发 数据安全/隐私保护
Thanox安卓系统增加工具下载,管理、阻止、限制后台每个APP运行情况
Thanox是一款Android系统管理工具,专注于权限、后台启动及运行管理。支持应用冻结、系统优化、UI自定义和模块管理,基于Xposed框架开发,安全可靠且开源免费,兼容Android 6.0及以上版本。
2071 4
|
数据采集 数据可视化 API
驱动业务决策:基于Python的App用户行为分析与可视化方案
驱动业务决策:基于Python的App用户行为分析与可视化方案
|
BI 开发工具 开发者
App全渠道统计方案:如何用一个工具整合所有获客渠道数据?
还在为地推、社群、广告等不同获客渠道的数据分散而烦恼吗?本文将教您如何用一个工具整合所有渠道数据,实现精准的渠道归因与效果分析。
643 0
|
缓存 移动开发 JavaScript
如何优化UniApp开发的App的启动速度?
如何优化UniApp开发的App的启动速度?
1990 139
|
移动开发 JavaScript weex
UniApp开发的App在启动速度方面有哪些优势和劣势?
UniApp开发的App在启动速度方面有哪些优势和劣势?
945 137
|
移动开发 小程序 Android开发
基于 uni-app 开发的废品回收类多端应用功能与界面说明
本文将对一款基于 uni-app 开发的废品回收类多端应用,从多端支持范围、核心功能模块及部分界面展示进行客观说明,相关资源信息也将一并呈现。
456 0

热门文章

最新文章