当前位置: 首页 > news >正文

MTK平台关机流程和原因(二)

(1)ShutdownThread

从上一篇可以看到,最终会调用此类的shutdown以及reboot等函数,我们来看一下这些函数的实现。

(A)被调用函数

//frameworks/base/services/core/java/com/android/server/power/ShutdownThread.javapublic static void shutdown(final Context context, String reason, boolean confirm) {mReboot = false;mRebootSafeMode = false;mReason = reason;shutdownInner(context, confirm);}public static void reboot(final Context context, String reason, boolean confirm) {mReboot = true;mRebootSafeMode = false;mRebootHasProgressBar = false;mReason = reason;shutdownInner(context, confirm);}public static void rebootSafeMode(final Context context, boolean confirm) {UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);if (um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {return;}mReboot = true;mRebootSafeMode = true;mRebootHasProgressBar = false;mReason = null;shutdownInner(context, confirm);}public static void rebootOrShutdown(final Context context, boolean reboot, String reason) {if (reboot) {Log.i(TAG, "Rebooting, reason: " + reason);PowerManagerService.lowLevelReboot(reason);Log.e(TAG, "Reboot failed, will attempt shutdown instead");reason = null;} else if (SHUTDOWN_VIBRATE_MS > 0 && context != null) {// vibrate before shutting downVibrator vibrator = new SystemVibrator(context);try {vibrator.vibrate(SHUTDOWN_VIBRATE_MS, VIBRATION_ATTRIBUTES);} 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) {}}///M: added for shutdown Enhancement@{sInstance.mLowLevelShutdownSeq(context);/// @}// Shutdown powerLog.i(TAG, "Performing low-level shutdown...");PowerManagerService.lowLevelShutdown(reason);}

(B)shutdownInner函数实现

接下来看一下shutdownInner内部实现。

private static void shutdownInner(final Context context, boolean confirm) {// ShutdownThread is called from many places, so best to verify here that the context passed// in is themed.context.assertRuntimeOverlayThemable();//xinghui add.avoid shutdown when monkey test.if (ActivityManager.isUserAMonkey()) {Log.d(TAG, "Cannot request to shutdown when Monkey is running, returning.");return;}final int longPressBehavior = context.getResources().getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior);final int resourceId = mRebootSafeMode? com.android.internal.R.string.reboot_safemode_confirm: (longPressBehavior == 2? com.android.internal.R.string.shutdown_confirm_question: com.android.internal.R.string.shutdown_confirm);Log.d(TAG, "Notifying thread to start shutdown longPressBehavior=" + longPressBehavior);if (confirm) {final CloseDialogReceiver closer = new CloseDialogReceiver(context);if (sConfirmDialog != null) {sConfirmDialog.dismiss();}sConfirmDialog = new AlertDialog.Builder(context).setTitle(mRebootSafeMode? com.android.internal.R.string.reboot_safemode_title: com.android.internal.R.string.power_off).setMessage(resourceId).setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {beginShutdownSequence(context);}}).setNegativeButton(com.android.internal.R.string.no, null).create();if (mReboot && !mRebootSafeMode) {sConfirmDialog.setTitle(com.android.internal.R.string.global_action_restart);sConfirmDialog.setMessage(context.getText(com.android.internal.R.string.reboot_confirm_question));}closer.dialog = sConfirmDialog;sConfirmDialog.setOnDismissListener(closer);sConfirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);sConfirmDialog.show();} else {beginShutdownSequence(context);}}

由于这段代码融合了phone,TV,tablet等平台,所以字符串有不同的区分。

<string name="shutdown_confirm" product="tablet" msgid="2872769463279602432">"您的平板电脑会关闭。"</string>
<string name="shutdown_confirm" product="tv" msgid="7975942887313518330">"您的 Android TV 设备将关闭。"</string>
<string name="shutdown_confirm" product="watch" msgid="2977299851200240146">"您的手表即将关机。"</string>
<string name="shutdown_confirm" product="default" msgid="136816458966692315">"您的手机将会关机。"</string>
<string name="shutdown_confirm_question" msgid="796151167261608447">"您要关机吗?"</string>

而具体是如何区分phone,TV,tablet等平台的,因为会根据系统的如下属性。

PRODUCT_CHARACTERISTICS := nosdcard
PRODUCT_CHARACTERISTICS := tvifndef PRODUCT_CHARACTERISTICSTARGET_AAPT_CHARACTERISTICS := defaultelseTARGET_AAPT_CHARACTERISTICS := $(PRODUCT_CHARACTERISTICS)endifADDITIONAL_PRODUCT_PROPERTIES += ro.build.characteristics=$(TARGET_AAPT_CHARACTERISTICS)

将TARGET_AAPT_CHARACTERISTICS的值赋予ro.build.characteristics,而这个属性在Android编译完成后最终写入到/system目录下的build.prop文件。

(C)MTK重载的部分关机流程函数

这里要提一下,MTK平台有自定义部分关机流程函数,我们可以同步了解一下。

public class ShutdownThread extends Thread {protected boolean mIsShowShutdownSysui() {return true;}protected boolean mIsShowShutdownDialog(Context c) {return true;}//add by fenghuan for 开关机动画 endprotected boolean mStartShutdownSeq(Context c, boolean IsReboot) {return true;}protected void mShutdownSeqFinish(Context c) {return;}protected void mLowLevelShutdownSeq(Context c) {return;}
}

(D)beginShutdownSequence函数实现

private static void beginShutdownSequence(Context context) {synchronized (sIsStartedGuard) {if (sIsStarted) {Log.d(TAG, "Shutdown sequence already running, returning.");return;}sIsStarted = true;}sInstance.mProgressDialog = showShutdownDialog(context);sInstance.mContext = context;sInstance.mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);//...// start the thread that initiates shutdownsInstance.mHandler = new Handler() {};///M: added for Shutdown Enhancement @{if(sInstance.mStartShutdownSeq(context, mReboot)) {sInstance.start();}}

(2)MtkShutdownThread

//vendor/mediatek/proprietary/frameworks/base/services/core/java/com/mediatek/server/MtkShutdownThread.javapublic class MtkShutdownThread extends ShutdownThread {@Overrideprotected boolean mIsShowShutdownSysui() {//...return true;}@Overrideprotected boolean mIsShowShutdownDialog(Context context) {//...return true;}@Overrideprotected boolean mStartShutdownSeq(Context context, boolean isReboot) {//...return true;}@Overrideprotected void mShutdownSeqFinish(Context context) {//...}@Overrideprotected void mLowLevelShutdownSeq(Context context) {//...}
}

