Android O 版本(Android 8.0) 存储空间不足

2020-11-02  本文已影响0人  荣智超

在 frameworks/base/core/java/android/os/storage/StorageManager.java 中,

 /**
 * Return the number of available bytes at which the given path is
 * considered running low on storage.
 *
 * @hide
 */
public long getStorageLowBytes(File path) {
    final long lowPercent = Settings.Global.getInt(mResolver,
            Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE, DEFAULT_THRESHOLD_PERCENTAGE);
    final long lowBytes = (path.getTotalSpace() * lowPercent) / 100;

    final long maxLowBytes = Settings.Global.getLong(mResolver,
            Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES, DEFAULT_THRESHOLD_MAX_BYTES);

    return Math.min(lowBytes, maxLowBytes);
}

通过getStorageLowBytes()方法获取低内存不足提醒的阀值。该方法是取lowBytes 和 maxLowBytes 中的较小值。

private static final int DEFAULT_THRESHOLD_PERCENTAGE = 5;
private static final long DEFAULT_THRESHOLD_MAX_BYTES = 500 * MB_IN_BYTES;

在StorageManager.java 中可以看到 这两个值的定义,所以是取内存的5% 和 500MB 中的较小值作为存储空间不足 提醒的阀值。

上一篇下一篇

猜你喜欢

热点阅读