平台: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. 变换CALayer锚点实现模拟时钟的动画

    变换CALayer锚点实现模拟时钟的动画 变换锚点得需要一点理论知识,看下图就能明白:). https://developer.apple.com/library/ios/documentation/ ...

  2. 使用Facebook开源代码FBShimmering封装进度显示的ShimmeCircleView

    使用Facebook开源代码FBShimmering封装进度显示的ShimmeCircleView 效果图: 静态图: 源码: ShimmeCircleView.h 与 ShimmeCircleVie ...

  3. FTP自动上传

    注:该脚本上传的压缩文件,通过文件资源管理器拿下来后会提示压缩文件损坏.使用 ftp -s:d:\audit_log\ftp_upload.txt 方法可行(http://www.cnblogs.co ...

  4. Git小抄

    生存必备 分支 忽略已提交的文件 版本回退 撤销修改 删除文件 修改最后一次提交的说明信息 tag 生存必备 git init git add <file1> <file2> ...

  5. 乘风破浪:LeetCode真题_005_Longest Palindromic Substring

    乘风破浪:LeetCode真题_005_Longest Palindromic Substring 一.前言 前面我们已经提到过了一些解题方法,比如递推,逻辑推理,递归等等,其实这些都可以用到动态规划 ...

  6. awk 截取某段时间的日志

    好久没有截取nginx/haproxy 中 的日志了,竟有点不熟悉了. 记录一下,以免以后忘记. NGINX 日志格式: 192.168.1.26 - - [14/Sep/2017:16:48:42 ...

  7. Dictionary<Tkey.TValue>与SortedList

    一.概述 表示Key/Value集合,可以添加删除元素,允许按Key来访问元素.是Hashtable的泛型等效类. 它需要一个相等实现来确定键是否相等,可以使用实现了IEqualityComparer ...

  8. SAP ABAP里数据库表的Storage Parameters从哪里来的

    如何查看ABAP数据库表的storage parameter? 事务码SE11,utilities->Database Object->Database Utility: 点这个Stora ...

  9. PhoneGap的通知

    一.通知类型列表 1.notification.alert         提示警告框 2.notification.confirm                  确认对话框 3.notifica ...

  10. ASP.Net GridView 基础 绑定字段

    通过以前的学习,我们实现了效果如下: 现在我想修改显示/隐藏部分列,有两种做法: 一.在配置数据源的时候不是有查询哪些字段的吗,去除不需要的字段,重新绑定. 二.就是直接编辑列 下面是分析每种字段类型 ...