blob: 699ec099de7fa3c58ef0e3bba7b0df25b54b872e [file] [log] [blame]
<html devsite><head>
<title>识别运营商</title>
<meta name="project_path" value="/_project.yaml"/>
<meta name="book_path" value="/_book.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.
-->
<p>
运行 Android 9 及更高版本的设备可以识别订阅运营商信息,以提供相应 ID 和运营商名称。Android 维护着一个运营商 ID 数据库,该数据库采用针对每个运营商及其专属运营商 ID 的匹配规则。AOSP 在 <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb" class="external"><code>android/packages/providers/TelephonyProvider/assets/carrier_list.textpb</code></a> 文件中包含运营商 ID 数据库的内容。统一的数据库有助于最大限度地减少需要识别运营商的应用内的重复逻辑,并限制暴露可用于识别运营商的属性。
</p>
<p>
为了更准确地识别更多运营商,Android 支持带外运营商 ID 表更新。每个更新版本都会有一个版本号,并会发布到 AOSP。
</p>
<h2 id="implementation">实现</h2>
<p>
想要实现带外更新的用户可以从 AOSP 下载 <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.pb" class="external"><code>carrier_list.pb</code></a> 二进制文件。要查看该表的可读懂格式,请参阅 <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb" class="external"><code>carrier_list.txtpb</code></a>
</p>
<p>
请将更新后的运营商 ID 表放到 <code>/data/misc/carrierid/</code> 数据分区中。如果更新后的版本高于安装的版本,设备会将该表保留到<a href="https://developer.android.com/reference/android/provider/Telephony.CarrierId" class="external">运营商 ID 数据库</a>中。公共 API <a href="https://developer.android.com/reference/android/telephony/TelephonyManager#getSimCarrierId()" class="external"><code>getSimCarrierId()</code></a><a href="https://developer.android.com/reference/android/telephony/TelephonyManager#getSimCarrierIdName()" class="external"><code>getSimCarrierIdName()</code></a> 将获取运营商 ID 数据库中的最新信息。
</p>
</body></html>