fixed crash

Signed-off-by: 18518779689 <litingting84@huawei.com>
This commit is contained in:
18518779689 2023-09-14 21:09:46 +08:00
parent 2f50882f15
commit 3d4a477dfd
2 changed files with 28 additions and 20 deletions

View File

@ -31,27 +31,35 @@ export default class TelephonyApi {
* @param { Function } callBack - inject an Function
*/
public registerCallStateCallback(callBack) {
call.on('callDetailsChange', (data) => {
if (!data) {
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback")
return;
}
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback callState: " + JSON.stringify(data.callState))
callBack(data);
});
try {
call.on('callDetailsChange', (data) => {
if (!data) {
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback")
return;
}
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback callState: " + JSON.stringify(data.callState))
callBack(data);
});
} catch (err) {
LogUtils.i(TAG, "call.on registerCallStateCallback catch:" + JSON.stringify(err));
}
}
/**
* onRegister call state callback
*/
public unRegisterCallStateCallback() {
call.off('callDetailsChange', (data) => {
if (!data) {
try {
call.off('callDetailsChange', (data) => {
if (!data) {
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
return;
}
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
return;
}
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
});
});
} catch (err) {
LogUtils.i(TAG, "call.off unRegisterCallStateCallback catch:" + JSON.stringify(err));
}
}
/**

View File

@ -110,11 +110,11 @@ struct Index {
this.mCallDataManager = CallDataManager.getInstance();
byTrace.finishTrace('aboutToAppear', 0);
this.smListener = mediaQuery.matchMediaSync('(320vp<width<=520vp)');
this.smListener.on("change", this.isBreakpointSM);
this.smListener?.on("change", this.isBreakpointSM);
this.mdListener = mediaQuery.matchMediaSync('(520vp<width<=840vp)');
this.mdListener.on("change", this.isBreakpointMD);
this.mdListener?.on("change", this.isBreakpointMD);
this.lgListener = mediaQuery.matchMediaSync('(840vp<width)');
this.lgListener.on("change", this.isBreakpointLG);
this.lgListener?.on("change", this.isBreakpointLG);
this.initAirPlaneMode();
}
@ -171,9 +171,9 @@ struct Index {
aboutToDisappear() {
LogUtils.i(TAG, "aboutToDisappear");
this.stopBackgroundRunning();
this.smListener.off('change', this.isBreakpointSM);
this.mdListener.off('change', this.isBreakpointMD);
this.lgListener.off('change', this.isBreakpointLG);
this.smListener?.off('change', this.isBreakpointSM);
this.mdListener?.off('change', this.isBreakpointMD);
this.lgListener?.off('change', this.isBreakpointLG);
removeAirPlaneModeListener();
}