// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.content.browser;

import android.content.Context;
import android.content.pm.PackageManager;

import org.chromium.content.common.CommandLine;

/**
 * A utility class that has helper methods for device configuration.
 */
public class DeviceUtils {

    /**
     * The minimum width that would classify the device as a tablet.
     */
    private static final int MINIMUM_TABLET_WIDTH_DP = 600;

    private static Boolean isTv = null;
    private static Boolean isTablet = null;

    /**
     * @param context Android's context
     * @return        Whether the app is should treat the device as a tablet for layout.
     */
    public static boolean isTablet(Context context) {
        if (isTablet == null) {
            if (isTv(context)) {
                isTablet = true;
                return isTablet;
            }
            int minimumScreenWidthDp = context.getResources().getConfiguration().
                    smallestScreenWidthDp;
            isTablet = minimumScreenWidthDp >= MINIMUM_TABLET_WIDTH_DP;
        }
        return isTablet;
    }

    /**
     * Checks if the device should be treated as TV. Note that this should be
     * invoked before {@link #isTablet(Context)} to get the correct result
     * since they are not orthogonal.
     *
     * @param context Android context
     * @return {@code true} if the device should be treated as TV.
     */
    public static boolean isTv(Context context) {
        if (isTv == null) {
            PackageManager manager = context.getPackageManager();
            if (manager != null) {
                isTv = manager.hasSystemFeature(PackageManager.FEATURE_TELEVISION);
                return isTv;
            }
            isTv = false;
        }
        return isTv;
    }

    /**
     * Appends the switch specifying which user agent should be used for this device.
     * @param context The context for the caller activity.
     */
    public static void addDeviceSpecificUserAgentSwitch(Context context) {
        if (isTablet(context)) {
            CommandLine.getInstance().appendSwitch(CommandLine.TABLET_UI);
        } else {
            CommandLine.getInstance().appendSwitch(CommandLine.USE_MOBILE_UA);
        }
    }
}

@@ -604,17 +604,18 @@
 Boolean 
-i
+sI
 sTv = nu
@@ -641,25 +641,26 @@
 tic Boolean 
-i
+sI
 sTablet = nu
@@ -871,25 +871,26 @@
         if (
-i
+sI
 sTablet == n
@@ -937,33 +937,34 @@
                 
-i
+sI
 sTablet = true;%0A
@@ -978,33 +978,34 @@
          return 
-i
+sI
 sTablet;%0A       
@@ -1148,17 +1148,18 @@
         
-i
+sI
 sTablet 
@@ -1234,17 +1234,18 @@
  return 
-i
+sI
 sTablet;
@@ -1633,17 +1633,18 @@
     if (
-i
+sI
 sTv == n
@@ -1763,25 +1763,26 @@
             
-i
+sI
 sTv = manage
@@ -1851,33 +1851,34 @@
          return 
-i
+sI
 sTv;%0A           
@@ -1892,17 +1892,18 @@
         
-i
+sI
 sTv = fa
@@ -1932,17 +1932,18 @@
  return 
-i
+sI
 sTv;%0A   

Update variable names to follow the style guide.