PhoneモードとTabletモードの切り分け

Android 4.x(Ice Cream Sandwich)はPhoneとTablet、両方のOSとして使用されます。

では、どこでPhone/Tabletの切り分けはどこで行っているか確認します。

Phone/Tabletの切り分け

起動処理中、以下の処理でFrameworks内のDisplaySizeを初期化します。

ServerThread#run()
- WindowManagerService#displayReady
- PhoneWindowManagerService#setInitialDisplaySize


PhoneWindowManagerService#setInitialDisplaySizeのそれらしき処理があります。

        // Determine whether the status bar can hide based on the size
        // of the screen.  We assume sizes > 600dp are tablets where we
        // will use the system bar.
        int shortSizeDp = shortSize
                * DisplayMetrics.DENSITY_DEFAULT
                / DisplayMetrics.DENSITY_DEVICE;
        mStatusBarCanHide = shortSizeDp < 600;

ソースは
 スクリーンのswWidth * DisplayMetrics.DENSITY_DEFAULT
/ DisplayMetrics.DENSITY_DEVICE が600未満かどうか
と記述されています。


DisplayMetrics.javaに記述されている値はこんな感じ。

    /**
     * Standard quantized DPI for medium-density screens.
     */
    public static final int DENSITY_MEDIUM = 160;

    /**
     * The reference density used throughout the system.
     */
    public static final int DENSITY_DEFAULT = DENSITY_MEDIUM;

    /**
     * The device's density.
     * @hide becase eventually this should be able to change while
     * running, so shouldn't be a constant.
     */
    public static final int DENSITY_DEVICE = getDeviceDensity();

    private static int getDeviceDensity() {
        // qemu.sf.lcd_density can be used to override ro.sf.lcd_density
        // when running in the emulator, allowing for dynamic configurations.
        // The reason for this is that ro.sf.lcd_density is write-once and is
        // set by the init process when it parses build.prop before anything else.
        return SystemProperties.getInt("qemu.sf.lcd_density",
                SystemProperties.getInt("ro.sf.lcd_density", DENSITY_DEFAULT));
    }

crespo(Nexus s)の場合、

 swWidth = 480
 ro.sf.lcd_density=240
  shortSizeDp = 480 * 160 / 240 = 320

よって、Phoneモードとなる。


maguro(Galaxy Nexus)の場合、

 swWidth = 720
 ro.sf.lcd_density=320
  shortSizeDp = 720 * 160 / 320 = 360

よって、Phoneモードとなる。

maguro(Galaxy Nexus)でTabletモードで起動したい場合、
lcd_densityを320から160に変更すれば可能なはず。

 swWidth = 720
 ro.sf.lcd_density=160
  shortSizeDp = 720 * 160 / 160 = 720

確認しておきたいソース

\frameworks\base\policy\src\com\android\internal\policy\impl
- PhoneWindowManagerService.java

\frameworks\base\core\java\android\util
- DisplayMetrics.java

\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar
- この配下全部 StatusBar / SystemBarの切り分けなど。