更新记录

1.0.0(2026-06-15)

  • 首版提供 Android 真前台服务保活、常驻通知、通知动作、开机恢复、包更新恢复、屏幕唤醒恢复、AlarmManager 看门狗、JobScheduler 兜底守护、WakeLock、WiFiLock、静音音频辅助策略和稳定后台任务定时器。
  • 提供保活权限诊断、系统限制诊断、通知通道体检、前台服务合规体检、厂商 ROM 指引、厂商设置验收审计、保活准备度报告、保活巡检、保活证据包、事件时间线、长跑观测报告和验收报告。
  • 提供一键保活套件、一键保活策略预设、一键自愈守护、自愈闭环证据、自愈证据聚合、自愈后复测计划、恢复证据快照、保活证据会话、交付验收计划、售后/交付支持报告和交付证据导出能力。
  • iOS 提供后台配置指引、后台套件、轻量运行态心跳和报告;Harmony 提供后台配置指引、后台套件、轻量运行态心跳和能力矩阵;Web 与小程序提供明确降级能力。
  • README 按插件功能和从简单到复杂的演示示例组织,客户可按“查询能力、发送心跳、启动基础保活、使用预设、注册后台任务、一键套件与交付诊断”的顺序接入。

平台兼容性

uni-app(4.84)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - - - - - - -

uni-app x(4.84)

Chrome Safari Android iOS 鸿蒙 微信小程序

lizhao-app-keepalive

lizhao-app-keepalive 是纯 UTS 多端保活插件,用于在 uni-app / uni-app x 项目中接入 Android 真前台服务常驻、开机与包更新恢复、AlarmManager 看门狗、JobScheduler 兜底守护、WakeLock / WiFiLock、稳定后台任务、静音音频辅助策略、厂商 ROM 设置指引、保活诊断报告、验收证据包、自愈复测计划,以及 iOS / Harmony / Web / 小程序的明确降级能力。插件内置心跳、活性评分、资源快照和事件时间线,便于把后台运行状态、系统限制和交付验收结果直接展示给业务方或客户。

核心功能

  • Android 使用真实 Service + startForeground() 承载常驻通知,不再只是普通通知或页面计时器。
  • startKeepAlive 成功前会先确认前台服务启动链路可用;启动失败会触发 fail,不伪造保活成功。
  • Android 支持开机恢复、包更新恢复、屏幕唤醒恢复、AlarmManager 看门狗和策略持久化,冷启动广播也能按用户配置恢复。
  • Android 新增 JobScheduler 兜底守护,可在前台服务和 AlarmManager 之外增加系统允许的周期性恢复链路,并通过 getJobSchedulerGuardianStatus 输出 scheduled / runCount / reason
  • Android 常驻通知内置动作按钮,可直接停止保活、重启保活、打开保活设置和电源管理,动作会回传 notificationAction 事件。
  • Android 提供前台服务合规体检 getKeepAliveForegroundServiceComplianceReport,可检查 targetSdkVersion、Android 12/13/14+ 前台服务启动风险、前台服务类型权限、通知权限和通知通道可展示条件。
  • Android 提供插件市场发布体检报告 getKeepAliveMarketReadinessReport,把能力覆盖、功能亮点、推荐市场文案、合规边界、验收 API 路径和 Markdown 证据聚合为一份上架/售前/交付报告。
  • Android 提供交付报告一键复制 copyKeepAliveDeliveryReport,使用系统 ClipboardManager + ClipData 把市场发布体检、售后支持报告、一键终极体检或交付验收计划的 Markdown 写入剪贴板,便于插件市场审核、售前演示和客户工单直接粘贴。
  • Android 提供交付证据文件导出 exportKeepAliveDeliveryEvidence,把市场发布体检、售后支持报告、一键终极体检或交付验收计划导出为应用私有目录中的 Markdown/JSON 文件,便于插件市场审核、售前演示和客户工单作为附件归档。
  • Android 提供交付证据归档包导出 exportKeepAliveDeliveryArchive,使用应用私有目录生成 ZIP 归档包,内含 manifest.json / market.md / support.md / ultimate.md / acceptance-plan.md,便于插件市场审核、售前演示、客户验收和售后工单一次性上传。
  • Android 提供保活证据会话 startKeepAliveEvidenceSession / getKeepAliveEvidenceSession / finishKeepAliveEvidenceSession,通过 evidence-session 能力把市场体检、自愈复测计划、售后支持报告、事件时间线和交付归档包串成 KeepAliveEvidenceSession,便于同一轮验收留痕。
  • 发布包质量门禁 scripts\check-lizhao-app-keepalive-release-gate.js 会在上架前检查 package、README、changelog、验收清单、Android Manifest、运行时 API、平台 fallback 和市场发布体检能力,避免卖点、文档或生成物漏项。
  • Android 提供通知通道体检 getKeepAliveNotificationChannelReport,可检查通知总开关、Android 8+ 通知通道是否存在、通道重要级别是否被关闭,以及前台服务通知是否具备可展示条件。
  • Android 可选 WiFi 锁,wifiLockEnabled 开启后使用高性能 WiFiLock 提升后台网络长连稳定性。
  • Android 内置保活权限诊断,可检查/引导 POST_NOTIFICATIONS 通知权限、SCHEDULE_EXACT_ALARM 精确闹钟、电池优化白名单和厂商自启动设置。
  • Android 提供厂商 ROM 指引 getKeepAliveVendorGuide,可识别小米、华为、荣耀、OPPO、vivo、魅族、三星等系统,并返回自启动、后台运行、电池优化和通知设置步骤。
  • Android 提供厂商 ROM 设置验收审计与下一项设置导航 getKeepAliveVendorSettingsAudit / openNextKeepAliveVendorSetting / setKeepAliveVendorSettingState,把通知、电池优化、自启动、后台运行、最近任务锁定等设置变成可记录、可跳转、可复测、可交付的结构化报告。
  • Android 提供任务划掉恢复闭环 getKeepAliveTaskRemovedRecoveryReport,前台服务声明 stopWithTask=false 并覆盖 onTaskRemoved,用户从最近任务划掉应用后会记录 taskRemoved 事件、持久化计数,并重排 Watchdog、JobScheduler、稳定定时器和静音音频等合法恢复链路。
  • Android 提供服务销毁自恢复闭环 getKeepAliveServiceDestroyRecoveryReport,前台服务 onDestroy 会记录 serviceDestroy 事件、持久化销毁与重排次数,并在非显式停止且运行策略允许时重建 Watchdog、JobScheduler、稳定定时器和静音音频等链路。
  • Android 提供一键保活巡检 getKeepAliveHealthReport,聚合运行状态、权限、系统限制、评分和建议。
  • Android 提供保活准备度报告 getKeepAliveReadinessReport,聚合权限诊断、系统限制、厂商指引、策略预设和巡检评分,直接给出阻断项、推荐动作和下一步验收。
  • Android 提供保活证据包 getKeepAliveEvidencePack,聚合状态、能力矩阵、准备度、巡检、权限、系统限制、厂商指引、预设指引和后台任务统计,方便售后排障。
  • Android 提供保活巡航守护 startKeepAliveCruiseGuardian / getKeepAliveCruiseGuardianReport,运行期周期采样 aliveScore / readinessScore / healthScore / runScore,低于 lowScoreThreshold 时记录告警,并可选触发合法 autoHealKeepAlive
  • Android 提供一键终极体检 getKeepAliveUltimateReport,把基座自检、准备度、厂商 ROM 设置验收、下一项设置导航建议和支持报告聚合成一份 JSON 与 Markdown,适合插件市场演示、交付首检和售后排障。
  • Android 提供售后/交付支持报告 getKeepAliveSupportReport,把基座自检、诊断包、验收报告、长跑报告和事件时间线合并成一份 JSON 与 Markdown,便于插件市场演示、客户交付和售后工单。
  • Android 提供恢复证据快照 getKeepAliveRecoveryEvidenceSnapshot,把 taskRemovedRecoveryReport / serviceDestroyRecoveryReport / persistentEventTimeline / runReport 聚合成 KeepAliveRecoveryEvidenceSnapshot,输出 recoveryEvidenceSnapshot / evidenceItems / score / level / markdown,让客户能快速判断恢复链路是否已经形成可交付证据。
  • Android 提供自愈闭环证据 getKeepAliveAutoHealEvidenceLoop,通过 auto-heal-evidence-loop 能力把最近一次 autoHealKeepAlive 的动作、前后评分、人工确认项和 autoHealLoopId / persistedTotal / markdown 持久化到应用私有 SharedPreferences,便于售后复盘和交付验收。
  • Android 提供自愈证据聚合 auto-heal-report-aggregationgetKeepAliveSupportReport / getKeepAliveUltimateReport / getKeepAliveMarketReadinessReport 会内嵌 KeepAliveAutoHealEvidenceSummary,客户打开任一交付报告都能看到最近一次自愈闭环证据摘要。
  • Android 提供自愈后复测计划 getKeepAliveAutoHealRetestPlan,通过 auto-heal-retest-plan 能力把 autoHealEvidenceSummary、自愈闭环证据、交付验收计划、startKeepAliveSurvivalTest 长跑状态、恢复证据快照和 getKeepAliveSupportReport 串成 KeepAliveAutoHealRetestPlan,让客户按步骤完成一键自愈后的复测闭环。
  • Android 提供交付验收计划 getKeepAliveAcceptancePlan,按快速/标准/严格/插件市场档位输出 stages / adbCommands / passCriteria / evidenceFields / markdown,客户可以照计划完成真机、锁屏、息屏和厂商 ROM 复测。
  • Android 提供自定义基座完整性报告 getKeepAliveBaseIntegrityReport,聚合基座桥接、Manifest 类、前台服务、JobScheduler、通知权限、电池优化、诊断/验收/长跑报告和事件审计,适合重打基座后的第一步验收。
  • Android 提供持久化事件时间线与恢复审计 getKeepAliveEventTimeline / clearKeepAliveEventTimeline,记录前后台、通知动作、开机恢复、看门狗、JobScheduler、屏幕唤醒、心跳和任务事件,并通过 persistent-event-timeline 能力把最近 200 条审计事件写入应用私有 SharedPreferences,返回 persistentEventTimeline / storageKey / persistedTotal / restored 作为恢复证据。
  • Android 提供售后诊断包 getKeepAliveDiagnosticBundle,把状态、能力矩阵、准备度、巡检、证据包、自愈报告、JobScheduler、稳定定时器、静音音频、任务状态和生存力测试聚合为诊断 JSON。
  • Android 提供保活验收报告 getKeepAliveAcceptanceReport,把诊断包整理为通过、警告、失败、需人工确认的验收清单,便于交付验收和客户复测。
  • Android 提供长跑观测报告 getKeepAliveRunReport,把当前/最近一次生存力测试、验收报告和诊断包聚合成复测报告,适合重打自定义基座后的长跑验收。
  • Android 提供保活生存力测试 startKeepAliveSurvivalTest / getKeepAliveSurvivalTestStatus / stopKeepAliveSurvivalTest,按时间窗口采样 sampleCount / aliveScore / heartbeatDelta / taskFailureCount,输出 KeepAliveSurvivalTestReport 和证据包。
  • Android 提供一键自愈守护 autoHealKeepAlive / getKeepAliveAutoHealReport / getKeepAliveAutoHealEvidenceLoop,自动补齐预设、注册、前台服务、稳定定时器、JobScheduler 和默认任务,并输出自愈动作、前后评分、证据包和可恢复的闭环证据。
  • Android 提供一键保活套件 applyKeepAliveSuite,可一次完成策略预设、注册、启动前台服务、稳定定时器、默认巡检任务、证据包和下一步验收建议。
  • Android 提供一键保活策略预设 getKeepAlivePresetOptions / applyKeepAlivePreset / getKeepAlivePresetGuide,内置均衡保活、强保活、极限保活、媒体保活和任务保活。
  • Android 提供稳定后台任务定时器 startStableTimer,组合前台服务运行态定时器与 AlarmManager 兜底,适合后台轮询、设备巡检、心跳上报。
  • Android 提供后台任务守护 registerKeepAliveTask / setOnKeepAliveTaskListener / reportKeepAliveTaskResult,在前台服务心跳或稳定定时器 tick 中按任务间隔派发任务事件,并记录业务执行结果、成功次数、失败次数和连续失败次数。
  • Android 提供静音音频保活策略 startSilentAudio,在前台服务运行期间使用原生 AudioTrack 写入静音 PCM,并通过 setOnSilentAudioListenergetSilentAudioStatus 暴露状态。
  • Harmony 提供后台配置指引 getKeepAliveHarmonyGuide,明确 harmony-configs/entry/src/main/module.json5ohos.permission.KEEP_BACKGROUND_RUNNINGaudioPlaybackdataTransfer 的验收要求。
  • Harmony 提供鸿蒙后台套件 applyKeepAliveHarmonySuite / getKeepAliveHarmonyBackgroundReport,组合配置体检、轻量运行态心跳、状态报告和下一步验收建议,并通过 harmonyBackgroundSuite 标记能力。
  • iOS 提供后台配置指引与后台套件 getKeepAliveIosBackgroundGuide / applyKeepAliveIosBackgroundSuite / getKeepAliveIosBackgroundReport,围绕 Info.plistUIBackgroundModesaudio / fetch / processing、轻量心跳和验收报告形成闭环,并通过 iosBackgroundSuite 标记能力。
  • 内置心跳、活性评分、CPU/内存快照和平台能力矩阵,方便商业项目排查后台运行质量。
  • 多端统一 API,iOS/Harmony/Web/小程序明确返回 best-effort 或降级能力,避免客户误判系统限制。

支持平台

平台 是否支持 说明
uni-app Vue2/Vue3 可用
uni-app x App/Web/小程序可用
Android 保活证据会话、自愈后复测计划、自愈证据聚合、自愈闭环证据、通知通道体检、服务销毁自恢复、任务划掉恢复、一键终极体检报告、保活巡航守护、厂商 ROM 设置验收审计、交付验收计划、售后/交付支持报告、自定义基座完整性报告、事件时间线与恢复审计、长跑观测报告、保活验收报告、售后诊断包、一键自愈守护、一键保活套件、保活生存力测试、保活证据包、后台任务守护与执行结果回执、保活准备度报告、一键保活策略预设、真前台服务、常驻通知、通知动作、通知权限、精确闹钟、唤醒锁、WiFi 锁、稳定后台任务定时器、JobScheduler 兜底守护、静音音频保活策略、开机恢复、屏幕唤醒恢复、AlarmManager 看门狗、电池优化策略、厂商自启动设置、厂商 ROM 指引、保活巡检、状态观测
iOS iOS 后台套件、Info.plist/UIBackgroundModes 配置指引、轻量运行态心跳和报告;后台效果仍受 Apple 系统调度、后台刷新、低电量和审核策略约束
Harmony 鸿蒙后台套件、配置指引、轻量运行态心跳和能力矩阵;后台效果仍受 KEEP_BACKGROUND_RUNNINGaudioPlayback / dataTransfer、系统长时任务和审核策略约束
Web 轻量降级,不提供系统保活
微信小程序 轻量降级,不提供系统保活
支付宝小程序 轻量降级,不提供系统保活

安装与导入

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

目录结构

uni_modules/
└─ lizhao-app-keepalive/
   ├─ package.json
   ├─ readme.md
   ├─ changelog.md
   ├─ verification-checklist.md
   └─ utssdk/
      ├─ interface.uts
      ├─ unierror.uts
      ├─ index.uts
      ├─ app-android/
      ├─ app-ios/
      ├─ app-harmony/
      ├─ web/
      ├─ mp-weixin/
      └─ mp-alipay/

API 列表

  • 生命周期:registerunregisterstartKeepAlivestopKeepAlivepauseKeepAliveresumeKeepAliverebootrestartService
  • 状态查询:getStatusgetLaunchTypecheckAlivegetCpuMemoryInfogetCapabilities
  • 策略配置:setConfigsetPowerModesetAlwaysEnablesetAutoStartOnBootsetAlwaysKillServicesetOpenHigh
  • 通知配置:setNoticesetNotifaicationSoundEnablesetNotifaicationVibrateEnablesetNotificationIconRessetNotificationChannelIDsetForegroundServiceTypesetLargeIcon
  • 通知点击与动作:setNofificationClickStartPagesetNofificationClickStartPageCallBacksetNofificationClickStartActivitynotificationActionsEnabled
  • 监听器:setOnServiceStartListenersetOnServiceStopListenersetOnTimerListenersetOnStartCSystemTimerListenersetCanOpenAliveSettingssetOnAliveStartsetOnAliveStop
  • 高级能力:setScreenWakeLocksetWifiLocksetJobSchedulerGuardiangetJobSchedulerGuardianStatuswakeUpOnScreenOngetBatteryOptimizationStatusrequestIgnoreBatteryOptimizationopenAppSettingsopenAutoStartSettingsopenPowerManagementSettings
  • 策略预设:getKeepAlivePresetOptionsapplyKeepAlivePresetgetKeepAlivePresetGuide
  • 可观测能力:sendHeartbeatshowNotificationhideNotificationgetKeepAliveHealthReportgetKeepAliveReadinessReportgetKeepAliveEvidencePackstartKeepAliveCruiseGuardianstopKeepAliveCruiseGuardiangetKeepAliveCruiseGuardianStatusgetKeepAliveCruiseGuardianReportgetKeepAliveSupportReportgetKeepAliveTaskRemovedRecoveryReportgetKeepAliveServiceDestroyRecoveryReportgetKeepAliveNotificationChannelReportgetKeepAliveForegroundServiceComplianceReportgetKeepAliveMarketReadinessReportcopyKeepAliveDeliveryReportexportKeepAliveDeliveryEvidenceexportKeepAliveDeliveryArchivestartKeepAliveEvidenceSessiongetKeepAliveEvidenceSessionfinishKeepAliveEvidenceSessiongetKeepAliveAcceptancePlangetKeepAliveAutoHealRetestPlangetKeepAliveBaseIntegrityReportgetKeepAliveEventTimelineclearKeepAliveEventTimelinegetKeepAliveDiagnosticBundlegetKeepAliveAcceptanceReportgetKeepAliveRunReportapplyKeepAliveSuiteautoHealKeepAlivegetKeepAliveAutoHealReportgetKeepAliveAutoHealEvidenceLoopstartKeepAliveSurvivalTestgetKeepAliveSurvivalTestStatusstopKeepAliveSurvivalTestgetKeepAliveVendorGuidegetKeepAliveHarmonyGuidegetKeepAliveHarmonyBackgroundStatusapplyKeepAliveHarmonySuitegetKeepAliveHarmonyBackgroundReportgetKeepAliveIosBackgroundGuidegetKeepAliveIosBackgroundStatusapplyKeepAliveIosBackgroundSuitegetKeepAliveIosBackgroundReportstartStableTimerstopStableTimergetStableTimerStatussetOnStableTimerListenerregisterKeepAliveTaskunregisterKeepAliveTaskgetKeepAliveTaskStatusesreportKeepAliveTaskResultsetOnKeepAliveTaskListenerstartSilentAudiostopSilentAudiogetSilentAudioStatussetOnSilentAudioListener
  • 常用别名:setNotificationSoundEnabledsetNotificationVibrateEnabledsetNotificationClickStartPagesetNotificationClickStartPageCallbacksetNotificationClickStartActivity