(3)关机Log分析

大致关机Log如下:

03-30 07:48:25.865  1342  1342 D ShutdownThread: Notifying thread to start shutdown longPressBehavior=1
03-30 07:48:27.303  1342  1342 D ShutdownThread: Attempting to use SysUI shutdown UI
03-30 07:48:27.303  1342  1342 D ShutdownThread: SysUI handling shutdown UI03-30 07:48:27.311  1342  1342 I MtkShutdownThread: hct screen turn off time shutdown_animation_play_time =6000
03-30 07:48:27.312  1342  1342 I MtkShutdownThread: screen turn off time screenTurnOffTime =600003-30 07:48:27.321  1342  7625 I ShutdownThread: Sending shutdown broadcast...
03-30 07:48:27.554  1342  7625 I ShutdownThread: Shutting down activity manager...
03-30 07:48:27.842  1342  7625 I ShutdownThread: Shutting down package manager...
03-30 07:48:27.888  1342  7630 W ShutdownThread: Turning off cellular radios...
03-30 07:48:27.902  1342  7630 I ShutdownThread: Waiting for Radio...
03-30 07:48:28.413  1342  7630 I ShutdownThread: Radio turned off.
03-30 07:48:28.414  1342  7630 I ShutdownThread: Radio shutdown complete.03-30 07:48:28.415  1342  7625 I MtkShutdownThread: mShutOffAnimation: 103-30 07:48:28.418  1342  7625 I ShutdownThread: rebootOrShutdown:goToSleep
03-30 07:48:28.918  1342  7625 I ShutdownThread: Rebooting, reason: user requested

在boot_normal中可以看到开机原因。

