android storage_state

发布于:2025-03-12 ⋅ 阅读:(71) ⋅ 点赞:(0)

storage_state是android用来输出磁盘状态的event类型的日志,下面我们看下它的定义和使用以及磁盘状态介绍。

定义

# ---------------------------
# DeviceStorageMonitorService.java
# ---------------------------
# Storage volume state and usable space in bytes
2749 storage_state (uuid|3),(old_state|1),(new_state|1),(usable|2),(total|2)
03-03 15:16:30.006  1000  2874  3911 I storage_state: [41217664-9172-527a-b3d5-edabb50a7d69,1,1,198541312,501777104896]
03-03 15:19:31.244  1000  2874  3911 I storage_state: [41217664-9172-527a-b3d5-edabb50a7d69,1,1,11362304,501777104896]

storage_state的参数分别是uuid、之前的状态、现在的状态、可用磁盘空间大小,总的磁盘空间大小。

使用

            // Log whenever we notice drastic storage changes
            if ((Math.abs(state.lastUsableBytes - usableBytes) > DEFAULT_LOG_DELTA_BYTES)
                    || oldLevel != newLevel) {
                EventLogTags.writeStorageState(uuid.toString(), oldLevel, newLevel,
                        usableBytes, totalBytes);
                state.lastUsableBytes = usableBytes;
            }

日志的打印需要满足两个条件的至少一个即可,第一个就是上次监控到的可用空间比现在监控到的可用空间大于64M,第二个就是上次监控到的磁盘状态与现在的磁盘状态不相同。

磁盘状态

        private static final int LEVEL_UNKNOWN = -1;
        private static final int LEVEL_NORMAL = 0;
        private static final int LEVEL_LOW = 1;
        private static final int LEVEL_FULL = 2;
adb shell dumpsys devicestoragemonitor
		Known volumes:
  		Default:
    		level=NORMAL lastUsableBytes=997076271104 
    		lowBytes=524288000 fullBytes=1048576
    		path=/data

		mSeq=1 mForceState=UNKNOWN
            int newLevel;
            if (mForceLevel != State.LEVEL_UNKNOWN) {
                // When in testing mode, use unknown old level to force sending
                // of any relevant broadcasts.
                oldLevel = State.LEVEL_UNKNOWN;
                newLevel = mForceLevel;
            } else if (usableBytes <= fullBytes) {
                newLevel = State.LEVEL_FULL;
            } else if (usableBytes <= lowBytes) {
                newLevel = State.LEVEL_LOW;
            } else if (StorageManager.UUID_DEFAULT.equals(uuid)
                    && usableBytes < BOOT_IMAGE_STORAGE_REQUIREMENT) {
                newLevel = State.LEVEL_LOW;
            } else {
                newLevel = State.LEVEL_NORMAL;
            }

LEVEL_FULL: 小于等于1M
LEVEL_LOW:小于等于524M
LEVEL_NORMAL:大于524M


网站公告

今日签到

点亮在社区的每一天
去签到