Java Code Examples for org.chromium.base.SysUtils

The following examples show how to use org.chromium.base.SysUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: delion   Source File: CustomTabsConnection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Starts as much as possible in anticipation of a future navigation.
 *
 * @param mayCreatesparewebcontents true if warmup() can create a spare renderer.
 * @return true for success.
 */
private boolean warmupInternal(final boolean mayCreateSpareWebContents) {
    // Here and in mayLaunchUrl(), don't do expensive work for background applications.
    if (!isCallerForegroundOrSelf()) return false;
    mClientManager.recordUidHasCalledWarmup(Binder.getCallingUid());
    final boolean initialized = !mWarmupHasBeenCalled.compareAndSet(false, true);
    // The call is non-blocking and this must execute on the UI thread, post a task.
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (!initialized) initializeBrowser(mApplication);
            if (mayCreateSpareWebContents && mPrerender == null && !SysUtils.isLowEndDevice()) {
                createSpareWebContents();
            }
            mWarmupHasBeenFinished.set(true);
        }
    });
    return true;
}
 
Example 2
Source Project: delion   Source File: ChromeActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void enableHardwareAcceleration() {
    // HW acceleration is disabled in the manifest. Enable it only on high-end devices.
    if (!SysUtils.isLowEndDevice()) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

        // When HW acceleration is enabled manually for an activity, child windows (e.g.
        // dialogs) don't inherit HW acceleration state. However, when HW acceleration is
        // enabled in the manifest, child windows do inherit HW acceleration state. That
        // looks like a bug, so I filed b/23036374
        //
        // In the meanwhile the workaround is to call
        //   window.setWindowManager(..., hardwareAccelerated=true)
        // to let the window know that it's HW accelerated. However, since there is no way
        // to know 'appToken' argument until window's view is attached to the window (!!),
        // we have to do the workaround in onAttachedToWindow()
        mSetWindowHWA = true;
    }
}
 
Example 3
private static boolean detectEnabled() {
    if (SysUtils.isLowEndDevice()) {
        return false;
    }

    // Allow this user-flippable flag to disable the feature.
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_CONTEXTUAL_SEARCH)) {
        return false;
    }

    // Allow this user-flippable flag to enable the feature.
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CONTEXTUAL_SEARCH)) {
        return true;
    }

    // Allow disabling the feature remotely.
    if (getBooleanParam(DISABLED_PARAM)) {
        return false;
    }

    return true;
}
 
Example 4
Source Project: AndroidChromium   Source File: ChromeActivity.java    License: Apache License 2.0 6 votes vote down vote up
private boolean shouldDisableHardwareAcceleration() {
    // Low end devices should disable hardware acceleration for memory gains.
    if (SysUtils.isLowEndDevice()) return true;

    // Turning off hardware acceleration reduces crash rates. See http://crbug.com/651918
    // GT-S7580 on JDQ39 accounts for 42% of crashes in libPowerStretch.so on dev and beta.
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1
            && Build.MODEL.equals("GT-S7580")) {
        return true;
    }
    // SM-N9005 on JSS15J accounts for 44% of crashes in libPowerStretch.so on stable channel.
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2
            && Build.MODEL.equals("SM-N9005")) {
        return true;
    }
    return false;
}
 
Example 5
Source Project: 365browser   Source File: BackgroundOfflinerTask.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Triggers processing of background offlining requests.  This is called when
 * system conditions are appropriate for background offlining, typically from the
 * GcmTaskService onRunTask() method.  In response, we will start the
 * task processing by passing the call along to the C++ RequestCoordinator.
 * Also starts UMA collection.
 *
 * @returns Whether processing will be carried out and completion will be indicated through a
 *     callback.
 */
static boolean startBackgroundRequestsImpl(BackgroundSchedulerProcessor bridge, Context context,
        Bundle taskExtras, Callback<Boolean> callback) {
    TriggerConditions triggerConditions =
            TaskExtrasPacker.unpackTriggerConditionsFromBundle(taskExtras);
    DeviceConditions currentConditions = DeviceConditions.getCurrentConditions(context);
    if (!currentConditions.isPowerConnected()
            && currentConditions.getBatteryPercentage()
                    < triggerConditions.getMinimumBatteryPercentage()) {
        Log.d(TAG, "Battery percentage is lower than minimum to start processing");
        return false;
    }

    if (SysUtils.isLowEndDevice() && ApplicationStatus.hasVisibleActivities()) {
        Log.d(TAG, "Application visible on low-end device so deferring background processing");
        return false;
    }

    // Gather UMA data to measure how often the user's machine is amenable to background
    // loading when we wake to do a task.
    long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(taskExtras);
    OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis);

    return bridge.startScheduledProcessing(currentConditions, callback);
}
 
