Implementation of a preemptive camera service, when some applications (such as flashlights) open camera in the background, when the camera app open camera can be occupied by the background app camera.
1. Modify CameraService.cpp (frameworks/av/services/camera/libcameraservice/)
The Connect () method of the file, which will
The original
Mutex::autolock Lock (Mservicelock);
if (Mclient[cameraid]! = 0) {
Client = Mclient[cameraid].promote ();
if (client! = 0) {
if (cameraclient->asbinder () = = Client->getcameraclient ()->asbinder ()) {
LOG1 ("Cameraservice::connect X (PID%d) (The same client)",
CALLINGPID);
return client;
} else {
ALOGW ("Cameraservice::connect X (PID%d) rejected (existing client).",
CALLINGPID);
return NULL;
}
}
Mclient[cameraid].clear ();
}
Modified to:
if (Mclient[cameraid]! = 0) {
Client = Mclient[cameraid].promote ();
if (client! = 0) {
LOG1 ("Cameraservice::connect X (PID%d) Disconnect the old client", callingpid);
Client->disconnect ();
}
Mclient[cameraid].clear ();
}
Mutex::autolock Lock (Mservicelock);
2. Modify CameraClient.cpp (frameworks/av/services/camera/libcameraservice/)
Disconnect () method of the file:
Will be the original:
if (callingpid! = Mclientpid && callingpid! = mservicepid) {
ALOGW ("Different Client-don ' t disconnect");
Return
}
Modified to:
if (callingpid! = Mclientpid && callingpid! = mservicepid) {
ALOGW ("Different client but preemptive camera service! ");
Return
}
How the Android Jelly Bean version modifies the camera service to a preemptive type