mirror of
https://gitee.com/openharmony/applications_call
synced 2025-02-11 09:45:50 +00:00
clear call alerm
Signed-off-by: 18518779689 <litingting84@huawei.com>
This commit is contained in:
parent
fbd48a9240
commit
d9dd1966c0
@ -32,6 +32,9 @@ const CALL_STATUS_WAITING = 5;
|
|||||||
const CALL_STATUS_DIALING = 2;
|
const CALL_STATUS_DIALING = 2;
|
||||||
const CALL_STATUS_DISCONNECTED = 6;
|
const CALL_STATUS_DISCONNECTED = 6;
|
||||||
const CALL_STATUS_DISCONNECTING = 7;
|
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'];
|
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) => {
|
commonEvent.subscribe(subscriber, (err, res) => {
|
||||||
if (err.code === 0) {
|
if (err.code === 0) {
|
||||||
if (res.event === events[0]) {
|
if (res.event === events[CALL_EVENT]) {
|
||||||
const obj = JSON.parse(res.data);
|
const obj = JSON.parse(res.data);
|
||||||
if (obj && obj.key === 'getInitCallData') {
|
if (obj && obj.key === 'getInitCallData') {
|
||||||
this.publishData(this.callData);
|
this.publishData(this.callData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.event === events[1]) {
|
if (res.event === events[CALL_CLICK]) {
|
||||||
const {callId, btnType} = res.parameters;
|
const {callId, btnType} = res.parameters;
|
||||||
this.btnclickAgent(callId, btnType);
|
this.btnclickAgent(callId, btnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.event === events[2]) {
|
if (res.event === events[CALL_SCREEN_OFF]) {
|
||||||
VibrationAndProximityUtils.stopVibration();
|
VibrationAndProximityUtils.stopVibration();
|
||||||
CallServiceProxy.getInstance().muteRinger();
|
CallServiceProxy.getInstance().muteRinger();
|
||||||
}
|
}
|
||||||
@ -176,7 +179,7 @@ export default class CallManagerService {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public onDisconnected(): void {
|
public onDisconnected(): void {
|
||||||
if (this.callData != null && this.callData.callState === 6) {
|
if (this.callData != null && this.callData.callState === CALL_STATUS_DISCONNECTED) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
this.callData.callState = CALL_STATUS_DISCONNECTED;
|
this.callData.callState = CALL_STATUS_DISCONNECTED;
|
||||||
|
@ -13,13 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default class DeviceTypeConst {
|
export const DEVICE_EARPIECE = 0;
|
||||||
//DEVICE_EARPIECE
|
export const DEVICE_SPEAKER = 1;
|
||||||
public static DEVICE_EARPIECE = 0;
|
export const DEVICE_WIRED_HEADSET = 2;
|
||||||
//DEVICE_SPEAKER
|
export const DEVICE_BLUETOOTH_SCO = 3;
|
||||||
public static DEVICE_SPEAKER = 1;
|
|
||||||
//DEVICE_WIRED_HEADSET
|
|
||||||
public static DEVICE_WIRED_HEADSET = 2;
|
|
||||||
//DEVICE_BLUETOOTH_SCO
|
|
||||||
public static DEVICE_BLUETOOTH_SCO = 3;
|
|
||||||
}
|
|
@ -28,85 +28,33 @@ import audio from '@ohos.multimedia.audio';
|
|||||||
import CallServiceProxy from '../../model/CallServiceProxy';
|
import CallServiceProxy from '../../model/CallServiceProxy';
|
||||||
import LogUtils from './LogUtils';
|
import LogUtils from './LogUtils';
|
||||||
import runningLock from '@ohos.runningLock';
|
import runningLock from '@ohos.runningLock';
|
||||||
import sensor from '@ohos.sensor';
|
|
||||||
import vibrator from '@ohos.vibrator';
|
import vibrator from '@ohos.vibrator';
|
||||||
|
|
||||||
const TAG = 'VibrationAndProximityUtils';
|
const TAG = 'VibrationAndProximityUtils';
|
||||||
const PROXIMITY_INTERVAL = 10000000;
|
|
||||||
const VIBRATION_COUNT = 20;
|
const VIBRATION_COUNT = 20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vibration And Proximity tool class
|
* Vibration And Proximity tool class
|
||||||
*/
|
*/
|
||||||
export class VibrationAndProximityUtils {
|
export class VibrationAndProximityUtils {
|
||||||
|
private static startVibrationFlag = false;
|
||||||
startVibrationFlag = false;
|
private static recordLock = null;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suspend Screen
|
* suspend Screen
|
||||||
*/
|
*/
|
||||||
public suspendScreen() {
|
public suspendScreen(): void {
|
||||||
if (this.recordLock) {
|
if (VibrationAndProximityUtils.recordLock) {
|
||||||
this.recordLock.hold(Number.MAX_VALUE);
|
VibrationAndProximityUtils.recordLock.hold(Number.MAX_VALUE);
|
||||||
LogUtils.i(TAG, 'suspendScreen hold');
|
LogUtils.i(TAG, 'suspendScreen hold');
|
||||||
} else {
|
} else {
|
||||||
let that = this;
|
|
||||||
runningLock.create('call_lock', runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL).then(lock => {
|
runningLock.create('call_lock', runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL).then(lock => {
|
||||||
LogUtils.i(TAG, 'suspendScreen create running lock success');
|
LogUtils.i(TAG, 'suspendScreen create running lock success');
|
||||||
try {
|
try {
|
||||||
that.recordLock = lock;
|
VibrationAndProximityUtils.recordLock = lock;
|
||||||
lock.hold(Number.MAX_VALUE);
|
lock.hold(Number.MAX_VALUE);
|
||||||
LogUtils.i(TAG, 'suspendScreen hold');
|
LogUtils.i(TAG, 'suspendScreen hold');
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
LogUtils.e(TAG, 'suspendScreen hold running lock failed, err: ' + err);
|
LogUtils.e(TAG, 'suspendScreen hold running lock failed, err: ' + err);
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
@ -118,19 +66,18 @@ export class VibrationAndProximityUtils {
|
|||||||
/**
|
/**
|
||||||
* wakeup Screen
|
* wakeup Screen
|
||||||
*/
|
*/
|
||||||
public wakeupScreen() {
|
public wakeupScreen(): void {
|
||||||
if (this.recordLock) {
|
if (VibrationAndProximityUtils.recordLock) {
|
||||||
this.recordLock.unhold();
|
VibrationAndProximityUtils.recordLock.unhold();
|
||||||
LogUtils.i(TAG, 'wakeupScreen unhold');
|
LogUtils.i(TAG, 'wakeupScreen unhold');
|
||||||
} else {
|
} else {
|
||||||
let that = this;
|
|
||||||
runningLock.create('call_lock', runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL).then(lock => {
|
runningLock.create('call_lock', runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL).then(lock => {
|
||||||
LogUtils.i(TAG, 'wakeupScreen create running lock success');
|
LogUtils.i(TAG, 'wakeupScreen create running lock success');
|
||||||
try {
|
try {
|
||||||
that.recordLock = lock;
|
VibrationAndProximityUtils.recordLock = lock;
|
||||||
lock.unhold();
|
lock.unhold();
|
||||||
LogUtils.i(TAG, 'wakeupScreen unhold');
|
LogUtils.i(TAG, 'wakeupScreen unhold');
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
LogUtils.e(TAG, 'wakeupScreen unhold running lock failed, err: ' + err);
|
LogUtils.e(TAG, 'wakeupScreen unhold running lock failed, err: ' + err);
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
@ -142,13 +89,12 @@ export class VibrationAndProximityUtils {
|
|||||||
/**
|
/**
|
||||||
* start Vibration
|
* start Vibration
|
||||||
*/
|
*/
|
||||||
public startVibration() {
|
public startVibration(): void {
|
||||||
try {
|
try {
|
||||||
if (this.startVibrationFlag) {
|
if (VibrationAndProximityUtils.startVibrationFlag) {
|
||||||
LogUtils.e(TAG, 'startVibration return');
|
LogUtils.e(TAG, 'startVibration return');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let that = this;
|
|
||||||
vibrator.startVibration({
|
vibrator.startVibration({
|
||||||
type: 'preset',
|
type: 'preset',
|
||||||
effectId: 'haptic.ringtone.T-Mobile_Ring',
|
effectId: 'haptic.ringtone.T-Mobile_Ring',
|
||||||
@ -159,7 +105,7 @@ export class VibrationAndProximityUtils {
|
|||||||
if (error) {
|
if (error) {
|
||||||
LogUtils.e(TAG, 'startVibration fail, error.code: ' + error.code + ', error.message: ' + error.message);
|
LogUtils.e(TAG, 'startVibration fail, error.code: ' + error.code + ', error.message: ' + error.message);
|
||||||
} else {
|
} else {
|
||||||
that.startVibrationFlag = true;
|
VibrationAndProximityUtils.startVibrationFlag = true;
|
||||||
LogUtils.i(TAG, 'startVibration Callback returned to indicate a successful vibration.');
|
LogUtils.i(TAG, 'startVibration Callback returned to indicate a successful vibration.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -171,21 +117,20 @@ export class VibrationAndProximityUtils {
|
|||||||
/**
|
/**
|
||||||
* stop Vibration
|
* stop Vibration
|
||||||
*/
|
*/
|
||||||
public stopVibration() {
|
public stopVibration(): void {
|
||||||
if (!this.startVibrationFlag) {
|
if (!VibrationAndProximityUtils.startVibrationFlag) {
|
||||||
LogUtils.e(TAG, 'stopVibration return');
|
LogUtils.e(TAG, 'stopVibration return');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let that = this;
|
|
||||||
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function (error) {
|
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function (error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
LogUtils.e(TAG, 'stopVibration error.code: ' + error.code + ', error.message: ' + error.message);
|
LogUtils.e(TAG, 'stopVibration error.code: ' + error.code + ', error.message: ' + error.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
that.startVibrationFlag = false;
|
VibrationAndProximityUtils.startVibrationFlag = false;
|
||||||
LogUtils.i(TAG, 'stopVibration Callback returned to indicate successful.');
|
LogUtils.i(TAG, 'stopVibration Callback returned to indicate successful.');
|
||||||
})
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
LogUtils.e(TAG, 'stopVibration errCode: ' + err.code + ' ,msg: ' + err.message);
|
LogUtils.e(TAG, 'stopVibration errCode: ' + err.code + ' ,msg: ' + err.message);
|
||||||
}
|
}
|
||||||
@ -194,7 +139,7 @@ export class VibrationAndProximityUtils {
|
|||||||
/**
|
/**
|
||||||
* add Voice Observe
|
* add Voice Observe
|
||||||
*/
|
*/
|
||||||
addVoiceObserver() {
|
addVoiceObserver(): void {
|
||||||
audio.getAudioManager().on('volumeChange', () => {
|
audio.getAudioManager().on('volumeChange', () => {
|
||||||
LogUtils.i(TAG, 'addVoiceObserver volumeChange');
|
LogUtils.i(TAG, 'addVoiceObserver volumeChange');
|
||||||
this.stopVibration();
|
this.stopVibration();
|
||||||
|
@ -4,7 +4,7 @@ import LogUtils from '../common/utils/LogUtils'
|
|||||||
const TAG = "MyAbilityStage";
|
const TAG = "MyAbilityStage";
|
||||||
|
|
||||||
export default class MyAbilityStage extends AbilityStage {
|
export default class MyAbilityStage extends AbilityStage {
|
||||||
onCreate() {
|
onCreate() {
|
||||||
LogUtils.i(TAG, "onWindowStageDestroy")
|
LogUtils.i(TAG, 'onWindowStageDestroy');
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +1,22 @@
|
|||||||
import Ability from '@ohos.app.ability.UIAbility'
|
import Ability from '@ohos.app.ability.UIAbility'
|
||||||
import Window from '@ohos.window'
|
import type Window from '@ohos.window';
|
||||||
import LogUtils from '../common/utils/LogUtils'
|
import LogUtils from '../common/utils/LogUtils'
|
||||||
|
|
||||||
const TAG = "MainAbility";
|
const TAG = "MainAbility";
|
||||||
|
|
||||||
export default class MainAbility extends Ability {
|
export default class MainAbility extends Ability {
|
||||||
onCreate(want, launchParam) {
|
onCreate(want, launchParam) {
|
||||||
LogUtils.i(TAG, "onCreate");
|
LogUtils.i(TAG, 'onCreate');
|
||||||
globalThis.simCardAbilityContext = this.context;
|
globalThis.simCardAbilityContext = this.context;
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy() {
|
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
|
// Main window is created, set main page for this ability
|
||||||
LogUtils.i(TAG, "onWindowStageCreate");
|
LogUtils.i(TAG, 'onWindowStageCreate');
|
||||||
|
|
||||||
windowStage.loadContent('pages/index', (err, data) => {
|
windowStage.loadContent('pages/index', (err, data) => {
|
||||||
if (err.code) {
|
if (err.code) {
|
||||||
@ -29,16 +29,16 @@ export default class MainAbility extends Ability {
|
|||||||
|
|
||||||
onWindowStageDestroy() {
|
onWindowStageDestroy() {
|
||||||
// Main window is destroyed, release UI related resources
|
// Main window is destroyed, release UI related resources
|
||||||
LogUtils.i(TAG, "onWindowStageDestroy");
|
LogUtils.i(TAG, 'onWindowStageDestroy');
|
||||||
}
|
}
|
||||||
|
|
||||||
onForeground() {
|
onForeground() {
|
||||||
// Ability has brought to foreground
|
// Ability has brought to foreground
|
||||||
LogUtils.i(TAG, "onForeground");
|
LogUtils.i(TAG, 'onForeground');
|
||||||
}
|
}
|
||||||
|
|
||||||
onBackground() {
|
onBackground() {
|
||||||
// Ability has back to background
|
// Ability has back to background
|
||||||
LogUtils.i(TAG, "onBackground");
|
LogUtils.i(TAG, 'onBackground');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,19 +30,19 @@
|
|||||||
*/
|
*/
|
||||||
export class LogUtils {
|
export class LogUtils {
|
||||||
d(TAG, msg): void {
|
d(TAG, msg): void {
|
||||||
console.debug("[simcardmanagement:]" + TAG + ":" + msg);
|
console.debug('[simcardmanagement:]' + TAG + ':' + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
i(TAG, msg): void {
|
i(TAG, msg): void {
|
||||||
console.info("[simcardmanagement:]" + TAG + ":" + msg);
|
console.info('[simcardmanagement:]' + TAG + ':' + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
w(TAG, msg): void {
|
w(TAG, msg): void {
|
||||||
console.warn("[simcardmanagement:]" + TAG + ":" + msg);
|
console.warn('[simcardmanagement:]' + TAG + ':' + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
e(TAG, msg): void {
|
e(TAG, msg): void {
|
||||||
console.error("[simcardmanagement:]" + TAG + ":" + msg);
|
console.error('[simcardmanagement:]' + TAG + ':' + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user