Android version 2.3.5
首先查看Settings里控制开关
// 获取当前状态
boolean ipoSettingEnabled = Settings.System.getInt(getContentResolver(),
Settings.System.IPO_SETTING,1) == 1;
if(mIpoSetting!=null){
mIpoSetting.setChecked(ipoSettingEnabled);
}
//设置新状态
boolean isChecked = ((CheckBoxPreference) preference).isChecked();
Settings.System.putInt(getContentResolver(), Settings.System.IPO_SETTING,
isChecked ? 1:0);
全局搜索 Settings.System.IPO_SETTING ,发现在关机系统里调用了该状态(ShutdownThread.java)
ShutdownThread 里的 checkShutdownFlow 方法
// 判断是否不支持该功能 是否需要重启
if (FeatureOption.MTK_IPO_SUPPORT == false || mReboot == true) {
mShutdownFlow = NORMAL_SHUTDOWN_FLOW; // 更改状态
return;
}
boolean isIPOEnabled;
try {
// 获取当前状态
isIPOEnabled = Settings.System.getInt(sInstance.mContext.getContentResolver(),
Settings.System.IPO_SETTING, 1) == 1;
} catch (NullPointerException ex) {
mShutdownFlow = NORMAL_SHUTDOWN_FLOW;
return;
}
if (isIPOEnabled == true) {
// 判断系统参数
if ("1".equals(SystemProperties.get("sys.ipo.battlow")))
mShutdownFlow = NORMAL_SHUTDOWN_FLOW;
else
mShutdownFlow = IPO_SHUTDOWN_FLOW;
} else {
mShutdownFlow = NORMAL_SHUTDOWN_FLOW;
}
return;
以上函数如果正常进入快速关机模式
mShutdownFlow = IPO_SHUTDOWN_FLOW
关机流程会调用 ShutdownThread.shutdown(mContext, true);
ShutdownThread 里的 shutdown 方法
bConfirmForAnimation = confirm;
if (confirm) {
if (mDialog == null) {
mDialog = new AlertDialog.Builder(context)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(com.android.internal.R.string.power_off)
.setMessage(com.android.internal.R.string.shutdown_confirm)
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//确认关机 检查状态
beginShutdownSequence(context);
if (mDialog != null) {
mDialog = null;
}
}
})
.setNegativeButton(com.android.internal.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
synchronized (sIsStartedGuard) {
sIsStarted = false;
}
if (mDialog != null) {
mDialog = null;
}
}
})
.create();
mDialog.setCancelable(false);
mDialog.getWindow().setType(
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
mDialog.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
if (!mDialog.isShowing()) {
mDialog.show();
}
} else {
beginShutdownSequence(context);
}
ShutdownThread 里的 beginShutdownSequence 方法
if (mShutdownFlow == IPO_SHUTDOWN_FLOW) {
checkShutdownFlow();
synchronized (mShutdownThreadSync) {
mShutdownThreadSync.notify();
}
}
ShutdownThread 里的 run 方法
public void run() {
checkShutdownFlow();
while (mShutdownFlow == IPO_SHUTDOWN_FLOW) {
stMgr.saveStates(mContext);
running();
}
if (mShutdownFlow != IPO_SHUTDOWN_FLOW) {
running();
}
}
adb logcat -s “ShutdownThread”
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
D/ShutdownThread( 189): !!! Request to shutdown !!!
D/ShutdownThread( 189): Notifying thread to start radio shutdown
D/ShutdownThread( 189): PowerOff dialog doesn't exist. Create it first
D/ShutdownThread( 189): ShutdownThread exists already
D/ShutdownThread( 189): checkShutdownFlow: IPO_Support=true mReboot=false
D/ShutdownThread( 189): checkShutdownFlow: isIPOEnabled=true mShutdownFlow=1
D/ShutdownThread( 189): shutdown acquire partial WakeLock 2
I/ShutdownThread( 189): Sending shutdown broadcast...
I/ShutdownThread( 189): Waiting for Bluetooth and Radio...
I/ShutdownThread( 189): Radio and Bluetooth shutdown complete.
I/ShutdownThread( 189): Shutting down MountService
W/ShutdownThread( 189): Result code 0 from MountService.shutdown
I/ShutdownThread( 189): Performing ipo low-level shutdown...
ShutdownManager 里的 saveStates 方法
//保存wifi状态
ShutdownThread 里的 running 方法
//广播全局事件 android.intent.action.ACTION_SHUTDOWN_IPO
//关闭蓝牙
//关闭Radio
//关闭MountService
stMgr.shutdown(mContext);
ShutdownManager 里的 shutdown 方法
mPowerManager = (PowerManager)context.getSystemService("power");
mPowerManager.goToSleep(SystemClock.uptimeMillis());
......
SystemProperties.set("ctl.start", "ipod");
Intent intent = new Intent("android.intent.action.black.mode");
intent.putExtra("_black_mode", true);
context.sendBroadcast(intent);
adb logcat -s “ShutdownManager”
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/ShutdownManager( 189): btState: false
I/ShutdownManager( 189): saveStates: wifi:0, airplaneModeState: 0
V/ShutdownManager( 189): Current Wallpaper = null
V/ShutdownManager( 189): Current IME: com.android.inputmethod.pinyin
I/ShutdownManager( 189): accessibility is disabled
I/ShutdownManager( 189): killProcess (IME): com.android.inputmethod.pinyin
I/ShutdownManager( 189): forceStopPackage: com.cooliris.media
V/ShutdownManager( 189): process = com.android.settings
I/ShutdownManager( 189): forceStopPackage: com.android.settings
I/ShutdownManager( 189): forceStopPackage: com.mediatek.launcherplus
I/ShutdownManager( 189): forceStopPackage: com.android.mms
I/ShutdownManager( 189): forceStopPackage: android.process.media
I/ShutdownManager( 189): forceStopPackage: android.process.media
I/ShutdownManager( 189): forceStopPackage: android.process.media
I/ShutdownManager( 189): forceStopPackage: com.mediatek.moreapp
I/ShutdownManager( 189): forceStopPackage: com.mediatek.omacp
I/ShutdownManager( 189): forceStopPackage: com.android.email
V/ShutdownManager( 189): uid-process = com.mediatek.mdlogger
I/ShutdownManager( 189): forceStopPackage: com.android.providers.calendar
I/ShutdownManager( 189): forceStopPackage: com.android.deskclock
V/ShutdownManager( 189): uid-process = com.android.ActivityNetwork
I/ShutdownManager( 189): forceStopPackage: com.mediatek.weather
ActivityManagerPlus 接收到关机广播
adb logcat -s “ActivityManagerPlus”
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/ActivityManagerPlus( 189): Receive:
Intent { act=android.intent.action.ACTION_SHUTDOWN_IPO }
I/ActivityManagerPlus( 189): finished
I/ActivityManagerPlus( 189): Receive:
Intent { act=android.intent.action.black.mode (has extras) }
I/ActivityManagerPlus( 189): createIPOWin
ActivityManagerPlus 里的 createIPOWin 方法 关机调用
Window win = PolicyManager.makeNewWindow(context);
win.setType(2016);
win.setFlags(1024, 1024);
win.setLayout(-1, -1);
win.requestFeature(1);
android.view.WindowManager.LayoutParams params = win.getAttributes();
params.setTitle("IPOWindow");
params.flags = 24;
WindowManagerImpl wm = (WindowManagerImpl)context.getSystemService("window");
view = win.getDecorView();
wm.addView(view, params);
ActivityManagerPlus 里的 removeIPOWin 方法 开机调用
WindowManagerImpl wm = (WindowManagerImpl)context.getSystemService("window");
wm.removeView(view);
底层实现
mediatek/source/external/ipod/