Linux mobile phone DIY. Shell application extension 1. Random incoming ringtone (e680 Series)

Source: Internet
Author: User

Linux mobile phone DIY. Shell application extension 1. Random incoming ringtone (e680 Series)

Papayas

2007-03-18

I. What is shell?

Before getting started, I always used to copy some stuff from the Internet to "enrich" the content of the article.
Shell is a program with special functions. It is between the user and the Unix/Linux operating system core.
An interface between the core program (kernel. In other words, if you want to operate Unix/Linux,
It needs to be done through shell.
Why do we say shell is an intermediary between the core program of the system and the user? Read operation
Readers who are introducing the system know that the operating system is a manager and distributor of system resources.
The request must be submitted to the system. From the operating system perspective, it must also prevent users from performing wrong operations.
And cause system damage. As we all know, commands in computer systems must pass through predefined commands or programs.
Shell itself is a program, a program that has been written and compiled by others.
Slave READ command, convert it to a machine code that can be understood by the computer operating system, and then execute.
Various operating systems actually have their own shells. Taking dos, which is easy to understand as an example, its shell
Is the command.com file. In Windows, the doscommand Dir, copy, and so on are all executed through its interpretation.
.

There are also a variety of shells in Unix/Linux systems. Frequently used: Bourne shell (SH) and C-shell
(CSH), KoRn shell (Ksh), And Bourne again shell (BASH ).
Bourne shell (SH) is developed by Steven Bourne Of The at&t Bell lab for at&t UNIX,
It is the default shell of UNIX and also the development basis of other shells. Bourne shell is equivalent
Excellent, but not as good as several other shells in dealing with user interactions.
C shell (CSH) is developed for bsd unix by Bill Joy of Berkeley University. Unlike SH, it
The syntax is very similar to the C language. It provides user interaction features that the Bourne shell cannot process, such as commands
Completion, command alias, historical command replacement, etc. However, C shell and bourneshell are not compatible.
The Korn shell (Ksh) is developed by David Korn of the at&t Bell lab and integrates the C Shell
And the advantages of the Bourne shell, and is fully compatible with the Bourne shell. Korn shell is very efficient.
High, its command interaction interface and programming interaction interface are good.
Bourne again shell (BASH) is a shell developed by the Free Software Foundation (GNU). It is a Linux
A default shell in the system. Bash is not only compatible with the Bourne shell, but also inherits C shell and Korn
Shell and many other advantages.

<Linux phone DIY series: http://blog.csdn.net/liwei_cmg/category/241839.aspx>

II. General idea of random incoming calls

The random bell call has long been implemented, and there are many methods. The specific purpose of this item is
The benevolent sees benevolence, the wise sees wisdom. I personally think it is good to use it occasionally. The important thing is to explore shell extension mobile phones.
Application potential. In addition, shell is easier to get started for most people and has a lot of related information. Xia Xin
The installation packages of e600 and Philips 968 are implemented through some simple shell. It can be said that studying these mobile phones
The most important part is shell!

Currently, most Linux smart phones use the text format for ringtone configuration. It can be seen that the parameter is directly modified theoretically.
This type of file allows you to easily change short messages and ringtones. However, during actual operations
If you modify the file, the e680 cannot take effect immediately. You need to reset the refresh settings.
After some attempts, we found that setting the configuration file of the Bell tone is the most effective.

Alertringtone1 =/MMC/mmca1/music/ring/ring.pdf
Alertringtone2 =/MMC/mmca1/music/ring/ring.pdf
Alertringerids = 0
Alertstyleicondir =/usr/Language/alertstyle/
Alertsystemvolume = 10
Alerttextmsg =/MMC/mmca1/music/ring/message.mp3

[Alerttextmsg] corresponds to the short message ringtone, and [alertringtone1] corresponds to the incoming call ringtone. This configuration text
I will not change the file. The actual file of ring.mp3, message.mp3 is modified in the dynamic state. The modification process is only
MV artist.mp3 ring.pdf is so simple.

The following two problems need to be solved: the modification time and the instant. I am here obviously a constant stream in the background
When a short message or call is sent, the system starts the alterprocss process.
The process information that can be detected and the corresponding ringtone file can be modified. As for randomness, in fact, the caller Base
Body is a random event. Here we only use a pseudo-random method, that is, the ringtone file is carried out based on the call time information.
Select.

Iii. full content of the script file

001 #! /Bin/bash
002
003
004 # current path
005 path_current =/MMC/mmca1/soft/Ring
006
007 # log files
008 file_log = $ path_current/log.txt
009
010 # ringtone catalog
011 if [! -F $ path_current/ring.txt]
012 then
013 echo/MMC/mmca1/music/Game> $ path_current/ring.txt
014 fi
015 path_ring = 'cat $ path_current/ring.txt'
016
017 # text message ringtone directory
018 if [! -F $ path_current/msg.txt]
019 then
020 echo/MMC/mmca1/music/Game> $ path_current/msg.txt
021 fi
022 path_message = 'cat $ path_current/msg.txt'
023
024 # fixed call message file directory
025 If [! -F $ path_current/default.txt]
026 then
027 echo/MMC/mmca1/music/ring> $ path_current/default.txt
028 isreset = 1
029 else
030 isreset = 0
031 fi
032 path_default = 'cat $ path_current/default.txt'
033
034
035 # maximum number of seconds for the system pre-defined SMS
036 if [! -F $ path_current/maxmessage.txt]
037 then
038 echo "15"> $ path_current/maxmessage.txt
039 fi
040 var_msgmaxsecond = 'cat $ path_current/maxmessage.txt'
041
042 # specified short message ringtone
043 default_messagefile = $ path_default/message.mp3
044 # specified phone ringtone
045 default_ringfile = $ path_default/ring.pdf
046
047
048 # Instruction Set
049 file_busybox =/MMC/mmca1/tmp/busybox
050 # Temporarily process the configuration file
051 file_sed = $ path_current/tmpsed.txt
052 # Loud temporary file
053 file_tmpringpattern = $ path_current/tmpringpattern. PTs
054 # moderate voice of temporary files
055 file_tmpringsoft = $ path_current/tmpringsoft. PTs
056
057 # temporary process File
058 file_tmpprocess = $ path_current/tmpgrep.txt
059
060
061 # temporary list of randomly available files
062 filelist_tmp1_filelist.txt
063
064 # Loud configuration file
065 file_ringrules =/ezxlocal/download/appwrite/Setup/ringrules. PTs
066 # configuration files that are soft in the system
067 file_ringsoft =/ezxlocal/download/appwrite/Setup/ringsoft. PTs
068
069
070 echo "===== random ring ======"> $ file_log
071 echo '$ file_busybox date' ": Start"> $ file_log
072
073
074 if ["$ isreset" = "1"]
075 then
076
077 echo '$ file_busybox date' ": Create New ptsfile"> $ file_log
078
079 # generate a new configuration file
080 echo "#! /Bin/sed-F "> $ file_sed
081 echo "/alertringtone1/C //" >$ file_sed
082 echo "alertringtone1 = $ default_ringfile"> $ file_sed
083 echo "/alertringtone2/C //" >$ file_sed
084 echo "alertringtone2 = $ default_ringfile"> $ file_sed
085 echo "/alerttextmsg/C //" >$ file_sed
086 echo "alerttextmsg = $ default_messagefile"> $ file_sed
087
088 # echo $ file_sed "" $ file_ring.pdf
089 $ file_sed $ file_ring.pdf> $ file_tmpring.pdf
090 $ file_sed $ file_ringsoft> $ file_tmpringsoft
091
092 CP-F $ file_tmpring1_$ file_ring1 _
093 CP-F $ file_tmpringsoft $ file_ringsoft
094
095 fi
096
097 # $ file_busybox renice-20 $
098 echo $> $ path_current/proc.txt
099
100 echo '$ file_busybox date' ": processid" $ >>$ file_log
101
102 while
103
104 do
105
106 procid_alert = 'pidof alertprocess'
107
108 if ["$ procid_alert" = ""]
109 then
110
111 echo "runing ..."
112 sleep 1 s
113
114 else
115
116 echo '$ file_busybox date' ": alertprocessid" $ procid_alert >>$ file_log
117
118 PS-Ef | grep ". MP3" | grep-V grep> $ file_tmpprocess
119
120 If grep "ring1_" $ file_tmpprocess | grep-V grep
121 then
122 havesession = "phone"
123 echo '$ file_busybox date' ": have phone" >>$ file_log
124 fi
125
126 If grep "message.mp3" $ file_tmpprocess | grep-V grep
127 then
128 havesession = "message"
129 echo '$ file_busybox date' ": Have message"> $ file_log
130 fi
131
132 # cyclic Variables
133 I = 0
134
135 while [! "$ Procid_alert" = ""]
136 do
137 procid_alert = 'pidof alertprocess'
138 sleep 1 s
139 # echo "sleep now! "
140
141 If ["$ havesession" = "message"]
142 then
143 If ["$ I" = "$ var_msgmaxsecond"]
144 then
145 kill-9 'pidof alertprocess'
146 else
147 I = $ ($ I + 1 ))
148 fi
149 fi
150
151 done
152
153 value_base = '$ file_busybox date-U' + % m % s''
154
155 # echo "OK"
156
157 if ["$ havesession" = "phone"]
158 then
159
160 # handle random incoming calls
161 CD $ path_ring
162 RM $ filelist_tmp
163 find.-Name '* [M, m] [p, p] 3' | SED's/^. // G'> $ filelist_tmp
164 max_count = '$ file_busybox WC $ filelist_tmp | $ file_busybox awk' {print $1 }''
165 value_round =$ ($ value_base % $ max_count + 1 ))
166
167 # echo $ value_round
168
169 name_nextring = 'sed-n "$ value_round P" $ path_ring/$ filelist_tmp'
170 RM $ filelist_tmp
171
172 if [-F $ default_ringfile]
173 then
174
175 if [-F $ path_current/prering.txt]
176 then
177 # echo
178 mV "$ default_ringfile" "'cat $ path_current/prering.txt '"
179 echo '$ file_busybox date' ": MV $ default_ringfile" "'cat $ path_current/prering.txt '"> $ file_log
180 else
181 RM "$ default_ringfile"
182 echo '$ file_busybox date' ": Rm $ default_ringfile" >>$ file_log
183 fi
184
185 fi
186
187 # echo
188 mv "$ path_ring $ name_nextring" "$ default_ringfile"
189 echo $ path_ring $ name_nextring> $ path_current/prering.txt
190 echo '$ file_busybox date' ": MV $ path_ring $ name_nextring" "$ default_ringfile" >>> $ file_log
191
192 fi
193
194 If ["$ havesession" = "message"]
195 then
196
197 # process random messages
198 CD $ path_message
199 RM $ filelist_tmp
200 find.-Name '* [M, m] [p, p] 3' | SED's/^. // G'> $ filelist_tmp
201 max_count = '$ file_busybox WC $ filelist_tmp | $ file_busybox awk' {print $1 }''
202 value_round =$ ($ value_base % $ max_count + 1 ))
203
204 # echo $ value_round
205
206 name_nextmessage = 'sed-n "$ value_round P" $ path_message/$ filelist_tmp'
207 RM $ filelist_tmp
208
209
210 if [-F $ default_messagefile]
211 then
212
213 If [-F $ path_current/premsg.txt]
214 then
215 # echo
216 mv "$ default_messagefile" "'cat $ path_current/premsg.txt '"
217 echo '$ file_busybox date' ": MV $ default_messagefile" "'cat $ path_current/premsg.txt '"> $ file_log
218 else
219 RM "$ default_messagefile"
220 echo '$ file_busybox date' ": Rm $ default_messagefile" >>$ file_log
221 fi
222
223 fi
224
225 # echo
226 mv "$ path_message $ name_nextmessage" "$ default_messagefile"
227 echo $ path_message $ name_nextmessage> $ path_current/premsg.txt
228 echo '$ file_busybox date' ": MV $ path_message $ name_nextmessage" "$ default_messagefile" >>$ file_log
229
230
231 # Kill-9 'pidof alertprocess'
232 # cp-F $ path_ring/$ name_nextring
233
234 fi
235
236
237 sleep 1 s
238
239 fi
240
241
242 done

