android safe mode

转载 2016年05月31日 10:20:48

http://android.stackexchange.com/questions/131188/entering-safe-mode-from-adb-shell

My question is similar to this one, but I don’t necessarily have a powered off device.

How can I enter Android’ safe mode (or make it boot into safe mode the next time) from within my recovery image?

I suppose it is possible to mimic the actions the actual Android system would do when you select safe mode from the reboot menu. However, I don’t even know what selecting safe mode actually causes Android to do with the system.

adb recovery-mode safe-mode
shareimprove this question
asked Dec 10 ‘15 at 12:59

Frederick Nord
1536
add a comment
1 Answer
active oldest votes
up vote
4
down vote
accepted
Note: The solution is tested on Android 4.2.1, 5.0.2 and 5.1.1.

The value for the system property persist.sys.safemode determines whether the phone should boot into safe mode or in normal mode.

When booted into Android OS, provided root access, the value can be changed as

adb shell su -c 'setprop persist.sys.safemode 1'
adb shell su -c 'echo "1" > /data/property/persist.sys.safemode' #alternative 

When booted into a custom recovery, given the data and optionally, system partition are mounted, do

adb shell busybox printf "1" > /data/property/persist.sys.safemode         #works if recovery has Busybox. If Android OS has busybox then system/xbin/busybox would work
adb shell echo "1" > /data/property/persist.sys.safemode                   #alternative
adb shell chmod 600 /data/property/persist.sys.safemode    

#required; changes the permission of file to rw——-, identical to rest of the files under /data/property
It is to be noted that, if you’ve never booted into safe mode since last factory reset, the file persist.sys.safemode wouldn’t be found.

Android resets the content of said file at every reboot, so you need not to worry about getting stuck at safe mode. However, for the purpose of fail-safe requirement, change the value to 0 or empty the file (NULL), should you ever get stuck.

In a nutshell, the property that you set is stored in a file, hence it remains persistent when you shutdown the device. You can see your value inside the file from recovery mode, provided that you’ve not booted into Android again after editing the property. Now, once you begin to boot into Android OS, Android et al reads the file, and based on the content, prepares the safe/ordinary mode for you. After reading the file, it resets the content of the file, so the next time you reboot, it would always be in ordinary mode.

I, in my experiments, noticed that Android would boot into safe mode even if the value is any positive or negative integer or even a decimal value.

I got a good hint from source code of ShutdownThread.java that safe mode requires a system property to be set. However, I reached the final conclusion using a comment by pylerSM and a post from ZiT777.

shareimprove this answer
edited Dec 10 ‘15 at 20:28
answered Dec 10 ‘15 at 19:41

Firelord
9,64482768

You can test this on your own. Set the prop, reboot the device but pull out the battery at OEM logo. Boot into recovery and check the file’s content. Now boot into Android normally but run adb shell getprop | grep persist.sys.safemode or adb shell su -c echo /data/property/persist.sys.safemode continuously during boot animation. You would see that the value changes from 1 to nothing (NULL). // In fact, full restart is not needed to boot into safe mode. Once the prop is set, even a soft reset would boot into safe mode. – Firelord Dec 10 ‘15 at 20:06

相关文章推荐

Android safe mode

作者:YiLi Xie(yili.xie@gmail.com) 日期:2010/04/07 欢迎转载,请注明出处   Android safe mode  • Enter saf...

Android four load mode. Safe

原文链接: http://unknownerror.net/2011-05/android-four-load-mode-safe-7929 Suggest first read the f...

safe_mode 开启后linux下影响

http://www.frostsky.com/2011/11/php-safe-mode-2/ php勿庸置疑是非常强大的服务器端脚本语言,但是强大的功能总是伴随着重大的危险,在这里,你将...

inline hook in user mode ---single thread safe ( test passed in window7 )

风格:为了让国外朋友也能看懂,代码中的注释全部用英文,而分析部分我用中文做详细解释, 如果您不习惯这种表达风格,或者有什么意见,欢迎向我反馈.     前言:本文主要讨论现在网传很广的单线程...

Name node is in safe mode.

[root@master bin]# ./hadoop fs -mkdir /user/hive/warehouse mkdir: org.apache.hadoop.hdfs.server.name...

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE tha

ErrorCode: 1175. You are using safe update mode and you tried to update a table without a WHERE that...

Hadoop 解除 NameNode is in safe mode

运行hadoop程序时,有时候会报以下错误:  org.apache.hadoop.dfs.SafeModeException: Cannot delete /user/hadoop/input. ...

php安全模式 safe_mode

php安全模式:safe_mode=on|off 启用safe_mode指令将对在共享环境中使用PHP时可能有危险的语言特性有所限制。可以将safe_mode是指为布尔值on来启用,或者设置为 off...

php常见面试题之一在php.ini中safe_mode开启之后对于PHP系统函数有什么影响呢?

开启之后,主要会对系统操作、文件、权限设置等方法产生影响,平常项目基本上也用不到这些方法。主要我想还是用来应对webshell吧,减少被人植入webshell所带来的某些安全问题。 http:/...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:android safe mode
举报原因:
原因补充:

(最多只允许输入30个字)