android4.4 重启的开机不播放开机铃声,按power键的开机播放开机铃声
平台:A33
Android4.4
Linux3.4
功能描述:实现重启的开机不播放开机铃声,按power键的开机播放开机铃声
一,无论关机还是重启都会经过rebootOrShutdown这个方法,在方法中通过参数reboot判断是否为重启,否则直接关机。在重启的那部分代码中新建一个文件/data/for_reboot_check.txt并写入"reboot"信息。注:文件创建在/sdcard目录中不合适,因为/sdcard目录是启动后期挂载的,在/system/目录中创建文件没有权限,所以选择在/data/目录中创建
代码路径:android/frameworks/base/services/java/com/android/server/power/ShutdownThread.java
/**
* Do not call this directly. Use {@link #reboot(Context, String, boolean)}
* or {@link #shutdown(Context, boolean)} instead.
*
* @param reboot true to reboot or false to shutdown
* @param reason reason for reboot
*/
public static void rebootOrShutdown(boolean reboot, String reason) {
if (reboot) { //if is reboot create a new file //add by jin,create a new file to store shutdown information
//=======================================================
String filenameTemp;
String path;
FileWriter writer = null; filenameTemp = "/data"+"/for_reboot_check" + ".txt"; //file path
File filename = new File(filenameTemp); Log.i(TAG, "----new file-----");
try{
if(!filename.exists()){
filename.createNewFile(); //create a new file
Log.i(TAG, "------create new file:"+ filenameTemp+"-----\n");
}
writer = new FileWriter(filename, false);
writer.append("reboot"); //write data to file
Log.i(TAG, "------writer data-----\n");
writer.flush(); //flush write cache Log.i(TAG, "flush");
writer.close(); //close writer
}catch(IOException e){
e.printStackTrace();
}finally{
if(null != writer){
}
}
//================================================================================ Log.i(TAG, "Rebooting, reason: " + reason);
try {
PowerManagerService.lowLevelReboot(reason);
} catch (Exception e) {
Log.e(TAG, "Reboot failed, will attempt shutdown instead", e);
}
} else if (SHUTDOWN_VIBRATE_MS > ) {
// vibrate before shutting down
Vibrator vibrator = new SystemVibrator();
try {
vibrator.vibrate(SHUTDOWN_VIBRATE_MS);
} catch (Exception e) {
// Failure to vibrate shouldn't interrupt shutdown. Just log it.
Log.w(TAG, "Failed to vibrate during shutdown.", e);
} // vibrator is asynchronous so we need to wait to avoid shutting down too soon.
try {
Thread.sleep(SHUTDOWN_VIBRATE_MS);
} catch (InterruptedException unused) {
}
}
IWindowManager mWindowManager;
mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
if(mWindowManager != null ){
try{
if(isFreeze==){
mWindowManager.thawRotation();
mWindowManager.updateRotation(true, true);
mWindowManager.setEventDispatching(false);
} }catch (RemoteException e) {
}
}
// Shutdown power
Log.i(TAG, "Performing low-level shutdown...");
PowerManagerService.lowLevelShutdown();
}
二,开机动画和开机铃声是由bootanimation应用实现的,在开机动画播放前读取/data/for_reboot_check.txt文件的内容,判断上次关机是否是重启,如果是重启则不播放开机铃声,
代码路径:android/frameworks/base/cmds/bootanimation/bootanimation_main.cpp
int main(int argc, char** argv)
{
#if 1
//add by jin, for check reboot information
//=======================================================
FILE *file = NULL;
int ret = ;
int flag = ; //用于判断是否是重启
char buf_read[]; file = fopen("/data/for_reboot_check.txt", "rt+");
if(file == NULL){
printf("------file open failed----\n");
//return -1;
}else{
printf("------file open sucess----\n");
ret = fread(buf_read, sizeof(char), , file);
if(ret != )
{
printf("----read failed:ret=%d----\n",ret);
}else{ printf("-----%s----\n", buf_read);
if(strncmp("reboot", buf_read, sizeof("reboot")) == ){
printf("------cmp sucess----\n");
flag = ; //为重启,则flag置1 if(remove("/data/for_reboot_check.txt") ==)
printf("----remove file sucess----"); }else{
//return -1;
}
}
} #endif
//===============================================================
#if defined(HAVE_PTHREADS)
setpriority(PRIO_PROCESS, , ANDROID_PRIORITY_DISPLAY);
#endif char value[PROPERTY_VALUE_MAX];
property_get("debug.sf.nobootanimation", value, "");
int noBootAnimation = atoi(value);
ALOGI_IF(noBootAnimation, "boot animation disabled");
if (!noBootAnimation) {
char cmd[PROPERTY_VALUE_MAX];
property_get("sys.shutdown_animation", cmd, "boot");
const char* url = "/system/media/boot.wav";
if (!strcmp(cmd, "shutdown")) {
url = "/system/media/shutdown.wav";
} sp<ProcessState> proc(ProcessState::self());
ProcessState::self()->startThreadPool(); // create the boot animation object
sp<BootAnimation> boot = new BootAnimation(); //add by jin, flag为0,则为关机后的启动,flag为1,则为重启后的启动
if(flag == ){
boot->playBootMusic(url);
} IPCThreadState::self()->joinThreadPool(); }
return ;
}
推荐博客:
关于关机重启的流程分析:https://blog.csdn.net/lxl584685501/article/details/45747967
android4.4 重启的开机不播放开机铃声,按power键的开机播放开机铃声的更多相关文章
- Linux/CentOS 服务安装/卸载,开机启动chkconfig命令详解|如何让MySQL、Apache开机启动?
		chkconfig chkconfig在命令行操作时会经常用到.它可以方便地设置和查询不同运行级上的系统服务.这个可要好好掌握,用熟练之后,就可以轻轻松松的管理好你的启动服务了. 注:谨记chkcon ... 
