安卓14系统应用收不到开机广播

安卓14系统应用收不到开机广播 - Wesley’s Blog

前段时间有测试反馈在安卓14 上面某系统应用恢复出厂设置后没有自启动,究竟是什么原因呢?
请添加图片描述

回顾

Android 从3.1开始,会将新安装并且从未被启动的应用置为“STOPPED”状态,或者被force stop的应用,这种状态下的应用是无法接收到广播的。但发送方可以通过添加FLAG_INCLUDE_STOPPED_PACKAGES 来豁免,但一般情况下,系统会默认添加FLAG_EXCLUDE_STOPPED_PACKAGES flag。

http://xrefandroid.com/android-16.0.0_r2/s?refs=FLAG_EXCLUDE_STOPPED_PACKAGES&project=frameworks

    /*** If set, this intent will not match any components in packages that* are currently* {@linkplain android.content.pm.ApplicationInfo#FLAG_STOPPED stopped}.* If this is not set, then the default behavior is to include such* applications in the result.*/public static final int FLAG_EXCLUDE_STOPPED_PACKAGES = 0x00000010;/*** If set, this intent will always match any components in packages that* are currently* {@linkplain android.content.pm.ApplicationInfo#FLAG_STOPPED stopped}.* This is the default behavior when* {@link #FLAG_EXCLUDE_STOPPED_PACKAGES} is not set.  If both of these* flags are set, this one wins (it allows overriding of exclude for* places where the framework may automatically set the exclude flag,* such as broadcasts).*/public static final int FLAG_INCLUDE_STOPPED_PACKAGES = 0x00000020;

豁免

IntentResolver.java - OpenGrok cross reference for /frameworks/base/services/core/java/com/android/server/IntentResolver.java

private void buildResolveList(@NonNull Computer computer, Intent intent,FastImmutableArraySet<String> categories, boolean debug, boolean defaultOnly,String resolvedType, String scheme, F[] src, List<R> dest, int userId,long customFlags) { ...........if (excludingStopped && isFilterStopped(computer.getPackageStateInternal(packageName),userId)) {if (debug) {Slog.v(TAG, "  Filter's target is stopped; skipping");}continue;}..................
}

