作者:徐建祥(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(true, null);
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(false, null);
17 } // Otherwise, we're in the desired state
18 }
3.4 RADIO關掉後(狀態變為RADIO_OFF),再向上發一個EVENT_RADIO_STATE_CHANGED通知,參考3.3。