Description: 修改支持来电振动和接近光功能

Sig: SIG_BscSoftSrv
Feature or Bugfix: Feature
Binary Source: callui.p7b

Signed-off-by: gaobingqing <gaobingqing5@h-partners.com>
This commit is contained in:
masz0822 2023-05-26 15:06:25 +08:00
parent b5d03f539a
commit 7e8ed032c6
15 changed files with 94 additions and 44 deletions

View File

@ -16,7 +16,7 @@
/** /**
* @file: call manager service * @file: call manager service
*/ */
import CallServiceProxy from '../model/CallServiceProxy';
import TelephonyCall from './TelephonyApi'; import TelephonyCall from './TelephonyApi';
import commonEvent from '@ohos.commonEvent'; import commonEvent from '@ohos.commonEvent';
import LogUtils from "../common/utils/LogUtils"; import LogUtils from "../common/utils/LogUtils";
@ -94,6 +94,7 @@ export default class CallManagerService {
if (res.event === events[2]) { if (res.event === events[2]) {
VibrationAndProximityUtils.stopVibration(); VibrationAndProximityUtils.stopVibration();
CallServiceProxy.getInstance().muteRinger();
} }
} else { } else {
LogUtils.i(TAG, "addSubscriber commonEvent.subscribe failed err :" + JSON.stringify(err)) LogUtils.i(TAG, "addSubscriber commonEvent.subscribe failed err :" + JSON.stringify(err))
@ -156,7 +157,7 @@ export default class CallManagerService {
} }
if (callState === CALL_STATUS_DIALING) { if (callState === CALL_STATUS_DIALING) {
// add Proximity Listener // add Proximity Listener
VibrationAndProximityUtils.addProximityListener(); VibrationAndProximityUtils.suspendScreen();
} }
} else if (callState !== CALL_STATUS_DISCONNECTING) { } else if (callState !== CALL_STATUS_DISCONNECTING) {
this.publishData(callData); this.publishData(callData);

View File

@ -219,7 +219,7 @@ export default struct IncomingCom {
} else { } else {
this.mCallServiceProxy.acceptCall(this.callData.callId); this.mCallServiceProxy.acceptCall(this.callData.callId);
} }
VibrationAndProximityUtils.addProximityListener(); VibrationAndProximityUtils.suspendScreen();
VibrationAndProximityUtils.stopVibration(); VibrationAndProximityUtils.stopVibration();
} }

View File