//adb reboot
bootstat: Canonical boot reason: reboot,shell
bootstat: Last reboot reason read from /metadata/bootstat/persist.sys.boot.reason : reboot,shell. Last reboot reason read from persist.sys.boot.reason : reboot,shell
bootstat: Normalized last reboot reason : reboot,shell//adb reboot -p
bootstat: Canonical boot reason: cold,powerkey
bootstat: Last reboot reason read from /metadata/bootstat/persist.sys.boot.reason : shutdown,shell. Last reboot reason read from persist.sys.boot.reason : shutdown,shell
bootstat: Normalized last reboot reason : shutdown,shell//power键关机
bootstat: Canonical boot reason: cold,powerkey
bootstat: Last reboot reason read from /metadata/bootstat/persist.sys.boot.reason : shutdown,userrequested. Last reboot reason read from persist.sys.boot.reason : shutdown,userrequested
bootstat: Normalized last reboot reason : shutdown,userrequested//power键重启
bootstat: Canonical boot reason: reboot,userrequested
bootstat: Last reboot reason read from /metadata/bootstat/persist.sys.boot.reason : reboot,userrequested. Last reboot reason read from persist.sys.boot.reason : reboot,userrequested
bootstat: Normalized last reboot reason : reboot,userrequested

相关文章:

MTK平台关机流程和原因(二)

&#xff08;1&#xff09;ShutdownThread 从上一篇可以看到&#xff0c;最终会调用此类的shutdown以及reboot等函数&#xff0c;我们来看一下这些函数的实现。 &#xff08;A&#xff09;被调用函数 //frameworks/base/services/core/java/com/android/server/power/Shutdo…...

【Python】pyqt6入门到入土系列,非常详细...

前言 嗨喽&#xff0c;大家好呀~这里是爱看美女的茜茜呐 一、什么是PyQt6? 简单介绍一下PyQt6 1、基础简介 PyQt6 Digia 公司的 Qt 程序的 Python 中间件。Qt库是最强大的GUI库之一。 PyQt6的官网&#xff1a;www.riverbankcomputing.co.uk/news。 PyQt6是由Riverbank Co…...

TCP socket编程

一、服务端代码 #encoding utf -8 #导入socket库 from socket import * #等待客户端来连接&#xff0c;主机地址为0.0.0.0表示绑定本机所有网络接口ip地址 IP 0.0.0.0 #端口号 PORT 50000 #定义一次从socket缓存区最多读入512个字节数据 BUFLEN 512 #实例化一个socket编程…...

HTTP——一、了解Web及网络基础

HTTP 一、使用HTTP协议访问Web二、HTTP的诞生1、为知识共享而规划Web2、Web成长时代3、驻足不前的HTTP 三、网络基础TCP/IP1、TCP/IP协议族2、TCP/IP的分层管理3、TCP/IP 通信传输流 四、与HTTP关系密切的协议&#xff1a;IP、TCP和DNS1、负责传输的 IP 协议2、确保可靠性的TCP…...

[论文笔记] chatgpt系列 2.6 DeepSpeed-chat 数据集

一、FT数据集 & Reward model数据集 Deepspeed-chat 源代码的数据集: Dahoas/rm-static: 这是一个用于强化学习的静态环境数据集,包含了一个机器人在一个固定环境中的运动轨迹。该数据集旨在用于评估强化学习算法在静态环境下的表现。 Dahoas/full-hh-rlhf: 这是一个用于…...

探究SAM和眼球追踪技术在自动医学图像分割的应用(2023+GazeSAM: What You See is What You Segment)

摘要&#xff1a; 本研究探讨眼动追踪技术与SAM的潜力&#xff0c;以设计一个协同的人机交互系统&#xff0c;自动化医学图像分割。提出了GazeSAM系统&#xff0c;使放射科医生能够在图像诊断过程中通过简单地查看感兴趣的区域来收集分割掩模。该系统跟踪放射科医生的眼球运动…...

excle中的条件求和SUMIF

问题&#xff1a;将每一行中红色文字的前一个值累计求和到境外总数这一列 使用的公式 自制单元格的格式计算公式&#xff1a;ctrlf3打开格式管理&#xff0c;创建如下公式&#xff0c;其中24是表示获取文字颜色 由于sumif只能直接与第二参数条件比较&#xff0c;所以先使用IF(公…...

python-网络爬虫.Request

Request python中requests库使用方法详解&#xff1a; 一简介&#xff1a; Requests 是Python语言编写&#xff0c;基于urllib&#xff0c; 采用Apache2 Licensed开源协议的 HTTP 库。 与urllib相比&#xff0c;Requests更加方便&#xff0c;处理URL资源特别流畅。 可以节约我…...

时序预测 | MATLAB实现GRNN广义回归神经网络时间序列预测(多指标,多图)

