当前位置: 首页 > 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中保证单例呢?那可能就要用分布式锁这些技术,这里的重点…...

【JavaEE】-- HTTP

1. HTTP是什么&#xff1f; HTTP&#xff08;全称为"超文本传输协议"&#xff09;是一种应用非常广泛的应用层协议&#xff0c;HTTP是基于TCP协议的一种应用层协议。 应用层协议&#xff1a;是计算机网络协议栈中最高层的协议&#xff0c;它定义了运行在不同主机上…...

跨链模式:多链互操作架构与性能扩展方案

跨链模式&#xff1a;多链互操作架构与性能扩展方案 ——构建下一代区块链互联网的技术基石 一、跨链架构的核心范式演进 1. 分层协议栈&#xff1a;模块化解耦设计 现代跨链系统采用分层协议栈实现灵活扩展&#xff08;H2Cross架构&#xff09;&#xff1a; 适配层&#xf…...

HTML前端开发:JavaScript 常用事件详解

作为前端开发的核心&#xff0c;JavaScript 事件是用户与网页交互的基础。以下是常见事件的详细说明和用法示例&#xff1a; 1. onclick - 点击事件 当元素被单击时触发&#xff08;左键点击&#xff09; button.onclick function() {alert("按钮被点击了&#xff01;&…...

Java多线程实现之Thread类深度解析

Java多线程实现之Thread类深度解析 一、多线程基础概念1.1 什么是线程1.2 多线程的优势1.3 Java多线程模型 二、Thread类的基本结构与构造函数2.1 Thread类的继承关系2.2 构造函数 三、创建和启动线程3.1 继承Thread类创建线程3.2 实现Runnable接口创建线程 四、Thread类的核心…...

Redis的发布订阅模式与专业的 MQ(如 Kafka, RabbitMQ)相比,优缺点是什么?适用于哪些场景?

Redis 的发布订阅&#xff08;Pub/Sub&#xff09;模式与专业的 MQ&#xff08;Message Queue&#xff09;如 Kafka、RabbitMQ 进行比较&#xff0c;核心的权衡点在于&#xff1a;简单与速度 vs. 可靠与功能。 下面我们详细展开对比。 Redis Pub/Sub 的核心特点 它是一个发后…...

佰力博科技与您探讨热释电测量的几种方法

热释电的测量主要涉及热释电系数的测定&#xff0c;这是表征热释电材料性能的重要参数。热释电系数的测量方法主要包括静态法、动态法和积分电荷法。其中&#xff0c;积分电荷法最为常用&#xff0c;其原理是通过测量在电容器上积累的热释电电荷&#xff0c;从而确定热释电系数…...

初探Service服务发现机制

1.Service简介 Service是将运行在一组Pod上的应用程序发布为网络服务的抽象方法。 主要功能&#xff1a;服务发现和负载均衡。 Service类型的包括ClusterIP类型、NodePort类型、LoadBalancer类型、ExternalName类型 2.Endpoints简介 Endpoints是一种Kubernetes资源&#xf…...

CRMEB 中 PHP 短信扩展开发:涵盖一号通、阿里云、腾讯云、创蓝

目前已有一号通短信、阿里云短信、腾讯云短信扩展 扩展入口文件 文件目录 crmeb\services\sms\Sms.php 默认驱动类型为&#xff1a;一号通 namespace crmeb\services\sms;use crmeb\basic\BaseManager; use crmeb\services\AccessTokenServeService; use crmeb\services\sms\…...

论文阅读笔记——Muffin: Testing Deep Learning Libraries via Neural Architecture Fuzzing

Muffin 论文 现有方法 CRADLE 和 LEMON&#xff0c;依赖模型推理阶段输出进行差分测试&#xff0c;但在训练阶段是不可行的&#xff0c;因为训练阶段直到最后才有固定输出&#xff0c;中间过程是不断变化的。API 库覆盖低&#xff0c;因为各个 API 都是在各种具体场景下使用。…...

uniapp 小程序 学习(一)

利用Hbuilder 创建项目 运行到内置浏览器看效果 下载微信小程序 安装到Hbuilder 下载地址 &#xff1a;开发者工具默认安装 设置服务端口号 在Hbuilder中设置微信小程序 配置 找到运行设置&#xff0c;将微信开发者工具放入到Hbuilder中&#xff0c; 打开后出现 如下 bug 解…...