从简单到复杂的演示示例

1. 查询当前平台能力

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 第一步先查询能力矩阵,确认当前平台支持哪些保活、诊断和报告能力。
keepAlive.getCapabilities({
  success(res) {
    console.log('keepAlive capabilities', res)
  },
  fail(err) {
    console.log('getCapabilities failed', err)
  }
})

2. 发送一次业务心跳

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 心跳用于记录业务仍在运行,可配合诊断报告查看最近活跃时间。
keepAlive.sendHeartbeat({
  tag: 'home-page',
  payload: { scene: 'home' },
  success(res) {
    console.log('heartbeat sent', res)
  }
})

3. 启动基础保活

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// Android 会启动真前台服务;其它平台按能力矩阵返回降级结果。
keepAlive.register({
  config: {
    alwaysEnable: true,
    autoStartOnBoot: true,
    heartbeatIntervalMs: 10000,
    notificationActionsEnabled: true
  },
  success() {
    keepAlive.startKeepAlive({
      success(status) {
        console.log('keep alive started', status.running)
      },
      fail(err) {
        console.log('startKeepAlive failed', err)
      }
    })
  }
})

4. 使用预设增强策略

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 预设会统一写入前台服务、看门狗、JobScheduler、WakeLock 等推荐配置。
keepAlive.applyKeepAlivePreset({
  presetId: 'strong',
  startImmediately: true,
  success(res) {
    console.log('preset applied', res.presetId, res.config)
  },
  fail(err) {
    console.log('applyKeepAlivePreset failed', err)
  }
})

5. 注册稳定后台任务

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 业务在 listener 中执行自己的同步、巡检或上报逻辑,并回传执行结果。
keepAlive.setOnKeepAliveTaskListener({
  listener(event) {
    console.log('task fired', event.taskId, event.tick)
    keepAlive.reportKeepAliveTaskResult({
      taskId: event.taskId,
      result: 'success',
      message: '业务同步完成'
    })
  }
})

keepAlive.registerKeepAliveTask({
  task: {
    taskId: 'sync-order',
    title: '订单同步',
    intervalMs: 30000,
    runImmediately: true
  },
  success(list) {
    console.log('task registered', list)
  }
})

6. 一键套件与交付诊断

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 一键套件适合演示或首轮接入,会自动应用策略、启动服务并生成下一步验收建议。
keepAlive.applyKeepAliveSuite({
  presetId: 'strong',
  includeEvidencePack: true,
  success(report) {
    console.log('suite result', report.level, report.nextSteps)
  }
})

// 售后/交付支持报告用于输出当前运行态、系统限制和可复制 Markdown。
keepAlive.getKeepAliveSupportReport({
  includeMarkdown: true,
  success(report) {
    console.log('support report', report.level, report.markdown)
  }
})

核心参数(Register / SetConfig)

参数 类型 必填 说明 默认值 可选参数
options.config Partial 保活配置对象 alwaysEnable / autoStartOnBoot / alwaysKillService / openHigh / notice / notificationSoundEnabled / notificationVibrateEnabled / notificationIconRes / notificationChannelID / notificationActionsEnabled / openAliveSetting / foregroundServiceType / largeIcon / notificationClickStartPage / notificationClickStartPageCallback / notificationClickStartActivity / heartbeatIntervalMs / wakeLockEnabled / wifiLockEnabled / watchdogEnabled / watchdogIntervalMs / jobSchedulerEnabled / jobSchedulerIntervalMs / wakeUpOnScreenOnEnabled / silentAudioEnabled / powerMode
options.success function 成功回调
options.fail function 失败回调
options.complete function 完成回调

返回值(getStatus)

字段 类型 说明
registered boolean 是否已注册
running boolean 是否正在运行
paused boolean 是否暂停
runtimeStatus string 运行状态
launchType string 启动来源
config KeepAliveConfig 当前配置
capabilities KeepAliveCapabilities 能力矩阵
observation KeepAliveObservation 可观测指标
jobSchedulerStatus KeepAliveJobSchedulerStatus Android JobScheduler 兜底守护状态

返回值(getCapabilities)

字段 类型 说明
supported boolean 插件在当前平台是否可调用
sessionLevel string native / best-effort / fallback / none
keepAlive boolean 是否具备系统级保活能力
foregroundService boolean 是否支持前台服务
wakeLock boolean 是否支持唤醒锁
batteryOptimization boolean 是否支持电池优化白名单能力
notificationActions boolean 是否支持前台通知动作按钮
healthReport boolean 是否支持真实一键保活巡检
readinessReport boolean 是否支持保活准备度报告
evidencePack boolean 是否支持保活证据包
cruiseGuardian boolean 是否支持保活巡航守护
vendorSettingsAudit boolean 是否支持厂商 ROM 设置验收审计
supportReport boolean 是否支持售后/交付支持报告
acceptancePlan boolean 是否支持交付验收计划
ultimateReport boolean 是否支持一键终极体检报告
taskRemovedRecovery boolean 是否支持 Android 最近任务划掉恢复审计与报告
serviceDestroyRecovery boolean 是否支持 Android 前台服务销毁自恢复审计与报告
notificationChannelAudit boolean 是否支持 Android 通知通道体检与前台通知可展示条件报告
foregroundServiceCompliance boolean 是否支持 Android 前台服务合规体检与启动风险报告
marketReadinessReport boolean 是否支持插件市场发布体检报告
deliveryReportClipboard boolean 是否支持交付报告一键复制到系统剪贴板
deliveryEvidenceExport boolean 是否支持交付证据文件导出到 Android 应用私有目录
deliveryArchiveExport boolean 是否支持交付证据 ZIP 归档包导出到 Android 应用私有目录
evidenceSession boolean 是否支持保活证据会话
baseIntegrity boolean 是否支持自定义基座完整性报告
eventTimeline boolean 是否支持事件时间线与恢复审计
diagnosticKit boolean 是否支持售后诊断包
acceptanceReport boolean 是否支持保活验收报告
runReport boolean 是否支持长跑观测/复测报告
survivalTest boolean 是否支持保活生存力测试
keepAliveSuite boolean 是否支持一键保活套件
autoHeal boolean 是否支持一键自愈守护
autoHealEvidenceLoop boolean 是否支持一键自愈闭环证据
taskGuardian boolean 是否支持后台任务守护
taskResultReport boolean 是否支持后台任务执行结果回执
jobSchedulerGuardian boolean 是否支持 Android JobScheduler 兜底守护
vendorGuide boolean 是否支持 Android 厂商 ROM 指引
harmonyGuide boolean 是否支持 Harmony 后台配置指引
harmonyBackgroundSuite boolean 是否支持鸿蒙后台套件状态、启动和报告
iosBackgroundSuite boolean 是否支持 iOS 后台套件状态、启动和报告
stableTimer boolean 是否支持稳定后台任务定时器
silentAudio boolean 是否支持静音音频保活策略
strategyPresets boolean 是否支持一键保活策略预设
restrictedReason string 受限原因说明

错误码

错误码 含义 说明
9013001 platform unsupported 当前平台不支持该能力
9013002 invalid options 参数不合法
9013003 service not registered 服务未注册
9013004 service already running 服务已在运行
9013005 service not running 服务未运行
9013006 permission denied 权限不足
9013007 capability restricted 能力受限
9013008 operation failed 系统调用失败
9013009 battery optimization denied 忽略电池优化申请失败
9013010 wake lock unavailable 唤醒锁不可用
9013011 settings unavailable 设置页不可达
9013012 throttled 调用过于频繁

权限与配置

平台 是否需要 说明
Android FOREGROUND_SERVICE / FOREGROUND_SERVICE_DATA_SYNC / WAKE_LOCK / ACCESS_WIFI_STATE / CHANGE_WIFI_STATE / REQUEST_IGNORE_BATTERY_OPTIMIZATIONS / RECEIVE_BOOT_COMPLETED / POST_NOTIFICATIONS / SCHEDULE_EXACT_ALARM / BIND_JOB_SERVICE
iOS UIBackgroundModes(audio/fetch/processing)
Harmony/Web/小程序 使用降级策略,无系统常驻能力

说明:Android 真前台服务、Manifest 服务注册、通知动作广播、开机/屏幕唤醒自恢复、AlarmManager 看门狗、JobScheduler 兜底守护、WiFi 锁、POST_NOTIFICATIONS 通知运行时权限、SCHEDULE_EXACT_ALARM 精确闹钟、BIND_JOB_SERVICE JobService 绑定和原生权限必须进入自定义基座后才会生效。标准基座仅保证降级接口可用。

Android 权限与系统设置诊断

getKeepAlivePermissionStatus 会一次性返回通知权限、精确闹钟、电池优化白名单和厂商自启动设置建议。Android 12+ 如果未允许 SCHEDULE_EXACT_ALARM,看门狗会自动降级为 setAndAllowWhileIdle,同时建议用户打开精确闹钟授权;Android 13+ 如果未允许 POST_NOTIFICATIONS,前台服务仍会按系统规则启动,但通知可能不可见,建议先请求通知权限或打开通知设置页。

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 诊断保活前置系统设置,适合注册或启动前调用。
keepAlive.getKeepAlivePermissionStatus({
  success(res) {
    console.log('keepalive permission status', res)
  }
})

// Android 13+ 请求通知运行时权限;低版本会直接返回已满足状态。
keepAlive.requestPostNotificationsPermission({
  success(res) {
    console.log('notification permission result', res)
  }
})

// Android 12+ 打开精确闹钟授权页,授权后看门狗可使用精确 idle 闹钟。
keepAlive.requestExactAlarmPermission({
  success(res) {
    console.log('exact alarm setting opened', res)
  }
})

运行态事件监听

setOnKeepAliveEvent 用于统一接收保活运行过程中的关键事件。Android 自定义基座中支持通知点击、通知动作、前后台、亮屏、息屏、解锁、开机恢复、包更新恢复和 AlarmManager 看门狗恢复事件;其它平台会保留 API 形态并返回轻量运行事件,不伪造 Android 系统事件。

参数 类型 必填 说明 默认值 可选参数
options EventListenerOptions 运行态事件监听参数 listener / success / fail / complete
options.listener function 事件回调,返回 KeepAliveEvent
options.success function 监听绑定成功回调
options.fail function 监听绑定失败回调
options.complete function 监听完成回调
字段 类型 说明
name KeepAliveEventName 事件名,如 notificationClick / notificationAction / screenOn / screenOff / foreground / background / watchdog
payload any 事件携带数据,通知点击会返回页面、回调名和 Activity 配置,通知动作会返回 action/result/runtimeStatus
timestamp number 事件触发时间戳
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 统一监听通知点击、前后台、屏幕状态和恢复事件。
keepAlive.setOnKeepAliveEvent({
  listener(event) {
    console.log('keepalive runtime event', event.name, event.payload)
  }
})

Android 通知动作

notificationActionsEnabled 用于控制 Android 常驻通知动作按钮。默认开启后,前台服务通知会展示“停止保活 / 重启保活 / 保活设置 / 电源管理”四个动作按钮。按钮会通过 KeepAliveBootReceiver 进入原生处理链路,不依赖页面必须在前台;如果页面还没有绑定事件监听,notificationAction 会先进入事件队列,页面恢复并调用 setOnKeepAliveEvent 后再派发。

参数 类型 必填 说明 默认值 可选参数
config.notificationActionsEnabled boolean 是否在 Android 前台服务通知中显示动作按钮 true true / false
动作 行为 事件
停止保活 停止前台服务、心跳、看门狗、WakeLock 与 WiFiLock notificationActionpayload.action = stop
重启保活 重新启动前台服务、心跳、看门狗和已启用的锁 notificationActionpayload.action = restart
保活设置 打开厂商自启动/后台运行设置,失败回退应用详情 notificationActionpayload.action = settings
电源管理 打开系统省电/电源管理页,失败回退应用详情 notificationActionpayload.action = powerManagement
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 开启通知动作按钮,便于用户直接在常驻通知里停止、重启和进入设置。
keepAlive.setConfig({
  config: {
    notificationActionsEnabled: true
  }
})

Android 系统限制诊断

getKeepAliveRestrictionStatus 用于诊断系统层是否正在限制后台运行。Android 端会读取 PowerManager.isPowerSaveMode / isDeviceIdleMode / isLowPowerStandbyEnabledUsageStatsManager.getAppStandbyBucketActivityManager.isBackgroundRestricted,并返回可执行建议。该 API 只负责诊断和引导设置,不绕过 Android 系统限制。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 系统限制诊断参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveRestrictionStatus
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
powerSaveMode KeepAliveBooleanStatus 系统省电模式是否正在影响后台能力
deviceIdleMode KeepAliveBooleanStatus Doze 设备空闲模式状态
backgroundRestricted KeepAliveBooleanStatus 用户或系统是否限制应用后台运行
lowPowerStandby KeepAliveBooleanStatus Android 13+ 低功耗待机状态
appStandbyBucket KeepAliveStandbyBucket App Standby 待机桶
appStandbyBucketCode number 系统返回的待机桶原始值
appStandbyBucketReason string 待机桶说明
recommendations Array 建议用户处理的设置项
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 检查系统省电、Doze、待机桶、后台限制和低功耗待机。
keepAlive.getKeepAliveRestrictionStatus({
  success(res) {
    console.log('restriction status', res)
  }
})

// 打开电源管理相关设置页,便于用户调整后台限制。
keepAlive.openPowerManagementSettings({
  success(res) {
    console.log('power settings opened', res)
  }
})

一键保活巡检

getKeepAliveHealthReport 返回 KeepAliveHealthReport,会聚合当前 status、权限诊断 permissionStatus、系统限制诊断 restrictionStatus,并输出 score / level / issues / recommendations。Android 能力矩阵中的 healthReporttrue 时代表支持真实巡检;其它平台返回 unsupported 等级降级报告。该 API 适合在“启动保活后”“客户反馈后台被杀时”“插件市场演示页”中调用,用一份报告解释当前保活质量。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 巡检参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveHealthReport
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
score number 综合评分,范围 0-100
level KeepAliveHealthLevel excellent / good / fair / poor / unsupported
issues Array 当前发现的问题
recommendations Array 建议用户处理的配置或系统设置
status KeepAliveStatus 当前运行状态
permissionStatus KeepAliveSystemPermissionStatus 通知权限、精确闹钟、电池优化和厂商设置建议
restrictionStatus KeepAliveRestrictionStatus 省电模式、Doze、待机桶、后台限制等系统限制诊断
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 一次性获取保活质量评分和可执行建议。
keepAlive.getKeepAliveHealthReport({
  success(report) {
    console.log('health score', report.score, report.level)
    console.log('issues', report.issues)
    console.log('recommendations', report.recommendations)
  }
})

保活准备度报告

getKeepAliveReadinessReport 返回 KeepAliveReadinessReport,会聚合 getKeepAliveHealthReport、权限诊断、系统限制诊断、厂商 ROM 指引和策略预设指引,输出 readinessScore / level / ready / blockingActions / recommendedActions / nextSteps / warnings。Android 能力矩阵中的 readinessReporttrue 时代表支持真实准备度报告;其它平台返回 unsupported 降级报告,避免误判系统级保活能力。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 准备度报告参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveReadinessReport
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
readinessScore number 准备度评分,范围 0-100
level KeepAliveReadinessLevel ready / warning / blocked / unsupported
ready boolean 是否达到可进入长时间真机验收的状态
blockingActions Array 必须优先处理的阻断项
recommendedActions Array 建议继续处理的增强项
nextSteps Array 下一步验收顺序
warnings Array 系统限制、合规和自定义基座提醒
healthReport KeepAliveHealthReport 一键巡检报告
permissionStatus KeepAliveSystemPermissionStatus 通知权限、精确闹钟、电池优化和厂商设置建议
restrictionStatus KeepAliveRestrictionStatus 系统省电、Doze、后台限制和待机桶诊断
vendorGuide KeepAliveVendorGuide 当前厂商 ROM 设置指引
presetGuide KeepAlivePresetGuide 默认极限保活预设启用指引
字段 类型 说明
action string 动作标识
title string 面向用户展示的动作标题
reason string 为什么需要处理
required boolean 是否属于阻断项
done boolean 当前是否已完成
apiName string 建议配合调用的 API
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 一次性查看保活准备度,适合放在上线前验收页或客户排障页。
keepAlive.getKeepAliveReadinessReport({
  success(report) {
    console.log('readiness', report.readinessScore, report.level, report.ready)
    console.log('blockingActions', report.blockingActions)
    console.log('recommendedActions', report.recommendedActions)
    console.log('vendorGuide', report.vendorGuide)
  }
})

Android 厂商 ROM 指引

getKeepAliveVendorGuide 返回 KeepAliveVendorGuide,会根据 Android Build.BRAND / Build.MANUFACTURER 识别小米、华为、荣耀、OPPO、vivo、魅族、三星等常见 ROM,并给出自启动、后台运行、电池优化、通知权限和最近任务锁定等设置步骤。Android 能力矩阵中的 vendorGuidetrue 时代表支持真实厂商识别;其它平台返回明确降级说明,不伪造 Android ROM 设置能力。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 厂商指引参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveVendorGuide
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
brand string Android Build.BRAND
manufacturer string Android Build.MANUFACTURER
vendor string 归一化厂商名,如 小米 / 华为 / 荣耀 / OPPO / vivo / 魅族 / 三星 / 通用 Android
matched boolean 是否命中内置厂商规则
steps Array 推荐用户手动开启的 ROM 保活步骤
settingsActions Array 可结合调用的插件设置入口,如 openAutoStartSettings
warnings Array 系统限制、入口差异和验收提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 获取当前 Android 厂商 ROM 的保活设置步骤,适合在客户排障页展示。
keepAlive.getKeepAliveVendorGuide({
  success(guide) {
    console.log('vendor', guide.vendor, guide.matched)
    console.log('steps', guide.steps)
    console.log('actions', guide.settingsActions)
  }
})

