当前位置:   article > 正文

android L 关机流程图_pmic halt

pmic halt

下面是简单的流程图,从java到kernel层。





ShutdownThread.java文件

stop playing music,因为后面可能要playing shutdown music.

代码如下:


  1. private static void beginShutdownSequence(Context context) {
  2. ....
  3. //acquire audio focus to make the other apps to stop playing muisc
  4. mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  5. mAudioManager.requestAudioFocus(null,
  6. AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);


show system dialog to indicate phone is shutting down,如果没有关机动画的话,要show一个关机提示出来。

代码如下:


  1. if (!checkAnimationFileExist()) {
  2. // throw up an indeterminate system dialog to indicate radio is
  3. // shutting down.
  4. ProgressDialog pd = new ProgressDialog(context);
  5. pd.setTitle(context.getText(com.android.internal.R.string.power_off));
  6. pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
  7. pd.setIndeterminate(true);
  8. pd.setCancelable(false);
  9. pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
  10. pd.show();
  11. }

Hold the wakelock,make sure we never fall asleep again,抓锁防止机器关机过程中休眠

代码如下:


  1. sInstance.mCpuWakeLock = sInstance.mPowerManager.newWakeLock(
  2. PowerManager.PARTIAL_WAKE_LOCK, TAG + "-cpu");//这个只是锁住cpu不进入休眠,但screen是off的,需full锁来保证screen常亮
  3. sInstance.mCpuWakeLock.setReferenceCounted(false);
  4. sInstance.mCpuWakeLock.acquire();


make sure the screen stays on,再抓一个full锁,防止屏幕半暗

代码如下:

  1. sInstance.mScreenWakeLock = sInstance.mPowerManager.newWakeLock(
  2. PowerManager.FULL_WAKE_LOCK, TAG + "-screen");//保持srceen常亮
  3. sInstance.mScreenWakeLock.setReferenceCounted(false);
  4. sInstance.mScreenWakeLock.acquire();

起一下新进程

sending shutdown broadcast,发出广播,通知各app该保存数据赶紧的,我要关机了

代码如下:

  1. Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
  2. intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
  3. mContext.sendOrderedBroadcastAsUser(intent,//发广播
  4. UserHandle.ALL, null, br, mHandler, 0, null, null);

shutdown activity manager,关闭activity manager,即关闭AppOpsService,UsageStatsService,BatteryStatsService

注意:android L 与KK在关闭UsageStatsService上有所区别

代码如下:

[ActivityManagerService.java]

  1. final IActivityManager am =
  2. ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
  3. if (am != null) {
  4. try {
  5. am.shutdown(MAX_BROADCAST_TIME);
  6. } catch (RemoteException e) {
  7. }
  8. }

shutdown package manager,保存app使用时间到 disk里,这是android L新增的功能。

代码如下:

[PackageManagerService.java]

  1. final PackageManagerService pm = (PackageManagerService)
  2. ServiceManager.getService("package");
  3. if (pm != null) {
  4. pm.shutdown();
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号