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