EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.content.browser]

COVERAGE SUMMARY FOR SOURCE FILE [DeviceUtils.java]

nameclass, %method, %block, %line, %
DeviceUtils.java100% (1/1)80%  (4/5)69%  (46/67)71%  (14.8/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DeviceUtils100% (1/1)80%  (4/5)69%  (46/67)71%  (14.8/21)
DeviceUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
addDeviceSpecificUserAgentSwitch (Context): void 100% (1/1)64%  (7/11)75%  (3/4)
isTablet (Context): boolean 100% (1/1)70%  (19/27)69%  (4.8/7)
isTv (Context): boolean 100% (1/1)71%  (15/21)71%  (5/7)
<static initializer> 100% (1/1)100% (5/5)100% (2/2)

1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4 
5package org.chromium.content.browser;
6 
7import android.content.Context;
8import android.content.pm.PackageManager;
9 
10import org.chromium.content.common.CommandLine;
11 
12/**
13 * A utility class that has helper methods for device configuration.
14 */
15public class DeviceUtils {
16 
17    /**
18     * The minimum width that would classify the device as a tablet.
19     */
20    private static final int MINIMUM_TABLET_WIDTH_DP = 600;
21 
22    private static Boolean sIsTv = null;
23    private static Boolean sIsTablet = null;
24 
25    /**
26     * @param context Android's context
27     * @return        Whether the app is should treat the device as a tablet for layout.
28     */
29    public static boolean isTablet(Context context) {
30        if (sIsTablet == null) {
31            if (isTv(context)) {
32                sIsTablet = true;
33                return sIsTablet;
34            }
35            int minimumScreenWidthDp = context.getResources().getConfiguration().
36                    smallestScreenWidthDp;
37            sIsTablet = minimumScreenWidthDp >= MINIMUM_TABLET_WIDTH_DP;
38        }
39        return sIsTablet;
40    }
41 
42    /**
43     * Checks if the device should be treated as TV. Note that this should be
44     * invoked before {@link #isTablet(Context)} to get the correct result
45     * since they are not orthogonal.
46     *
47     * @param context Android context
48     * @return {@code true} if the device should be treated as TV.
49     */
50    public static boolean isTv(Context context) {
51        if (sIsTv == null) {
52            PackageManager manager = context.getPackageManager();
53            if (manager != null) {
54                sIsTv = manager.hasSystemFeature(PackageManager.FEATURE_TELEVISION);
55                return sIsTv;
56            }
57            sIsTv = false;
58        }
59        return sIsTv;
60    }
61 
62    /**
63     * Appends the switch specifying which user agent should be used for this device.
64     * @param context The context for the caller activity.
65     */
66    public static void addDeviceSpecificUserAgentSwitch(Context context) {
67        if (isTablet(context)) {
68            CommandLine.getInstance().appendSwitch(CommandLine.TABLET_UI);
69        } else {
70            CommandLine.getInstance().appendSwitch(CommandLine.USE_MOBILE_UA);
71        }
72    }
73}

[all classes][org.chromium.content.browser]
EMMA 2.0.5312 (C) Vladimir Roubtsov