Android Auto-boot Analysis

Source: Internet
Author: User

1.1 Enabling self-booting of the Android system
1.1.1. Implement your own broadcast receiver and implement the logic to be processed in the OnReceive () method




1.1.2. Androidmanifest.xml registers the broadcast receiver, stating that the receiving broadcast filter is boot_completed broadcast



1.1.3. Declaration of authority



Android Self-booting is not very different from general broadcast reception, but there are some areas to be aware of:
1. When using boot_completed broadcasts, you must receive_boot_completed permissions, which is modified after 4.0
2. You can set the priority of the boot_completed broadcast by specifying the precedence property so that the app receives the broadcast before other apps
3. Under 4.4 boot_completed broadcasts are ordered broadcasts, but not interruptible (flag_receiver_no_abort fields specified), and before 4.4, boot_completed broadcast
It's disordered.
4. Because the package stopped flag is added after 4.0, the app in this state cannot receive boot_completed broadcasts when the status is generated by the following conditions:
A. Calling a hidden interface via reflection Forcestoppackage interface Stop Application
B. Disable button in Setting?application?detail, deactivated app
C. New installation complete, never open and running apps

1.2 boot_completed broadcast the time of dispatch to understand the timing of the boot_completed broadcast, you must understand the Android startup process,
Get a quick overview of the Android boot sequence:

1 system boot, bootloader
2 Systemserver
3 AMS
4 Send Systemready Signal
5 Launcher Start
6 Send finishbooting Signal
7 Sending boot_completed broadcasts

1.3 Principle of prohibition of self-primingby understanding the timing and rationale of boot_completed broadcast, we can probably analyze several ways to disable self-booting:
1. Prevent the app from receiving boot_completed broadcasts, after 4.0, can be implemented by setting the app's package stopped flag (reflection calls the hidden Forcestoppackage method)
2. Block boot_completed broadcast by disabling the app's broadcast receiver, that is, set the component's Android:enable property to stop the receiver's response
3. The kill process to end the self-launched app


1.4 Methods of prohibiting self-booting1.4.1 Forcestoppackage
disabling by Forcestoppackage will not only deactivate the app's components, but also stop his timer, etc., and require system privileges and the systems signature.


1.4.2 Disabling Component methods
The Android components in the Android documentation are described below:
the<application> element has it own enabled attribute that applies to allapplication components, including Broadcas T receivers.
That is, we can set whether a component is enabled.
The following two methods are available in Packagemanager:






setapplicationenabledsetting can deactivate all components in the app.
Setcomponentenabledsetting can deactivate the specified component.
There are a few points to note about this approach:
A. Compared to the Forcestoppackage interface, the interface does not empty the timer, etc., only the component is enabled, deactivated, so a custom broadcast is sent in the timer, and the flag_exclude_stopped_packages specified in the broadcast is capable of waking the component.
B. Using the Setcomponentenabledsetting interface must be a system program and have a system signature
C. Need to assert change_component_enabled_state authority
How to use:



Unfortunately, this method can only be modified for its own app, while the operation of the third-party app requires system permissions, even if root is not available, so we need to take advantage of Packagemanager's CMD implementation, the PM command.
command requires root privileges: PM enable/disable package/package.class

1.4.3 Kill Process Method

the most commonly used method is to kill the process through the Killbackgroundprocesses interface in the Activitymanager class, which is the following common code:



However, this method cleans up the process level is not too high, killprocess (PID) is a way to kill higher priority, but this method does not guarantee that the process is killed, because the method is only to emit the kill process signal, whether or not to kill is the The system determines, in general, the process that can be killed as follows:
A. Under-the-package process
B. The same UID process
C. Processes generated by the app at run time

1.5 Find Boot boot permissions apkThere are many ways to find permissions, and here is one, which is implemented by Packagemnager:




1.6 SummaryIn summary , the general self-starting management app in the market, mostly by the use of the PM command after root permission to disable the receiver containing the boot_completed to achieve, and others by monitoring the background process, polling to find the blacklist process to kill the corresponding self- Starting the program, not only to boot, but also to monitor background self-booting, but the biggest problem with this method is to increase the system consumption, including memory consumption and power consumption. There are also some third-party ROM also with rights management tools, such as Xiaomi's rights management system, is to resolve the receiver's permissions, the priority of all receivers will be reduced by 1, so that the priority of other applications will always be lower than the priority of their system apps.
Through the survey found that the user cleanup process, the habit of controlling boot start from windows, process cleanup or control boot Startup items for Android system does not make much sense, if an Android system is not root, then the third-party app The control of the system is basically not, the use of these software, on the one hand to reduce the security of the Android system, on the other hand will also consume a lot of system resources, resulting in a vicious circle, mobile phone use more slowly.







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.