厂商 ROM 设置验收审计

getKeepAliveVendorSettingsAudit 返回 KeepAliveVendorSettingsAudit,用于把 Android 厂商 ROM 设置从“口头提醒”变成“可记录的交付证据”。Android 会自动检测通知权限、电池优化白名单和精确闹钟状态;自启动、后台运行、最近任务锁定等厂商 ROM 私有开关无法被第三方应用可靠读取,需要业务在用户完成设置后调用 setKeepAliveVendorSettingState 标记 confirmed,再用报告中的 score / requiredPassed / items / nextSteps 做交付归档。能力矩阵中的 vendorSettingsAudittrue 时代表支持真实 Android 审计;其它平台返回 vendorSettingsAudit=false 的降级边界。

openNextKeepAliveVendorSetting 会读取当前审计报告,优先找到下一项未完成的必填设置并打开对应系统入口,返回 KeepAliveVendorSettingsNavigationResult。该函数适合做“下一步”按钮:先打开通知、电池优化、自启动或电源管理入口,用户完成后再调用 setKeepAliveVendorSettingState 标记人工项。

该审计和导航不写本地文件、不申请存储权限,也不会承诺绕过 Android 系统、Doze 或厂商后台限制。它的定位是配合 getKeepAliveVendorGuidegetKeepAliveAcceptancePlangetKeepAliveSupportReport 做客户现场复测。

getKeepAliveVendorSettingsAudit(options)

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 获取 ROM 设置验收审计参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveVendorSettingsAudit
options.fail function 失败回调
options.complete function 完成回调

setKeepAliveVendorSettingState(options)

参数 类型 必填 说明 默认值 可选参数
options SetKeepAliveVendorSettingStateOptions 设置 ROM 验收项状态参数 id / state / evidence / success / fail / complete
options.id string 验收项 ID auto-start / background-run / battery-optimization / notification-permission / recent-task-lock / exact-alarm
options.state string 验收状态 unknown / enabled / disabled / confirmed / unsupported
options.evidence string 人工证据备注,如截图编号、交付单号或用户确认说明 manual-{state}
options.success function 成功回调,返回更新后的 KeepAliveVendorSettingsAudit
options.fail function 失败回调
options.complete function 完成回调

resetKeepAliveVendorSettingsAudit(options)

参数 类型 必填 说明 默认值 可选参数
options KeepAliveBaseOptions 重置 ROM 验收记录参数 success / fail / complete

openNextKeepAliveVendorSetting(options)

参数 类型 必填 说明 默认值 可选参数
options KeepAliveBaseOptions 打开下一项未完成设置参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveVendorSettingsNavigationResult
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
vendorSettingsAudit boolean 当前平台是否支持真实 Android ROM 设置验收审计
vendor string 归一化厂商名
completed boolean 必填验收项是否全部通过或已确认
requiredPassed number 必填项已通过数量
requiredTotal number 必填项总数
score number 必填项完成度评分
items Array 验收项列表,包含 id / title / descriptionText / state / evidence / nextStep / warnings
vendorGuide KeepAliveVendorGuide 当前厂商 ROM 指引
nextSteps Array 仍需执行的设置动作
warnings Array 系统限制和人工确认边界

KeepAliveVendorSettingsNavigationResult

字段 类型 说明
opened boolean 是否成功打开下一项未完成设置
targetItemId string 被导航的验收项 ID
targetTitle string 被导航的验收项标题
settingsAction string 使用的设置入口,如 openAutoStartSettings / openPowerManagementSettings
fallbackUsed boolean 是否使用近似或兜底入口
reason string 本次导航说明
audit KeepAliveVendorSettingsAudit 打开前生成的审计报告
warnings Array 设置入口失败或平台限制提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 先查看 ROM 设置验收报告,确认 auto-start、background-run 等人工项是否还未完成。
keepAlive.getKeepAliveVendorSettingsAudit({
  success(report) {
    console.log('vendorSettingsAudit', report.vendorSettingsAudit, report.score)
    console.log('items', report.items)
  }
})

// 用户已在厂商设置页开启自启动后,业务可记录人工确认结果。
keepAlive.setKeepAliveVendorSettingState({
  id: 'auto-start',
  state: 'confirmed',
  evidence: '客户现场截图-自启动已开启',
  success(report) {
    console.log('required', report.requiredPassed, report.requiredTotal)
  }
})

// 打开下一项未完成设置,适合做交付页中的“下一步”按钮。
keepAlive.openNextKeepAliveVendorSetting({
  success(result) {
    console.log('targetItemId', result.targetItemId)
    console.log('opened', result.opened, result.reason)
  }
})

一键终极体检报告

getKeepAliveUltimateReport 返回 KeepAliveUltimateReport,用于把 Android 自定义基座首检、保活准备度、厂商 ROM 设置验收、下一项设置导航建议和售后/交付支持报告合并成一个入口。它适合插件市场演示页、客户交付首检页和售后排障页:用户点击一次即可看到 verdict / score / ready / nextSteps / warnings,并可复制 markdown 作为验收或工单记录。

默认情况下该 API 只生成“下一项设置建议”,不会自动打开系统设置页;如果确实要在报告生成时顺带跳转,可传 openNextSetting: true。能力矩阵中的 ultimateReporttrue 时代表当前 Android 基座包含真实终极体检聚合能力;其它平台返回 ultimateReport=false 的降级边界。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveUltimateReportOptions 一键终极体检参数 strictMode / includeMarkdown / includeSupportReport / openNextSetting / success / fail / complete
options.strictMode boolean 是否按严格交付口径判断阻断项 false true / false
options.includeMarkdown boolean 是否返回可复制 Markdown true true / false
options.includeSupportReport boolean 是否内嵌售后/交付支持报告 true true / false
options.openNextSetting boolean 是否生成报告时直接打开下一项 ROM 设置 false true / false
options.success function 成功回调,返回 KeepAliveUltimateReport
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
ultimateReport boolean 当前平台是否支持真实 Android 一键终极体检
verdict KeepAliveUltimateVerdict 总体结论,可能为 excellent / ready / action-required / blocked / unsupported
score number 综合评分
ready boolean 是否达到交付可通过状态
baseIntegrityReport KeepAliveBaseIntegrityReport Android 自定义基座完整性报告
readinessReport KeepAliveReadinessReport 保活准备度报告
vendorSettingsAudit KeepAliveVendorSettingsAudit 厂商 ROM 设置验收审计
vendorSettingsNavigation KeepAliveVendorSettingsNavigationResult 下一项设置建议或跳转结果
supportReport KeepAliveSupportReport 售后/交付支持报告
markdown string 可复制的终极体检 Markdown
nextSteps Array 下一步动作
warnings Array 系统限制、ROM 限制和平台边界提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 一键生成交付首检报告;默认不打开系统设置页,只返回下一项设置建议。
keepAlive.getKeepAliveUltimateReport({
  strictMode: false,
  includeMarkdown: true,
  includeSupportReport: true,
  openNextSetting: false,
  success(report) {
    console.log('ultimateReport', report.ultimateReport, report.verdict, report.score)
    console.log('next setting', report.vendorSettingsNavigation.targetItemId)
    console.log('next steps', report.nextSteps)
  }
})

服务销毁自恢复报告

getKeepAliveServiceDestroyRecoveryReport 返回 KeepAliveServiceDestroyRecoveryReport,用于验证 Android 前台服务被系统销毁后的恢复闭环。Android 端会在 KeepAliveForegroundService.onDestroy 中记录 serviceDestroy 事件,持久化 serviceDestroyCount / restartScheduledCount / lastServiceDestroyAt / lastRestartScheduledAt / lastDestroyReason,并在“不是用户显式停止、运行态已注册、当前策略允许恢复”时重建前台服务、Watchdog、JobScheduler、稳定定时器和静音音频等合法链路。

该能力用于“服务生命周期恢复审计”和“交付验收”,不会在用户主动点击停止、调用 stopKeepAlive/unregister、系统强行停止应用、ROM 禁止后台运行或 Doze 强限制时伪造恢复成功。能力矩阵中的 serviceDestroyRecoverytrue 时代表当前 Android 自定义基座包含真实 onDestroy 自恢复链路;其它平台返回 serviceDestroyRecovery=false 的降级边界。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 获取服务销毁自恢复报告参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveServiceDestroyRecoveryReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
serviceDestroyRecovery boolean 当前平台是否支持真实 Android 服务销毁自恢复
supported boolean 当前报告是否来自支持平台
canRecover boolean 当前注册、运行态和策略是否允许服务销毁后恢复
serviceDestroyCount number 已记录的前台服务 onDestroy 次数
restartScheduledCount number 已触发的恢复重排次数
lastServiceDestroyAt number 最近一次服务销毁时间戳
lastRestartScheduledAt number 最近一次恢复重排时间戳
lastDestroyReason string 最近一次服务销毁原因,例如 service-onDestroyexplicit-stop
eventTimeline KeepAliveEventTimeline 最近 serviceDestroy 事件时间线
nextSteps Array 下一步验收或配置建议
warnings Array 系统限制、ROM 限制和平台边界提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 真机验收建议:先 register -> startKeepAlive,再模拟服务销毁或观察系统回收后的报告。
keepAlive.getKeepAliveServiceDestroyRecoveryReport({
  success(report) {
    console.log('serviceDestroyRecovery', report.serviceDestroyRecovery)
    console.log('destroy', report.serviceDestroyCount, 'restart', report.restartScheduledCount)
    console.log('reason', report.lastDestroyReason)
    console.log('events', report.eventTimeline.events)
    console.log('next steps', report.nextSteps)
  },
  fail(err) {
    console.log('getKeepAliveServiceDestroyRecoveryReport failed', err)
  }
})

通知通道体检报告

getKeepAliveNotificationChannelReport 返回 KeepAliveNotificationChannelReport,用于验证 Android 前台服务通知是否具备可展示条件。Android 端会检查 App 通知总开关、Android 8+ 通知通道是否存在、通道重要级别是否为 IMPORTANCE_NONE、Android 13+ 通知运行时权限和当前保活状态,并输出 nextSteps / warnings 作为交付排障依据。

该能力解决“前台服务已经启动,但通知不可见或被系统拦截”的常见售后问题。能力矩阵中的 notificationChannelAudittrue 时代表当前 Android 自定义基座包含真实通知通道体检逻辑;其它平台返回 notificationChannelAudit=false 的降级边界,不把 fallback 当作 Android 通知通道通过证据。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 获取通知通道体检报告参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveNotificationChannelReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
notificationChannelAudit boolean 当前平台是否支持真实 Android 通知通道体检
supported boolean 当前报告是否来自支持平台
channelId string 当前前台服务通知通道 ID
channelName string 当前前台服务通知通道名称
channelExists boolean Android 8+ 通知通道是否存在
notificationsEnabled boolean App 通知总开关是否可用
notificationPermissionGranted boolean Android 13+ POST_NOTIFICATIONS 是否已授权
channelImportance number 通知通道重要级别;IMPORTANCE_NONE 表示通道被关闭
channelImportanceLabel string 通道重要级别可读标签
channelBlocked boolean 通道是否被用户关闭或降为不可展示
canPostForegroundNotification boolean 当前是否具备展示前台服务通知的基础条件
requiresUserAction boolean 是否需要用户进入系统设置修复通知配置
status KeepAliveStatus 当前保活运行状态
capabilities KeepAliveCapabilities 当前能力矩阵,重点关注 notificationChannelAudit
nextSteps Array 下一步设置或验收建议
warnings Array 通知权限、通道和平台边界提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 启动保活前后都可以执行,用于确认前台服务通知是否会被系统展示。
keepAlive.getKeepAliveNotificationChannelReport({
  success(report) {
    console.log('notificationChannelAudit', report.notificationChannelAudit)
    console.log('channel', report.channelId, report.channelExists)
    console.log('blocked', report.channelBlocked, 'canPost', report.canPostForegroundNotification)
    console.log('next steps', report.nextSteps)
  },
  fail(err) {
    console.log('getKeepAliveNotificationChannelReport failed', err)
  }
})

Android 前台服务合规体检报告

getKeepAliveForegroundServiceComplianceReport 返回 KeepAliveForegroundServiceComplianceReport,用于在 Android 自定义基座中排查前台服务启动和展示的合规风险。报告会汇总 sdkInt / targetSdkVersion / foregroundServiceType / manifestForegroundServiceTypes / declaredPermissions / missingPermissions / backgroundStartRisk / serviceTypePermissionRisk / notificationPermissionRisk / notificationChannelRisk / runningStateRisk,并复用通知通道体检结果判断前台服务通知是否具备可展示条件。

该能力解决 Android 12+ 后台启动前台服务受限、Android 13+ 通知权限未授权、Android 14+ 前台服务类型和权限不匹配、通知通道被关闭等常见真机交付问题。能力矩阵中的 foregroundServiceCompliance=true 表示当前 Android 自定义基座包含真实合规体检逻辑;其它平台返回 foregroundServiceCompliance=false 的降级边界。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 获取前台服务合规体检报告参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveForegroundServiceComplianceReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
foregroundServiceCompliance boolean 当前平台是否支持真实 Android 前台服务合规体检
ready boolean 前台服务关键合规项是否可进入真机验收
riskLevel string 综合风险等级:none / low / medium / high / blocked / unsupported
sdkInt number 当前 Android 系统 SDK 版本
targetSdkVersion number 当前 App targetSdkVersion
foregroundServiceType string 当前插件配置的前台服务类型
manifestForegroundServiceTypes Array Manifest 声明的前台服务类型
declaredPermissions Array 当前插件声明的前台服务相关权限
missingPermissions Array 当前服务类型缺失的权限或声明
backgroundStartRisk string 后台启动前台服务风险
serviceTypePermissionRisk string 前台服务类型和权限匹配风险
notificationPermissionRisk string Android 13+ 通知权限风险
notificationChannelRisk string Android 8+ 通知通道风险
notificationChannelReport KeepAliveNotificationChannelReport 复用的通知通道体检报告
checks Array 结构化检查项
nextSteps Array 下一步处理建议
warnings Array 系统限制和人工验收提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 重新打 Android 自定义基座后,优先执行该报告判断前台服务是否具备合规启动条件。
keepAlive.getKeepAliveForegroundServiceComplianceReport({
  success(report) {
    console.log('foregroundServiceCompliance', report.foregroundServiceCompliance)
    console.log('targetSdkVersion', report.targetSdkVersion)
    console.log('backgroundStartRisk', report.backgroundStartRisk)
    console.log('serviceTypePermissionRisk', report.serviceTypePermissionRisk)
    console.log('next steps', report.nextSteps)
  },
  fail(err) {
    console.log('getKeepAliveForegroundServiceComplianceReport failed', err)
  }
})

插件市场发布体检报告

getKeepAliveMarketReadinessReport 返回 KeepAliveMarketReadinessReport,用于插件市场上架、售前演示、客户购买后首轮验收和售后复盘。Android 端会聚合能力矩阵、getKeepAliveForegroundServiceComplianceReportgetKeepAliveSupportReportgetKeepAliveUltimateReport,输出推荐市场文案、合规边界、验收 API 路径和可复制 Markdown。

该能力会把插件的核心功能、系统限制、厂商 ROM 设置、前台服务合规、通知权限、电池优化、WakeLock/WiFiLock、事件回调和交付证据链整理成结构化报告。能力矩阵中的 marketReadinessReport=true 表示当前 Android 自定义基座包含真实市场发布体检逻辑;其它平台返回 marketReadinessReport=false 的降级边界。

getKeepAliveMarketReadinessReport(options)

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveMarketReadinessReportOptions 获取插件市场发布体检报告参数 includeMarkdown / includeSupportReport / includeUltimateReport / success / fail / complete
options.includeMarkdown boolean 是否返回可复制 Markdown 报告 true true / false
options.includeSupportReport boolean 是否聚合售后/交付支持报告 true true / false
options.includeUltimateReport boolean 是否聚合一键终极体检报告 true true / false
options.success function 成功回调,返回 KeepAliveMarketReadinessReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
marketReadinessReport boolean 当前平台是否支持真实插件市场发布体检
level KeepAliveMarketReadinessLevel 发布体检等级:market-ready / needs-device-verification / action-required / unsupported
score number 市场发布体检评分
recommendedMarketClaims Array 推荐用于插件市场的合规卖点文案
complianceBoundaries Array 不可夸大的系统限制和合规边界
acceptanceApiPath Array 建议客户验收 API 路径
foregroundServiceComplianceReport KeepAliveForegroundServiceComplianceReport 前台服务合规体检报告
supportReport KeepAliveSupportReport 售后/交付支持报告
ultimateReport KeepAliveUltimateReport 一键终极体检报告
markdown string 可复制的市场发布/验收 Markdown
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 建议在重新打 Android 自定义基座后,作为插件市场上架和客户交付的第一份报告。
keepAlive.getKeepAliveMarketReadinessReport({
  includeMarkdown: true,
  includeSupportReport: true,
  includeUltimateReport: true,
  success(report) {
    console.log('marketReadinessReport', report.marketReadinessReport)
    console.log('level', report.level, 'score', report.score)
    console.log('recommendedMarketClaims', report.recommendedMarketClaims)
    console.log('complianceBoundaries', report.complianceBoundaries)
    console.log('acceptanceApiPath', report.acceptanceApiPath)
  },
  fail(err) {
    console.log('getKeepAliveMarketReadinessReport failed', err)
  }
})

交付报告一键复制

copyKeepAliveDeliveryReport 返回 CopyKeepAliveDeliveryReportResult,用于把 Android 交付证据链直接写入系统剪贴板。Android 端通过系统 ClipboardManager + ClipData 复制纯文本 Markdown,可复制的报告包括插件市场发布体检、售后/交付支持报告、一键终极体检和交付验收计划。

