linux如何进去recovery模式,Android------recovery 模式启动进入流程

1.  上层应用的设置->隐私权->恢复出厂设置对应的java代码在以下路径文件:

packages/apps/Settings/src/com/android/settings/MasterClear.java

MasterClear:mFinalClickListener()函数会发送一个广播出去:

sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));

2.  这个广播的接收者在收到广播以后会开启一个java服务线程:MasterClearReceiver:RebootThread

frameworks/base/services/java/com/android/server/MasterClearReceiver.java  -- TAG = "MasterClear"

public void onReceive(Context context, Intent intent) {

html

RebootThread mThread =newRebootThread(context, intent);

mThread.start();

}

在线程的run函数中会调用函数:RecoverySystem.rebootWipeUserData(mContext);这个方法是RecoverySystem类的静态方法。

3.  RecoverySystem类定义于文件:frameworks/base/core/java/android/os/RecoverySystem.java   --  TAG = "RecoverySystem"

java

publicclassRecoverySystem {

/** Used to communicate with recovery.  See bootable/recovery/recovery.c. */

privatestaticFile RECOVERY_DIR =newFile("/cache/recovery");

privatestaticFile COMMAND_FILE =newFile(RECOVERY_DIR,"command");

privatestaticFile LOG_FILE =newFile(RECOVERY_DIR,"log");

publicstaticvoidrebootWipeUserData(Context context)

throws IOException {

bootCommand(context, "--wipe_data");

}

privatestaticvoidbootCommand(Context context, String arg) throws IOException {

RECOVERY_DIR.mkdirs();  // In case we need it

COMMAND_FILE.delete();// In case it's not writable

LOG_FILE.delete();

FileWriter command = newFileWriter(COMMAND_FILE);

try{

command.write(arg);  // 往文件/cache/recovery/command中写入recovery ELF的执行参数。

command.write("\n");

} finally {

command.close();

}

// Having written the command file, go ahead and reboot

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

pm.reboot("recovery");// 调用PowerManager类中的reboot方法

thrownewIOException("Reboot failed (no permissions?)");

}

}

4.  PowerManager类定义于文件:frameworks/base/core/java/android/os/PowerManager.java  --  TAG = "PowerManager"

publicclassPowerManager

{

...

publicvoidreboot(String reason)

{

try{

mService.reboot(reason);

} catch(RemoteException e) {

}

}

publicPowerManager(IPowerManager service, Handler handler)

{

mService = service;

mHandler = handler;

}

IPowerManager mService;

Handler mHandler;

}

5.  mService指向的是PowerManagerService类,这个类定义于文件:

linux

frameworks/base/services/java/com/android/server/PowerManagerService.java  --  TAG ="PowerManagerService"

/**

* Reboot the device immediately, passing 'reason' (may be null)

* to the underlying __reboot system call.  Should not return.

*/

publicvoidreboot(String reason)

{

mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);

if(mHandler == null || !ActivityManagerNative.isSystemReady()) {

thrownewIllegalStateException("Too early to call reboot()");

}

final String finalReason = reason;

Runnable runnable = newRunnable() {

publicvoidrun() {

synchronized (this) {

ShutdownThread.reboot(mContext, finalReason, false);

} // 调用ShutdownThread服务中的reboot方法

}

};

// ShutdownThread must run on a looper capable of displaying the UI.

mHandler.post(runnable);

// PowerManage

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值