How does the android system disable camera sound in mute mode? (2)

Source: Internet
Author: User

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.

 

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.