Home | History | Annotate | Download | only in connect
      1 <html devsite>
      2   <head>
      3     <title>Implementing Block Phone Numbers</title>
      4     <meta name="project_path" value="/_project.yaml" />
      5     <meta name="book_path" value="/_book.yaml" />
      6   </head>
      7   <body>
      8   <!--
      9       Copyright 2017 The Android Open Source Project
     10 
     11       Licensed under the Apache License, Version 2.0 (the "License");
     12       you may not use this file except in compliance with the License.
     13       You may obtain a copy of the License at
     14 
     15           http://www.apache.org/licenses/LICENSE-2.0
     16 
     17       Unless required by applicable law or agreed to in writing, software
     18       distributed under the License is distributed on an "AS IS" BASIS,
     19       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20       See the License for the specific language governing permissions and
     21       limitations under the License.
     22   -->
     23 
     24 
     25 
     26 <p>
     27 Because telephony is such an open communications channel - anyone may call or
     28 text any number at any time - Android users need the ability to easily block
     29 unwanted calls and texts.
     30 </p>
     31 
     32 <p>
     33 Before N, Android users had to rely on downloaded apps to restrict calls and
     34 texts from bothersome phone numbers. Many of those apps either do not work as
     35 desired or provide a less-than ideal experience because there are no proper APIs
     36 for blocking calls and messages.
     37 </p>
     38 
     39 <p>
     40 Some manufacturers might ship their own blocking solutions out-of-the-box, but
     41 if users switch devices, they may lose the blocked list completely due to lack
     42 of interoperability. Finally, even if users are employing dialing apps and
     43 messaging clients that provide such functionality, they likely still have to
     44 perform the block action in each app for the block to take effect for both
     45 calling and texting.
     46 </p>
     47 
     48 <h2 id="features">Features</h2>
     49 
     50 <p>
     51 The Android 7.0 release introduces a <code>BlockedNumberProvider</code> content
     52 provider that stores a list of phone numbers the user has specified should not
     53 be able to contact them via telephony communications (calls, SMS, MMS). The
     54 system will respect the numbers in the blocked list by restricting calls and
     55 texts from those numbers. Android 7.0 displays the list of blocked numbers and
     56 allows the user to add and remove numbers.
     57 </p>
     58 
     59 <p>
     60 Further, the number-blocking feature enables the system and the relevant apps on
     61 the platform to work together to help protect the user and to simplify the
     62 experience. The default dialer, default messaging client, UICC-privileged app,
     63 and apps with the same signature as the system can all directly read from and
     64 write to the blocked list. Because the blocked numbers are stored on the system,
     65 no matter what dialing or messaging apps the user employs, the numbers stay
     66 blocked. Finally, the blocked numbers list may be restored on any new device,
     67 regardless of the manufacturer.
     68 </p>
     69 
     70 <ul>
     71 <li>User will be guaranteed to have a blocking feature that works out-of-the-box
     72 and will not lose their block list when they switch apps or get a new phone. All
     73 relevant apps on the system can share the same list to provide the user with the
     74 most streamlined experience.
     75 <li>App developers do not need to develop their own way to manage a block list
     76 and the calls and messages that come in. They can simply use the
     77 platform-provided feature.
     78 <li>Dialer / messenger apps that are selected as the default by the user can
     79 read and write to the provider. Other apps can launch the block list management
     80 user interface by using <code>createManageBlockedNumbersIntent()</code>
     81 <li>OEMs can use platform provided feature to ship a blocking feature
     82 out-of-the-box. OEMs can rest assured that when users switch from another OEMs
     83 device that they have a better onboarding experience because the block list will
     84 be transferred as well.
     85 <li>If carrier has their own dialer or messenger app, they can reuse platform
     86 feature for allowing the user to maintain a block list. They can rest assured
     87 that the users block list can stay with the users, even when they get a new
     88 device. Finally, all carrier-privileged apps can read the block list, so if the
     89 carrier wants to provide some additional more powerful blocking for the user
     90 based on the block list, that is now possible with this feature.</li></ul>
     91 
     92 <h2 id="data-flow">Data flow</h2>
     93 
     94 <img src="/devices/tech/connect/images/block-numbers-flow.png" alt="block numbers data flow" id="block-numbers-flow" />
     95 <p class="img-caption">
     96   <strong>Figure 1.</strong> Block phone numbers data flow
     97 </p>
     98 
     99 <h2 id="examples-and-source">Examples and source</h2>
    100 
    101 <p>
    102 Here are example calls using the number-blocking new feature:
    103 </p>
    104 
    105 <h3 id="launch-from-app">Launch blocked number manager from app</h3>
    106 
    107 <pre class="prettyprint">
    108 Context.startActivity(telecomManager.createManageBlockedNumbersIntent(), null);
    109 </pre>
    110 
    111 <h3 id="query-blocked-numbers">Query blocked numbers</h3>
    112 
    113 <pre class="prettyprint">
    114 Cursor c = getContentResolver().query(BlockedNumbers.CONTENT_URI,
    115          new String[]{BlockedNumbers.COLUMN_ID,
    116          BlockedNumbers.COLUMN_ORIGINAL_NUMBER,
    117          BlockedNumbers.COLUMN_E164_NUMBER}, null, null, null);
    118 </pre>
    119 
    120 <h3 id="put-blocked-number">Put blocked number</h3>
    121 
    122 <pre class="prettyprint">
    123 ContentValues values = new ContentValues();
    124 values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, "1234567890");
    125 Uri uri = getContentResolver().insert(BlockedNumbers.CONTENT_URI, values);
    126 </pre>
    127 
    128 <h3 id="delete-blocked-number">Delete blocked number</h3>
    129 
    130 <pre class="prettyprint">
    131 ContentValues values = new ContentValues();
    132 values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, "1234567890");
    133 Uri uri = getContentResolver().insert(BlockedNumbers.CONTENT_URI, values);
    134 getContentResolver().delete(uri, null, null);
    135 </pre>
    136 
    137 <h2 id="implementation">Implementation</h2>
    138 
    139 <p>
    140 These are the high-level tasks that must be completed to put the number-blocking
    141 feature to use:
    142 </p>
    143 
    144 <ul>
    145 <li>OEMs implement call/message-restriction features on their devices by using
    146 <code>BlockedNumberProvider</code>
    147 <li>If carrier has dialer or messenger application, implement call/message
    148 restriction features by using <code>BlockedNumberProvider</code>
    149 <li>Third-party dialer and messenger app vendors use
    150 <code>BlockedNumberProvider</code> for their blocking features</li>
    151 </ul>
    152 
    153 <h3 id="recommendations-for-oems">Recommendations for OEMs</h3>
    154 
    155 <p>
    156 If the device had previously never shipped with any additional call/message
    157 restriction features, use the number-blocking feature in the Android Open Source
    158 Project (AOSP) on all such devices. It is recommended that reasonable entry
    159 points for blocking are supported, such as blocking a number right from the call
    160 log or within a message thread.
    161 </p>
    162 
    163 <p>
    164 If the device had previously shipped with call/message restriction features,
    165 adapt the features so all <em>strict-match phone numbers</em> that are blocked
    166 are stored in the <code>BlockedNumberProvider,</code> and that the behavior
    167 around the provider satisfy the requirements for this feature outlined in the
    168 Android Compatibility Definition Document (CDD).
    169 </p>
    170 
    171 <p>
    172 Any other advanced feature can be implemented via custom providers and custom UI
    173 / controls, as long as the CDD requirements are satisfied with regards to
    174 blocking strict-match phone numbers. It is recommended that those other features
    175 be labeled as advanced features to avoid confusion with the basic
    176 number-blocking feature.
    177 </p>
    178 
    179 <h3 id="apis">APIs</h3>
    180 
    181 <p>
    182 Here are the APIs in use:
    183 </p>
    184 <ul>
    185 <li><code><a
    186 href="http://developer.android.com/reference/android/telecom/TelecomManager.html">TelecomManager</a>
    187 API</code>
    188   <ul>
    189  <li><code>Intent createManageBlockedNumbersIntent()</code>
    190   </ul>
    191 </li>
    192 <li><code><a
    193 href="http://developer.android.com/reference/android/telephony/CarrierConfigManager.html">Carrier
    194 Config</a></code>
    195   <ul>
    196  <li><code>KEY_DURATION_BLOCKING_DISABLED_AFTER_EMERGENCY_INT</code>
    197   </ul>
    198 </li>
    199 <li>Please refer to  <code>BlockedNumberContract</code>
    200   <ul>
    201  <li>APIs provided by <code><a
    202  href="https://developer.android.com/reference/android/provider/BlockedNumberContract.html">BlockedNumberContract</a></code></li>
    203  <li><code>boolean isBlocked(Context context, String phoneNumber)</code></li>
    204  <li><code>int unblock(Context context, String phoneNumber)</code></li>
    205  <li><code>boolean canCurrentUserBlockNumbers(Context context)</code></li>
    206   </ul>
    207  </li>
    208 </ul>
    209 
    210 <h3 id="user-interface">User interface</h3>
    211 <p>
    212 The BlockedNumbersActivity.java user interface provided in AOSP can be used as
    213 is. Device implementers may also implement their own version of the UI, as long as it
    214 satisfies related CDD requirements.
    215 </p>
    216 
    217 <p>
    218 Please note, the partners PC application for backup and restore may be needed
    219 to implement restoration of the block list by using
    220 <code>BlockedNumberProvider</code>. See the images below for the blocked
    221 numbers interface supplied in AOSP.
    222 </p>
    223 
    224 <img src="images/block-numbers-ui.png" alt="block numbers user interface" width="665" id="block-numbers-ui" />
    225 <p class="img-caption">
    226   <strong>Figure 2.</strong> Block phone numbers user interface
    227 </p>
    228 
    229 <h2 id="validation">Validation</h2>
    230 
    231 <p>
    232 Implementers can ensure their version of the feature works as intended by
    233 running the following CTS tests:
    234 </p>
    235 
    236 <pre class="devsite-click-to-copy">
    237 android.provider.cts.BlockedNumberContractTest
    238 com.android.cts.numberblocking.hostside.NumberBlockingTest
    239 android.telecom.cts.ExtendedInCallServiceTest#testIncomingCallFromBlockedNumber_IsRejected
    240 android.telephony.cts.SmsManagerTest#testSmsBlocking
    241 </pre>
    242 
    243 <p>
    244 The <code>BlockedNumberProvider</code> can be manipulated using <code>adb</code> commands
    245 after running <code>$ adb root</code>. For example:
    246 </p>
    247 <pre class="devsite-click-to-copy">
    248 <code class="devsite-terminal">adb root</code>
    249 <code class="devsite-terminal">adb shell content query --uri content://com.android.blockednumber/blocked</code>
    250 <code class="devsite-terminal">adb shell content insert --uri / content://com.android.blockednumber/blocked --bind / original_number:s:'6501002000'</code>
    251 <code class="devsite-terminal">adb shell content delete --uri / content://com.android.blockednumber/blocked/1</code>
    252 </pre>
    253 
    254   </body>
    255 </html>
    256