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