Android Security (v) preemptive interception of SMS

Source: Internet
Author: User

As in the previous article, only the results are presented here, and the code analysis is given later

Introduction: This article describes how to first in some fake anti-virus software, viruses, conventional software to obtain text messages

Note: If you want to receive a message first, please be sure to read my previous article to ensure that your application starts first

It is well known that the Android system sends a broadcast when it receives a short message, but the broadcast is an orderly broadcast, which means that the person who first receives the broadcast will not pass it back if he is in a bad mood.

This is different from the disorderly broadcast, the disorderly broadcast is not really not the order (just as it seems to be used to call it), the receiver of the disorderly broadcast is queued for broadcast, but in the process of transmission, we must follow the rules, the message to the last person can

The previous article has made it clear that the order in which random broadcasts are paired with static receivers

Because the program does not start running after the boot, so want to automatically run must receive

Now let's take a look at what happened after the program was started, and I took the short message as an example

To receive a message in a program, you should receive the following broadcast

Android.provider.Telephony.SMS_RECEIVED

System to send it as an ordered broadcast, then, who is the first to receive text messages will become critical, whether you are anti-virus software, fake anti-virus software, viruses or ordinary programs

Previously said the order of reception of the static receiver

What about the dynamic receiver versus the static receiver?

If you are receiving a static broadcast

The answer is that the static receiver priority is lower than the dynamic receiver, that is, no matter how high the static receiver and how low-level dynamic receiver all receive the same broadcast, is always a dynamic receiver first received!

The dynamic receiver is set in code, so we need to start the program before we can receive the broadcast, which is why we can't use it to receive the boot broadcast.

If you are receiving dynamic broadcasts

At the same priority, the dynamic receiver receives the broadcast first, and then receives the static

Similarly, a dynamic receiver can set a priority, and a high-priority receiver receives a broadcast before a lower-priority receiver

So what is the order of receiving broadcasts for the same priority dynamic receiver?

Luckily, their rules are different from those of static receivers.

The same priority of the dynamic receiver, who first registered to the system, who will be preemptive to receive the broadcast

Although the above is only a textual narration, but I believe, we also see the understanding of the

Here's a summary of how you can ensure your program gets the message from other programs

1. According to the previous article, to ensure that you start before other programs

2. Start the first thing is to open the service, dynamic registration broadcast, and the priority set to the highest

Code implementation is also very simple

A receiver

Private Dynamicreceiver dynamicreceiver = new 

dynamicreceiver ();  
public class Dynamicreceiver extends Broadcastreceiver {public  
    void OnReceive (context context, Intent Intent) {  
        LOG.E (Smsutil.tag, "dynamic Receiver");  
        String action = Intent.getaction ();  
        if (SmsUtil.SMS_ACTION.equals (ACTION)) {Context.startservice (smsutil.getintent) (context  
            , Mainservice.class, Intent, "Dynamic 

Receiver"));}}  

Dynamic registration

public static final String sms_action = 

"Android.provider.Telephony.SMS_RECEIVED";  
      
Intentfilter intentfilter = new Intentfilter (sms_action);  
Intentfilter.setpriority (integer.max_value);  
Registerreceiver (Dynamicreceiver, Intentfilter);

Finally, the order in which the receiver receives the broadcast

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.