• Android Configuration介绍 (未完成)


    博客很空,想赶紧填一篇东西,选的这个题目看了下中文网络中还不是很常见,但是由于我也不了解全部的configuration,需要验证思路,写起来也很慢,先发个未完成的占座。

    所谓Configuration指的是Configuration.java这个类所代表的配置信息,它的位置在($ANDROID_ROOT)/frameworks/base/core/java/android/content/res/Configuration.java

    本文分三部分:

    一. 逐一讲解成员变量,了解功能和每一个数值代表的含义;

    二. 追寻configuration的初始化和被使用的过程;

    三. 总结作为一个Android平台维护者怎么配置这些数值。

    一. 成员变量

    public int densityDpi //The target screen density being rendered to, corresponding to density resource qualifier.

    目前一般是一个3位数的10进制数,分别对应着:

    120 –> ldpi: Low-density screens.

    160 –> mdpi: Medium-density (on traditional HVGA) screens.

    240 –> hdpi: High-density screens.

    320 –> xhdpi: Extra high-density screens.

    之后还有更大的xxhdpi(480)和xxxhdpi(640),densityDpi越大,代表当前设备的屏幕分辨率(dpi,dot per inch)越高,一个设备的densityDpi在出厂时已根据设备屏幕dpi决定了;假设我现在有一个MX3,1800 × 1080 resolution,5.1 inches,那么它的dpi就是对角线的像素点数除以5.1约等于411.6,我把densityDpi配置成与411.6最接近的xxhdpi。它的作用在于让app在不知道每一款Android设备的屏幕大小和分辨率的情况下,可以通过densityDpi动态决定载入什么资源,从而适配这些设备。比如在画UI的时候一般用dp做单位,系统会帮忙缩放,在不同分辨率的设备上视觉上会有相同的大小;而用pixel做单位就只有固定pixel的大小,相同pixel大小的view在高分辨率的设备上视觉上就相对显得小。这里就用到的pixel和dp的转换:

    dp= px*160/densityDpi;

    另外app的res目录下会有一些drawable-mdpi/drawable-hdpi/drawable-xhdpi,也是通过densityDpi来决定的,当然这些目录的分法更复杂一点,这里就不多说了。

    *由windowManagerService负责维护,参考WindowManagerService.computeScreenConfigurationLocked()

    public float fontScale //Current user preference for the scaling factor for fonts, relative to the base density scaling.

    它的直接显示就是在Settings app –> Display –> Font Size, 从KitKat的源码来看分别对应着:Small: 0.75,Normal: 1, Large:1.25 (不同平台可能会有客制化)。Normal对应着一个基准的font size,最终系统会将fontScale与density相乘,得到一个scaledDensity,影响所有用sp做单位的view的缩放比。

    Settings app –> Accessibility –> Large Text也会有影响,勾上的话会选择最大的那个fontScale。

    *由Settings和SettingsProvider负责维护,参考Settings.System.getConfiguration()

    public int hardKeyboardHidden //A flag indicating whether the hard keyboard has been hidden.

    public int keyboardHidden //A flag indicating whether any keyboard is available.

    public int navigationHidden //A flag indicating whether any 5-way or DPAD navigation available.

    这三条放一起说,顾名思义分别是物理键盘是否功能可用(不包括usb键盘),键盘是否功能可用(物理键盘和虚拟键盘都不能用为不可用),触摸板、方向键等navigation方式是否功能可用,用于判断。

    *由PhoneWindowManager负责维护,参考PhoneWindowManager.adjustConfigurationLw()

    public int keyboard //The kind of keyboard attached to the device.

    public int navigation //The kind of navigation method available on the device.

    public int touchscreen //The kind of touch screen attached to the device.

    这三条也放在一起说,keyboard种类有

    KEYBOARD_UNDEFINED、KEYBOARD_NOKEYS、KEYBOARD_QWERTY、KEYBOARD_12KEY

    navigation种类有

    NAVIGATION_UNDEFINED、NAVIGATION_NONAV、NAVIGATION_DPAD、NAVIGATION_TRACKBALL、NAVIGATION_WHEEL

    touchScreen种类有

    TOUCHSCREEN_UNDEFINED、TOUCHSCREEN_NOTOUCH、TOUCHSCREEN_FINGER

    从名字很明显能看出各个数值的含义。

    *由windowManagerService负责维护,参考WindowManagerService.computeScreenConfigurationLocked()

    public Locale locale

    Current user preference for the locale, corresponding to locale resource qualifier.

    public int mcc

    IMSI MCC (Mobile Country Code), corresponding to mcc resource qualifier.

    public int mnc

    IMSI MNC (Mobile Network Code), corresponding to mnc resource qualifier.

    public int orientation

    Overall orientation of the screen.

    public int screenHeightDp

    The current height of the available screen space, in dp units, corresponding to screen height resource qualifier.

    public int screenLayout

    Bit mask of overall layout of the screen.

    public int screenWidthDp

    The current width of the available screen space, in dp units, corresponding to screen width resource qualifier.

    public int smallestScreenWidthDp

    The smallest screen size an application will see in normal operation, corresponding to smallest screen width resource qualifier.

    public int uiMode

    Bit mask of the ui mode.

  • 相关阅读:
    Firefox+BurpSuite绕过HSTS抓包
    如何在百万行代码中发现隐藏的后门
    10款常见的Webshell检测工具
    真实揭露:一段激情.视频裸.聊被骗的经历
    Kerberos速查表:如何攻击Kerberos
    在线播放视频加密/PDF电子书在线加密
    私人珍藏:WAF攻防实战笔记
    渗透利器 | 提权辅助工具箱
    这些年,我们一直追逐的漏洞利用神器
    如何防止CDN防护被绕过
  • 原文地址:https://www.cnblogs.com/orangec/p/3861516.html
Copyright © 2020-2023  润新知