时序预测 | MATLAB实现GRNN广义回归神经网络时间序列预测(多指标,多图) 目录 时序预测 | MATLAB实现GRNN广义回归神经网络时间序列预测(多指标,多图)效果一览基本介绍程序设计参考资料效果一览 基本介绍 1.MATLAB实现GRNN广义回归神经网络时间序列预测(完整源码和数据) …...

如何看待低级爬虫与高级爬虫?

爬虫之所以分为高级和低级&#xff0c;主要是基于其功能、复杂性和灵活性的差异。根据我总结大概有下面几点原因&#xff1a; 功能和复杂性&#xff1a;高级爬虫通常提供更多功能和扩展性&#xff0c;包括处理复杂页面结构、模拟用户操作、解析和清洗数据等。它们解决了开发者…...

3.分支与循环

一、分支结构 1.概念 一个 CPP 程序默认是按照代码书写顺序&#xff0c;从上到下依次执行下来的。但是&#xff0c;有时我们需要选择性的执行某些语句&#xff0c;来实现更加复杂的逻辑&#xff0c;这时候就需要分支结构语句的功能来实现。选择合适的分支语句可以显著提高程序…...

面试之多线程案例(四)

1.单例模式 单例模式是指在内存中只会创建且仅创建一次对象的设计模式。在程序中多次使用同一个对象且作用相同时&#xff0c;为了防止频繁地创建对象使得内存飙升&#xff0c;单例模式可以让程序仅在内存中创建一个对象&#xff0c;让所有需要调用的地方都共享这一单例对象。…...

抄写Linux源码(Day1:获取并运行 Linux0.11)

Day1&#xff1a;获取并运行 Linux0.11 参考资料&#xff1a;https://zhuanlan.zhihu.com/p/438577225 这是我参考的一个别人写的 Linux0.11 解读&#xff1a;https://github.com/dibingfa/flash-linux0.11-talk 我获取 Linux-0.11 源码的链接&#xff1a;https://github.com/…...

大数据_Hadoop_Parquet数据格式详解

之前有面试官问到了parquet的数据格式&#xff0c;下面对这种格式做一个详细的解读。 参考链接 &#xff1a; 列存储格式Parquet浅析 - 简书 Parquet 文件结构与优势_parquet文件_KK架构的博客-CSDN博客 Parquet文件格式解析_parquet.block.size_davidfantasy的博客-CSDN博…...

Docker的安装和部署

目录 一、Docker的安装部署 &#xff08;1&#xff09;关闭防火墙 &#xff08;2&#xff09;关闭selinux &#xff08;3&#xff09;安装docker引擎 &#xff08;4&#xff09;启动docker &#xff08;5&#xff09;设置docker自启动 &#xff08;6&#xff09;测试doc…...

FPGA项目实现:秒表设计

文章目录 项目要求项目设计 项目要求 设计一个时钟秒表&#xff0c;共六个数码管&#xff0c;前两位显示分钟&#xff0c;中间两位显示时间秒&#xff0c;后两位显示毫秒的高两位&#xff0c;可以通过按键来开始、暂停以及重新开始秒表的计数。 项目设计 为完成此项目共设计…...

Postgresql源码(109)并行框架实例与分析

1 PostgreSQL并行参数 系统参数 系统总worker限制&#xff1a;max_worker_processes 默认8 系统总并发限制&#xff1a;max_parallel_workers 默认8 单Query限制&#xff1a;max_parallel_workers_per_gather 默认2 表参数限制&#xff1a;parallel_workers alter table tbl …...

ES派生类的prototype方法中,不能访问super的解决方案

1 下面的B.prototype.compile方法中&#xff0c;无法访问super class A {compile() {console.log(A)} }class B extends A {compile() {super.compile()console.log(B)} }B.prototype.compile function() {super.compile() // 报错&#xff0c;不可以在此处使用superconsole.…...

使用adb通过电脑给安卓设备安装apk文件

最近碰到要在开发板上安装软件的问题&#xff0c;由于是开发板上的安卓系统没有解析apk文件的工具&#xff0c;所以无法通过直接打开apk文件来安装软件。因此查询各种资料后发现可以使用adb工具&#xff0c;这样一来可以在电脑上给安卓设备安装软件。 ADB 就是连接 Android 手…...

113、单例Bean是单例模式吗?

