mirror of
https://gitee.com/openharmony/applications_call
synced 2024-11-23 06:19:44 +00:00
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:
parent
b5d03f539a
commit
7e8ed032c6
@ -16,7 +16,7 @@
|
||||
/**
|
||||
* @file: call manager service
|
||||
*/
|
||||
|
||||
import CallServiceProxy from '../model/CallServiceProxy';
|
||||
import TelephonyCall from './TelephonyApi';
|
||||
import commonEvent from '@ohos.commonEvent';
|
||||
import LogUtils from "../common/utils/LogUtils";
|
||||
@ -94,6 +94,7 @@ export default class CallManagerService {
|
||||
|
||||
if (res.event === events[2]) {
|
||||
VibrationAndProximityUtils.stopVibration();
|
||||
CallServiceProxy.getInstance().muteRinger();
|
||||
}
|
||||
} else {
|
||||
LogUtils.i(TAG, "addSubscriber commonEvent.subscribe failed err :" + JSON.stringify(err))
|
||||
@ -156,7 +157,7 @@ export default class CallManagerService {
|
||||
}
|
||||
if (callState === CALL_STATUS_DIALING) {
|
||||
// add Proximity Listener
|
||||
VibrationAndProximityUtils.addProximityListener();
|
||||
VibrationAndProximityUtils.suspendScreen();
|
||||
}
|
||||
} else if (callState !== CALL_STATUS_DISCONNECTING) {
|
||||
this.publishData(callData);
|
||||
|
@ -219,7 +219,7 @@ export default struct IncomingCom {
|
||||
} else {
|
||||
this.mCallServiceProxy.acceptCall(this.callData.callId);
|
||||
}
|
||||
VibrationAndProximityUtils.addProximityListener();
|
||||
VibrationAndProximityUtils.suspendScreen();
|
||||
VibrationAndProximityUtils.stopVibration();
|
||||
}
|
||||
|
||||
|
@ -135,18 +135,15 @@ export function queryAirPlaneMode(callback) {
|
||||
return;
|
||||
}
|
||||
let condition = new dataSharePredicates.DataSharePredicates();
|
||||
condition.equalTo('KEYWORD', 'airplane_mode');
|
||||
try {
|
||||
// ID, KEYWORD, VALUE
|
||||
dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed');
|
||||
let hasNext = data.goToFirstRow();
|
||||
while (hasNext) {
|
||||
if (data.getString(data.getColumnIndex('KEYWORD')) == QUERY_AIRPLANE_MODE_KEY) {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
|
||||
callback(data.getLong(data.getColumnIndex('VALUE')));
|
||||
return;
|
||||
}
|
||||
hasNext = data.goToNextRow();
|
||||
if (data && data.goToFirstRow()) {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
|
||||
callback(data.getLong(data.getColumnIndex('VALUE')));
|
||||
return;
|
||||
}
|
||||
callback(-1);
|
||||
}).catch((err) => {
|
||||
|
@ -25,14 +25,15 @@
|
||||
* 6. uniqueness.
|
||||
*/
|
||||
import audio from '@ohos.multimedia.audio';
|
||||
import CallServiceProxy from '../../model/CallServiceProxy';
|
||||
import LogUtils from './LogUtils';
|
||||
import power from '@ohos.power';
|
||||
import runningLock from '@ohos.runningLock';
|
||||
import sensor from '@ohos.sensor';
|
||||
import vibrator from '@ohos.vibrator';
|
||||
|
||||
const TAG = 'VibrationAndProximityUtils';
|
||||
const PROXIMITY_INTERVAL = 10000000;
|
||||
const VIBRATION_DURATION = 100 * 1000;
|
||||
const VIBRATION_COUNT = 20;
|
||||
|
||||
/**
|
||||
* Vibration And Proximity tool class
|
||||
@ -42,6 +43,7 @@ export class VibrationAndProximityUtils {
|
||||
startVibrationFlag = false;
|
||||
addProximityListenerFlag = false;
|
||||
recordDistance = -1;
|
||||
recordLock = null;
|
||||
|
||||
/**
|
||||
* add Proximity Listener
|
||||
@ -93,11 +95,23 @@ export class VibrationAndProximityUtils {
|
||||
* suspend Screen
|
||||
*/
|
||||
public suspendScreen() {
|
||||
try {
|
||||
power.suspend();
|
||||
LogUtils.i(TAG, 'suspendScreen suspend');
|
||||
} catch(err) {
|
||||
LogUtils.e(TAG, 'suspendScreen suspend failed, err: ' + err);
|
||||
if (this.recordLock) {
|
||||
this.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;
|
||||
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
|
||||
*/
|
||||
public wakeupScreen() {
|
||||
try {
|
||||
power.wakeup('wakeup_call');
|
||||
LogUtils.i(TAG, 'wakeupScreen wakeup');
|
||||
} catch(err) {
|
||||
LogUtils.e(TAG, 'wakeupScreen wakeup failed, err: ' + err);
|
||||
if (this.recordLock) {
|
||||
this.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;
|
||||
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;
|
||||
vibrator.startVibration({
|
||||
type: 'time',
|
||||
duration: VIBRATION_DURATION,
|
||||
type: 'preset',
|
||||
effectId: 'haptic.ringtone.T-Mobile_Ring',
|
||||
count: VIBRATION_COUNT
|
||||
}, {
|
||||
usage: 'ring'
|
||||
}, (error) => {
|
||||
@ -151,7 +178,7 @@ export class VibrationAndProximityUtils {
|
||||
}
|
||||
try {
|
||||
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) {
|
||||
LogUtils.e(TAG, 'stopVibration error.code: ' + error.code + ', error.message: ' + error.message);
|
||||
return;
|
||||
@ -171,6 +198,7 @@ export class VibrationAndProximityUtils {
|
||||
audio.getAudioManager().on('volumeChange', () => {
|
||||
LogUtils.i(TAG, 'addVoiceObserver volumeChange');
|
||||
this.stopVibration();
|
||||
CallServiceProxy.getInstance().muteRinger();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ export default class CallDataManager {
|
||||
LogUtils.i(TAG, "calluiAbility terminateSelf");
|
||||
});
|
||||
// remove Proximity Listener
|
||||
VibrationAndProximityUtils.removeProximityListener();
|
||||
VibrationAndProximityUtils.wakeupScreen();
|
||||
VibrationAndProximityUtils.stopVibration();
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ import call from '@ohos.telephony.call';
|
||||
import CallStateConst from '../common/constant/CallStateConst';
|
||||
import DefaultCallData from '../common/struct/TypeUtils';
|
||||
import CallListStruct from '../common/struct/CallListStruct';
|
||||
import VibrationAndProximityUtils from '../common/utils/VibrationAndProximityUtils';
|
||||
|
||||
const TAG = "CallManager";
|
||||
const TIMING = 1000;
|
||||
@ -114,6 +115,9 @@ export default class CallManager {
|
||||
globalThis.calluiAbilityContext?.terminateSelf().then((data) => {
|
||||
LogUtils.i(TAG, "calluiAbility terminateSelf because service disconnected");
|
||||
});
|
||||
// remove Proximity Listener
|
||||
VibrationAndProximityUtils.wakeupScreen();
|
||||
VibrationAndProximityUtils.stopVibration();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -42,7 +42,7 @@ export default struct ConfirmDialogEx {
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
.maxLines(2)
|
||||
}
|
||||
.margin({ bottom: 10, top: 10 })
|
||||
.margin({ bottom: 8, top: 10 })
|
||||
|
||||
Row() {
|
||||
Flex({
|
||||
|
@ -114,6 +114,10 @@
|
||||
{
|
||||
"name": "ohos.permission.PLACE_CALL",
|
||||
"reason": "$string:PLACE_CALL"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.RUNNING_LOCK",
|
||||
"reason": "$string:RUNNING_LOCK"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -129,6 +129,10 @@
|
||||
{
|
||||
"name": "ohos.permission.PLACE_CALL",
|
||||
"reason": "$string:PLACE_CALL"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.RUNNING_LOCK",
|
||||
"reason": "$string:RUNNING_LOCK"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -267,6 +267,10 @@
|
||||
{
|
||||
"name": "PLACE_CALL",
|
||||
"value": "place call"
|
||||
},
|
||||
{
|
||||
"name": "RUNNING_LOCK",
|
||||
"value": "running lock"
|
||||
}
|
||||
]
|
||||
}
|
@ -271,6 +271,10 @@
|
||||
{
|
||||
"name": "PLACE_CALL",
|
||||
"value": "拨打电话"
|
||||
},
|
||||
{
|
||||
"name": "RUNNING_LOCK",
|
||||
"value": "屏幕运行锁"
|
||||
}
|
||||
]
|
||||
}
|
@ -80,18 +80,15 @@ export function queryAirPlaneMode(callback) {
|
||||
return;
|
||||
}
|
||||
let condition = new dataSharePredicates.DataSharePredicates();
|
||||
condition.equalTo('KEYWORD', 'airplane_mode');
|
||||
try {
|
||||
// ID, KEYWORD, VALUE
|
||||
dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed');
|
||||
let hasNext = data.goToFirstRow();
|
||||
while (hasNext) {
|
||||
if (data.getString(data.getColumnIndex('KEYWORD')) == QUERY_AIRPLANE_MODE_KEY) {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
|
||||
callback(data.getLong(data.getColumnIndex('VALUE')));
|
||||
return;
|
||||
}
|
||||
hasNext = data.goToNextRow();
|
||||
if (data && data.goToFirstRow()) {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
|
||||
callback(data.getLong(data.getColumnIndex('VALUE')));
|
||||
return;
|
||||
}
|
||||
callback(-1);
|
||||
}).catch((err) => {
|
||||
|
Binary file not shown.
@ -80,18 +80,15 @@ export function queryAirPlaneMode(callback) {
|
||||
return;
|
||||
}
|
||||
let condition = new dataSharePredicates.DataSharePredicates();
|
||||
condition.equalTo('KEYWORD', 'airplane_mode');
|
||||
try {
|
||||
// ID, KEYWORD, VALUE
|
||||
dataShareHelper.query(SETTING_AIRPLANE_MODE_URI, condition, null).then((data) => {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed');
|
||||
let hasNext = data.goToFirstRow();
|
||||
while (hasNext) {
|
||||
if (data.getString(data.getColumnIndex('KEYWORD')) == QUERY_AIRPLANE_MODE_KEY) {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
|
||||
callback(data.getLong(data.getColumnIndex('VALUE')));
|
||||
return;
|
||||
}
|
||||
hasNext = data.goToNextRow();
|
||||
if (data && data.goToFirstRow()) {
|
||||
LogUtils.i(TAG, 'queryAirPlaneMode query succeed return key');
|
||||
callback(data.getLong(data.getColumnIndex('VALUE')));
|
||||
return;
|
||||
}
|
||||
callback(-1);
|
||||
}).catch((err) => {
|
||||
|
Loading…
Reference in New Issue
Block a user