Example 6
Source Project: 365browser   Source File: ContextualSearchFieldTrial.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean detectEnabled() {
    if (SysUtils.isLowEndDevice()) {
        return false;
    }

    // Allow this user-flippable flag to disable the feature.
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_CONTEXTUAL_SEARCH)) {
        return false;
    }

    // Allow this user-flippable flag to enable the feature.
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CONTEXTUAL_SEARCH)) {
        return true;
    }

    // Allow disabling the feature remotely.
    if (getBooleanParam(DISABLED_PARAM)) {
        return false;
    }

    return true;
}
 
Example 7
Source Project: 365browser   Source File: ChromeActivity.java    License: Apache License 2.0 6 votes vote down vote up
private boolean shouldDisableHardwareAcceleration() {
    // Low end devices should disable hardware acceleration for memory gains.
    if (SysUtils.isLowEndDevice()) return true;

    // Turning off hardware acceleration reduces crash rates. See http://crbug.com/651918
    // GT-S7580 on JDQ39 accounts for 42% of crashes in libPowerStretch.so on dev and beta.
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1
            && Build.MODEL.equals("GT-S7580")) {
        return true;
    }
    // SM-N9005 on JSS15J accounts for 44% of crashes in libPowerStretch.so on stable channel.
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2
            && Build.MODEL.equals("SM-N9005")) {
        return true;
    }
    return false;
}
 
Example 8
Source Project: 365browser   Source File: Toast.java    License: Apache License 2.0 6 votes vote down vote up
private Toast(Context context, android.widget.Toast toast) {
    mToast = toast;

    if (SysUtils.isLowEndDevice() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Don't HW accelerate Toasts. Unfortunately the only way to do that is to make
        // toast.getView().getContext().getApplicationInfo() return lies to prevent
        // WindowManagerGlobal.addView() from adding LayoutParams.FLAG_HARDWARE_ACCELERATED.
        mSWLayout = new FrameLayout(new ContextWrapper(context) {
            @Override
            public ApplicationInfo getApplicationInfo() {
                ApplicationInfo info = new ApplicationInfo(super.getApplicationInfo());
                // On Lollipop the condition we need to fail is
                // "targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP"
                // (and for Chrome targetSdkVersion is always the latest)
                info.targetSdkVersion = Build.VERSION_CODES.KITKAT;

                // On M+ the condition we need to fail is
                // "flags & ApplicationInfo.FLAG_HARDWARE_ACCELERATED"
                info.flags &= ~ApplicationInfo.FLAG_HARDWARE_ACCELERATED;
                return info;
            }
        });

        setView(toast.getView());
    }
}
 
Example 9
private static void initializeAlreadyLocked(String[] initCommandLine)
        throws ProcessInitException {
    if (sInitialized) {
        return;
    }
    int resultCode = nativeLibraryLoaded(initCommandLine);
    if (resultCode != 0) {
        Log.e(TAG, "error calling nativeLibraryLoaded");
        throw new ProcessInitException(resultCode);
    }
    // From this point on, native code is ready to use and checkIsReady()
    // shouldn't complain from now on (and in fact, it's used by the
    // following calls).
    sInitialized = true;
    CommandLine.enableNativeProxy();
    TraceEvent.setEnabledToMatchNative();
    // Record histogram for the content linker.
    if (Linker.isUsed())
      nativeRecordContentAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(),
                                                SysUtils.isLowEndDevice());
}
 
Example 10
private static void initializeAlreadyLocked(String[] initCommandLine)
        throws ProcessInitException {
    if (sInitialized) {
        return;
    }
    int resultCode = nativeLibraryLoaded(initCommandLine);
    if (resultCode != 0) {
        Log.e(TAG, "error calling nativeLibraryLoaded");
        throw new ProcessInitException(resultCode);
    }
    // From this point on, native code is ready to use and checkIsReady()
    // shouldn't complain from now on (and in fact, it's used by the
    // following calls).
    sInitialized = true;
    CommandLine.enableNativeProxy();
    TraceEvent.setEnabledToMatchNative();
    // Record histogram for the content linker.
    if (Linker.isUsed())
      nativeRecordContentAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(),
                                                SysUtils.isLowEndDevice());
}
 
