update stage mode

Signed-off-by: w00636648 <wangziming14@huawei.com>
This commit is contained in:
w00636648 2022-09-26 11:09:35 +08:00
parent 41f2eb4d79
commit 1de816286b
24 changed files with 155 additions and 187 deletions

View File

@ -7,8 +7,6 @@
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"singleton": true,
"keepAlive": true
"distributedNotificationEnabled": true
},
}

View File

@ -3,7 +3,7 @@
"types":"",
"devDependencies":{},
"name":"@ohos/common",
"description":"a npm package which contains arkUI2.0 page",
"description":"a npm package which contains common function",
"ohos":{
"org":""
},

View File

@ -1,6 +1,6 @@
@Component
export struct MainPage {
@State message: string = 'Hello World'
@State message: string = ''
build() {
Row() {

View File

@ -5,9 +5,6 @@
"targets": [
{
"name": "default"
},
{
"name": "ohosTest",
}
]
}

View File

@ -2,32 +2,40 @@ 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';
const TAG = "MyAbilityStage";
export default class MyAbilityStage extends AbilityStage {
onCreate() {
globalThis.deviceTypeInfo = deviceInfo.deviceType;
this.applyEfficiencyResources();
LogUtils.i(TAG, "MyAbilityStage onCreate")
}
onCreate() {
globalThis.deviceTypeInfo = deviceInfo.deviceType;
this.applyEfficiencyResources();
notification.enableNotification({
bundle: "com.ohos.callui"
}, true, (err, data) => {
if (err) {
LogUtils.e(TAG, "enableNotification err: " + JSON.stringify(err));
}
})
LogUtils.i(TAG, "MyAbilityStage onCreate")
}
onDestroy() {
LogUtils.i(TAG, "MyAbilityStage onDestroy")
backgroundTaskManager.resetAllEfficiencyResources();
}
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)
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

@ -5,42 +5,42 @@ import LogUtils from '../common/utils/LogUtils'
const TAG = "MainAbility";
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
LogUtils.i(TAG, "onCreate")
globalThis.abilityWant = want;
globalThis.calluiAbilityContext = this.context;
}
onCreate(want, launchParam) {
LogUtils.i(TAG, "onCreate")
globalThis.abilityWant = want;
globalThis.calluiAbilityContext = this.context;
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
LogUtils.i(TAG, "onWindowStageCreate")
windowStage.loadContent("pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
});
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
LogUtils.i(TAG, "onWindowStageCreate")
windowStage.loadContent("pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
LogUtils.i(TAG, "onWindowStageDestroy")
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
LogUtils.i(TAG, "onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
LogUtils.i(TAG, "onForeground")
}
onForeground() {
// Ability has brought to foreground
LogUtils.i(TAG, "onForeground")
}
onBackground() {
// Ability has back to background
LogUtils.i(TAG, "onBackground")
}
onBackground() {
// Ability has back to background
LogUtils.i(TAG, "onBackground")
}
onDestroy() {
LogUtils.i(TAG, "onDestroy")
globalThis.callManager.clearTimer();
globalThis.callManager.unsubscribe();
}
onDestroy() {
LogUtils.i(TAG, "onDestroy")
globalThis.callManager.clearTimer();
globalThis.callManager.unsubscribe();
}
};

View File

@ -79,8 +79,8 @@ export default class CallManagerService {
}
subscriber.finishCommonEvent()
.then(() => {
LogUtils.i(TAG, "addSubscriber finishCommonEvent")
})
LogUtils.i(TAG, "addSubscriber finishCommonEvent")
})
});
}
@ -142,9 +142,9 @@ export default class CallManagerService {
*/
startAbility(callData) {
this.context.startAbility({
bundleName: CALL_BUNDLE_NAME,
abilityName: ABILITY_NAME,
parameters: callData
bundleName: CALL_BUNDLE_NAME,
abilityName: ABILITY_NAME,
parameters: callData
}).then((data) => {
LogUtils.i(TAG, "callUI service startAbility data :" + JSON.stringify(data))
}).catch((err) => {
@ -179,7 +179,7 @@ export default class CallManagerService {
* @param { Object } callData - Object
*/
publishData(callData) {
commonEvent.publish('callui.event.callDetailsChange', {
commonEvent.publish('callui.event.callDetailsChange', {
bundleName: 'com.ohos.callui',
isOrdered: false,
data: JSON.stringify(callData)

View File

@ -5,43 +5,44 @@ import rpc from '@ohos.rpc';
import LogUtils from "../common/utils/LogUtils"
const TAG = "ServiceAbility";
export default class ServiceAbility extends ServiceExtension {
callManagerService: CallManagerService
onCreate(want) {
LogUtils.i(TAG, "onCreate callUI service");
this.callManagerService = new CallManagerService(this.context);
}
onConnect(want:Want) {
LogUtils.i(TAG, "onConnect callUI service want:" + JSON.stringify(want));
let callData:any = {};
callData.accountNumber = want.parameters.accountNumber;
callData.videoState = want.parameters.videoState;
callData.callType = want.parameters.callType;
callData.callState = want.parameters.callState;
callData.conferenceState = want.parameters.conferenceState;
onConnect(want: Want) {
LogUtils.i(TAG, "onConnect callUI service");
let callData: any = {};
callData.accountNumber = want.parameters?.accountNumber;
callData.videoState = want.parameters?.videoState;
callData.callType = want.parameters?.callType;
callData.callState = want.parameters?.callState;
callData.conferenceState = want.parameters?.conferenceState;
this.callManagerService.getCallData(callData);
return new Stub("ServiceAbility");
}
onRequest(want:Want, startId:number) {
onRequest(want: Want, startId: number) {
LogUtils.i(TAG, "onRequest callUI service");
}
onDestroy() {
LogUtils.i(TAG, "onDestroy callUI service");
this.callManagerService.removeRegisterListener();
}
}
class Stub extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
}
onRemoteRequest(code, date, reply, option) {
try {
LogUtils.i(TAG, "Stub onRemoteRequest code:" + code)
return true;
} finally {
}
class Stub extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
}
onRemoteRequest(code, date, reply, option) {
LogUtils.i(TAG, "Stub onRemoteRequest code:" + code)
return true;
}
}

View File

@ -33,7 +33,7 @@ export default class TelephonyApi {
public registerCallStateCallback(callBack) {
call.on('callDetailsChange', (data) => {
if (!data) {
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback: " + JSON.stringify(data))
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback")
return;
}
LogUtils.i(TAG, prefixLog + "call.on registerCallStateCallback callState: " + JSON.stringify(data.callState))
@ -47,7 +47,7 @@ export default class TelephonyApi {
public unRegisterCallStateCallback() {
call.off('callDetailsChange', (data) => {
if (!data) {
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback" + JSON.stringify(data))
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
return;
}
LogUtils.i(TAG, prefixLog + "call.off unRegisterCallStateCallback")
@ -61,9 +61,9 @@ export default class TelephonyApi {
*/
public acceptCall = function (callId) {
call.answer(callId).then((res) => {
LogUtils.i(TAG, prefixLog + "call.answer")
LogUtils.i(TAG, prefixLog + "call.answer callId: " + JSON.stringify(callId))
}).catch((err) => {
LogUtils.i(TAG, prefixLog + "call.answer catch : %s" + JSON.stringify(err))
LogUtils.i(TAG, prefixLog + "call.answer catch : " + JSON.stringify(err))
})
}

View File

@ -16,25 +16,12 @@
/**
* @file: Header information display component
*/
import LogUtils from '../utils/LogUtils';
import callStateConst from '../constant/CallStateConst';
import Utils from '../utils/utils'
const TAG = "contactCard";
/**
* call global variable 会黑屏
*/
/*
let callTimeList;
let defaultTemp = globalThis.exports.default;
if (defaultTemp != undefined) {
callTimeList = defaultTemp.data.callTimeList;
}
*/
@Component
export default struct ContactCard {
@State callStateText: string = '';
@ -198,7 +185,6 @@ export default struct ContactCard {
if (this.isShowTime()) {
Column() {
Text(this.callTimeList[0].callTime)
// Text('00:56 ')
.fontSize(14)
.height(19)
.lineHeight(19)

View File

@ -154,12 +154,12 @@ export default struct FuncBtnGroup {
this.mCallServiceProxy.switchCall(callId);
break;
case 'add':
globalThis.calluiAbilityContext.startAbility({
bundleName: 'com.ohos.contacts',
abilityName: 'com.ohos.contacts.MainAbility',
parameters: {
pageFlag : 'page_flag_dialer'
}
globalThis.calluiAbilityContext?.startAbility({
bundleName: 'com.ohos.contacts',
abilityName: 'com.ohos.contacts.MainAbility',
parameters: {
pageFlag: 'page_flag_dialer'
}
});
break;
case 'video':
@ -168,12 +168,12 @@ export default struct FuncBtnGroup {
this.muteHandle('mute');
break;
case 'contact':
globalThis.calluiAbilityContext.startAbility({
bundleName: 'com.ohos.contacts',
abilityName: 'com.ohos.contacts.MainAbility',
parameters: {
pageFlag: "page_flag_choose_contacts"
}
globalThis.calluiAbilityContext?.startAbility({
bundleName: 'com.ohos.contacts',
abilityName: 'com.ohos.contacts.MainAbility',
parameters: {
pageFlag: "page_flag_choose_contacts"
}
});
break;
case 'merge':

View File

@ -164,7 +164,7 @@ export default struct IncomingCom {
if (this.SendResult) {
resourceManager.getResourceManager().then(result => {
result.getString($r("app.string.SMS_Sent")
.id, (err, typeName) => {
.id, (err, typeName) => {
Content = typeName
prompt.showToast({
message: this.callData.contactName ? Content + `${this.callData.contactName}` : Content + `${this.callData.accountNumber}`,

View File

@ -88,7 +88,7 @@ export default struct callList {
public onHangUp(callId) {
this.mCallServiceProxy.hangUpCall(callId);
if (this.callList.length === 1) {
globalThis.calluiAbilityContext.terminateSelf().then((data) => {
globalThis.calluiAbilityContext?.terminateSelf().then((data) => {
LogUtils.i(TAG, "onHangUp terminateSelfCallBack");
});
}

View File

@ -29,21 +29,21 @@
* log package tool class
*/
export class LogUtils {
d(TAG, msg): void {
console.debug("[callui:]" + TAG + ":" + msg);
}
d(TAG, msg): void {
console.debug("[callui:]" + TAG + ":" + msg);
}
i(TAG, msg): void {
console.info("[callui:]" + TAG + ":" + msg);
}
i(TAG, msg): void {
console.info("[callui:]" + TAG + ":" + msg);
}
w(TAG, msg): void {
console.warn("[callui:]" + TAG + ":" + msg);
}
w(TAG, msg): void {
console.warn("[callui:]" + TAG + ":" + msg);
}
e(TAG, msg): void {
console.error("[callui:]" + TAG + ":" + msg);
}
e(TAG, msg): void {
console.error("[callui:]" + TAG + ":" + msg);
}
}
let mLogUtil = new LogUtils();

View File

@ -47,7 +47,6 @@ export default class CallDataManager {
/**
* update callList and callData callTimeList
*`
*
* @param { object } callData
*/
public update(callData) {
@ -85,7 +84,7 @@ export default class CallDataManager {
this.NotificationManager.cancelNotification();
AppStorage.Get<NotificationManager>('notificationManager').sendCapsuleNotification(callData, true);
AppStorage.Delete("CallTimeList");
globalThis.calluiAbilityContext.terminateSelf().then((data) => {
globalThis.calluiAbilityContext?.terminateSelf().then((data) => {
LogUtils.i(TAG, "calluiAbility terminateSelf");
});
} else {

View File

@ -33,7 +33,7 @@ export default class CallStateManager {
*
* @param { Object } data - callData
*/
public static getInstance(): CallStateManager {
public static getInstance():CallStateManager{
return CallStateManager.sCallStateManager;
}

View File

@ -28,28 +28,26 @@ const DBUri = DBbaseUri + '/contacts/contact_data';
* class ContactManager
*/
export default class ContactManager {
/**
* get contact info
*
* @param { Object } callData -Object
*/
async getContactInfo(callData) {
try {
const columns = ['id', 'display_name', 'detail_info'];
const predicates = new dataAbility.DataAbilityPredicates();
predicates.equalTo('detail_info', callData.accountNumber);
predicates.equalTo('is_deleted', 0);
const dataAbilityHelper = await featureAbility.acquireDataAbilityHelper(globalThis.calluiAbilityContext, DBbaseUri);
const resSet = await dataAbilityHelper.query(DBUri, columns, predicates);
LogUtils.i(TAG, "getContactInfo resSet : " + JSON.stringify(resSet))
if (resSet.rowCount > 0) {
resSet.goToFirstRow();
callData.contactName = resSet.getString(resSet.getColumnIndex('display_name'));
LogUtils.i(TAG, "getContactInfo callData.contactName:" + callData.contactName);
}
} catch (err) {
LogUtils.i(TAG, "getContactInfo catch err : %s" + JSON.stringify(err))
}
/**
* get contact info
*
* @param { Object } callData -Object
*/
async getContactInfo(callData) {
try {
const columns = ['id', 'display_name', 'detail_info'];
const predicates = new dataAbility.DataAbilityPredicates();
predicates.equalTo('detail_info', callData.accountNumber);
predicates.equalTo('is_deleted', 0);
const dataAbilityHelper = await featureAbility.acquireDataAbilityHelper(globalThis.calluiAbilityContext, DBbaseUri);
const resSet = await dataAbilityHelper.query(DBUri, columns, predicates);
LogUtils.i(TAG, "getContactInfo resSet : " + JSON.stringify(resSet.rowCount))
if (resSet.rowCount > 0) {
resSet.goToFirstRow();
callData.contactName = resSet.getString(resSet.getColumnIndex('display_name'));
}
} catch (err) {
LogUtils.i(TAG, "getContactInfo catch err : %s" + JSON.stringify(err))
}
}
}

View File

@ -79,7 +79,7 @@ export default class NotificationManager {
callId, btnType: key
};
const wantAgentObj = await this.getWantAgent(data, SEND_COMMON_EVENT);
globalThis.calluiAbilityContext.resourceManager.getString(textMap[key].id, (error, value) => {
globalThis.calluiAbilityContext?.resourceManager.getString(textMap[key].id, (error, value) => {
if (error != null) {
LogUtils.i(TAG, "sendNotification getResourceManager getString err")
} else {

View File

@ -7,12 +7,9 @@ import CallStateConst from '../common/constant/CallStateConst';
import LogUtils from '../common/utils/LogUtils';
import byTrace from "@ohos.bytrace"
import NotificationManager from '../model/NotificationManager';
import call from '@ohos.telephony.call';
import CallManager from '../model/CallManager';
import notification from '@ohos.notification';
const TAG = "MainAbility Index";
const SIM_CARD_DELAYED_DISPLAY = 100;
const TAG = "MainAbility";
/**
* @file: Main interface
@ -25,20 +22,14 @@ struct Index {
@State callData: any = CallStateConst.defaultCallData;
@State isShowKeyboard: boolean = false;
@State callList: Array<any> = [];
private consoleTxt: '';
private callStateConst;
private notificationManager: NotificationManager;
aboutToAppear(): void {
LogUtils.i(TAG, "aboutToAppear :")
byTrace.startTrace('aboutToAppear', 0);
this.callStateConst = new CallStateConst();
this.notificationManager = new NotificationManager();
globalThis.callManager = new CallManager(this)
AppStorage.SetOrCreate<NotificationManager>('notificationManager', this.notificationManager);
let delayMethod = setTimeout(() => {
clearTimeout(delayMethod);
}, SIM_CARD_DELAYED_DISPLAY);
byTrace.finishTrace('aboutToAppear', 0);
}
@ -58,8 +49,10 @@ struct Index {
const {callState, accountNumber, contactName, callId} = this.callData;
let fool = (callState !== CallStateConst.callStateObj.CALL_STATUS_DISCONNECTED && callId)
if (callState !== CallStateConst.callStateObj.CALL_STATUS_DISCONNECTED && callId) {
let text = contactName + ' ' + accountNumber + ' ';
if (!contactName) {
let text = '';
if (contactName) {
text = contactName + ' ' + accountNumber + ' ';
} else {
text = accountNumber + ' ';
}
this.notificationManager.sendNotification(text, this.callData);
@ -87,18 +80,6 @@ struct Index {
return this.callData.callState;
}
/**
* Dialing function
*/
public dialCall(phoneNumber, accountId = 0, videoState = 0, dialScene = 0) {
LogUtils.i(TAG, "dialCall phoneNumber :")
call.dial(phoneNumber, {
accountId,
videoState,
dialScene
});
}
build() {
Column() {
Stack() {

View File

@ -18,9 +18,9 @@
"name": "com.ohos.callui.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:callui_description",
"icon": "$media:icon",
"icon": "$media:app_icon",
"label": "$string:callui_description",
"startWindowIcon": "$media:icon",
"startWindowIcon": "$media:app_icon",
"startWindowBackground": "$color:black",
"visible": true,
"skills": [
@ -57,10 +57,10 @@
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.SET_TELEPHONY_STATE"
"name": "ohos.permission.GET_TELEPHONY_STATE"
},
{
"name": "ohos.permission.GET_TELEPHONY_STATE"
"name": "ohos.permission.NOTIFICATION_CONTROLLER"
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

View File

@ -17,9 +17,9 @@
"name": "com.ohos.mobiledatasettings.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description",
"icon": "$media:ic_icon",
"icon": "$media:app_icon",
"label": "$string:MainAbility_label",
"startWindowIcon": "$media:ic_icon",
"startWindowIcon": "$media:app_icon",
"startWindowBackground": "$color:white",
"visible": true
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.