Android security Issues (iv) preemptive boot

Source: Internet
Author: User

Guide: How do we start the first boot as an example to illustrate the receiving order of static broadcast receivers receiving unordered broadcasts

(Note that the text is only a statement of results, so called the result of the article, and then give the source code analysis)

First, let's start with the broadcast and broadcast receivers in Android.

Broadcast can be divided into orderly, disorderly and sticky altogether three kinds

Broadcast receivers can be divided into two kinds: static and dynamic

First, we need to be clear on two issues.

1. The order in which the receiver receives the broadcast in a disorderly broadcast is ordered

2. The receiver that receives the unordered broadcast can also set the priority

Here is the main point of the static broadcast receivers in multiple applications (with the same priority) receive order of receiving Out-of-order broadcasts

Note: Here the main description of the conclusion, the specific principle of follow-up given

Note: It is important that the static sinks that appear on the same device in this article have the same priority by default.

Let's take the broadcast Android.intent.action.BOOT_COMPLETED as an example, this is a disorderly broadcast

If the application wants to turn on the start, then listen to the broadcast, before the program started, the dynamic broadcast receiver is definitely not available, I believe that we have no questions about this

If received first, then the program will start first, as for the advantages of starting first, I think those who can't wait more than anyone knows

Receive order in the end with what is relevant, to tell the truth, I do not know, but don't rush to shoot me, I am not completely unaware ...

The order of the applications is the same as the parsing application, but what is the order of parsing applications?

The first thing to tell you is that it has nothing to do with your APK file name!

For example, a.apk, b.apk two applications, the result does not guarantee a can than B received first, or b can than a first received

And then tell everyone that this is related to the APK file name!

Yes, but why do you say that?

There are a few steps that a user installs an application

1 Download an application, assuming the download down when this application is called new.apk

2 installation. In general, the user will be in the mobile phone operation, click on the file, and then the system will install the page ... And then we all know. Another case program ape may like to use ADB install-r new.apk

As we all know, third party applications will be stored in the/data/app directory

When the installation is finished, we go here to see, found a serious problem, that is, you can not find a file called new.apk!

So what are you going to find? You will find a file whose name starts with the NEW.APK application package name, and may then follow the "-Number. apk", such as: com.android.test-1.apk

The order of reception is related to this name! So what is the relationship?

When the system is powered on, it will parse the APK in a sequence.

1. First of all, will parse the mobile phone in the/system/framework this directory, the original system, which is below a apk-framework-res.apk

Of course, manufacturers will also add their own content, such as my directory under the com.htc.resources.apk

2. The folders that were then taken into attention were, in order:

/system/app

/vendor/app

/data/app

/drm/app-private

(Code analysis for the next blog)

So what is the order of parsing in each folder?

We'll just look at the/data/app, which is where the user-installed Third-party apps are stored.

This is consistent with the order in which the following code returns results

File File = new file ("/data/app/");  
string[] files = file.list ();

That is, we print the array sequentially, and we know which receiver will receive the broadcast first and which will receive it after (why is this consistent with this result, the next article analyzes)

(Remember: This article defaults to say that these receivers assume the same priority, if the priority is different, of course, high-priority first received)

Now you may have so many questions:

1.string[] Java.io.File.list (), what is the order of the return result of this function?

2. How do I execute the above code?

First answer question 1.

I do not know!

Let's see what Javadoc has to say.

Javadoc writes

There is no guarantee this name strings in the resulting array would appear in any specific order; They are not, in particular, guaranteed to appear in alphabetical order.

It's very clear that they don't give you any guarantees.

It is said that when executed under Windows, the result will be in alphabetical order, unfortunately, Android is Linux

But we can cheat, print the above results, if your own application in the back, change the package name, until you can row to the front, of course, this is not a good way, but I do not have any better way

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.