赞
踩
下面是简单的流程图,从java到kernel层。
ShutdownThread.java文件
stop playing music,因为后面可能要playing shutdown music.
代码如下:
- private static void beginShutdownSequence(Context context) {
- ....
- //acquire audio focus to make the other apps to stop playing muisc
- mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- mAudioManager.requestAudioFocus(null,
- AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
show system dialog to indicate phone is shutting down,如果没有关机动画的话,要show一个关机提示出来。
代码如下:
- if (!checkAnimationFileExist()) {
- // throw up an indeterminate system dialog to indicate radio is
- // shutting down.
- ProgressDialog pd = new ProgressDialog(context);
- pd.setTitle(context.getText(com.android.internal.R.string.power_off));
- pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
- pd.setIndeterminate(true);
- pd.setCancelable(false);
- pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
-
- pd.show();
- }
代码如下:
- sInstance.mCpuWakeLock = sInstance.mPowerManager.newWakeLock(
- PowerManager.PARTIAL_WAKE_LOCK, TAG + "-cpu");//这个只是锁住cpu不进入休眠,但screen是off的,需full锁来保证screen常亮
- sInstance.mCpuWakeLock.setReferenceCounted(false);
- sInstance.mCpuWakeLock.acquire();
make sure the screen stays on,再抓一个full锁,防止屏幕半暗
代码如下:
- sInstance.mScreenWakeLock = sInstance.mPowerManager.newWakeLock(
- PowerManager.FULL_WAKE_LOCK, TAG + "-screen");//保持srceen常亮
- sInstance.mScreenWakeLock.setReferenceCounted(false);
- sInstance.mScreenWakeLock.acquire();
sending shutdown broadcast,发出广播,通知各app该保存数据赶紧的,我要关机了
代码如下:
- Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
- intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
- mContext.sendOrderedBroadcastAsUser(intent,//发广播
- UserHandle.ALL, null, br, mHandler, 0, null, null);
注意:android L 与KK在关闭UsageStatsService上有所区别
代码如下:
[ActivityManagerService.java]
- final IActivityManager am =
- ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
- if (am != null) {
- try {
- am.shutdown(MAX_BROADCAST_TIME);
- } catch (RemoteException e) {
- }
- }
代码如下:
[PackageManagerService.java]
- final PackageManagerService pm = (PackageManagerService)
- ServiceManager.getService("package");
- if (pm != null) {
- pm.shutdown();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。