Android Q 版本开机铃声控制
程序员文章站
2022-03-03 19:22:19
在处理Android Q版本的客户需求时,遇到了一个问题如下:要求在振动或静音模式下禁止播放开机铃声。具体的解决思路并不是很复杂,解决方案如下:path:vendor/mediatek/proprietary/operator/frameworks/bootanimation/MtkBootanimation/BootAnimation.cpp // We have no bootanimation file, so we use the stock android logo...
在处理Android Q版本的客户需求时,遇到了一个问题如下:
要求在振动或静音模式下禁止播放开机铃声。
具体的解决思路并不是很复杂,解决方案如下:
path:vendor/mediatek/proprietary/operator/frameworks/bootanimation/MtkBootanimation/BootAnimation.cpp
// We have no bootanimation file, so we use the stock android logo
// animation.
sp<MediaPlayer> mediaplayer;
- const char* resourcePath = NULL;
+ // Monkey.20200611
+ // const char* resourcePath = NULL;
+ char audio[PROPERTY_VALUE_MAX];
+ property_get("persist.sys.bootanim.play_sound", audio, "1");
+ int index = 0;
+ if (bBootOrShutDown) {
+ index = 0;
+ } else {
+ index = 1;
+ }
+
+ const char* resourcePath = mAudioPath[index][0];
+ if(atoi(audio) == 0){
+ resourcePath = NULL;
+ }
+ //for bootanimation end
+
status_t mediastatus = NO_ERROR;
if (resourcePath != NULL) {
bPlayMP3 = true;
根据系统属性persist.sys.bootanim.play_sound去控制开机铃声是否播放
path:frameworks/base/services/core/java/com/android/server/audio/AudioService.java
int maxSystemVolume = SystemProperties.getInt("ro.config.system_vol_steps", -1);
@@ -4955,6 +4963,17 @@ public class AudioService extends IAudioService.Stub
intent.putExtra(AudioManager.EXTRA_STREAM_VOLUME_MUTED, state);
sendBroadcastToAll(intent);
}
+ // Monkey.20201219 bootanim play sound
+ if (mStreamType == AudioSystem.STREAM_SYSTEM) {
+ if (state) {
+ Log.d("monkey_boot","resourcePath = NULL|"+state+"-|-"+SystemProperties.get("persist.sys.bootanim.play_sound","-1"));
+ SystemProperties.set("persist.sys.bootanim.play_sound", "0");
+ } else {
+ SystemProperties.set("persist.sys.bootanim.play_sound", "1");
+ Log.d("monkey_boot","resourcePath = NULL|"+state+"-|-"+SystemProperties.get("persist.sys.bootanim.play_sound","-1"));
+ }
+ }
+ // end
}
public int getStreamType() {
然后烧录进行验证,问题解决!
注:关于添加开机铃声方式网上很多,这部分就不做记录,我是在vendor下面处理的开机铃声。
本文地址:https://blog.csdn.net/CodingNotes/article/details/111830812