能力矩阵中的 deliveryReportClipboard=true 表示当前 Android 自定义基座包含真实剪贴板写入逻辑;其它平台返回 deliveryReportClipboard=false / copied=false 的降级边界,不能当作 Android 剪贴板复制成功证据。该能力只复制报告文本,不替代真机长跑、ROM 设置截图或 ADB 证据归档。

copyKeepAliveDeliveryReport(options)

参数 类型 必填 说明 默认值 可选参数
options CopyKeepAliveDeliveryReportOptions 复制交付报告参数 reportKind / includeMarkdown / label / success / fail / complete
options.reportKind KeepAliveDeliveryReportKind 要复制的报告类型 market market / support / ultimate / acceptance-plan
options.includeMarkdown boolean 成功回调是否返回完整 Markdown;不影响实际复制内容 true true / false
options.label string Android 剪贴板标签 lizhao-app-keepalive-{reportKind}
options.success function 成功回调,返回 CopyKeepAliveDeliveryReportResult
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
copied boolean 是否真实写入系统剪贴板
clipboard boolean 当前调用是否使用系统剪贴板完成复制
deliveryReportClipboard boolean 当前平台是否支持真实交付报告剪贴板复制
reportKind KeepAliveDeliveryReportKind 实际复制的报告类型
sourceReportId string 来源报告 ID,例如市场体检 reportId 或验收计划 planId
textLength number 被复制 Markdown 的字符长度
markdown string 可选返回的 Markdown;includeMarkdown=false 时为空
summaryText string 来源报告摘要
warnings Array 降级、合规边界或真机验收提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 重新打 Android 自定义基座后,可直接复制市场发布体检 Markdown 给客户或插件市场审核。
keepAlive.copyKeepAliveDeliveryReport({
  reportKind: 'market',
  includeMarkdown: false,
  label: 'lizhao-app-keepalive-market-report',
  success(result) {
    console.log('deliveryReportClipboard', result.deliveryReportClipboard)
    console.log('copied', result.copied, 'textLength', result.textLength)
    console.log('sourceReportId', result.sourceReportId)
  },
  fail(err) {
    console.log('copyKeepAliveDeliveryReport failed', err)
  }
})

交付证据文件导出

exportKeepAliveDeliveryEvidence 返回 ExportKeepAliveDeliveryEvidenceResult,用于把 Android 交付证据链落到应用私有目录。Android 端会复用市场发布体检、售后/交付支持报告、一键终极体检或交付验收计划的 Markdown,并导出 .md 与可选 .json 元数据文件;不申请公共存储权限,不写入下载目录,避免新增上架合规风险。

能力矩阵中的 deliveryEvidenceExport=true 表示当前 Android 自定义基座包含真实文件导出逻辑;其它平台返回 deliveryEvidenceExport=false / exported=false 的降级边界,不能当作 Android 文件导出成功证据。文件导出用于归档和沟通,不替代目标设备、目标 ROM 和目标系统版本的真机长跑验收。

exportKeepAliveDeliveryEvidence(options)

参数 类型 必填 说明 默认值 可选参数
options ExportKeepAliveDeliveryEvidenceOptions 导出交付证据文件参数 reportKind / includeJson / filePrefix / success / fail / complete
options.reportKind KeepAliveDeliveryReportKind 要导出的报告类型 market market / support / ultimate / acceptance-plan
options.includeJson boolean 是否同时导出 JSON 元数据 true true / false
options.filePrefix string 文件名前缀;非法路径字符会替换为 - lizhao-app-keepalive-{reportKind}
options.success function 成功回调,返回 ExportKeepAliveDeliveryEvidenceResult
options.fail function 失败回调;上下文不可用或文件写入异常时触发
options.complete function 完成回调
字段 类型 说明
exported boolean 是否真实完成文件导出
deliveryEvidenceExport boolean 当前平台是否支持真实交付证据文件导出
reportKind KeepAliveDeliveryReportKind 实际导出的报告类型
sourceReportId string 来源报告 ID,例如市场体检 reportId 或验收计划 planId
directoryPath string Android 应用私有证据目录路径
markdownFilePath string 导出的 Markdown 文件路径
jsonFilePath string 导出的 JSON 元数据文件路径;includeJson=false 时为空
markdownLength number Markdown 字符长度
jsonLength number JSON 字符长度
summaryText string 来源报告摘要
warnings Array 降级、合规边界或真机验收提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 重新打 Android 自定义基座后,可导出市场发布证据文件给客户或插件市场审核。
keepAlive.exportKeepAliveDeliveryEvidence({
  reportKind: 'market',
  includeJson: true,
  filePrefix: 'lizhao-app-keepalive-market-evidence',
  success(result) {
    console.log('deliveryEvidenceExport', result.deliveryEvidenceExport)
    console.log('exported', result.exported)
    console.log('markdownFilePath', result.markdownFilePath)
    console.log('jsonFilePath', result.jsonFilePath)
  },
  fail(err) {
    console.log('exportKeepAliveDeliveryEvidence failed', err)
  }
})

交付证据归档包导出

exportKeepAliveDeliveryArchive 返回 ExportKeepAliveDeliveryArchiveResult,用于把 Android 交付证据链整理为一个 ZIP 归档包。Android 端会在应用私有目录中生成 delivery-archive-export 证据包,包含 manifest.json / market.md / support.md / ultimate.md / acceptance-plan.md,覆盖插件市场发布体检、售后支持报告、一键终极体检和交付验收计划。

能力矩阵中的 deliveryArchiveExport=true 表示当前 Android 自定义基座包含真实 ZIP 归档导出逻辑;其它平台返回 deliveryArchiveExport=false / exported=false 的降级边界,不能当作 Android 归档包导出成功证据。归档包只写入应用私有目录,不申请公共存储权限,不写下载目录,业务可自行决定是否上传到工单或作为插件市场审核材料附件。

exportKeepAliveDeliveryArchive(options)

参数 类型 必填 说明 默认值 可选参数
options ExportKeepAliveDeliveryArchiveOptions 归档包导出参数 reportKinds / filePrefix / success / fail / complete
options.reportKinds Array 需要写入 ZIP 的报告类型 market/support/ultimate/acceptance-plan market / support / ultimate / acceptance-plan
options.filePrefix string 导出文件名前缀 keepalive-market
options.success function 成功回调,返回 ExportKeepAliveDeliveryArchiveResult
options.fail function 失败回调;上下文不可用、文件写入失败或平台不支持时触发
options.complete function 完成回调
字段 类型 说明
exported boolean 是否真实导出归档包
deliveryArchiveExport boolean 当前平台是否支持真实交付证据归档包导出
reportKinds Array 本次归档包含的报告类型
sourceReportIds Array 本次归档引用的报告 ID
platform string 当前运行平台
pluginVersion string 插件版本
directoryPath string 应用私有证据目录路径
archiveFilePath string ZIP 归档包路径
archiveLength number ZIP 归档包字节长度
manifestLength number manifest.json 文本长度
summaryText string 归档摘要
warnings Array 风险和限制说明
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 交付前导出一份 ZIP 归档包,便于插件市场审核、售前演示或客户工单上传。
keepAlive.exportKeepAliveDeliveryArchive({
  reportKinds: ['market', 'support', 'ultimate', 'acceptance-plan'],
  filePrefix: 'lizhao-app-keepalive-delivery-archive',
  success(result) {
    console.log('deliveryArchiveExport', result.deliveryArchiveExport)
    console.log('archiveFilePath', result.archiveFilePath)
    console.log('archiveLength', result.archiveLength)
  },
  fail(err) {
    console.log('exportKeepAliveDeliveryArchive failed', err)
  }
})

发布包质量门禁

发布到插件市场前建议先运行 scripts\check-lizhao-app-keepalive-release-gate.js。该脚本会检查 package.json 版本、关键词、权限声明,README/changelog/verification-checklist 是否包含核心卖点和验收路径,interface.uts 与根入口是否暴露市场体检、交付报告复制、交付证据文件导出、交付证据归档包导出、保活证据会话、恢复证据快照和自愈闭环证据 API,Android Manifest 是否包含前台服务、JobScheduler、通知权限、开机恢复和 stopWithTask=false,以及 Android 源码是否同步 PLUGIN_VERSIONmarketReadinessReport=truedeliveryReportClipboard=truedeliveryEvidenceExport=truedeliveryArchiveExport=trueevidenceSession=truerecoveryEvidenceSnapshot=trueautoHealEvidenceLoop: truegetKeepAliveMarketReadinessReportcopyKeepAliveDeliveryReportexportKeepAliveDeliveryEvidenceexportKeepAliveDeliveryArchivestartKeepAliveEvidenceSessionfinishKeepAliveEvidenceSessiongetKeepAliveRecoveryEvidenceSnapshotgetKeepAliveAutoHealEvidenceLoopbuildKeepAliveAutoHealEvidenceLoopZipOutputStreamarchiveFilePathgetKeepAliveForegroundServiceComplianceReportgetKeepAliveSupportReportgetKeepAliveAcceptancePlan

建议发布前命令:

D:\HBuilderX\plugins\node\node.exe scripts\check-lizhao-app-keepalive-release-gate.js
D:\HBuilderX\plugins\node\node.exe scripts\check-lizhao-app-keepalive-delivery-archive-export.js
D:\HBuilderX\plugins\node\node.exe scripts\check-lizhao-app-keepalive-auto-heal-evidence-loop.js
D:\HBuilderX\plugins\node\node.exe scripts\check-lizhao-app-keepalive-delivery-evidence-export.js
D:\HBuilderX\plugins\node\node.exe scripts\check-lizhao-app-keepalive-delivery-report-clipboard.js
D:\HBuilderX\plugins\node\node.exe scripts\check-lizhao-app-keepalive-market-readiness-report.js
D:\HBuilderX\plugins\node\node.exe scripts\check-lizhao-app-keepalive-foreground-service-compliance.js
D:\HBuilderX\cli.exe publish app-android --type appResource --project E:\test\lizhao-plugin

门禁通过只代表发布包结构、文档和生成物链路满足当前插件市场交付标准;最终是否达到客户设备上的保活效果,仍需要重新打 Android 自定义基座后按 getKeepAliveMarketReadinessReport -> autoHealKeepAlive -> getKeepAliveAutoHealEvidenceLoop -> copyKeepAliveDeliveryReport -> exportKeepAliveDeliveryEvidence -> exportKeepAliveDeliveryArchive -> getKeepAliveAcceptancePlan -> startKeepAliveSurvivalTest -> getKeepAliveRunReport -> getKeepAliveSupportReport 完成真机验收。

任务划掉恢复报告

getKeepAliveTaskRemovedRecoveryReport 返回 KeepAliveTaskRemovedRecoveryReport,用于验证 Android 最近任务划掉后的恢复闭环。Android 端会在前台服务中设置 android:stopWithTask="false",并覆盖 KeepAliveForegroundService.onTaskRemoved:当用户从最近任务划掉应用时,插件记录 taskRemoved 事件,持久化 taskRemovedCount / recoveryCount / lastTaskRemovedAt / lastRecoveryAt,并按当前配置重排 Watchdog、JobScheduler、稳定定时器和静音音频等合法恢复链路。

该能力用于“恢复审计”和“交付验收”,不承诺绕过用户在系统设置里的强行停止、厂商 ROM 后台限制、Doze、电池优化或最近任务锁定策略。能力矩阵中的 taskRemovedRecoverytrue 时代表当前 Android 自定义基座包含真实 onTaskRemoved 恢复链路;其它平台返回 taskRemovedRecovery=false 的降级边界。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 获取任务划掉恢复报告参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveTaskRemovedRecoveryReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
taskRemovedRecovery boolean 当前平台是否支持真实 Android 任务划掉恢复
supported boolean 当前报告是否来自支持平台
serviceStopWithTask boolean Android 前台服务是否会随最近任务停止;真实能力应为 false
canRecover boolean 当前注册和运行策略是否允许任务移除后恢复
taskRemovedCount number 已记录的最近任务划掉次数
recoveryCount number 已触发的恢复尝试次数
lastTaskRemovedAt number 最近一次任务移除时间戳
lastRecoveryAt number 最近一次恢复尝试时间戳
eventTimeline KeepAliveEventTimeline 最近 taskRemoved 事件时间线
nextSteps Array 下一步验收或配置建议
warnings Array 系统限制、ROM 限制和平台边界提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 真机验收建议:先 register -> startKeepAlive,再从最近任务划掉应用,回到页面查询报告。
keepAlive.getKeepAliveTaskRemovedRecoveryReport({
  success(report) {
    console.log('taskRemovedRecovery', report.taskRemovedRecovery)
    console.log('count', report.taskRemovedCount, 'recovery', report.recoveryCount)
    console.log('events', report.eventTimeline.events)
    console.log('next steps', report.nextSteps)
  },
  fail(err) {
    console.log('getKeepAliveTaskRemovedRecoveryReport failed', err)
  }
})

Harmony 后台配置指引

getKeepAliveHarmonyGuide 返回 KeepAliveHarmonyGuide,用于在 Harmony 端构建前检查后台运行相关配置。仓库已提供 harmony-configs/entry/src/main/module.json5 样板,核心要求是在 requestPermissions 中声明 ohos.permission.KEEP_BACKGROUND_RUNNING,并在 EntryAbility.backgroundModes 中声明 audioPlayback / dataTransfer。该能力是配置体检和验收指引,不会承诺绕过 Harmony 系统后台任务、长时任务、通知和审核策略。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 查询参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveHarmonyGuide
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
platform string 当前返回所属平台
supported boolean 当前平台是否支持 Harmony 配置指引
requiresHarmonyConfigs boolean 是否需要维护根目录 harmony-configs
moduleJsonPath string 推荐检查的 module.json5 路径
requiredPermissions Array 必要权限列表
requiredBackgroundModes Array 必要后台模式列表
steps Array 配置步骤
verification Array 验收步骤
warnings Array 平台限制和审核提示
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 构建鸿蒙前查询配置指引,并在发布前对照 module.json5 做人工复核。
keepAlive.getKeepAliveHarmonyGuide({
  success(guide) {
    console.log('module path', guide.moduleJsonPath)
    console.log('permissions', guide.requiredPermissions)
    console.log('background modes', guide.requiredBackgroundModes)
    console.log('warnings', guide.warnings)
  }
})

鸿蒙后台套件

applyKeepAliveHarmonySuite 用于在 Harmony 端启动轻量运行态心跳,并返回 KeepAliveHarmonyBackgroundStatusgetKeepAliveHarmonyBackgroundStatus 可查询当前状态;getKeepAliveHarmonyBackgroundReport 返回 KeepAliveHarmonyBackgroundReport,把状态、KeepAliveHarmonyGuide、当前保活状态、样本数和 warning 聚合成验收报告。能力矩阵中的 harmonyBackgroundSuitetrue 时代表当前平台提供鸿蒙后台套件入口。

该套件依赖根目录 harmony-configs/entry/src/main/module.json5 已声明 ohos.permission.KEEP_BACKGROUND_RUNNING,并在 EntryAbility.backgroundModes 中包含 audioPlayback / dataTransfer。修改该配置后,需要重新运行 Harmony 原生联编或重新打对应自定义基座;仅更新页面资源不能替换已编译进基座的 Harmony 原生配置。该能力不会承诺无条件后台常驻,仍需按 Harmony 长时任务、用户感知场景、通知和应用市场审核策略做真机验收。

applyKeepAliveHarmonySuite(options)

参数 类型 必填 说明 默认值 可选参数
options ApplyKeepAliveHarmonySuiteOptions 鸿蒙后台套件启动参数 startImmediately / heartbeatIntervalMs / tag / success / fail / complete
options.startImmediately boolean 是否立即进入轻量运行态并启动心跳 true true / false
options.heartbeatIntervalMs number 心跳间隔,低于 5000 时会回退为 15000 15000
options.tag string 运行标签,便于日志区分场景 harmony-background
options.success function 成功回调,返回 KeepAliveHarmonyBackgroundStatus
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
supported boolean 当前平台是否提供鸿蒙后台套件
configured boolean 当前仓库样板配置是否满足必要项
running boolean 轻量运行态是否正在运行
heartbeatCount number 运行期心跳数量
lastHeartbeatAt number 最近一次心跳时间
startedAt number 套件启动时间
elapsedMs number 套件已运行时长
moduleJsonPath string 推荐检查的 Harmony 配置文件路径
requiredPermissions Array 必要权限列表
requiredBackgroundModes Array 必要后台模式列表
missingPermissions Array 缺失权限列表
missingBackgroundModes Array 缺失后台模式列表
nextSteps Array 下一步原生联编和真机验收动作
warnings Array Harmony 系统限制、审核和验收提醒

getKeepAliveHarmonyBackgroundReport(options)

字段 类型 说明
platform string 当前平台
level KeepAliveReadinessLevel 当前准备度等级
ready boolean 配置和运行态是否达到可继续真机长跑验收的状态
status KeepAliveHarmonyBackgroundStatus 当前鸿蒙后台套件状态
guide KeepAliveHarmonyGuide Harmony 后台配置指引
keepAliveStatus KeepAliveStatus 当前插件运行态
sampleCount number 报告采样数,当前取心跳数量
summary string 简短摘要
warnings Array 风险和限制说明
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// Harmony 构建并安装新基座后,先启动鸿蒙后台套件,再查看后台报告。
keepAlive.applyKeepAliveHarmonySuite({
  startImmediately: true,
  heartbeatIntervalMs: 15000,
  tag: 'harmony-background-demo',
  success(status) {
    console.log('harmony suite', status.configured, status.running, status.heartbeatCount)
  }
})

// 切后台或息屏一段时间后再次查询报告,用于观察 heartbeatCount 是否继续增长。
keepAlive.getKeepAliveHarmonyBackgroundReport({
  success(report) {
    console.log('Harmony background report', report.level, report.summary)
    console.log('required modes', report.status.requiredBackgroundModes)
  }
})

iOS 后台套件

