首页 > 其他分享 >Android T don't abort background activity starts

Android T don't abort background activity starts

时间:2024-08-20 18:05:07浏览次数:4  
标签:callingUid ... false starts abort intent activity don BAL

log:

2024-08-20 15:45:12.457   581-1128  ActivityTaskManager     system_process                       I  START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=acr.browser.lightning cmp=acr.browser.lightning/.MainActivity} from uid 10056
2024-08-20 15:45:12.460   581-1128  ActivityTaskManager     system_process                       W  Background activity start [callingPackage: com.xx.xxxapp; callingUid: 10056; appSwitchState: 2; isCallingUidForeground: false; callingUidHasAnyVisibleWindow: false; callingUidProcState: FOREGROUND_SERVICE; isCallingUidPersistentSystemProcess: false; realCallingUid: 10056; isRealCallingUidForeground: false; realCallingUidHasAnyVisibleWindow: false; realCallingUidProcState: FOREGROUND_SERVICE; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: null; allowBackgroundActivityStart: false; intent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=acr.browser.lightning cmp=acr.browser.lightning/.MainActivity }; callerApp: ProcessRecord{4974058 1519:com.portworld.bootstartapp/u0a56}; inVisibleTask: false]
2024-08-20 15:45:12.491   581-1128  ActivityTaskManager     system_process                       E  Abort background activity starts from 10056

看日志是系统不让我们从后台启动app,跟踪源码,开始分析:

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

函数流程:
executeRequest->startActivityUnchecked->startActivityInner->isAllowedToStart


private int executeRequest(Request request) {
    ...
    boolean abort = !mSupervisor.checkStartAnyActivityPermission(intent, aInfo, resultWho,
                requestCode, callingPid, callingUid, callingPackage, callingFeatureId,
                request.ignoreTargetSecurity, inTask != null, callerApp, resultRecord,
                resultRootTask);
        abort |= !mService.mIntentFirewall.checkStartActivity(intent, callingUid,
                callingPid, resolvedType, aInfo.applicationInfo);
        abort |= !mService.getPermissionPolicyInternal().checkStartActivity(intent, callingUid,
                callingPackage);

        // Merge the two options bundles, while realCallerOptions takes precedence.
        ActivityOptions checkedOptions = options != null
                ? options.getOptions(intent, aInfo, callerApp, mSupervisor) : null;

        @BalCode int balCode = BAL_ALLOW_DEFAULT;
        if (!abort) {
            try {
                Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER,
                        "shouldAbortBackgroundActivityStart");
                BackgroundActivityStartController balController =
                        mController.getBackgroundActivityLaunchController();
                //key       
                balCode =
                        balController.checkBackgroundActivityStart(
                                callingUid,
                                callingPid,
                                callingPackage,
                                realCallingUid,
                                realCallingPid,
                                callerApp,
                                request.originatingPendingIntent,
                                request.allowBackgroundActivityStart,
                                intent,
                                checkedOptions);
            } finally {
                Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
            }
        }
    ...
        
    mLastStartActivityResult = startActivityUnchecked(r, sourceRecord, voiceSession,
                request.voiceInteractor, startFlags, true /* doResume */, checkedOptions,
                inTask, inTaskFragment, balCode, intentGrants);
    ... 
    
}

//这个类是用来管理那些app可以后台启动的,checkBackgroundActivityStart里面有很多判断,符合要求的返回定义的BAL常量
/frameworks/base/services/core/java/com/android/server/wm/BackgroundActivityStartController.java

    /**
     * @return A code denoting which BAL rule allows an activity to be started,
     * or {@link BAL_BLOCK} if the launch should be blocked  
     */
    @BalCode
    int checkBackgroundActivityStart(...){
        ...
        // IME should always be allowed to start activity, like IME settings.
            final WindowState imeWindow =
                    mService.mRootWindowContainer.getCurrentInputMethodWindow();
            if (imeWindow != null && callingAppId == imeWindow.mOwnerUid) {
                return logStartAllowedAndReturnCode(BAL_ALLOW_ALLOWLISTED_COMPONENT,
                        /*background*/ false, callingUid, realCallingUid, intent,
                        "Active ime");
            }
        }

        //add text
        if(callingPackage.equals("com.xx.xx")){
            Slog.v(TAG, "Background activity start for xxx ,ignored");
            return BAL_ALLOW_DEFAULT;
        }
        //add text
        
        ...
        return BAL_BLOCK;
    }