Example 11
private static void initializeAlreadyLocked(String[] initCommandLine)
        throws ProcessInitException {
    if (sInitialized) {
        return;
    }
    int resultCode = nativeLibraryLoaded(initCommandLine);
    if (resultCode != 0) {
        Log.e(TAG, "error calling nativeLibraryLoaded");
        throw new ProcessInitException(resultCode);
    }
    // From this point on, native code is ready to use and checkIsReady()
    // shouldn't complain from now on (and in fact, it's used by the
    // following calls).
    sInitialized = true;
    CommandLine.enableNativeProxy();
    TraceEvent.setEnabledToMatchNative();
    // Record histogram for the content linker.
    if (Linker.isUsed())
      nativeRecordContentAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(),
                                                SysUtils.isLowEndDevice());
}
 
Example 12
private static void initializeAlreadyLocked(String[] initCommandLine)
        throws ProcessInitException {
    if (sInitialized) {
        return;
    }
    int resultCode = nativeLibraryLoaded(initCommandLine);
    if (resultCode != 0) {
        Log.e(TAG, "error calling nativeLibraryLoaded");
        throw new ProcessInitException(resultCode);
    }
    // From this point on, native code is ready to use and checkIsReady()
    // shouldn't complain from now on (and in fact, it's used by the
    // following calls).
    sInitialized = true;
    CommandLine.enableNativeProxy();
    TraceEvent.setEnabledToMatchNative();
    // Record histogram for the content linker.
    if (Linker.isUsed())
      nativeRecordContentAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(),
                                                SysUtils.isLowEndDevice());
}
 
Example 13
Source Project: delion   Source File: ReaderModeManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether Reader mode and its new UI are enabled.
 * @param context A context
 */
public static boolean isEnabled(Context context) {
    if (context == null) return false;

    boolean enabled = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_DOM_DISTILLER)
            && !CommandLine.getInstance().hasSwitch(
                    ChromeSwitches.DISABLE_READER_MODE_BOTTOM_BAR)
            && !DeviceFormFactor.isTablet(context)
            && DomDistillerTabUtils.isDistillerHeuristicsEnabled()
            && !SysUtils.isLowEndDevice();
    return enabled;
}
 
Example 14
Source Project: delion   Source File: DeviceClassManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
        mDisableDomainReliability = true;
    } else {
        mEnableSnapshots = true;
        mEnableLayerDecorationCache = true;
        mEnableAccessibilityLayout = false;
        mEnableAnimations = true;
        mEnablePrerendering = true;
        mEnableToolbarSwipe = true;
        mDisableDomainReliability = false;
    }

    if (DeviceFormFactor.isTablet(ContextUtils.getApplicationContext())) {
        mEnableAccessibilityLayout = false;
    }

    // Flag based configurations.
    CommandLine commandLine = CommandLine.getInstance();
    mEnableAccessibilityLayout |= commandLine
            .hasSwitch(ChromeSwitches.ENABLE_ACCESSIBILITY_TAB_SWITCHER);
    mEnableFullscreen =
            !commandLine.hasSwitch(ChromeSwitches.DISABLE_FULLSCREEN);
    mEnableToolbarSwipeInDocumentMode =
            commandLine.hasSwitch(ChromeSwitches.ENABLE_TOOLBAR_SWIPE_IN_DOCUMENT_MODE);

    // Related features.
    if (mEnableAccessibilityLayout) {
        mEnableAnimations = false;
    }
}
 
Example 15
Source Project: delion   Source File: DeferredStartupHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void startModerateBindingManagementIfNeeded() {
    // Moderate binding doesn't apply to low end devices.
    if (SysUtils.isLowEndDevice()) return;

    boolean moderateBindingTillBackgrounded =
            FieldTrialList.findFullName("ModerateBindingOnBackgroundTabCreation")
                    .equals("Enabled");
    ChildProcessLauncher.startModerateBindingManagement(
            mAppContext, moderateBindingTillBackgrounded);
}
 