getKeepAliveIosBackgroundGuide 返回 KeepAliveIosBackgroundGuide,用于在 iOS 端构建前检查后台运行相关配置。仓库已提供 uni_modules/lizhao-app-keepalive/utssdk/app-ios/Info.plist,其中声明了 UIBackgroundModesaudio / fetch / processingapplyKeepAliveIosBackgroundSuite 会启动轻量运行态心跳并返回 KeepAliveIosBackgroundStatusgetKeepAliveIosBackgroundReport 会把状态、配置指引、当前运行态和 warning 聚合为 KeepAliveIosBackgroundReport。能力矩阵中的 iosBackgroundSuitetrue 时代表当前平台提供 iOS 后台套件入口。

该套件不会承诺绕过 Apple 后台执行策略。audio / fetch / processing 必须匹配真实业务场景;修改 Info.plist 后,需要重新运行 iOS 原生联编或重新打 iOS 自定义基座,仅更新页面资源不能替换已编译进基座的 iOS 原生配置。

getKeepAliveIosBackgroundGuide(options)

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 查询参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveIosBackgroundGuide
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
platform string 当前返回所属平台
supported boolean 当前平台是否支持 iOS 后台配置指引
requiresInfoPlist boolean 是否需要维护 iOS Info.plist
infoPlistPath string 推荐检查的 Info.plist 路径
requiredBackgroundModes Array 必要后台模式列表
optionalBackgroundModes Array 可按真实业务额外配置的后台模式
steps Array 配置步骤
verification Array 验收步骤
warnings Array 平台限制和审核提示

applyKeepAliveIosBackgroundSuite(options)

参数 类型 必填 说明 默认值 可选参数
options ApplyKeepAliveIosBackgroundSuiteOptions iOS 后台套件启动参数 startImmediately / heartbeatIntervalMs / assumeConfigured / tag / success / fail / complete
options.startImmediately boolean 是否立即进入轻量运行态并启动心跳 true true / false
options.heartbeatIntervalMs number 心跳间隔,低于 5000 时会回退为 20000 20000
options.assumeConfigured boolean 调用方是否已人工确认 Info.plist 包含必要 UIBackgroundModes true true / false
options.tag string 运行标签,便于日志区分场景 ios-background
options.success function 成功回调,返回 KeepAliveIosBackgroundStatus
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
supported boolean 当前平台是否提供 iOS 后台套件
configured boolean 调用方是否已确认必要 UIBackgroundModes 配置
running boolean 轻量运行态是否正在运行
heartbeatCount number 运行期心跳数量
lastHeartbeatAt number 最近一次心跳时间
startedAt number 套件启动时间
elapsedMs number 套件已运行时长
infoPlistPath string 推荐检查的 iOS 配置文件路径
requiredBackgroundModes Array 必要后台模式列表
missingBackgroundModes Array 未确认的后台模式列表
assumeConfigured boolean 是否使用调用方人工确认结果
nextSteps Array 下一步原生联编和真机验收动作
warnings Array iOS 系统限制、审核和验收提醒

getKeepAliveIosBackgroundReport(options)

字段 类型 说明
platform string 当前平台
level KeepAliveReadinessLevel 当前准备度等级
ready boolean 配置和运行态是否达到可继续真机长跑验收的状态
status KeepAliveIosBackgroundStatus 当前 iOS 后台套件状态
guide KeepAliveIosBackgroundGuide iOS 后台配置指引
keepAliveStatus KeepAliveStatus 当前插件运行态
sampleCount number 报告采样数,当前取心跳数量
summary string 简短摘要
warnings Array 风险和限制说明
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// iOS 构建并安装新基座后,先查看配置指引,再启动 iOS 后台套件。
keepAlive.getKeepAliveIosBackgroundGuide({
  success(guide) {
    console.log('Info.plist path', guide.infoPlistPath)
    console.log('background modes', guide.requiredBackgroundModes)
    console.log('warnings', guide.warnings)
  }
})

// assumeConfigured 表示调用方已核对 Info.plist 中的 UIBackgroundModes。
keepAlive.applyKeepAliveIosBackgroundSuite({
  startImmediately: true,
  heartbeatIntervalMs: 20000,
  assumeConfigured: true,
  tag: 'ios-background-demo',
  success(status) {
    console.log('ios suite', status.configured, status.running, status.heartbeatCount)
  }
})

// 切后台或息屏一段时间后再次查询报告,用于观察 heartbeatCount 是否继续增长。
keepAlive.getKeepAliveIosBackgroundReport({
  success(report) {
    console.log('iOS background report', report.level, report.summary)
    console.log('required modes', report.status.requiredBackgroundModes)
  }
})

一键保活策略预设

getKeepAlivePresetOptions 返回内置策略预设列表,applyKeepAlivePreset 会把选中的预设写入当前保活配置,getKeepAlivePresetGuide 返回该预设的启用步骤、推荐动作、验收点和风险提示。Android 能力矩阵中的 strategyPresetstrue 时代表支持真实策略预设;其它平台返回明确降级说明,不伪造 Android 系统级保活能力。

内置预设包括:

预设 说明 推荐场景
balanced 均衡保活,降低系统打扰 常规后台心跳、轻量状态上报
strong 强保活,启用开机恢复、看门狗、WiFi 锁和屏幕唤醒恢复 IM 长连、设备在线、后台同步
ultra 极限保活,叠加更短看门狗间隔和静音音频建议 专用设备、企业内部分发、巡检终端
media 媒体保活,面向媒体前台服务边界和静音音频策略 语音播报、导航提示、后台音频类业务
task 任务保活,偏向周期性后台任务和稳定定时器 后台轮询、设备巡检、订单同步
参数 类型 必填 说明 默认值 可选参数
options StatusOptions 获取预设列表参数 success / fail / complete
options.success function 成功回调,返回 Array<KeepAlivePresetOption>
options.fail function 失败回调
options.complete function 完成回调

KeepAlivePresetOption 关键字段:

字段 类型 说明
id KeepAlivePresetId 预设 ID
title string 预设名称
descriptionText string 预设说明;iOS 端避免使用 description,防止与 Swift NSObject.description 冲突
recommendedScenes Array 推荐业务场景
stableTimerIntervalMs number 建议稳定定时器间隔
silentAudioRecommended boolean 是否建议启用静音音频策略
参数 类型 必填 说明 默认值 可选参数
options ApplyKeepAlivePresetOptions 应用或查询预设指引参数 presetId / startImmediately / success / fail / complete
options.presetId KeepAlivePresetId 预设 ID balanced / strong / ultra / media / task
options.startImmediately boolean 应用预设后是否立即启动保活服务 false true / false
options.success function 成功回调,applyKeepAlivePreset 返回 KeepAlivePresetApplyResultgetKeepAlivePresetGuide 返回 KeepAlivePresetGuide
options.fail function 失败回调;预设不存在或平台不支持时触发
options.complete function 完成回调
字段 类型 说明
presetId KeepAlivePresetId 已应用的预设 ID
appliedConfig KeepAliveConfig 应用预设后的完整保活配置
status KeepAliveStatus 应用预设后的运行状态
stableTimerIntervalMs number 建议用于 startStableTimer 的间隔
stableTimerTag string 建议用于稳定定时器的业务标记
silentAudioRecommended boolean 是否建议启用静音音频保活策略
recommendedActions Array 后续建议调用的 API,如权限诊断、厂商指引、静音音频或稳定定时器
warnings Array 系统限制、合规和自定义基座提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 先展示可选预设,便于在业务后台或调试页中按场景选择。
keepAlive.getKeepAlivePresetOptions({
  success(list) {
    console.log('preset options', list)
  }
})

// 查询极限保活的启用步骤和验收清单。
keepAlive.getKeepAlivePresetGuide({
  presetId: 'ultra',
  success(guide) {
    console.log('guide steps', guide.steps)
    console.log('guide warnings', guide.warnings)
  }
})

// 应用极限保活预设。该 API 会写入配置;后续仍应按 recommendedActions 完成授权、白名单和真机验收。
keepAlive.applyKeepAlivePreset({
  presetId: 'ultra',
  startImmediately: false,
  success(result) {
    console.log('applied config', result.appliedConfig)
    console.log('recommended actions', result.recommendedActions)
  }
})

稳定后台任务定时器

startStableTimer 启动稳定后台任务定时器。Android 端会在真前台服务运行期间使用运行态定时器派发 tick,并通过 AlarmManager 设置兜底广播;Android 6+ 且已允许精确闹钟时优先使用 setExactAndAllowWhileIdle,否则降级为 setAndAllowWhileIdle。该能力适合后台轮询、设备巡检、心跳上报等业务任务;它仍受系统省电策略、通知权限、电池优化白名单和厂商 ROM 后台限制影响。

参数 类型 必填 说明 默认值 可选参数
options StartStableTimerOptions 启动参数 intervalMs / tag / success / fail / complete
options.intervalMs number 定时器间隔,Android 小于 5000ms 会按 5000ms 处理 5000
options.tag string 业务任务标记,回调事件会原样返回 stable
options.success function 成功回调,返回 KeepAliveStableTimerStatus
options.fail function 失败回调;未注册或未启动保活时会失败
options.complete function 完成回调
字段 类型 说明
enabled boolean 是否已启用稳定定时器
running boolean 当前是否随保活服务运行中
intervalMs number 实际间隔
tick number 已触发次数
lastTickAt number 最近触发时间戳
tag string 业务任务标记
alarmBacked boolean 是否已设置 AlarmManager 兜底广播
requiresForegroundService boolean 是否依赖 Android 前台服务
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 建议在 register 和 startKeepAlive 成功后启动稳定后台任务定时器。
keepAlive.setOnStableTimerListener({
  listener(event) {
    console.log('stable timer tick', event.tick, event.source, event.tag)
  }
})

keepAlive.startStableTimer({
  intervalMs: 30000,
  tag: 'sync-order',
  success(status) {
    console.log('stable timer status', status)
  }
})

JobScheduler 兜底守护

setJobSchedulerGuardian 用于启停 Android JobScheduler 兜底守护,getJobSchedulerGuardianStatus 用于查询系统作业是否已经调度。Android 端会注册 KeepAliveJobService,在系统允许的周期窗口内触发恢复链路;它适合做前台服务、开机恢复和 AlarmManager 看门狗之外的第三层保活兜底。该能力遵守 Android JobScheduler 的周期限制,默认和最小间隔均为 15 分钟,不承诺秒级任务调度。

Android Manifest 会声明 uts.lizhaoappkeepalive.KeepAliveJobService,并使用 android.permission.BIND_JOB_SERVICE 绑定 JobService。修改该能力后必须重新打 Android 自定义基座或重新运行原生联编,仅更新 wgt/appResource 不能替换已经编译进基座的 JobService。

setJobSchedulerGuardian(options)

参数 类型 必填 说明 默认值 可选参数
options SetJobSchedulerGuardianOptions JobScheduler 守护配置 enabled / intervalMs / success / fail / complete
options.enabled boolean 是否启用 JobScheduler 兜底守护 true / false
options.intervalMs number 周期调度间隔,Android 小于 900000ms 会按 900000ms 处理 900000
options.success function 成功回调,返回 KeepAliveJobSchedulerStatus
options.fail function 失败回调;上下文不可用或平台不支持时触发
options.complete function 完成回调

getJobSchedulerGuardianStatus(options)

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 查询参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveJobSchedulerStatus
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
supported boolean 当前平台是否支持 JobScheduler 兜底守护
enabled boolean 当前配置是否启用
scheduled boolean 最近一次是否已成功提交到系统 JobScheduler
jobId number Android 系统作业 ID
intervalMs number 实际周期间隔
minIntervalMs number 插件内置最小周期间隔
lastRunAt number 最近一次 JobService 触发时间戳
runCount number JobService 已触发次数
persisted boolean 是否请求系统持久化调度
requiresCharging boolean 是否要求充电,本插件默认不要求
requiresDeviceIdle boolean 是否要求设备空闲,本插件默认不要求
reason string 最近一次调度、取消或失败说明
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 建议在 register 之后开启 JobScheduler 兜底守护,系统会按允许的周期窗口触发恢复。
keepAlive.setJobSchedulerGuardian({
  enabled: true,
  intervalMs: 900000,
  success(status) {
    console.log('job scheduled', status.scheduled, status.reason)
  }
})

// 真机验收时可配合 adb shell dumpsys jobscheduler | findstr lizhao 复核系统作业。
keepAlive.getJobSchedulerGuardianStatus({
  success(status) {
    console.log('job status', status.enabled, status.scheduled, status.runCount)
  }
})

保活证据包

getKeepAliveEvidencePack 返回一份结构化 KeepAliveEvidencePack,用于真机验收、插件市场演示和售后排障。Android 端会聚合当前状态、能力矩阵、保活巡检、准备度报告、权限诊断、系统限制诊断、厂商 ROM 指引、策略预设指引、JobScheduler 兜底状态和后台任务状态列表。该 API 不写文件、不申请存储权限,业务可自行 JSON.stringify 后复制、上传或附加到工单。

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 获取证据包参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveEvidencePack
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
evidenceId string 本次证据包 ID
generatedAt number 生成时间戳
platform string 当前平台
pluginVersion string 插件版本
summary string 简短摘要,便于日志中快速判断
status KeepAliveStatus 当前保活状态
capabilities KeepAliveCapabilities 当前能力矩阵
healthReport KeepAliveHealthReport 保活巡检报告
readinessReport KeepAliveReadinessReport 保活准备度报告
permissionStatus KeepAliveSystemPermissionStatus 权限诊断结果
restrictionStatus KeepAliveRestrictionStatus 系统限制诊断结果
vendorGuide KeepAliveVendorGuide 厂商 ROM 指引
presetGuide KeepAlivePresetGuide 推荐策略预设指引
jobSchedulerStatus KeepAliveJobSchedulerStatus JobScheduler 兜底守护状态
taskStatuses Array 后台任务状态和执行结果统计
warnings Array 证据包限制和注意事项
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 售后排障时可把证据包 JSON 发给技术支持,避免只靠截图猜测保活状态。
keepAlive.getKeepAliveEvidencePack({
  success(pack) {
    console.log('keepalive evidence', JSON.stringify(pack))
  }
})

保活巡航守护

startKeepAliveCruiseGuardian 用于在 Android 真前台保活运行期间启动持续巡航。插件会按 intervalMs 周期采样当前 KeepAliveStatus、巡检报告、准备度报告和长跑报告,生成 KeepAliveCruiseGuardianSample;当 aliveScore 低于 lowScoreThreshold 时记录 warning / critical,并可在 autoHealEnabled=true 时触发插件内部合法 autoHealKeepAlive。能力矩阵中的 cruiseGuardiantrue 时代表当前平台支持真实 Android 巡航守护;其它平台返回 cruiseGuardian=false 的降级边界。

巡航守护不会自动申请权限、不会修改厂商 ROM 设置,也不会承诺绕过 Android 系统、Doze 或厂商后台限制。它适合在客户现场、插件市场演示和长时间真机复测时持续观察保活链路是否变弱,并把 autoHealTriggeredCount / samples / supportReport 作为交付证据。

startKeepAliveCruiseGuardian(options)

参数 类型 必填 说明 默认值 可选参数
options StartKeepAliveCruiseGuardianOptions 启动巡航守护参数 intervalMs / lowScoreThreshold / autoHealEnabled / autoHealPresetId / maxSamples / includeSupportReport / success / fail / complete
options.intervalMs number 采样间隔,过小会自动提升到 15000ms 60000 15000-3600000
options.lowScoreThreshold number 活性评分低分阈值 70 30-95
options.autoHealEnabled boolean 低分时是否触发插件内部合法自愈 false true / false
options.autoHealPresetId string 自动自愈使用的策略预设 strong balanced / strong / ultra / media / task
options.maxSamples number 内存中保留的最大采样数量 120 5-1000
options.includeSupportReport boolean 保留给业务侧语义,报告接口会输出支持报告 true true / false
options.success function 成功回调,返回 KeepAliveCruiseGuardianStatus
options.fail function 失败回调;前台保活未运行时触发
options.complete function 完成回调

getKeepAliveCruiseGuardianReport(options)

字段 类型 说明
reportId string 本次巡航报告 ID
cruiseGuardian boolean 当前平台是否支持真实 Android 巡航守护
summaryText string 巡航摘要,包含运行态、等级、采样数、最低分和自愈次数
status KeepAliveCruiseGuardianStatus 当前巡航状态
samples Array 采样列表
supportReport KeepAliveSupportReport 当前售后/交付支持报告
autoHealReport KeepAliveAutoHealReport 最近一次巡航触发的自愈报告,或当前自愈状态
nextSteps Array 下一步复测与交付建议
warnings Array 系统限制、低分和自愈边界提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 先 register -> startKeepAlive,确认前台保活处于 running 后再启动巡航守护。
keepAlive.startKeepAliveCruiseGuardian({
  intervalMs: 30000,
  lowScoreThreshold: 70,
  autoHealEnabled: true,
  autoHealPresetId: 'strong',
  maxSamples: 60,
  success(status) {
    console.log('cruiseGuardian status', status.cruiseGuardian, status.running)
  },
  fail(err) {
    console.log('startKeepAliveCruiseGuardian failed', err)
  }
})

// 交付或售后时导出巡航报告,查看 autoHealTriggeredCount 和最近采样。
keepAlive.getKeepAliveCruiseGuardianReport({
  success(report) {
    console.log('cruise summary', report.summaryText)
    console.log('autoHealTriggeredCount', report.status.autoHealTriggeredCount)
    console.log('samples', report.samples)
  }
})

自愈后复测计划

getKeepAliveAutoHealRetestPlan 返回结构化 KeepAliveAutoHealRetestPlan,用于把一键自愈后的验证动作拆成可执行步骤。Android 端会聚合 autoHealEvidenceSummarygetKeepAliveAutoHealEvidenceLoopgetKeepAliveAcceptancePlanstartKeepAliveSurvivalTest / getKeepAliveSurvivalTestStatusgetKeepAliveRecoveryEvidenceSnapshotgetKeepAliveRunReportgetKeepAliveSupportReport,输出 stages / apiPath / passCriteria / evidenceFields / markdown。能力矩阵中的 autoHealRetestPlan=true 表示当前 Android 自定义基座支持真实自愈后复测计划;其它平台返回 autoHealRetestPlan=false 的降级边界,不伪造 Android 强保活复测通过证据。

该计划只生成复测路径和证据字段,不自动打开系统设置、不自动启动长时间测试,也不会承诺绕过 Android 系统、Doze 或厂商 ROM 后台限制。正式交付建议按 autoHealKeepAlive -> getKeepAliveAutoHealEvidenceLoop -> getKeepAliveAutoHealRetestPlan -> startKeepAliveSurvivalTest -> getKeepAliveSupportReport 完成闭环。

