Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.cellbroadcastreceiver.tests;
     18 
     19 import android.Manifest;
     20 import android.app.Activity;
     21 import android.app.AppOpsManager;
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.os.UserHandle;
     25 import android.provider.Telephony.Sms.Intents;
     26 import android.telephony.SmsCbLocation;
     27 import android.telephony.SmsCbMessage;
     28 import android.util.Log;
     29 
     30 import com.android.internal.telephony.gsm.GsmSmsCbMessage;
     31 import com.android.internal.telephony.gsm.SmsCbConstants;
     32 import com.android.internal.telephony.gsm.SmsCbHeader;
     33 import com.android.internal.telephony.uicc.IccUtils;
     34 
     35 /**
     36  * Send test messages.
     37  */
     38 public class SendTestMessages {
     39 
     40     private static String TAG = "SendTestMessages";
     41 
     42     private static final String CB_RECEIVER_PKG = "com.android.cellbroadcastreceiver";
     43 
     44     private static final int DCS_7BIT_ENGLISH = 0x01;
     45     private static final int DCS_16BIT_UCS2 = 0x48;
     46 
     47     /* ETWS Test message including header */
     48     private static final byte[] etwsMessageNormal = IccUtils.hexStringToBytes("000011001101" +
     49             "EA305BAE57CE770C531790E85C716CBF3044573065B930675730" +
     50             "9707767A751F30025F37304463FA308C306B5099304830664E0B30553044FF086C178C615E81FF09" +
     51             "0000000000000000000000000000");
     52 
     53     private static final byte[] etwsMessageCancel = IccUtils.hexStringToBytes("000011001101" +
     54             "EA305148307B3069002800310030003A0035" +
     55             "00320029306E7DCA602557309707901F5831309253D66D883057307E3059FF086C178C615E81FF09" +
     56             "00000000000000000000000000000000000000000000");
     57 
     58     private static final byte[] etwsMessageTest = IccUtils.hexStringToBytes("000011031101" +
     59             "EA305BAE57CE770C531790E85C716CBF3044" +
     60             "573065B9306757309707300263FA308C306B5099304830664E0B30553044FF086C178C615E81FF09" +
     61             "00000000000000000000000000000000000000000000");
     62 
     63     private static final byte[] gsm7BitTest = {
     64             (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x40, (byte)0x11, (byte)0x41,
     65             (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91, (byte)0xCB, (byte)0xE6,
     66             (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07, (byte)0x85, (byte)0xD9, (byte)0x70,
     67             (byte)0x74, (byte)0x58, (byte)0x5C, (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5,
     68             (byte)0xF9, (byte)0x3C, (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69,
     69             (byte)0x3A, (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
     70             (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9, (byte)0x75,
     71             (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93, (byte)0xC9, (byte)0x69,
     72             (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
     73             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
     74             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
     75             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
     76             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
     77     };
     78 
     79     private static final byte[] gsm7BitTestUmts = {
     80             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
     81 
     82             (byte)0x01,
     83 
     84             (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
     85             (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
     86             (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
     87             (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
     88             (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
     89             (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
     90             (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
     91             (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
     92             (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
     93             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
     94             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
     95             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
     96             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
     97             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
     98 
     99             (byte)0x34
    100     };
    101 
    102     private static final byte[] gsm7BitTestMultipageUmts = {
    103             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
    104 
    105             (byte)0x02,
    106 
    107             (byte)0xC6, (byte)0xB4, (byte)0x7C, (byte)0x4E, (byte)0x07, (byte)0xC1,
    108             (byte)0xC3, (byte)0xE7, (byte)0xF2, (byte)0xAA, (byte)0xD1, (byte)0x68,
    109             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    110             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    111             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    112             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    113             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
    114             (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
    115             (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
    116             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    117             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    118             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    119             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    120             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
    121 
    122             (byte)0x0A,
    123 
    124             (byte)0xD3, (byte)0xF2, (byte)0xF8, (byte)0xED, (byte)0x26, (byte)0x83,
    125             (byte)0xE0, (byte)0xE1, (byte)0x73, (byte)0xB9, (byte)0xD1, (byte)0x68,
    126             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    127             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    128             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    129             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    130             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
    131             (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
    132             (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
    133             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    134             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    135             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    136             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    137             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
    138 
    139             (byte)0x0A
    140     };
    141 
    142     private static final byte[] gsm7BitTestMultipage1 = {
    143             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
    144             (byte)0xC6, (byte)0xB4, (byte)0x7C, (byte)0x4E, (byte)0x07, (byte)0xC1,
    145             (byte)0xC3, (byte)0xE7, (byte)0xF2, (byte)0xAA, (byte)0xD1, (byte)0x68,
    146             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    147             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    148             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    149             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    150             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
    151             (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
    152             (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
    153             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    154             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    155             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    156             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    157             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
    158     };
    159 
    160     private static final byte[] gsm7BitTestMultipage2 = {
    161             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
    162             (byte)0xD3, (byte)0xF2, (byte)0xF8, (byte)0xED, (byte)0x26, (byte)0x83,
    163             (byte)0xE0, (byte)0xE1, (byte)0x73, (byte)0xB9, (byte)0xD1, (byte)0x68,
    164             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    165             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    166             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    167             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    168             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
    169             (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
    170             (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
    171             (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    172             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    173             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    174             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    175             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
    176     };
    177 
    178     private static final byte[] gsm7BitTestNoPadding = {
    179             (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x40, (byte)0x11, (byte)0x41,
    180             (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91, (byte)0xCB, (byte)0xE6,
    181             (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07, (byte)0x85, (byte)0xD9, (byte)0x70,
    182             (byte)0x74, (byte)0x58, (byte)0x5C, (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5,
    183             (byte)0xF9, (byte)0x3C, (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xC4, (byte)0xE5,
    184             (byte)0xB4, (byte)0xFB, (byte)0x0C, (byte)0x2A, (byte)0xE3, (byte)0xC3, (byte)0x63,
    185             (byte)0x3A, (byte)0x3B, (byte)0x0F, (byte)0xCA, (byte)0xCD, (byte)0x40, (byte)0x63,
    186             (byte)0x74, (byte)0x58, (byte)0x1E, (byte)0x1E, (byte)0xD3, (byte)0xCB, (byte)0xF2,
    187             (byte)0x39, (byte)0x88, (byte)0xFD, (byte)0x76, (byte)0x9F, (byte)0x59, (byte)0xA0,
    188             (byte)0x76, (byte)0x39, (byte)0xEC, (byte)0x4E, (byte)0xBB, (byte)0xCF, (byte)0x20,
    189             (byte)0x3A, (byte)0xBA, (byte)0x2C, (byte)0x2F, (byte)0x83, (byte)0xD2, (byte)0x73,
    190             (byte)0x90, (byte)0xFB, (byte)0x0D, (byte)0x82, (byte)0x87, (byte)0xC9, (byte)0xE4,
    191             (byte)0xB4, (byte)0xFB, (byte)0x1C, (byte)0x02
    192     };
    193 
    194     private static final byte[] gsm7BitTestNoPaddingUmts = {
    195             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
    196 
    197             (byte)0x01,
    198 
    199             (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
    200             (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
    201             (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
    202             (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
    203             (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xC4, (byte)0xE5, (byte)0xB4,
    204             (byte)0xFB, (byte)0x0C, (byte)0x2A, (byte)0xE3, (byte)0xC3, (byte)0x63,
    205             (byte)0x3A, (byte)0x3B, (byte)0x0F, (byte)0xCA, (byte)0xCD, (byte)0x40,
    206             (byte)0x63, (byte)0x74, (byte)0x58, (byte)0x1E, (byte)0x1E, (byte)0xD3,
    207             (byte)0xCB, (byte)0xF2, (byte)0x39, (byte)0x88, (byte)0xFD, (byte)0x76,
    208             (byte)0x9F, (byte)0x59, (byte)0xA0, (byte)0x76, (byte)0x39, (byte)0xEC,
    209             (byte)0x4E, (byte)0xBB, (byte)0xCF, (byte)0x20, (byte)0x3A, (byte)0xBA,
    210             (byte)0x2C, (byte)0x2F, (byte)0x83, (byte)0xD2, (byte)0x73, (byte)0x90,
    211             (byte)0xFB, (byte)0x0D, (byte)0x82, (byte)0x87, (byte)0xC9, (byte)0xE4,
    212             (byte)0xB4, (byte)0xFB, (byte)0x1C, (byte)0x02,
    213 
    214             (byte)0x52
    215     };
    216 
    217     private static final byte[] gsm7BitTestWithLanguage = {
    218             (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x04, (byte)0x11, (byte)0x41,
    219             (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91, (byte)0xCB, (byte)0xE6,
    220             (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07, (byte)0x85, (byte)0xD9, (byte)0x70,
    221             (byte)0x74, (byte)0x58, (byte)0x5C, (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5,
    222             (byte)0xF9, (byte)0x3C, (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69,
    223             (byte)0x3A, (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
    224             (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9, (byte)0x75,
    225             (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93, (byte)0xC9, (byte)0x69,
    226             (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    227             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    228             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    229             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    230             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
    231     };
    232 
    233     private static final byte[] gsm7BitTestWithLanguageInBody = {
    234             (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x10, (byte)0x11, (byte)0x73,
    235             (byte)0x7B, (byte)0x23, (byte)0x08, (byte)0x3A, (byte)0x4E, (byte)0x9B, (byte)0x20,
    236             (byte)0x72, (byte)0xD9, (byte)0x1C, (byte)0xAE, (byte)0xB3, (byte)0xE9, (byte)0xA0,
    237             (byte)0x30, (byte)0x1B, (byte)0x8E, (byte)0x0E, (byte)0x8B, (byte)0xCB, (byte)0x74,
    238             (byte)0x50, (byte)0xBB, (byte)0x3C, (byte)0x9F, (byte)0x87, (byte)0xCF, (byte)0x65,
    239             (byte)0xD0, (byte)0x3D, (byte)0x4D, (byte)0x47, (byte)0x83, (byte)0xC6, (byte)0x61,
    240             (byte)0xB9, (byte)0x3C, (byte)0x1D, (byte)0x3E, (byte)0x97, (byte)0x41, (byte)0xF2,
    241             (byte)0x32, (byte)0xBD, (byte)0x2E, (byte)0x77, (byte)0x83, (byte)0xE0, (byte)0x61,
    242             (byte)0x32, (byte)0x39, (byte)0xED, (byte)0x3E, (byte)0x37, (byte)0x1A, (byte)0x8D,
    243             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    244             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    245             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    246             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
    247     };
    248 
    249     private static final byte[] gsm7BitTestWithLanguageInBodyUmts = {
    250             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x10,
    251 
    252             (byte)0x01,
    253 
    254             (byte)0x73, (byte)0x7B, (byte)0x23, (byte)0x08, (byte)0x3A, (byte)0x4E,
    255             (byte)0x9B, (byte)0x20, (byte)0x72, (byte)0xD9, (byte)0x1C, (byte)0xAE,
    256             (byte)0xB3, (byte)0xE9, (byte)0xA0, (byte)0x30, (byte)0x1B, (byte)0x8E,
    257             (byte)0x0E, (byte)0x8B, (byte)0xCB, (byte)0x74, (byte)0x50, (byte)0xBB,
    258             (byte)0x3C, (byte)0x9F, (byte)0x87, (byte)0xCF, (byte)0x65, (byte)0xD0,
    259             (byte)0x3D, (byte)0x4D, (byte)0x47, (byte)0x83, (byte)0xC6, (byte)0x61,
    260             (byte)0xB9, (byte)0x3C, (byte)0x1D, (byte)0x3E, (byte)0x97, (byte)0x41,
    261             (byte)0xF2, (byte)0x32, (byte)0xBD, (byte)0x2E, (byte)0x77, (byte)0x83,
    262             (byte)0xE0, (byte)0x61, (byte)0x32, (byte)0x39, (byte)0xED, (byte)0x3E,
    263             (byte)0x37, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
    264             (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
    265             (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
    266             (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
    267             (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
    268 
    269             (byte)0x37
    270     };
    271 
    272     private static final byte[] gsmUcs2Test = {
    273             (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x48, (byte)0x11, (byte)0x00,
    274             (byte)0x41, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x55, (byte)0x00, (byte)0x43,
    275             (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x32, (byte)0x00, (byte)0x20, (byte)0x00,
    276             (byte)0x6D, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73,
    277             (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65, (byte)0x00,
    278             (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F, (byte)0x00, (byte)0x6E,
    279             (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x69, (byte)0x00,
    280             (byte)0x6E, (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x67,
    281             (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x20, (byte)0x04,
    282             (byte)0x34, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68,
    283             (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61, (byte)0x00,
    284             (byte)0x63, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x72,
    285             (byte)0x00, (byte)0x0D, (byte)0x00, (byte)0x0D
    286     };
    287 
    288     private static final byte[] gsmUcs2TestUmts = {
    289             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x48,
    290 
    291             (byte)0x01,
    292 
    293             (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x55,
    294             (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x32,
    295             (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x6D, (byte)0x00, (byte)0x65,
    296             (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x61,
    297             (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x20,
    298             (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F, (byte)0x00, (byte)0x6E,
    299             (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x69,
    300             (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E,
    301             (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x61,
    302             (byte)0x00, (byte)0x20, (byte)0x04, (byte)0x34, (byte)0x00, (byte)0x20,
    303             (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68, (byte)0x00, (byte)0x61,
    304             (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x63,
    305             (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x72,
    306             (byte)0x00, (byte)0x0D, (byte)0x00, (byte)0x0D,
    307 
    308             (byte)0x4E
    309     };
    310 
    311     private static final byte[] gsmUcs2TestMultipageUmts = {
    312             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x48,
    313 
    314             (byte)0x02,
    315 
    316             (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x41,
    317             (byte)0x00, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    318             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    319             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    320             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    321             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    322             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    323             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    324             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    325             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    326             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    327             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    328             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    329             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    330 
    331             (byte)0x06,
    332 
    333             (byte)0x00, (byte)0x42, (byte)0x00, (byte)0x42, (byte)0x00, (byte)0x42,
    334             (byte)0x00, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    335             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    336             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    337             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    338             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    339             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    340             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    341             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    342             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    343             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    344             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    345             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    346             (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
    347 
    348             (byte)0x06
    349     };
    350 
    351     private static final byte[] gsmUcs2TestWithLanguageInBody = {
    352             (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x11, (byte)0x11, (byte)0x78,
    353             (byte)0x3C, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x55,
    354             (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x32, (byte)0x00,
    355             (byte)0x20, (byte)0x00, (byte)0x6D, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73,
    356             (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x67, (byte)0x00,
    357             (byte)0x65, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F,
    358             (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61, (byte)0x00,
    359             (byte)0x69, (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E,
    360             (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x61, (byte)0x00,
    361             (byte)0x20, (byte)0x04, (byte)0x34, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63,
    362             (byte)0x00, (byte)0x68, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x72, (byte)0x00,
    363             (byte)0x61, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65,
    364             (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x0D
    365     };
    366 
    367     private static final byte[] gsmUcs2TestWithLanguageInBodyUmts = {
    368             (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x11,
    369 
    370             (byte)0x01,
    371 
    372             (byte)0x78, (byte)0x3C, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20,
    373             (byte)0x00, (byte)0x55, (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53,
    374             (byte)0x00, (byte)0x32, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x6D,
    375             (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73,
    376             (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65,
    377             (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F,
    378             (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61,
    379             (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69,
    380             (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20,
    381             (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x20, (byte)0x04, (byte)0x34,
    382             (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68,
    383             (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61,
    384             (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65,
    385             (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x0D,
    386 
    387             (byte)0x50
    388     };
    389 
    390     private static final SmsCbLocation sEmptyLocation = new SmsCbLocation();
    391 
    392     private static SmsCbMessage createFromPdu(Context context, byte[] pdu, int serialNumber,
    393                                               int category) {
    394         byte[][] pdus = new byte[1][];
    395         pdus[0] = pdu;
    396         return createFromPdus(context, pdus, serialNumber, category);
    397     }
    398 
    399     private static SmsCbMessage createFromPdus(Context context, byte[][] pdus, int serialNumber,
    400                                                int category) {
    401         try {
    402             for (byte[] pdu : pdus) {
    403                 if (pdu.length <= 88) {
    404                     // GSM format cell broadcast
    405                     Log.d(TAG, "setting GSM serial number to " + serialNumber);
    406                     pdu[0] = (byte) ((serialNumber >>> 8) & 0xff);
    407                     pdu[1] = (byte) (serialNumber & 0xff);
    408                     if (category != 0) {
    409                         Log.d(TAG, "setting GSM message identifier to " + category);
    410                         pdu[2] = (byte) ((category >>> 8) & 0xff);
    411                         pdu[3] = (byte) (category & 0xff);
    412                     }
    413                 } else {
    414                     // UMTS format cell broadcast
    415                     Log.d(TAG, "setting UMTS serial number to " + serialNumber);
    416                     pdu[3] = (byte) ((serialNumber >>> 8) & 0xff);
    417                     pdu[4] = (byte) (serialNumber & 0xff);
    418                     if (category != 0) {
    419                         Log.d(TAG, "setting UMTS message identifier to " + category);
    420                         pdu[1] = (byte) ((category >>> 8) & 0xff);
    421                         pdu[2] = (byte) (category & 0xff);
    422                     }
    423                 }
    424             }
    425             return GsmSmsCbMessage.createSmsCbMessage(context, new SmsCbHeader(pdus[0]),
    426                     sEmptyLocation, pdus);
    427         } catch (IllegalArgumentException e) {
    428             return null;
    429         }
    430     }
    431 
    432     private static void sendBroadcast(Activity activity, int serialNumber, int category,
    433                                       byte[] pdu) {
    434         Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
    435         intent.putExtra("message", createFromPdu(activity, pdu, serialNumber, category));
    436         intent.setPackage(CB_RECEIVER_PKG);
    437         activity.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, Manifest.permission.RECEIVE_SMS,
    438                 AppOpsManager.OP_RECEIVE_SMS, null, null, Activity.RESULT_OK, null, null);
    439     }
    440 
    441     public static void testSendMessage7bit(Activity activity, int serialNumber,
    442             int category) {
    443         sendBroadcast(activity, serialNumber, category, gsm7BitTest);
    444     }
    445 
    446     public static void testSendMessage7bitUmts(Activity activity, int serialNumber,
    447             int category) {
    448         sendBroadcast(activity, serialNumber, category, gsm7BitTestUmts);
    449     }
    450 
    451     public static void testSendMessage7bitNoPadding(Activity activity, int serialNumber,
    452             int category) {
    453         sendBroadcast(activity, serialNumber, category, gsm7BitTestNoPadding);
    454     }
    455 
    456     public static void testSendMessage7bitNoPaddingUmts(Activity activity, int serialNumber,
    457             int category) {
    458         sendBroadcast(activity, serialNumber, category, gsm7BitTestNoPaddingUmts);
    459     }
    460 
    461     public static void testSendMessage7bitMultipageGsm(Activity activity, int serialNumber,
    462             int category) {
    463         Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
    464         byte[][] pdus = new byte[2][];
    465         pdus[0] = gsm7BitTestMultipage1;
    466         pdus[1] = gsm7BitTestMultipage2;
    467         intent.putExtra("message", createFromPdus(activity, pdus, serialNumber, category));
    468         intent.setPackage(CB_RECEIVER_PKG);
    469         activity.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, Manifest.permission.RECEIVE_SMS,
    470                 AppOpsManager.OP_RECEIVE_SMS, null, null, Activity.RESULT_OK, null, null);
    471     }
    472 
    473     public static void testSendMessage7bitMultipageUmts(Activity activity, int serialNumber,
    474             int category) {
    475         sendBroadcast(activity, serialNumber, category, gsm7BitTestMultipageUmts);
    476     }
    477 
    478     public static void testSendMessage7bitWithLanguage(Activity activity, int serialNumber,
    479             int category) {
    480         sendBroadcast(activity, serialNumber, category, gsm7BitTestWithLanguage);
    481     }
    482 
    483     public static void testSendMessage7bitWithLanguageInBody(Activity activity, int serialNumber,
    484             int category) {
    485         sendBroadcast(activity, serialNumber, category, gsm7BitTestWithLanguageInBody);
    486     }
    487 
    488     public static void testSendMessage7bitWithLanguageInBodyUmts(Activity activity,
    489             int serialNumber, int category) {
    490         sendBroadcast(activity, serialNumber, category, gsm7BitTestWithLanguageInBodyUmts);
    491     }
    492 
    493     public static void testSendMessageUcs2(Activity activity, int serialNumber,
    494             int category) {
    495         sendBroadcast(activity, serialNumber, category, gsmUcs2Test);
    496     }
    497 
    498     public static void testSendMessageUcs2Umts(Activity activity, int serialNumber,
    499             int category) {
    500         sendBroadcast(activity, serialNumber, category, gsmUcs2TestUmts);
    501     }
    502 
    503     public static void testSendMessageUcs2MultipageUmts(Activity activity, int serialNumber,
    504             int category) {
    505         sendBroadcast(activity, serialNumber, category, gsmUcs2TestMultipageUmts);
    506     }
    507 
    508     public static void testSendMessageUcs2WithLanguageInBody(Activity activity, int serialNumber,
    509             int category) {
    510         sendBroadcast(activity, serialNumber, category, gsmUcs2TestWithLanguageInBody);
    511     }
    512 
    513     public static void testSendMessageUcs2WithLanguageUmts(Activity activity, int serialNumber,
    514             int category) {
    515         sendBroadcast(activity, serialNumber, category, gsmUcs2TestWithLanguageInBodyUmts);
    516     }
    517 
    518     public static void testSendEtwsMessageEarthquake(Activity activity, int serialNumber) {
    519         sendBroadcast(activity, serialNumber, SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_WARNING,
    520                 etwsMessageNormal);
    521     }
    522 
    523     public static void testSendEtwsMessageTsunami(Activity activity, int serialNumber) {
    524         sendBroadcast(activity, serialNumber, SmsCbConstants.MESSAGE_ID_ETWS_TSUNAMI_WARNING,
    525                 etwsMessageNormal);
    526     }
    527 
    528     public static void testSendEtwsMessageEarthquakeTsunami(Activity activity, int serialNumber) {
    529         sendBroadcast(activity, serialNumber,
    530                 SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING, etwsMessageNormal);
    531     }
    532 
    533     public static void testSendEtwsMessageOther(Activity activity, int serialNumber) {
    534         sendBroadcast(activity, serialNumber, SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE,
    535                 etwsMessageNormal);
    536     }
    537 
    538     public static void testSendEtwsMessageCancel(Activity activity, int serialNumber) {
    539         sendBroadcast(activity, serialNumber, 0, etwsMessageCancel);
    540     }
    541 
    542     public static void testSendEtwsMessageTest(Activity activity, int serialNumber) {
    543         sendBroadcast(activity, serialNumber, SmsCbConstants.MESSAGE_ID_ETWS_TEST_MESSAGE,
    544                 etwsMessageTest);
    545     }
    546 }