The company needs to add a switch in the camera application to enable or disable the camera sound.
In the previous article, the system mute property is used to solve the problem of mute without camera sound. It is determined by the camera playsound () function (see section 1 ). How to define a property by yourself so that it can have the get permission, the key is to have the set permission.
In fact, the android system has a service used to check the SystemProperty permission, which is hidden in system/core/init/property_service.c.
The specific modification is as follows:
<SPAN style="FONT-SIZE: 18px">/* * Checks permissions for setting system properties. * Returns 1 if uid allowed, 0 otherwise. */ static int check_perms(const char *name, unsigned int uid, unsigned int gid) { int i; if (uid == 0) return 1; if(!strncmp(name, "ro.", 3)) name +=3; //add duanyf for start if (strncmp(name, "ty.camera.", 10) == 0){ return 1; } //add duanyf for end for (i = 0; property_perms[i].prefix; i++) { int tmp; if (strncmp(property_perms[i].prefix, name, strlen(property_perms[i].prefix)) == 0) { if ((uid && property_perms[i].uid == uid) || (gid && property_perms[i].gid == gid)) { return 1; } } } return 0; }</SPAN> /* * Checks permissions for setting system properties. * Returns 1 if uid allowed, 0 otherwise. */static int check_perms(const char *name, unsigned int uid, unsigned int gid){ int i; if (uid == 0) return 1; if(!strncmp(name, "ro.", 3)) name +=3; //add duanyf for start if (strncmp(name, "ty.camera.", 10) == 0){ return 1; } //add duanyf for end for (i = 0; property_perms[i].prefix; i++) { int tmp; if (strncmp(property_perms[i].prefix, name, strlen(property_perms[i].prefix)) == 0) { if ((uid && property_perms[i].uid == uid) || (gid && property_perms[i].gid == gid)) { return 1; } } } return 0;}
Where:
// Add duanyf for start
If (strncmp (name, "ty. camera.", 10) = 0 ){
Return 1;
}
// Add duanyf for end
It is a modification, which is equivalent to opening a backdoor. As long as SystemProperty starting with ty. camera returns 1.
Then, the property is used as the judgment condition in cameraservice. The rest is the modification of the add switch of the Camera App.
Conclusion: This method avoids other unknown problems caused by system permissions required by the set. If the platform does not allow such modification, You have to discuss it with PM.
Of course, it is recommended that you use JNI and binder to pass to the cameraservice system to modify the native upper layer and framework interaction mode. This method can also be used and I have already tried it. However, the method described above is relatively simple and the code is slightly modified.