getKeepAliveAutoHealRetestPlan(options)

参数

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveAutoHealRetestPlanOptions 获取自愈后复测计划参数 profile / includeMarkdown / includeSupportReport / includeAcceptancePlan / includeRecoveryEvidence / success / fail / complete
options.profile KeepAliveAutoHealRetestPlanProfile 复测档位 standard quick / standard / strict / market
options.includeMarkdown boolean 是否生成可复制 Markdown true true / false
options.includeSupportReport boolean 是否聚合售后/交付支持报告 true true / false
options.includeAcceptancePlan boolean 是否聚合交付验收计划 true true / false
options.includeRecoveryEvidence boolean 是否聚合恢复证据快照 true true / false
options.success function 成功回调,返回 KeepAliveAutoHealRetestPlan
options.fail function 失败回调
options.complete function 完成回调

返回值

字段 类型 说明
planId string 本次自愈复测计划 ID
autoHealRetestPlan boolean 当前平台是否支持真实 Android 自愈后复测计划
profile KeepAliveAutoHealRetestPlanProfile 复测档位
ready boolean 当前证据是否达到可交付状态
score number 聚合评分
stageCount number 复测阶段数量
stages Array 阶段列表,每阶段包含动作、API、通过标准和证据字段
apiPath Array 推荐调用路径
passCriteria Array 通过标准
evidenceFields Array 需要归档的证据字段
autoHealEvidenceSummary KeepAliveAutoHealEvidenceSummary 最近一次自愈闭环摘要
autoHealEvidenceLoop KeepAliveAutoHealEvidenceLoop 最近一次自愈闭环证据
acceptancePlan KeepAliveAcceptancePlan 交付验收计划
survivalTestStatus KeepAliveSurvivalTestStatus 生存力测试状态
recoveryEvidenceSnapshot KeepAliveRecoveryEvidenceSnapshot 恢复证据快照
runReport KeepAliveRunReport 长跑观测报告
supportReport KeepAliveSupportReport 售后/交付支持报告
markdown string 可复制的复测计划 Markdown
nextSteps Array 下一步动作
warnings Array 系统限制、证据不足和人工确认提醒

示例

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 一键自愈后生成复测计划,按 apiPath 继续执行长跑和交付报告归档。
keepAlive.getKeepAliveAutoHealRetestPlan({
  profile: 'standard',
  includeMarkdown: true,
  includeSupportReport: true,
  includeAcceptancePlan: true,
  includeRecoveryEvidence: true,
  success(plan) {
    console.log('autoHealRetestPlan', plan.autoHealRetestPlan)
    console.log('apiPath', plan.apiPath.join(' -> '))
    console.log('passCriteria', plan.passCriteria)
    console.log('autoHealEvidenceSummary', plan.autoHealEvidenceSummary)
  },
  fail(err) {
    console.log('getKeepAliveAutoHealRetestPlan failed', err)
  }
})

保活证据会话

startKeepAliveEvidenceSession / getKeepAliveEvidenceSession / finishKeepAliveEvidenceSession 返回结构化 KeepAliveEvidenceSession,用于把同一轮 Android 保活验收串成可交付证据。Android 端会聚合 getKeepAliveMarketReadinessReportgetKeepAliveAutoHealRetestPlangetKeepAliveSupportReportgetKeepAliveEventTimelineexportKeepAliveDeliveryArchive,输出 stages / evidenceFields / nextSteps / warnings / markdown。能力矩阵中的 evidenceSession=true 表示当前 Android 自定义基座支持真实证据会话;其它平台返回 evidenceSession=false 的降级边界,不能当作 Android 保活验收通过证据。

证据会话只整理和归档已有验收链路,不会承诺绕过 Android 系统、Doze 或厂商 ROM 后台限制。正式交付建议按 startKeepAliveEvidenceSession -> autoHealKeepAlive -> getKeepAliveAutoHealRetestPlan -> startKeepAliveSurvivalTest -> getKeepAliveSupportReport -> finishKeepAliveEvidenceSession 留存一轮闭环证据。

startKeepAliveEvidenceSession(options)

参数

参数 类型 必填 说明 默认值 可选参数
options StartKeepAliveEvidenceSessionOptions 开始保活证据会话参数 tag / includeMarkdown / includeDeliveryArchive / success / fail / complete
options.tag string 本轮证据会话标签 keepalive-delivery
options.includeMarkdown boolean 是否返回 Markdown false true / false
options.includeDeliveryArchive boolean 是否在开始时导出归档包 false true / false
options.success function 成功回调,返回 KeepAliveEvidenceSession
options.fail function 失败回调
options.complete function 完成回调

getKeepAliveEvidenceSession(options)

参数

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveEvidenceSessionOptions 查询保活证据会话参数 sessionId / includeMarkdown / includeDeliveryArchive / success / fail / complete
options.sessionId string 指定会话 ID;为空时使用当前会话 当前会话
options.includeMarkdown boolean 是否返回 Markdown false true / false
options.includeDeliveryArchive boolean 查询时是否导出归档包 false true / false
options.success function 成功回调,返回 KeepAliveEvidenceSession
options.fail function 失败回调
options.complete function 完成回调

finishKeepAliveEvidenceSession(options)

参数

参数 类型 必填 说明 默认值 可选参数
options FinishKeepAliveEvidenceSessionOptions 结束保活证据会话参数 sessionId / includeMarkdown / includeDeliveryArchive / success / fail / complete
options.sessionId string 指定会话 ID;为空时使用当前会话 当前会话
options.includeMarkdown boolean 是否返回 Markdown true true / false
options.includeDeliveryArchive boolean 结束时是否导出 ZIP 归档包 false true / false
options.success function 成功回调,返回 KeepAliveEvidenceSession
options.fail function 失败回调
options.complete function 完成回调

返回值

字段 类型 说明
sessionId string 本次保活证据会话 ID
evidenceSession boolean 当前平台是否支持真实 Android 保活证据会话
tag string 会话标签
running boolean 会话是否仍在进行
ready boolean 当前证据是否达到可交付状态
score number 聚合评分
stageCount number 证据阶段数量
stages Array 阶段列表
evidenceFields Array 建议归档的 API 和证据字段
marketReadinessReport KeepAliveMarketReadinessReport 插件市场发布体检报告
autoHealRetestPlan KeepAliveAutoHealRetestPlan 自愈后复测计划
supportReport KeepAliveSupportReport 售后/交付支持报告
eventTimeline KeepAliveEventTimeline 事件时间线
deliveryArchiveResult ExportKeepAliveDeliveryArchiveResult 交付归档包导出结果
markdown string 可复制的会话 Markdown
nextSteps Array 下一步动作
warnings Array 系统限制、证据不足和人工确认提醒

示例

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 开始一轮 Android 保活交付验收证据会话。
keepAlive.startKeepAliveEvidenceSession({
  tag: 'customer-acceptance',
  includeMarkdown: true,
  success(session) {
    console.log('startKeepAliveEvidenceSession', session.sessionId, session.evidenceSession)
  }
})

// 查询当前证据会话,确认阶段和证据字段。
keepAlive.getKeepAliveEvidenceSession({
  includeMarkdown: true,
  success(session) {
    console.log('KeepAliveEvidenceSession', session.stageCount, session.evidenceFields)
  }
})

// 结束会话时可导出 ZIP 归档包,供售后工单或市场审核留档。
keepAlive.finishKeepAliveEvidenceSession({
  includeMarkdown: true,
  includeDeliveryArchive: true,
  success(session) {
    console.log('deliveryArchiveResult', session.deliveryArchiveResult.archiveFilePath)
  }
})

交付验收计划

getKeepAliveAcceptancePlan 返回结构化 KeepAliveAcceptancePlan,用于把 Android 自定义基座验收拆成可执行阶段。Android 端会按 quick / standard / strict / market 档位生成 stagesadbCommandspassCriteriaevidenceFields 和可复制 markdown,覆盖基座完整性、前台服务启动、JobScheduler 兜底、后台长跑、息屏锁屏和厂商 ROM 白名单。能力矩阵中的 acceptancePlantrue 时代表当前平台支持真实 Android 交付验收计划;其它平台返回 acceptancePlan=false 的降级边界。

该计划只返回测试步骤和归档字段,不写本地文件、不申请存储权限,也不承诺绕过 Android 系统、Doze 或厂商 ROM 后台限制。正式交付时建议先调用 getKeepAliveBaseIntegrityReport,再按计划执行 startKeepAliveSurvivalTest,最后用 getKeepAliveSupportReport 导出 Markdown。

getKeepAliveAcceptancePlan(options)

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveAcceptancePlanOptions 获取交付验收计划参数 profile / includeAdbCommands / includeMarkdown / includeSupportReport / success / fail / complete
options.profile string 验收档位 standard quick / standard / strict / market
options.includeAdbCommands boolean 是否返回 ADB 辅助命令 true true / false
options.includeMarkdown boolean 是否返回可复制 Markdown true true / false
options.includeSupportReport boolean 是否在计划中包含支持报告摘要 true true / false
options.success function 成功回调,返回 KeepAliveAcceptancePlan
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
planId string 本次交付验收计划 ID
acceptancePlan boolean 当前平台是否支持真实 Android 验收计划
profile string 当前计划档位
totalDurationMs number 建议验收总时长
stageCount number 验收阶段数量
stages Array 阶段列表,每阶段包含动作、API、ADB 命令、通过标准和证据字段
adbCommands Array 去重后的 ADB 辅助命令
passCriteria Array 去重后的通过标准
evidenceFields Array 建议归档字段
supportReport KeepAliveSupportReport 当前状态的售后/交付支持报告
markdown string 可复制的交付验收计划 Markdown
nextSteps Array 下一步执行建议
warnings Array 系统限制、厂商 ROM 和自定义基座提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 生成标准交付验收计划,用于 Android 自定义基座真机复测和客户交付归档。
keepAlive.getKeepAliveAcceptancePlan({
  profile: 'standard',
  includeAdbCommands: true,
  includeMarkdown: true,
  includeSupportReport: true,
  success(plan) {
    console.log('acceptancePlan', plan.acceptancePlan)
    console.log('stages', plan.stages)
    console.log('adbCommands', plan.adbCommands)
    console.log('markdown', plan.markdown)
  },
  fail(err) {
    console.log('getKeepAliveAcceptancePlan failed', err)
  }
})

售后/交付支持报告

getKeepAliveSupportReport 返回结构化 KeepAliveSupportReport,用于插件市场演示、客户交付复测和售后工单归档。Android 端会聚合 getKeepAliveBaseIntegrityReportgetKeepAliveDiagnosticBundlegetKeepAliveAcceptanceReportgetKeepAliveRunReportgetKeepAliveEventTimeline,输出 summary / nextSteps / warnings,并生成可复制的 markdown。能力矩阵中的 supportReporttrue 时代表当前平台支持真实 Android 售后/交付支持报告;其它平台返回明确降级报告。

该报告只通过回调返回,不写本地文件、不申请存储权限,也不自动上传。业务可以在用户授权后把 markdown 或完整 JSON 发到自己的售后系统。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveSupportReportOptions 获取售后/交付支持报告参数 strictMode / includeTimeline / timelineLimit / includeMarkdown / success / fail / complete
options.strictMode boolean 是否把未完成采样、未启动服务等人工项按失败处理 false true / false
options.includeTimeline boolean 是否聚合事件时间线 true true / false
options.timelineLimit number 支持报告中包含的最近事件数量 50 1-200
options.includeMarkdown boolean 是否生成可复制 Markdown true true / false
options.success function 成功回调,返回 KeepAliveSupportReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
reportId string 本次支持报告 ID
supportReport boolean 当前平台是否支持真实 Android 支持报告
summaryText string 一行摘要
summary KeepAliveSupportSummary level / ready / score / issueCount / actionCount
markdown string 可复制到工单或交付记录的 Markdown 文本
baseIntegrityReport KeepAliveBaseIntegrityReport 自定义基座完整性报告
diagnosticBundle KeepAliveDiagnosticBundle 售后诊断包
acceptanceReport KeepAliveAcceptanceReport 保活验收报告
runReport KeepAliveRunReport 长跑观测报告
eventTimeline KeepAliveEventTimeline 事件时间线
nextSteps Array 聚合后的下一步动作
warnings Array 系统限制和报告边界
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 交付或售后时生成一份可复制 Markdown,同时保留完整 JSON。
keepAlive.getKeepAliveSupportReport({
  includeTimeline: true,
  timelineLimit: 50,
  includeMarkdown: true,
  success(report) {
    console.log('support summary', report.summaryText)
    console.log('support markdown', report.markdown)
  }
})

恢复证据快照

getKeepAliveRecoveryEvidenceSnapshot 返回结构化 KeepAliveRecoveryEvidenceSnapshot,用于把 Android 恢复链路的关键证据合成一份快照。Android 端会聚合 taskRemovedRecoveryReportserviceDestroyRecoveryReportgetKeepAliveEventTimelinepersistentEventTimeline 证据和 getKeepAliveRunReport,输出 recoveryEvidenceSnapshot / level / score / evidenceItems / nextSteps / warnings / markdown

该能力使用 recovery-evidence-snapshot 标记,定位是客户验收、插件市场演示和售后工单归档,不承诺绕过 Android 系统强杀、用户强行停止、Doze 或厂商 ROM 后台限制。其它平台返回 recoveryEvidenceSnapshot=false / level=unsupported 的降级边界,不能作为 Android 恢复证据。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveRecoveryEvidenceSnapshotOptions 获取恢复证据快照参数 includeMarkdown / timelineLimit / strictMode / success / fail / complete
options.includeMarkdown boolean 是否生成 Markdown true true / false
options.timelineLimit number 聚合的最近事件数量 50 1-200
options.strictMode boolean 是否按严格模式聚合长跑报告 false true / false
options.success function 成功回调,返回 KeepAliveRecoveryEvidenceSnapshot
options.fail function 失败回调;Android 上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
snapshotId string 本次快照 ID
recoveryEvidenceSnapshot boolean 当前平台是否支持真实 Android 恢复证据快照
level string ready / warning / blocked / unsupported
ready boolean 是否达到可继续交付验收的状态
score number 恢复证据评分
summaryText string 一行摘要
markdown string 可复制到工单或交付记录的 Markdown
taskRemovedRecoveryReport KeepAliveTaskRemovedRecoveryReport 最近任务划掉恢复报告
serviceDestroyRecoveryReport KeepAliveServiceDestroyRecoveryReport 服务销毁自恢复报告
eventTimeline KeepAliveEventTimeline 持久化事件时间线
runReport KeepAliveRunReport 长跑观测报告
evidenceItems Array 恢复证据检查项
nextSteps Array 下一步动作
warnings Array 系统限制和证据边界
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 客户复测或售后工单前生成一份恢复证据快照,直接查看恢复链路是否完整。
keepAlive.getKeepAliveRecoveryEvidenceSnapshot({
  includeMarkdown: true,
  timelineLimit: 50,
  success(snapshot) {
    console.log('recoveryEvidenceSnapshot', snapshot.recoveryEvidenceSnapshot, snapshot.level, snapshot.score)
    console.log('taskRemovedRecoveryReport', snapshot.taskRemovedRecoveryReport.summaryText)
    console.log('serviceDestroyRecoveryReport', snapshot.serviceDestroyRecoveryReport.summaryText)
    console.log('persistentEventTimeline', snapshot.eventTimeline.persistent, snapshot.eventTimeline.persistedTotal)
    console.log('markdown', snapshot.markdown)
  }
})

自定义基座完整性报告

getKeepAliveBaseIntegrityReport 返回结构化 KeepAliveBaseIntegrityReport,用于用户重新制作 Android 自定义基座后的第一步验收。Android 端会聚合基座桥接、Manifest 类名、前台服务运行态、JobScheduler、通知权限、电池优化、精确闹钟、诊断/验收/长跑报告和事件时间线能力,输出 score / ready / requiredPassed / checks / nextSteps / warnings。能力矩阵中的 baseIntegritytrue 时代表当前平台支持真实 Android 基座完整性自检;其它平台返回明确降级报告,不把 fallback 当作 Android 基座通过证据。

该报告不写文件、不申请存储权限,也不承诺绕过 Android 系统或厂商 ROM 后台限制。它的定位是快速回答“我刚打的自定义基座是否真的包含保活插件桥接和关键能力”,通过后仍应继续做锁屏、后台、息屏和厂商 ROM 长跑验收。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveBaseIntegrityReportOptions 获取自定义基座完整性报告参数 strictMode / includeRunReport / success / fail / complete
options.strictMode boolean 是否把未启动前台服务、未产生采样等人工项按失败处理 false true / false
options.includeRunReport boolean 是否同时聚合长跑观测报告 true true / false
options.success function 成功回调,返回 KeepAliveBaseIntegrityReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
reportId string 本次基座自检报告 ID
generatedAt number 生成时间戳
platform string 当前平台
pluginVersion string 插件版本
baseIntegrity boolean 当前平台是否支持真实 Android 基座完整性自检
ready boolean 是否达到可继续长时间真机验收的状态
score number 综合评分
requiredPassed number 必选项通过数
requiredTotal number 必选项总数
checks Array 基座桥接、Manifest、前台服务、JobScheduler、权限、电池优化和报告 API 检查项
acceptanceReport KeepAliveAcceptanceReport 同步生成的保活验收报告
runReport KeepAliveRunReport 同步生成的长跑观测报告
permissionStatus KeepAliveSystemPermissionStatus 通知、精确闹钟、电池优化和厂商设置诊断
jobSchedulerStatus KeepAliveJobSchedulerStatus JobScheduler 兜底守护状态
nextSteps Array 下一步授权、重打基座、启动服务或长跑验收建议
warnings Array 系统限制和报告边界提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 重打 Android 自定义基座后,先运行基座自检,再进入锁屏/后台/息屏长跑验收。
keepAlive.getKeepAliveBaseIntegrityReport({
  strictMode: false,
  includeRunReport: true,
  success(report) {
    console.log('baseIntegrity', report.baseIntegrity, report.score, report.ready)
    console.log('基座检查项', JSON.stringify(report.checks))
    console.log('下一步', JSON.stringify(report.nextSteps))
  }
})