@ -135,18 +135,15 @@ export function queryAirPlaneMode(callback) {
return; return;
} }
let condition = new dataSharePredicates.DataSharePredicates(); let condition = new dataSharePredicates.DataSharePredicates();
condition.equalTo('KEYWORD', 'airplane_mode');
try { try {
// ID, KEYWORD, VALUE // ID, KEYWORD, VALUE
dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => { dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => {
LogUtils.i(TAG, 'queryAirPlaneMode query succeed'); LogUtils.i(TAG, 'queryAirPlaneMode query succeed');
let hasNext = data.goToFirstRow(); if (data && data.goToFirstRow()) {
while (hasNext) { LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
if (data.getString(data.getColumnIndex('KEYWORD')) == QUERY_AIRPLANE_MODE_KEY) { callback(data.getLong(data.getColumnIndex('VALUE')));
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key'); return;
callback(data.getLong(data.getColumnIndex('VALUE')));
return;
}
hasNext = data.goToNextRow();
} }
callback(-1); callback(-1);
}).catch((err) => { }).catch((err) => {

View File

@ -25,14 +25,15 @@
* 6. uniqueness. * 6. uniqueness.
*/ */
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
import CallServiceProxy from '../../model/CallServiceProxy';
import LogUtils from './LogUtils'; import LogUtils from './LogUtils';
import power from '@ohos.power'; import runningLock from '@ohos.runningLock';
import sensor from '@ohos.sensor'; 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 PROXIMITY_INTERVAL = 10000000;
const VIBRATION_DURATION = 100 * 1000; const VIBRATION_COUNT = 20;
/** /**
* Vibration And Proximity tool class * Vibration And Proximity tool class
@ -42,6 +43,7 @@ export class VibrationAndProximityUtils {
startVibrationFlag = false; startVibrationFlag = false;
addProximityListenerFlag = false; addProximityListenerFlag = false;
recordDistance = -1; recordDistance = -1;
recordLock = null;
/** /**
* add Proximity Listener * add Proximity Listener
@ -93,11 +95,23 @@ export class VibrationAndProximityUtils {
* suspend Screen * suspend Screen
*/ */
public suspendScreen() { public suspendScreen() {
try { if (this.recordLock) {
power.suspend(); this.recordLock.hold(Number.MAX_VALUE);
LogUtils.i(TAG, 'suspendScreen suspend'); LogUtils.i(TAG, 'suspendScreen hold');
} catch(err) { } else {
LogUtils.e(TAG, 'suspendScreen suspend failed, err: ' + err); 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;
lock.hold(Number.MAX_VALUE);
LogUtils.i(TAG, 'suspendScreen hold');
} catch(err) {
LogUtils.e(TAG, 'suspendScreen hold running lock failed, err: ' + err);
}
}).catch(err => {
LogUtils.e(TAG, 'suspendScreen create running lock failed, err: ' + err);
});
} }
} }
@ -105,11 +119,23 @@ export class VibrationAndProximityUtils {
* wakeup Screen * wakeup Screen
*/ */
public wakeupScreen() { public wakeupScreen() {
try { if (this.recordLock) {
power.wakeup('wakeup_call'); this.recordLock.unhold();
LogUtils.i(TAG, 'wakeupScreen wakeup'); LogUtils.i(TAG, 'wakeupScreen unhold');
} catch(err) { } else {
LogUtils.e(TAG, 'wakeupScreen wakeup failed, err: ' + err); 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;
lock.unhold();
LogUtils.i(TAG, 'wakeupScreen unhold');
} catch(err) {
LogUtils.e(TAG, 'wakeupScreen unhold running lock failed, err: ' + err);
}
}).catch(err => {
LogUtils.e(TAG, 'wakeupScreen create running lock failed, err: ' + err);
});
} }
} }
@ -124,8 +150,9 @@ export class VibrationAndProximityUtils {
} }
let that = this; let that = this;
vibrator.startVibration({ vibrator.startVibration({
type: 'time', type: 'preset',
duration: VIBRATION_DURATION, effectId: 'haptic.ringtone.T-Mobile_Ring',
count: VIBRATION_COUNT
}, { }, {
usage: 'ring' usage: 'ring'
}, (error) => { }, (error) => {
@ -151,7 +178,7 @@ export class VibrationAndProximityUtils {
} }
try { try {
let that = this; let that = this;
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, 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;
@ -171,6 +198,7 @@ export class VibrationAndProximityUtils {
audio.getAudioManager().on('volumeChange', () => { audio.getAudioManager().on('volumeChange', () => {
LogUtils.i(TAG, 'addVoiceObserver volumeChange'); LogUtils.i(TAG, 'addVoiceObserver volumeChange');
this.stopVibration(); this.stopVibration();
CallServiceProxy.getInstance().muteRinger();
}); });
} }
} }

View File

@ -159,7 +159,7 @@ export default class CallDataManager {
LogUtils.i(TAG, "calluiAbility terminateSelf"); LogUtils.i(TAG, "calluiAbility terminateSelf");
}); });
// remove Proximity Listener // remove Proximity Listener
VibrationAndProximityUtils.removeProximityListener(); VibrationAndProximityUtils.wakeupScreen();
VibrationAndProximityUtils.stopVibration(); VibrationAndProximityUtils.stopVibration();
} }

View File

@ -25,6 +25,7 @@ import call from '@ohos.telephony.call';
import CallStateConst from '../common/constant/CallStateConst'; import CallStateConst from '../common/constant/CallStateConst';
import DefaultCallData from '../common/struct/TypeUtils'; import DefaultCallData from '../common/struct/TypeUtils';
import CallListStruct from '../common/struct/CallListStruct'; import CallListStruct from '../common/struct/CallListStruct';
import VibrationAndProximityUtils from '../common/utils/VibrationAndProximityUtils';
const TAG = "CallManager"; const TAG = "CallManager";
const TIMING = 1000; const TIMING = 1000;
@ -114,6 +115,9 @@ export default class CallManager {
globalThis.calluiAbilityContext?.terminateSelf().then((data) => { globalThis.calluiAbilityContext?.terminateSelf().then((data) => {
LogUtils.i(TAG, "calluiAbility terminateSelf because service disconnected"); LogUtils.i(TAG, "calluiAbility terminateSelf because service disconnected");
}); });
// remove Proximity Listener
VibrationAndProximityUtils.wakeupScreen();
VibrationAndProximityUtils.stopVibration();
return; return;
} }
} }

