In-depth explanation of the security of Android processes and processes

Source: Internet
Author: User

If the caller initiates another Android process and the method runs in another thread, this thread is in the same thread pool with the IBinder object, because a service may have multiple client requests, more than one thread pool calls the IBinder method at the same time.

This attribute can be used to run processes by components. This attribute allows you to configure components to run in an independent process, or multiple components to run in the same process. You can even run multiple programs in one process-if these programs share a User ID and give the same permissions. <Application> the Node also contains the process attribute, which is used to set the default process of all components in the program.

All components are used as examples in the Android process of the process. The system calls these components from the main thread. Not every object is separated from the main thread. In general, response methods such as View. onKeyDown () user operation methods and notifications will be discussed later in Component Lifecycles) will also run in the main thread.

This means that the component should not run for a long time or block operations such as network operations or computing a large amount of data when it is called by the system, because it will block other components in the process. This type of operations can be separated from the main thread, and the subsequent Threads and chapters will be reduced. When more commonly used processes cannot obtain enough memory, Android may shut down infrequently used processes. The next time you start the program, a process will be started.

When determining which process needs to be disabled, Android considers which process is more useful to users. For example, Android tends to close a process that is not displayed on the interface for a long time to support a process that is often displayed on the interface. Whether to close a process depends on the status of the Component in the process. For more information, see Component Lifecycles.

Even if different processes are assigned to the component, the Android process sometimes needs to be assigned. For example, the user interface needs to respond quickly to the user, so some time-consuming operations, such as network connection, downloading, or operations that take up a lot of server time, should be placed in other threads.

The Thread is created through the standard java object Thread. android provides many convenient methods to manage Android processes:-Logoff threads run a message loop, Handler transmits a message, and HandlerThread creates a thread with a message loop.

Remote procedure callsAndroid has a lightweight Remote Call (RPCs) mechanism through which methods can be called locally and executed remotely in other processes ), you can also return a value. To achieve this, the method call must break down the method call, and all the data to be passed must be accessible to the operating system. The local process and memory address are transferred to the remote process and memory address and processed and returned remotely.

The return value must be passed in the opposite direction. Android provides the code for the above operations, so developers can focus on implementing RPC interfaces.
One RPC interface can only have one method. All methods are synchronously executed until the remote method returns and the local method stops blocking). This is also true if no return value is returned.

In short, this mechanism is as follows: Use IDL (interface definition language ). define the interface you want to implement. The aidl tool can generate an interface definition for java. This definition must be used both locally and remotely. It contains two classes, see:

The inner class contains all the interfaces used to manage remote programs that comply with the IDL description. All inner classes implement the IBinder interface. One of them is used locally. Regardless of its code, Stub inherits the Binder class. To remotely call the Android process, this class contains the RPC interface. Developers can inherit the Stub class to implement the required methods.

Generally, a remote process is managed by a service because the service can notify the operating system of the process information and communicate with other processes). It also contains the interface file generated by the aidl tool, stub class implements the method in the distance. The service client only needs the interface file generated by the aidl tool.

The following describes how to connect to the service and call the client:

◆ Local service client) implements the onServiceConnected () and onServiceDisconnected () methods. In this way, you can get notifications when the client is connected or disconnected. Obtain the connection to the service through bindService.

◆ The onBind () method of the service can receive or reject connections, depending on the intent it receives (the intent connects to the service through the bindService () method ). if the service receives a connection, a Stub instance is returned.

◆ If the service accepts the connection, Android will call the onServiceConnected () method of the client and pass a Stub-class proxy managed by the Ibinder object system.) through this proxy, the client can connect to a remote service.

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.