平台: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键的开机播放开机铃声的更多相关文章

  1. Linux/CentOS 服务安装/卸载,开机启动chkconfig命令详解|如何让MySQL、Apache开机启动?

    chkconfig chkconfig在命令行操作时会经常用到.它可以方便地设置和查询不同运行级上的系统服务.这个可要好好掌握,用熟练之后,就可以轻轻松松的管理好你的启动服务了. 注:谨记chkcon ...

  2. iPhone开机键坏了如何开机

    作死 开机 [苹果手机/iphone开机键坏了怎么开机]

  3. Lily_music 网页音乐播放器 -可搜索(附歌词联动播放效果解说)

    博客地址:https://ainyi.com/59 写在前面 这是我今年(2018)年初的小项目,当时也是手贱,不想用别的播放器,想着做一个自己的网页播放器,有个歌曲列表.可关键词搜索.歌词滚动播放的 ...

  4. javascript JSMpeg.js 播放视频解决不用全屏也能播放(也支持自动播放哦)

    javascript JSMpeg.js 播放视频解决不用全屏也能播放(也支持自动播放哦) 缺陷就是 因为采用的是 MPEG1解码器 所以清晰度有点低 做直播可以考虑下 如果要清晰度高点 可以采取序列 ...

  5. iPhone电源键坏了怎么开机和关机?

    一.开机 1.将USB数据线插到iPhone上,此时先不要将另一头插到电脑上 2.长按Home键不要动 3.将数据线的另一头插到电脑上 这时iPhone就会自动开机 二.关机 1.进入设置找到“通用” ...

  6. 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 ...

  7. Swift版音乐播放器(简化版),swift音乐播放器

    这几天闲着也是闲着,学习一下Swift的,于是到开源社区Download了个OC版的音乐播放器,练练手,在这里发扬开源精神, 希望对大家有帮助! 这个DEMO里,使用到了 AudioPlayer(对音 ...

  8. 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 ...

  9. [工具]利用EasyRTSPClient工具检查摄像机RTSP流不能播放原因以及排查音视频数据无法播放问题

    出现问题 我们在做流媒体开发的过程中,进程会出现摄像机RTSP流莫名其妙无法播放的问题,而我们常用的vlc经常是直接弹出一个无法播放的提示框就完事了,没有说明出错的原因,或者在vlc的消息里面能看到日 ...

随机推荐

  1. [翻译] SlideInView

    SlideInView This is a quick and lightweight example of how to present a notification like view from ...

  2. kotlin 1.3

    原文:https://www.oschina.net/news/101292/kotlin-1-3-released

  3. Connection to linux server with ORACLE SQL DEVELOPER

    1.Link name is random 2.username and password is database account 3.host name  is ip address  ifconf ...

  4. ASP.NET Core 使用 SQLite 教程,EF SQLite教程,修改模型更新数据库,适合初学者看懂详细、简单教程

    SQLIte 操作方便,简单小巧,这里笔者就不再过多介绍,感兴趣可以到以下博文 https://blog.csdn.net/qq_31930499/article/details/80420246 文 ...

  5. 沉淀再出发:spring boot的理解

    沉淀再出发:spring boot的理解 一.前言 关于spring boot,我们肯定听过了很多遍了,其实最本质的东西就是COC(convention over configuration),将各种 ...

  6. Web Service超限

    问题现状: {System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP respon ...

  7. January 05 2017 Week 1st Thursday

    The true nobility is in being superior to your previous self. 真正的高贵在于超越过去的自己. I will be satisfied if ...

  8. python操作mysql二

    游标 游标是一种能从包括多条数据记录的结果集中每次提取一条记录的机制,游标充当指针的作用,尽管游标能遍历结果中的所有行,但它一次只指向一行,游标的作用就是用于对查询数据库所返回的记录进行遍历,以便进行 ...

  9. BZOJ 1012 最大数maxnumber 线段树

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1012 题目大意: 见链接 思路: 直接用线段树模拟一下就可以了. #include&l ...

  10. concatenate函数

    numpy.concatenate((a1, a2, ...), axis=0) Join a sequence of arrays along an existing axis.(按轴axis连接a ...