Example 16
Source Project: delion   Source File: ContextualSearchFieldTrial.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean detectEnabled() {
    if (SysUtils.isLowEndDevice()) {
        return false;
    }

    // This is used for instrumentation tests (i.e. it is not a user-flippable flag). We cannot
    // use Variations params because in the test harness, the initialization comes before any
    // native methods are available. And the ContextualSearchManager is initialized very early
    // in the Chrome initialization.
    if (CommandLine.getInstance().hasSwitch(
                ChromeSwitches.ENABLE_CONTEXTUAL_SEARCH_FOR_TESTING)) {
        return true;
    }

    // Allow this user-flippable flag to disable the feature.
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_CONTEXTUAL_SEARCH)) {
        return false;
    }

    // Allow this user-flippable flag to enable the feature.
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CONTEXTUAL_SEARCH)) {
        return true;
    }

    // Allow disabling the feature remotely.
    if (getBooleanParam(DISABLED_PARAM)) {
        return false;
    }

    return true;
}
 
Example 17
Source Project: delion   Source File: ChromeMediaRouter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Starts background monitoring for available media sinks compatible with the given
 * |sourceUrn| if the device is in a state that allows it.
 * @param sourceId a URL to use for filtering of the available media sinks
 * @return whether the monitoring started (ie. was allowed).
 */
@CalledByNative
public boolean startObservingMediaSinks(String sourceId) {
    if (SysUtils.isLowEndDevice()) return false;

    for (MediaRouteProvider provider : mRouteProviders) {
        provider.startObservingMediaSinks(sourceId);
    }

    return true;
}
 
Example 18
Source Project: delion   Source File: ToolbarPhone.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void setTabSwitcherMode(
        boolean inTabSwitcherMode, boolean showToolbar, boolean delayAnimation) {
    if (mIsInTabSwitcherMode == inTabSwitcherMode) return;

    finishAnimations();

    mDelayingTabSwitcherAnimation = delayAnimation;

    if (inTabSwitcherMode) {
        if (mUrlFocusLayoutAnimator != null && mUrlFocusLayoutAnimator.isRunning()) {
            mUrlFocusLayoutAnimator.end();
            mUrlFocusLayoutAnimator = null;
            // After finishing the animation, force a re-layout of the location bar,
            // so that the final translation position is correct (since onMeasure updates
            // won't happen in tab switcher mode). crbug.com/518795.
            layoutLocationBar(getMeasuredWidth());
            updateUrlExpansionAnimation();
        }
        mNewTabButton.setEnabled(true);
        updateViewsForTabSwitcherMode(true);
        mTabSwitcherModeAnimation = createEnterTabSwitcherModeAnimation();
    } else {
        if (!mDelayingTabSwitcherAnimation) {
            mTabSwitcherModeAnimation = createExitTabSwitcherAnimation(showToolbar);
        }
        mUIAnimatingTabSwitcherTransition = true;
    }

    mAnimateNormalToolbar = showToolbar;
    mIsInTabSwitcherMode = inTabSwitcherMode;
    if (mTabSwitcherModeAnimation != null) mTabSwitcherModeAnimation.start();

    if (SysUtils.isLowEndDevice()) finishAnimations();

    postInvalidateOnAnimation();
}
 
Example 19
Source Project: AndroidChromium   Source File: ReaderModeManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether Reader mode and its new UI are enabled.
 * @param context A context
 */
public static boolean isEnabled(Context context) {
    if (context == null) return false;

    boolean enabled = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_DOM_DISTILLER)
            && !CommandLine.getInstance().hasSwitch(
                    ChromeSwitches.DISABLE_READER_MODE_BOTTOM_BAR)
            && !DeviceFormFactor.isTablet(context)
            && DomDistillerTabUtils.isDistillerHeuristicsEnabled()
            && !SysUtils.isLowEndDevice();
    return enabled;
}
 
Example 20
Source Project: AndroidChromium   Source File: DeviceClassManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
        mDisableDomainReliability = true;
    } else {
        mEnableSnapshots = true;
        mEnableLayerDecorationCache = true;
        mEnableAccessibilityLayout = false;
        mEnableAnimations = true;
        mEnablePrerendering = true;
        mEnableToolbarSwipe = true;
        mDisableDomainReliability = false;
    }

    if (DeviceFormFactor.isTablet(ContextUtils.getApplicationContext())) {
        mEnableAccessibilityLayout = false;
    }

    // Flag based configurations.
    CommandLine commandLine = CommandLine.getInstance();
    mEnableAccessibilityLayout |= commandLine
            .hasSwitch(ChromeSwitches.ENABLE_ACCESSIBILITY_TAB_SWITCHER);
    mEnableFullscreen =
            !commandLine.hasSwitch(ChromeSwitches.DISABLE_FULLSCREEN);

    // Related features.
    if (mEnableAccessibilityLayout) {
        mEnableAnimations = false;
    }
}
 
