Android security question (5) preemptive interception of text messages-Result

Source: Internet
Author: User

As in the previous article, only the results are presented here, and code analysis will be provided later.

This article describes how to get text messages before some pseudo anti-virus software, viruses, and conventional software.

Note: If you want to receive text messages first, please read my previous article and ensure that your application is started first.

As we all know, the android system sends a broadcast when it receives a short message, but this broadcast is an ordered broadcast. That is to say, if the broadcast receives a message first, it will not pass the broadcast back if it is in a bad mood, people later will not know that text messages are coming.

This is different from unordered broadcast. unordered broadcast does not really have no order (it seems that everyone is used to it). The unordered broadcast receiver is also waiting in queue for broadcast, but in the transmission process, everyone must follow the rules and always pass the message to the last talent.

The previous article has made it clear about the order of unordered broadcast and static receivers.

Because the program does not start running after it is started, you must receive

Now let's take a look at the situation after the program is started. I will take the receipt of short messages that everyone cares about as an example.

To receive text messages in a program, you need to receive the following broadcasts:

Android. provider. telephony. sms_received

The system sends messages as an ordered broadcast. Then, whoever receives the first text message becomes crucial, whether you are an anti-virus software, pseudo anti-virus software, virus, or common program.

Previously, the receiving sequence of the static receiver was mentioned.

What about Dynamic and Static receivers?

To receive static broadcasts

The answer is that the static receiver has a lower priority than the dynamic receiver. That is to say, no matter how advanced the static receiver and the low-level dynamic receiver receive the same broadcast, the dynamic receiver always receives the same broadcast first!

The dynamic receiver is set in the Code. Therefore, we need to start the program to receive broadcasts. This is why we cannot use it to receive boot broadcasts.

To receive dynamic broadcasts

With the same priority, the dynamic receiver receives the broadcast first, and then receives the broadcast statically.

Similarly, a dynamic receiver can set a priority. A high-priority receiver receives a broadcast before a low-priority receiver.

What is the order in which a dynamic receiver with the same priority receives broadcasts?

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

For a dynamic receiver with the same priority, whoever registers to the system will receive the broadcast first.

Although the above is only a text description, I believe that everyone understands it.

The following is a summary of how to ensure that your program is the first to receive text messages from other programs.

1. Based on the practice in the previous article, ensure that you start the program before other programs.

2. The first thing to start is to enable the Service, dynamically register the broadcast, and set the priority to the highest.

Code implementation is also very simple

One 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 receiver receives the broadcast order.

General principles

A dynamic receiver with the same priority, first registered first received

For static receivers with the same priority, the order of receiving broadcasts is the same as that of string [] java. Io. file. List ().

Ordered Broadcast

Assume that there are five receivers with the following priority:

1. Dynamic A (priority = 1)

2. Dynamic B (priority = 2)

3. Dynamic C (priority = 2)

4. Static D (priority = 1)

5. Static E (priority = 2)

And B is registered before C.

The actual receiving order should be

B c e a d

That is to say,If the priority of the static receiver is higher than that of the dynamic receiver, the static receiver receives the broadcast first (for example, receives the text message)

Non-ordered Broadcast

High-priority dynamic receivers> low-priority dynamic receivers> high-priority static receivers> low-priority static Receivers

Digress before conclusion

Some broadcasts cannot be received using static receivers.

For example, action_screen_on, the system sends this broadcast when the screen is lit.

If you try to register a receiver in manifest to receive the message, it will fail. Why?

Let's see how the system sends this broadcast.

Void com. Android. server. powermanagerservice. initinthread ()

void initInThread() {    ……    mScreenOnIntent = new Intent(Intent.ACTION_SCREEN_ON);    mScreenOnIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);    mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF);    mScreenOffIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);    ……}

They have set intent. flag_receiver_registered_only in intent. Therefore, to receive the message, you must register the broadcast receiver dynamically.

The same is true for action_screen_off.

(This section describes the android security issues. (3) add them to the phishing program)

Description of flag_receiver_registered_only

Public static final int flag_receiver_registered_onlyadded in API Level 1

If set, when sending a broadcast only registered receivers will be called -- no broadcastreceiver components will be launched.

Constant Value: 1073741824 (0x40000000)

Let's see a broadcast, action_battery_changed

The system sends this broadcast when the battery power changes.

Void com. Android. server. batteryservice. sendintent ()

private final void sendIntent() {    //  Pack up the values and broadcast them to everyone    Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY            | Intent.FLAG_RECEIVER_REPLACE_PENDING);    ……}

Therefore, we must dynamically receive

Security issues after Android phone root (1)

Security issues after Android mobile phone root (2)

Security issues after Android mobile phone root (3)

Security issues after Android mobile phone root (4)

Android security question (1) Mute photo and photograph

Android security question (2) program lock

Android security question (3) phishing programs

Android security question (4) preemptive startup-Result

Android security question (5) preemptive interception of text messages-Result

Please do not use the root mobile phone to download software at will, or use any excuse to create any virus!

Repost the following link

My blog address

Http://su1216.iteye.com/

Http://blog.csdn.net/su1216/

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.