Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2015 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 | ## Script that generates SMS and MMS messages and fills the Android |
| 17 | ## telephony provider mmssms.db. This is used for testing SMS/MMS. |
| 18 | ################################################################### |
| 19 | |
| 20 | AREA_CODE=605 |
| 21 | |
| 22 | TABLE_CANONICAL_ADDRESSES_START_ID=100 |
| 23 | TABLE_THREADS_START_ID=100 |
| 24 | TABLE_SMS_START_ID=1000 |
| 25 | |
| 26 | START_TIMESTAMP_IN_SECONDS=1357683093 # 1/8/2013 2:11:33 PM |
| 27 | TIMESTAMP_INC_IN_SECONDS=120 |
| 28 | |
| 29 | PART_DIR="/data/data/com.android.providers.telephony/app_parts" |
| 30 | |
| 31 | USAGE='fillsms [-f] [-x] <device_phone_number> <# of threads> <# of sms per thread> <# of mms per thread> <image list file> <sql file> |
| 32 | -f -- Only generates the SQL file, do not push to the device |
| 33 | -x -- Only execute a SQL file |
| 34 | -g -- For GB devices |
| 35 | Examples: |
| 36 | # Generate 2 threads each with 10 SMSes and 10 MMSes on device with phone |
| 37 | # number +16508619525. MMS messages use images listed in ./images, which list |
| 38 | # *.jpg and *.gif files in local directory. The SQL commands are in sql.txt |
| 39 | fillsms +16508619525 2 10 10 images sql.txt |
| 40 | |
| 41 | # Same as above but only creating the SQL command file without pushing to |
| 42 | # device |
| 43 | fillsms -f +16508619525 2 10 10 images sql.txt |
| 44 | |
| 45 | # Just push the sql.txt to device without generating new SQLs |
| 46 | fillsms -x +16508619525 2 10 10 images sql.txt |
| 47 | ' |
| 48 | |
| 49 | SMIL='<smil> <head> <layout> <root-layout height="%dpx" width="%dpx"> <region fit="meet" height="%dpx" id="Image" left="0" top="0" width="%dpx"/></root-layout> </layout> </head> <body> <par dur="5000ms"> <img region="Image" src="%s"/> </par> </body> </smil>' |
| 50 | |
| 51 | MAX_WORDS_PER_MESSAGE=15 |
| 52 | |
| 53 | DICT=american-english |
| 54 | |
| 55 | # don't actually run the sql on device |
| 56 | opt_sql_only=0 |
| 57 | opt_exec_only=0 |
| 58 | opt_for_gb=0 |
| 59 | |
| 60 | while test $# -gt 0 |
| 61 | do |
| 62 | case $1 in |
| 63 | -f) |
| 64 | opt_sql_only=1 |
| 65 | shift |
| 66 | ;; |
| 67 | -x) |
| 68 | opt_exec_only=1 |
| 69 | shift |
| 70 | ;; |
| 71 | -g) |
| 72 | opt_for_gb=1 |
| 73 | shift |
| 74 | ;; |
| 75 | *) |
| 76 | break; |
| 77 | esac |
| 78 | done |
| 79 | |
| 80 | |
| 81 | if [ $opt_sql_only -eq "1" -a $opt_exec_only -eq "1" ]; then |
| 82 | echo "-f and -x can not coexist" |
| 83 | echo "$USAGE" |
| 84 | exit 1 |
| 85 | fi |
| 86 | |
| 87 | if [ $# -lt 6 ]; then |
| 88 | echo "$USAGE" |
| 89 | exit 1 |
| 90 | fi |
| 91 | device_phone=$1 |
| 92 | shift |
| 93 | num_of_threads=$1 |
| 94 | shift |
| 95 | sms_per_thread=$1 |
| 96 | shift |
| 97 | mms_per_thread=$1 |
| 98 | shift |
| 99 | image_list_file=$1 |
| 100 | shift |
| 101 | sql_file=$1 |
| 102 | shift |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 103 | echo $image_list_file |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 104 | |
| 105 | dict_lines=`wc -l < $DICT` |
| 106 | image_files=`wc -l < $image_list_file` |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 107 | echo $image_files |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 108 | |
| 109 | if [ $mms_per_thread -gt "0" ]; then |
| 110 | if [ ! -f $image_list_file ]; then |
| 111 | echo "No image files for creating MMS messages" |
| 112 | exit 1 |
| 113 | fi |
| 114 | fi |
| 115 | |
| 116 | echoerr () |
| 117 | { |
| 118 | echo "$@" 1>&2; |
| 119 | } |
| 120 | |
| 121 | random_value () |
| 122 | { |
| 123 | echo $(( $RANDOM % $1 + 1 )) |
| 124 | } |
| 125 | |
| 126 | dict_word () |
| 127 | { |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 128 | local v=$(random_value $dict_lines) |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 129 | sed $v"q;d" $DICT |
| 130 | } |
| 131 | |
| 132 | gen_message () |
| 133 | { |
| 134 | local words=$(random_value $MAX_WORDS_PER_MESSAGE) |
| 135 | local message= |
| 136 | for k in `seq 1 $words`; |
| 137 | do |
| 138 | local word=$(dict_word) |
| 139 | message="$message $word" |
| 140 | done |
| 141 | echo $message | sed -e "s/'//g" |
| 142 | } |
| 143 | |
| 144 | random_image () |
| 145 | { |
| 146 | local v=$(random_value $image_files) |
| 147 | sed $v"q;d" $image_list_file |
| 148 | } |
| 149 | |
| 150 | add_sql () |
| 151 | { |
| 152 | echo $1 >> $sql_file |
| 153 | } |
| 154 | |
| 155 | adb_sql () |
| 156 | { |
| 157 | echo $1 |
| 158 | adb shell sqlite3 data/data/com.android.providers.telephony/databases/mmssms.db "$1" |
| 159 | } |
| 160 | |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 161 | adb_sql_with_quotes () |
| 162 | { |
| 163 | echo $1 |
| 164 | adb shell "sqlite3 data/data/com.android.providers.telephony/databases/mmssms.db \"$1\"" |
| 165 | } |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 166 | ###################################################################################### |
| 167 | ###################################################################################### |
| 168 | |
| 169 | if [ $opt_exec_only -eq "0" ]; then |
| 170 | # clean up sql file |
| 171 | rm -f $sql_file |
| 172 | |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 173 | add_sql "PRAGMA trusted_schema=1;" |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 174 | # add sql to clean up database |
| 175 | add_sql "delete from pdu where _id>=$TABLE_SMS_START_ID;" |
| 176 | add_sql "delete from part where _id>=$TABLE_SMS_START_ID;" |
| 177 | add_sql "delete from addr where _id>=$TABLE_SMS_START_ID;" |
| 178 | add_sql "delete from sms where _id>=$TABLE_SMS_START_ID;" |
| 179 | add_sql "delete from threads where _id>=$TABLE_THREADS_START_ID;" |
| 180 | add_sql "delete from canonical_addresses where _id>=$TABLE_CANONICAL_ADDRESSES_START_ID;" |
| 181 | |
| 182 | for i in `seq 1 $num_of_threads`; |
| 183 | do |
| 184 | echo |
| 185 | echo "Creating thread $i ......" |
| 186 | echo |
| 187 | |
| 188 | # Get random phone number |
| 189 | value=$(random_value 1000) |
| 190 | middle=$(printf '%03d' $value) |
| 191 | value=$(random_value 10000) |
| 192 | last=$(printf '%04d' $value) |
| 193 | phone="+1$AREA_CODE$middle$last" |
| 194 | echo $phone |
| 195 | echo |
| 196 | |
| 197 | timestamp=$(( $START_TIMESTAMP_IN_SECONDS + 5 * $TIMESTAMP_INC_IN_SECONDS * $i )) |
| 198 | |
| 199 | # Generate threads |
| 200 | addr_id=$(( $TABLE_CANONICAL_ADDRESSES_START_ID + $i )) |
| 201 | add_sql "insert into canonical_addresses (_id,address) values ($addr_id,'$phone');" |
| 202 | |
| 203 | thread_id=$(( $TABLE_THREADS_START_ID + $i )) |
| 204 | add_sql "insert into threads (_id,date,message_count,recipient_ids,snippet,snippet_cs,read,type,error,has_attachment) values ($thread_id, $timestamp, $sms_per_thread, $addr_id, 'snippet', 0, 1, 0, 0, 0);" |
| 205 | |
| 206 | # Generate SMS |
| 207 | if [ $sms_per_thread -gt "0" ]; then |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 208 | add_sql "PRAGMA trusted_schema=1;" |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 209 | half_timestamp_inc=$(( 500 + ((($sms_per_thread + $mms_per_thread) * $TIMESTAMP_INC_IN_SECONDS) * 500 / $sms_per_thread) )) |
| 210 | for j in `seq 1 $sms_per_thread`; |
| 211 | do |
| 212 | message=$(gen_message) |
| 213 | date=$(( ( 1000 * $timestamp ) - $half_timestamp_inc * ( 2 * ($sms_per_thread - $j) + ( $i % 2 ) ) )) |
| 214 | message_id=$(( $TABLE_SMS_START_ID + $sms_per_thread * $i * 2 + (2 * $j) )) |
| 215 | message_type=$(( $j % 2 + 1 )) |
| 216 | add_sql "insert into sms (_id,thread_id,address,person,date,status,type,body,read,seen) values ($message_id, $thread_id, '$phone', '$phone', $date, -1, $message_type, '$message', 1, 1);" |
| 217 | done |
| 218 | fi |
| 219 | |
| 220 | # Generate MMS |
| 221 | if [ $mms_per_thread -gt "0" ]; then |
| 222 | half_timestamp_inc=$(( 1 + ((($sms_per_thread + $mms_per_thread) * $TIMESTAMP_INC_IN_SECONDS) / ( 2 * $mms_per_thread) ) )) |
| 223 | for j in `seq 1 $mms_per_thread`; |
| 224 | do |
| 225 | image_line=$(random_image) |
| 226 | image=`echo $image_line | awk '{ print $1 }'` |
| 227 | width=`echo $image_line | awk '{ print $2 }'` |
| 228 | height=`echo $image_line | awk '{ print $3 }'` |
| 229 | size=`echo $image_line | awk '{ print $4 }'` |
| 230 | date=$(( $timestamp - $half_timestamp_inc * ( 2 * ($mms_per_thread - $j) + ( ($i+1) % 2 ) ) )) |
| 231 | message_id=$(( $TABLE_SMS_START_ID + $sms_per_thread * $i * 2 + (2 * $j + 1) )) |
| 232 | message_type=$(( $j % 2 + 1 )) |
| 233 | if [ $message_type -eq '1' ]; then |
| 234 | m_type=132 |
| 235 | else |
| 236 | m_type=128 |
| 237 | fi |
| 238 | if [ $opt_for_gb -eq "0" ]; then |
| 239 | add_sql "insert into pdu (_id,thread_id,date,date_sent,msg_box,read,m_id,sub,sub_cs,ct_t,m_cls,m_type,v,m_size,pri,rr,tr_id,d_rpt,locked,seen,text_only) values ($message_id, $thread_id, $date, 0, $message_type, 1, 'hmma3p5s1a3m526@w.tmomail.net', 'no subject', 106, 'application/vnd.wap.multipart.related', 'personal', $m_type, 18, $size, 129, 129 , '$message_id', 129, 0, 1, 0);" |
| 240 | else |
| 241 | add_sql "insert into pdu (_id,thread_id,date,msg_box,read,m_id,sub,sub_cs,ct_t,m_cls,m_type,v,m_size,pri,rr,tr_id,d_rpt,locked,seen) values ($message_id, $thread_id, $date, $message_type, 1, 'hmma3p5s1a3m526@w.tmomail.net', 'no subject', 106, 'application/vnd.wap.multipart.related', 'personal', $m_type, 18, $size, 129, 129 , '$message_id', 129, 0, 1);" |
| 242 | fi |
| 243 | id_1=$(( $message_id )) |
| 244 | id_2=$(( $message_id + 1 )) |
| 245 | smil=$(printf "$SMIL" $height $width $height $width $image) |
| 246 | add_sql "insert into part (_id,mid,seq,ct,cid,cl,text) values ($id_1, $message_id, -1, 'application/smil', '<smil>', 'smil.xml', '$smil');" |
| 247 | image_no_suffix=${image%.*} |
| 248 | add_sql "insert into part (_id,mid,seq,ct,cid,cl,_data) values ($id_2, $message_id, 0, 'image/jpeg', '$image_no_suffix', '$image', '$PART_DIR/$image');" |
| 249 | if [ $message_type -eq '1' ]; then |
| 250 | add_sql "insert into addr (_id,msg_id,address,type,charset) values ($id_1, $message_id, '$phone', 137, 106);" |
| 251 | add_sql "insert into addr (_id,msg_id,address,type,charset) values ($id_2, $message_id, '$device_phone', 151, 106);" |
| 252 | else |
| 253 | add_sql "insert into addr (_id,msg_id,address,type,charset) values ($id_1, $message_id, 'insert-address-token', 137, 106);" |
| 254 | add_sql "insert into addr (_id,msg_id,address,type,charset) values ($id_2, $message_id, '$phone', 151, 106);" |
| 255 | fi |
| 256 | done |
| 257 | fi |
| 258 | done |
| 259 | fi |
| 260 | |
| 261 | # Push to device |
| 262 | if [ $opt_sql_only -eq "0" ]; then |
| 263 | # make sure we have access |
| 264 | adb root |
| 265 | |
| 266 | # Push all local jpgs or gifs to device, being lazy here. |
| 267 | if [ $mms_per_thread -gt "0" ]; then |
| 268 | for file in `ls *.jpg *.gif`; |
| 269 | do |
| 270 | echo "adb push $file $PART_DIR/$file" |
| 271 | adb push $file $PART_DIR/$file |
| 272 | done |
| 273 | fi |
| 274 | |
| 275 | echo "adb push $sql_file /data/fillsms" |
| 276 | adb push $sql_file /data/fillsms |
| 277 | echo |
| 278 | adb_sql ".read /data/fillsms" |
| 279 | echo |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 280 | add_sql "PRAGMA trusted_schema=1;" |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 281 | echo |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 282 | adb_sql_with_quotes "select count(*) from canonical_addresses where _id>=$TABLE_CANONICAL_ADDRESSES_START_ID;" |
| 283 | echo |
| 284 | adb_sql_with_quotes "select count(*) from threads where _id>=$TABLE_THREADS_START_ID;" |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 285 | echo |
| 286 | if [ $sms_per_thread -gt "0" ]; then |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 287 | adb_sql_with_quotes "select count(*) from sms where _id>=$TABLE_SMS_START_ID;" |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 288 | echo |
| 289 | fi |
| 290 | if [ $mms_per_thread -gt "0" ]; then |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 291 | adb_sql_with_quotes "select count(*) from pdu where _id>=$TABLE_SMS_START_ID;" |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 292 | echo |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 293 | adb_sql_with_quotes "select count(*) from part where _id>=$TABLE_SMS_START_ID;" |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 294 | echo |
Sooraj Sasindran | 3586032 | 2023-10-25 15:04:46 -0700 | [diff] [blame] | 295 | adb_sql_with_quotes "select count(*) from addr where _id>=$TABLE_SMS_START_ID;" |
Mike Dodd | d3b009a | 2015-08-11 11:16:59 -0700 | [diff] [blame] | 296 | echo |
| 297 | fi |
| 298 | fi |