事件时间线与恢复审计

getKeepAliveEventTimeline 返回结构化 KeepAliveEventTimeline,用于查看运行期保活事件时间线。Android 端会记录 emitKeepAliveEvent / recordKeepAliveEvent 进入的关键事件,包括前后台切换、通知点击、通知动作、开机恢复、包更新恢复、屏幕唤醒、看门狗、JobScheduler、前台服务启动停止、心跳、生存力测试和后台任务。能力矩阵中的 eventTimelinetrue 时代表当前平台支持真实 Android 事件时间线;persistentEventTimelinetrue 时代表 Android 会把最近 200 条审计事件持久化到应用私有 SharedPreferences

持久化事件时间线使用 persistent-event-timeline 能力标记,存储 key 为 storageKey 返回值,当前实现只写插件运行态摘要字段,不持久化业务 payload,不申请公共存储权限,也不上传数据。页面重开或进程恢复后,插件会先从 SharedPreferences 恢复历史事件,并通过 restored / persistedTotal / persistedAt 告知是否来自持久化数据;其它平台返回明确降级时间线,不伪造 Android 恢复证据。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveEventTimelineOptions 获取事件时间线参数 limit / since / eventName / includePayload / success / fail / complete
options.limit number 返回最近多少条事件,最大 200 50
options.since number 只返回该时间戳之后的事件 0
options.eventName KeepAliveEventName 只返回指定事件名 watchdog / jobScheduler / foreground / background / notificationAction / heartbeat / task
options.includePayload boolean 是否包含原始事件 payload true true / false
options.success function 成功回调,返回 KeepAliveEventTimeline
options.fail function 失败回调;平台不支持或上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
timelineId string 本次时间线报告 ID
generatedAt number 生成时间戳
platform string 当前平台
pluginVersion string 插件版本
eventTimeline boolean 当前平台是否支持真实事件时间线
persistent boolean 当前返回是否来自支持持久化的时间线能力
restored boolean 是否曾从 SharedPreferences 恢复历史时间线
persistedAt number 最近一次写入持久化时间线的时间戳
persistedTotal number 当前已持久化/可恢复的事件数量
storageKey string 持久化事件时间线的逻辑存储 key
total number 当前内存中保留的事件总数
returned number 本次返回事件数
firstEventAt number 本次返回第一条事件时间
lastEventAt number 本次返回最后一条事件时间
events Array 事件列表,包含 index / name / timestamp / runtimeStatus / source / summary
status KeepAliveStatus 查询时的保活状态
warnings Array 内存时间线、系统限制和审计边界
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 售后排障时可先获取最近 50 条事件,判断是看门狗、JobScheduler 还是用户操作触发恢复。
keepAlive.getKeepAliveEventTimeline({
  limit: 50,
  includePayload: false,
  success(timeline) {
    console.log('eventTimeline', timeline.eventTimeline, timeline.persistent, timeline.total)
    console.log('persistent-event-timeline', timeline.storageKey, timeline.persistedTotal, timeline.restored)
    console.log('恢复审计', JSON.stringify(timeline.events))
  }
})

// 完成一次复测后可清空内存与 SharedPreferences 中的持久化时间线,再开始下一轮测试。
keepAlive.clearKeepAliveEventTimeline({
  success(res) {
    console.log('cleared timeline events', res.cleared, res.persistent, res.storageKey)
  }
})

售后诊断包

getKeepAliveDiagnosticBundle 返回结构化 KeepAliveDiagnosticBundle,面向插件市场演示、客户现场排障和售后工单。Android 端会把当前状态、能力矩阵、保活巡检、准备度报告、保活证据包、一键自愈报告、JobScheduler 兜底状态、稳定后台任务定时器、静音音频状态、后台任务状态和生存力测试状态聚合为一份诊断 JSON,并输出 summary / recommendedActions / warnings。能力矩阵中的 diagnosticKittrue 时代表当前平台支持真实售后诊断包;其它平台返回明确降级诊断包。

诊断包只通过回调返回,不写本地文件、不申请存储权限,也不采集账号、Token、定位、通讯录等敏感信息。业务如需上传诊断 JSON,应按自身隐私政策和用户授权流程处理。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveDiagnosticBundleOptions 获取售后诊断包参数 includeEvidencePack / includeAutoHealReport / includeTaskStatuses / includeSurvivalTestStatus / success / fail / complete
options.includeEvidencePack boolean 是否包含完整保活证据包 true true / false
options.includeAutoHealReport boolean 是否包含一键自愈报告 true true / false
options.includeTaskStatuses boolean 是否包含后台任务状态列表 true true / false
options.includeSurvivalTestStatus boolean 是否包含生存力测试状态 true true / false
options.success function 成功回调,返回 KeepAliveDiagnosticBundle
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
bundleId string 本次诊断包 ID
generatedAt number 生成时间戳
platform string 当前平台
pluginVersion string 插件版本
summary string 摘要,便于日志和工单快速判断
status KeepAliveStatus 当前保活状态
capabilities KeepAliveCapabilities 当前能力矩阵,重点关注 diagnosticKit
healthReport KeepAliveHealthReport 保活巡检报告
readinessReport KeepAliveReadinessReport 保活准备度报告
evidencePack KeepAliveEvidencePack 保活证据包
autoHealReport KeepAliveAutoHealReport 一键自愈报告
jobSchedulerStatus KeepAliveJobSchedulerStatus JobScheduler 兜底守护状态
stableTimerStatus KeepAliveStableTimerStatus 稳定后台任务定时器状态
silentAudioStatus KeepAliveSilentAudioStatus 静音音频保活状态
taskStatuses Array 后台任务状态和执行结果统计
survivalTestStatus KeepAliveSurvivalTestStatus 生存力测试状态
recommendedActions Array 下一步处理建议
warnings Array 隐私、系统限制和验收边界提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 客户现场排障时生成一份完整诊断 JSON,便于对比授权、运行态和守护链路。
keepAlive.getKeepAliveDiagnosticBundle({
  includeEvidencePack: true,
  includeAutoHealReport: true,
  includeTaskStatuses: true,
  includeSurvivalTestStatus: true,
  success(bundle) {
    console.log('keepalive diagnostic', JSON.stringify(bundle))
    console.log('diagnosticKit', bundle.capabilities.diagnosticKit, bundle.summary)
  }
})

保活验收报告

getKeepAliveAcceptanceReport 返回结构化 KeepAliveAcceptanceReport,用于把诊断包进一步整理成客户可读的验收清单。Android 端会基于 KeepAliveDiagnosticBundle 生成 checks,每个检查项都有 passed / warning / failed / manual / unsupported 状态、分值、证据和下一步建议。能力矩阵中的 acceptanceReporttrue 时代表当前平台支持真实 Android 保活验收报告;其它平台返回明确降级报告。

验收报告不会替代真机长跑测试,也不会把未验证项目伪造成通过。未启动前台服务、未授权通知、未调度 JobScheduler、未运行生存力测试或未注册任务时,会在 checks / nextSteps / warnings 中明确暴露。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveAcceptanceReportOptions 获取保活验收报告参数 includeOptionalChecks / includeDiagnosticBundle / strictMode / success / fail / complete
options.includeOptionalChecks boolean 是否包含静音音频、WiFi 锁、通知动作等可选检查项 true true / false
options.includeDiagnosticBundle boolean 是否在返回值中包含完整诊断包;当前 Android 固定包含,便于工单复核 true true / false
options.strictMode boolean 是否把未运行生存力测试视为失败;关闭时标记为需人工验收 false true / false
options.success function 成功回调,返回 KeepAliveAcceptanceReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
reportId string 本次验收报告 ID
generatedAt number 生成时间戳
platform string 当前平台
pluginVersion string 插件版本
score number 验收综合分
level KeepAliveAcceptanceLevel 验收等级,passed / warning / failed / unsupported
passed boolean 是否整体通过
requiredPassed number 必选检查通过数量
requiredTotal number 必选检查总数
optionalPassed number 可选检查通过数量
optionalTotal number 可选检查总数
summary string 报告摘要
diagnosticBundle KeepAliveDiagnosticBundle 本次验收依赖的诊断包
checks Array 验收清单,每项包含状态、分值、证据和下一步
nextSteps Array 后续处理建议
warnings Array 系统限制、人工验收和真机长跑边界
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 用户重新打 Android 自定义基座后,可先生成验收报告,快速判断还缺哪些授权和长跑验证。
keepAlive.getKeepAliveAcceptanceReport({
  includeOptionalChecks: true,
  includeDiagnosticBundle: true,
  strictMode: false,
  success(report) {
    console.log('keepalive acceptance', report.score, report.level, report.summary)
    console.log('验收清单', JSON.stringify(report.checks))
  }
})

长跑观测报告

getKeepAliveRunReport 返回结构化 KeepAliveRunReport,用于把当前/最近一次 KeepAliveSurvivalTestReportKeepAliveAcceptanceReportKeepAliveDiagnosticBundle 合成一份复测报告。Android 端会输出长跑采样数、平均活性评分、最低活性评分、心跳增长、中断次数、后台任务失败数和验收评分等 metrics,并给出 score / level / passed / nextSteps / warnings。能力矩阵中的 runReporttrue 时代表当前平台支持真实 Android 长跑观测报告;其它平台返回明确降级报告。

长跑观测报告适合用户重新打 Android 自定义基座后做插件市场演示、客户交付复测和售后回归。它不会把未运行的生存力测试伪造成通过;未产生采样点时,默认给出人工复测建议,strictMode=true 时会按失败处理。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveRunReportOptions 获取长跑观测报告参数 includeSamples / strictMode / success / fail / complete
options.includeSamples boolean 是否返回生存力测试样本数组 true true / false
options.strictMode boolean 是否把未产生采样点视为失败 false true / false
options.success function 成功回调,返回 KeepAliveRunReport
options.fail function 失败回调;上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
reportId string 本次长跑报告 ID
generatedAt number 生成时间戳
platform string 当前平台
pluginVersion string 插件版本
score number 长跑综合分
level KeepAliveRunReportLevel 长跑等级,excellent / stable / warning / failed / unsupported
passed boolean 是否整体通过
durationMs number 当前或最近一次测试持续时长
sampleCount number 生存力测试采样点数量
minAliveScore number 长跑期间最低活性评分
averageAliveScore number 长跑期间平均活性评分
heartbeatDelta number 长跑期间心跳增长量
interruptions number 长跑期间运行中断次数
taskFailureCount number 后台任务失败总数
maxConsecutiveTaskFailures number 后台任务最大连续失败数
acceptanceReport KeepAliveAcceptanceReport 本次报告依赖的验收报告
diagnosticBundle KeepAliveDiagnosticBundle 本次报告依赖的诊断包
metrics Array 长跑指标列表
samples Array 生存力测试样本;includeSamples=false 时为空数组
nextSteps Array 后续复测或修复建议
warnings Array 系统限制、长跑边界和平台降级提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 建议先运行 startKeepAliveSurvivalTest,结束后再生成长跑观测报告用于复测归档。
keepAlive.getKeepAliveRunReport({
  includeSamples: true,
  strictMode: false,
  success(report) {
    console.log('keepalive run report', report.score, report.level, report.sampleCount)
    console.log('复测指标', JSON.stringify(report.metrics))
  }
})

一键保活套件

applyKeepAliveSuite 是面向快速接入和插件市场演示的一键编排 API。Android 端会按指定预设写入保活配置,必要时自动注册运行态,启动真前台服务,启动稳定后台任务定时器,注册默认巡检任务,并返回 KeepAliveSuiteResult。返回结果中包含 readinessReportevidencePack,方便客户继续处理系统授权、厂商后台设置和长跑验收。

参数 类型 必填 说明 默认值 可选参数
options ApplyKeepAliveSuiteOptions 一键套件参数 presetId / startImmediately / startStableTimer / stableTimerIntervalMs / stableTimerTag / startSilentAudio / registerDefaultTask / defaultTaskId / defaultTaskIntervalMs / suggestSurvivalTest / success / fail / complete
options.presetId KeepAlivePresetId 使用的保活预设 strong balanced / strong / ultra / media / task
options.startImmediately boolean 是否自动注册并启动前台保活服务 true true / false
options.startStableTimer boolean 是否自动启动稳定后台任务定时器 true true / false
options.stableTimerIntervalMs number 稳定定时器间隔 预设值
options.stableTimerTag string 稳定定时器标签 预设值
options.startSilentAudio boolean 是否强制启动静音音频策略;未传时按预设建议决定 预设建议 true / false
options.registerDefaultTask boolean 是否注册默认巡检任务 true true / false
options.defaultTaskId string 默认任务 ID suite-heartbeat
options.defaultTaskIntervalMs number 默认任务间隔 预设稳定定时器间隔
options.suggestSurvivalTest boolean 是否在结果中建议继续运行生存力测试 true true / false
options.success function 成功回调,返回 KeepAliveSuiteResult
options.fail function 失败回调;平台不支持、预设非法或前台服务启动失败时触发
options.complete function 完成回调
字段 类型 说明
presetId KeepAlivePresetId 实际应用的预设
presetApplied boolean 是否已写入预设配置
registered boolean 是否已注册运行态
started boolean 前台保活服务是否已启动
stableTimerStarted boolean 稳定后台任务定时器是否已启动
silentAudioStarted boolean 静音音频策略是否已启动
defaultTaskRegistered boolean 默认巡检任务是否已注册
survivalTestSuggested boolean 是否建议继续运行生存力测试
status KeepAliveStatus 当前保活状态
evidencePack KeepAliveEvidencePack 套件执行后的证据包
readinessReport KeepAliveReadinessReport 套件执行后的准备度报告
taskStatuses Array 当前后台任务状态
nextSteps Array 下一步验收动作
warnings Array 风险和限制说明
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 首次接入或插件市场演示时,可用一键套件快速启动强保活链路。
keepAlive.applyKeepAliveSuite({
  presetId: 'strong',
  startImmediately: true,
  startStableTimer: true,
  registerDefaultTask: true,
  suggestSurvivalTest: true,
  success(result) {
    console.log('suite result', result.started, result.stableTimerStarted, result.evidencePack.summary)
  }
})

一键自愈守护

autoHealKeepAlive 是面向“客户已经接入但保活链路不完整”的自愈编排 API。Android 端会先生成准备度基线,再按参数自动补齐插件内部可合法完成的动作:应用保活预设、注册运行态、启动真前台服务、重建稳定后台任务定时器、重建 JobScheduler 兜底守护、注册默认巡检任务,并返回 KeepAliveAutoHealReportgetKeepAliveAutoHealReport 用于只读查询当前自愈报告,getKeepAliveAutoHealEvidenceLoop 用于查询最近一次自愈闭环证据。能力矩阵中的 autoHealtrue 时代表当前平台支持真实一键自愈守护;autoHealEvidenceLooptrue 时代表 Android 会通过 auto-heal-evidence-loop 能力持久化最近一次闭环证据。其它平台返回明确降级报告。

一键自愈不会绕过 Android 系统权限和厂商 ROM 限制。通知授权、电池优化白名单、厂商自启动/后台运行设置仍会作为 requiresUserAction=true 的自愈动作返回,交给业务引导用户确认。

autoHealKeepAlive(options)

参数 类型 必填 说明 默认值 可选参数
options AutoHealKeepAliveOptions 一键自愈参数 presetId / startImmediately / rebuildStableTimer / stableTimerIntervalMs / stableTimerTag / rebuildJobScheduler / jobSchedulerIntervalMs / registerDefaultTask / defaultTaskId / defaultTaskIntervalMs / success / fail / complete
options.presetId KeepAlivePresetId 自愈时应用的保活预设 strong balanced / strong / ultra / media / task
options.startImmediately boolean 是否自动启动真前台服务 true true / false
options.rebuildStableTimer boolean 是否重建稳定后台任务定时器 true true / false
options.stableTimerIntervalMs number 稳定定时器间隔 30000
options.stableTimerTag string 稳定定时器标签 auto-heal
options.rebuildJobScheduler boolean 是否重建 JobScheduler 兜底守护 true true / false
options.jobSchedulerIntervalMs number JobScheduler 周期间隔,Android 最小 15 分钟 900000 >=900000
options.registerDefaultTask boolean 是否注册默认巡检任务 true true / false
options.defaultTaskId string 默认巡检任务 ID auto-heal-heartbeat
options.defaultTaskIntervalMs number 默认巡检任务间隔 30000
options.success function 成功回调,返回 KeepAliveAutoHealReport
options.fail function 失败回调;平台不支持或上下文不可用时触发
options.complete function 完成回调

getKeepAliveAutoHealReport(options)

参数 类型 必填 说明 默认值 可选参数
options StatusOptions 查询自愈报告参数 success / fail / complete
options.success function 成功回调,返回 KeepAliveAutoHealReport
options.fail function 失败回调
options.complete function 完成回调
字段 类型 说明
healed boolean 自愈后评分是否提升或已 ready
autoStarted boolean 是否处于运行中的真前台保活状态
presetApplied boolean 是否已应用强保活相关预设
stableTimerRebuilt boolean 稳定后台任务定时器是否已启用
jobSchedulerRebuilt boolean JobScheduler 兜底守护是否已调度
defaultTaskRegistered boolean 默认巡检任务是否已注册
beforeReadinessScore number 自愈前准备度评分
afterReadinessScore number 自愈后准备度评分
beforeLevel KeepAliveReadinessLevel 自愈前准备度等级
afterLevel KeepAliveReadinessLevel 自愈后准备度等级
status KeepAliveStatus 自愈后的保活状态
readinessReport KeepAliveReadinessReport 自愈后的准备度报告
evidencePack KeepAliveEvidencePack 自愈后的保活证据包
actions Array 自愈动作列表,包含 fixed / skipped / failed / manual 状态
autoHealLoopId string 本次自愈闭环编号,用于和 KeepAliveAutoHealEvidenceLoop.loopId 对齐
autoHealEvidenceLoop boolean 是否启用自愈闭环证据能力
persistent boolean 本次报告是否已经写入应用私有持久化存储
persistedAt number 最近一次自愈闭环证据持久化时间戳
persistedTotal number 当前累计写入的自愈闭环证据次数
storageKey string Android 私有 SharedPreferences 存储 key
nextSteps Array 下一步验收或用户确认动作
warnings Array 系统限制和合规提醒

getKeepAliveAutoHealEvidenceLoop(options)

