Correcting a preemptive camera may lead to deadlock problems

Source: Internet
Author: User

Background:

Implement Seizing - Camera Service when certain applications (such as flashlights) open in the background Camera after, when Cameraapp Open Camera when you can taken possession of by a background application. camera.

Note that this modification destroys the Android of the native Camera Service rules that could lead to some tripartite apk An exception occurred



Problem: Probabilistic deadlock


Analysis:

Close : jni--"cameraclient::d isconnect () {...:

Mutex::autolock Lock (MLock); get lock:mlock----> belongs to a camera app: a process space.

Cameraservice::client::d isconnect ();---"To close the client on the server side

Not yet exited, so Mlock won't be released.

}

Voidcameraservice::removeclientbyremote (const wp<ibinder>& remotebinder) {

int callingpid = Getcallingpid ();

LOG1 ("Cameraservice::removeclientbyremote E (PID%d)", callingpid);

Declare this before the lock to makeabsolutely sure the

Destructor won ' t is called with the Lockheld.

Mutex::autolocklock (mservicelock);----//Get lock:mservicelock----> belong to a camera app process space.

Open : Android_hardware_camera_native_setup ()---"camera::connect----binder----" mediaserver process----" Cameraservice::connect () {

....

Mutex::autolocklock (Mservicelock);//Get lock:mservicelock----> belong to MediaServer process space.

....

}---"Canconnectunsafe ()

{

....

Client->disconnect ();-----> Call Cameraclient::d isconnect () {mutex::autolocklock (mLock);} Also acquires Lock:mlock----> belongs to mediaserver application process space.

Summary : For Mlock and Mservicelock, which means closing the process, they belong to the application process space. Open the process, which belongs to the MediaServer process. therefore, MLock and Mservicelock are likely to deadlock.

For example: A process closes the camera process, runs to Cameraservice::removeclientbyremote () to try to get lock:mservicelock, but process B runs first and tries to open the camera, will run to the mediaserver process and get lock:mservicelock. That is, the MediaServer process first obtains the Mservicelock, then attempts to obtain the mlock, but the a process obtains the Mlock first.


Correcting a preemptive camera may lead to deadlock problems

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.