clear call alerm

Signed-off-by: 18518779689 <litingting84@huawei.com>
This commit is contained in:
18518779689 2023-07-28 19:54:05 +08:00
parent fbd48a9240
commit d9dd1966c0
6 changed files with 46 additions and 104 deletions

View File

@ -32,6 +32,9 @@ const CALL_STATUS_WAITING = 5;
const CALL_STATUS_DIALING = 2;
const CALL_STATUS_DISCONNECTED = 6;
const CALL_STATUS_DISCONNECTING = 7;
const CALL_EVENT = 0;
const CALL_CLICK = 1;
const CALL_SCREEN_OFF = 2;
const events = ['callui.event.callEvent', 'callui.event.click', 'usual.event.SCREEN_OFF'];
/**
@ -80,19 +83,19 @@ export default class CallManagerService {
commonEvent.subscribe(subscriber, (err, res) => {
if (err.code === 0) {
if (res.event === events[0]) {
if (res.event === events[CALL_EVENT]) {
const obj = JSON.parse(res.data);
if (obj && obj.key === 'getInitCallData') {
this.publishData(this.callData);
}
}
if (res.event === events[1]) {
if (res.event === events[CALL_CLICK]) {
const {callId, btnType} = res.parameters;
this.btnclickAgent(callId, btnType);
}
if (res.event === events[2]) {
if (res.event === events[CALL_SCREEN_OFF]) {
VibrationAndProximityUtils.stopVibration();
CallServiceProxy.getInstance().muteRinger();
}
@ -176,7 +179,7 @@ export default class CallManagerService {
* @return void
*/
public onDisconnected(): void {
if (this.callData != null && this.callData.callState === 6) {
if (this.callData != null && this.callData.callState === CALL_STATUS_DISCONNECTED) {
return;
} else {
this.callData.callState = CALL_STATUS_DISCONNECTED;

View File

@ -13,13 +13,7 @@
* limitations under the License.
*/
export default class DeviceTypeConst {
//DEVICE_EARPIECE
public static DEVICE_EARPIECE = 0;
//DEVICE_SPEAKER
public static DEVICE_SPEAKER = 1;
//DEVICE_WIRED_HEADSET
public static DEVICE_WIRED_HEADSET = 2;
//DEVICE_BLUETOOTH_SCO
public static DEVICE_BLUETOOTH_SCO = 3;
}
export const DEVICE_EARPIECE = 0;
export const DEVICE_SPEAKER = 1;
export const DEVICE_WIRED_HEADSET = 2;
export const DEVICE_BLUETOOTH_SCO = 3;

View File

@ -28,85 +28,33 @@ import audio from '@ohos.multimedia.audio';
import CallServiceProxy from '../../model/CallServiceProxy';
import LogUtils from './LogUtils';
import runningLock from '@ohos.runningLock';
import sensor from '@ohos.sensor';
import vibrator from '@ohos.vibrator';
const TAG = 'VibrationAndProximityUtils';
const PROXIMITY_INTERVAL = 10000000;
const VIBRATION_COUNT = 20;
/**
* Vibration And Proximity tool class
*/
export class VibrationAndProximityUtils {
startVibrationFlag = false;
addProximityListenerFlag = false;
recordDistance = -1;
recordLock = null;
/**
* add Proximity Listener
*/
public addProximityListener() {
try {
if (this.addProximityListenerFlag) {
LogUtils.e(TAG, 'addProximityListener return');
return;
}
this.addProximityListenerFlag = true;
let that = this
sensor.on(sensor.SensorId.PROXIMITY, function (data) {
if (data) {
if (that.recordDistance != data.distance) {
if (data.distance == 0) {
that.suspendScreen();
} else {
that.wakeupScreen();
}
}
that.recordDistance = data.distance;
}
}, { interval: PROXIMITY_INTERVAL });
} catch (err) {
LogUtils.e(TAG, 'addProximityListener sensor On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
}
/**
* remove Proximity Listener Vibration
*/
removeProximityListener() {
try {
if (!this.addProximityListenerFlag) {
LogUtils.e(TAG, 'removeProximityListener return');
return;
}
this.addProximityListenerFlag = false;
sensor.off(sensor.SensorId.PROXIMITY, function () {
LogUtils.i(TAG, 'removeProximityListener ');
})
} catch (err) {
LogUtils.e(TAG, 'removeProximityListener sensor off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
}
private static startVibrationFlag = false;
private static recordLock = null;
/**
* suspend Screen
*/
public suspendScreen() {
if (this.recordLock) {
this.recordLock.hold(Number.MAX_VALUE);
public suspendScreen(): void {
if (VibrationAndProximityUtils.recordLock) {
VibrationAndProximityUtils.recordLock.hold(Number.MAX_VALUE);
LogUtils.i(TAG, 'suspendScreen hold');
} else {
let that = this;
runningLock.create('call_lock', runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL).then(lock => {
LogUtils.i(TAG, 'suspendScreen create running lock success');
try {
that.recordLock = lock;
VibrationAndProximityUtils.recordLock = lock;
lock.hold(Number.MAX_VALUE);
LogUtils.i(TAG, 'suspendScreen hold');
} catch(err) {
} catch (err) {
LogUtils.e(TAG, 'suspendScreen hold running lock failed, err: ' + err);
}
}).catch(err => {
@ -118,19 +66,18 @@ export class VibrationAndProximityUtils {
/**
* wakeup Screen
*/
public wakeupScreen() {
if (this.recordLock) {
this.recordLock.unhold();
public wakeupScreen(): void {
if (VibrationAndProximityUtils.recordLock) {
VibrationAndProximityUtils.recordLock.unhold();
LogUtils.i(TAG, 'wakeupScreen unhold');
} else {
let that = this;
runningLock.create('call_lock', runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL).then(lock => {
LogUtils.i(TAG, 'wakeupScreen create running lock success');
try {
that.recordLock = lock;
VibrationAndProximityUtils.recordLock = lock;
lock.unhold();
LogUtils.i(TAG, 'wakeupScreen unhold');
} catch(err) {
} catch (err) {
LogUtils.e(TAG, 'wakeupScreen unhold running lock failed, err: ' + err);
}
}).catch(err => {
@ -142,13 +89,12 @@ export class VibrationAndProximityUtils {
/**
* start Vibration
*/
public startVibration() {
public startVibration(): void {
try {
if (this.startVibrationFlag) {
if (VibrationAndProximityUtils.startVibrationFlag) {
LogUtils.e(TAG, 'startVibration return');
return;
}
let that = this;
vibrator.startVibration({
type: 'preset',
effectId: 'haptic.ringtone.T-Mobile_Ring',
@ -159,7 +105,7 @@ export class VibrationAndProximityUtils {
if (error) {
LogUtils.e(TAG, 'startVibration fail, error.code: ' + error.code + ', error.message: ' + error.message);
} else {
that.startVibrationFlag = true;
VibrationAndProximityUtils.startVibrationFlag = true;
LogUtils.i(TAG, 'startVibration Callback returned to indicate a successful vibration.');
}
});
@ -171,21 +117,20 @@ export class VibrationAndProximityUtils {
/**
* stop Vibration
*/
public stopVibration() {
if (!this.startVibrationFlag) {
public stopVibration(): void {
if (!VibrationAndProximityUtils.startVibrationFlag) {
LogUtils.e(TAG, 'stopVibration return');
return;
}
try {
let that = this;
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function (error) {
if (error) {
LogUtils.e(TAG, 'stopVibration error.code: ' + error.code + ', error.message: ' + error.message);
return;
}
that.startVibrationFlag = false;
VibrationAndProximityUtils.startVibrationFlag = false;
LogUtils.i(TAG, 'stopVibration Callback returned to indicate successful.');
})
});
} catch (err) {
LogUtils.e(TAG, 'stopVibration errCode: ' + err.code + ' ,msg: ' + err.message);
}
@ -194,7 +139,7 @@ export class VibrationAndProximityUtils {
/**
* add Voice Observe
*/
addVoiceObserver() {
addVoiceObserver(): void {
audio.getAudioManager().on('volumeChange', () => {
LogUtils.i(TAG, 'addVoiceObserver volumeChange');
this.stopVibration();

View File

@ -4,7 +4,7 @@ import LogUtils from '../common/utils/LogUtils'
const TAG = "MyAbilityStage";
export default class MyAbilityStage extends AbilityStage {
onCreate() {
LogUtils.i(TAG, "onWindowStageDestroy")
}
onCreate() {
LogUtils.i(TAG, 'onWindowStageDestroy');
}
}

View File

@ -1,22 +1,22 @@
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import type Window from '@ohos.window';
import LogUtils from '../common/utils/LogUtils'
const TAG = "MainAbility";
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
LogUtils.i(TAG, "onCreate");
LogUtils.i(TAG, 'onCreate');
globalThis.simCardAbilityContext = this.context;
}
onDestroy() {
LogUtils.i(TAG, "onDestroy");
LogUtils.i(TAG, 'onDestroy');
}
onWindowStageCreate(windowStage: Window.WindowStage) {
onWindowStageCreate(windowStage: Window.WindowStage): void {
// Main window is created, set main page for this ability
LogUtils.i(TAG, "onWindowStageCreate");
LogUtils.i(TAG, 'onWindowStageCreate');
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
@ -29,16 +29,16 @@ export default class MainAbility extends Ability {
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
LogUtils.i(TAG, "onWindowStageDestroy");
LogUtils.i(TAG, 'onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
LogUtils.i(TAG, "onForeground");
LogUtils.i(TAG, 'onForeground');
}
onBackground() {
// Ability has back to background
LogUtils.i(TAG, "onBackground");
LogUtils.i(TAG, 'onBackground');
}
}

View File

@ -30,19 +30,19 @@
*/
export class LogUtils {
d(TAG, msg): void {
console.debug("[simcardmanagement:]" + TAG + ":" + msg);
console.debug('[simcardmanagement:]' + TAG + ':' + msg);
}
i(TAG, msg): void {
console.info("[simcardmanagement:]" + TAG + ":" + msg);
console.info('[simcardmanagement:]' + TAG + ':' + msg);
}
w(TAG, msg): void {
console.warn("[simcardmanagement:]" + TAG + ":" + msg);
console.warn('[simcardmanagement:]' + TAG + ':' + msg);
}
e(TAG, msg): void {
console.error("[simcardmanagement:]" + TAG + ":" + msg);
console.error('[simcardmanagement:]' + TAG + ':' + msg);
}
}