Iv. Script File description

Although this script is a bit annotated, it is still a bit messy at first glance. Here are some supplements.

The script is mainly divided into two parts: "variable definition and preprocessing" <001-100> "Main Loop" <101-242>.

A. "variable definition and preprocessing"

This script is named randomly, but the storage path must be the same as the path defined in <005>. (Note:
It can be replaced by 'pwd .)
After the script is run, the following file is generated in the current path:

Log.txt record the entire running log

Ring.txt records the directories randomly selected by the incoming call. The current script will contain all the sub-accounts of this directory.
Directory

Msg.txt records the directory selected immediately after the short message tone, as shown in the preceding figure.

Default.txt records the directory of the fixed file for incoming calls,

Maxmessage.txt records the maximum alert time of a text message.

In addition, some temporary TMP files are generated.


B. "Main Loop"

The system always executes the <106> statement. After some attempts, pidof is the most efficient,
Otherwise, the overall system speed will be slightly slowed down once shell is started in the background.
After the shell process runs, once a call is made, the following content is automatically executed, <114>-<118>
Extract process information and determine whether it is short messages or incoming calls. <132>-<151> special handling of text messages,
If the maximum ringing time is exceeded, the ring will be terminated.
<157>-<234> is the real processing of the ringtone file. That is, the file MV is stored for each incoming call.
The randomness of the next ring.
This script mainly uses busybox, because the original functions of the system are relatively limited.


V. Postscript

The commands involved in this script are very common: PS, sed, find, grep, date, etc. Note that
The e680 uses Bash. For the value expression of $ (), other shells are not universal.
For new Linux mobile phones, it only requires patience to digest the shell commands used by the script.
And shell specifications.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.