单例Bean是单例模式吗? 通常来说,单例模式是指在一个JVM中,一个类只能构造出来一个对象,有很多方法来实现单例模式,比如懒汉模式,但是我们通常讲的单例模式有一个前提条件就是规定在一个JVM中,那如果要在两个JVM中保证单例呢?那可能就要用分布式锁这些技术,这里的重点…...

RabbitMQ 集群部署

RabbiMQ 是用 Erlang 开发的,集群非常方便,因为 Erlang 天生就是一门分布式语言,但其本身并不支持负载均衡。 RabbitMQ 的集群节点包括内存节点、磁盘节点。RabbitMQ 支持消息的持久化,也就是数据写在磁盘上,最合适的方案就是既有内存节点,又有磁盘节点。 RabbitMQ 模式大…...

2023年【零声教育】13代C/C++Linux服务器开发高级架构师课程体系分析

对于零声教育的C/CLinux服务器高级架构师的课程到2022目前已经迭代到13代了&#xff0c;像之前小编也总结过&#xff0c;但是课程每期都有做一定的更新&#xff0c;也是为了更好的完善课程跟上目前互联网大厂的岗位技术需求&#xff0c;之前课程里面也包含了一些小的分支&#…...

iOS开发-实现热门话题标签tag显示控件

iOS开发-实现热门话题标签tag显示控件 话题标签tag显示非常常见&#xff0c;如选择你的兴趣&#xff0c;选择关注的群&#xff0c;超话&#xff0c;话题等等。 一、效果图 二、实现代码 由于显示的是在列表中&#xff0c;这里整体控件是放在UITableViewCell中的。 2.1 标签…...

linux系统磁盘性能监视工具iostat

目录 一、iostat介绍 二、命令格式 三、命令参数 四、参考命令&#xff1a;iostat -c -x -k -d 1 &#xff08;一&#xff09;输出CPU 属性值 &#xff08;二&#xff09;CPU参数分析 &#xff08;三&#xff09;磁盘每一列的含义 &#xff08;四&#xff09;磁盘参数分…...

BT#蓝牙 - Link Policy Settings

对于Classic Bluetooth的Connection&#xff0c;有一个Link_Policy_Settings&#xff0c;是HCI configuration parameters中的一个。 Link_Policy_Settings 参数决定了本地链路管理器(Link Manager)在收到来自远程链路管理器的请求时的行为&#xff0c;还用来决定改变角色(rol…...

c++ | 动态链接库 | 小结

//环境 linux c //生成动态链接库 //然后调用动态链接库中的函数//出现的问题以及解决//注意在win和在linux中调用动态链接库的函数是不一样的//在要生成链接库的cpp文件中比如以后要调用本文件中的某个函数&#xff0c;需要extern "c" 把你定的函数“再封装”避免重…...

如何使用Flask-SQLAlchemy来管理数据库连接和操作数据?

首先&#xff0c;我们需要安装Flask-SQLAlchemy。你可以使用pip来安装它&#xff0c;就像这样&#xff1a; pip install Flask-SQLAlchemy好了&#xff0c;现在我们已经有了一个可以操作数据库的工具&#xff0c;接下来让我们来看看如何使用它吧&#xff01; 首先&#xff0c…...

麒麟-飞腾Kylin-V4桌面arm64系统静态编译QT

1.系统具体版本&#xff1a; 2. 因为此版本的源很老了&#xff0c;需要修改版本的源&#xff0c;才能正常更新各种软件&#xff0c;否则&#xff0c;你连麒麟商店都打不开。 sudo vi /etc/apt/sources.list 选择你系统对应版本的源地址&#xff1a; #4.0.2桌面版本: deb ht…...

CentOS 项目发出一篇奇怪的博文

导读最近&#xff0c;在红帽限制其 RHEL 源代码的访问之后&#xff0c;整个社区围绕这件事发生了很多事情。 CentOS 项目发出一篇奇怪的博文 周五&#xff0c;CentOS 项目董事会发出了一篇模糊不清的简短博文&#xff0c;文中称&#xff0c;“发展社区并让人们更容易做出贡献…...

【Mybatis-Plus】or拼接

Mybatis-Plus的or拼接是个坑&#xff1a; 这是需要的结果&#xff1a; queryWrapper.and(c->c.or(a->a.eq("qcs3.status", "SIGNING").eq("qcs.status", "SIGNING")).or(b->b.eq("qcs.status","INVALIDING&q…...