ComponentResolver.java - OpenGrok cross reference for /frameworks/base/services/core/java/com/android/server/pm/resolution/ComponentResolver.java

        @Overrideprotected boolean isFilterStopped(@Nullable PackageStateInternal packageState,@UserIdInt int userId) {if (!mUserManager.exists(userId)) {return true;}if (packageState == null || packageState.getPkg() == null) {return false;}// System apps are never considered stopped for purposes of// filtering, because there may be no way for the user to// actually re-launch them.return !packageState.isSystem()&& packageState.getUserStateOrDefault(userId).isStopped();}

安卓 14 之前的代码表明系统应用(系统标记为ApplicationInfo.FLAG_SYSTEM 的应用)是可以豁免的。

注意: 直接安装在 data 分区的 system uid 应用是不会被标记为ApplicationInfo.FLAG_SYSTEM 的。但更新在 data 分区的系统应用依然有效。

安卓 14 的变化

ComponentResolver.java - OpenGrok cross reference for /frameworks/base/services/core/java/com/android/server/pm/resolution/ComponentResolver.java

        @Overrideprotected boolean isFilterStopped(@NonNull Computer computer, F filter,@UserIdInt int userId) {if (!mUserManager.exists(userId)) {return true;}final PackageStateInternal packageState = computer.getPackageStateInternal(filter.first.getPackageName());if (packageState == null || packageState.getPkg() == null) {return false;}return packageState.getUserStateOrDefault(userId).isStopped();}

系统应用不能豁免了,一刀切了。🤣 当然,这里可以打补丁让原来的修改有效。

安卓 15 峰回路转

ComponentResolver.java - OpenGrok cross reference for /frameworks/base/services/core/java/com/android/server/pm/resolution/ComponentResolver.java

        @Overrideprotected boolean isFilterStopped(@NonNull Computer computer, F filter,@UserIdInt int userId) {if (!mUserManager.exists(userId)) {return true;}final PackageStateInternal packageState = computer.getPackageStateInternal(filter.first.getPackageName());if (packageState == null || packageState.getPkg() == null) {return false;}if (packageState.isSystem()) {// A system app can be considered in the stopped state only if it was originally// scanned in the stopped state.return packageState.isScannedAsStoppedSystemApp() &&packageState.getUserStateOrDefault(userId).isStopped();}return packageState.getUserStateOrDefault(userId).isStopped();}}

安卓 15 开始,又把系统应用的豁免加回来了,但有了更加精细化的控制。不仅需要满足是系统应用,同时也要满足不是被第一次开机标记为停止状态的系统应用。

isScannedAsStoppedSystemApp() 是用来检查一个系统应用在系统首次启动时,是否被自动置于“强制停止”(stopped)状态。

那么这个状态是怎么标记的呢?

哪些应用会被标记?

adb可以通过 dumpsys package 包名 | grep isScannedAsStoppedSystemApp来查看

主要看PackageSettingsetScannedAsStoppedSystemApp 的调用关系

«interface»
PackageState
«interface»
PackageStateInternal
SettingBase
PackageSetting

最后确认为扫描系统 apk 时添加了SCAN_AS_STOPPED_SYSTEM_APP 的扫描标志位的应用会标记为停止状态。

InstallPackageHelper.java - OpenGrok cross reference for /frameworks/base/services/core/java/com/android/server/pm/InstallPackageHelper.java

private Pair<ScanResult, Boolean> scanSystemPackageLI(ParsedPackage parsedPackage,@ParsingPackageUtils.ParseFlags int parseFlags,@PackageManagerService.ScanFlags int scanFlags,@Nullable UserHandle user) throws PackageManagerException { // A new application appeared on /system, and we are seeing it for the first time.// Its also not updated as we don't have a copy of it on /data. So, scan it in a// STOPPED state.// We'll skip this step under the following conditions://   - It's "android"//   - It's an APEX or overlay package since stopped state does not affect them.//   - It is enumerated with a <initial-package-state> tag having the stopped attribute//     set to false//   - It doesn't have an enabled and exported launcher activity, which means the user//     wouldn't have a way to un-stop itfinal boolean isApexPkg = (scanFlags & SCAN_AS_APEX) != 0;if (mPm.mShouldStopSystemPackagesByDefault&& scanSystemPartition&& !pkgAlreadyExists&& !isApexPkg&& !parsedPackage.isOverlayIsStatic()) {String packageName = parsedPackage.getPackageName();if (!"android".contentEquals(packageName)&& !mPm.mInitialNonStoppedSystemPackages.contains(packageName)&& hasLauncherEntry(parsedPackage)) {scanFlags |= SCAN_AS_STOPPED_SYSTEM_APP;}}
}

根据函数的注释,一个应用会被标记为“停止的系统应用”(Scanned As Stopped System App)需要满足以下所有条件

  1. 是系统应用:即系统标记为ApplicationInfo.FLAG_SYSTEM 的应用。

  2. 在core/res/res/values/config.xml 配置config_stopSystemPackagesByDefault为 true,默认启用。

        <!-- Whether system apps should be scanned in the stopped state during initial boot.Packages can be added by OEMs in an allowlist, to prevent them from being scanned as"stopped" during initial boot of a device, or after an OTA update. Stopped state ofan app is not changed during subsequent reboots.  --><bool name="config_stopSystemPackagesByDefault">true</bool>
    
  3. 应用不存在

  4. 不是 system_server(包名为 android )

  5. 不是 APEX 包和静态资源覆盖包(Overlay)

  6. 有启动入口 (Launcher Entry)。

  7. 没有在initial-package-stopped-states.xml 配置中被豁免。

initial-package-stopped-states.xml - OpenGrok cross reference for /frameworks/base/data/etc/initial-package-stopped-states.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
This XML defines an allowlist for packages that should not be scanned in a "stopped" state.
When this feature is turned on (indicated by the config config_stopSystemPackagesByDefault in
core/res/res/values/config.xml) packages on the system partition that are encountered by
the PackageManagerService for the first time are scanned in the "stopped" state. This allowlist
is also considered while creating new users on the device. Stopped state is not set during
subsequent reboots.Example usage1. <initial-package-state package="com.example.app" stopped="false"/>Indicates that a system package - com.example.app's initial stopped state should not be setby the Package Manager. By default, system apps are marked as stopped.2. <initial-package-state package="com.example.app" stopped="true"/>Indicates that a system package - com.example.app's initial state should be set by thePackage Manager to "stopped=true". It will have the same effect on thepackage's stopped state even if this package was not included in the allow list.3. <initial-package-state package="com.example.app"/>Invalid usage.
--><config></config>

参考

stop应用无法收到广播问题_应用未启动接收广播-CSDN博客

关于Android中App的停止状态 - 技术小黑屋

PMS 第 4 篇 - PMS_DATA_SCAN_START 阶段 | Coolqi`s Blog

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/93926.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/93926.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C# Attribute 方法扩展

场景 刚写完一个干净利落的方法&#xff0c;比如保存数据到数据库&#xff0c;逻辑清晰、结构优雅&#xff0c; 第二天&#xff0c;“嘿&#xff0c;保存完数据&#xff0c;记得给客户发个邮件哦~” 第三天&#xff0c;“能不能再发个消息通知其他系统&#xff1f;” 第四天&am…

【URP】[法线贴图]为什么主要是蓝色的?

【从UnityURP开始探索游戏渲染】专栏-直达 法线贴图呈现蓝紫色调&#xff08;尤其以蓝色为主&#xff09;是由其‌存储原理、切线空间坐标系设计及颜色编码规则共同决定的‌。 核心原因&#xff1a;法线向量的存储规则‌ ‌法线向量的物理范围‌ 法线是单位向量&#xff0c;…

驱动开发系列63 - NVIDIA 开源GPU驱动open-gpu-kernel-modules编译调试

目录 一:通过apt方式安装nvidia 驱动 二:通过 .run 方式安装nvidia驱动 三:编译安装nvidia开源内核驱动 四:验证和调试 五:卸载驱动 1. 以apt方式安装nvidia 驱动的卸载方法 2. 以.run方式安装nvidia驱动的卸载方法 六:安装CUDA环境 一:通过apt方式安装nvidia 驱动…

对KingbaseES架构的解析:从读写分离到异地灾备的技术实现与保障机制

声明&#xff1a;文章为本人真实测评博客&#xff0c;非广告&#xff0c;并没有推广该平台 &#xff0c;为用户体验文章 本人旨在分享最真实的用户体验&#xff0c;为关注此类产品的朋友们提供一个客观的参考。 文章目录一、架构全景&#xff1a;四级高可用构建数字基础1.1 物…

Visual Studio中的常用调试功能(上)

1、利用断点进行调试添加断点的方式有以下几种1.键盘快捷键F92.通过菜单【Debug&#xff08;调试&#xff09;】-》【Toggle BreakPoint&#xff08;切换断点&#xff09;】3.点击代码行左边的空白处&#xff08;推荐&#xff09;设置断点后&#xff0c;按F5运行程序&#xff0…

Linux -- 线程同步

1.1条件变量 (1)当⼀个线程互斥地访问某个变量时&#xff0c;它可能发现在其它线程改变状态之前&#xff0c;它什么也做不了。 (2)例如⼀个线程访问队列时&#xff0c;发现队列为空&#xff0c;它只能等待&#xff0c;只到其它线程将⼀个节点添加到队列 中。这种情况就需要⽤到…

前端进阶指南:JavaScript性能优化实战全解析

深入剖析 JavaScript 性能瓶颈&#xff0c;分享优化技巧与最佳实践&#xff0c;让你的前端应用更快、更稳、更流畅。 &#x1f4d1; 目录 一、前言 二、性能瓶颈的常见来源 三、JavaScript代码优化技巧 1. 避免重复计算 2. 合理使用防抖与节流 3. 使用事件委托 四、渲染…

RabbitMQ:SpringAMQP Direct Exchange(直连型交换机)

目录一、案例需求二、基础配置三、代码实现直连型交换机也叫做定向交换机&#xff0c;通过RoutingKey绑定交换机与队列直接的关系。 生产者源码 消费者源码 一、案例需求 在RabbitMQ控制台中&#xff0c;声明队列direct.queue1和direct.queue2。在RabbitMQ控制台中&#xff…

implement libtime on Windows

因为Windows的time命令和Linux的time命令不一样&#xff0c;尝试实现libtime libtime.h /** libtime.h - 跨平台时间测量库* 功能&#xff1a;执行外部命令并测量其运行时间和资源使用*/#ifndef LIBTIME_H #define LIBTIME_H#include <stdio.h> #include <stdlib.h>…

Unity进阶--C#补充知识点--【C#各版本的新功能新语法】C#1~4与C#5

来源于唐老狮的视频教学&#xff0c;仅作记录和感悟记录&#xff0c;方便日后复习或者查找 一.C#版本与Unity的关系 1.各Unity版本支持的C#版本 更多信息可以在Untiy官网说明查看 https://docs.unity3d.com/2020.3/Documentation/Manual/CSharpCompiler.html&#xff08;这个好…

水闸安全综合监测系统解决方案

一、方案概述 水闸作为重要的水利工程设施&#xff0c;承担着防洪、排涝、供水和灌溉等关键功能。其安全性直接关系到下游人民群众的生命财产安全以及区域经济的稳定发展。近年来&#xff0c;随着极端天气频发和工程老化问题日益突出&#xff0c;水闸安全监测工作显得尤为重要。…

基于单片机智能点滴输液系统

传送门 &#x1f449;&#x1f449;&#x1f449;&#x1f449;其他作品题目速选一览表 &#x1f449;&#x1f449;&#x1f449;&#x1f449;其他作品题目功能速览 概述 该系统基于单片机控制技术&#xff0c;结合传感器和无线通信模块&#xff0c;实现对输液过程的实…

AI数据仓库管理提升效率

内容概要在数字化转型浪潮中&#xff0c;AI数据仓库管理正重塑企业数据处理格局。本部分简要介绍其核心机制&#xff0c;即通过智能API接入外部数据源实现多平台数据无缝整合&#xff0c;随后应用数据清洗技术去除冗余信息&#xff0c;确保数据质量。同时&#xff0c;加密存储机…

使用 Docker 安装长安链管理平台 + 部署区块链与示例合约

文章目录简介登录官网GithubPodman 配置&#xff08;Docker 配置 registry 地址&#xff09;安装长安链管理平台下载源码docker-compose.yml登录管理平台部署区块链Dockerfile构建镜像部署长安链订阅区块链部署合约下载示例合约部署示例合约投票管理文件哈希存证查找存证信息区…

Python训练营打卡 DAY 41 简单CNN

知识回顾 数据增强卷积神经网络定义的写法batch归一化&#xff1a;调整一个批次的分布&#xff0c;常用与图像数据特征图&#xff1a;只有卷积操作输出的才叫特征图调度器&#xff1a;直接修改基础学习率 卷积操作常见流程如下&#xff1a; 1. 输入 → 卷积层 → Batch归一化层…

云端赋能,智慧运维:分布式光伏电站一体化监控平台研究

摘要 本文针对分布式光伏电站存在的监管困难、火灾隐患、系统繁杂及运维不规范等行业痛点&#xff0c;提出AcrelCloud-1200光伏运维云平台解决方案。平台通过ANet-1E2S-4G网关集成多品牌逆变器数据&#xff0c;结合视频监控与气象站&#xff0c;实现电站全域监测&#xff1b;开…

CVPR 2025 | 具身智能 | HOLODECK:一句话召唤3D世界,智能体的“元宇宙练功房”来了

关注gongzhonghao【CVPR顶会精选】1.导读1.1 论文基本信息论文标题&#xff1a;《HOLODECK: Language Guided Generation of 3D Embodied AI Environments》作者&#xff1a;Yue Yang*1, Fan-Yun Sun*2, Luca Weihs*4, Eli Vanderbilt4, Alvaro Herrasti4,Winson Han4, Jiajun …

迅为RK3568开发板搭建Ubuntu环境

本小节介绍开发所需 Ubuntu 环境的搭建方法。系统要求:Ubuntu 系统要求&#xff1a;Ubuntu18.04~21.10 版本。推荐使用 20.04 版本&#xff0c;内存 16GB 及以上&#xff0c;硬盘 100GB 及以上。Ubuntu 系统的用户名不能包含中文字符。建议 Ubuntu 和 Windows 系统上安装的 Dev…

【数据结构】用堆解决TOPK问题

设计一个算法&#xff0c;找出数组中最小的k个数。以任意顺序返回这k个数均可。示例&#xff1a;输入&#xff1a; arr [1,3,5,7,2,4,6,8], k 4 输出&#xff1a; [1,2,3,4]比较替换堆顶的数时&#xff0c;不需要让堆顶与数组的每一个数再进行比较&#xff0c;比较数组减去k个…

【深度长文】Anthropic发布Prompt Engineering全新指南

目录 1.什么时候适合用提示工程? 2.如何进行提示工程 2.1 使用提示模板 2.1.1 使用提示模板和变量 2.1.2 何时使用提示模板和变量 2.1.3 提示模板示例 2.2 保持清晰和直接 2.2.1 如何保持清晰、具有上下文和具体 2.2.2 示例 ​2.3 使用示例&#xff08;多示例提示…