mirror of
https://github.com/openharmony/telephony_telephony_cangjie_wrapper.git
synced 2026-07-01 03:23:11 -04:00
initialize
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
**/.vscode
|
||||
**/.cache
|
||||
**/cjpm.lock
|
||||
**/.idea
|
||||
@@ -1,3 +1,40 @@
|
||||
# telephony_telephony_cangjie_wrapper
|
||||
# Telephony <a name="EN-US_TOPIC_0000001162422291"></a>
|
||||
|
||||
电话服务模块仓颉封装层
|
||||
## Introduction<a name="section104mcpsimp"></a>
|
||||
|
||||
The Telephony subsystem provides APIs for obtaining information about the wireless cellular network and SIM card. Applications can call these APIs to obtain information such as the name of the currently registered network, network service status, signal strength, and SIM card information.
|
||||
|
||||
The Telephony subsystem consists of the following modules:
|
||||
|
||||
- Telephony core service: initializes the Radio Interface Layer (RIL) Manager, SIM card module, and radio module.
|
||||
- Call Manager module: manages three types of calls – circuit switched \(CS\), IP multimedia subsystem \(IMS\), and over the top \(OTT\) calls. It is responsible for applying for the audio and video resources required for a call and resolving conflicts in a multi-channel call.
|
||||
- Cellular call module: implements basic calls over carrier networks.
|
||||
- Cellular data module: implements cellular data services over carrier networks.
|
||||
- SMS & MMS module: provides the capabilities of sending and receiving short message service \(SMS\) messages and encoding and decoding multimedia messaging service \(MMS\) messages.
|
||||
- State registry module: provides APIs to register and deregister an observer that listens for various callback events of the telephony subsystem.
|
||||
- Data storage module: stores persistent data and provides **DataAbility** access APIs.
|
||||
- RIL Adapter module: implements adaptation of the modem communication interfaces.
|
||||
|
||||
**Figure 1** Architecture of the network management subsystem
|
||||
|
||||

|
||||
|
||||
## Directory Structure<a name="section119mcpsimp"></a>
|
||||
|
||||
```
|
||||
base/telephony/telephony_cangjie_api
|
||||
├── ohos # Cangjie Telephony code
|
||||
├── kit # Cangjie kit code
|
||||
├── figures # architecture pictures
|
||||
```
|
||||
|
||||
## Constraints<a name="section123mcpsimp"></a>
|
||||
|
||||
1. The open-source version currently provides the cellular call (CS call only), SMS & MMS, and cellular data services and supports the dual-SIM framework.
|
||||
2. The southbound HDI depends on the chip vendor.
|
||||
|
||||
## Repositories Involved<a name="section152mcpsimp"></a>
|
||||
|
||||
**Telephony**
|
||||
|
||||
telephony_cangjie_api
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
# 电话服务子系统<a name="ZH-CN_TOPIC_0000001162422291"></a>
|
||||
|
||||
## 简介<a name="section104mcpsimp"></a>
|
||||
|
||||
电话服务子系统,提供了一系列的API用于获取无线蜂窝网络和SIM卡相关的一些信息。应用可以通过调用API来获取当前注册网络名称、网络服务状态、信号强度以及SIM卡的相关信息。
|
||||
|
||||
各个模块主要作用如下:
|
||||
|
||||
- 核心服务模块:主要功能是初始化RIL管理、SIM卡和搜网模块。
|
||||
- 通话管理模块:主要功能是管理CS(Circuit Switch,电路交换)、IMS(IP Multimedia Subsystem,IP多媒体子系统)和OTT(over the top,OTT解决方案)三种类型的通话,申请通话所需要的音视频资源,处理多路通话时产生的各种冲突。
|
||||
- 蜂窝通话模块:主要功能是实现基于运营商网络的基础通话。
|
||||
- 蜂窝数据模块:主要功能是实现基于运营商网络的蜂窝数据上网。
|
||||
- 短彩信模块:主要功能是短信收发和彩信编解码。
|
||||
- 状态订阅模块:主要功能是提供电话服务子系统各种消息事件的订阅以及取消订阅的API。
|
||||
- 数据存储模块:主要功能是持久化数据存储,提供DataAbility访问接口。
|
||||
- RIL Adapter模块: 主要功能是与modem通信接口的适配。
|
||||
|
||||
**图 1** 子系统架构图
|
||||
|
||||

