Android 1.5: 飞行模式分析

作者:徐建祥(netpirate@gmail.com)
日期:2009/11/05
网址:http://www.anymobile.org



1.1 通过com.android.settings.WirelessSettings打开飞行模式;

1.1.1 设置飞行模式值;
Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, enabling ? 1 : 0);

1.1.2 发出Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED)。
AirplaneModeEnabler.setAirplaneModeOn(boolean enabling)

1.2 关闭相关的服务连接

1.2.1 关闭WIFI;
frameworks/base/services/java/com/android/server/WifiService.BroadcastReceiver.onReceive(...)

1.2.2 关闭Bluetooth;
frameworks/base/core/java/android/server/BluetoothDeviceService.BroadcastReceiver.onReceive(...)

1.2.3 关闭RADIO。
PhoneApp.PhoneAppBroadcastReceiver.onReceive(...) -> GSMPhone.setRadioPower(false)->ServiceStateTracker.setRadioPower(false)->ServiceStateTracker.setPowerStateToDesired()->RIL.setRadioPower(true, null)

2/ 取消飞行模式

与打开飞行模式流程类似,false改为true,略。

3/ 飞行模式启动流程

在SIM_READY后,ServiceStateTracker收到RADIO_STATE_CHANGED通知后,关闭RADIO;WIFI和蓝牙部分,则会在对应的服务程序中判断飞行模式设置,如果是飞行模式,则不可用。

下面是RADIO OFF流程:

3.1 正常开机,在RADIO STATE切换到SIM_READY状态后,向上发出EVENT_RADIO_STATE_CHANGED通知;
RADIO.STATE = RADIO_STATE_UNAVAILABLE->RADIO_STATE_OFF->SIM_NOT_READY->SIM_READY
(hardware/ril/reference-ril/reference-ril.c)

3.2 ServiceStateTracker.java初始化,设置mDesiredPowerState = ! (airplaneMode > 0),并调用RIL接口注册EVENT_RADIO_STATE_CHANGED;
frameworks/base/telephony/java/com/android/internal/telephony/gsm/ServiceStateTracker.java

3.3 ServiceStateTracker.java处理RADIO STATE的变化,如果不是飞行模式,设置RADIO状态为ON;如果是飞行模式,且开机状态,则关掉RADIO;

 1     public void handleMessage (Message msg)
 2             case EVENT_RADIO_STATE_CHANGED:
 3                 // This will do nothing in the radio not
 4                 // available case
 5                 setPowerStateToDesired();
 6                 pollState();
 7                 break;
 8     private void setPowerStateToDesired()
 9         if (mDesiredPowerState
10             && cm.getRadioState() == CommandsInterface.RadioState.RADIO_OFF
11         ) {
12             cm.setRadioPower(truenull);
13         } else if (!mDesiredPowerState && cm.getRadioState().isOn()) {
14             dcTracker.cleanConnectionBeforeRadioOff();
15             // If it's on and available and we want it off..
16             cm.setRadioPower(falsenull);
17         } // Otherwise, we're in the desired state
18     }

3.4 RADIO关掉后(状态变为RADIO_OFF),再向上发一个EVENT_RADIO_STATE_CHANGED通知,参考3.3。

posted @ 2011-01-25 20:23  SimonShi  阅读(3512)  评论(1编辑  收藏  举报