- iPhone开机键坏了如何开机
		作死 开机 [苹果手机/iphone开机键坏了怎么开机] 
- Lily_music 网页音乐播放器 -可搜索(附歌词联动播放效果解说)
		博客地址:https://ainyi.com/59 写在前面 这是我今年(2018)年初的小项目,当时也是手贱,不想用别的播放器,想着做一个自己的网页播放器,有个歌曲列表.可关键词搜索.歌词滚动播放的 ... 
- javascript JSMpeg.js 播放视频解决不用全屏也能播放(也支持自动播放哦)
		javascript JSMpeg.js 播放视频解决不用全屏也能播放(也支持自动播放哦) 缺陷就是 因为采用的是 MPEG1解码器 所以清晰度有点低 做直播可以考虑下 如果要清晰度高点 可以采取序列 ... 
- iPhone电源键坏了怎么开机和关机?
		一.开机 1.将USB数据线插到iPhone上,此时先不要将另一头插到电脑上 2.长按Home键不要动 3.将数据线的另一头插到电脑上 这时iPhone就会自动开机 二.关机 1.进入设置找到“通用” ... 
- CentOS7,安装Tomcat8.5、JDK1.8,并设置开机启动(Linux CentOS Tomcat、JDK+Tomcat、Tomcat开机自启动)
		1.下载JDK1.8.Tomcat8 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.ht ... 
- Swift版音乐播放器(简化版),swift音乐播放器
		这几天闲着也是闲着,学习一下Swift的,于是到开源社区Download了个OC版的音乐播放器,练练手,在这里发扬开源精神, 希望对大家有帮助! 这个DEMO里,使用到了 AudioPlayer(对音 ... 
- vue播放video插件vue-video-player实现hls, rtmp播放全过程
		1.安装插件 1 npm install vue-video-player -S 2.配置插件 在main.js里添加 1 import VideoPlayer from 'vue-video-pla ... 
- [工具]利用EasyRTSPClient工具检查摄像机RTSP流不能播放原因以及排查音视频数据无法播放问题
		出现问题 我们在做流媒体开发的过程中,进程会出现摄像机RTSP流莫名其妙无法播放的问题,而我们常用的vlc经常是直接弹出一个无法播放的提示框就完事了,没有说明出错的原因,或者在vlc的消息里面能看到日 ... 
随机推荐
- Linux入门-4 Linux下获取帮助
			help MAN INFO doc help <command> -h或<command> --help whatis <cmd> MAN man <comm ... 
- magento2常见的命令
			常见的命令如下: php bin/magento list 查看所有命令列表 ----------------------------moudule相关的参数------------------ ... 
- 乘风破浪:LeetCode真题_017_Letter Combinations of a Phone Number
			乘风破浪:LeetCode真题_017_Letter Combinations of a Phone Number 一.前言 如何让两个或者多个集合中的随机挑选的元素结合到一起,并且得到所有的可能呢? ... 
- 沉淀,再出发:PHP的简单使用
			沉淀,再出发:PHP的简单使用 一.前言 关于PHP,笔者在本科的时候就听到了太多太多,可惜虽然看了很多的教材,听到了无数遍,也没有系统性的整理过和学习过这方面的知识,这点无论什么时候想起来都是一种遗 ... 
- metasploit 渗透测试笔记(meterpreter篇)
			0x01 背景 meterpreter作为后渗透模块有多种类型,并且命令由核心命令和扩展库命令组成,极大的丰富了攻击方式. 需要说明的是meterpreter在漏洞利用成功后会发送第二阶段的代码和me ... 
- 面向对象的JavaScript --- 原型模式和基于原型继承的JavaScript对象系统
			面向对象的JavaScript --- 原型模式和基于原型继承的JavaScript对象系统 原型模式和基于原型继承的JavaScript对象系统 在 Brendan Eich 为 JavaScrip ... 
- BZOJ2599:[IOI2011]Race(点分治)
			Description 给一棵树,每条边有权.求一条简单路径,权值和等于K,且边的数量最小.N <= 200000, K <= 1000000 Input 第一行 两个整数 n, k 第二 ... 
- [19/04/23-星期二] GOF23_创建型模式(工厂模式、抽象工厂模式)
			一.工厂模式(分为:简单工厂模式.工厂方法模式.抽象工厂模式) 实现了创建者和调用者的分离 核心本质:1.实例化对象,用工厂方法代替new操作:2.将选择实现类.创建对象统一管理和控制,从而将调用者跟 ... 
- jQuery Mobile中jQuery.mobile.changePage方法使用详解
			jQuery.mobile.changePage方法用的还是很多的.作为一个老手,有必要对jQuery mobile中实用方法做一些总结.系列文章请看jQuery Mobile专栏.jquery.mo ... 
- Ubuntu16.04配置单机版Zookeeper和Kafka
			1. 配置zookeeper单机模式 选择的是zookeeper-3.4.10版本,官网下载链接:http://mirrors.hust.edu.cn/apache/zookeeper/stable/ ... 