|
||||
|
||||
## 目录<a name="section119mcpsimp"></a>
|
||||
|
||||
```
|
||||
base/telephony/telephony_cangjie_api
|
||||
├── ohos # 仓颉电话服务子系统接口实现
|
||||
├── kit # 仓颉kit化代码
|
||||
├── figures # 存放readme中的架构图
|
||||
```
|
||||
|
||||
## 约束<a name="section123mcpsimp"></a>
|
||||
|
||||
1. 目前开源的范围包括蜂窝通话(仅支持CS通话)、短信、数据上网,支持双SIM卡框架。
|
||||
2. 南向HDI依赖芯片厂商适配。
|
||||
|
||||
## 相关仓<a name="section152mcpsimp"></a>
|
||||
|
||||
**电话服务子系统**
|
||||
|
||||
telephony_cangjie_api
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"name": "@ohos/telephony_cangjie_api",
|
||||
"version": "6.0",
|
||||
"description": "telephony call manager service",
|
||||
"publishAs": "code-segment",
|
||||
"homePage": "https://gitee.com/openharmony",
|
||||
"repository": "https://gitee.com/openharmony/telephony_cangjie_api",
|
||||
"license": "Apache License 2.0",
|
||||
"language": "",
|
||||
"private": false,
|
||||
"scripts": {},
|
||||
"envs": [],
|
||||
"dirs": [],
|
||||
"author": {},
|
||||
"contributors": [],
|
||||
"segment": {
|
||||
"destPath": "base/telephony/telephony_cangjie_api"
|
||||
},
|
||||
"component": {
|
||||
"name": "telephony_cangjie_api",
|
||||
"subsystem": "telephony",
|
||||
"syscap": [
|
||||
"SystemCapability.Telephony.CallManager",
|
||||
"SystemCapability.Applications.Contacts"
|
||||
],
|
||||
"features": [
|
||||
],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom": "1639KB",
|
||||
"ram": "6MB",
|
||||
"deps": {
|
||||
"components": [
|
||||
"cangjie_api",
|
||||
"hiviewdfx_cangjie_api",
|
||||
"ability_cangjie_api",
|
||||
"arkui_cangjie_api",
|
||||
"call_manager"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/telephony/telephony_cangjie_api/ohos/telephony:ohos.telephony",
|
||||
"//base/telephony/telephony_cangjie_api/ohos/telephony/call:ohos.telephony_call",
|
||||
"//base/telephony/telephony_cangjie_api/kit/TelephonyKit:kit.TelephonyKit"
|
||||
],
|
||||
"inner_kits": [
|
||||
],
|
||||
"test": [
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 207 KiB |
@@ -0,0 +1,28 @@
|
||||
# Copyright (c) 2025 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("//build/ohos.gni")
|
||||
import("//build/cangjie/cjc.gni")
|
||||
|
||||
ohos_cj_library("kit.TelephonyKit") {
|
||||
sources = [ "index.cj" ]
|
||||
|
||||
cj_deps = [
|
||||
"../../ohos/telephony/call:ohos.telephony_call",
|
||||
]
|
||||
|
||||
kit = true
|
||||
subsystem_name = "telephony"
|
||||
part_name = "telephony_cangjie_api"
|
||||
lib_name = "TelephonyKit"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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.
|
||||
*/
|
||||
|
||||
package kit.TelephonyKit
|
||||
|
||||
public import ohos.telephony_call.*
|
||||
@@ -0,0 +1,22 @@
|
||||
# Copyright (c) 2025 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("//build/cangjie/cjc.gni")
|
||||
|
||||
ohos_cj_library("ohos.telephony") {
|
||||
sources = [ "telephony.cj" ]
|
||||
|
||||
subsystem_name = "telephony"
|
||||
part_name = "telephony_cangjie_api"
|
||||
lib_name = "telephony"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# Copyright (c) 2025 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("//build/cangjie/cjc.gni")
|
||||
|
||||
ohos_cj_library("ohos.telephony_call") {
|
||||
sources = [
|
||||
"number_format_options.cj",
|
||||
"telephony_call.cj",
|
||||
"telephony_call_ffi.cj",
|
||||
]
|
||||
|
||||
cj_external_deps = [
|
||||
"ability_cangjie_api:ohos.ability",
|
||||
"arkui_cangjie_api:ohos.base",
|
||||
"cangjie_api:ohos.ffi",
|
||||
"hiviewdfx_cangjie_api:ohos.hilog",
|
||||
"cangjie_api:ohos.encoding.json",
|
||||
"cangjie_api:ohos.labels",
|
||||
]
|
||||
|
||||
external_deps = [ "call_manager:cj_telephony_call_ffi" ]
|
||||
|
||||
subsystem_name = "telephony"
|
||||
part_name = "telephony_cangjie_api"
|
||||
lib_name = "ohos.telephony_call"
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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.
|
||||
*/
|
||||
|
||||
package ohos.telephony_call
|
||||
|
||||
import ohos.ffi.*
|
||||
import ohos.hilog.*
|
||||
import std.collection.*
|
||||
import ohos.labels.*
|
||||
import ohos.base.*
|
||||
|
||||
let TELEPHONY_CALL_LOG = HilogChannel(0, 0xD002B25, "CJ-Telephony_Call")
|
||||
const ERROR_CELLUAR_DATA_SERVICE_UNAVAILABLE: Int32 = -2
|
||||
protected let ERROR_CODE_MAP = HashMap<Int32, String>(
|
||||
[
|
||||
(8300001, "Invalid parameter value."),
|
||||
(8300002, "Operation failed. Cannot connect to service."),
|
||||
(8300003, "System internal error."),
|
||||
(8300004, "Do not have sim card."),
|
||||
(8300005, "Airplane mode is on."),
|
||||
(8300006, "Network not in service."),
|
||||
(8300999, "Unknown error code."),
|
||||
(8301001, "SIM card is not activated."),
|
||||
(8301002, "SIM card operation error."),
|
||||
(8301003, "Operator config error."),
|
||||
(8401001, "UT is not connected.")
|
||||
]
|
||||
)
|
||||
|
||||
func getErrorCode(code: Int32): Int32 {
|
||||
if (code == ERROR_CELLUAR_DATA_SERVICE_UNAVAILABLE) {
|
||||
8300003
|
||||
} else {
|
||||
code
|
||||
}
|
||||
}
|
||||
|
||||
protected func getErrorMsg(code: Int32): String {
|
||||
let errCode = getErrorCode(code)
|
||||
if (let Some(v) <- getUniversalErrorMsg(errCode)) {
|
||||
return v
|
||||
} else if (ERROR_CODE_MAP.contains(errCode)) {
|
||||
return ERROR_CODE_MAP[errCode]
|
||||
} else {
|
||||
return "Unknown error code: ${errCode}"
|
||||
}
|
||||
}
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public enum EmergencyNumberOptions {
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
SLOT_ID_ONE
|
||||
| @!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
SLOT_ID_TWO
|
||||
| ...
|
||||
|
||||
func getValue(): Int32 {
|
||||
match (this) {
|
||||
case SLOT_ID_ONE => 0
|
||||
case SLOT_ID_TWO => 1
|
||||
case _ => throw IllegalArgumentException("The type is not supported.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public enum CallState {
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
CALL_STATE_UNKNOWN
|
||||
| @!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
CALL_STATE_IDLE
|
||||
| @!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
CALL_STATE_RINGING
|
||||
| @!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
CALL_STATE_OFFHOOK
|
||||
| ...
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public func getValue(): Int32 {
|
||||
match (this) {
|
||||
case CALL_STATE_UNKNOWN => -1
|
||||
case CALL_STATE_IDLE => 0
|
||||
case CALL_STATE_RINGING => 1
|
||||
case CALL_STATE_OFFHOOK => 2
|
||||
case _ => throw IllegalArgumentException("The type is not supported.")
|
||||
}
|
||||
}
|
||||
|
||||
protected static func parse(val: Int32): CallState {
|
||||
match (val) {
|
||||
case -1 => CALL_STATE_UNKNOWN
|
||||
case 0 => CALL_STATE_IDLE
|
||||
case 1 => CALL_STATE_RINGING
|
||||
case 2 => CALL_STATE_OFFHOOK
|
||||
case _ => throw IllegalArgumentException("The type is not supported.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public class NumberFormatOptions {
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public let countryCode: String
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public init(countryCode: String) {
|
||||
this.countryCode = countryCode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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.
|
||||
*/
|
||||
|
||||
package ohos.telephony_call
|
||||
|
||||
import ohos.base.*
|
||||
import ohos.ability.*
|
||||
import std.collection.*
|
||||
import ohos.encoding.json.*
|
||||
import ohos.ffi.*
|
||||
import std.collection.*
|
||||
import ohos.labels.*
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public class TelephonyCall {
|
||||
static init() {
|
||||
unsafe {
|
||||
FfiOHOSTelephonyCallInit()
|
||||
}
|
||||
}
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func formatPhoneNumberToE164(phoneNumber: String, countryCode: String): String {
|
||||
unsafe {
|
||||
var result = ""
|
||||
try (
|
||||
cPhoneNumber = LibC.mallocCString(phoneNumber).asResource(),
|
||||
cCountryCode = LibC.mallocCString(countryCode).asResource()
|
||||
) {
|
||||
var errCode = 0i32
|
||||
let formatNumber = FfiOHOSTelephonyCallFormatPhoneNumberToE164(cPhoneNumber.value, cCountryCode.value,
|
||||
inout errCode)
|
||||
result = formatNumber.toString()
|
||||
LibC.free(formatNumber)
|
||||
if (errCode != SUCCESS_CODE) {
|
||||
TELEPHONY_CALL_LOG.error("Telephony_Call formatPhoneNumberToE164 failed: ${getErrorMsg(errCode)}")
|
||||
throw BusinessException(getErrorCode(errCode),
|
||||
"TelephonyCall formatPhoneNumberToE164 failed: ${getErrorMsg(errCode)}")
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
atomicservice: true,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func makeCall(phoneNumber: String): Unit {
|
||||
unsafe {
|
||||
try (cNumber = LibC.mallocCString(phoneNumber).asResource()) {
|
||||
let errCode = FfiOHOSTelephonyCallMakeCall(cNumber.value)
|
||||
if (errCode != SUCCESS_CODE) {
|
||||
TELEPHONY_CALL_LOG.error("Telephony_Call makeCall failed: ${getErrorMsg(errCode)}")
|
||||
throw BusinessException(getErrorCode(errCode),
|
||||
"TelephonyCall makeCall failed: ${getErrorMsg(errCode)}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@!APILevel[
|
||||
21,
|
||||
atomicservice: true,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func makeCall(context: UIAbilityContext, phoneNumber: String): Unit {
|
||||
let parametersMap = HashMap<String, JsonValue>()
|
||||
parametersMap.add("phoneNumber", JsonString(phoneNumber))
|
||||
parametersMap.add("pageFlag", JsonString("page_flag_edit_before_calling"))
|
||||
context.startAbility(
|
||||
Want(bundleName: "com.ohos.contacts", abilityName: "com.ohos.contacts.MainAbility",
|
||||
parameters: JsonObject(parametersMap).toString()))
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief isEmergencyPhoneNumber(phoneNumber: string, options: EmergencyNumberOptions,
|
||||
* callback: AsyncCallback<boolean>): void
|
||||
*/
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func isEmergencyPhoneNumber(phoneNumber: String, options: EmergencyNumberOptions): Bool {
|
||||
unsafe {
|
||||
var result = true
|
||||
try (cNumber = LibC.mallocCString(phoneNumber).asResource()) {
|
||||
var errCode = 0i32
|
||||
result = FfiOHOSTelephonyCallIsEmergencyPhoneNumber(cNumber.value, options.getValue(), inout errCode)
|
||||
if (errCode != SUCCESS_CODE) {
|
||||
TELEPHONY_CALL_LOG.error("Telephony_Call isEmergencyPhoneNumber failed: ${getErrorMsg(errCode)}")
|
||||
throw BusinessException(getErrorCode(errCode),
|
||||
"TelephonyCall isEmergencyPhoneNumber failed: ${getErrorMsg(errCode)}")
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief isEmergencyPhoneNumber(phoneNumber: string, callback: AsyncCallback<boolean>): void
|
||||
*/
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func isEmergencyPhoneNumber(phoneNumber: String): Bool {
|
||||
return isEmergencyPhoneNumber(phoneNumber, EmergencyNumberOptions.SLOT_ID_ONE)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief hasCallSync(): boolean
|
||||
*/
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func hasCall(): Bool {
|
||||
return unsafe { FfiOHOSTelephonyCallHasCall() }
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief getCallStateSync(): CallState
|
||||
*/
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func getCallState(): CallState {
|
||||
let enumCode = unsafe { FfiOHOSTelephonyCallGetCallState() }
|
||||
return CallState.parse(enumCode)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief hasVoiceCapability(): boolean
|
||||
*/
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func hasVoiceCapability(): Bool {
|
||||
unsafe {
|
||||
return FfiOHOSTelephonyCallHasVoiceCapability()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief formatPhoneNumber(phoneNumber: string, callback: AsyncCallback<string>): void
|
||||
* @brief formatPhoneNumber(phoneNumber: string, options: NumberFormatOptions,
|
||||
* callback: AsyncCallback<string>): void
|
||||
* @brief formatPhoneNumber(phoneNumber: string, options?: NumberFormatOptions): Promise<string>
|
||||
*/
|
||||
@!APILevel[
|
||||
21,
|
||||
stagemodelonly: true,
|
||||
syscap: "SystemCapability.Telephony.CallManager"
|
||||
]
|
||||
public static func formatPhoneNumber(
|
||||
phoneNumber: String,
|
||||
options!: NumberFormatOptions = NumberFormatOptions("CN")
|
||||
): String {
|
||||
unsafe {
|
||||
var result = ""
|
||||
try (
|
||||
cPhoneNumber = LibC.mallocCString(phoneNumber).asResource(),
|
||||
cCountryCode = LibC.mallocCString(options.countryCode).asResource()
|
||||
) {
|
||||
var errCode = 0i32
|
||||
let formatNumber = FfiOHOSTelephonyCallFormatPhoneNumber(cPhoneNumber.value, cCountryCode.value,
|
||||
inout errCode)
|
||||
result = formatNumber.toString()
|
||||
LibC.free(formatNumber)
|
||||
if (errCode != SUCCESS_CODE) {
|
||||
TELEPHONY_CALL_LOG.error("Telephony_Call formatPhoneNumber failed: ${getErrorMsg(errCode)}")
|
||||
throw BusinessException(getErrorCode(errCode),
|
||||
"TelephonyCall formatPhoneNumber failed: ${getErrorMsg(errCode)}")
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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.
|
||||
*/
|
||||
|
||||
package ohos.telephony_call
|
||||
|
||||
import ohos.ffi.*
|
||||
import ohos.base.*
|
||||
|
||||
foreign {
|
||||
func FfiOHOSTelephonyCallFormatPhoneNumberToE164(phoneNumber: CString, countryCode: CString,
|
||||
errCode: CPointer<Int32>): CString
|
||||
|
||||
func FfiOHOSTelephonyCallInit(): Unit
|
||||
|
||||
func FfiOHOSTelephonyCallHasVoiceCapability(): Bool
|
||||
|
||||
func FfiOHOSTelephonyCallFormatPhoneNumber(phoneNumber: CString, countryCode: CString, errCode: CPointer<Int32>): CString
|
||||
|
||||
func FfiOHOSTelephonyCallGetCallState(): Int32
|
||||
|
||||
func FfiOHOSTelephonyCallHasCall(): Bool
|
||||
|
||||
func FfiOHOSTelephonyCallIsEmergencyPhoneNumber(phoneNumber: CString, slotId: Int32, errCode: CPointer<Int32>): Bool
|
||||
|
||||
func FfiOHOSTelephonyCallMakeCall(phoneNumber: CString): Int32
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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.
|
||||
*/
|
||||
|
||||
package ohos.telephony
|
||||
Reference in New Issue
Block a user