M5: Provider 前后台生命周期(非激活槽真正停 native 活动)
forEachForeground/forEachBackground 此前扇出但多数 Provider 未实现 → 非激活槽 native 监听仍跑。补齐:
- ShakeProvider:onBackground 停传感器、onForeground 按 H5 意图(wantShake)恢复;区分 H5 请求态与实际监听态
- LocationProvider:onBackground 停连续定位、onForeground 按 wantContinuous 恢复(单次定位无需恢复)
- NetworkProvider:onBackground 注销网络订阅、onForeground 重订阅(抽 unsubscribe)
- AudioProvider:onBackground 停语音/音效播放(非激活端不出声)
至此"同时只有一个激活"在 native 侧也落实:去激活槽停传感器/定位/网络/音频;H5 侧由 appservice('2') 自停。
WeChat resp 路由保持现状(微信整体延期;双 Web 下发起槽持续存活,边缘情形见 m3-deferred 记录)。
devecocli build + scripts/test.sh 通过。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ export class LocationProvider implements CapabilityProvider {
|
||||
private context: common.UIAbilityContext | undefined = undefined;
|
||||
private lastInfo: MaplocationInfo | undefined = undefined;
|
||||
private continuousOn: boolean = false;
|
||||
private wantContinuous: boolean = false;
|
||||
private readonly onLocation: (loc: geoLocationManager.Location) => void;
|
||||
|
||||
constructor() {
|
||||
@@ -39,7 +40,20 @@ export class LocationProvider implements CapabilityProvider {
|
||||
});
|
||||
}
|
||||
|
||||
/** 槽激活:恢复连续定位(若 H5 仍要)。 */
|
||||
onForeground(): void {
|
||||
if (this.wantContinuous) {
|
||||
this.startContinuous();
|
||||
}
|
||||
}
|
||||
|
||||
/** 槽去激活:停连续定位监听(保留 H5 意图)。 */
|
||||
onBackground(): void {
|
||||
this.stopContinuous();
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
this.wantContinuous = false;
|
||||
this.stopContinuous();
|
||||
}
|
||||
|
||||
@@ -54,6 +68,7 @@ export class LocationProvider implements CapabilityProvider {
|
||||
this.push(this.lastInfo);
|
||||
return;
|
||||
}
|
||||
this.wantContinuous = continuous;
|
||||
if (continuous) {
|
||||
this.startContinuous();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user