音效改善的控制类是/alps/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/mediatek/audioprofile文件夹下的SoundEnhancement.java
四个if所判断的返回结果都是removePreference说明音效改善界面是没有东西的,我这样判断其实是不一定的,万一其他版本的安卓源码是可以显示出音效改善界面的,那就让系统自动去判断是否移除声音界面下的音效改善选项。
在/alps/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/sound目录下新增SoundEnhancePreferenceController.java (或者加在/alps/vendor/mediatek/.../mediatek/audioprofile文件夹下也行,知道自己建在哪里就行)
代码如下:
package com.android.settings.sound;
import static android.provider.Settings.Secure.MEDIA_CONTROLS_RESUME;
import android.content.Context;
import android.media.AudioManager;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.mediatek.settings.FeatureOption;
/**
* Parent menu summary of media controls settings
*/
public class SoundEnhancePreferenceController extends BasePreferenceController {
private static final String MTK_AUDENH_SUPPORT_State = "MTK_AUDENH_SUPPORT";
private static final String MTK_AUDENH_SUPPORT_on = "MTK_AUDENH_SUPPORT=true";
private Context mContext;
public SoundEnhancePreferenceController(Context context, String key) {
super(context, key);
mContext = context;
}
@Override
public int getAvailabilityStatus() {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
String mAudenhState = audioManager.getParameters(MTK_AUDENH_SUPPORT_State);
if (mAudenhState.equalsIgnoreCase(MTK_AUDENH_SUPPORT_on)) {
return AVAILABLE;
}
String besLoudnessParam = audioManager.getParameters("MTK_BESLOUDNESS_SUPPORT");
boolean mIsBessLoudnessSupported = !besLoudnessParam.equalsIgnoreCase("MTK_BESLOUDNESS_SUPPORT=false");
if (mIsBessLoudnessSupported) {
return AVAILABLE;
}
if (FeatureOption.MTK_ANC_SUPPORT) {
return AVAILABLE;
}
if (FeatureOption.MTK_HIFI_AUDIO_SUPPORT) {
return AVAILABLE;
}
return UNSUPPORTED_ON_DEVICE;
}
}
控制类写完后,修改/alps/vendor/mediatek/proprietary/packages/apps/MtkSettings/res/xml/sound_settings.xml 在音效改善的Preference里加上settings:controller="(控制类所在的包名路径)"
最后就能够实现自动化判断这个选项显示或不显示了。