getKeepAliveAutoHealEvidenceLoop 返回 KeepAliveAutoHealEvidenceLoop,用于把最近一次 autoHealKeepAlive 的自愈结果整理成可恢复、可复制、可交付的闭环证据。Android 端会优先从内存读取最近报告,页面重开或进程恢复后会尝试从应用私有 SharedPreferences 恢复;其它平台返回 autoHealEvidenceLoop=false / level=unsupported,不伪造 Android 自愈闭环证据。

自愈证据聚合使用 auto-heal-report-aggregation 能力标记。Android 端的 getKeepAliveSupportReport / getKeepAliveUltimateReport / getKeepAliveMarketReadinessReport 会同步返回 autoHealEvidenceSummary: KeepAliveAutoHealEvidenceSummary,把最近一次闭环证据压缩成摘要字段,便于售后报告、终极体检和插件市场发布体检直接展示。

参数 类型 必填 说明 默认值 可选参数
options GetKeepAliveAutoHealEvidenceLoopOptions 查询自愈闭环证据参数 includeMarkdown / success / fail / complete
options.includeMarkdown boolean 是否返回 Markdown 证据文本 true true / false
options.success function 成功回调,返回 KeepAliveAutoHealEvidenceLoop
options.fail function 失败回调;Android 上下文不可用时触发
options.complete function 完成回调
字段 类型 说明
loopId string 最近一次自愈闭环编号,通常等于 lastReport.autoHealLoopId
autoHealEvidenceLoop boolean 当前平台是否支持自愈闭环证据
persistent boolean 是否支持持久化恢复
restored boolean 本次结果是否从持久化数据恢复
persistedAt number 最近一次持久化时间戳
persistedTotal number 当前累计持久化次数
storageKey string Android 私有持久化 key
level string ready / warning / empty / unsupported
ready boolean 自愈闭环是否达到可交付状态
summaryText string 便于日志展示的摘要
lastReport KeepAliveAutoHealReport 最近一次自愈报告
fixedActionCount number fixed 动作数量
manualActionCount number 需要人工确认的动作数量
failedActionCount number 失败动作数量
skippedActionCount number 跳过动作数量
markdown string 可复制到售后工单或交付报告的 Markdown 证据
status KeepAliveStatus 当前运行态
capabilities KeepAliveCapabilities 当前能力矩阵
nextSteps Array 下一步验收动作
warnings Array 系统限制和合规提醒

KeepAliveAutoHealEvidenceSummary

字段 类型 说明
supported boolean 当前报告是否包含真实 Android 自愈证据聚合
level string ready / warning / empty / unsupported
ready boolean 最近一次自愈闭环是否达到可交付状态
loopId string 最近一次自愈闭环编号
autoHealLoopId string 最近一次 autoHealKeepAlive 报告编号
persistent boolean 是否支持持久化恢复
restored boolean 当前摘要是否来自持久化恢复
persistedTotal number 当前累计持久化次数
fixedActionCount number 已自动修复动作数量
manualActionCount number 仍需人工确认动作数量
failedActionCount number 执行失败动作数量
skippedActionCount number 跳过动作数量
summaryText string 适合日志和报告展示的一行摘要
nextSteps Array 下一步自愈或人工确认动作
warnings Array 系统限制和合规提醒
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 发现客户环境保活不稳定时,可执行一键自愈并记录 actions 与证据包。
keepAlive.autoHealKeepAlive({
  presetId: 'strong',
  startImmediately: true,
  rebuildStableTimer: true,
  rebuildJobScheduler: true,
  registerDefaultTask: true,
  success(report) {
    console.log('autoHeal', report.autoHealLoopId, report.beforeReadinessScore, report.afterReadinessScore, report.actions)
  }
})

// 只读查询当前自愈报告,不改变运行状态。
keepAlive.getKeepAliveAutoHealReport({
  success(report) {
    console.log('autoHeal report', report.status.capabilities.autoHeal, report.nextSteps)
  }
})

// 查询最近一次自愈闭环证据,交付或售后时可复制 markdown。
keepAlive.getKeepAliveAutoHealEvidenceLoop({
  includeMarkdown: true,
  success(loop) {
    console.log('autoHealEvidenceLoop', loop.loopId, loop.autoHealEvidenceLoop, loop.persistedTotal, loop.manualActionCount, loop.markdown)
  }
})

// 交付报告会聚合自愈摘要,客户无需单独理解所有自愈字段。
keepAlive.getKeepAliveSupportReport({
  includeMarkdown: true,
  success(report) {
    console.log('autoHealEvidenceSummary', report.autoHealEvidenceSummary.level, report.autoHealEvidenceSummary.persistedTotal)
  }
})

keepAlive.getKeepAliveUltimateReport({
  includeMarkdown: true,
  includeSupportReport: true,
  success(report) {
    console.log('ultimate autoHealEvidenceSummary', report.autoHealEvidenceSummary.ready)
  }
})

keepAlive.getKeepAliveMarketReadinessReport({
  includeMarkdown: true,
  success(report) {
    console.log('market autoHealEvidenceSummary', report.autoHealEvidenceSummary.summaryText)
  }
})

保活生存力测试

startKeepAliveSurvivalTest 用于在 Android 真前台服务运行期间启动一段采样式保活生存力测试。插件会按 sampleIntervalMs 采集运行状态、活性评分、心跳数、后台任务失败数、连续失败数、内存和 CPU 估算值;getKeepAliveSurvivalTestStatus 可查询实时状态;stopKeepAliveSurvivalTest 会停止测试并返回 KeepAliveSurvivalTestReport。该能力用于真机长跑验收、插件市场演示和售后排障,不写文件、不新增存储权限,也不承诺绕过 Android 系统或厂商 ROM 后台限制。

startKeepAliveSurvivalTest(options)

参数 类型 必填 说明 默认值 可选参数
options StartKeepAliveSurvivalTestOptions 启动测试参数 durationMs / sampleIntervalMs / tag / success / fail / complete
options.durationMs number 测试持续时长,Android 会限制在 30 秒到 24 小时之间 300000 30000-86400000
options.sampleIntervalMs number 采样间隔,Android 会限制在 5 秒到 10 分钟之间 15000 5000-600000
options.tag string 业务标签,便于日志区分测试场景 survival
options.success function 成功回调,返回 KeepAliveSurvivalTestStatus
options.fail function 失败回调;未注册、未启动保活、重复启动或平台不支持时触发
options.complete function 完成回调

getKeepAliveSurvivalTestStatus(options)

字段 类型 说明
running boolean 测试是否正在运行
testId string 本次测试 ID
startedAt number 测试开始时间戳
durationMs number 计划测试时长
sampleIntervalMs number 实际采样间隔
sampleCount number 已采样次数
elapsedMs number 已运行时长
remainingMs number 剩余时长
lastSampleAt number 最近采样时间戳
level KeepAliveSurvivalTestLevel 当前测试等级,running / passed / warning / failed / unsupported
lastSample KeepAliveSurvivalTestSample 最近一次采样
warnings Array 测试限制和注意事项

stopKeepAliveSurvivalTest(options)

字段 类型 说明
testId string 本次测试 ID
startedAt number 测试开始时间戳
endedAt number 测试结束时间戳
durationMs number 计划测试时长
actualDurationMs number 实际测试时长
sampleIntervalMs number 实际采样间隔
sampleCount number 采样次数
level KeepAliveSurvivalTestLevel 最终测试等级
passed boolean 是否通过当前测试规则
minAliveScore number 测试期间最低活性评分
averageAliveScore number 测试期间平均活性评分
heartbeatDelta number 测试期间心跳增长量
interruptions number 测试期间发现的运行中断次数
taskFailureCount number 已注册后台任务累计失败次数
maxConsecutiveTaskFailures number 后台任务最大连续失败次数
samples Array 全量采样列表
status KeepAliveStatus 测试结束时保活状态
evidencePack KeepAliveEvidencePack 同步生成的保活证据包
warnings Array 风险提示
recommendations Array 下一步处理建议
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 生存力测试必须在 register 和 startKeepAlive 成功后启动。
keepAlive.startKeepAliveSurvivalTest({
  durationMs: 60000,
  sampleIntervalMs: 10000,
  tag: 'demo-survival',
  success(status) {
    console.log('survival status', status.testId, status.sampleCount)
  }
})

// 测试过程中可查询实时状态。
keepAlive.getKeepAliveSurvivalTestStatus({
  success(status) {
    console.log('survival sampleCount', status.sampleCount)
  }
})

// 手动停止后会返回 KeepAliveSurvivalTestReport。
keepAlive.stopKeepAliveSurvivalTest({
  success(report) {
    console.log('survival report', report.level, report.sampleCount, JSON.stringify(report.evidencePack))
  }
})

后台任务守护

registerKeepAliveTask 用于注册运行期后台任务守护,setOnKeepAliveTaskListener 用于监听任务到期事件,reportKeepAliveTaskResult 用于回传业务执行结果,getKeepAliveTaskStatuses 返回当前任务状态列表。Android 端会在真前台服务运行期间,结合普通心跳和稳定定时器 tick 检查任务是否到期,然后派发 KeepAliveTaskEvent。插件只负责可靠触发事件和记录执行结果回执,不伪造业务执行成功;业务应在监听回调中执行自己的同步、巡检、上报或补偿逻辑,并在执行完成后调用 reportKeepAliveTaskResult

参数 类型 必填 说明 默认值 可选参数
options RegisterKeepAliveTaskOptions 注册任务参数 task / success / fail / complete
options.task.taskId string 任务唯一 ID
options.task.title string 任务标题,用于日志和状态展示
options.task.intervalMs number 任务触发间隔,Android 小于 5000ms 会按 5000ms 处理 5000
options.task.tag string 业务标签 taskId
options.task.runImmediately boolean 注册后是否在保活运行中立即触发一次 false true / false
options.success function 成功回调,返回 Array<KeepAliveTaskStatus>
options.fail function 失败回调;参数非法或平台不支持时触发
options.complete function 完成回调
字段 类型 说明
taskId string 任务唯一 ID
title string 任务标题
tag string 业务标签
intervalMs number 实际触发间隔
enabled boolean 是否启用
running boolean 当前是否处于可触发状态
tick number 已触发次数
lastRunAt number 最近触发时间戳
nextRunAt number 下次预计触发时间戳
lastSource string 最近触发来源,如 heartbeat / interval / alarm / register
lastResultState KeepAliveTaskResultState 最近一次业务执行结果,pending / success / failure
successCount number 业务回执成功次数
failureCount number 业务回执失败次数
consecutiveFailureCount number 连续失败次数,用于判断任务是否异常
lastResultMessage string 最近一次业务回执消息
lastResultAt number 最近一次业务回执时间戳
requiresForegroundService boolean 是否依赖 Android 前台服务

reportKeepAliveTaskResult(options)

参数 类型 必填 说明 默认值 可选参数
options ReportKeepAliveTaskResultOptions 后台任务执行结果回执参数 taskId / result / message / timestamp / success / fail / complete
options.taskId string 已注册任务 ID
options.result KeepAliveTaskResultInput 业务执行结果 success / failure
options.message string 业务执行结果说明,建议写失败原因或成功摘要 空字符串
options.timestamp number 业务执行完成时间戳,不传时使用当前时间 当前时间
options.success function 成功回调,返回更新后的 KeepAliveTaskStatus
options.fail function 失败回调;任务不存在、参数非法或平台不支持时触发
options.complete function 完成回调
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 监听后台任务守护事件。业务在这里执行自己的同步、巡检、补偿或上报逻辑。
keepAlive.setOnKeepAliveTaskListener({
  listener(event) {
    console.log('task fired', event.taskId, event.tick, event.source)
    // 业务执行完成后回传结果,插件会统计成功、失败和连续失败次数。
    keepAlive.reportKeepAliveTaskResult({
      taskId: event.taskId,
      result: 'success',
      message: '订单同步完成'
    })
  }
})

// 注册一个后台同步任务。建议先启动保活服务,再注册任务。
keepAlive.registerKeepAliveTask({
  task: {
    taskId: 'sync-order',
    title: '订单同步',
    intervalMs: 30000,
    tag: 'order',
    runImmediately: true
  },
  success(list) {
    console.log('task statuses', list)
  }
})

// 查看当前任务守护状态。
keepAlive.getKeepAliveTaskStatuses({
  success(list) {
    console.log('tasks', list)
  }
})

静音音频保活策略

startSilentAudio 启动 Android 静音音频保活策略。Android 端会在真前台服务运行期间使用原生 AudioTrack 写入静音 PCM,并要求 Android Manifest 声明 FOREGROUND_SERVICE_MEDIA_PLAYBACK 与前台服务 mediaPlayback 类型。该策略适合对后台音频类、长连接类和设备巡检类业务做辅助增强;它必须由业务显式开启,不会在开机广播中偷偷启动,也不能替代通知权限、电池优化白名单和厂商 ROM 后台设置。

参数 类型 必填 说明 默认值 可选参数
options StartSilentAudioOptions 启动参数 mode / volume / success / fail / complete
options.mode KeepAliveSilentAudioMode 静音音频实现模式,当前 Android 使用 PCM 静音流 pcm pcm / media
options.volume number 音量,范围 0 到 1;静音策略建议保持 0 0 0-1
options.success function 成功回调,返回 KeepAliveSilentAudioStatus
options.fail function 失败回调;未注册、未启动保活或平台不支持时会失败
options.complete function 完成回调
字段 类型 说明
enabled boolean 是否已启用静音音频策略
running boolean 当前 AudioTrack 是否运行中
mode string 当前静音音频模式
volume number 当前音量
startedAt number 启动时间戳
lastError string 最近一次失败原因
requiresForegroundService boolean 是否依赖 Android 前台服务
import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

// 建议在 register 和 startKeepAlive 成功后显式启动静音音频策略。
keepAlive.setOnSilentAudioListener({
  listener(event) {
    console.log('silent audio event', event.name, event.status)
  }
})

keepAlive.startSilentAudio({
  mode: 'pcm',
  volume: 0,
  success(status) {
    console.log('silent audio status', status)
  }
})

// 业务停止保活或不再需要后台辅助策略时,应主动释放 AudioTrack。
keepAlive.stopSilentAudio({
  success(status) {
    console.log('silent audio stopped', status)
  }
})

uni-app 调用示例

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

keepAlive.register({
  config: {
    alwaysEnable: true,
    autoStartOnBoot: true,
    openHigh: true,
    heartbeatIntervalMs: 10000,
    wakeLockEnabled: true,
    wifiLockEnabled: true,
    watchdogEnabled: true,
    watchdogIntervalMs: 60000,
    jobSchedulerEnabled: true,
    jobSchedulerIntervalMs: 900000,
    wakeUpOnScreenOnEnabled: true,
    notificationActionsEnabled: true,
    silentAudioEnabled: false
  },
  success() {
    keepAlive.startKeepAlive({})
  }
})

keepAlive.setOnTimerListener({
  listener(event) {
    console.log('timer tick', event)
  }
})

keepAlive.setOnKeepAliveEvent({
  listener(event) {
    console.log('runtime event', event.name)
  }
})

uni-app x 调用示例

import * as keepAlive from '@/uni_modules/lizhao-app-keepalive'

keepAlive.getCapabilities({
  success(res) {
    console.log('capabilities', res)
  }
})

keepAlive.sendHeartbeat({
  tag: 'manual-check',
  payload: { scene: 'home' },
  success(res) {
    console.log('heartbeat', res)
  }
})

注意事项

  1. Android 的系统级保活效果受 ROM 策略影响,请结合设备白名单/电池优化设置验证。
  2. Android 修改前台服务、Manifest、权限、JobScheduler JobService 或 Kotlin 兼容壳后,必须重新打 Android 自定义基座。
  3. iOS 端为最佳努力策略,不保证 Android 级别常驻。
  4. Harmony 端需检查 harmony-configs/entry/src/main/module.json5,至少包含 ohos.permission.KEEP_BACKGROUND_RUNNINGaudioPlayback / dataTransfer;调用 applyKeepAliveHarmonySuite 后仍需重新打 Harmony 自定义基座或重新原生联编,并按真机心跳增长做验收。
  5. 静音音频保活策略依赖 Android AudioTrackFOREGROUND_SERVICE_MEDIA_PLAYBACK 和前台服务 mediaPlayback 类型;该策略不是绕过系统限制的手段,发布前应确认业务场景、通知展示和商店合规说明。
  6. 售后诊断包只返回诊断 JSON,不写文件、不申请存储权限、不采集账号、Token、定位、通讯录等敏感信息;业务上传前仍需遵守自身隐私政策。
  7. 保活验收报告只汇总当前运行态与诊断项,不替代用户在目标机型、锁屏、后台、息屏和厂商 ROM 场景下的真实长跑验收。
  8. Web/小程序仅返回降级能力,不应承诺系统后台常驻。

联系方式

信-微:l-z-1-8-7-1512-5421(-去掉,不这样写会被和谐)

隐私、权限声明

1. 本插件需要申请的系统权限列表:

前台服务、保活证据会话、自愈后复测计划、自愈证据聚合、自愈闭环证据、恢复证据快照、持久化事件时间线、交付证据归档包导出、交付证据文件导出、交付报告一键复制、发布包质量门禁、插件市场发布体检报告、前台服务合规体检、媒体播放前台服务、通知、通知通道体检、通知动作广播、通知运行时权限、精确闹钟、JobScheduler 兜底守护、BIND_JOB_SERVICE、电池优化忽略、唤醒锁、WiFi 锁、Android onDestroy 服务销毁自恢复、Android onTaskRemoved 任务划掉恢复、stopWithTask=false 前台服务配置、iOS 后台套件、iOS UIBackgroundModes、一键终极体检报告、保活巡航守护、厂商 ROM 设置验收审计与下一项设置导航、交付验收计划、售后/交付支持报告、自定义基座完整性报告、事件时间线与恢复审计、长跑观测报告、保活验收报告、售后诊断包、一键自愈守护、鸿蒙后台套件、一键保活套件、保活生存力测试、保活证据包、后台任务守护与执行结果回执、保活准备度报告、一键保活策略预设、静音音频保活策略、稳定后台任务定时器、Harmony 后台运行配置指引、厂商 ROM 保活指引、开机/屏幕唤醒自恢复广播、通知点击与运行态事件广播按平台配置

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。