blob: 38e38da9f374edbb2d46009289f202015b2b7a9c [file] [log] [blame]
// Copyright 2013 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.chrome.browser.device;
import org.chromium.base.CommandLine;
import org.chromium.base.SysUtils;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.ui.base.DeviceFormFactor;
/**
* This class is used to turn on and off certain features for different types of
* devices.
*/
public class DeviceClassManager {
private static DeviceClassManager sInstance;
// Set of features that can be enabled/disabled
private boolean mEnableSnapshots;
private boolean mEnableLayerDecorationCache;
private boolean mEnableAccessibilityLayout;
private boolean mEnableAnimations;
private boolean mEnablePrerendering;
private boolean mEnableToolbarSwipe;
private final boolean mEnableFullscreen;
private static DeviceClassManager getInstance() {
if (sInstance == null) {
sInstance = new DeviceClassManager();
}
return sInstance;
}
/**
* The {@link DeviceClassManager} constructor should be self contained and
* rely on system information and command line flags.
*/
private DeviceClassManager() {
// Device based configurations.
if (SysUtils.isLowEndDevice()) {
mEnableSnapshots = false;
mEnableLayerDecorationCache = true;
mEnableAccessibilityLayout = true;
mEnableAnimations = false;
mEnablePrerendering = false;
mEnableToolbarSwipe = false;
} else {
mEnableSnapshots = true;
mEnableLayerDecorationCache = true;
mEnableAccessibilityLayout = false;
mEnableAnimations = true;
mEnablePrerendering = true;
mEnableToolbarSwipe = true;
}
if (DeviceFormFactor.isTablet()) {
mEnableAccessibilityLayout = false;
}
// Flag based configurations.
CommandLine commandLine = CommandLine.getInstance();
assert commandLine.isNativeImplementation();
mEnableAccessibilityLayout |= commandLine
.hasSwitch(ChromeSwitches.ENABLE_ACCESSIBILITY_TAB_SWITCHER);
mEnableFullscreen =
!commandLine.hasSwitch(ChromeSwitches.DISABLE_FULLSCREEN);
// Related features.
if (mEnableAccessibilityLayout) {
mEnableAnimations = false;
}
}
/**
* @return Whether or not we can take screenshots.
*/
public static boolean enableSnapshots() {
return getInstance().mEnableSnapshots;
}
/**
* @return Whether or not we can use the layer decoration cache.
*/
public static boolean enableLayerDecorationCache() {
return getInstance().mEnableLayerDecorationCache;
}
/**
* @return Whether or not should use the accessibility tab switcher.
*/
public static boolean enableAccessibilityLayout() {
if (getInstance().mEnableAccessibilityLayout) return true;
if (!AccessibilityUtil.isAccessibilityEnabled()) return false;
return SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceManager.ACCESSIBILITY_TAB_SWITCHER, true);
}
/**
* @return Whether or not full screen is enabled.
*/
public static boolean enableFullscreen() {
return getInstance().mEnableFullscreen;
}
/**
* @return Whether or not we are showing animations.
*/
public static boolean enableAnimations() {
if (!getInstance().mEnableAnimations) return false;
if (!AccessibilityUtil.isAccessibilityEnabled()) return true;
return !SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceManager.ACCESSIBILITY_TAB_SWITCHER, true);
}
/**
* @return Whether or not prerendering is enabled.
*/
public static boolean enablePrerendering() {
return getInstance().mEnablePrerendering;
}
/**
* @return Whether or not we can use the toolbar swipe.
*/
public static boolean enableToolbarSwipe() {
return getInstance().mEnableToolbarSwipe;
}
}