最近项目中遇到一个问题:一个客户应用从后台启动Activity,有如下打印

Slog.w(TAG, "Background activity start [callingPackage: " + callingPackage+ "; callingUid: " + callingUid+ "; isCallingUidForeground: " + isCallingUidForeground+ "; isCallingUidPersistentSystemProcess: " + isCallingUidPersistentSystemProcess+ "; realCallingUid: " + realCallingUid+ "; isRealCallingUidForeground: " + isRealCallingUidForeground+ "; isRealCallingUidPersistentSystemProcess: "+ isRealCallingUidPersistentSystemProcess+ "; originatingPendingIntent: " + originatingPendingIntent+ "; isBgStartWhitelisted: " + allowBackgroundActivityStart+ "; intent: " + intent+ "; callerApp: " + callerApp+ "]");

通过在源代码里面搜索,找到对应的文件是

frameworks/base/services/core/java/com/android/server/wm/ActivityStarter.java

shouldAbortBackgroundActivityStart方法里面会判断是否拦截,方法如下:

   boolean shouldAbortBackgroundActivityStart(int callingUid, int callingPid,final String callingPackage, int realCallingUid, int realCallingPid,WindowProcessController callerApp, PendingIntentRecord originatingPendingIntent,boolean allowBackgroundActivityStart, Intent intent) {// don't abort for the most important UIDsfinal int callingAppId = UserHandle.getAppId(callingUid);if (callingUid == Process.ROOT_UID || callingAppId == Process.SYSTEM_UID|| callingAppId == Process.NFC_UID) {return false;}// don't abort if the callingUid has a visible window or is a persistent system processfinal int callingUidProcState = mService.getUidState(callingUid);final boolean callingUidHasAnyVisibleWindow =mService.mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(callingUid);final boolean isCallingUidForeground = callingUidHasAnyVisibleWindow|| callingUidProcState == ActivityManager.PROCESS_STATE_TOP|| callingUidProcState == ActivityManager.PROCESS_STATE_BOUND_TOP;final boolean isCallingUidPersistentSystemProcess =callingUidProcState <= ActivityManager.PROCESS_STATE_PERSISTENT_UI;if (callingUidHasAnyVisibleWindow || isCallingUidPersistentSystemProcess) {return false;}// take realCallingUid into considerationfinal int realCallingUidProcState = (callingUid == realCallingUid)? callingUidProcState: mService.getUidState(realCallingUid);final boolean realCallingUidHasAnyVisibleWindow = (callingUid == realCallingUid)? callingUidHasAnyVisibleWindow: mService.mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(realCallingUid);final boolean isRealCallingUidForeground = (callingUid == realCallingUid)? isCallingUidForeground: realCallingUidHasAnyVisibleWindow|| realCallingUidProcState == ActivityManager.PROCESS_STATE_TOP;final int realCallingAppId = UserHandle.getAppId(realCallingUid);final boolean isRealCallingUidPersistentSystemProcess = (callingUid == realCallingUid)? isCallingUidPersistentSystemProcess: (realCallingAppId == Process.SYSTEM_UID)|| realCallingUidProcState <= ActivityManager.PROCESS_STATE_PERSISTENT_UI;if (realCallingUid != callingUid) {// don't abort if the realCallingUid has a visible windowif (realCallingUidHasAnyVisibleWindow) {return false;}// if the realCallingUid is a persistent system process, abort if the IntentSender// wasn't whitelisted to start an activityif (isRealCallingUidPersistentSystemProcess && allowBackgroundActivityStart) {return false;}// don't abort if the realCallingUid is an associated companion appif (mService.isAssociatedCompanionApp(UserHandle.getUserId(realCallingUid),realCallingUid)) {return false;}}// don't abort if the callingUid has START_ACTIVITIES_FROM_BACKGROUND permissionif (mService.checkPermission(START_ACTIVITIES_FROM_BACKGROUND, callingPid, callingUid)== PERMISSION_GRANTED) {return false;}// don't abort if the caller has the same uid as the recents componentif (mSupervisor.mRecentTasks.isCallerRecents(callingUid)) {return false;}// don't abort if the callingUid is the device ownerif (mService.isDeviceOwner(callingUid)) {return false;}// don't abort if the callingUid has companion devicefinal int callingUserId = UserHandle.getUserId(callingUid);if (mService.isAssociatedCompanionApp(callingUserId, callingUid)) {return false;}// If we don't have callerApp at this point, no caller was provided to startActivity().// That's the case for PendingIntent-based starts, since the creator's process might not be// up and alive. If that's the case, we retrieve the WindowProcessController for the send()// caller, so that we can make the decision based on its foreground/whitelisted state.int callerAppUid = callingUid;if (callerApp == null) {callerApp = mService.getProcessController(realCallingPid, realCallingUid);callerAppUid = realCallingUid;}// don't abort if the callerApp or other processes of that uid are whitelisted in any wayif (callerApp != null) {// first check the original calling processif (callerApp.areBackgroundActivityStartsAllowed()) {return false;}// only if that one wasn't whitelisted, check the other onesfinal ArraySet<WindowProcessController> uidProcesses =mService.mProcessMap.getProcesses(callerAppUid);if (uidProcesses != null) {for (int i = uidProcesses.size() - 1; i >= 0; i--) {final WindowProcessController proc = uidProcesses.valueAt(i);if (proc != callerApp && proc.areBackgroundActivityStartsAllowed()) {return false;}}}}// don't abort if the callingUid has SYSTEM_ALERT_WINDOW permissionif (mService.hasSystemAlertWindowPermission(callingUid, callingPid, callingPackage)) {Slog.w(TAG, "Background activity start for " + callingPackage+ " allowed because SYSTEM_ALERT_WINDOW permission is granted.");return false;}// anything that has fallen through would currently be abortedSlog.w(TAG, "Background activity start [callingPackage: " + callingPackage+ "; callingUid: " + callingUid+ "; isCallingUidForeground: " + isCallingUidForeground+ "; isCallingUidPersistentSystemProcess: " + isCallingUidPersistentSystemProcess+ "; realCallingUid: " + realCallingUid+ "; isRealCallingUidForeground: " + isRealCallingUidForeground+ "; isRealCallingUidPersistentSystemProcess: "+ isRealCallingUidPersistentSystemProcess+ "; originatingPendingIntent: " + originatingPendingIntent+ "; isBgStartWhitelisted: " + allowBackgroundActivityStart+ "; intent: " + intent+ "; callerApp: " + callerApp+ "]");// log aborted activity start to TRONif (mService.isActivityStartsLoggingEnabled()) {mSupervisor.getActivityMetricsLogger().logAbortedBgActivityStart(intent, callerApp,callingUid, callingPackage, callingUidProcState, callingUidHasAnyVisibleWindow,realCallingUid, realCallingUidProcState, realCallingUidHasAnyVisibleWindow,(originatingPendingIntent != null));}return true;}

从此方法可以看出,有如下打印,就是此方法返回true,拦截启动

Slog.w(TAG, "Background activity start [callingPackage: " + callingPackage

查看官方文档,在android q版本上增加了对后台启动Activity的限制
https://developer.android.google.cn/guide/components/activities/background-starts

新增加了一个权限定义在

frameworks/base/core/res/AndroidManifest.xml

具体定义如下:

<permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"android:protectionLevel="signature|privileged|vendorPrivileged|oem|verifier" />

应用预制在system/app下是不满足条件的,修改到system/priv-app/目录下,满足privileged这个条件,不会拦截

android Q版本START_ACTIVITIES_FROM_BACKGROUND相关推荐

  1. Android Q版本应用兼容性适配指导

    目录 Android Q版本应用兼容性适配指导... 1 1.      背景说明... 4 2.      存储空间限制... 4 2.1背景     4 2.2兼容性影响... 5 2.3 适配指 ...

  2. 一文看懂:Android Q版本在安全方面进行了哪些系统性改进

    5月8日凌晨,2019年谷歌I/O开发者大会召开.谷歌下一代Android系统Android Q正式亮相,版本号是10.0.其实早在3月14日,谷歌就放出了Android Q的首个测试版. 那么,此次 ...

  3. android Q版本外部存储问题以及获取空间大小问题

    Q版本: 1.在manifest 文件中添加权限 <uses-permission android:name="android.permission.WRITE_EXTERNAL_ST ...

  4. 首批Android Q版本真机上线,Testin云测助力尝鲜

    2019年3月14日,Android 最新操作系统 Android Q beta 版本正式上线.Testin云测作为国内先进的应用服务平台,在第一时间完成了 Android Q beta 版本的手机系 ...

  5. Android Q版本读取SDcard

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses ...

  6. Android高版本P/Q/R源码编译指南

           Android高版本P/Q/R源码编译指南 Android源码编译系列博客: Android.bp你真的了解吗 Android.bp入门指南之Android.mk转换成Android.b ...

  7. Android Q(10.0 API29)版本新特性和兼容性适配

    摘要 1.本文档基于谷歌AndroidQ官方文档和一加Q版本应用兼容性整改指导 2.本文档主要对影响比较大的部分进行简单总结,内容并不全面: 3.版本号对应关系: Android-Q = Androi ...

  8. Android Q(10.0)版本新特性和兼容性适配

    北京时间2019年3月14日Google正式对外发布Android Q Beta 1及预览版SDK,这意味着安卓开发者们又即将迎来一年一度的新版本适配工作了.Android Q 为开发者们带来了许多新 ...

  9. MTK平台Metadata的加载(4)—Q版本后

    (1)Loading static metadata(senosor and 3A) 与 Android P 加载流程一致,在 Android Q 中 buildStaticInfo 首先通过 imp ...

  10. android Q屏幕录制,设备音频录制无声

    Android q 之后google添加了音频录制的api 在状态栏中可以开启录制功能. 使用中发现,选择音源为设备内部音频的时候,录制的视频无声. 内部音乐录制时android Q版本之后googl ...

最新文章

  1. 时间序列、时间序列分析、时间序列效应分解、平稳时间序列、AIC和BIC
  2. java静态和动态的区别是什么意思_Java中的动态和静态多态性有什么区别?
  3. VMware网络连接模式—桥接、NAT以及仅主机模式的详细介绍和区别.ziw
  4. 【Linux基础】crontab定时命令详解
  5. React虚拟DOM的理解
  6. 用vue开发一个app(1,基础环境配置)
  7. mysql jdbc实例_jdbc操作mysql数据库实例
  8. scala-传名函数和传值函数
  9. 区块链 以太坊 智能合约 运行原理和开发实例
  10. 6. Keras-RNN应用
  11. 宝软网java软件下载_手机游戏怎么下载
  12. DEAP:使用生理信号进行情绪分析的数据库IEEE
  13. 如何让Ubuntu联网
  14. 怎么设置ppt页面的长度和宽度_ppt幻灯片的尺寸大小要设置成多少厘米的,但是我的页面设置的大小单位是英寸,怎么设置...
  15. 简述 Spring Bean的生命周期
  16. 安卓虚拟机_VMOS虚拟大师-独立的安卓虚拟机系统(已ROOT)「安卓」
  17. 智融SW6206、SW3516、SW3522、SW2303等快充市场方案应用
  18. dvd-rom属于什么
  19. 浅谈数据中心新型末端母线配电系统
  20. 【微信抢红包】红包助手-修改版

热门文章

  1. 基于STM32HAL库ADS1256调试笔记
  2. js的数据类型,深拷贝和浅拷贝的原理,loda实现一个深拷贝
  3. 全球与中国塑料拖链市场深度研究分析报告
  4. 公司小程序,公众号申请支付流程
  5. python高德地图api调用实例_Python玩转高德地图API(二)
  6. 基于高德地图API渲染首页
  7. 有哪些实用的软件开发项目管理工具?
  8. html中盒子透明度代码,用CSS制作一个透明盒子
  9. 泊松分布(Poisson Distribution)
  10. 问题解决:Too many errors! 3 errors were dropped