您的位置:首页 > 移动开发 > Android开发

android 系统上做GC双模的--音频通路等相关设计分析 【转】

2013-05-05 23:08 609 查看
转自:http://blog.csdn.net/basonjiang_sz/article/details/6255893?reload

一:通话相关的语音通路切换原理、震动接口

6、语音通路

6.1、设置语音通路的路由

目前我们有两处处理:

a、CallTracker.java中的

handlePollCalls()

检测到+clcc返回的电话列表中有状态为DriverCall.State.ALERTING(表示拨打电话后,对方已经振铃),此时需要设置语音通路为MODE_IN_CALL

b、PhoneUtils.java中setAudioMode()函数

c、调用通路分析

AudioManager audioManager = (AudioManager) context.getSystemService

(Context.AUDIO_SERVICE);

audioManager.setMode(mode);

AudioManager.setMode(mode);

AudioService.setMode(mode);

AudioSystem.setMode(mode);(native function)

android_media_AudioSystem.cpp==>android_media_AudioSystem_setMode()

AudioSystem.cpp==>setMode()

const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();

binder = sm->getService(String16("media.audio_flinger"));

...

gAudioFlinger = interface_cast<IAudioFlinger>(binder);

...

return gAudioFlinger;

通过查找“media.audio_flinger”发现AudioFlinger.cpp==>instantiate()//Main_mediaserver.cpp中被实例化。

defaultServiceManager()->addService(String16("media.audio_flinger"), new AudioFlinger());

mAudioHardware = AudioHardwareInterface::create();

LOGV("Creating Vendor Specific AudioHardware");

hw = createAudioHardware();

return new AudioHardwareMarvell();

return af->setMode(mode);

AudioHardwareLittle.cpp==>setMode(mode)

doRouting();

enable_incall_headphone()//or others...

system("alsactl -f /etc/alsactl/asound.state_none restore");

system("alsactl -f /etc/alsactl/asound.state_headset_r_s restore");

6.2、来电播放振铃,挂断或接听停止振铃。

==>Phone.app

onCreate()

ringer = new Ringer(phone);

Vibrator mVibrator = new Vibrator();

mService = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware"));

notifier = new CallNotifier(this, phone, ringer, mBtHandsfree);

mPhone.registerForIncomingRing(this, PHONE_INCOMING_RING, null);

mPhone.registerForPhoneStateChanged(this, PHONE_STATE_CHANGED, null);

mPhone.registerForDisconnect(this, PHONE_DISCONNECT, null);

...

case PHONE_INCOMING_RING:

mRinger.ring();

mHardwareService.setAttentionLight(true);

mVibratorThread.start();

while (mContinueVibrating) {

mVibrator.vibrate(VIBRATE_LENGTH);

SystemClock.sleep(VIBRATE_LENGTH + PAUSE_LENGTH);

}

...

makeLooper();

mRingHandler.sendEmptyMessage(PLAY_RING_ONCE);

...

case PLAY_RING_ONCE:

PhoneUtils.setAudioMode(mContext, AudioManager.MODE_RINGTONE);

r.play();

...

case PHONE_DISCONNECT:

case PHONE_STATE_CHANGED:

...

mRinger.stopRing();

Message msg = mRingHandler.obtainMessage(STOP_RING);

msg.obj = mRingtone;

mRingHandler.sendMessage(msg);

case STOP_RING:

r.stop();

getLooper().quit();

...

mVibrator.cancel();

二:通话相关的notification服务

7、通话相关的notification服务。

7.1、NotificationMgr

==>PhoneApp.java

onCreate()

NotificationMgr.init(this)//NotificationMgr.java//此类主要负责电话通知的具体表现(通知和取消通知),未接图标、通话中、蓝牙激活中、保持中,静音、免提等。封装了简单的瞬间显示文本消息的功能。提供漫游数据连接禁止的通知封装和漫游数据连接允许时取消通知

sMe = new NotificationMgr(context);

mNotificationMgr = (NotificationManager)

context.getSystemService(Context.NOTIFICATION_SERVICE);

mStatusBar = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE); //主要用于显示静音和speaker状态的图表(在状态条右边显示)

sMe.updateNotifications();//主要功能是:

1、查询是否有未读的未接听电话,并显示到状态栏图标,和通知列表

2、根据是否是电话状态,更新状态栏图表和通知列表(可能是激活,蓝牙,保持等)

7.2、CallNotifier

==>PhoneApp.java

onCreate()

notifier = new CallNotifier(this, phone, ringer, mBtHandsfree);//此类主要是监听通话相关的事件,然后进行例如来电播放铃声,震动。挂断、接听停止振铃等(调用Ringer类实现此功能),根据不同的状态调用调用NotificationMgr进行具体的通知和取消通知。

三: 通话相关的各种server

电话通信相关的服务:
(1)、从ServiceManager得到的:
a、wifiService
b、PhoneInterfaceManager
c、PhoneSubInfo
d、SimPhoneBookInterfaceManager
e、SimSmsInterfaceManager
f、TelephonyRegistry
g、NetStatService
h、ConnectivityService

(2)、从ApplicationContext得到的:
a、TelephonyManager
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