Detailed explanation of sound / size modification and configuration of default system in Android

preface

The sound management system is used to realize the functions of sound input and output, sound control and routing, including volume adjustment of main and various sound sources, sound focus control, sound peripheral detection and status management, sound source input and output strategy management, sound effect playback, track setting and playback, recording setting and startup, etc.

Recently, when making customization requirements, it is necessary to modify the sound of the system notification and disable it, so as to prevent the third-party application from scaring users when sending notifications. Just turn off the notification sound. Let's talk about several methods to turn off the sound and how to modify the system's default sound. Let's share it for your reference and study. I won't say much below. Let's take a look at the detailed introduction together.

This article is based on Android 5.1 code

1、 Directly modify the default sound size of the system layer

Two arrays, one max, are defined at the beginning of the system code frameworks / base / media / Java / Android / media / audioservice.java_ STREAM_ Volume defines the maximum value of various sounds (the maximum value is not 100, so audiomanager.getstreammaxvolume (type) is required to obtain the maximum value of each volume), and then set it.

An array default is also defined_ STREAM_ Volume is the same as max_ STREAM_ The order defined in volume is the same, indicating the default size of various sounds.

This block code is as follows:

If we need to modify the default notification sound, we can change stream_ The value 5 in front of the notification is 0, so the default sound is 0.

2、 Modify the notification sound value in the database

The data of media sound will be stored in the database by default. We know that most of the data are loaded with initialization values in the settingprovider application when the system is started for the first time. Of course, the notification sound is also in it.

The specific code is in frameworks / base / packages / settingsprovider / SRC / COM / Android / providers / settings / databasehelper.java. There is a method loadvolumelevels (DB). This method is where all default sound sizes are loaded. The specific code is as follows:

We found that all default values related to sound are written into the database in loadsetting, so we can start here at settings.system.volume_ In the setting item of notification, we set it to 0, and the default sound of system notification will be 0. Let's take a look at the implementation of audioservice.getdefaultstreamvolume

In fact, it returns the value in the default volume array in the system in scheme 1. Therefore, scheme 1 and scheme 2 are actually one effect

3、 Modify ro.config.notification_ Attribute value of sound

This attribute value means to notify the default music file name. We use the system code build / target / product / full_ Base.mk defines that if we don't want to have a sound, we can change the default value to a non-existent file, and the notification sound will not be played. Of course, we can also use product in MK defined by the customer_ PROPERTY_ Overrides to replicate this property, and specify it as nonexistent or empty, so that no notification sound will sound.

4、 Modify the default sound

The system defaults to many sounds, so we need to modify some default sound effect files in the system. Then we can modify the sound files in the files and folders under frameworks / base / data / sounds. If you change the name, remember to replace the original name with a new name in MK. The function of the following MK is to package all these music files into the files of each module under the system / media / audio. Then, when the system starts up, scan these files and add them to the database. Later, when changing the sound in the setting, directly query these music files from the database for users to choose.

summary

The media of the system is a very heavy and big piece. It's just a little fur here. It's only found when it's used. There's still a lot of work to study if you want to learn systematically.

Well, the above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>