Java Code Examples for android.app.ActivityManager#isLowRamDeviceStatic()

The following examples show how to use android.app.ActivityManager#isLowRamDeviceStatic() . 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 File: RecentTasks.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Loads the parameters from the system resources.
 */
@VisibleForTesting
void loadParametersFromResources(Resources res) {
    if (ActivityManager.isLowRamDeviceStatic()) {
        mMinNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_minNumVisibleRecentTasks_lowRam);
        mMaxNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_maxNumVisibleRecentTasks_lowRam);
    } else if (SystemProperties.getBoolean("ro.recents.grid", false)) {
        mMinNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_minNumVisibleRecentTasks_grid);
        mMaxNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_maxNumVisibleRecentTasks_grid);
    } else {
        mMinNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_minNumVisibleRecentTasks);
        mMaxNumVisibleTasks = res.getInteger(
                com.android.internal.R.integer.config_maxNumVisibleRecentTasks);
    }
    final int sessionDurationHrs = res.getInteger(
            com.android.internal.R.integer.config_activeTaskDurationHours);
    mActiveTasksSessionDurationMs = (sessionDurationHrs > 0)
            ? TimeUnit.HOURS.toMillis(sessionDurationHrs)
            : -1;
}
 
Example 2
Source File: SystemImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isMultiProcessDefaultEnabled() {
    // Multiprocess is enabled for all 64-bit devices, since the ability to run the renderer
    // process in 32-bit when it's a separate process typically results in a net memory saving.
    // Multiprocess is also enabled for 32-bit devices unless they report they are "low ram".
    return Build.SUPPORTED_64_BIT_ABIS.length > 0 || !ActivityManager.isLowRamDeviceStatic();
}
 
Example 3
Source File: TaskSnapshotController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * If we are not allowed to take a real screenshot, this attempts to represent the app as best
 * as possible by using the theme's window background.
 */
private TaskSnapshot drawAppThemeSnapshot(Task task) {
    final AppWindowToken topChild = task.getTopChild();
    if (topChild == null) {
        return null;
    }
    final WindowState mainWindow = topChild.findMainWindow();
    if (mainWindow == null) {
        return null;
    }
    final int color = ColorUtils.setAlphaComponent(
            task.getTaskDescription().getBackgroundColor(), 255);
    final int statusBarColor = task.getTaskDescription().getStatusBarColor();
    final int navigationBarColor = task.getTaskDescription().getNavigationBarColor();
    final LayoutParams attrs = mainWindow.getAttrs();
    final SystemBarBackgroundPainter decorPainter = new SystemBarBackgroundPainter(attrs.flags,
            attrs.privateFlags, attrs.systemUiVisibility, statusBarColor, navigationBarColor);
    final int width = mainWindow.getFrameLw().width();
    final int height = mainWindow.getFrameLw().height();

    final RenderNode node = RenderNode.create("TaskSnapshotController", null);
    node.setLeftTopRightBottom(0, 0, width, height);
    node.setClipToBounds(false);
    final DisplayListCanvas c = node.start(width, height);
    c.drawColor(color);
    decorPainter.setInsets(mainWindow.mContentInsets, mainWindow.mStableInsets);
    decorPainter.drawDecors(c, null /* statusBarExcludeFrame */);
    node.end(c);
    final Bitmap hwBitmap = ThreadedRenderer.createHardwareBitmap(node, width, height);
    if (hwBitmap == null) {
        return null;
    }
    // Note, the app theme snapshot is never translucent because we enforce a non-translucent
    // color above
    return new TaskSnapshot(hwBitmap.createGraphicBufferHandle(),
            topChild.getConfiguration().orientation, mainWindow.mStableInsets,
            ActivityManager.isLowRamDeviceStatic() /* reduced */, 1.0f /* scale */,
            false /* isRealSnapshot */, task.getWindowingMode(), getSystemUiVisibility(task),
            false);
}
 
Example 4
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne) {
    checkManageUsersPermission("check if more managed profiles can be added.");
    if (ActivityManager.isLowRamDeviceStatic()) {
        return false;
    }
    if (!mContext.getPackageManager().hasSystemFeature(
            PackageManager.FEATURE_MANAGED_USERS)) {
        return false;
    }
    // Limit number of managed profiles that can be created
    final int managedProfilesCount = getProfiles(userId, false).size() - 1;
    final int profilesRemovedCount = managedProfilesCount > 0 && allowedToRemoveOne ? 1 : 0;
    if (managedProfilesCount - profilesRemovedCount >= getMaxManagedProfiles()) {
        return false;
    }
    synchronized(mUsersLock) {
        UserInfo userInfo = getUserInfoLU(userId);
        if (userInfo == null || !userInfo.canHaveProfile()) {
            return false;
        }
        int usersCountAfterRemoving = getAliveUsersExcludingGuestsCountLU()
                - profilesRemovedCount;
        // We allow creating a managed profile in the special case where there is only one user.
        return usersCountAfterRemoving  == 1
                || usersCountAfterRemoving < UserManager.getMaxSupportedUsers();
    }
}
 
Example 5
Source File: ActiveServices.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public ActiveServices(ActivityManagerService service) {
    mAm = service;
    int maxBg = 0;
    try {
        maxBg = Integer.parseInt(SystemProperties.get("ro.config.max_starting_bg", "0"));
    } catch(RuntimeException e) {
    }
    mMaxStartingBackground = maxBg > 0
            ? maxBg : ActivityManager.isLowRamDeviceStatic() ? 1 : 8;
}
 
