blob: 8db627bc37a1df465ba96a6d630f73b60f36223b [file] [log] [blame]
<html devsite><head>
<meta name="book_path" value="/_book.yaml"/>
<meta name="project_path" value="/_project.yaml"/>
</head>
<body>
<!--
Copyright 2018 The Android Open Source Project
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.
-->
<h1 id="supporting_third_party_calling_apps" class="page-title">支持第三方通话应用</h1>
<p>Android 9 提供的 API 可更好地支持第三方通话应用。第三方通话应用通常借助电话 API(例如 <code>PHONE_STATE</code> 广播)与运营商通话共存。因此,第三方通话应用必须礼让运营商通话,而且通常会默默拒绝应用中的来电,或者终止正在进行的通话,以便为运营商通话“让路”。</p>
<p>Android 9 中的 API 支持在运行第三方应用的同时进行运营商通话。这使得在运营商通话过程中接听第三方来电成为可能。该框架要负责确保,在用户进行第三方应用通话时使运营商通话处于呼叫保持状态。</p>
<p>在 Android 9 中,建议您使用第三方通话应用来实现自行管理的 <code>ConnectionService</code> API。要详细了解如何使用此 API 构建通话应用,请参阅<a href="https://developer.android.com/guide/topics/connectivity/telecom/selfManaged">构建通话应用</a></p>
<p>借助自行管理的 <code>ConnectionService</code> API,开发者还可以选择使其应用中的通话记录显示在系统的通话记录中(请参阅 <a href="https://developer.android.com/reference/android/telecom/PhoneAccount#EXTRA_LOG_SELF_MANAGED_CALLS"><code>EXTRA_LOG_SELF_MANAGED_CALLS</code></a>)。根据 <a href="/compatibility/android-cdd#7_4_data_connectivity">Android 兼容性定义文档 (CDD)</a>(第 7.4.1.2 节)中的要求,您应确保自己的拨号器/电话应用能够显示此类通话记录条目,并显示接入相应通话的第三方通话应用的名称(要查看有关 AOSP 拨号器应用如何满足此要求的示例,请参阅<a href="#call_log_entries_from_3p_calling_apps">源自第三方通话应用的通话记录条目</a>)。</p>
<p>应用需要在其连接中设置 <a href="https://developer.android.com/reference/android/telecom/Connection.html#CAPABILITY_SUPPORT_HOLD"><code>CAPABILITY_SUPPORT_HOLD</code></a><a href="https://developer.android.com/reference/android/telecom/Connection.html#CAPABILITY_HOLD"><code>CAPABILITY_HOLD</code></a>。但在某些情况下,应用可能无法使通话处于呼叫保持状态。该框架包含了应对此类情形的规定。</p>
<h2 id="scenarios">场景</h2>
<p>您应当修改自己的拨号器应用以应对以下场景。</p>
<h3 id="handling_incoming_calls_which_disconnect_an_ongoing_call">处理导致正在进行的通话中断的来电</h3>
<p>如果正在进行的第三方通话(例如 SuperCaller 通话)不支持呼叫保持,而此时用户接到移动网络来电(例如通过运营商 FooCom),您的拨号器/电话应用应提示用户:接听移动网络来电将终止正在进行的第三方通话。</p>
<p>这种用户体验非常重要,因为该框架可能不支持对第三方通话应用的通话进行呼叫保持。接听新的移动网络来电会导致正在进行的第三方通话中断。</p>
<p>请参阅以下界面示例:</p>
<figure id="incoming-call-3p-call-app">
<img src="/devices/tech/connect/images/incoming-call-3p-call-app.png" width="250" class="screenshot" alt="导致正在进行的第三方通话中断的来电"/>
<figcaption><strong>图 1.</strong> 导致正在进行的第三方通话中断的来电</figcaption>
</figure>
<p>您的拨号器应用可通过检查<a href="https://developer.android.com/reference/android/telecom/Call.Details.html#getExtras()">通话 extra</a> 来判断某个来电是否会导致其他通话中断。请务必将 <a href="https://developer.android.com/reference/android/telecom/Connection.html#EXTRA_ANSWERING_DROPS_FG_CALL"><code>EXTRA_ANSWERING_DROPS_FG_CALL</code></a> 设置为 <code>TRUE</code>,并将 <a href="https://developer.android.com/reference/android/telecom/Connection.html#EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME"><code>EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME</code></a> 设置为接听移动网络来电时其通话会被中断的应用的名称。</p>
<h3 id="call_log_entries_from_3p_calling_apps">源自第三方通话应用的通话记录条目</h3>
<p>第三方通话应用的开发者可以选择让其应用中的通话记录显示在系统的通话记录中(请参阅 <a href="https://developer.android.com/reference/android/telecom/PhoneAccount#EXTRA_LOG_SELF_MANAGED_CALLS"><code>EXTRA_LOG_SELF_MANAGED_CALLS</code></a>)。这意味着通话记录中可以包含有关非移动网络通话的条目。</p>
<p>当 AOSP 拨号器应用显示与第三方通话应用相关的通话记录条目时,发生通话的应用的名称将显示在通话记录中,如下图所示:</p>
<figure id="call-log-entry-3p">
<img src="/devices/tech/connect/images/call-log-entry-3p.png" width="400" class="screenshot" alt="第三方通话应用中的通话记录条目"/>
<figcaption><strong>图 2.</strong> 拨号器应用上显示的通话记录条目(包含第三方通话应用的名称)</figcaption>
</figure>
<p>要确定与通话记录条目相关联的应用的名称,请使用通话记录提供程序中的 <a href="https://developer.android.com/reference/android/provider/CallLog.Calls.html#PHONE_ACCOUNT_COMPONENT_NAME"><code>PHONE_ACCOUNT_COMPONENT_NAME</code></a><a href="https://developer.android.com/reference/android/provider/CallLog.Calls.html#PHONE_ACCOUNT_ID"><code>PHONE_ACCOUNT_ID</code></a> 列创建一个 <a href="https://developer.android.com/reference/android/telecom/PhoneAccountHandle.html#PhoneAccountHandle(android.content.ComponentName, java.lang.String)"><code>PhoneAccountHandle</code></a> 实例,以用于识别通话记录条目的来源。查询 <a href="https://developer.android.com/reference/android/telecom/TelecomManager.html#getPhoneAccount(android.telecom.PhoneAccountHandle)"><code>TelecomManager</code></a> 以获取相应 PhoneAccount 的详细信息。<br />要确定某条通话记录条目是否源自第三方通话应用,请检查 <a href="https://developer.android.com/reference/android/telecom/PhoneAccount.html#getCapabilities()"><code>PhoneAccount</code> 功能</a>,查看是否已设置 <a href="https://developer.android.com/reference/android/telecom/PhoneAccount.html#CAPABILITY_SELF_MANAGED"><code>CAPABILITY_SELF_MANAGED</code></a></p>
<p>返回的 <code>PhoneAccount</code><a href="https://developer.android.com/reference/android/telecom/PhoneAccount.html#getLabel()"><code>getLabel</code></a> 方法将返回与相关通话记录条目(源自第三方通话应用)相关联的应用的名称。</p>
<h2 id="validation">验证</h2>
<p>要测试您的设备是否支持第三方通话应用,请使用 Telecomm 测试应用,该应用可实现自行管理的 ConnectionService API。该应用位于 <a href="https://android.googlesource.com/platform/packages/services/Telecomm/+/master/testapps/"><code>/packages/services/Telecomm/testapps/</code></a> 中。</p>
<ol>
<li><p>使用以下命令从 Android 源代码代码库的根目录构建测试应用:</p>
<p><code>mmma packages/services/Telecomm/testapps/</code></p></li>
<li><p>使用 <code>adb install -g -r &lt;apk path&gt;</code> 安装编译 APK。然后,将自行管理的示例图标添加到您的启动器中。</p></li>
<li><p>点按该图标以打开测试应用。</p></li>
</ol>
<h3 id="handling_incoming_calls_which_disconnect_an_ongoing_call_2">处理导致正在进行的通话中断的来电</h3>
<p>请按照以下步骤操作,以验证某个来电是否会导致正在进行的第三方通话中断。</p>
<figure id="test-app-3p-call">
<img src="/devices/tech/connect/images/test-app-3p-call.png" width="250" class="screenshot" alt="适用于第三方通话应用的测试应用"/>
<figcaption><strong>图 3.</strong> 测试应用,以及自行管理的 ConnectionService API 的示例实现</figcaption>
</figure>
<ol>
<li>取消选中 <strong>Holdable</strong> 选项。</li>
<li>点按 <strong>OUTGOING</strong> 以启动新的去电示例。</li>
<li>点按 <strong>ACTIVE</strong> 按钮以激活通话。</li>
<li>用另一部手机拨打被测设备的电话号码。在这一场景中,您的拨号器会显示一个应用的名称,而该应用将中断其通话。</li>
<li>操作完成后,在测试应用中点按 <strong>DISCONNECT</strong> 按钮。</li>
</ol>
<h3 id="call_log_entries_from_3p_calling_apps_2">源自第三方通话应用的通话记录条目</h3>
<p>完成上述步骤后,测试应用会在系统通话记录中添加一条通话记录。要确认设备是否记录了源自第三方通话应用的通话记录,请打开您的拨号器应用并确认相应通话显示在系统通话记录中。</p>
</body></html>