Example 21
Source Project: AndroidChromium   Source File: BackgroundOfflinerTask.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Triggers processing of background offlining requests.  This is called when
 * system conditions are appropriate for background offlining, typically from the
 * GcmTaskService onRunTask() method.  In response, we will start the
 * task processing by passing the call along to the C++ RequestCoordinator.
 * Also starts UMA collection.
 *
 * @returns true for success
 */
public boolean startBackgroundRequests(Context context, Bundle bundle,
                                       ChromeBackgroundServiceWaiter waiter) {
    // Set up backup scheduled task in case processing is killed before RequestCoordinator
    // has a chance to reschedule base on remaining work.
    TriggerConditions previousTriggerConditions =
            TaskExtrasPacker.unpackTriggerConditionsFromBundle(bundle);
    BackgroundScheduler.backupSchedule(context, previousTriggerConditions, DEFER_START_SECONDS);

    DeviceConditions currentConditions = OfflinePageUtils.getDeviceConditions(context);
    if (!currentConditions.isPowerConnected()
            && currentConditions.getBatteryPercentage()
                    < previousTriggerConditions.getMinimumBatteryPercentage()) {
        Log.d(TAG, "Battery percentage is lower than minimum to start processing");
        return false;
    }

    if (SysUtils.isLowEndDevice() && ApplicationStatus.hasVisibleActivities()) {
        Log.d(TAG, "Application visible on low-end device so deferring background processing");
        return false;
    }

    // Now initiate processing.
    processBackgroundRequests(bundle, currentConditions, waiter);

    // Gather UMA data to measure how often the user's machine is amenable to background
    // loading when we wake to do a task.
    long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bundle);
    OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis);

    return true;
}
 
Example 22
Source Project: AndroidChromium   Source File: DeferredStartupHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void startModerateBindingManagementIfNeeded() {
    // Moderate binding doesn't apply to low end devices.
    if (SysUtils.isLowEndDevice()) return;

    boolean moderateBindingTillBackgrounded =
            FieldTrialList.findFullName("ModerateBindingOnBackgroundTabCreation")
                    .equals("Enabled");
    ChildProcessLauncher.startModerateBindingManagement(
            mAppContext, moderateBindingTillBackgrounded);
}
 
Example 23
Source Project: AndroidChromium   Source File: CustomTabsConnection.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Starts as much as possible in anticipation of a future navigation.
 *
 * @param mayCreatesparewebcontents true if warmup() can create a spare renderer.
 * @return true for success.
 */
private boolean warmupInternal(final boolean mayCreateSpareWebContents) {
    // Here and in mayLaunchUrl(), don't do expensive work for background applications.
    if (!isCallerForegroundOrSelf()) return false;
    mClientManager.recordUidHasCalledWarmup(Binder.getCallingUid());
    final boolean initialized = !mWarmupHasBeenCalled.compareAndSet(false, true);
    final int uid = Binder.getCallingUid();
    // The call is non-blocking and this must execute on the UI thread, post a task.
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (!initialized) initializeBrowser(mApplication);
            if (mayCreateSpareWebContents && mSpeculation == null
                    && !SysUtils.isLowEndDevice()) {
                WarmupManager.getInstance().createSpareWebContents();
                // The throttling database uses shared preferences, that can cause a StrictMode
                // violation on the first access. Make sure that this access is not in
                // mayLauchUrl.
                RequestThrottler.getForUid(mApplication, uid);

                Profile profile = Profile.getLastUsedProfile();
                new ResourcePrefetchPredictor(profile).startInitialization();
            }
            mWarmupHasBeenFinished.set(true);
        }
    });
    return true;
}
 
Example 24
Source Project: AndroidChromium   Source File: ChromeMediaRouter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Starts background monitoring for available media sinks compatible with the given
 * |sourceUrn| if the device is in a state that allows it.
 * @param sourceId a URL to use for filtering of the available media sinks
 * @return whether the monitoring started (ie. was allowed).
 */
