AudioManager分析
一、AudioManager类
1、frameworks/base/media/java/android/media/AudioManager.java
该类主要是用于上层应用的API接口与frameworks的逻辑交互工作,这里有很多的功能设置选项;
AudioManager类位于android.Media 包中,该类提供访问控制音量和钤声模式的操作。
通过getSystemService(Context.AUDIO_SERVICE)方法获得AudioManager实例对象。
AudioManager audiomanage = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
audiomanager就是我们定义的控制系统声音的对象。
/**
* AudioManager provides access to volume and ringer mode control.
* <p>
* Use <code>Context.getSystemService(Context.AUDIO_SERVICE)</code> to get
* an instance of this class.
*/
public class AudioManager {
private final Context mContext;
private long mVolumeKeyUpTime;
private final boolean mUseMasterVolume; //从config.xml文件中获取,默认为false
private final boolean mUseVolumeKeySounds;//从config.xml文件中获取,默认为true;
private final boolean mUseFixedVolume; //从config.xml文件中获取,默认为false;
private final Binder mToken = new Binder();//默认还没有用这个对象,
private static String TAG = "AudioManager";
private static final AudioPortEventHandler sAudioPortEventHandler = new AudioPortEventHandler();
2、初始化变量:
/**
* @hide
*/
public AudioManager(Context context) {
mContext = context;
mUseMasterVolume = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_useMasterVolume);
mUseVolumeKeySounds = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_useVolumeKeySounds);
mUseFixedVolume = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_useFixedVolume);
sAudioPortEventHandler.init();
}
private static IAudioService getService()
{
if (sService != null) {
return sService;
}
IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
sService = IAudioService.Stub.asInterface(b);
return sService;
}
3、从配置文件中获取属性值,和初始化对象;同时获取一个IBinder的服务对象;