Example 6
Source File: UserManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the maximum number of users that can be created on this device. A return value
 * of 1 means that it is a single user device.
 * @hide
 * @return a value greater than or equal to 1
 */
public static int getMaxSupportedUsers() {
    // Don't allow multiple users on certain builds
    if (android.os.Build.ID.startsWith("JVP")) return 1;
    if (ActivityManager.isLowRamDeviceStatic()) {
        // Low-ram devices are Svelte. Most of the time they don't get multi-user.
        if ((Resources.getSystem().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK)
                != Configuration.UI_MODE_TYPE_TELEVISION) {
            return 1;
        }
    }
    return SystemProperties.getInt("fw.max_users",
            Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers));
}
 
Example 7
Source File: SQLiteDatabase.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private SQLiteDatabase(final String path, final int openFlags,
        CursorFactory cursorFactory, DatabaseErrorHandler errorHandler,
        int lookasideSlotSize, int lookasideSlotCount, long idleConnectionTimeoutMs,
        String journalMode, String syncMode) {
    mCursorFactory = cursorFactory;
    mErrorHandler = errorHandler != null ? errorHandler : new DefaultDatabaseErrorHandler();
    mConfigurationLocked = new SQLiteDatabaseConfiguration(path, openFlags);
    mConfigurationLocked.lookasideSlotSize = lookasideSlotSize;
    mConfigurationLocked.lookasideSlotCount = lookasideSlotCount;
    // Disable lookaside allocator on low-RAM devices
    if (ActivityManager.isLowRamDeviceStatic()) {
        mConfigurationLocked.lookasideSlotCount = 0;
        mConfigurationLocked.lookasideSlotSize = 0;
    }
    long effectiveTimeoutMs = Long.MAX_VALUE;
    // Never close idle connections for in-memory databases
    if (!mConfigurationLocked.isInMemoryDb()) {
        // First, check app-specific value. Otherwise use defaults
        // -1 in idleConnectionTimeoutMs indicates unset value
        if (idleConnectionTimeoutMs >= 0) {
            effectiveTimeoutMs = idleConnectionTimeoutMs;
        } else if (DEBUG_CLOSE_IDLE_CONNECTIONS) {
            effectiveTimeoutMs = SQLiteGlobal.getIdleConnectionTimeout();
        }
    }
    mConfigurationLocked.idleConnectionTimeoutMs = effectiveTimeoutMs;
    mConfigurationLocked.journalMode = journalMode;
    mConfigurationLocked.syncMode = syncMode;
    if (!SQLiteGlobal.isCompatibilityWalSupported() || (
            SQLiteCompatibilityWalFlags.areFlagsSet() && !SQLiteCompatibilityWalFlags
                    .isCompatibilityWalSupported())) {
        mConfigurationLocked.openFlags |= DISABLE_COMPATIBILITY_WAL;
    }
}
 
Example 8
Source File: TaskSnapshotController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private TaskSnapshot snapshotTask(Task task) {
    final AppWindowToken top = task.getTopChild();
    if (top == null) {
        return null;
    }
    final WindowState mainWindow = top.findMainWindow();
    if (mainWindow == null) {
        return null;
    }
    if (!mService.mPolicy.isScreenOn()) {
        if (DEBUG_SCREENSHOT) {
            Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
        }
        return null;
    }
    if (task.getSurfaceControl() == null) {
        return null;
    }

    if (top.hasCommittedReparentToAnimationLeash()) {
        if (DEBUG_SCREENSHOT) {
            Slog.w(TAG_WM, "Failed to take screenshot. App is animating " + top);
        }
        return null;
    }

    final boolean hasVisibleChild = top.forAllWindows(
            // Ensure at least one window for the top app is visible before attempting to take
            // a screenshot. Visible here means that the WSA surface is shown and has an alpha
            // greater than 0.
            ws -> (ws.mAppToken == null || ws.mAppToken.isSurfaceShowing())
                    && ws.mWinAnimator != null && ws.mWinAnimator.getShown()
                    && ws.mWinAnimator.mLastAlpha > 0f, true);

    if (!hasVisibleChild) {
        if (DEBUG_SCREENSHOT) {
            Slog.w(TAG_WM, "Failed to take screenshot. No visible windows for " + task);
        }
        return null;
    }

    final boolean isLowRamDevice = ActivityManager.isLowRamDeviceStatic();
    final float scaleFraction = isLowRamDevice ? REDUCED_SCALE : 1f;
    task.getBounds(mTmpRect);
    mTmpRect.offsetTo(0, 0);

    final GraphicBuffer buffer = SurfaceControl.captureLayers(
            task.getSurfaceControl().getHandle(), mTmpRect, scaleFraction);
    final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE;
    if (buffer == null || buffer.getWidth() <= 1 || buffer.getHeight() <= 1) {
        if (DEBUG_SCREENSHOT) {
            Slog.w(TAG_WM, "Failed to take screenshot for " + task);
        }
        return null;
    }
    return new TaskSnapshot(buffer, top.getConfiguration().orientation,
            getInsets(mainWindow), isLowRamDevice /* reduced */, scaleFraction /* scale */,
            true /* isRealSnapshot */, task.getWindowingMode(), getSystemUiVisibility(task),
            !top.fillsParent() || isWindowTranslucent);
}
 
Example 9
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
boolean injectIsLowRamDevice() {
    return ActivityManager.isLowRamDeviceStatic();
}