@CalledByNative
public boolean startObservingMediaSinks(String sourceId) {
    if (SysUtils.isLowEndDevice()) return false;

    for (MediaRouteProvider provider : mRouteProviders) {
        provider.startObservingMediaSinks(sourceId);
    }

    return true;
}
 
Example 25
Source Project: 365browser   Source File: ReaderModeManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether Reader mode and its new UI are enabled.
 * @param context A context
 */
public static boolean isEnabled(Context context) {
    if (context == null) return false;

    boolean enabled = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_DOM_DISTILLER)
            && !CommandLine.getInstance().hasSwitch(
                       ChromeSwitches.DISABLE_READER_MODE_BOTTOM_BAR)
            && !DeviceFormFactor.isTablet()
            && DomDistillerTabUtils.isDistillerHeuristicsEnabled()
            && !SysUtils.isLowEndDevice();
    return enabled;
}
 
Example 26
Source Project: 365browser   Source File: ChromeBrowserInitializer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This is needed for device class manager which depends on commandline args that are
 * initialized in preInflationStartup()
 */
private void preInflationStartupDone() {
    // Domain reliability uses significant enough memory that we should disable it on low memory
    // devices for now.
    // TODO(zbowling): remove this after domain reliability is refactored. (crbug.com/495342)
    if (SysUtils.isLowEndDevice()) {
        CommandLine.getInstance().appendSwitch(ChromeSwitches.DISABLE_DOMAIN_RELIABILITY);
    }
}
 
Example 27
Source Project: 365browser   Source File: MediaNotificationManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @returns The ideal size of the media image.
 */
public static int getIdealMediaImageSize() {
    if (SysUtils.isLowEndDevice()) {
        return LOW_IMAGE_SIZE_PX;
    }
    return HIGH_IMAGE_SIZE_PX;
}
 
Example 28
Source Project: 365browser   Source File: ChromeMediaRouter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Starts background monitoring for available media sinks compatible with the given
 * |sourceUrn| if the device is in a state that allows it.
 * @param sourceId a URL to use for filtering of the available media sinks
 * @return whether the monitoring started (ie. was allowed).
 */
@CalledByNative
public boolean startObservingMediaSinks(String sourceId) {
    if (SysUtils.isLowEndDevice()) return false;

    for (MediaRouteProvider provider : mRouteProviders) {
        provider.startObservingMediaSinks(sourceId);
    }

    return true;
}
 
Example 29
/**
 * Registers a freshly started child process. On low-memory devices this will also drop the
 * oom bindings of the last process that was oom-bound. We can do that, because every time a
 * connection is created on the low-end, it is used in foreground (no prerendering, no
 * loading of tabs opened in background).
 * @param pid handle of the process.
 */
void addNewConnection(int pid) {
    synchronized (mCountLock) {
        if (SysUtils.isLowEndDevice() && mLastOomPid >= 0) {
            dropOomBindings(mLastOomPid);
        }
        // This will reset the previous entry for the pid in the unlikely event of the OS
        // reusing renderer pids.
        mOomBindingCount.put(pid, 0);
        // Every new connection is bound with initial oom binding.
        incrementOomCount(pid);
    }
}
 
Example 30
/**
 * Unbind a high priority process which was previous bound with bindAsHighPriority.
 * @param pid The process handle of the service.
 */
void unbindAsHighPriority(final int pid) {
    final ChildProcessConnection connection = sServiceMap.get(pid);
    if (connection == null) {
        LogPidWarning(pid, "Tried to unbind non-existent connection");
        return;
    }
    if (!connection.isStrongBindingBound()) return;

    // This runnable performs the actual unbinding. It will be executed synchronously when
    // on low-end devices and posted with a delay otherwise.
    Runnable doUnbind = new Runnable() {
        @Override
        public void run() {
            synchronized (mCountLock) {
                if (connection.isStrongBindingBound()) {
                    decrementOomCount(pid);
                    connection.detachAsActive();
                }
            }
        }
    };

    if (SysUtils.isLowEndDevice()) {
        doUnbind.run();
    } else {
        ThreadUtils.postOnUiThreadDelayed(doUnbind, DETACH_AS_ACTIVE_HIGH_END_DELAY_MILLIS);
    }
}