update notification mode

Signed-off-by: w00636648 <wangziming14@huawei.com>
This commit is contained in:
w00636648 2022-10-14 17:18:54 +08:00
parent 89a926cd09
commit 1de6f67bb9
21 changed files with 169 additions and 75 deletions

View File

@ -22,7 +22,7 @@
"certpath": "signature/OpenHarmony.cer",
"keyAlias": "OpenHarmony Application Profile Release",
"keyPassword": "",
"profile": "signature/com_ohos_Callui.p7b",
"profile": "signature/callui.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "signature/OpenHarmony.p12"
}
@ -39,7 +39,7 @@
},
"modules": [
{
"name": "com.ohos.callui",
"name": "callui",
"srcPath": "./entry",
"targets": [
{
@ -55,7 +55,7 @@
"srcPath": "./common"
},
{
"name": "com.ohos.mobiledatasettings",
"name": "mobiledatasettings",
"srcPath": "./mobiledatasettings",
"targets": [
{

View File

@ -1,6 +1,5 @@
import AbilityStage from "@ohos.application.AbilityStage"
import deviceInfo from '@ohos.deviceInfo';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import LogUtils from '../common/utils/LogUtils'
import notification from '@ohos.notification';
@ -9,7 +8,6 @@ const TAG = "MyAbilityStage";
export default class MyAbilityStage extends AbilityStage {
onCreate() {
globalThis.deviceTypeInfo = deviceInfo.deviceType;
this.applyEfficiencyResources();
notification.enableNotification({
bundle: "com.ohos.callui"
}, true, (err, data) => {
@ -22,20 +20,6 @@ export default class MyAbilityStage extends AbilityStage {
onDestroy() {
LogUtils.i(TAG, "MyAbilityStage onDestroy")
backgroundTaskManager.resetAllEfficiencyResources();
}
private applyEfficiencyResources() {
let request: backgroundTaskManager.EfficiencyResourcesRequest = {
resourceTypes: backgroundTaskManager.ResourceType.COMMON_EVENT,
isApply: true,
timeOut: 0,
reason: "apply",
isPersist: true,
isProcess: false,
}
let res = backgroundTaskManager.applyEfficiencyResources(request);
LogUtils.i(TAG, "result of applyEfficiencyResources is:" + res)
}
}

View File

@ -1,4 +1,3 @@
import featureAbility from '@ohos.ability.featureAbility';
import Ability from '@ohos.application.Ability'
import LogUtils from '../common/utils/LogUtils'

View File

@ -17,7 +17,7 @@ import Method from '../utils/Method';
import FuncBtn from './FuncBtn';
import CallStateConst from '../constant/CallStateConst';
import CallServiceProxy from '../../model/CallServiceProxy';
import Clone from '../utils/clone';
import Clone from '../utils/Clone';
import ConferenceConst from '../constant/ConferenceConst';
import BtnGroupConfig from '../configs/BtnGroupConfig';
import LogUtils from '../utils/LogUtils';

View File

@ -16,7 +16,7 @@
import FuncBtn from './FuncBtn';
import InComDialog from './InComDialog';
import ImagePathConst from '../constant/ImagePathConst';
import CallStateConst from '../constant/callStateConst';
import CallStateConst from '../constant/CallStateConst';
import CallServiceProxy from '../../model/CallServiceProxy';
import sms from '@ohos.telephony.sms';
import resourceManager from '@ohos.resourceManager';

View File

@ -0,0 +1,28 @@
/**
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* constants package tool class
*/
export class Constants {
public APP_KEY_CALLDATAMANGER_MANAGER: string = "CallDataManager";
public CALL_BUNDLE_NAME = 'com.ohos.callui';
public CALL_ABILITY_NAME = 'com.ohos.callui.MainAbility';
}
let mConstants = new Constants();
export default mConstants as Constants;

View File

@ -0,0 +1,26 @@
/**
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import LogUtils from './LogUtils'
const TAG = "SingleInstanceHelper";
export default function createOrGet<T>(objectClass: { new(): T }, storageKey: string): T {
if (!globalThis[storageKey]) {
globalThis[storageKey] = new objectClass();
LogUtils.i(TAG, "Create key of: " + JSON.stringify(storageKey));
}
return globalThis[storageKey];
}

View File

@ -20,8 +20,10 @@ import CallStateManager from './CallStateManager';
import CallStateConst from '../common/constant/CallStateConst';
import NotificationManager from '../model/NotificationManager';
import LogUtils from '../common/utils/LogUtils';
import getSingleInstance from '../common/utils/SingleInstanceHelper'
const TAG = "CallDataManager";
const CALL_DATA_MANAGER_KEY = 'AppStorage_CallDataManager';
/**
* class CallDataManager
@ -33,9 +35,15 @@ export default class CallDataManager {
private callStateChange: any;
private mCallStateManager: CallStateManager ;
private NotificationManager ;
private sCallDataManager: CallDataManager ;
constructor(callData, callList, callTimeList) {
public static getInstance():CallDataManager{
return getSingleInstance(CallDataManager, CALL_DATA_MANAGER_KEY);
}
/**
* Init data.
*/
public init(callData, callList, callTimeList) {
this.NotificationManager = new NotificationManager()
this.mCallStateManager = CallStateManager.getInstance()
this.callData = callData;
@ -101,6 +109,15 @@ export default class CallDataManager {
}
}
/**
* Judge whether the call exists.
*/
public hasAliveCall(): Boolean {
LogUtils.i(TAG, "hasAliveCall 1: true")
return this.callList.find((call) => call.callState !== CallStateConst.CALL_STATUS_DISCONNECTED
&& call.callState !== CallStateConst.CALL_STATUS_DISCONNECTING);
}
/**
* addCallList
*

View File

@ -54,7 +54,8 @@ export default class CallManager {
this.timer = null;
this.ctx = ctx;
this.callTimeList = ctx.callTimeList;
this.mCallDataManager = new CallDataManager(ctx.callData, ctx.callList, ctx.callTimeList);
this.mCallDataManager = CallDataManager.getInstance();
this.mCallDataManager.init(ctx.callData, ctx.callList, ctx.callTimeList);
this.openTimer();
this.sendNotificationHandle = (arg) => arg;
this.registerSubscriber();

View File

@ -25,11 +25,12 @@
import commonEvent from '@ohos.commonEvent';
import call from '@ohos.telephony.call';
import app from '@system.app';
import getSingleInstance from '../common/utils/SingleInstanceHelper'
import LogUtils from '../common/utils/LogUtils';
const TAG = "CallServiceProxy";
const prefixLog = 'callUI app:@ohos.telephony.call:';
const CALL_SERVICE_PROXY_KEY = 'AppStorage_CallServiceProxy'
/**
* dial call
@ -40,7 +41,9 @@ const prefixLog = 'callUI app:@ohos.telephony.call:';
* @return { Object } promise object
*/
export default class CallServiceProxy {
private static sCallServiceProxy: CallServiceProxy ;
public static getInstance(): CallServiceProxy {
return getSingleInstance(CallServiceProxy, CALL_SERVICE_PROXY_KEY);
}
/**
* Make a phone call
@ -54,13 +57,6 @@ export default class CallServiceProxy {
});
}
public static getInstance(): CallServiceProxy {
if (CallServiceProxy.sCallServiceProxy == null) {
CallServiceProxy.sCallServiceProxy = new CallServiceProxy();
}
return CallServiceProxy.sCallServiceProxy;
}
/**
* accept call
*
@ -84,13 +80,15 @@ export default class CallServiceProxy {
* @param { string } msg - message string
*/
public rejectCall = function (callId, isSendSms = false, msg = '') {
const rejectCallPromise = isSendSms ? call.reject(callId, {messageContent: msg}) : call.reject(callId);
const rejectCallPromise = isSendSms ? call.reject(callId, {
messageContent: msg
}) : call.reject(callId);
rejectCallPromise.then((res) => {
LogUtils.i(TAG,prefixLog + "then:rejectCall")
LogUtils.i(TAG, prefixLog + "then:rejectCall")
})
.catch((err) => {
LogUtils.i(TAG, prefixLog + "catch:rejectCall : %s" + JSON.stringify(err))
});
});
};
/**
@ -124,8 +122,8 @@ export default class CallServiceProxy {
})
.catch((err) => {
reject(err);
LogUtils.i(TAG, prefixLog + "catch:holdCall : %s" + JSON.stringify(err))
});
LogUtils.i(TAG, prefixLog + "catch:holdCall : %s" + JSON.stringify(err))
});
});
/**
@ -142,8 +140,8 @@ export default class CallServiceProxy {
})
.catch((err) => {
reject(err);
LogUtils.i(TAG, prefixLog + "catch:unHoldCall : %s" + JSON.stringify(err))
});
LogUtils.i(TAG, prefixLog + "catch:unHoldCall : %s" + JSON.stringify(err))
});
});
@ -160,7 +158,7 @@ export default class CallServiceProxy {
resolve(res);
}).catch((err) => {
reject(err);
LogUtils.i(TAG, prefixLog + "catch:setAudioDevice : %s" + JSON.stringify(err))
LogUtils.i(TAG, prefixLog + "catch:setAudioDevice : %s" + JSON.stringify(err))
});
});
@ -169,9 +167,9 @@ export default class CallServiceProxy {
*/
public setMuted() {
call.setMuted().then((res) => {
LogUtils.i(TAG, prefixLog + "then:setMute")
LogUtils.i(TAG, prefixLog + "then:setMute")
}).catch((err) => {
LogUtils.i(TAG,prefixLog + "catch:setMute : %s" + JSON.stringify(err))
LogUtils.i(TAG, prefixLog + "catch:setMute : %s" + JSON.stringify(err))
});
};
@ -180,9 +178,9 @@ export default class CallServiceProxy {
*/
public cancelMuted() {
call.cancelMuted().then((res) => {
LogUtils.i(TAG,prefixLog + "then:cancelMuted")
LogUtils.i(TAG, prefixLog + "then:cancelMuted")
}).catch((err) => {
LogUtils.i(TAG, prefixLog + "catch:cancelMuted : %s" + JSON.stringify(err))
LogUtils.i(TAG, prefixLog + "catch:cancelMuted : %s" + JSON.stringify(err))
});
};
@ -200,8 +198,8 @@ export default class CallServiceProxy {
})
.catch((err) => {
reject(err);
LogUtils.i(TAG, prefixLog + "catch:switchCall : %s" + JSON.stringify(err))
});
LogUtils.i(TAG, prefixLog + "catch:switchCall : %s" + JSON.stringify(err))
});
});
/**
@ -212,10 +210,10 @@ export default class CallServiceProxy {
public registerCallStateCallback(callBack) {
call.on('callDetailsChange', (data) => {
if (!data) {
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback")
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback")
return;
}
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback callState")
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback callState")
callBack(data);
});
}
@ -226,10 +224,10 @@ export default class CallServiceProxy {
public unRegisterCallStateCallback() {
call.off('callDetailsChange', (data) => {
if (!data) {
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
return;
}
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
});
}
@ -239,9 +237,9 @@ export default class CallServiceProxy {
public registerCallEventCallback() {
call.on('callEventChange', (data) => {
if (!data) {
LogUtils.i(TAG, prefixLog + "call.on callEventChange")
LogUtils.i(TAG, prefixLog + "call.on callEventChange")
} else {
LogUtils.i(TAG, prefixLog + "call.on callEventChange")
LogUtils.i(TAG, prefixLog + "call.on callEventChange")
}
});
}
@ -252,9 +250,9 @@ export default class CallServiceProxy {
public unRegisterCallEventCallback() {
call.off('callEventChange', (data) => {
if (!data) {
LogUtils.i(TAG,prefixLog + "call.off unRegisterCallEventCallback : %s")
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallEventCallback : %s")
} else {
LogUtils.i(TAG,prefixLog + "call.off unRegisterCallEventCallback : %s")
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallEventCallback : %s")
}
});
}

View File

@ -140,8 +140,8 @@ export default class NotificationManager {
return wantAgent.getWantAgent({
wants: [{
deviceId: '',
bundleName: CALL_BUNDLE_NAME,
abilityName: CALL_ABILITY_NAME,
bundleName: Constants.CALL_BUNDLE_NAME,
abilityName: Constants.CALL_ABILITY_NAME,
uri: '',
type: 'phone',
action: 'callui.event.click',
@ -186,8 +186,8 @@ export default class NotificationManager {
callState,
startTime: startTime * 1000,
isBackground,
wantBundleName: CALL_BUNDLE_NAME,
wantAbilityName: CALL_ABILITY_NAME
wantBundleName: Constants.CALL_BUNDLE_NAME,
wantAbilityName: Constants.CALL_ABILITY_NAME
})
}

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
import wantAgent from '@ohos.wantAgent';
import ContactCard from '../common/components/ContactCard';
import FuncBtnGroup from '../common/components/FuncBtnGroup';
import BottomBtn from '../common/components/BottomBtn';
@ -23,6 +24,9 @@ import LogUtils from '../common/utils/LogUtils';
import byTrace from "@ohos.bytrace"
import NotificationManager from '../model/NotificationManager';
import CallManager from '../model/CallManager';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import Constants from '../common/utils/Constants';
import CallDataManager from '../model/CallDataManager';
const TAG = "MainAbility";
@ -37,6 +41,7 @@ struct Index {
@State isShowKeyboard: boolean = false;
@State callList: Array<any> = [];
private notificationManager: NotificationManager;
private mCallDataManager: CallDataManager;
aboutToAppear(): void {
LogUtils.i(TAG, "aboutToAppear :")
@ -51,6 +56,7 @@ struct Index {
LogUtils.i(TAG, "onPageShow : ")
byTrace.startTrace('onPageShow', 1);
globalThis.appInactiveState = false;
this.stopBackgroundRunning();
this.notificationManager.cancelNotification();
this.notificationManager.sendCapsuleNotification(this.callData, false);
byTrace.finishTrace('onPageShow', 1);
@ -69,12 +75,49 @@ struct Index {
} else {
text = accountNumber + ' ';
}
this.mCallDataManager = CallDataManager.getInstance();
if (this.mCallDataManager.hasAliveCall()) {
this.startBackgroundRunning();
}
this.notificationManager.sendNotification(text, this.callData);
this.notificationManager.sendCapsuleNotification(this.callData, true);
LogUtils.i(TAG, "onPageHide end : ")
}
}
aboutToDisappear() {
LogUtils.i(TAG, "aboutToDisappear :")
this.stopBackgroundRunning();
}
private stopBackgroundRunning() {
backgroundTaskManager.stopBackgroundRunning(globalThis.calluiAbilityContext).then(() => {
LogUtils.i(TAG, "stopBackgroundRunning succeeded")
}).catch((err) => {
LogUtils.i(TAG, "stopBackgroundRunning failed")
});
}
private startBackgroundRunning() {
let wantAgentInfo = {
wants: [{
bundleName: Constants.CALL_BUNDLE_NAME,
abilityName: Constants.CALL_ABILITY_NAME,
}],
requestCode: 0,
operationType: wantAgent.OperationType.START_ABILITY,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(globalThis.calluiAbilityContext,
backgroundTaskManager.BackgroundMode.VOIP, wantAgentObj).then(() => {
LogUtils.i(TAG, "startBackgroundRunning succeeded")
}).catch((err) => {
LogUtils.i(TAG, "startBackgroundRunning failed cause:" + JSON.stringify(err))
});
});
}
/**
* method to control the display of DTMF keyboard
*

View File

@ -15,7 +15,7 @@
{
"module": {
"name": "com.ohos.callui",
"name": "callui",
"type": "entry",
"srcEntrance": "./ets/Application/MyAbilityStage.ts",
"description": "$string:callui_description",
@ -47,6 +47,9 @@
"action.system.home"
]
}
],
"backgroundModes": [
"voip"
]
}
],
@ -79,6 +82,9 @@
},
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
},
{
"name": "ohos.permission.KEEP_BACKGROUND_RUNNING"
}
]
}

View File

@ -1,13 +0,0 @@
## This file is automatically generated by DevEco Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Mar 23 14:49:28 CST 2022
sdk.dir=
nodejs.dir=
npm.dir=

View File

@ -15,7 +15,7 @@
{
"module": {
"name": "com.ohos.mobiledatasettings",
"name": "mobiledatasettings",
"type": "feature",
"srcEntrance": "./ets/Application/MyAbilityStage.ts",
"description": "$string:app_name",

View File

@ -0,0 +1,2 @@
DiÂßÚì9˜
afŠ]¥

Binary file not shown.

View File

@ -0,0 +1 @@
W<EFBFBD>w+itť);ÁHžŽű

View File

@ -0,0 +1 @@
?<3F>u<17>/}<7D>M<EFBFBD><4D><EFBFBD>e<EFBFBD>

View File

@ -0,0 +1 @@
<EFBFBD>*sY6P<36>,Q*<2A><><t<>