View File

@ -60,6 +60,16 @@ export default class CallServiceProxy {
}); });
} }
/**
* Stops the ringtone.
*/
public muteRinger() {
LogUtils.i(TAG, 'muteRinger')
call.muteRinger((err) => {
LogUtils.e(TAG, `muteRinger callback: err->${JSON.stringify(err)}`);
});
}
/** /**
* accept call * accept call
* *

View File

@ -42,7 +42,7 @@ export default struct ConfirmDialogEx {
.textOverflow({ overflow: TextOverflow.Ellipsis }) .textOverflow({ overflow: TextOverflow.Ellipsis })
.maxLines(2) .maxLines(2)
} }
.margin({ bottom: 10, top: 10 }) .margin({ bottom: 8, top: 10 })
Row() { Row() {
Flex({ Flex({

View File

@ -114,6 +114,10 @@
{ {
"name": "ohos.permission.PLACE_CALL", "name": "ohos.permission.PLACE_CALL",
"reason": "$string:PLACE_CALL" "reason": "$string:PLACE_CALL"
},
{
"name": "ohos.permission.RUNNING_LOCK",
"reason": "$string:RUNNING_LOCK"
} }
] ]
} }

View File

@ -129,6 +129,10 @@
{ {
"name": "ohos.permission.PLACE_CALL", "name": "ohos.permission.PLACE_CALL",
"reason": "$string:PLACE_CALL" "reason": "$string:PLACE_CALL"
},
{
"name": "ohos.permission.RUNNING_LOCK",
"reason": "$string:RUNNING_LOCK"
} }
] ]
} }

View File

@ -267,6 +267,10 @@
{ {
"name": "PLACE_CALL", "name": "PLACE_CALL",
"value": "place call" "value": "place call"
},
{
"name": "RUNNING_LOCK",
"value": "running lock"
} }
] ]
} }

View File

@ -271,6 +271,10 @@
{ {
"name": "PLACE_CALL", "name": "PLACE_CALL",
"value": "拨打电话" "value": "拨打电话"
},
{
"name": "RUNNING_LOCK",
"value": "屏幕运行锁"
} }
] ]
} }

View File

@ -80,18 +80,15 @@ export function queryAirPlaneMode(callback) {
return; return;
} }
let condition = new dataSharePredicates.DataSharePredicates(); let condition = new dataSharePredicates.DataSharePredicates();
condition.equalTo('KEYWORD', 'airplane_mode');
try { try {
// ID, KEYWORD, VALUE // ID, KEYWORD, VALUE
dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => { dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => {
LogUtils.i(TAG, 'queryAirPlaneMode query succeed'); LogUtils.i(TAG, 'queryAirPlaneMode query succeed');
let hasNext = data.goToFirstRow(); if (data && data.goToFirstRow()) {
while (hasNext) { LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
if (data.getString(data.getColumnIndex('KEYWORD')) == QUERY_AIRPLANE_MODE_KEY) { callback(data.getLong(data.getColumnIndex('VALUE')));
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key'); return;
callback(data.getLong(data.getColumnIndex('VALUE')));
return;
}
hasNext = data.goToNextRow();
} }
callback(-1); callback(-1);
}).catch((err) => { }).catch((err) => {

Binary file not shown.

View File

@ -80,18 +80,15 @@ export function queryAirPlaneMode(callback) {
return; return;
} }
let condition = new dataSharePredicates.DataSharePredicates(); let condition = new dataSharePredicates.DataSharePredicates();
condition.equalTo('KEYWORD', 'airplane_mode');
try { try {
// ID, KEYWORD, VALUE // ID, KEYWORD, VALUE
dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => { dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => {
LogUtils.i(TAG, 'queryAirPlaneMode query succeed'); LogUtils.i(TAG, 'queryAirPlaneMode query succeed');
let hasNext = data.goToFirstRow(); if (data && data.goToFirstRow()) {
while (hasNext) { LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
if (data.getString(data.getColumnIndex('KEYWORD')) == QUERY_AIRPLANE_MODE_KEY) { callback(data.getLong(data.getColumnIndex('VALUE')));
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key'); return;
callback(data.getLong(data.getColumnIndex('VALUE')));
return;
}
hasNext = data.goToNextRow();
} }
callback(-1); callback(-1);
}).catch((err) => { }).catch((err) => {