标签:callingUid,...,false,starts,abort,intent,activity,don,BAL
From: https://www.cnblogs.com/kato-T/p/18370004

相关文章

  • k8s 手动更新 seldon core ca证书
    前言seldoncore报错:x509:certificatehasexpiredorisnotyetvalid:currenttime这是因为seldoncore默认的证书有效期为一年,需要helm重新安装才行,或者在安装seldoncore时启用了certManager自动更新证书helminstallseldon-coreseldon-core-operator--namespac......
  • PCL 法线微分分割(Don)
    1.原理对于点云中的每个点云点P,使用一大一小两个半径计算该点的两个法向量,然后用两个单位法向量的差异计算Don特征。如下图:图1为大半径计算得到的法向量;图2为小半径计算得到的法向量;图3为一大一小两个法向量计算得出的Don特征。步骤:(1)建KD树,计算点云平均密度(即点云点之间......
  • js 字符操作startswidth 方法使用
    startswidth用于检查字符串是否以指定的子字符串开头。startsWith(searchString,position)searchString:要搜索的子字符串。position:可选参数,指定搜索开始的位置(默认值为0)。用法:conststr="helloworld";//检查字符串是否以"hello"开头conststartsWithHello......
  • coca would have done 搭配
      have:585the:213to:190been:138i:135that:111it:110a:110and:93of:85in:72":66he:56you:53#:50had:45they:45she:37for:36on:36as:33if:33with:30we:30be:29but:28him:27his:25her:24think:24would:23more:23was:23-:22this:22th......
  • Python科研武器库 - 字符串操作 - 字符串开头结尾判断 startswith() endswith()
    使用场景:按照开头的前缀、结尾的后缀来判断、筛选目标字符串。使用函数:str.startswith(search_string,start,end)str.endswith(search_string,start,end)search_string:要匹配的目标字符串。start:要从中匹配search_string的str的起始索引。end:要考虑匹配的str的结......
  • Lyndon Word 小记
    1.定义一个字符串\(S\)被定义为LyndonWord当且仅当其严格小于所有真cyclicshift。LyndonWord的等价定义:是其所有后缀中最小的。2.性质性质1:LyndonWord无\(\text{Border}\)。不妨设\(w\)有\(\text{Border}\),则我们可以表示为\(w=xu=uy\),从而得到\(w......
  • 使用 abortNavigation 阻止导航
    title:使用abortNavigation阻止导航date:2024/8/3updated:2024/8/3author:cmdragonexcerpt:摘要:在Nuxt3中,abortNavigation是一个辅助函数,用于路由中间件内阻止不符合条件的页面访问,实现权限控制、错误处理及动态重定向,提升用户体验和应用可靠性categories:前端开......
  • [已解决] Rstudio出现炸弹 R Session Aborted
    因为打开了一个过大文件,导致Rstudio环境损坏。查到可以通过替换.history可解决,尝试后无果。重装因为第一次重装没有删除干净,导致重装后再次打开还是同样出现新的问题。卸载再次重装Rstudio在系统中的变量路径全部删除彻底清除Rstudio痕迹,删除隐藏文件夹并在R中运......
  • CentOS6.3安装xtables-addons,实现流量复制&镜像克隆
    一、版本要求CentOS6.3,64位(内核版本2.6.32-279),iptables版本是自带的v1.4.7CentOS6.9--6.10也可以,其它版本没有测试。ubuntu22.04上没有安装成功。二、依赖安装yuminstallgccyuminstallgcc-c++yuminstalliptables-devel三、下载安装包下载地址:https://inai.d......
  • Lyndon 分解 & runs
    万成章在2022年集训队论文《浅谈与Lyndon理论有关的字符串组合问题》中做过详细介绍,由于笔者太菜,这里只做简单介绍,并且不做证明。Lyndon分解Lyndon串:对于字符串\(s\),如果\(s\)的字典序严格小于\(s\)的所有后缀的字典序,我们称\(s\)是Lyndon串。Lyndon分解:串\(s\)的Lyndon分解记......