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相关推荐

  1. android使用pm降级安装apk,360手机N5线刷降级2.0,屏蔽更新以及pm系统应用教程汇总!!!...

    摘要 看到很多机油在问以上问题,本人也对这些问题感到烦人,特此汇总论一贴教程,希望能帮到大家!1.先刷降级教程就不再多说,请移步官方教程:http://bbs.360.cn/thread-150050 ...

  2. Android 中的 安全模式(safe mode)

    前言 安全模式是安卓系统的一种特殊模式,和WINDOWS的安全模式相似,在安全模式下用户可以轻松地修复手机系统的一些错误,方便快捷.由于第三方应用程序,可能会存在一定的兼容性问题,所以在安装软件后会出 ...

  3. 吴昊品工程级别软件项目 Round 3 —— Mobile Safe(for android)

    以下这一款软件是我在大二的时候 由我,尹达奇,肖晓和曾蔚同学给出的,当时我还不负责编码,只是做一些简单的设计以及软件说明书以及软件文档的写作.如图所示,这是一个和你的手机随时" 互通有无&q ...

  4. Android靶场All Safe wp

    环境准备 ADB DDMS ALLsafe app part 1 不安全的日志记录 挑战 在不反编译的情况下从日志中获取输入的密钥. 方法一 使用DDMS监控日志记录,工具在SDK/tools目录下的 ...

  5. [原创] Android Automotive 车载应用对驾驶模式(Safe Drive Mode)适配的几种方法

    目录 前言 开发环境 1. Android Automotive 和 Android Auto的区别 Android Auto: 2. Android Automotive 的驾驶模式介绍 3. An ...

  6. android intent email,Android Email Intent

    问题 I've set up two buttons. One opens the compose sms intent and the other opens the compose email i ...

  7. 另辟蹊径创建移动应用:iOS和Android代码共享

    2019独角兽企业重金招聘Python工程师标准>>> 过去几年,移动应用席卷了整个世界,在工作和生活的方方面面改变着我们使用互联网的方式.创建移动应用的各种技术也随之兴起,各种开发 ...

  8. 开发Android应用用Kotlin还是Java?

    还记得多年前有关Android与iOS孰优孰劣的辩论吗?如今,Kotlin与Java的争论,时常广泛地发生在开发人员之中.不过,由于大家往往关注的是Java所不具备的Kotlin功能,因此他们的结论可 ...

  9. Android 实用工具Hierarchy Viewer实战

    在Android的SDK工具包中,有很多十分有用的工具,可以帮助程序员开发和测试Android应用程序,大大提高其工作效率.其中的一款叫Hierachy Viewer的可视化调试工具,可以很方便地在开 ...

  10. Binder相关面试总结(一):为什么Android要采用Binder作为IPC机制?

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Nwy9SoNo-1609925310525)(//upload-images.jianshu.io/upload_ima ...

最新文章

  1. Python+OpenCV 图像处理系列(1)— Ubuntu OpenCV安装、图片加载、显示和保存
  2. 控制文字长度,多出的文字用省略号代替
  3. 一次实现可以在某些场合替代菱形继承?
  4. Linux学习之系统编程篇: 阻塞信号集、未决信号集、自定义信号集
  5. DT100pro上手体验
  6. python从小到大的顺序输出_「小白专栏」Python中使用for循环,为什么输出结果不是按顺序?...
  7. @SuppressWarnings(rawtypes) 是什么含义
  8. LeetCode数据库 177. 第N高的薪水
  9. 如何限制浏览器使用_如何使用浪涌电流限制器NTC(一)
  10. AudFree Tidable Music Converter for Mac - 音乐格式转换软件
  11. C#:访问web.config中的常量
  12. 4、EPM ——Smart View介绍和使用
  13. mysql 分页 conut优化_mysql count函数与分页功能极限优化
  14. 2017-9-22 NOIP模拟赛[xxy][数论]
  15. (Emitted value instead of an instance of Error) postcss-viewport-units:
  16. android 本地图片模糊,Android端图片模糊的实现原理及方案
  17. 面向对象编程基本概念
  18. Git常用命令有哪些?
  19. 设编号为1,2,… n的n个人围坐一圈,约定编号为k(1=k=n)的人从1开始报数,数到m 的那个人出列,它的下一位又从1开始报数,数到m的那个人又出列,依次类推,直到所有人出列为止,由此产生一个
  20. 使用cocoscreator接入google AdSence广告

热门文章

  1. Win系统 - 全屏看视频时任务栏没有自动隐藏怎么办?
  2. CR blocks 创建
  3. 计算机ps特效教程,制作木质电脑桌的PS滤镜教程
  4. visual studio 2019 marketplace下载安装vsix插件
  5. 字节跳动面试真题- 整数反转
  6. blender 快捷键
  7. 智能客服搭建(4) - 语音流的分贝计算
  8. Scintilla教程(6): 字符集
  9. PCB检查流程checklist
  10. 炼石:栉风沐雨七载路,不负韶华再出发