import { LoadScheduler } from '../../mx/module/res/LoadScheduler'; import { DeviceCapability } from './DeviceCapability'; import { MEMORY_PROFILE, MemoryTierConfig, MemoryTierId } from './memory-profile.json'; import { ThermalProfile } from './ThermalProfile'; /** Boot 读取:按运行时设备能力选 Tier,驱动预载并行 / Tab 卸载 / 降档开关 */ export class MemoryProfile { private static _tier: MemoryTierId = MEMORY_PROFILE.defaultTier; private static _config: MemoryTierConfig = MEMORY_PROFILE.tiers[MEMORY_PROFILE.defaultTier]; private static _resolved = false; static resolve(): void { if (this._resolved) return; this._resolved = true; DeviceCapability.resolve(); this._tier = DeviceCapability.memoryTier; this._config = MEMORY_PROFILE.tiers[this._tier] ?? MEMORY_PROFILE.tiers[MEMORY_PROFILE.defaultTier]; } static get tier(): MemoryTierId { this.resolve(); return this._tier; } static get current(): MemoryTierConfig { this.resolve(); return this._config; } /** 将档位写入 LoadScheduler(Boot 后调用;切档后可再调) */ static applyLoadPolicy(): void { this.resolve(); const cfg = this.current; const scheduler = LoadScheduler.getInstance(); scheduler.setSilentMaxConcurrent(cfg.silentPreloadParallel); scheduler.setSilentBudgetMs(cfg.silentBudgetMs); scheduler.setSilentGapMs(cfg.silentDownloadGapMs); ThermalProfile.resolve(); scheduler.setSilentBudgetScale(ThermalProfile.current.hallLoadBudgetScale); scheduler.setBackgroundBudgetScale(ThermalProfile.current.hallLoadBudgetScale); } /** 平台探测完成后若档位变化,重载 LoadScheduler 策略 */ static reapplyAfterProbe(): void { const prev = this._tier; this._resolved = false; this.resolve(); if (this._tier === prev) return; this.applyLoadPolicy(); } }