Android O 版本(Android 8.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 中的较小值作为存储空间不足 提醒的阀值。

你可能感兴趣的:(Android O 版本(Android 8.0) 存储空间不足时提醒)