From 7e8ed032c6a69912b4906c282552fc4f8932df0a Mon Sep 17 00:00:00 2001 From: masz0822 Date: Fri, 26 May 2023 15:06:25 +0800 Subject: [PATCH] =?UTF-8?q?Description:=20=E4=BF=AE=E6=94=B9=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=9D=A5=E7=94=B5=E6=8C=AF=E5=8A=A8=E5=92=8C=E6=8E=A5?= =?UTF-8?q?=E8=BF=91=E5=85=89=E5=8A=9F=E8=83=BD=20Sig:=20SIG=5FBscSoftSrv?= =?UTF-8?q?=20Feature=20or=20Bugfix:=20Feature=20Binary=20Source:=20callui?= =?UTF-8?q?.p7b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaobingqing --- .../ets/ServiceAbility/CallManagerService.ts | 5 +- .../ets/common/components/IncomingCom.ets | 2 +- .../main/ets/common/utils/AirplaneMode.ets | 13 ++-- .../utils/VibrationAndProximityUtils.ts | 58 +++++++++++++----- entry/src/main/ets/model/CallDataManager.ets | 2 +- entry/src/main/ets/model/CallManager.ets | 4 ++ entry/src/main/ets/model/CallServiceProxy.ets | 10 +++ .../main/ets/pages/dialog/ConfirmDialogEx.ets | 2 +- entry/src/main/module.json | 4 ++ entry/src/main/module.json5 | 4 ++ .../main/resources/base/element/string.json | 4 ++ .../main/resources/zh_CN/element/string.json | 4 ++ .../main/ets/common/utils/AirplaneMode.ets | 13 ++-- signature/callui.p7b | Bin 4043 -> 4074 bytes .../main/ets/common/utils/AirplaneMode.ets | 13 ++-- 15 files changed, 94 insertions(+), 44 deletions(-) diff --git a/entry/src/main/ets/ServiceAbility/CallManagerService.ts b/entry/src/main/ets/ServiceAbility/CallManagerService.ts index 4d2279d..54958be 100644 --- a/entry/src/main/ets/ServiceAbility/CallManagerService.ts +++ b/entry/src/main/ets/ServiceAbility/CallManagerService.ts @@ -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); diff --git a/entry/src/main/ets/common/components/IncomingCom.ets b/entry/src/main/ets/common/components/IncomingCom.ets index bc3cd0e..7ae4bc0 100644 --- a/entry/src/main/ets/common/components/IncomingCom.ets +++ b/entry/src/main/ets/common/components/IncomingCom.ets @@ -219,7 +219,7 @@ export default struct IncomingCom { } else { this.mCallServiceProxy.acceptCall(this.callData.callId); } - VibrationAndProximityUtils.addProximityListener(); + VibrationAndProximityUtils.suspendScreen(); VibrationAndProximityUtils.stopVibration(); } diff --git a/entry/src/main/ets/common/utils/AirplaneMode.ets b/entry/src/main/ets/common/utils/AirplaneMode.ets index bbff82d..af41045 100644 --- a/entry/src/main/ets/common/utils/AirplaneMode.ets +++ b/entry/src/main/ets/common/utils/AirplaneMode.ets @@ -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) => { diff --git a/entry/src/main/ets/common/utils/VibrationAndProximityUtils.ts b/entry/src/main/ets/common/utils/VibrationAndProximityUtils.ts index 10e907a..9fe95a5 100644 --- a/entry/src/main/ets/common/utils/VibrationAndProximityUtils.ts +++ b/entry/src/main/ets/common/utils/VibrationAndProximityUtils.ts @@ -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(); }); } } diff --git a/entry/src/main/ets/model/CallDataManager.ets b/entry/src/main/ets/model/CallDataManager.ets index d2d5914..84f8b40 100644 --- a/entry/src/main/ets/model/CallDataManager.ets +++ b/entry/src/main/ets/model/CallDataManager.ets @@ -159,7 +159,7 @@ export default class CallDataManager { LogUtils.i(TAG, "calluiAbility terminateSelf"); }); // remove Proximity Listener - VibrationAndProximityUtils.removeProximityListener(); + VibrationAndProximityUtils.wakeupScreen(); VibrationAndProximityUtils.stopVibration(); } diff --git a/entry/src/main/ets/model/CallManager.ets b/entry/src/main/ets/model/CallManager.ets index dc210f8..fed0a13 100644 --- a/entry/src/main/ets/model/CallManager.ets +++ b/entry/src/main/ets/model/CallManager.ets @@ -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; } } diff --git a/entry/src/main/ets/model/CallServiceProxy.ets b/entry/src/main/ets/model/CallServiceProxy.ets index e4aee9c..9ddbd8c 100644 --- a/entry/src/main/ets/model/CallServiceProxy.ets +++ b/entry/src/main/ets/model/CallServiceProxy.ets @@ -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 * diff --git a/entry/src/main/ets/pages/dialog/ConfirmDialogEx.ets b/entry/src/main/ets/pages/dialog/ConfirmDialogEx.ets index 4f00d00..6d95000 100644 --- a/entry/src/main/ets/pages/dialog/ConfirmDialogEx.ets +++ b/entry/src/main/ets/pages/dialog/ConfirmDialogEx.ets @@ -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({ diff --git a/entry/src/main/module.json b/entry/src/main/module.json index c20f3e3..88da4b1 100644 --- a/entry/src/main/module.json +++ b/entry/src/main/module.json @@ -114,6 +114,10 @@ { "name": "ohos.permission.PLACE_CALL", "reason": "$string:PLACE_CALL" + }, + { + "name": "ohos.permission.RUNNING_LOCK", + "reason": "$string:RUNNING_LOCK" } ] } diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index 99144ec..03f6111 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -129,6 +129,10 @@ { "name": "ohos.permission.PLACE_CALL", "reason": "$string:PLACE_CALL" + }, + { + "name": "ohos.permission.RUNNING_LOCK", + "reason": "$string:RUNNING_LOCK" } ] } diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 4994946..634dcc4 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -267,6 +267,10 @@ { "name": "PLACE_CALL", "value": "place call" + }, + { + "name": "RUNNING_LOCK", + "value": "running lock" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 0df288f..ab716df 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -271,6 +271,10 @@ { "name": "PLACE_CALL", "value": "拨打电话" + }, + { + "name": "RUNNING_LOCK", + "value": "屏幕运行锁" } ] } \ No newline at end of file diff --git a/mobiledatasettings/src/main/ets/common/utils/AirplaneMode.ets b/mobiledatasettings/src/main/ets/common/utils/AirplaneMode.ets index a4f196b..3683200 100644 --- a/mobiledatasettings/src/main/ets/common/utils/AirplaneMode.ets +++ b/mobiledatasettings/src/main/ets/common/utils/AirplaneMode.ets @@ -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) => { diff --git a/signature/callui.p7b b/signature/callui.p7b index 59e128e20bf93a77cb972ae356af5941b25a2d77..8dc39f02424833bc2523e520417ac4ed72dddbdd 100644 GIT binary patch delta 241 zcmX>t|4QD$po#w(8>d#AN85K^Ms}tJP5jq^LYJ8s84Y<2xY;-p+B_IjnOT?^4Vu{7 z5DFO=G_jYnG_e)#)RR7NIFpIAB#U+nJRAx+7l+8-sd2_|xLkHil11kA@mEl&a*36a% dLDHsT;Sz$YEY=E}f99IEBR+Kg%h?9cQve>&R44!d delta 224 zcmaDQe_Gzbpo#xD8>d#AN85K^Ms}tJP5e86LR**^84Y<2xY;-p+B_IjnOT?^4Vu`~ z5egX>G_gmpG_i+lbU4ShS(jaxqu$We(9qb(*f`2SAFhs*#ZZYwA*=D}?`=_jET6jW zm@>E)b}mv?h?w4ay{dG@P_f;WU54gKZ8*8q#9M z)zf5>7SD1}HIDrtV5lUruX}5smOoI*ViaWm$Gzu-!aef6f(KkNp$= Lr#iJrW^4rjeMd?l diff --git a/simcardmanagement/src/main/ets/common/utils/AirplaneMode.ets b/simcardmanagement/src/main/ets/common/utils/AirplaneMode.ets index 709c5be..366d2b1 100644 --- a/simcardmanagement/src/main/ets/common/utils/AirplaneMode.ets +++ b/simcardmanagement/src/main/ets/common/utils/AirplaneMode.ets @@ -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) => {