linux如何进去recovery模式,Android
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
linux如何进去recovery模式,Android
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