/** * 运行环境判断(生产加固,对应 CLAUDE.md 附录 B 红线)。 * * isDebug():是否为 debug 包(debug 签名)。用于守卫仅 debug 可开的能力, * 如 setWebDebuggingAccess——release 包 appInfo.debug 为 false,自动关闭远程调试。 * 等价 BuildProfile.DEBUG 的意图,但用运行时签名信息判断、不依赖构建期字段注入。 */ import { bundleManager } from '@kit.AbilityKit'; export class AppEnv { private static debugCache: boolean | undefined = undefined; static isDebug(): boolean { if (AppEnv.debugCache === undefined) { try { const info = bundleManager.getBundleInfoForSelfSync( bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION); AppEnv.debugCache = info.appInfo.debug; } catch (e) { AppEnv.debugCache = false; // 取不到时保守按 release(不开调试) } } return AppEnv.debugCache; } }